320 likes | 458 Views
CGAL. The Computational Geometry Algorithm Library. Andreas Fabri INRIA Sophia-Antipolis. European Project CGAL. Started in 1996 as joined project of: ETH Zurich, INRIA, MPI für Informatik, Tel-Aviv U, Utrecht U, Trier U, FU Berlin.
E N D
CGAL The Computational Geometry Algorithm Library Andreas FabriINRIA Sophia-Antipolis
European Project CGAL Started in 1996 as joined project of: ETH Zurich, INRIA, MPI für Informatik, Tel-Aviv U, Utrecht U, Trier U, FU Berlin “Make the large body of geometric algorithms developed in the field of computational geometry available for industrial applications” Andreas Fabri, Meshing Roundtable 2001
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++ • 1500 downloads of each release • CGAL is enabling technology Andreas Fabri, Meshing Roundtable 2001
Structure of CGAL Basic Library HalfedgeDatastructure Triangulations Arrangements Convex Hull Optimisation ... • Visualization • File I/O • Number Types • Generators • STL extensions Point, Segment,... Predicates Kernel Support Library:Configuration, Assertions Andreas Fabri, Meshing Roundtable 2001
The Basic Library A collection of pearls
Triangulations • Basic, Delaunay, regular, constrained 2D • Fully dynamic data structures • Operations • point location, • traversal along a line • traversal of the triangulation Andreas Fabri, Meshing Roundtable 2001
Triangulations • Hierarchy< Triangulation > • Alpha shapes • Voronoi diagram, power diagram • k-order Voronoi diagram 2D* • Natural neighbors* • Conforming Delaunay 3D** Andreas Fabri, Meshing Roundtable 2001
Polyhedral Surface • Orientable 2-manifolds with boundary • Based on half edge data structure • Operations • Euler operations • rich low level API • HEDS is highly configurable Andreas Fabri, Meshing Roundtable 2001
Convex Hull • 2D Convex Hull • 5 algorithms for points • CH of a simple polyline • Convexity Test • Extremal Points • 3D Convex Hull • static, incremental, dynamic Andreas Fabri, Meshing Roundtable 2001
Boolean Operations on Polygons Andreas Fabri, Meshing Roundtable 2001
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,.. Andreas Fabri, Meshing Roundtable 2001
Optimization • Smallest enclosing sphere in dD • Polytope distance in dD • Smallest enclosing circle/ellipse in 2D • Rectangular p center • Smallest enclosing annulus in dD Andreas Fabri, Meshing Roundtable 2001
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* Andreas Fabri, Meshing Roundtable 2001
The Kernel Robustness by Exactness Exact but Efficient
Kernel • Point, vector, direction, segment, ray, line, triangle, circle, sphere, tetrahedron • Predicates • orientation, do_intersect, closer_than • Constructions • intersection, distance, affine transformation Andreas Fabri, Meshing Roundtable 2001
Collinear iff det(M) == 0 Collinear iff det(M) == 0 Collinear iff det(M) in [ - , ] Robustness of Predicates • Correctness through • exact arithmetic, or • exact geometric predicates and constructions • Challenge: Being exact and efficient Andreas Fabri, Meshing Roundtable 2001
Exact Arithmetic • exact number types • integers: GMP_Z, leda_integer • rationals: Quotient<IntegerType> , MP_Float • reals: Core, leda_real • Leads to unacceptable slowdown Andreas Fabri, Meshing Roundtable 2001
Fast Exact Predicates • Filtered arithmetic predicate • Filtered geometric predicate • Principle • interval arithmetic • fast inexact but certified computation • if filter fails: slow exact computation Andreas Fabri, Meshing Roundtable 2001
S construct Q S Fast Exact Constructions • Store history of computation in a DAG of geometric constructions* P1 P2 P1 P2 intersect intersect S2 S1 S4 S3 S1 S2 S3 S4 Andreas Fabri, Meshing Roundtable 2001
Library Design Let’s play Lego
Design Goals • Offer trade-off between • robustness and efficiency • flexibility and ease of use • Technical decision • C++ class library • Generic programming paradigm [Musser89] Andreas Fabri, Meshing Roundtable 2001
Generic Programming float min(float a, float b) int min(int a, int b) template < CompType> 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 Andreas Fabri, Meshing Roundtable 2001
Cartesian Homogeneous Parameterization in the Kernel Point int double gmpz Quotient<gmpz> MP_Float typedef Cartesian <double> C; typedef Filtered_kernel<C> K; typedef K::Point_3 Point; Andreas Fabri, Meshing Roundtable 2001
A Third Party Code Problem How to use ucb_Delaunay(ucb_list< ucb_point >) cmu::AlphaHull(cmu::PointList) in your application class point Andreas Fabri, Meshing Roundtable 2001
Geometry as Parameter • Works with CGAL kernels • Works with projections kernels • Write thin glue layer for your kernel template < Geometry > class Delaunay_triangulation_2 { void insert(Geometry::Point t) { if(Geometry::orientation(p,q,t)==..) if(Geometry::incircle(p,q,r,t)) } }; Andreas Fabri, Meshing Roundtable 2001
Combinatorics as Parameter • Combinatorics allocates vertices, facets • Default data structure is facet based • It could be half edge based template < Geometry, Combinatorics > class Delaunay_triangulation_2{ void insert(Point p) { .. Facet v = Combinatorics::create_facet(); .. } }; Andreas Fabri, Meshing Roundtable 2001
Iterators and Circulators • A concept: generalisation of pointers • Decouple algorithms and datastructures template < Geometry, Combinatorics > class Delaunay_triangulation_2 { template < Iterator > void insert(Iterator begin, Iterator end) { Point p = *begin; ++begin; ..} Vertex_iterator vertices_begin(){..} }; Andreas Fabri, Meshing Roundtable 2001
Hello Triangle #include <CGAL/Cartesian.h> #include <CGAL/Triangulation_2.h> typedef Cartesian< double> Geometry; typedef Triangulation_2< Geometry> 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 << vc->point(); } while(++vc != done); } Andreas Fabri, Meshing Roundtable 2001
Robust and Fast Hello Triangle #include <CGAL/Cartesian.h> #include <CGAL/Filtered_kernel.h> #include <CGAL/Triangulation_2.h> typedef Cartesian< double> K; typedef Filtered_kernel< K > Geometry; typedef Triangulation_2< Geometry> T; typedef Triangulation_hierarchy_2< T > 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 << vc->point(); } while(++vc != done); } Andreas Fabri, Meshing Roundtable 2001
Points in a Coordinate Array #include <CGAL/Cartesian.h> #include <CGAL/Delaunay_triangulation_3.h> typedef CGAL::Cartesian<double> Geometry; typedef CGAL::Triangulation_cell_base_3<Geometry> Cell; typedef CGAL::Triangulation_vertex_base_pointer_3<Geometry> Vertex; typedef CGAL::Triangulation_data_structure_3<Vertex, Cell> Combinatorics; typedef CGAL::Delaunay_triangulation_3<Geometry, Combinatorics> 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; } Andreas Fabri, Meshing Roundtable 2001
The C++ is Slow Myth • std::sort is faster than clib sort • Delaunay 3D • 51,095 points, 340,275 cells in 11.176 sec. • 2 mio points, in 156 sec, P3 1Ghz • HPC projects Blitz++ Andreas Fabri, Meshing Roundtable 2001
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 Andreas Fabri, Meshing Roundtable 2001