The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL
Andreas Fabri, Meshing Roundtable European Project CGAL “Make the large body of geometric algorithms developed in the field of computational geometry available for industrial applications” Started in 1996 as joined project of: ETH Zurich, INRIA, MPI für Informatik, Tel-Aviv U, Utrecht U, Trier U, FU Berlin
CGALAndreas Fabri, Meshing Roundtable The CGAL Class Library 1200 C++ classes, 300 KLOC, 1100 p manual 40 developer years Supported Platforms –Irix 6.5 / SGI Mips CC 7.3, g++ –Solaris 2.6 / KCC, g++ –Wintel/ VC++6.0, Borland C++5.0, g downloads of each release CGAL is enabling technology
CGALAndreas Fabri, Meshing Roundtable Basic Library Structure of CGAL Support Library: Configuration, Assertions Visualization File I/O Number Types Generators STL extensions Point, Segment,... Predicates Kernel TriangulationsArrangements Halfedge Datastructure Convex HullOptimisation...
The Basic Library A collection of pearls
CGALAndreas Fabri, Meshing Roundtable Triangulations Basic, Delaunay, regular, constrained 2D Fully dynamic data structures Operations –point location, –traversal along a line –traversal of the triangulation
CGALAndreas Fabri, Meshing Roundtable Triangulations Hierarchy Alpha shapes Voronoi diagram, power diagram k-order Voronoi diagram 2D* Natural neighbors* Conforming Delaunay 3D**
CGALAndreas Fabri, Meshing Roundtable Polyhedral Surface Orientable 2-manifolds with boundary Based on half edge data structure Operations –Euler operations –rich low level API HEDS is highly configurable
CGALAndreas Fabri, Meshing Roundtable Convex Hull 2D Convex Hull –5 algorithms for points –CH of a simple polyline Convexity Test Extremal Points 3D Convex Hull –static, incremental, dynamic
CGALAndreas Fabri, Meshing Roundtable Boolean Operations on Polygons
CGALAndreas Fabri, Meshing Roundtable Planar Subdivisions Framework for arrangements of 2D curves –based on planar maps –based on topological maps –Models exist for polylines, circles, conic arcs Operations –point location, overlay, ray shooting,..
CGALAndreas Fabri, Meshing Roundtable Optimization Smallest enclosing sphere in dD Polytope distance in dD Smallest enclosing circle/ellipse in 2D Rectangular p center Smallest enclosing annulus in dD
CGALAndreas Fabri, Meshing Roundtable and... Polygon decomposition Boolean operations on polyhedra ** Range trees, segment trees, kd-trees Visibility complex 2* Plane sweep framework* Largest empty rectangle* Smallest enclosing sphere of spheres*
The Kernel Robustness by Exactness Exact but Efficient
CGALAndreas Fabri, Meshing Roundtable Kernel Point, vector, direction, segment, ray, line, triangle, circle, sphere, tetrahedron Predicates –orientation, do_intersect, closer_than Constructions –intersection, distance, affine transformation
CGALAndreas Fabri, Meshing Roundtable Robustness of Predicates Correctness through –exact arithmetic, or –exact geometric predicates and constructions Challenge: Being exact and efficient Collinear iff det(M) == 0 Collinear iff det(M) in [ - , ] Collinear iff det(M) == 0
CGALAndreas Fabri, Meshing Roundtable Exact Arithmetic exact number types –integers: GMP_Z, leda_integer –rationals: Quotient, MP_Float –reals: Core, leda_real Leads to unacceptable slowdown
CGALAndreas Fabri, Meshing Roundtable Fast Exact Predicates Filtered arithmetic predicate Filtered geometric predicate Principle –interval arithmetic –fast inexact but certified computation –if filter fails: slow exact computation
CGALAndreas Fabri, Meshing Roundtable Fast Exact Constructions Store history of computation in a DAG of geometric constructions* S2 S1 S4 S3 S1 P2 P1 P2 P1 Q S2S3S4 intersect construct S S
Library Design Let’s play Lego
CGALAndreas Fabri, Meshing Roundtable Design Goals Offer trade-off between –robustness and efficiency –flexibility and ease of use Technical decision –C++ class library –Generic programming paradigm [Musser89]
CGALAndreas Fabri, Meshing Roundtable int min(int a, int b) float min(float a, float b) template CompType min(CompType a, CompType b) { return (a<b) ? a : b; } BigInt n(9), m(8), r; r = min( n, m ); BigInt is a model for the concept CompType Generic Programming
CGALAndreas Fabri, Meshing Roundtable Parameterization in the Kernel Point CartesianHomogeneous double Quotient MP_Float int gmpz typedef Cartesian C; typedef Filtered_kernel K; typedef K::Point_3 Point;
CGALAndreas Fabri, Meshing Roundtable How to use ucb_Delaunay(ucb_list ) cmu::AlphaHull(cmu::PointList) in your application class point A Third Party Code Problem
CGALAndreas Fabri, Meshing Roundtable template class Delaunay_triangulation_2 { void insert(Geometry::Point t) { if(Geometry::orientation(p,q,t)==..) if(Geometry::incircle(p,q,r,t)) } }; Geometry as Parameter Works with CGAL kernels Works with projections kernels Write thin glue layer for your kernel
CGALAndreas Fabri, Meshing Roundtable Combinatorics as Parameter template class Delaunay_triangulation_2{ void insert(Point p) {.. Facet v = Combinatorics::create_facet();.. } }; Combinatorics allocates vertices, facets –Default data structure is facet based –It could be half edge based
CGALAndreas Fabri, Meshing Roundtable Iterators and Circulators A concept: generalisation of pointers Decouple algorithms and datastructures template class Delaunay_triangulation_2 { template void insert(Iterator begin, Iterator end) { Point p = *begin; ++begin;..} Vertex_iterator vertices_begin(){..} };
CGALAndreas Fabri, Meshing Roundtable Hello Triangle #include typedef Cartesian Geometry; typedef Triangulation_2 Triangulation ; typedef Triangulation::Vertex_circulator Vertex_circulator; typedef Geometry::Point_2 Point; int main() { Triangulation t; Point p; while (cin >> p) { t.insert(p); } Vertex_circulator vc = t.incident_vertices(t.infinite_vertex()), done(vc); do{ cout point(); } while(++vc != done); }
CGALAndreas Fabri, Meshing Roundtable Robust and Fast Hello Triangle #include typedef Cartesian K; typedef Filtered_kernel Geometry; typedef Triangulation_2 T; typedef Triangulation_hierarchy_2 Triangulation; typedef Triangulation::Vertex_circulator Vertex_circulator; typedef Geometry::Point_2 Point; int main() { Triangulation t; Point p; while (cin >> p) { t.insert(p); } Vertex_circulator vc = t.incident_vertices(t.infinite_vertex()), done(vc); do{ cout point(); } while(++vc != done); }
CGALAndreas Fabri, Meshing Roundtable Points in a Coordinate Array #include typedef CGAL::Cartesian Geometry; typedef CGAL::Triangulation_cell_base_3 Cell; typedef CGAL::Triangulation_vertex_base_pointer_3 Vertex; typedef CGAL::Triangulation_data_structure_3 Combinatorics; typedef CGAL::Delaunay_triangulation_3 Triangulation; typedef Geometry::Point_3 Point; double xyz[4][4] = { {0,0,0, 6}, {3,0,0, 5}, {0,4,0, 9.3}, {2,2,2, 0.1}}; int main( ) { Triangulation t; for(int i=0; i < 4; i++) { t.insert((Point&) (*xyz[i])); } return 0; }
CGALAndreas Fabri, Meshing Roundtable The C++ is Slow Myth std::sort is faster than clib sort Delaunay 3D –51,095 points, 340,275 cells in sec. –2 mio points, in 156 sec, P3 1Ghz HPC projects Blitz++
CGALAndreas Fabri, Meshing Roundtable GeometryFactory Library has reached a critical mass Acceptance of exact computing paradigm Maturity of compilers Acceptance of generic programming (STL) The right moment to found a company