ViSP
2.8.0
|
#include <vpPolygon.h>
Public Member Functions | |
vpPolygon () | |
vpPolygon (const std::vector< vpImagePoint > &corners) | |
vpPolygon (const vpPolygon &poly) | |
virtual | ~vpPolygon () |
vpPolygon & | operator= (const vpPolygon &poly) |
void | buildFrom (const std::vector< vpImagePoint > &corners) |
void | buildFrom (const std::vector< vpPoint > &corners, const vpCameraParameters &cam) |
void | initClick (const vpImage< unsigned char > &I) |
bool | isInside (const vpImagePoint &iP) |
void | display (const vpImage< unsigned char > &I, const vpColor &color, unsigned int thickness=1) |
const std::vector< vpImagePoint > & | getCorners () const |
double | getArea () const |
vpImagePoint | getCenter () const |
vpRect | getBoundingBox () const |
Protected Member Functions | |
void | init (const std::vector< 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.
vpPolygon::vpPolygon | ( | ) |
Basic constructor.
By default, it defines a triangle with the three 2D points coordinates : , and .
Definition at line 59 of file vpPolygon.cpp.
vpPolygon::vpPolygon | ( | const std::vector< vpImagePoint > & | corners | ) |
Constructor which initialise the polygon thanks to the given corners.
corners | : The Points defining the corners. |
Definition at line 76 of file vpPolygon.cpp.
vpPolygon::vpPolygon | ( | const vpPolygon & | poly | ) |
|
virtual |
Basic destructor
Definition at line 100 of file vpPolygon.cpp.
void vpPolygon::buildFrom | ( | const std::vector< vpImagePoint > & | corners | ) |
Initialise the triangle thanks to the collection of 2D points (in pixel).
corners | : The corners of the polyon. |
Definition at line 127 of file vpPolygon.cpp.
References init().
Referenced by buildFrom(), and initClick().
void vpPolygon::buildFrom | ( | const std::vector< vpPoint > & | corners, |
const vpCameraParameters & | cam | ||
) |
Initialise 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 polyon. |
cam | : The camera parameters used to convert the coordinates from meter to pixel. |
Definition at line 144 of file vpPolygon.cpp.
References buildFrom(), and vpMeterPixelConversion::convertPoint().
void vpPolygon::display | ( | const vpImage< unsigned char > & | I, |
const vpColor & | color, | ||
unsigned int | thickness = 1 |
||
) |
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 is displayed the polygon. |
color | : The color of the lines of the polygon. |
thickness | : The thickness of the lines used to display the polygon. |
Definition at line 403 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.
|
inline |
Return the bounding box. The bounding box is the smallest rectangle containing all the polygon.
Definition at line 168 of file vpPolygon.h.
|
inline |
Return the center of the polygon. The center is computed when the polygon is built from the corners.
Definition at line 158 of file vpPolygon.h.
|
inline |
Get the corners of the polygon.
Definition at line 137 of file vpPolygon.h.
|
protected |
Intialise the polygon using the collection of image points. This method compute come internal variables such as center, area, ...
corners | : The corners of the polyon. |
Definition at line 189 of file vpPolygon.cpp.
References _corners, updateArea(), updateBoundingBox(), and updateCenter().
Referenced by buildFrom(), and vpPolygon().
void vpPolygon::initClick | ( | const vpImage< unsigned char > & | I | ) |
Initialise the polygon by (left-)clicking to add a corners to the polygon. A right click is used to stop the addition of new corner.
I | : The image where to click to initialise the corners. |
Definition at line 160 of file vpPolygon.cpp.
References buildFrom(), vpMouseButton::button1, vpDisplay::displayCross(), vpDisplay::flush(), vpDisplay::getClick(), and vpColor::red.
bool vpPolygon::isInside | ( | const vpImagePoint & | ip | ) |
Check if the 2D point is inside the polygon.
ip | : The point which have to be tested. |
Definition at line 247 of file vpPolygon.cpp.
References _corners, vpImagePoint::get_i(), vpImagePoint::get_j(), vpImagePoint::set_i(), and vpImagePoint::set_j().
|
protected |
|
protected |
Definition at line 365 of file vpPolygon.cpp.
References _bbox, _corners, _goodPoly, vpRect::setBottomRight(), and vpRect::setTopLeft().
Referenced by init().
|
protected |
Update the _center attribute of the polygon using the corners.
The i coordinates is computed using:
The computation of the j coordinate is similar.
Definition at line 325 of file vpPolygon.cpp.
References _area, _center, _corners, _goodPoly, vpImagePoint::set_i(), and vpImagePoint::set_j().
Referenced by init().
|
protected |
Area of the polygon.
Definition at line 110 of file vpPolygon.h.
Referenced by operator=(), updateArea(), updateCenter(), and vpPolygon().
|
protected |
Boumding box containing the polygon.
Definition at line 114 of file vpPolygon.h.
Referenced by updateBoundingBox().
|
protected |
Center of the polygon. It is automatically computed when the corners are set.
Definition at line 108 of file vpPolygon.h.
Referenced by operator=(), updateCenter(), and vpPolygon().
|
protected |
Collection of image points containing the corners.
Definition at line 106 of file vpPolygon.h.
Referenced by display(), init(), isInside(), operator=(), updateArea(), updateBoundingBox(), updateCenter(), and vpPolygon().
|
protected |
Flag to indicate whether the polygon is a good polygon (ie. it has more than two corners, ...)
Definition at line 112 of file vpPolygon.h.
Referenced by operator=(), updateArea(), updateBoundingBox(), updateCenter(), and vpPolygon().