Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

vgl_polygon< T > Class Template Reference

#include <vgl_polygon.h>

List of all members.


Detailed Description

template<class T>
class vgl_polygon< T >

Store a polygon.

May have holes or multiple sections. The polygon is stored as a list of "sheets", each sheet is a list of 2d points. Iterate through all points using

for (unsigned int s = 0; s < polygon.num_sheets(); ++s) for (unsigned int p = 0; p < polygon[s].size(); ++p) do_something(polygon[s][p].x(), polygon[s][p].y());

Definition at line 31 of file vgl_polygon.h.

Public Types

typedef vgl_point_2d< T > point_t
typedef vcl_vector< point_tsheet_t

Public Member Functions

 vgl_polygon ()
 Default constructor - constructs an empty polygon with no sheets.
 vgl_polygon (unsigned int num_sheets)
 Construct an empty polygon, setting the number of (empty) sheets.
 vgl_polygon (point_t const p[], int n)
 Construct a single-sheet polygon from a list of n points.
 vgl_polygon (T const *x, T const *y, int n)
 Construct a single-sheet polygon from a list of n points.
 vgl_polygon (T const x_y[], int n)
 Construct a single-sheet polygon from a list of n points, given in (x,y) pairs.
 vgl_polygon (sheet_t const &points, unsigned n_sheets=1)
 Construct a single-sheet polygon from a sheet, i.e.
 vgl_polygon (vcl_vector< sheet_t > const &sheets)
 Construct by specifying all of its sheets.
 vgl_polygon (vgl_polygon const &a)
 ~vgl_polygon ()
bool contains (point_t const &p) const
 Returns true if p(x,y) is inside the polygon, else false.
bool contains (T x, T y) const
void add_contour (point_t const p[], int n)
 Add a single sheet to this polygon, specified by the given list of n points.
void add_contour (T const *x, T const *y, int n)
 Add a single sheet to this polygon, specified by the given list of n points.
void add_contour (T const x_y[], int n)
 Add a single sheet to this polygon, specified by the given list of n (x,y) pairs.
void clear ()
 Set the number of sheets to zero, so the polygon becomes empty.
void new_sheet ()
 Add a new (empty) sheet to the polygon.
void push_back (T x, T y)
 Add a new point to the last sheet.
void push_back (point_t const &)
 Add a new point to the last sheet.
void push_back (sheet_t const &s)
 Add a pre-existing sheet to the polygon.
unsigned int num_sheets () const
unsigned int num_vertices () const
sheet_toperator[] (int i)
 Get the ith sheet.
sheet_t const & operator[] (int i) const
 Get the ith sheet.
vcl_ostream & print (vcl_ostream &) const
 Pretty print.

Protected Attributes

vcl_vector< sheet_tsheets_

Related Functions

(Note that these are not member functions.)

vgl_area_signed (vgl_polygon< T > const &poly)
 Computes the signed area of a polygon.
vgl_area (vgl_polygon< T > const &poly)
 The area of a polygon.
vgl_area_enforce_orientation (vgl_polygon< T > const &poly)
 The orientation enforced area of a polygon.
vgl_polygon< T > vgl_clip (const vgl_polygon< T > &poly1, const vgl_polygon< T > &poly2, vgl_clip_type op=vgl_clip_type_intersect)
 Clip a polygon against another polygon.
vgl_point_2d< T > vgl_closest_point (vgl_polygon< T > const &poly, vgl_point_2d< T > const &point, bool closed=true)
 Return the point on the given polygon closest to the given point.
double vgl_distance (vgl_polygon< T > const &poly, vgl_point_2d< T > const &point, bool closed=true)
 distance between a point and the closest point on the polygon.
bool vgl_polygon_test_inside (T const *xs, T const *ys, unsigned n, T x, T y)
 return true iff (x, y) is inside (or on boundary of) the given n-gon.


Member Typedef Documentation

template<class T>
typedef vgl_point_2d<T> vgl_polygon< T >::point_t
 

Definition at line 34 of file vgl_polygon.h.

template<class T>
typedef vcl_vector<point_t> vgl_polygon< T >::sheet_t
 

