computational geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 ·...

31
Computational Geometry Efi Fogel Tel Aviv University Computational Geometry Algorithm Library Dec. 19 th , 2016

Upload: others

Post on 09-Aug-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Computational Geometry

Efi Fogel

Tel Aviv University

Computational Geometry Algorithm LibraryDec. 19th, 2016

Page 2: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Outline

1 CgalIntroductionContentLiteratureGeometry FactoryDetails

Computational Geometry 2

Page 3: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Outline

1 CgalIntroductionContentLiteratureGeometry FactoryDetails

Computational Geometry 3

Page 4: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Cgal: Mission

“Make the large body of geometric algorithms developed in the field ofcomputational geometry available for industrial applications”

Cgal Project Proposal, 1996

Computational Geometry 4

Page 5: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Cgal Facts

Written in C++

Adheres the generic programming paradigmDevelopment started in 1995High search-engine ranking for www.cgal.orgActive European sites:

1 GeometryFactory2 INRIA Sophia Antipolis3 INRIA Nancy - Grand

Est4 INRIA Saclay - Île de

France5 CNRS - LIRIS6 CNRS - Université

Paris–Dauphin7 Tel Aviv University

8 MPII Saarbrücken9 ETH Zürich10 Universidade Federal de

Pernambuco11 University of California,

Davis12 Universitá della Svizzera

italiana13 Universidade Federal do

Rio de Janeiro

Computational Geometry 5

Page 6: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Cgal in Numbers

600,000 lines of C++ code10,000 downloads per year not including Linux distributions4,500 manual pages (user and reference manual)1,000 subscribers to user mailing list200 commercial users120 packages30 active developers6 months release cycle2 licenses: Open Source and commercial

Computational Geometry 6

Page 7: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Cgal HistoryYear Version Released Other Milestones1996 Cgal founded1998 July 1.11999 Work continued after end of European support2001 Aug 2.3 Editorial Board established2002 May 2.42003 Nov 3.0 Geometry Factory founded2004 Dec 3.120052006 May 3.22007 Jun 3.32008 CMake2009 Jan 3.4, Oct 3.52010 Mar 3.6, Oct 3.7 Google Summer of Code (GSoC) 20102011 Apr 3.8, Aug 3.9 GSoC 20112012 Mar 4.0, Oct 4.1 GSoC 20122013 Mar 4.2, Oct 4.3 GSoC 2013, Doxygen2014 Apr 4.4, Oct 4.5 GSoC 20142015 Apr 4.6, Oct 4.7 GitHub, HTML5, Main repository made public2016 Apr 4.8, Sep 4.9 20th anniversary

Computational Geometry 7

Page 8: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Cgal Properties

ReliabilityExplicitly handles degeneraciesFollows the Exact Geometric Computation (EGC) paradigm

EfficiencyDepends on leading 3rd party libraries

F e.g., Boost, Gmp, Mpfr, Qt, Eigen, Tbb, and CoreAdheres to the generic-programming paradigm

F Polymorphism is resolved at compile time

The best of both worlds

Computational Geometry 8

Page 9: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Cgal Properties, Cont

FlexibilityAn open source libraryAdaptable, e.g., graph algorithms can directly be applied to Cgal datastructuresExtensible, e.g., data structures can be extended

Ease of UseHas didactic and exhaustive ManualsFollows standard concepts (e.g., C++ and Stl)Has a modular structure, e.g., geometry and topology are separatedCharacterizes with a smooth learning-curve

Computational Geometry 9

Page 10: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Outline

1 CgalIntroductionContentLiteratureGeometry FactoryDetails

Computational Geometry 10

Page 11: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

2D Algorithms and Data Structures

Triangulations Mesh Generation Polyline Simplification Voronoi Diagrams

Arrangements Boolean Operations Neighborhood Queries Minkowski Sums Straight Skeleton

Computational Geometry 11

Page 12: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

3D Algorithms and Data Structures

Triangulations Mesh Generation Polyhedral Surface Deformation Boolean Operations

Mesh Simplification Skeleton Segmentation Classification Hole Filling

Computational Geometry 12

Page 13: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Outline

1 CgalIntroductionContentLiteratureGeometry FactoryDetails

Computational Geometry 13

Page 14: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Cgal Bibliography I

The Cgal Project.Cgal User and Reference Manual.Cgal Editorial Board, 4.4 edition, 2014. http://doc.cgal.org/4.2/CGAL.CGAL/html/index.html .

Efi Fogel, Ron Wein, and Dan Halperin.Cgal Arrangements and Their Applications, A Step-by-Step Guide.Springer, 2012.

Mario Botsch, Leif Kobbelt, Mark Pauly, Pierre Alliez, and Bruno Levy.Polygon Mesh Processing.CRC Press, 2010.

