CVR-Lib last update 20 Sep 2009

cvr::polygonPoints< T > Class Template Reference
[Aggregate Data TypesShape Analysis]

Contour classes: polygonPoints. More...

#include <cvrPolygonPoints.h>

Inheritance diagram for cvr::polygonPoints< T >:

Inheritance graph
[legend]
Collaboration diagram for cvr::polygonPoints< T >:

Collaboration graph
[legend]

List of all members.

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)
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)


Detailed Description

template<class T>
class cvr::polygonPoints< T >

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.

See also:
cvr::borderPoints, cvr::ioPoints, cvr::pointList

Constructor & Destructor Documentation

template<class T>
cvr::polygonPoints< T >::polygonPoints (  ) 

default constructor creates an empty border-point-list

template<class T>
cvr::polygonPoints< T >::polygonPoints ( const polygonPoints< T > &  other  ) 

create this pointList as a copy of another pointList

Parameters:
other the pointList to be copied.

template<class T>
virtual cvr::polygonPoints< T >::~polygonPoints (  )  [virtual]

destructor


Member Function Documentation

template<class T>
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:

  1. It must have the same sequence than theBorderPoints.
  2. The points must be contained by the theBorderPoints

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.

Parameters:
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.
Returns:
a reference to this polygon-points instance.

template<class T>
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.

Parameters:
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.
Returns:
a reference to this polygon-points instance.

template<class T>
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.

template<class T>
polygonPoints<T>& cvr::polygonPoints< T >::castFrom ( const pointList< T > &  thePointList  ) 

This is an alias for computeConvexHull().

template<class T>
polygonPoints<T>& cvr::polygonPoints< 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.

template<class T>
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()

template<class T>
bool cvr::polygonPoints< T >::clockwise (  )  const

Compute if this polygon has a clockwise direction or not.

template<class T>
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

Parameters:
vct set of vertices of the polygon
idx1 initial index
idx2 final index
maxDistance maximum allowed distance
flags flags for the points.

template<class T>
void cvr::polygonPoints< T >::invert (  ) 

invert the direction of the polygon points

template<class T>
const std::string& cvr::polygonPoints< T >::name (  )  const [virtual]

returns the name of this class

Reimplemented from cvr::pointList< T >.

template<class T>
polygonPoints<T>& cvr::polygonPoints< T >::operator= ( const polygonPoints< T > &  other  )  [inline]

assigment operator (alias for copy(other)).

Parameters:
other the pointList to be copied
Returns:
a reference to the actual pointList


The documentation for this class was generated from the following file:

Generated on Sun Sep 20 22:08:51 2009 for CVR-Lib by Doxygen 1.5.8