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()
58 std::vector<vpImagePoint> corners;
73 : _corners(), _center(), _area(0.), _goodPoly(true), _bbox()
75 if(corners.size() < 3){
87 : _corners(), _center(), _area(0.), _goodPoly(true), _bbox()
145 std::vector<vpImagePoint> ipCorners(corners.size());
146 for(
unsigned int i=0; i<corners.size(); ++i){
164 std::vector<vpImagePoint> cornersClick;
170 cornersClick.push_back(ip);
219 double denominator = di1 * dj2 - dj1 * di2;
221 if(fabs(denominator) < std::numeric_limits<double>::epsilon()){
225 double alpha = - ( ( ip1.
get_i() - ip3.
get_i() ) * dj2 + di2 * ( ip3.
get_j() - ip1.
get_j())) / denominator;
226 if(alpha < 0 || alpha >= 1){
230 double beta = - (di1 * (ip3.
get_j() - ip1.
get_j() ) + dj1 * (ip1.
get_i() - ip3.
get_i()) ) / denominator;
231 if(beta < 0 || beta >= 1){
250 infPoint.
set_i( infPoint.
get_i() + 1000 * generator());
251 infPoint.
set_j( infPoint.
get_j() + 1000 * generator());
253 unsigned int nbinterscetion = 0;
254 for(
unsigned int i=0; i<
_corners.size(); ++i){
257 bool intersection =
false;
265 intersection = testIntersectionSegments(ip1, ip2, ip, infPoint );
275 return ((nbinterscetion%2)==1);
299 for(
unsigned int i=0; i<
_corners.size(); ++i){
300 unsigned int i_p_1 = ( i+1 ) %
_corners.size();
334 for(
unsigned int i=0; i<(
_corners.size()-1); ++i){
342 for(
unsigned int i=0; i<
_corners.size(); ++i){
343 unsigned int i_p_1 = ( i+1 ) %
_corners.size();
373 std::set<double> setI;
374 std::set<double> setJ;
375 for(
unsigned int i=0; i<
_corners.size(); ++i){
380 std::set<double>::const_iterator iterI = setI.end();
381 std::set<double>::const_iterator iterJ = setJ.end();
404 const unsigned int N = (
unsigned int)
_corners.size();
405 for(
unsigned int i=0; i<N; ++i){
411 vpPolygon::intersect(
const vpImagePoint& p1,
const vpImagePoint& p2,
const double &i_test,
const double &j_test,
const double &i,
const double &j)
415 double ex = j - j_test;
416 double ey = i - i_test;
418 double den = dx * ey - dy * ex;
421 if(std::fabs(den) > std::fabs(den)*std::numeric_limits<double>::epsilon()){
422 t = -( ey * ( p1.
get_j() - j_test ) + ex * ( -p1.
get_i() + i_test ) ) / den;
423 u = -( dx * ( -p1.
get_i() + i_test ) + dy * ( p1.
get_j() - j_test ) ) / den;
428 return ( t >= std::numeric_limits<double>::epsilon() && t < 1.0 && u >= std::numeric_limits<double>::epsilon() && u < 1.0);
443 double i_test = 100000.;
444 double j_test = 100000.;
445 unsigned int nbInter = 0;
446 bool computeAgain =
true;
449 computeAgain =
false;
450 for(
unsigned int k=0; k< roi.size(); k++){
452 if(vpPolygon::intersect(roi[k], roi[(k+1)%roi.size()], i, j, i_test, j_test)){
468 return ((nbInter%2) == 1);
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.
void init(const std::vector< vpImagePoint > &corners)
error that can be emited by ViSP classes.
vpPolygon & operator=(const vpPolygon &poly)
vpRect _bbox
Boumding 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)
Defines a generic 2D polygon.
void set_i(const double ii)
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
Generic class defining intrinsic camera parameters.
void setTopLeft(const vpImagePoint &topLeft)
void set_j(const double jj)
std::vector< vpImagePoint > _corners
Collection of image points containing the corners.
void initClick(const vpImage< unsigned char > &I)
bool _goodPoly
Flag to indicate whether the polygon is a good polygon (ie. it has more than two corners, ...)
virtual bool getClick(bool blocking=true)=0
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.
virtual void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)=0
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