last update 20 Sep 2009 |
#include <cvrPolygonPoints.h>
Public Member Functions | |
polygonPoints () | |
polygonPoints (const polygonPoints< T > &other) | |
virtual | ~polygonPoints () |
const std::string & | name () const |
polygonPoints< T > & | castFrom (const borderPoints &theBorderPoints, const int minLength=-1, const double maxDistance=1.0, const bool closed=true, const bool searchMaxDist=false) |
polygonPoints< T > & | castFrom (const ioPoints &thePointList) |
polygonPoints< T > & | castFrom (const pointList< T > &thePointList) |
polygonPoints< T > & | operator= (const polygonPoints< T > &other) |
T | areaX2 () const |
bool | clockwise () const |
polygonPoints< T > & | approximate (const borderPoints &theBorderPoints, const int minStep=-1, const double maxDistance=1, const bool closed=false, const bool searchMaxDist=false) |
polygonPoints< T > & | approximate (const borderPoints &theBorderPoints, const ipointList &forcedVertices, const int minStep=-1, const double maxDistance=1, const bool closed=false, const bool searchMaxDist=false) |
void | invert () |
Protected Member Functions | |
void | fitAndSplit (const vector< ipoint > &vct, const int idx1, const int idx2, const double maxDistance, vector< ubyte > &flags) |
For the explanation of the contour description in this class, see following image:
-- 00000000001111111111222222222233 -- 01234567890123456789012345678901 00 -------------------------------- 01 -------------------------------- 02 -------------------------------- 03 --------Xooo-------Soo---------- 04 -------o++++Xoo----E++o--------- 05 -------o+++++++X---o+++X-------- 06 ------X+++++++o-----o+o--------- 07 -------o+++++++XoooX++o--------- 08 ---------X++++++++++++X--------- 09 --------o+++++++++++++++o------- 10 --------o+++++++++++++++o------- 11 -------X++++++++++++++Xo-------- 12 ------o++++++++++++++o---------- 13 ------o++++++++++++++oX--------- 14 -----X++++++++++++++++++o------- 15 -----o+++++++++++++++++++o------ 16 ----o+++++++++++++++++++Xo------ 17 ---X++++++++++++++++++oo-------- 18 ----ooooooooX++++++++X---------- 19 -------------oooooXoo----------- 20 -------------------------------- 21 -------------------------------- 22 -------------------------------- 23 --------------------------------
"-" means the background, "+" represents the inner part of the object, "o" indicates a borderPoint, "X" is a polygonPoint, the borderPoint "S" is start point of the polygonPointList and "E" the end point of the list.
This class cast given borderPoints into a polygon. The polygon has usually less points than the borderPoints, and thus it saves memory. The disadvantage is that you loose details of the object when you do the cast. Two parameters minLength and maxDistance control the number of points of the resulting polygon.
Between two points in the polygon there must be more than minLength points of the borderPoints, and the polygon must be closer to the borderPoints as maxDistance.
It is also possible to get the convex hull of a set of points (given in a pointList or in an ioPoints list) calling the respective castFrom() methods.
cvr::polygonPoints< T >::polygonPoints | ( | ) |
default constructor creates an empty border-point-list
cvr::polygonPoints< T >::polygonPoints | ( | const polygonPoints< T > & | other | ) |
virtual cvr::polygonPoints< T >::~polygonPoints | ( | ) | [virtual] |
destructor
polygonPoints<T>& cvr::polygonPoints< T >::approximate | ( | const borderPoints & | theBorderPoints, | |
const ipointList & | forcedVertices, | |||
const int | minStep = -1 , |
|||
const double | maxDistance = 1 , |
|||
const bool | closed = false , |
|||
const bool | searchMaxDist = false | |||
) |
Approximate the given border points as a polygon, but ensure that the given points are vertices.
The given list of points must fulfill following two conditions:
If one of these condition is not met, the algorithm will take too much time trying to figure out what happend and to recover.
The first condition ensures an efficient search for the vertices in the border points list.
At the end of the approximation process this polygon-points-list contains the coordinates of the vertices.
theBorderPoints | list with the border points to be approximated with a polygon. The elements of this list must be adjacent. | |
forcedVertices | list of vertices that must be included in the polygon representation. This list must be a subset and respect the same ordering as in theBorderPoints | |
minStep | minimal "distance" between vertices of the polygon. (if 0 or negative, only the maxDistance parameter will be considered). The "distance" used here is NOT the euclidean distance between the vertices but the number of elements between both vertices in the border list. These is usually therefore a city-block distance or a 8-neighborhood distance depending on the border points description used. | |
maxDistance | specify the maximal allowed euclidean distance between the border points and the approximated polygon. (if negative, each "minLength" pixel of the border points will be taken). | |
closed | if true (default), only the found vertices will be in the list. If false, the last point of the list will be adjacent to the first point in the list. | |
searchMaxDist | if true, the first two vertices will be computed as the two points in the border with the maximal distance. If false, the first point in the list will be a vertex and the border point with the maximal distance to it too. This faster method is the default. It provides usually good results. |
polygonPoints<T>& cvr::polygonPoints< T >::approximate | ( | const borderPoints & | theBorderPoints, | |
const int | minStep = -1 , |
|||
const double | maxDistance = 1 , |
|||
const bool | closed = false , |
|||
const bool | searchMaxDist = false | |||
) |
Approximate the given border points as a polygon.
At the end of the approximation process this polygon-points-list contains the coordinates of the vertices.
theBorderPoints | list with the border points to be approximated with a polygon. The elements of this list must be adjacent. | |
minStep | minimal "distance" between vertices of the polygon. (if 0 or negative, only the maxDistance parameter will be considered). The "distance" used here is NOT the euclidean distance between the vertices but the number of elements between both vertices in the border list. These is usually therefore a city-block distance or a 8-neighborhood distance depending on the border points description used. | |
maxDistance | specify the maximal allowed euclidean distance between the border points and the approximated polygon. (if negative, each "minLength" pixel of the border points will be taken). | |
closed | if true (default), only the found vertices will be in the list. If false, the last point of the list will be adjacent to the first point in the list. | |
searchMaxDist | if true, the first two vertices will be computed as the two points in the border with the maximal distance. If false, the first point in the list will be a vertex and the border point with the maximal distance to it too. This faster method is the default. It provides usually good results. |
T cvr::polygonPoints< T >::areaX2 | ( | ) | const |
Compute the 2 x area of this polygon.
The reason to return twice the area and not the area itself is very simple: For integer point types, twice the area is always an integer value, but the area itself is not.
If the area is positive, the polygon has a clockwise direction. Otherwise it will be negative.
polygonPoints<T>& cvr::polygonPoints< T >::castFrom | ( | const pointList< T > & | thePointList | ) |
This is an alias for computeConvexHull().
polygonPoints<T>& cvr::polygonPoints< T >::castFrom | ( | const ioPoints & | thePointList | ) |
polygonPoints<T>& cvr::polygonPoints< T >::castFrom | ( | const borderPoints & | theBorderPoints, | |
const int | minLength = -1 , |
|||
const double | maxDistance = 1.0 , |
|||
const bool | closed = true , |
|||
const bool | searchMaxDist = false | |||
) |
alias for approximate()
bool cvr::polygonPoints< T >::clockwise | ( | ) | const |
Compute if this polygon has a clockwise direction or not.
void cvr::polygonPoints< T >::fitAndSplit | ( | const vector< ipoint > & | vct, | |
const int | idx1, | |||
const int | idx2, | |||
const double | maxDistance, | |||
vector< ubyte > & | flags | |||
) | [protected] |
Used in the approximation of a border points with a polygon.
Implements the Ramer (or Duda Hart) method. See also Haralick and Shapiro. Computer and Robot Vision vol. 1 Addison Wesley, 1992. pp. 563ff
vct | set of vertices of the polygon | |
idx1 | initial index | |
idx2 | final index | |
maxDistance | maximum allowed distance | |
flags | flags for the points. |
void cvr::polygonPoints< T >::invert | ( | ) |
invert the direction of the polygon points
const std::string& cvr::polygonPoints< T >::name | ( | ) | const [virtual] |
polygonPoints<T>& cvr::polygonPoints< T >::operator= | ( | const polygonPoints< T > & | other | ) | [inline] |