the computational geometry algorithm library andreas fabri inria sophia-antipolis cgal

32
The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

Upload: jared-dorsey

Post on 18-Jan-2018

220 views

Category:

Documents


0 download

DESCRIPTION

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

TRANSCRIPT

Page 1: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

The Computational Geometry Algorithm Library

Andreas FabriINRIA Sophia-Antipolis

CGAL

Page 2: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

2

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

Page 3: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

3

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

Page 4: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

4

Basic Library

Structure of CGAL

Support Library: Configuration, Assertions

• Visualization• File I/O• Number Types• Generators• STL extensions

Point, Segment,... Predicates

Kernel

Tria

ngul

atio

ns

Arr

ange

men

ts

Hal

fedg

eD

atas

truct

ure

Con

vex

Hul

l

Opt

imis

atio

n

...

Page 5: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

The Basic Library

A collection of pearls

Page 6: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

6

Triangulations• Basic, Delaunay, regular, constrained

2D

• Fully dynamic data structures

• Operations– point location, – traversal along a line– traversal of the triangulation

Page 7: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

7

Triangulations• Hierarchy< Triangulation >• Alpha shapes• Voronoi diagram, power diagram

• k-order Voronoi diagram 2D*• Natural neighbors*• Conforming Delaunay 3D**

Page 8: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

8

Polyhedral Surface• Orientable 2-manifolds with

boundary• Based on half edge data structure

• Operations– Euler operations – rich low level API

• HEDS is highly configurable

Page 9: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

9

Convex Hull• 2D Convex Hull

– 5 algorithms for points– CH of a simple polyline

• Convexity Test• Extremal Points

• 3D Convex Hull– static, incremental, dynamic

Page 10: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

10

Boolean Operations on Polygons

Page 11: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

11

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,..

Page 12: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

12

Optimization• Smallest enclosing

sphere in dD• Polytope distance in dD

• Smallest enclosing circle/ellipse in 2D

• Rectangular p center• Smallest enclosing annulus in dD

Page 13: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

13

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*

Page 14: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

The Kernel

Robustness by ExactnessExact but Efficient

Page 15: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

15

Kernel

• Point, vector, direction, segment, ray, line, triangle, circle, sphere, tetrahedron

• Predicates – orientation, do_intersect, closer_than

• Constructions– intersection, distance, affine transformation

Page 16: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

16

Robustness of Predicates

• Correctness through – exact arithmetic, or– exact geometric predicates and constructions

• Challenge: Being exact and efficient

Collinear iff det(M) == 0Collinear iff det(M) in [ - , ]Collinear iff det(M) == 0

Page 17: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

17

Exact Arithmetic• exact number types

– integers: GMP_Z, leda_integer– rationals: Quotient<IntegerType> ,

MP_Float– reals: Core, leda_real

• Leads to unacceptable slowdown

Page 18: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

18

Fast Exact Predicates

• Filtered arithmetic predicate• Filtered geometric predicate

• Principle – interval arithmetic– fast inexact but certified computation– if filter fails: slow exact computation

Page 19: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

19

Fast Exact Constructions

• Store history of computation in a DAG

of geometric constructions*

S2S1 S4S3 S1

P2

P1P2

P1

Q

S2 S3 S4

intersect intersect

construct

S

S

Page 20: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

Library Design

Let’s play Lego

Page 21: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

21

Design Goals

• Offer trade-off between – robustness and efficiency– flexibility and ease of use

• Technical decision– C++ class library – Generic programming paradigm

[Musser89]

Page 22: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

22

int min(int a, int b) float min(float a, float 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

Generic Programming

Page 23: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

23

Parameterization in the Kernel

Point

Cartesian HomogeneousdoubleQuotient<gmpz>MP_Float

intgmpz

typedef Cartesian <double> C;typedef Filtered_kernel<C> K; typedef K::Point_3 Point;

Page 24: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

24

How to use

ucb_Delaunay(ucb_list< ucb_point >)cmu::AlphaHull(cmu::PointList)

in your application

class point

A Third Party Code Problem

Page 25: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

25

template < Geometry >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

Page 26: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

26

Combinatorics as Parametertemplate < Geometry, Combinatorics >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

Page 27: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

27

Iterators and Circulators• A concept: generalisation of

pointers• Decouple algorithms and

datastructurestemplate < Geometry, Combinatorics >class Delaunay_triangulation_2 {

template < Iterator > void insert(Iterator begin, Iterator end) {

Point p = *begin; ++begin;

..}

Vertex_iterator vertices_begin(){..}};

Page 28: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

28

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);}

Page 29: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

29

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);}

Page 30: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

30

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;}

Page 31: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

31

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++

Page 32: The Computational Geometry Algorithm Library Andreas Fabri INRIA Sophia-Antipolis CGAL

CGAL Andreas Fabri, Meshing Roundtable 2001

32

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