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> 52 : _corners(), _center(), _area(0.), _goodPoly(true), _bbox(), m_PnPolyConstants(), m_PnPolyMultiples()
67 if (corners.size() < 3) {
84 if (corners.size() < 3) {
97 m_PnPolyConstants(poly.m_PnPolyConstants), m_PnPolyMultiples(poly.m_PnPolyMultiples)
118 m_PnPolyConstants = poly.m_PnPolyConstants;
119 m_PnPolyMultiples = poly.m_PnPolyMultiples;
157 std::vector<vpImagePoint> ipCorners(corners.size());
158 for (
unsigned int i = 0; i < corners.size(); ++i) {
174 unsigned int thickness)
179 std::vector<vpImagePoint> cornersClick;
185 cornersClick.push_back(ip);
208 std::vector<vpImagePoint> cornersClick;
214 cornersClick.push_back(ip);
239 precalcValuesPnPoly();
259 precalcValuesPnPoly();
282 double denominator = di1 * dj2 - dj1 * di2;
284 if (fabs(denominator) < std::numeric_limits<double>::epsilon()) {
288 double alpha = -((ip1.
get_i() - ip3.
get_i()) * dj2 + di2 * (ip3.
get_j() - ip1.
get_j())) / denominator;
289 if (alpha < 0 || alpha >= 1) {
293 double beta = -(di1 * (ip3.
get_j() - ip1.
get_j()) + dj1 * (ip1.
get_i() - ip3.
get_i())) / denominator;
294 if (beta < 0 || beta >= 1) {
320 infPoint.
set_i(infPoint.
get_i() + 1000 * generator());
321 infPoint.
set_j(infPoint.
get_j() + 1000 * generator());
327 bool oddNbIntersections =
false;
328 for (
unsigned int i = 0; i <
_corners.size(); ++i) {
331 bool intersection =
false;
339 intersection = testIntersectionSegments(ip1, ip2, ip, infPoint);
345 oddNbIntersections = !oddNbIntersections;
349 test = oddNbIntersections;
355 bool oddNodes =
false;
359 oddNodes ^= (ip.
get_v() * m_PnPolyMultiples[i] + m_PnPolyConstants[i] < ip.
get_u());
372 void vpPolygon::precalcValuesPnPoly()
378 m_PnPolyConstants.resize(
_corners.size());
379 m_PnPolyMultiples.resize(
_corners.size());
383 m_PnPolyConstants[i] =
_corners[i].get_u();
384 m_PnPolyMultiples[i] = 0.0;
386 m_PnPolyConstants[i] =
_corners[i].get_u() -
414 for (
unsigned int i = 0; i <
_corners.size(); ++i) {
415 unsigned int i_p_1 = (i + 1) %
_corners.size();
446 for(
unsigned int i=0; i<(
_corners.size()-1); ++i){
454 for (
unsigned int i = 0; i <
_corners.size(); ++i) {
455 unsigned int i_p_1 = (i + 1) %
_corners.size();
487 std::set<double> setI;
488 std::set<double> setJ;
489 for (
unsigned int i = 0; i <
_corners.size(); ++i) {
494 std::set<double>::const_iterator iterI = setI.end();
495 std::set<double>::const_iterator iterJ = setJ.end();
517 const unsigned int N = (
unsigned int)
_corners.size();
518 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)
Class to define RGB 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 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)
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, bool segment=true)
void setBottomRight(const vpImagePoint &bottomRight)
void buildFrom(const std::vector< vpImagePoint > &corners)
double _area
Area of the polygon.