![Page 1: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/1.jpg)
Triangulations in
Monique Teillaud
Triangulations in
![Page 2: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/2.jpg)
Overview
SpecificationsDefinitionVarious triangulationsFunctionalities
Geometry vs. combinatorics
Representation
Software designThe traits classThe triangulation data structure
Using the Triangulation packagesUser ManualReference ManualExamples
More flexibility
Triangulations in 1
![Page 3: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/3.jpg)
Specifications
2
![Page 4: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/4.jpg)
Definition
A 2d- (3d-) triangulation is a set of triangles (tetrahedra) such that:- the set is edge- (facet-) connected- two triangles (tetrahedra) are either disjoint or share (a facet or) an edge or avertex.
yes :
no :
Triangulations in 3
![Page 5: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/5.jpg)
Various triangulations
2D, 3D Basic triangulations2D, 3D Delaunay triangulations2D, 3D Regular triangulations2D Constrained triangulations2D Constrained Delaunay triangulations
Triangulations in 4
![Page 6: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/6.jpg)
2d - 3d
Triangulations in 5
![Page 7: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/7.jpg)
Basic and Delaunay triangulations
Basic triangulations : lazy incremental construction
Delaunay triangulations: empty circle property
Triangulations in 6
![Page 8: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/8.jpg)
Regular triangulations
weighted point p(w) = (p, wp), p ∈ R3, wp ∈ R
p(w) = (p, wp) ' sphere of center p and radius wp.
power product between p(w) and z(w)
Π(p(w), z(w)) = ‖p− z‖2 − wp − wz
p(w) and z(w) orthogonal iff Π(p(w), z(w)) = 0
� �
� � � �
Triangulations in 7
![Page 9: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/9.jpg)
Power sphere of 4 weighted points in R3 = unique common orthogonal weightedpoint.
z(w) is regular iff ∀p(w),Π(p(w), z(w)) ≥ 0
Regular triangulations: generalization of Delaunay triangulations to weightedpoints. Dual of the power diagram.
The power sphere of all simplices is regular.
Triangulations in 8
![Page 10: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/10.jpg)
Constrained [Delaunay] triangulations
Constrained Delaunay triangulations
Constrained empty circle property : the circumscribing circle encloses no vertexvisible from the interior of the triangle.
Triangulations in 9
![Page 11: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/11.jpg)
Functionalities of CGAL triangulations
General functionalities
Traversal of a triangulation
- passing from a face to its neighbors- iterators to visit all or faces of a triangulation- circulators to visit all faces around a vertex
or all faces intersected by a line.
Point location query
Insertion, removal, flips
Triangulations in 10
![Page 12: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/12.jpg)
Traversal of a triangulation
Iterators
All faces iteratorAll vertices iteratorAll edges iterator
Circulators
Face circulator : faces incident to a vertexEdge circulator : edges incident to a vertexVertex circulator : incident to a vertex
All_vertices_iterator vit;for (vit = T.finite_vertices_begin();
vit != T.finite_vertices_end(); ++vit){ ... }
Triangulations in 11
![Page 13: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/13.jpg)
Traversal of a triangulations cont’d
Line face circulator
Triangulations in 12
![Page 14: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/14.jpg)
Point location, insertion, removal
Triangulations in 13
![Page 15: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/15.jpg)
Flip
Triangulations in 14
![Page 16: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/16.jpg)
Additional functionalities for Delaunay triangulations
Nearest neighbor queries
Voronoi diagram
Triangulations in 15
![Page 17: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/17.jpg)
Additional functionalities for [Delaunay] constrainedtriangulations
Insertion and deletion of constraints
Triangulations in 16
![Page 18: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/18.jpg)
Geometry vs. Combinatorics
17
![Page 19: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/19.jpg)
Infinite vertex
Triangulation of a set of points =partition of the convex hull into simplices.
Addition of an infinite vertex−→ “triangulation” of the outsideof the convex hull.
∞
∞
∞∞
∞
∞ ∞
2D:- Any face is a triangle.- Any edge is incident to two faces.
Triangulation of Rd
'Triangulation of the topological sphere Sd.
Triangulations in 18
![Page 20: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/20.jpg)
Dimensions
triangulateda 4-dimensional
dim 0
dim 2
sphere
dim 1
dim 3
Triangulations in 19
![Page 21: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/21.jpg)
Adding a point outside the current affine hull:
From d = 1 to d = 2
∞ ∞
∞ ∞ ∞
p
∞
v(∞) v(p)
Triangulations in 20
![Page 22: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/22.jpg)
Representation
21
![Page 23: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/23.jpg)
2D
Based on faces and vertices.
i
f
neighbor(ccw(i))
cw(i)
neighbor(i)ccw(i)
neighbor(cw(i))
VertexFace handle v face
FaceVertex handle vertex[3]Face handle neighbor[3]
Edges are implicit: std::pair< f, i >where f = one of the two incident faces.
Triangulations in 22
![Page 24: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/24.jpg)
3D
v0
v1
v2
v3
n0
n1
n2
n3
VertexCell handle v cell
CellVertex handle vertex[4]Cell handle neighbor[4]
Faces are implicit: std::pair< c, i >where c = one of the two incident cells.
Edges are implicit: std::pair< u, v >where u, v = vertices.
Triangulations in 23
![Page 25: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/25.jpg)
From one face to a another
j
neighbor(i)
i
f
n = f->neighbor(i)
j = n->index(f)
ccw(j)
cw(i)
ccw(i)
cw(j)
Triangulations in 24
![Page 26: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/26.jpg)
2D - Around a vertex
i
f
cw(i)
ccw(i)
neighbor(ccw(i))
Triangulations in 25
![Page 27: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/27.jpg)
Doubly Connected Edge List
incident vertex
next
halfe
dge
opposite halfedge
halfedge previous halfedgeincident face
VertexHalfedge* vhe
FaceHalfedge* fhe
HalfedgeFace * leftVertex* sourceHalfedge* oppositeHalfedge* nextHalfedge* prev
Triangulations in 26
![Page 28: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/28.jpg)
incident vertexne
xt ha
lfedg
e
opposite halfedge
halfedge previous halfedge
incident face
i
f
neighbor(ccw(i))
cw(i)
neighbor(i)ccw(i)
neighbor(cw(i))
n vertices3n− 6 edges2n− 4 faces
DCEL CGAL TDSVertices n nEdges 4× 2× (3n− 6)Faces (2n− 4) 6× (2n− 4)Total 27n 13n
Triangulations in 27
![Page 29: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/29.jpg)
Software Design
28
![Page 30: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/30.jpg)
“Traits” classes
convex hull 2<InputIterator, OutputIterator, Traits>Polygon 2<Traits, Container>Polyhedron 3<Traits, HDS>Triangulation 2<Traits, TDS>Triangulation 3<Traits, TDS>Min circle 2<Traits>Range tree k<Traits>. . .
![Page 31: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/31.jpg)
“Traits” classes
convex hull 2<InputIterator, OutputIterator, Traits>Polygon 2<Traits, Container>Polyhedron 3<Traits, HDS>Triangulation 2<Traits, TDS>Triangulation 3<Traits, TDS>Min circle 2<Traits>Range tree k<Traits>. . .
Geometric traits classes provide:Geometric objects + predicates + constructors
![Page 32: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/32.jpg)
“Traits” classes
convex hull 2<InputIterator, OutputIterator, Traits>Polygon 2<Traits, Container>Polyhedron 3<Traits, HDS>Triangulation 2<Traits, TDS>Triangulation 3<Traits, TDS>Min circle 2<Traits>Range tree k<Traits>. . .
Geometric traits classes provide:Geometric objects + predicates + constructors
Flexibility:
• The Kernel can be used as a traits class for several algorithms• Otherwise: Default traits classes provided• The user can plug his own traits class
Triangulations in 29
![Page 33: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/33.jpg)
2D Delaunay Triangulation
Requirements for a traits class:• 2D point• orientation test, in circle test
![Page 34: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/34.jpg)
2D Delaunay Triangulation
Requirements for a traits class:• 2D point• orientation test, in circle test
typedef CGAL::Exact predicates inexact constructions kernel K;typedef CGAL::Delaunay triangulation 2< K > Delaunay;
Triangulations in 30
![Page 35: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/35.jpg)
Playing with traits classes
• 3D points: coordinates (x,y, z)• orientation, in circle: on x and y coordinates
![Page 36: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/36.jpg)
Playing with traits classes
• 3D points: coordinates (x,y, z)• orientation, in circle: on x and y coordinates
typedef CGAL::Exact predicates inexact constructions kernel K;typedef CGAL::Triangulation euclidean traits xy 3< K > Traits;typedef CGAL::Delaunay triangulation 2< Traits > Terrain;
Triangulations in 31
![Page 37: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/37.jpg)
Layers
Triangulation 3< Traits, TDS >
Vertex Cell
Vertex-base
Cell-base
Geometric informationAdditional information
Data StructureCombinatoricsinsertion
TriangulationGeometrylocation
Triangulation data structure 2< Vb, Cb> ;
Vb and Cb have default values.
Triangulations in 32
![Page 38: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/38.jpg)
The base level
Concepts VertexBase and CellBase.
Provide
- Point + access function + setting
- incidence and adjacency relations (access and setting)
Several models, parameterised by the traits class.
Triangulations in 33
![Page 39: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/39.jpg)
Using the Triangulation packages
34
![Page 40: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/40.jpg)
A look at the User Manual
Representation, classes,. . .
Triangulations in 35
![Page 41: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/41.jpg)
A look at the Reference Manual
Locate type
locate
Triangulations in 36
![Page 42: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/42.jpg)
• Along a straight line
2 (/3) orientation testsper triangle (/tetrahedron)
degenerate cases
• By visibility
< 1.5 (/2) tests per triangle(/tetrahedron)
Breaking cycles: random choice of the neighbor
Triangulations in 37
![Page 43: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/43.jpg)
First example
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>#include <CGAL/Triangulation_3.h>
#include <iostream>#include <fstream>#include <cassert>#include <list>#include <vector>
struct K : CGAL::Exact_predicates_inexact_constructions_kernel {};
typedef CGAL::Triangulation_3<K> Triangulation;
typedef Triangulation::Cell_handle Cell_handle;typedef Triangulation::Vertex_handle Vertex_handle;typedef Triangulation::Locate_type Locate_type;typedef Triangulation::Point Point;
Triangulations in 38
![Page 44: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/44.jpg)
int main(){std::list<Point> L;L.push_front(Point(0,0,0));L.push_front(Point(1,0,0));L.push_front(Point(0,1,0));
Triangulation T(L.begin(), L.end());
int n = T.number_of_vertices();
std::vector<Point> V(3);V[0] = Point(0,0,1);V[1] = Point(1,1,1);V[2] = Point(2,2,2);
n = n + T.insert(V.begin(), V.end());
assert( n == 6 );assert( T.is_valid() );
Triangulations in 39
![Page 45: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/45.jpg)
Locate_type lt;int li, lj;Point p(0,0,0);Cell_handle c = T.locate(p, lt, li, lj);assert( lt == Triangulation::VERTEX );assert( c->vertex(li)->point() == p );
Vertex_handle v = c->vertex( (li+1)&3 );Cell_handle nc = c->neighbor(li);int nli;assert( nc->has_vertex( v, nli ) );
std::ofstream oFileT("output",std::ios::out);oFileT << T;Triangulation T1;std::ifstream iFileT("output",std::ios::in);iFileT >> T1;assert( T1.is_valid() );assert( T1.number_of_vertices() == T.number_of_vertices() );assert( T1.number_of_cells() == T.number_of_cells() );return 0;
}
Triangulations in 40
![Page 46: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/46.jpg)
Using the Delaunay Hierarchy
Location structure
1/α
Triangulations in 41
![Page 47: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/47.jpg)
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>#include <CGAL/Delaunay_triangulation_3.h>#include <CGAL/Triangulation_hierarchy_3.h>
#include <cassert>#include <vector>
struct K : CGAL::Exact_predicates_inexact_constructions_kernel {};
typedef CGAL::Triangulation_vertex_base_3<K> Vb;typedef CGAL::Triangulation_hierarchy_vertex_base_3<Vb> Vbh;typedef CGAL::Triangulation_data_structure_3<Vbh> Tds;typedef CGAL::Delaunay_triangulation_3<K,Tds> Dt;typedef CGAL::Triangulation_hierarchy_3<Dt> Dh;
typedef Dh::Vertex_iterator Vertex_iterator;typedef Dh::Vertex_handle Vertex_handle;typedef Dh::Point Point;
Triangulations in 42
![Page 48: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/48.jpg)
int main(){Dh T;
// insertion of points on a 3D gridstd::vector<Vertex_handle> V;
for (int z=0 ; z<5 ; z++)for (int y=0 ; y<5 ; y++)for (int x=0 ; x<5 ; x++)
V.push_back(T.insert(Point(x,y,z)));
assert( T.is_valid() );assert( T.number_of_vertices() == 125 );assert( T.dimension() == 3 );
// removal of the vertices in random orderstd::random_shuffle(V.begin(), V.end());
for (int i=0; i<125; ++i)T.remove(V[i]);
Triangulations in 43
![Page 49: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/49.jpg)
assert( T.is_valid() );assert( T.number_of_vertices() == 0 );
return 0;}
Triangulations in 44
![Page 50: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/50.jpg)
More flexibility
45
![Page 51: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/51.jpg)
Changing the Vertex base and the Cell base
OptionalUser
AdditionsUserVB UserCB
Derivation
TemplateParameters
Types
Tri
angu
latio
n
Tri
angu
latio
nD
ata
Stru
ctur
e
GeometricFunctionality
CombinatorialFunctionality
GeometricTraits
Vertex Cell
CellBaseVertexBase
Triangulations in 46
![Page 52: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/52.jpg)
First option: Triangulation vertex base with info 3
When the additional information does not depend on the TDS.
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>#include <CGAL/Delaunay_triangulation_3.h>#include <CGAL/Triangulation_vertex_base_with_info_3.h>#include <CGAL/IO/Color.h>
struct K : CGAL::Exact_predicates_inexact_constructions_kernel {};
typedef CGAL::Triangulation_vertex_base_with_info_3<CGAL::Color,K> Vb;
typedef CGAL::Triangulation_data_structure_3<Vb> Tds;typedef CGAL::Delaunay_triangulation_3<K, Tds> Delaunay;
typedef Delaunay::Point Point;
int main(){Delaunay T;
Triangulations in 47
![Page 53: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/53.jpg)
T.insert(Point(0,0,0));T.insert(Point(1,0,0));T.insert(Point(0,1,0));T.insert(Point(0,0,1));T.insert(Point(2,2,2));T.insert(Point(-1,0,1));
// Set the color of finite vertices of degree 6 to red.Delaunay::Finite_vertices_iterator vit;
for (vit = T.finite_vertices_begin();vit != T.finite_vertices_end(); ++vit)
if (T.degree(vit) == 6)vit->info() = CGAL::RED;
return 0;}
Triangulations in 48
![Page 54: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/54.jpg)
Third option: write new models of the concepts
![Page 55: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/55.jpg)
Third option: write new models of the concepts
Second option: the “rebind” mechanism
• Vertex and cell base classes: initially given a dummy TDS template parameter:
dummy TD provides the types that can be used by the vertex and cell base classes(such as handles).
• inside the TDS itself, vertex and cell base classes are rebound to the real TDStype
→ the same vertex and cell base classes are now parameterized with the realTDS instead of the dummy one.
Triangulations in 49
![Page 56: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/56.jpg)
Derivation
Optional Userand/or Geometric
Additions
Tri
angu
latio
n D
ata
Stru
ctur
e
Vertex CellTypes
Derivation
Template parameters
DSVertexBase<TDS=Dummy> DSCellBase<TDS=Dummy>
UserVB<...,DSVB<TDS=Self> > UserCB<...,DSCB<TDS=Self> >
Rebind_TDS
UserVB<...,DSVB<TDS=Dummy> > UserCB<...,DSCB<TDS=Dummy> >
Triangulations in 50
![Page 57: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/57.jpg)
...template < class GT, class Vb = Triangulation_vertex_base<GT> >class My_vertex: public Vb
{public:typedef typename Vb::Point Point;typedef typename Vb::Cell_handle Cell_handle;
template < class TDS2 >struct Rebind_TDS {typedef typename Vb::template Rebind_TDS<TDS2>::Other Vb2;typedef My_vertex<GT, Vb2> Other;
};
My_vertex() {}My_vertex(const Point&p) : Vb(p) {}My_vertex(const Point&p, Cell_handle c) : Vb(p, c) {}
...}
Triangulations in 51
![Page 58: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/58.jpg)
Example
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>#include <CGAL/Delaunay_triangulation_3.h>#include <CGAL/Triangulation_vertex_base_3.h>
template < class GT, class Vb=CGAL::Triangulation_vertex_base_3<GT> >class My_vertex_base: public Vb
{public:typedef typename Vb::Vertex_handle Vertex_handle;typedef typename Vb::Cell_handle Cell_handle;typedef typename Vb::Point Point;
template < class TDS2 >struct Rebind_TDS {typedef typename Vb::template Rebind_TDS<TDS2>::Other Vb2;typedef My_vertex_base<GT, Vb2> Other;
};
My_vertex_base() {}
Triangulations in 52
![Page 59: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/59.jpg)
My_vertex_base(const Point& p): Vb(p) {}
My_vertex_base(const Point& p, Cell_handle c): Vb(p, c) {}
Vertex_handle vh;Cell_handle ch;
};
struct K : CGAL::Exact_predicates_inexact_constructions_kernel {};
typedef CGAL::Triangulation_data_structure_3<My_vertex_base<K> > Tds;typedef CGAL::Delaunay_triangulation_3<K, Tds> Delaunay;
typedef Delaunay::Vertex_handle Vertex_handle;typedef Delaunay::Point Point;
Triangulations in 53
![Page 60: Monique Teillaud - LORIA · • Vertex and cell base classes: initially given a dummy TDS template parameter: dummy TD provides the types that can be used by the vertex and cell base](https://reader034.vdocuments.us/reader034/viewer/2022042121/5e9ad1abb74b016a9d7e5cca/html5/thumbnails/60.jpg)
int main(){Delaunay T;
Vertex_handle v0 = T.insert(Point(0,0,0));Vertex_handle v1 = T.insert(Point(1,0,0));Vertex_handle v2 = T.insert(Point(0,1,0));Vertex_handle v3 = T.insert(Point(0,0,1));Vertex_handle v4 = T.insert(Point(2,2,2));Vertex_handle v5 = T.insert(Point(-1,0,1));
// Now we can link the vertices as we like.v0->vh = v1;v1->vh = v2;v2->vh = v3;v3->vh = v4;v4->vh = v5;v5->vh = v0;
return 0;}
Triangulations in 54