Definition at line 36 of file vgl_polygon.h.


Constructor & Destructor Documentation

template<class T>
vgl_polygon< T >::vgl_polygon  )  [inline]
 

Default constructor - constructs an empty polygon with no sheets.

Definition at line 41 of file vgl_polygon.h.

template<class T>
vgl_polygon< T >::vgl_polygon unsigned int  num_sheets  )  [inline, explicit]
 

Construct an empty polygon, setting the number of (empty) sheets.

Definition at line 44 of file vgl_polygon.h.

template<class T>
vgl_polygon< T >::vgl_polygon point_t const   p[],
int  n
 

Construct a single-sheet polygon from a list of n points.

More sheets can be added later with the add_contour method.

Definition at line 13 of file vgl_polygon.txx.

template<class T>
vgl_polygon< T >::vgl_polygon T const *  x,
T const *  y,
int  n
 

Construct a single-sheet polygon from a list of n points.

More sheets can be added later with the add_contour method.

Definition at line 21 of file vgl_polygon.txx.

template<class T>
vgl_polygon< T >::vgl_polygon T const   x_y[],
int  n
 

Construct a single-sheet polygon from a list of n points, given in (x,y) pairs.

The x_y array should thus be of size 2*n ! More sheets can be added later with the add_contour method.

Definition at line 29 of file vgl_polygon.txx.

template<class T>
vgl_polygon< T >::vgl_polygon sheet_t const &  points,
unsigned  n_sheets = 1
[inline, explicit]
 

Construct a single-sheet polygon from a sheet, i.e.

, a vector of 2D points. Note: n_sheets is only there to distinguish this from the next constructor for VC6 which seems to have a problem.

Definition at line 62 of file vgl_polygon.h.

template<class T>
vgl_polygon< T >::vgl_polygon vcl_vector< sheet_t > const &  sheets  )  [inline, explicit]
 

Construct by specifying all of its sheets.

Definition at line 65 of file vgl_polygon.h.

template<class T>
vgl_polygon< T >::vgl_polygon vgl_polygon< T > const &  a  )  [inline]
 

Definition at line 68 of file vgl_polygon.h.

template<class T>
vgl_polygon< T >::~vgl_polygon  )  [inline]
 

Definition at line 71 of file vgl_polygon.h.


Member Function Documentation

template<class T>
void vgl_polygon< T >::add_contour T const   x_y[],
int  n
 

Add a single sheet to this polygon, specified by the given list of n (x,y) pairs.

The x_y array should thus be of size 2*n ! This increments the number of sheets by one.

Definition at line 55 of file vgl_polygon.txx.

template<class T>
void vgl_polygon< T >::add_contour T const *  x,
T const *  y,
int  n
 

Add a single sheet to this polygon, specified by the given list of n points.

This increments the number of sheets by one.

Definition at line 46 of file vgl_polygon.txx.

template<class T>
void vgl_polygon< T >::add_contour point_t const   p[],
int  n
 

Add a single sheet to this polygon, specified by the given list of n points.

This increments the number of sheets by one.

Definition at line 37 of file vgl_polygon.txx.

template<class T>
void vgl_polygon< T >::clear  )  [inline]
 

Set the number of sheets to zero, so the polygon becomes empty.

Definition at line 94 of file vgl_polygon.h.

template<class T>
bool vgl_polygon< T >::contains x,
y
const
 

Definition at line 78 of file vgl_polygon.txx.

template<class T>
bool vgl_polygon< T >::contains point_t const &  p  )  const [inline]
 

Returns true if p(x,y) is inside the polygon, else false.

Definition at line 74 of file vgl_polygon.h.

template<class T>
void vgl_polygon< T >::new_sheet  )  [inline]
 

Add a new (empty) sheet to the polygon.

This increments the number of sheets by one.

Definition at line 98 of file vgl_polygon.h.

template<class T>
unsigned int vgl_polygon< T >::num_sheets  )  const [inline]
 

Definition at line 109 of file vgl_polygon.h.

template<class T>
unsigned int vgl_polygon< T >::num_vertices  )  const [inline]
 

