The Triangulation_2<Gt,Tds> expects a model of geometric traits class as first template argument and a model of triangulation data structure as second argument. The requirements and defaults for these classes are described in the next sections and .
#include <CGAL/Triangulation_2.h>
|
| the geometric traits type. |
|
| |
the triangulation data structure type. | ||
|
| the point type |
| ||
| the segment type | |
| ||
| the triangle type |
The following types gives the classes representing the vertices and faces of the triangulation and the type corresponding to the edges. Recall that the edges are not explicitly represented and thus there is no corresponding class. The functionalities of the vertex and face classes are described in sections and .
| |
the vertex type.
| |
| |
the face type.
|
| ||
| the edge type. The Edge(f,i) is edge common to faces f and f.neighbor(i). It is also the edge joining the vertices vertex(cw(i)) and vertex(ccw(i)) of f. |
The vertices and faces of the triangulations are accessed through handles1, iterators and circulators. The iterators and circulators are all bidirectional and non mutable. The circulators and iterators are assignable to the corresponding handle types. Whenever a handle appear in the parameter list of a function, an appropriate iterator or circulator can be used as well. The edges of the triangulation can also be visited through iterators and circulators, the edge circulators and iterators are also bidirectional and non mutable. In the following, we called infinite any face or edge incident to the infinite vertex and the infinite vertex itself. Any other feature (face, edge or vertex) of the triangulation is said to be finite. Some iterators (the All iterators ) allows to visit finite or infinite feature while others (the Finite iterators) visit only finite features. Circulators visit infinite features as well as finite ones.
| |
handle to a vertex
| |
| |
handle to a facet
| |
| |
iterator over all faces.
| |
| |
iterator over all edges.
| |
| |
iterator over all vertices.
| |
| |
iterator over finite faces.
| |
| |
iterator over finite edges.
| |
| |
iterator over finite vertices.
| |
| |
circulator over faces intersected by a line.
| |
| |
circulator over faces incident to a given vertex.
| |
| |
circulator over edges incident to a given vertex.
| |
| |
circulator over vertices incident to a given vertex.
|
The triangulation class also defines the following enum type to specify which case occurs when locating a point in the triangulation.
| |
Introduces an empty triangulation t.
| |
| |
Copy constructor. All the vertices and faces are duplicated.
After the copy, t and tr
refer to different triangulations :
if tr is modified, t is not.
|
| ||
| Assignement. All the vertices and faces are duplicated. After the assignement, t and tr refer to different triangulations : if tr is modified, t is not. | |
|
| The triangulations tr and t are swapped. t. swap(tr) should be preferred to t = tr or to t(tr) if tr is deleted after that. |
|
| Deletes all faces and finite vertices resulting in an empty triangulation. |
| ||
| Destructor. All vertices and faces are deleted. |
|
| Returns a const reference to the triangulation traits object. |
|
| Returns the dimension of the convex hull. |
|
| |
Returns the number of finite vertices. | ||
|
| |
Returns the number of finite faces. | ||
|
| a face incident to the infinite_vertex. |
|
| |
the infinite_vertex. | ||
|
| a vertex distinct from the infinite_vertex. |
The class Triangulation_2<Gt,Tds> provides method to test the finite or infinite caracter of any feature, and also methods to test the presence in the triangulation of a particular feature (edge or face).
|
| |||
true, iff v is the infinite_vertex. | ||||
|
| |||
true, iff face f is infinite. | ||||
|
| |||
true, iff edge (f,i) is infinite. | ||||
|
| |||
true iff edge e is infinite. | ||||
|
| |||
true iff edge *ec is infinite. | ||||
|
| |||
true iff edge *ei is infinite. | ||||
|
| |||
true if there is an edge having va and vb as vertices. | ||||
|
| |||
as above. In addition, if true is returned, the edge with vertices va and vb is the edge e=(fr,i) where fr is a handle to the face incident to e and on the right side of e oriented from va to vb. | ||||
|
| |||
true if the line segment from va to vb includes an edge e incident to va. If true, vb becomes the other vertex of e, e is the edge (fr,i) where fr is a handle to the face incident to e and on the right side e oriented from va to vb. | ||||
|
| |||
true if there is a face having v1, v2 and av3 as vertices. This function is NOT YET implemented. | ||||
|
| |||
as above. In addition, if true is returned, fr is a handle to the face with v1, v2 and v3 as vertices. This function is NOT YET implemented. |
The class Triangulation_2<Gt,Tds> provides methods to locate a given point with respect to a triangulation. It also provides methods to locate a point with respect to a given finite face of the triangulation.
|
| |||
If the point query lies inside the convex hull of the points, a face
that contains the query in its interior or on its
boundary is returned. If the point query lies outside the convex hull of the triangulation but in the affine hull, the returned face is an infinite face which is a proof of the point's location : for a two dimensional triangulation, it is a face such that query lies to the left of the oriented line (the rest of the triangulation lying to the right of this line), for a degenerate one dimensional triangulation it is the (degenarate one dimensional) face such that query and the triangulation lie on either side of p. If the point query lies outside the affine hull, the returned Face_handle is NULL. The optional Face_handle argument, if provided, is used as a hint of where the locate process has to start its search. | ||||
|
| |||
Same as above. Additionally, the parameters lt and li describe where the query point is located. The variable lt is set to the locate type of the query. If lt==VERTEX the variable li is set to the index of the vertex, and if lt==EDGE li is set to the index of the vertex opposite to the edge. Be carefull that li has no meaning when the query type is FACE, OUTSIDE_CONVEX_HULL, or OUTSIDE_AFFINE_HULL or when the triangulation is -dimensional. | ||||
|
| |||
Returns on which side of the oriented boundary of f lies
the point p. Precondition: f is finite. | ||||
|
| |||
Returns on which side of the circumcircle of face f lies the point p. The circle is assumed to be counterclokwisely oriented, so its positive side correspond to its bounded side. This predicate is available only if the corresponding predicates on points is provided in the geometric traits class. |
The following operations are guaranteed to lead to a valid triangulation when they are applied on a valid triangulation.
|
| |||
Exchanges the edge incident to
f and f->neighbor(i) with the other
diagonal of the quadrilateral formed by f and f->neighbor(i). Precondition: The faces f and f->neighbor(i) are finite faces and their union form a convex quadrilateral. | ||||
|
| |||
Inserts point p in the triangulation and returns the corresponding
vertex. If point p coincides with an already existing vertex, this vertex is returned and the triangulation remains unchanged. If point p is on an edge, the two incident faces are split in two. If point p is strictly inside a face of the triangulation, the face is split in three. If point p is strictly outside the convex hull, p is linked to all visible points on the convex hull to form the new triangulation. At last, if p is outside the affine hull (in case of degenerate 1-dimensional or 0-dimensional triangulations), p is linked all the other vertices to form a triangulation whose dimension is increased by one. The last argument f is an indication to the underlying locate algorithm of where to start. | ||||
|
| |||
Same as above except that the location of the point p to be inserted is assumed to be given by (lt,loc,i) (see the description of the locate method above.) | ||||
|
| |||
Equivalent to insert(p). | ||||
| ||||
|
| |||
Inserts the points in the range
first, last.
Returns the number of inserted points. Precondition: The value_type of first and last is Point. | ||||
|
| |||
Removes the vertex from the triangulation. The created hole is
retriangulated. Precondition: Vertex v must be finite. |
Figure: Insertion of a point on an edge.
Figure: Insertion outside the convex hull.
The following member functions offer more specialized versions of the insertion or removal operation to be used when one knows to be in the corresponding case.
|
| |
Inserts the first finite vertex . | ||
|
| |
Inserts the second finite vertex . | ||
|
| |
Inserts vertex v in face
f. Face f is modified,
two new faces are created. Precondition: The point in vertex v lies inside face f. | ||
|
| |
Inserts vertex v in edge i of f. Precondition: The point in vertex v lies on the edge opposite to the vertex i of face f. | ||
|
| |
Inserts
a point which is outside the convex hull but in the affine hull.
Face handle f is assumed to point to a an infinite face
which is a prove of the point's location (see the description of the
locate method above.) Precondition: f point to a face which is a proof of the location off. | ||
|
| |
Inserts a point which is outside the affine hull. | ||
|
| |
Removes a vertex of degree three. Two of the incident faces are destroyed,
the third one is modified. Precondition: Vertex v is a finite vertex with degree three. | ||
|
| |
Removes the before last finite vertex. | ||
|
| |
Removes the last finite vertex. |
A triangulation can be seen as a container of faces and vertices. Therefore the triangulation provides several iterators and circulators that allow to traverse it (completely or partially).
The following iterators allow respectively to visit finite faces, finite edges and finite vertices of the triangulation. These iterators are non mutable, bidirectional and their value types are respectively Face, Edge and Vertex. They are all invalidated by any change in the triangulation.
|
| |
Starts at an arbitrary finite vertex | ||
|
| |
Past-the-end iterator | ||
|
| |
Starts at an arbitrary finite edge | ||
|
| |
Past-the-end iterator | ||
|
| |
Starts at an arbitrary finite face | ||
|
| |
Past-the-end iterator |
The following iterators allow respectively to visit all (finite or infinite) faces, edges and vertices of the triangulation. These iterators are non mutable, bidirectional and their value types are respectively Face, Edge and Vertex. They are all invalidated by any change in the triangulation.
|
| |
Starts at an arbitrary vertex | ||
|
| |
Past-the-end iterator | ||
|
| |
Starts at an arbitrary edge | ||
|
| Past-the-end iterator |
|
| |
Starts at an arbitrary face | ||
|
| Past-the-end iterator |
The triangulation defines a circulator that allows to visit all faces that are intersected by a line. More precisely a face f is enumerated by the circulator associated to the oriented line l if either:
| ||||
| ||||
This function returns a circulator that allows to visit the
faces intersected by the line pq.
If there is no such face the circulator has a singular value. The starting point of the circulator is the face f, or, if f is omitted, the first finite face traversed by l. The circulator wraps around the infinite_vertex : after the last traversed finite face, it steps through the infinite face adjacent to this face then through the infinite face adjacent to the first traversed finite face then through the first finite traversed face again. Precondition: If f != NULL, the point p must be inside or on the boundary of f. |
Figure illustrates which finite faces are enumerated. Lines and have no face to their left. Lines and have faces to their left. Note that the finite faces that are only vertex incident to lines and are not enumerated.
Figure: The line face circulator.
A line face circulator is invalidated if the face the circulator refers to is changed.
The triangulation also provides circulators that allows to visit respectively all faces or edges incident to a given vertex or all vertices adjacent to a given vertex. These circulator are non-mutable and bidirectional. The operator operator++ moves the circulator counterclockwise around the vertex while the operator-- moves clockwise. A face circulator is invalidated by any modification of the face pointed to. An edge or a vertex circulator are invalidated by any modification of one of the two faces incident to the edge pointed to.
|
| |
Starts at an arbitrary face incident to v. | ||
|
| |
Starts at face f. Precondition: Face f is incident to vertex v. | ||
|
| |
Starts at an arbitrary edge incident to v. | ||
|
| |
Starts at the the first edge of f incident to
v, in counterclockwise order around v. Precondition: Face f is incident to vertex v. | ||
|
| |
Starts at an arbitrary vertex incident to v. | ||
|
| |
Starts at the first vertex of f adjacent to v
in counterclockwise order around v. Precondition: Face f is incident to vertex v. |
Applied on the infinite_vertex the above functions allow to visit the vertices on the convex hull and the infinite edges and faces. Note that a counterclockwise traversal of the vertices adjacent to the infinite_vertex is a clockwise traversal of the convex hull.
|
| |||
|
| |||
|
| |||
|
| |||
|
| |||
|
|
|
|
Returns modulo 3. Precondition: . |
|
|
Returns modulo 3. Precondition: . |
|
| |
Returns the triangle formed by the three vertices of f. Precondition: The face is finite. | ||
|
| |
Returns the line segment formed by the vertices ccw(i)
and cw(i) of face f. Precondition: . The vertices ccw(i) and cw(i) of f are finite. | ||
|
| |
Returns the line segment corresponding to edge e. Precondition: e is a finite edge | ||
|
| |
Returns the line segment corresponding to edge *ec. Precondition: *ec is a finite edge. | ||
|
| |
Returns the line segment corresponding to edge *ei. Precondition: *ei is a finite edge. | ||
|
| |
Compute the circumcenter of the face pointed to by f. This function is available only if the correspoding function is provided in the geometric traits. |
|
| |
|
| |
|
|
|
| |
Checks the combinatorial validity of the triangulation and also the validity of its geometric embedding. This method is mainly a debugging help for the users of advanced features. |
The I/O operators are defined for iostream, and for the window stream provided by CGAL. The format for the iostream is an internal format.
|
|
Inserts the triangulation t into the stream os. Precondition: The insert operator must be defined for Point. |
|
|
Reads a triangulation from stream is and assigns it
to t. Precondition: The extract operator must be defined for Point. |
#include <CGAL/IO/Window_stream.h>
|
| |
Inserts the triangulation t into the window stream W. The insert operator must be defined for Point and Segment. |
The following code fragment creates a triangulation of 2D points for the usual Euclidean metric. The points are read from cin, inserted in the triangulation and finally points on the convex hull are written to cout.
/* triangulation_prog1.C */ /* --------------------- */ #include <CGAL/basic.h> #include <iostream> #include <CGAL/Cartesian.h> #include <CGAL/Point_2.h> #include <CGAL/Triangulation_2.h> #include <CGAL/Triangulation_euclidean_traits_2.h> using namespace CGAL; typedef Cartesian<double> Rp; typedef Triangulation_euclidean_traits_2<Rp> Gt; typedef Triangulation_vertex_base_2<Gt> Vb; typedef Triangulation_face_base_2<Gt> Fb; typedef Triangulation_default_data_structure_2<Gt,Vb,Fb> Tds; typedef Triangulation_2<Gt, Tds> Triangulation; typedef Triangulation::Vertex_circulator Vertex_circulator; typedef Gt::Point Point; int main() { Triangulation t; Point p; while (std::cin >> p){ t.insert(p); } Vertex_circulator vc = t.incident_vertices(t.infinite_vertex()), done(vc); if (vc != 0) { do{ std::cout << vc->point() << std::endl; }while(++vc != done); } }
Locate is implemented by a line walk from a vertex of the face given as optional parameter (or from a finite vertex of infinite_face() if no optional parameter is given). It takes time O(n) in the worst case, but only O(sqrt(n)) on average if the vertices are distributed uniformly at random.
Insertion of a point is done by locating a face that contains the point, and then splitting this face. If the point falls outside the convex hull, the triangulation is restored by flips. Apart from the location, insertion takes a time time O(1). This bound is only an amortized bound for points located outside the convex hull.
Removal of a vertex is done by removing all adjacent triangles, and retriangulating the hole. Removal takes time O(d^2) in the worst case, if d is the degree of the removed vertex, which is O(1) for a random vertex.
The face, edge, and vertex iterators on finite features are derived from their counterparts visiting all (finite and infinite) features which are themselves derived from the corresponding iterators of the triangulation data structure.
1 | A handle is a type which supports the two dereference operators operator* and operator->. |