latest version v1.9 - last update 10 Apr 2010 |
Contour classes: polygonPoints. More...
#include <ltiPolygonPoints.h>
Public Member Functions | |
tpolygonPoints () | |
tpolygonPoints (const tpolygonPoints< T > &other) | |
virtual | ~tpolygonPoints () |
const char * | getTypeName () const |
tpolygonPoints< T > & | castFrom (const borderPoints &theBorderPoints, const int minLength=-1, const double maxDistance=1.0, const bool closed=true, const bool searchMaxDist=false) |
tpolygonPoints< T > & | castFrom (const ioPoints &thePointList) |
tpolygonPoints< T > & | castFrom (const tpointList< T > &thePointList) |
tpolygonPoints< T > & | operator= (const tpolygonPoints< T > &other) |
T | areaX2 () const |
bool | clockwise () const |
tpolygonPoints< T > & | convexHullFrom (const tpointList< T > &thePointList) |
tpolygonPoints< T > & | approximate (const borderPoints &theBorderPoints, const int minStep=-1, const double maxDistance=1, const bool closed=false, const bool searchMaxDist=false) |
tpolygonPoints< T > & | approximate (const borderPoints &theBorderPoints, const pointList &forcedVertices, const int minStep=-1, const double maxDistance=1, const bool closed=false, const bool searchMaxDist=false) |
void | invert () |
tpolygonPoints< T > & | clipPoly (const tpolygonPoints< T > &polygon1, const tpolygonPoints< T > &polygon2, const int &minLength=4, const double &maxDistance=0.8) |
Protected Member Functions | |
void | fitAndSplit (const vector< point > &vct, const int idx1, const int idx2, const double maxDistance, vector< ubyte > &flags) |
Contour classes: polygonPoints.
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.
lti::tpolygonPoints< T >::tpolygonPoints | ( | ) |
default constructor creates an empty border-point-list
lti::tpolygonPoints< T >::tpolygonPoints | ( | const tpolygonPoints< T > & | other | ) |
create this pointList as a copy of another pointList
other | the pointList to be copied. |
virtual lti::tpolygonPoints< T >::~tpolygonPoints | ( | ) | [virtual] |
destructor
tpolygonPoints<T>& lti::tpolygonPoints< T >::approximate | ( | const borderPoints & | theBorderPoints, | |
const pointList & | 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. |
tpolygonPoints<T>& lti::tpolygonPoints< 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 lti::tpolygonPoints< 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.
tpolygonPoints<T>& lti::tpolygonPoints< T >::castFrom | ( | const tpointList< T > & | thePointList | ) |
This is an alias for computeConvexHull().
tpolygonPoints<T>& lti::tpolygonPoints< T >::castFrom | ( | const ioPoints & | thePointList | ) |
creates the smallest convex polygon that contains all points in the given io-points list.
(see computeConvexHull()).
This method eliminates the points present twice in the list before computing the convex hull.
tpolygonPoints<T>& lti::tpolygonPoints< 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()
tpolygonPoints<T>& lti::tpolygonPoints< T >::clipPoly | ( | const tpolygonPoints< T > & | polygon1, | |
const tpolygonPoints< T > & | polygon2, | |||
const int & | minLength = 4 , |
|||
const double & | maxDistance = 0.8 | |||
) |
Combine two polygons.
The result is the union of the points of both polygons. If both given polygons do not overlap, the result will be the first polygon.
polygon1 | first polygon | |
polygon2 | second polygon | |
minLength | minimal distance between vertices of the polygon. | |
maxDistance | specify the maximal allowed distance between the border points and the approximated polygon. If set to 0, every minLength points will be taken as vertice of the polygon. |
bool lti::tpolygonPoints< T >::clockwise | ( | ) | const |
Compute if this polygon has a clockwise direction or not.
tpolygonPoints<T>& lti::tpolygonPoints< T >::convexHullFrom | ( | const tpointList< T > & | thePointList | ) |
Creates the smallest convex polygon that contains all points in the given point list.
The list of points must be a set, i.e. the same point is not allowed to be twice in the list. (This usually is not the case in lti::ioPoints lists, see castFrom(const ioPoints&)).
For more information on the algorithm used here see:
M. de Berg, et.al. Computational Geometry, Algorithms and Applications. 2nd. edition, Springer, 2000, pp. 6ff
thePointList | a set of points (the same point ist not allowed to be twice in the list). |
void lti::tpolygonPoints< T >::fitAndSplit | ( | const vector< point > & | 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
const char* lti::tpolygonPoints< T >::getTypeName | ( | void | ) | const [inline, virtual] |
returns the name of this class: "polygonPoints"
Reimplemented from lti::tpointList< T >.
void lti::tpolygonPoints< T >::invert | ( | ) |
invert the direction of the polygon points
tpolygonPoints<T>& lti::tpolygonPoints< T >::operator= | ( | const tpolygonPoints< T > & | other | ) | [inline] |
assigment operator (alias for copy(other)).
other | the pointList to be copied |
Reimplemented from lti::tpointList< T >.