A. Fabri, G.-J. Giezeman, L. Kettner, S. Schirra, and S. Schönherr.On the design of Cgal a computational geometry algorithms library.Software — Practice and Experience, 30(11):1167–1202, 2000. Special Issue on Discrete AlgorithmEngineering.

A. Fabri and S. Pion.A generic lazy evaluation scheme for exact geometric computations.In 2nd Library-Centric Software Design Workshop, 2006.

M. H. Overmars.Designing the computational geometry algorithms library Cgal.In Proceedings of ACM Workshop on Applied Computational Geometry, Towards GeometricEngineering, volume 1148, pages 53–58, London, UK, 1996. Springer.

Many Many Many papers

Computational Geometry 14

Page 15: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Outline

1 CgalIntroductionContentLiteratureGeometry FactoryDetails

Computational Geometry 15

Page 16: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Some Cgal Commercial Customers

Computational Geometry 16

Page 17: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Cgal Commercial Customers, Geographic Segmentation

Computational Geometry 17

Page 18: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Outline

1 CgalIntroductionContentLiteratureGeometry FactoryDetails

Computational Geometry 18

Page 19: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Cgal Structure

Basic LibraryAlgorithms and Data Structurese.g., Triangulations, Surfaces, and Arrangements

KernelElementary geometric objectsElementary geometric computations on them

Support Library

Configurations, Assertions,...

VisualizationFilesI/O

Number TypesGenerators

Computational Geometry 19

Page 20: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Cgal Kernel Concept

Geometric objects of constant size.Geometric operations on object of constant size.

Primitives 2D, 3D, dD OperationsPredicates Constructions

point comparison intersectionvector orientation squared distancetriangle containment . . .iso rectangle . . .circle

. . .

Computational Geometry 20

Page 21: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Cgal Kernel Affine Geometry

point - origin → vectorpoint - point → vectorpoint + vector → point

point + point ← Illegalmidpoint(a,b) = a+1/2× (b−a)

Computational Geometry 21

Page 22: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Cgal Kernel Classification

Dimension: 2, 3, arbitraryNumber types:

Ring: +,−,×Euclidean ring (adds integer division and gcd) (e.g., CGAL : : Gmpz).Field: +,−,×,/ (e.g., CGAL : : Gmpq).Exact sign evaluation for expressions with roots (F i e l d_w i th_sq r ).

Coordinate representationCartesian — requires a field number type or Euclidean ring if noconstructions are performed.Homegeneous — requires Euclidean ring.

Reference countingExact, Filtered

Computational Geometry 22

Page 23: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Cgal Kernels and Number Types

Cartesian representation Homogeneous representation

point∣∣∣∣ x = hx

hwy = hy

hwpoint

∣∣∣∣∣∣hxhyhw

