![]() |
Visual Servoing Platform version 3.7.0
|
#include <vpPolygon.h>
Public Types | |
| enum | PointInPolygonMethod { PnPolySegmentIntersection , PnPolyRayCasting } |
Public Member Functions | |
| vpPolygon () | |
| VP_EXPLICIT | vpPolygon (const std::vector< vpImagePoint > &corners) |
| VP_EXPLICIT | vpPolygon (const std::list< vpImagePoint > &corners) |
| vpPolygon (const vpPolygon &poly) | |
| virtual | ~vpPolygon () |
| vpPolygon & | operator= (const vpPolygon &poly) |
| vpPolygon & | buildFrom (const std::vector< vpImagePoint > &corners, const bool &create_convex_hull=false) |
| vpPolygon & | buildFrom (const std::list< vpImagePoint > &corners, const bool &create_convex_hull=false) |
| vpPolygon & | buildFrom (const std::vector< vpPoint > &corners, const vpCameraParameters &cam, const bool &create_convex_hull=false) |
| unsigned int | getSize () const |
| void | initClick (const vpImage< unsigned char > &I, unsigned int size=5, const vpColor &color=vpColor::red, unsigned int thickness=1) |
| void | initClick (const vpImage< vpRGBa > &I, unsigned int size=5, const vpColor &color=vpColor::red, unsigned int thickness=1) |
| bool | isInside (const vpImagePoint &iP, const PointInPolygonMethod &method=PnPolyRayCasting) const |
| void | display (const vpImage< unsigned char > &I, const vpColor &color, unsigned int thickness=1) const |
| const std::vector< vpImagePoint > & | getCorners () const |
| double | getArea () const |
| vpImagePoint | getCenter () const |
| vpRect | getBoundingBox () const |
Static Public Member Functions | |
| static bool | isInside (const std::vector< vpImagePoint > &roi, const double &i, const double &j, const PointInPolygonMethod &method=PnPolyRayCasting) |
Protected Member Functions | |
| void | init (const std::vector< vpImagePoint > &corners) |
| void | init (const std::list< vpImagePoint > &corners) |
| void | updateArea () |
| void | updateCenter () |
| void | updateBoundingBox () |
Protected Attributes | |
| std::vector< vpImagePoint > | _corners |
| vpImagePoint | _center |
| double | _area |
| bool | _goodPoly |
| vpRect | _bbox |
Defines a generic 2D polygon.
A polygon is internally represented by N 2D points.
By default three coordinates in the
frame (see vpImagePoint class documentation for more details about the frame) are used
,
and
.
The code bellow shows how to manipulate a polygon.
Definition at line 102 of file vpPolygon.h.
| Enumerator | |
|---|---|
| PnPolySegmentIntersection | Legacy Point In Polygon test. |
| PnPolyRayCasting | Point In Polygon test using ray casting method (faster). |
Definition at line 105 of file vpPolygon.h.
| BEGIN_VISP_NAMESPACE vpPolygon::vpPolygon | ( | ) |
Default constructor that creates an empty polygon.
Definition at line 114 of file vpPolygon.cpp.
References _area, _bbox, _center, _corners, and _goodPoly.
Referenced by buildFrom(), buildFrom(), buildFrom(), isInside(), operator=(), and vpPolygon().
| vpPolygon::vpPolygon | ( | const std::vector< vpImagePoint > & | corners | ) |
Constructor which initialises the polygon thanks to the given corners.
| corners | : The Points defining the corners. |
Definition at line 126 of file vpPolygon.cpp.
References _area, _bbox, _center, _corners, _goodPoly, and init().
| vpPolygon::vpPolygon | ( | const std::list< vpImagePoint > & | corners | ) |
Constructor which initialises the polygon thanks to the given corners.
| corners | : The Points defining the corners. |
Definition at line 144 of file vpPolygon.cpp.
References _area, _bbox, _center, _corners, _goodPoly, and init().
| vpPolygon::vpPolygon | ( | const vpPolygon & | poly | ) |
Copy constructor
| poly | : The polygon used for the initialisation. |
Definition at line 159 of file vpPolygon.cpp.
References _area, _bbox, _center, _corners, _goodPoly, and vpPolygon().
|
virtual |
Basic destructor
Definition at line 167 of file vpPolygon.cpp.
| vpPolygon & vpPolygon::buildFrom | ( | const std::list< vpImagePoint > & | corners, |
| const bool & | create_convex_hull = false ) |
Initialises the polygon thanks to the collection of 2D points (in pixel).
| corners | : The corners of the polygon. |
| create_convex_hull | : Create a convex hull from the given corners. |
Definition at line 219 of file vpPolygon.cpp.
References init(), vpException::notImplementedError, and vpPolygon().
| vpPolygon & vpPolygon::buildFrom | ( | const std::vector< vpImagePoint > & | corners, |
| const bool & | create_convex_hull = false ) |
Initialises the triangle thanks to the collection of 2D points (in pixel).
| corners | : The corners of the polygon. |
| create_convex_hull | : Create a convex hull from the given corners. |
Definition at line 195 of file vpPolygon.cpp.
References init(), vpException::notImplementedError, and vpPolygon().
Referenced by buildFrom(), initClick(), initClick(), vpMbtDistanceKltCylinder::updateMask(), and vpMbtDistanceKltPoints::updateMask().
| vpPolygon & vpPolygon::buildFrom | ( | const std::vector< vpPoint > & | corners, |
| const vpCameraParameters & | cam, | ||
| const bool & | create_convex_hull = false ) |
Initialises the triangle thanks to the collection of 2D points (in meter). The fields x and y are used to compute the corresponding coordinates in pixel thanks to the camera parameters cam.
| corners | : The corners of the polygon. |
| cam | : The camera parameters used to convert the coordinates from meter to pixel. |
| create_convex_hull | : Create a convex hull from the given corners. |
Definition at line 246 of file vpPolygon.cpp.
References buildFrom(), vpMeterPixelConversion::convertPoint(), and vpPolygon().
| void vpPolygon::display | ( | const vpImage< unsigned char > & | I, |
| const vpColor & | color, | ||
| unsigned int | thickness = 1 ) const |
Display the polygon in the image (overlay, so the image is not modified). A call to the flush() method is necessary.
| I | : The image where the polygon is displayed. |
| color | : The color of the polygon's lines. |
| thickness | : The thickness of the polygon's lines. |
Definition at line 617 of file vpPolygon.cpp.
References _corners, and vpDisplay::displayLine().
|
inline |
Return the area of the polygon. The area is computed when the polygon is built from the corners.
Definition at line 148 of file vpPolygon.h.
References _area.
Referenced by vpPose::computePlanarObjectPoseFromRGBD(), vpPose::computePlanarObjectPoseFromRGBD(), vpMbtPolygon::isVisible(), vpMbtDistanceKltCylinder::updateMask(), and vpMbtDistanceKltPoints::updateMask().
|
inline |
Return the bounding box. The bounding box is the smallest rectangle containing all the polygon.
Definition at line 164 of file vpPolygon.h.
References _bbox.
Referenced by vpMbtFaceDepthDense::computeDesiredFeatures(), vpMbtFaceDepthDense::computeDesiredFeatures(), vpMbtFaceDepthDense::computeDesiredFeatures(), vpMbtFaceDepthNormal::computeDesiredFeatures(), vpMbtFaceDepthNormal::computeDesiredFeatures(), vpMbtFaceDepthNormal::computeDesiredFeatures(), vpPose::computePlanarObjectPoseFromRGBD(), vpPose::computePlanarObjectPoseFromRGBD(), vpKeyPoint::matchPointAndDetect(), and vpKeyPoint::matchPointAndDetect().
|
inline |
Return the center of the polygon. The center is computed when the polygon is built from the corners.
Definition at line 156 of file vpPolygon.h.
References _center.
|
inline |
Get the corners of the polygon.
Definition at line 140 of file vpPolygon.h.
References _corners.
| unsigned int vpPolygon::getSize | ( | ) | const |
Return number of corners belonging to the polygon.
Definition at line 646 of file vpPolygon.cpp.
References _corners.
|
protected |
Initialises the polygon using the collection of image points. This method computes some internal variables such as center, area, ...
| corners | : The corners of the polygon. |
Definition at line 344 of file vpPolygon.cpp.
References _corners, updateArea(), updateBoundingBox(), and updateCenter().
|
protected |
Initialises the polygon using the collection of image points. This method computes some internal variables such as center, area, ...
| corners | : The corners of the polygon. |
Definition at line 324 of file vpPolygon.cpp.
References _corners, updateArea(), updateBoundingBox(), and updateCenter().
Referenced by buildFrom(), buildFrom(), vpPolygon(), and vpPolygon().
| void vpPolygon::initClick | ( | const vpImage< unsigned char > & | I, |
| unsigned int | size = 5, | ||
| const vpColor & | color = vpColor::red, | ||
| unsigned int | thickness = 1 ) |
Initialises the polygon by (left-)clicking to add a corners to the polygon. A right click is used to stop the addition of new corners.
| I | : The image where to click to initialise the corners. |
| size | : Cross size in terms of number of pixels that is displayed over a polygon corner. |
| color | : Color used to display the cross over the polygon corner. |
| thickness | : Thickness used to display the cross. |
Definition at line 267 of file vpPolygon.cpp.
References buildFrom(), vpMouseButton::button1, vpDisplay::displayCross(), vpDisplay::flush(), and vpDisplay::getClick().
| void vpPolygon::initClick | ( | const vpImage< vpRGBa > & | I, |
| unsigned int | size = 5, | ||
| const vpColor & | color = vpColor::red, | ||
| unsigned int | thickness = 1 ) |
Initialises the polygon by (left-)clicking to add a corners to the polygon. A right click is used to stop the addition of new corners.
| I | : The image where to click to initialise the corners. |
| size | : Size of the cross in terms of number of pixels that is displayed over a polygon corner. |
| color | : Color used to display the cross over the polygon corner. |
| thickness | : Thickness used to display the cross. |
Definition at line 296 of file vpPolygon.cpp.
References buildFrom(), vpMouseButton::button1, vpDisplay::displayCross(), vpDisplay::flush(), and vpDisplay::getClick().
|
static |
Test if an image point is inside a 2D polygon.
| roi | : List of the polygon corners. |
| i | : i-coordinate of the image point to test. |
| j | : j-coordinate of the image point to test. |
| method | : Method to use for Point In Polygon test. |
Definition at line 636 of file vpPolygon.cpp.
References isInside(), and vpPolygon().
| bool vpPolygon::isInside | ( | const vpImagePoint & | ip, |
| const PointInPolygonMethod & | method = PnPolyRayCasting ) const |
Check if the 2D point
is inside the polygon.
| ip | : The point which have to be tested. |
| method | : Method to use for Point In Polygon test. |
Definition at line 402 of file vpPolygon.cpp.
References _corners, vpImagePoint::get_i(), vpImagePoint::get_j(), vpImagePoint::get_u(), vpImagePoint::get_v(), isInside(), PnPolySegmentIntersection, vpImagePoint::set_i(), and vpImagePoint::set_j().
Referenced by vpKeyPoint::compute3DForPointsOnCylinders(), vpKeyPoint::compute3DForPointsOnCylinders(), vpMbtFaceDepthDense::computeDesiredFeatures(), vpMbtFaceDepthDense::computeDesiredFeatures(), vpMbtFaceDepthDense::computeDesiredFeatures(), vpMbtFaceDepthNormal::computeDesiredFeatures(), vpMbtFaceDepthNormal::computeDesiredFeatures(), vpMbtFaceDepthNormal::computeDesiredFeatures(), vpPose::computePlanarObjectPoseFromRGBD(), vpPose::computePlanarObjectPoseFromRGBD(), vpMbtDistanceKltCylinder::init(), vpMbtDistanceKltPoints::init(), isInside(), isInside(), vpMbtDistanceKltCylinder::updateMask(), and vpMbtDistanceKltPoints::updateMask().
Equal operator.
Assign poly to this polygon and return a reference to it.
Definition at line 174 of file vpPolygon.cpp.
References _area, _bbox, _center, _corners, _goodPoly, and vpPolygon().
|
protected |
|
protected |
Update bounding box of the polygon.
Definition at line 579 of file vpPolygon.cpp.
|
protected |
|
protected |
Area of the polygon.
Definition at line 186 of file vpPolygon.h.
Referenced by getArea(), operator=(), updateArea(), updateCenter(), vpPolygon(), vpPolygon(), vpPolygon(), and vpPolygon().
|
protected |
Bounding box containing the polygon.
Definition at line 191 of file vpPolygon.h.
Referenced by getBoundingBox(), operator=(), updateBoundingBox(), vpPolygon(), vpPolygon(), vpPolygon(), and vpPolygon().
|
protected |
Center of the polygon. It is automatically computed when the corners are set.
Definition at line 184 of file vpPolygon.h.
Referenced by getCenter(), operator=(), updateCenter(), vpPolygon(), vpPolygon(), vpPolygon(), and vpPolygon().
|
protected |
Collection of image points containing the corners.
Definition at line 181 of file vpPolygon.h.
Referenced by display(), getCorners(), getSize(), init(), init(), isInside(), operator=(), updateArea(), updateBoundingBox(), updateCenter(), vpPolygon(), vpPolygon(), vpPolygon(), and vpPolygon().
|
protected |
Flag set to true when the polygon is a good polygon (ie. it has more than two corners) or false otherwise.
Definition at line 189 of file vpPolygon.h.
Referenced by operator=(), updateArea(), updateBoundingBox(), updateCenter(), vpPolygon(), vpPolygon(), vpPolygon(), and vpPolygon().