Definition at line 111 of file vgl_polygon.h.

template<class T>
sheet_t const& vgl_polygon< T >::operator[] int  i  )  const [inline]
 

Get the ith sheet.

Definition at line 119 of file vgl_polygon.h.

template<class T>
sheet_t& vgl_polygon< T >::operator[] int  i  )  [inline]
 

Get the ith sheet.

Definition at line 116 of file vgl_polygon.h.

template<class T>
vcl_ostream & vgl_polygon< T >::print vcl_ostream &   )  const
 

Pretty print.

Definition at line 102 of file vgl_polygon.txx.

template<class T>
void vgl_polygon< T >::push_back sheet_t const &  s  )  [inline]
 

Add a pre-existing sheet to the polygon.

Definition at line 107 of file vgl_polygon.h.

template<class T>
void vgl_polygon< T >::push_back point_t const &   ) 
 

Add a new point to the last sheet.

Definition at line 72 of file vgl_polygon.txx.

template<class T>
void vgl_polygon< T >::push_back x,
y
 

Add a new point to the last sheet.

Definition at line 66 of file vgl_polygon.txx.


Friends And Related Function Documentation

template<class T>
T vgl_area vgl_polygon< T > const &  poly  )  [related]
 

The area of a polygon.

See also:
vgl_area_signed

Definition at line 27 of file vgl_area.txx.

template<class T>
T vgl_area_enforce_orientation vgl_polygon< T > const &  poly  )  [related]
 

The orientation enforced area of a polygon.

Note:
This method assumes that the polygon is simple (i.e. no crossings) and the correct orientation is 'enforced' on the polygon (i.e. holes are given negative area) to ensure that the resultant area is correct
See also:
vgl_area

Definition at line 39 of file vgl_area.txx.

template<class T>
T vgl_area_signed vgl_polygon< T > const &  poly  )  [related]
 

Computes the signed area of a polygon.

The sign is positive if the polygon is oriented counter-clockwise (in RH coordinate system) and negative otherwise. For "polygons" consisting of more than one contour, the result is valid only if the contours are oriented consistently. That is, an enclosed contour must have opposite orientation to the enclosing contour.

See also:
vgl_area

Definition at line 11 of file vgl_area.txx.

template<class T>
vgl_polygon< T > vgl_clip const vgl_polygon< T > &  poly1,
const vgl_polygon< T > &  poly2,
vgl_clip_type  op = vgl_clip_type_intersect
[related]
 

Clip a polygon against another polygon.

The two polygons poly1 and poly2 are combined with each other. The operation (intersection, union, etc) is given by parameter op.

Note:
The implementation of this code is based on Alan Murta's GPC library (http://www.cs.man.ac.uk/aig/staff/alan/software/gpc.html) which is free for non-commercial use.

Definition at line 139 of file vgl_clip.txx.

template<class T>
vgl_point_2d< T > vgl_closest_point vgl_polygon< T > const &  poly,
vgl_point_2d< T > const &  point,
bool  closed = true
[related]
 

Return the point on the given polygon closest to the given point.

If the third argument is "false", the edge from last to first point of each polygon sheet is not considered part of the polygon.

Definition at line 286 of file vgl_closest_point.txx.

template<class T>
double vgl_distance vgl_polygon< T > const &  poly,
vgl_point_2d< T > const &  point,
bool  closed = true
[related]
 

distance between a point and the closest point on the polygon.

If the third argument is "false", the edge from last to first point of each polygon sheet is not considered part of the polygon.

Definition at line 252 of file vgl_distance.txx.

template<class T>
bool vgl_polygon_test_inside T const *  xs,
T const *  ys,
unsigned  n,
x,
y
[related]
 

return true iff (x, y) is inside (or on boundary of) the given n-gon.

Definition at line 12 of file vgl_polygon_test.txx.


Member Data Documentation

template<class T>
vcl_vector<sheet_t> vgl_polygon< T >::sheets_ [protected]
 

Definition at line 127 of file vgl_polygon.h.


The documentation for this class was generated from the following files:
Generated on Thu Jan 10 14:39:28 2008 for core/vgl by  doxygen 1.4.4