Intersection of two lines{a1x +b1y + c1 = 0a2x +b2y + c2 = 0

{a1hx +b1hy + c1hw = 0a2hx +b2hy + c2hw = 0

(x ,y) = (hx ,hy ,hw) =∣∣∣∣∣ b1 c1

b2 c2

∣∣∣∣∣∣∣∣∣∣ a1 b1a2 b2

∣∣∣∣∣,−

∣∣∣∣∣ a1 c1a2 c2

∣∣∣∣∣∣∣∣∣∣ a1 b1a2 b2

∣∣∣∣∣

(∣∣∣∣ b1 c1b2 c2

∣∣∣∣ ,− ∣∣∣∣ a1 c1a2 c2

∣∣∣∣ , ∣∣∣∣ a1 b1a2 b2

∣∣∣∣)

Field operations Ring operations

Computational Geometry 23

Page 24: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Example: Ke rne l s<NumberType>

Ca r t e s i a n <FieldNumberType>t y p ed e f CGAL : : Ca r t e s i a n <Gmpq> Kerne l ;t y p ed e f CGAL : : S imp l e_ca r t e s i an<double> Kerne l ;

F No reference-counting, inexact instantiationHomogeneous<RingNumberType>

t y pd e f CGAL : : Homogeneous<Core : : B ig In t> Kerne l ;d-dimensional Ca r t e s i an_d and Homogeneous_dTypes + Operations

Kerne l : : Point_2, Ke rne l : : Segment_3Ke rne l : : Less_xy_2, Ke rne l : : Con s t r u c t_b i s e c t o r_3

Computational Geometry 24

Page 25: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Cgal Numerical Issues� �t y p ed e f CGAL : : Ca r t e s i an <NT> Kerne l ;NT sq r t 2 = s q r t (NT( 2 ) ) ;

Ke rne l : : Point_2 p (0 , 0 ) , q ( sq r t2 , s q r t 2 ) ;Ke rne l : : C i r c l e_2 C(p , 4 ) ;

a s s e r t (C . has_on_boundary ( q ) ) ;� �OK if NT supports exact sqrt.Assertion violation otherwise.

p

qC

Computational Geometry 25

Page 26: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Cgal Pre-defined Cartesian Kernels

Support construction of points from doub l e Cartesian coordinates.Support exact geometric predicates.Handle geometric constructions differently:

CGAL : : E x a c t_p r e d i c a t e s_ i n e x a c t_ c on s t r u c t i o n s_k e r n e lF Geometric constructions may be inexact due to round-off errors.F It is however more efficient and sufficient for most Cgal algorithms.

CGAL : : E x a c t_p r e d i c a t e s_e x a c t_con s t r u c t i o n s_k e r n e lCGAL : : E x a c t_p r ed i c a t e s_e xa c t_con s t r u c t i o n s_ke r n e l_w i t h_ sq r t

F Its number type supports the exact square-root operation.

Computational Geometry 26

Page 27: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Cgal Special Kernels

Filtered kernels2D circular kernel3D spherical kernel

Refer to Cgal’s manual for more details.

Computational Geometry 27

Page 28: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Computing the Orientationimperative style� �#i n c l u d e <CGAL/ Exa c t_p r e d i c a t e s_ i n e x a c t_ c on s t r u c t i o n s_k e r n e l . h>

t yp ed e f CGAL : : E x a c t_p r e d i c a t e s_ i n e x a c t_ c on s t r u c t i o n s_k e r n e l Ke rne l ;t y p ed e f Ke rne l : : Point_2 Point_2 ;

i n t main ( ){

Point_2 p (0 , 0 ) , q (10 , 3 ) , r ( 1 2 , 1 9 ) ;r e t u r n (CGAL : : o r i e n t a t i o n (q , p , r ) == CGAL : : LEFT_TURN) ? 0 : 1 ;

}� �precative style� �#i n c l u d e <CGAL/ Exa c t_p r e d i c a t e s_ i n e x a c t_ c on s t r u c t i o n s_k e r n e l . h>

t yp ed e f CGAL : : E x a c t_p r e d i c a t e s_ i n e x a c t_ c on s t r u c t i o n s_k e r n e l Ke rne l ;t y p ed e f Ke rne l : : Point_2 Point_2 ;t y p ed e f Ke rne l : : O r i en t a t i on_2 Or i en t a t i on_2 ;

i n t main ( ){

Ke rne l k e r n e l ;O r i en t a t i on_2 o r i e n t a t i o n = k e r n e l . o r i e n t a t i o n_2_ob j e c t ( ) ;

Point_2 p (0 , 0 ) , q (10 , 3 ) , r ( 1 2 , 1 9 ) ;r e t u r n ( o r i e n t a t i o n (q , p , r ) == CGAL : : LEFT_TURN) ? 0 : 1 ;

}� �Computational Geometry 28

Page 29: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Computing the Intersection

� �#i n c l u d e <CGAL/ Exa c t_p r e d i c a t e s_ i n e x a c t_ c on s t r u c t i o n s_k e r n e l . h>#i n c l u d e <CGAL/ i n t e r s e c t i o n s . h>

t yp ed e f CGAL : : E x a c t_p r e d i c a t e s_ i n e x a c t_ c on s t r u c t i o n s_k e r n e l Ke rne l ;t y p ed e f Ke rne l : : Point_2 Point_2 ;t y p ed e f Ke rne l : : Segment_2 Segment_2 ;t y p ed e f Ke rne l : : L ine_2 Line_2 ;

i n t main ( ) {Point_2 p (1 , 1 ) , q ( 2 , 3 ) , r ( −12 ,19) ;Line_2 l i n e (p , q ) ;Segment_2 seg ( r , p ) ;auto r e s u l t = CGAL : : i n t e r s e c t i o n ( seg , l i n ) ;i f ( r e s u l t ) {

i f ( con s t Segment_2∗ s = boos t : : get<Segment_2>(&∗ r e s u l t ) ) {// hand l e segment

}e l s e {

cons t Point_2∗ p = boos t : : get<Point_2>(&∗ r e s u l t ) ;// hand l e po i n t

}}r e t u r n 0 ;

}� �Computational Geometry 29

Page 30: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Cgal Basic Library

Generic data structures are parameterized with TraitsSeparates algorithms and data structures from the geometric kernel.

Generic algorithms are parameterized with iterator rangesDecouples the algorithm from the data structure.

Computational Geometry 30

Page 31: Computational Geometryacg.cs.tau.ac.il/courses/computational-geometry/fall... · 2016-12-29 · Cgal History Year VersionReleased OtherMilestones 1996 Cgal founded 1998 July1.1 1999

Cgal Components Developed at Tel Aviv University

2D Arrangements2D Regularized Boolean Set-Operations2D Minkowski Sums2D Envelopes3D Envelopes2D Snap RoundingInscribed Areas / 2D Largest empty iso rectangle

Computational Geometry 31