43 #include <visp3/core/vpDisplay.h> 44 #include <visp3/core/vpException.h> 45 #include <visp3/core/vpMeterPixelConversion.h> 46 #include <visp3/core/vpPolygon.h> 47 #include <visp3/core/vpUniRand.h> 55 : _corners(), _center(), _area(0.), _goodPoly(true), _bbox(), m_PnPolyConstants(), m_PnPolyMultiples()
57 std::vector<vpImagePoint> corners;
75 if (corners.size() < 3) {
92 if (corners.size() < 3) {
105 m_PnPolyConstants(poly.m_PnPolyConstants), m_PnPolyMultiples(poly.m_PnPolyMultiples)
126 m_PnPolyConstants = poly.m_PnPolyConstants;
127 m_PnPolyMultiples = poly.m_PnPolyMultiples;
165 std::vector<vpImagePoint> ipCorners(corners.size());
166 for (
unsigned int i = 0; i < corners.size(); ++i) {
182 unsigned int thickness)
187 std::vector<vpImagePoint> cornersClick;
193 cornersClick.push_back(ip);
216 std::vector<vpImagePoint> cornersClick;
222 cornersClick.push_back(ip);
247 precalcValuesPnPoly();
267 precalcValuesPnPoly();
290 double denominator = di1 * dj2 - dj1 * di2;
292 if (fabs(denominator) < std::numeric_limits<double>::epsilon()) {
296 double alpha = -((ip1.
get_i() - ip3.
get_i()) * dj2 + di2 * (ip3.
get_j() - ip1.
get_j())) / denominator;
297 if (alpha < 0 || alpha >= 1) {
301 double beta = -(di1 * (ip3.
get_j() - ip1.
get_j()) + dj1 * (ip1.
get_i() - ip3.
get_i())) / denominator;
302 if (beta < 0 || beta >= 1) {
328 infPoint.
set_i(infPoint.
get_i() + 1000 * generator());
329 infPoint.
set_j(infPoint.
get_j() + 1000 * generator());
335 bool oddNbIntersections =
false;
336 for (
unsigned int i = 0; i <
_corners.size(); ++i) {
339 bool intersection =
false;
347 intersection = testIntersectionSegments(ip1, ip2, ip, infPoint);
353 oddNbIntersections = !oddNbIntersections;
357 test = oddNbIntersections;
363 bool oddNodes =
false;
367 oddNodes ^= (ip.
get_v() * m_PnPolyMultiples[i] + m_PnPolyConstants[i] < ip.
get_u());
380 void vpPolygon::precalcValuesPnPoly()
386 m_PnPolyConstants.resize(
_corners.size());
387 m_PnPolyMultiples.resize(
_corners.size());
391 m_PnPolyConstants[i] =
_corners[i].get_u();
392 m_PnPolyMultiples[i] = 0.0;
394 m_PnPolyConstants[i] =
_corners[i].get_u() -
422 for (
unsigned int i = 0; i <
_corners.size(); ++i) {
423 unsigned int i_p_1 = (i + 1) %
_corners.size();
454 for(
unsigned int i=0; i<(
_corners.size()-1); ++i){
462 for (
unsigned int i = 0; i <
_corners.size(); ++i) {
463 unsigned int i_p_1 = (i + 1) %
_corners.size();
495 std::set<double> setI;
496 std::set<double> setJ;
497 for (
unsigned int i = 0; i <
_corners.size(); ++i) {
502 std::set<double>::const_iterator iterI = setI.end();
503 std::set<double>::const_iterator iterJ = setJ.end();
525 const unsigned int N = (
unsigned int)
_corners.size();
526 for (
unsigned int i = 0; i < N; ++i) {
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)
unsigned int getSize() const
vpRect _bbox
Bounding box containing the polygon.
void display(const vpImage< unsigned char > &I, const vpColor &color, unsigned int thickness=1) const
static void flush(const vpImage< unsigned char > &I)
Defines a generic 2D polygon.
void set_i(const double ii)
void initClick(const vpImage< unsigned char > &I, unsigned int size=5, const vpColor &color=vpColor::red, unsigned int thickness=1)
bool isInside(const vpImagePoint &iP, const PointInPolygonMethod &method=PnPolyRayCasting) const
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.
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.