42 #include <visp3/core/vpPolygon.h>
43 #include <visp3/core/vpException.h>
44 #include <visp3/core/vpDisplay.h>
45 #include <visp3/core/vpMeterPixelConversion.h>
46 #include <visp3/core/vpUniRand.h>
56 : _corners(), _center(), _area(0.), _goodPoly(true), _bbox(), m_PnPolyConstants(), m_PnPolyMultiples()
58 std::vector<vpImagePoint> corners;
73 : _corners(), _center(), _area(0.), _goodPoly(true), _bbox(), m_PnPolyConstants(), m_PnPolyMultiples()
75 if(corners.size() < 3){
89 : _corners(), _center(), _area(0.), _goodPoly(true), _bbox(), m_PnPolyConstants(), m_PnPolyMultiples()
91 if(corners.size() < 3){
103 : _corners(), _center(), _area(0.), _goodPoly(true), _bbox()
110 m_PnPolyConstants = poly.m_PnPolyConstants;
111 m_PnPolyMultiples = poly.m_PnPolyMultiples;
134 m_PnPolyConstants = poly.m_PnPolyConstants;
135 m_PnPolyMultiples = poly.m_PnPolyMultiples;
179 std::vector<vpImagePoint> ipCorners(corners.size());
180 for(
unsigned int i=0; i<corners.size(); ++i){
198 std::vector<vpImagePoint> cornersClick;
204 cornersClick.push_back(ip);
230 precalcValuesPnPoly();
251 precalcValuesPnPoly();
275 double denominator = di1 * dj2 - dj1 * di2;
277 if(fabs(denominator) < std::numeric_limits<double>::epsilon()){
281 double alpha = - ( ( ip1.
get_i() - ip3.
get_i() ) * dj2 + di2 * ( ip3.
get_j() - ip1.
get_j())) / denominator;
282 if(alpha < 0 || alpha >= 1){
286 double beta = - (di1 * (ip3.
get_j() - ip1.
get_j() ) + dj1 * (ip1.
get_i() - ip3.
get_i()) ) / denominator;
287 if(beta < 0 || beta >= 1){
306 std::cerr <<
"It is not a polygon (_corners.size() < 3)!" << std::endl;
316 infPoint.
set_i( infPoint.
get_i() + 1000 * generator());
317 infPoint.
set_j( infPoint.
get_j() + 1000 * generator());
319 bool oddNbIntersections =
false;
320 for(
unsigned int i=0; i<
_corners.size(); ++i){
323 bool intersection =
false;
331 intersection = testIntersectionSegments(ip1, ip2, ip, infPoint );
337 oddNbIntersections = !oddNbIntersections;
341 test = oddNbIntersections;
349 bool oddNodes =
false;
352 oddNodes ^= (ip.
get_v()*m_PnPolyMultiples[i] + m_PnPolyConstants[i] < ip.
get_u());
367 vpPolygon::precalcValuesPnPoly() {
369 std::cerr <<
"It is not a polygon (_corners.size() < 3)!" << std::endl;
373 m_PnPolyConstants.resize(
_corners.size());
374 m_PnPolyMultiples.resize(
_corners.size());
378 m_PnPolyConstants[i] =
_corners[i].get_u();
379 m_PnPolyMultiples[i] = 0.0;
409 for(
unsigned int i=0; i<
_corners.size(); ++i){
410 unsigned int i_p_1 = ( i+1 ) %
_corners.size();
444 for(
unsigned int i=0; i<(
_corners.size()-1); ++i){
452 for(
unsigned int i=0; i<
_corners.size(); ++i){
453 unsigned int i_p_1 = ( i+1 ) %
_corners.size();
488 std::set<double> setI;
489 std::set<double> setJ;
490 for(
unsigned int i=0; i<
_corners.size(); ++i){
495 std::set<double>::const_iterator iterI = setI.end();
496 std::set<double>::const_iterator iterJ = setJ.end();
519 const unsigned int N = (
unsigned int)
_corners.size();
520 for(
unsigned int i=0; i<N; ++i){
526 vpPolygon::intersect(
const vpImagePoint& p1,
const vpImagePoint& p2,
const double &i_test,
const double &j_test,
const double &i,
const double &j)
530 double ex = j - j_test;
531 double ey = i - i_test;
533 double den = dx * ey - dy * ex;
536 if(std::fabs(den) > std::fabs(den)*std::numeric_limits<double>::epsilon()){
537 t = -( ey * ( p1.
get_j() - j_test ) + ex * ( -p1.
get_i() + i_test ) ) / den;
538 u = -( dx * ( -p1.
get_i() + i_test ) + dy * ( p1.
get_j() - j_test ) ) / den;
543 return ( t >= std::numeric_limits<double>::epsilon() && t < 1.0 && u >= std::numeric_limits<double>::epsilon() && u < 1.0);
568 return ((
unsigned int)
_corners.size());
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Point coordinates conversion from normalized coordinates in meter to pixel coordinates ...
Class to define colors available for display functionnalities.
static bool equal(double x, double y, double s=0.001)
void init(const std::vector< vpImagePoint > &corners)
error that can be emited by ViSP classes.
vpPolygon & operator=(const vpPolygon &poly)
vpRect _bbox
Bounding box containing the polygon.
vpImagePoint _center
Center of the polygon. It is automatically computed when the corners are set.
static void flush(const vpImage< unsigned char > &I)
bool isInside(const vpImagePoint &iP, const PointInPolygonMethod &method=PnPolyRayCasting) const
unsigned int getSize() const
Defines a generic 2D polygon.
void set_i(const double ii)
Generic class defining intrinsic camera parameters.
void setTopLeft(const vpImagePoint &topLeft)
void set_j(const double jj)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
std::vector< vpImagePoint > _corners
Collection of image points containing the corners.
void initClick(const vpImage< unsigned char > &I)
bool _goodPoly
Flag set to true when the polygon is a good polygon (ie. it has more than two corners) or false other...
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Class for generating random numbers with uniform probability density.
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
void setBottomRight(const vpImagePoint &bottomRight)
void buildFrom(const std::vector< vpImagePoint > &corners)
double _area
Area of the polygon.
void display(const vpImage< unsigned char > &I, const vpColor &color, unsigned int thickness=1) const