46 #include <visp/vpPolygon.h>
47 #include <visp/vpException.h>
48 #include <visp/vpDisplay.h>
49 #include <visp/vpMeterPixelConversion.h>
50 #include <visp/vpNoise.h>
60 : _corners(), _center(), _area(0.), _goodPoly(true), _bbox()
62 std::vector<vpImagePoint> corners;
77 : _corners(), _center(), _area(0.), _goodPoly(true), _bbox()
79 if(corners.size() < 3){
91 : _corners(), _center(), _area(0.), _goodPoly(true), _bbox()
149 std::vector<vpImagePoint> ipCorners(corners.size());
150 for(
unsigned int i=0; i<corners.size(); ++i){
168 std::vector<vpImagePoint> cornersClick;
174 cornersClick.push_back(ip);
223 double denominator = di1 * dj2 - dj1 * di2;
225 if(fabs(denominator) < std::numeric_limits<double>::epsilon()){
229 double alpha = - ( ( ip1.
get_i() - ip3.
get_i() ) * dj2 + di2 * ( ip3.
get_j() - ip1.
get_j())) / denominator;
230 if(alpha < 0 || alpha >= 1){
234 double beta = - (di1 * (ip3.
get_j() - ip1.
get_j() ) + dj1 * (ip1.
get_i() - ip3.
get_i()) ) / denominator;
235 if(beta < 0 || beta >= 1){
254 infPoint.
set_i( infPoint.
get_i() + 1000 * generator());
255 infPoint.
set_j( infPoint.
get_j() + 1000 * generator());
257 unsigned int nbinterscetion = 0;
258 for(
unsigned int i=0; i<
_corners.size(); ++i){
261 bool intersection =
false;
269 intersection = testIntersectionSegments(ip1, ip2, ip, infPoint );
279 return ((nbinterscetion%2)==1);
303 for(
unsigned int i=0; i<
_corners.size(); ++i){
304 unsigned int i_p_1 = ( i+1 ) %
_corners.size();
338 for(
unsigned int i=0; i<(
_corners.size()-1); ++i){
346 for(
unsigned int i=0; i<
_corners.size(); ++i){
347 unsigned int i_p_1 = ( i+1 ) %
_corners.size();
377 std::set<double> setI;
378 std::set<double> setJ;
379 for(
unsigned int i=0; i<
_corners.size(); ++i){
384 std::set<double>::const_iterator iterI = setI.end();
385 std::set<double>::const_iterator iterJ = setJ.end();
408 const unsigned int N = (
unsigned int)
_corners.size();
409 for(
unsigned int i=0; i<N; ++i){
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)
void display(const vpImage< unsigned char > &I, const vpColor &color, unsigned int thickness=1)
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.