Store a polygon. More...
#include <vgl_area.h>
Public Types | |
| typedef vgl_point_2d< T > | point_t |
| typedef std::vector< point_t > | sheet_t |
Public Member Functions | |
| vgl_polygon ()=default | |
| Default constructor - constructs an empty polygon with no sheets. More... | |
| vgl_polygon (unsigned int nr_sheets) | |
| Construct an empty polygon, setting the number of (empty) sheets. More... | |
| vgl_polygon (point_t const p[], int n) | |
| Construct a single-sheet polygon from a list of n points. More... | |
| vgl_polygon (T const *x, T const *y, int n) | |
| Construct a single-sheet polygon from a list of n points. More... | |
| vgl_polygon (T const x_y[], int n) | |
| Construct a single-sheet polygon from a list of n points, given in (x,y) pairs. More... | |
| vgl_polygon (sheet_t const &points, unsigned n_sheets=1) | |
| Construct a single-sheet polygon from a sheet, i.e., a vector of 2D points. More... | |
| vgl_polygon (std::vector< sheet_t > sheets) | |
| Construct by specifying all of its sheets. More... | |
| vgl_polygon (vgl_polygon const &a) | |
| ~vgl_polygon ()=default | |
| bool | contains (point_t const &p) const |
| Returns true if p(x,y) is inside the polygon, else false. More... | |
| 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. More... | |
| 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. More... | |
| 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. More... | |
| void | clear () |
| Set the number of sheets to zero, so the polygon becomes empty. More... | |
| void | new_sheet () |
| Add a new (empty) sheet to the polygon. More... | |
| void | push_back (T x, T y) |
| Add a new point to the last sheet. More... | |
| void | push_back (point_t const &) |
| Add a new point to the last sheet. More... | |
| void | push_back (sheet_t const &s) |
| Add a pre-existing sheet to the polygon. More... | |
| unsigned int | num_sheets () const |
| unsigned int | num_vertices () const |
| sheet_t & | operator[] (int i) |
| Get the ith sheet. More... | |
| sheet_t const & | operator[] (int i) const |
| Get the ith sheet. More... | |
| std::ostream & | print (std::ostream &) const |
| Pretty print. More... | |
| std::istream & | read (std::istream &) |
| read this polygon from ascii stream. More... | |
Protected Attributes | |
| std::vector< sheet_t > | sheets_ |
Related Functions | |
(Note that these are not member functions.) | |
| template<class T > | |
| T | vgl_area_signed (vgl_polygon< T > const &poly) |
| Computes the signed area of a polygon. More... | |
| template<class T > | |
| T | vgl_area (vgl_polygon< T > const &poly) |
| The area of a polygon. More... | |
| template<class T > | |
| T | vgl_area_enforce_orientation (vgl_polygon< T > const &poly) |
| The orientation enforced area of a polygon. More... | |
| template<class T > | |
| vgl_point_2d< T > | vgl_centroid (vgl_polygon< T > const &poly) |
| The area weighted center of a polygon. More... | |
| 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) |
| Clip a polygon against another polygon. More... | |
| template<class T > | |
| vgl_polygon< T > | vgl_clip (vgl_polygon< T > const &poly1, vgl_polygon< T > const &poly2, vgl_clip_type op, int *p_retval) |
| Clip a polygon against another polygon. More... | |
| template<class T > | |
| 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. More... | |
| template<class T > | |
| vgl_polygon< T > | vgl_convex_hull (std::vector< vgl_point_2d< T > > const &points) |
| Return a single-sheet polygon which is the smallest one containing all given points. More... | |
| template<class T > | |
| 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. More... | |
| template<class T > | |
| 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. More... | |
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());
Note: area is not defined on the polygon class to keep a clean interface see vgl_area<T>
Definition at line 6 of file vgl_area.h.
| typedef vgl_point_2d<T> vgl_polygon< T >::point_t |
Definition at line 41 of file vgl_polygon.h.
| typedef std::vector<point_t> vgl_polygon< T >::sheet_t |
Definition at line 43 of file vgl_polygon.h.
|
default |
Default constructor - constructs an empty polygon with no sheets.
|
inlineexplicit |
Construct an empty polygon, setting the number of (empty) sheets.
Definition at line 51 of file vgl_polygon.h.
| 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 28 of file vgl_polygon.hxx.
| 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 36 of file vgl_polygon.hxx.
| 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 44 of file vgl_polygon.hxx.
|
inlineexplicit |
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 69 of file vgl_polygon.h.
|
inlineexplicit |
Construct by specifying all of its sheets.
Definition at line 72 of file vgl_polygon.h.
|
inline |
Definition at line 75 of file vgl_polygon.h.
|
default |
| 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 52 of file vgl_polygon.hxx.
| 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 61 of file vgl_polygon.hxx.
| 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 70 of file vgl_polygon.hxx.
|
inline |
Set the number of sheets to zero, so the polygon becomes empty.
Definition at line 101 of file vgl_polygon.h.
|
inline |
Returns true if p(x,y) is inside the polygon, else false.
Definition at line 81 of file vgl_polygon.h.
| bool vgl_polygon< T >::contains | ( | T | x, |
| T | y | ||
| ) | const |
Definition at line 93 of file vgl_polygon.hxx.
|
inline |
Add a new (empty) sheet to the polygon.
This increments the number of sheets by one.
Definition at line 105 of file vgl_polygon.h.
|
inline |
Definition at line 116 of file vgl_polygon.h.
|
inline |
Definition at line 118 of file vgl_polygon.h.
|
inline |
Get the ith sheet.
Definition at line 124 of file vgl_polygon.h.
|
inline |
Get the ith sheet.
Definition at line 127 of file vgl_polygon.h.
| std::ostream & vgl_polygon< T >::print | ( | std::ostream & | os | ) | const |
Pretty print.
Definition at line 120 of file vgl_polygon.hxx.
| void vgl_polygon< T >::push_back | ( | T | x, |
| T | y | ||
| ) |
Add a new point to the last sheet.
Definition at line 81 of file vgl_polygon.hxx.
| void vgl_polygon< T >::push_back | ( | point_t const & | p | ) |
Add a new point to the last sheet.
Definition at line 87 of file vgl_polygon.hxx.
|
inline |
Add a pre-existing sheet to the polygon.
Definition at line 114 of file vgl_polygon.h.
| std::istream & vgl_polygon< T >::read | ( | std::istream & | is | ) |
read this polygon from ascii stream.
Definition at line 142 of file vgl_polygon.hxx.
|
related |
The area of a polygon.
|
related |
The orientation enforced area of a polygon.
Definition at line 61 of file vgl_area.hxx.
|
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.
|
related |
The area weighted center of a polygon.
In general this is different than the mean of the polygon's vertices
|
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.
In order to be able to use it, make sure to satisfy the copyright notice, then activate the "BUILD_NONCOMMERCIAL" compiler option.
|
related |
Clip a polygon against another polygon.
Same as vgl_clip( const vgl_polygon<T>& poly1, const vgl_polygon<T>& poly2, vgl_clip_type op = vgl_clip_type_intersect ); but where the fourth parameter is a return flag which is 1 if success, or 0 if the operation faced a geometric degeneracy which could not be handled. In this case, it might be necessary to perturb the input with a tiny amount of random noise and try again.
|
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.
|
related |
Return a single-sheet polygon which is the smallest one containing all given points.
|
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.
|
related |
return true iff (x, y) is inside (or on boundary of) the given n-gon.
|
protected |
Definition at line 137 of file vgl_polygon.h.
1.8.15