Navigation: Up, Table of Contents, Bibliography, Index, Title Page

2D Triangulation Data Structure

The second template parameter of a 2D triangulation class has to be instanciated with a model of TriangulationDataStructure_2. This model is decribed in section reference. CGAL provides two classes which are models for this concept. These models are described in section reference. Section reference described the base vertex and face classes of a triangulation. At last, section reference shows how the user can plug in the triangulation data structure his own vertex or face base class.

The Concept

A model of TriangulationDataStructure_2 can be seen has a container for the faces and vertices of the triangulation. This class is also responsible for the combinatorial integrity of the triangulation. This means that the triangulation data strucure maintains proper incidence and adjacency relations among the vertices and faces of a triangulation while combinatorial modifications of the triangulation are performed. The term combinatorial modification refers to operations which do not involve any knowledge about the geometric embedding of the triangulation. For example, the insertion of a new vertex in a given face, or in a given edge, the suppression of a vertex of degree three, the flip of two edge are examples of combinatorial operation performed at the data structure level.

The triangulation data structure is required to provide :

The triangulation data structure is responsible for the creation and removal of faces and vertices (memory management). It provides function that gives the number of faces, edges and vertices of the triangulation.

The triangulation data structure provides member functions to perform the following combinatorial transformation of the triangulation:
flip of two adjacent faces,
addition of a new vertex splitting a given face,
addition of a new vertex splitting a given edge,
addition of a new vertex raising by one the dimension of a degenerate lower dimensional triangulation,
removal of a vertex incident to three faces,
removal of a vertex lowering the dimension of the triangulation.

Insertion

Models of Triangulation Data Structure

CGAL currently offers two models of triangulation data structures. The first one, called Triangulation_default_data_structure_2<Tds_gt,Vb,Fb > is very economic with respect to memory space but its use is restricted to planar embedded triangulations. The second one, called Triangulation_data_structure_using_list_2<Vb,Fb> can be used for the representation of any orientable triangulations.

Software design

According to the software design described in section reference, the models of triangulation data structure offered by CGAL are themselves template classes, parametrized by the base classes for vertices and faces. The concepts of TriangulationVertexBase_2 and TriangulationFaceBase_2 are described in next section reference. The triangulation data structure derives from thoses base classes its own vertex and face classes. This design allows the user to plug in the triangulation data structure his own base classes tuned for his application.

The Default Triangulation Data Structure

CGAL proposes the class Triangulation_default_data_structure_2<TdsGt,Vb,Fb > as a model for the triangulation data structure class of a triangulation. This class has three template parameters. In addition to the template parameters Vb and Fb for the base classes, this model of triangulation data structure has a template parameter TdsGt which is a geometric traits class. This may be surprising because the triangulation data structure is supposed to deal only with the combinatorial aspect of the triangulation and not with its geometric embedding. The reason for that is the following. The class Triangulation_default_data_structure_2<TdsGt,Vb,Fb > does not use any additional data structure such as a list or a vector to act as a container for faces and vertices. The iterators which allows to visit all faces and vertices of the triangulation data structure is implemented using an implicit tree structure over the faces as described by de Berg et al. in [dBvKvOO97]. This tree structure is based on the planar geometric embedding the triangulation. Each face can find its parent and its children using only simple comparisons on the coordinates of the points embedding its vertices. This tree structure remain implicit and does not require any additional memory.

The requirements concerning the geometric traits TdsGt of Triangulation_default_data_structure_2 are very light and form a subset of the requirements needed for the geometric traits of the triangulations. This class is required to provide a type Point_2 and coordinate comparison predicates. The point type defined by the geometric traits class of the triangulation data structure and the point type defined by the geometric traits of the triangulation have to be the same. This is automatically achieved if the same model is used for both traits classes which is recommended but not compulsory.

A triangulation data structure using list

The class Triangulation_data_structure_using_list_2<Vb,Fb> can be used as a triangulation data structure for any orientable triangulation. It uses a STL list to store the full dimensional faces of the triangulation.

The Base Vertex and Face Classes

The concepts

The concepts TriangulationVertexBase_2 and TriangulationFaceBase_2 described the requirements for the base vertex and face classes of a two-dimensional triangulation.

At the bottom layer, a vertex is required to provide access to the embedding point and to one of its incident face through a void * pointer.

At the bottom layer, a face provides access to its three vertices and to its three neighboring faces through void * pointers. The vertices and neighbors are indexed 0,1 and 2 in counterclockwise order around the face. The neighbor indexed i lies opposite to vertex with the same index.

The Default Models

CGAL provides the models Triangulation_face_base_2<Traits> and Triangulation_vertex_base_2<Traits> for respectively the TriangulationVertexBase_2 and the TriangulationFaceBase_2 concepts. Both of them are templated by a geometric traits class. Using for this traits class, the geometric traits class used for the triangulation class is strongly recommended. It ensures that the point type defined by Triangulation_vertex_base_2<Traits> is the same as the point type defined the geometric traits class of the triangulation.

These default base classes can be used directly or can serve as a base to derive other base classes with some additional attribute (a color for example) tuned for a specific application.

Example : Using one's own Base Face

The following example derives a new base face class from the default one and adds a color to the faces of the triangulation. The face of the triangulation data structure and the face of the triangulation will inherit the new data member and its functionality. Any kind of additional functionality can thus be added to faces or vertices of a triangulation as long as this functionality does not involve additional pointers to vertices or faces (because the base classes use only void* pointer and have no knowledge of the vertex or face types.).

Example

// file          : examples/Triangulation_2/colored_face.C
#include <CGAL/Cartesian.h>
#include <CGAL/IO/Color.h>
#include <CGAL/Triangulation_2.h>

/* A facet with a color member variable. */
template < class Gt >
class My_face_base : public CGAL::Triangulation_face_base_2<Gt>
{
public:
  CGAL::Color color;
  My_face_base() :
    CGAL::Triangulation_face_base_2<Gt>() {}
  My_face_base(void* v0, void* v1, void* v2) : 
    CGAL::Triangulation_face_base_2<Gt>(v0,v1,v2) {}
  My_face_base(void* v0, void* v1, void* v2, void* n0, void* n1, void* n2) : 
    CGAL::Triangulation_face_base_2<Gt>(v0,v1,v2,n0,n1,n2) {}
};

typedef CGAL::Cartesian<double> Gt;
typedef CGAL::Triangulation_vertex_base_2<Gt> Vb;
typedef My_face_base<Gt> Fb;
typedef CGAL::Triangulation_data_structure_using_list_2<Vb,Fb > Tds;
typedef CGAL::Triangulation_2<Gt,Tds> Triangulation;

typedef Triangulation::Face_handle Face_handle;
typedef Triangulation::Face_iterator Face_iterator;
typedef Gt::Point_2  Point;

int main() {
  Triangulation t;
  t.insert(Point(0,1));
  t.insert(Point(0,0));
  t.insert(Point(2,0));
  t.insert(Point(2,2));
 
  Face_iterator fc = t.faces_begin();
  for( ; fc != t.faces_end(); ++fc)  fc->color = CGAL::BLUE;

  Point p(0.5,0.5);
  Face_handle fh = t.locate(p);
  fh->color = CGAL::RED;

  return 0;
}


Navigation: Up, Table of Contents, Bibliography, Index, Title Page
www.cgal.org. Aug 13, 2001.