Introduction to CGAL Constantinos Tsirogiannis TU / Eindhoven - - PowerPoint PPT Presentation

introduction to cgal
SMART_READER_LITE
LIVE PREVIEW

Introduction to CGAL Constantinos Tsirogiannis TU / Eindhoven - - PowerPoint PPT Presentation

Introduction to CGAL Constantinos Tsirogiannis TU / Eindhoven Constantinos Tsirogiannis Introduction to CGAL Thursday, April 7, 2011 CGAL ? CGAL = Computational Geometry Algorithms Library: Constantinos Tsirogiannis Introduction to CGAL


slide-1
SLIDE 1

Introduction to CGAL

Constantinos Tsirogiannis

TU/Eindhoven

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-2
SLIDE 2

CGAL ? CGAL = Computational Geometry Algorithms Library:

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-3
SLIDE 3

CGAL ? CGAL = Computational Geometry Algorithms Library: A library of Geometric algorithms and data structures.

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-4
SLIDE 4

CGAL ? CGAL = Computational Geometry Algorithms Library: A library of Geometric algorithms and data structures. Written in C++

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-5
SLIDE 5

CGAL ? CGAL = Computational Geometry Algorithms Library: A library of Geometric algorithms and data structures. Written in C++ Uses template programming

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-6
SLIDE 6

C++ C++ = C + Object Oriented Programming

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-7
SLIDE 7

C++ C++ = C + Object Oriented Programming Traditional C code:

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-8
SLIDE 8

C++ C++ = C + Object Oriented Programming Traditional C code: int a=5; int b=3; add function(a,b);

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-9
SLIDE 9

C++ C++ code: int a=5; int b=3; Example class foo; foo.add(a,b);

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-10
SLIDE 10

C++ Basics

Here follow few basic concepts of C++

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-11
SLIDE 11

Classes/Structures

Class:

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-12
SLIDE 12

Classes/Structures

Class: class Example class { public: int add( int a, int b) { return a+b; } ... private: int k; };

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-13
SLIDE 13

Classes/ Structures (cont’d) Structures: same as classes, yet everything is by default visible (“public”)

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-14
SLIDE 14

Namespaces Namespace: Can be seen as a “big bag” containing declarations of class types and functions.

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-15
SLIDE 15

Namespaces Namespace: Can be seen as a “big bag” containing declarations of class types and functions. Example: namespace FOO { class something{...}; class another class{...}; struct whatever{...}; int add(int a, int b){a+b;} }

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-16
SLIDE 16

Namespace std To access the type something from a namespace FOO try:

FOO::something or typename FOO::something

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-17
SLIDE 17

Namespace std To access the type something from a namespace FOO try:

FOO::something or typename FOO::something

Namespace std contains many helpfull classes and functions of the Standard Library of C++.

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-18
SLIDE 18

Containers Nice and easy classes to insert and manipulate sets of objects.

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-19
SLIDE 19

Containers Nice and easy classes to insert and manipulate sets of objects.

Example: Vectors std::vector<int> integers; integers.push back(4); integers.push back(-2); integers.push back(9); integers.push back(3); for( int i=0; i< integers.size(); i++ ) std::cout << integers[i] << std::endl;

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-20
SLIDE 20

Iterators

An iterator is a substitute of a pointer.

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-21
SLIDE 21

Iterators

An iterator is a substitute of a pointer. Iterators are used to go through the elements of a container or some other kind of range.

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-22
SLIDE 22

Iterators

An iterator is a substitute of a pointer. Iterators are used to go through the elements of a container or some other kind of range. Example: std::vector<int> integers; integers.push back(4); integers.push back(-2); integers.push back(9); integers.push back(3); for( typename std::vector<int>::iterator it=integers.begin(); it< integers.end(); it++ ) std::cout << *it << std::endl;

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-23
SLIDE 23

Input from file

In the beginning of your .cpp file put: # include<fstream>

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-24
SLIDE 24

Input from file

In the beginning of your .cpp file put: # include<fstream> To read a set of integers from a file: std::ifstream in(‘‘filename.txt’’); std::istream iterator<int> begin(in); std::istream iterator<int> end; std::vector<int> integers; integers.insert(integers.begin(),begin,end);

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-25
SLIDE 25

Output to file

Example: std::ofstream os("filename.cout"); std::vector<int> integers; integers.push back(4); integers.push back(-2); integers.push back(9); integers.push back(3); for( typename std::vector<int>::iterator it=integers.begin(); it< integers.end(); it++ )

  • s << *it << std::endl;

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-26
SLIDE 26

Template

A template is a class or function that one can choose the types that it contains/manipulates.

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-27
SLIDE 27

Template

A template is a class or function that one can choose the types that it contains/manipulates. Example: A function that computes a power of a given integer. int power (int base, int exponent) { int res=1; for( int i=1; i<=exponent; i++ ) res = res * base; return res; }

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-28
SLIDE 28

Templates

Example: A function that computes a power of a given

  • bject of type Type.

template <class Type> Type power ( Type base, int exponent) { Type res=1; for( int i=1; i<=exponent; i++ ) res = res * base; return res; }

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-29
SLIDE 29

CGAL CGAL provides implementations of:

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-30
SLIDE 30

CGAL CGAL provides implementations of: Triangulations.

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-31
SLIDE 31

CGAL CGAL provides implementations of: Triangulations. Voronoi diagrams.

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-32
SLIDE 32

CGAL CGAL provides implementations of: Triangulations. Voronoi diagrams. Arrangements.

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-33
SLIDE 33

CGAL CGAL provides implementations of: Triangulations. Voronoi diagrams. Arrangements. Kinetic Data Structures.

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-34
SLIDE 34

CGAL CGAL provides implementations of: Triangulations. Voronoi diagrams. Arrangements. Kinetic Data Structures. . . .

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-35
SLIDE 35

CGAL Concepts

The concepts provided by CGAL are categorized as:

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-36
SLIDE 36

CGAL Concepts

The concepts provided by CGAL are categorized as:

Geometric Objects

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-37
SLIDE 37

CGAL Concepts

The concepts provided by CGAL are categorized as:

Geometric Objects Geometric Predicates/Constructions

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-38
SLIDE 38

CGAL Concepts

The concepts provided by CGAL are categorized as:

Geometric Objects Geometric Predicates/Constructions Geometric Algorithms/Data-Structures

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-39
SLIDE 39

Kernel

Geometric objects and predicates appear inside a kernel.

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-40
SLIDE 40

Kernel

Geometric objects and predicates appear inside a kernel. A kernel is more or less a large class the encapsulates

  • bjects and predicates that fall in the same general

category.

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-41
SLIDE 41

Kernel

Geometric objects and predicates appear inside a kernel. A kernel is more or less a large class the encapsulates

  • bjects and predicates that fall in the same general

category. struct Cartesian kernel { class Point {...}; class Segment {...}; class Triangle {...}; ... class Do intersect predicate {...}; };

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-42
SLIDE 42

Kernel

A kernel is in fact a template. The template parameter is a number type.

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-43
SLIDE 43

Kernel

A kernel is in fact a template. The template parameter is a number type. template <typename Num type> struct Cartesian kernel { class Point<Num type> {...}; class Segment<Num type> {...}; class Triangle<Num type> {...}; ... class Do intersect pred<Num type> {...}; };

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-44
SLIDE 44

CGAL Number types CGAL provides many different number types: Built in: int,double.

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-45
SLIDE 45

CGAL Number types CGAL provides many different number types: Built in: int,double. Arbitrary precision rationals: Gmpq,MP Float.

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-46
SLIDE 46

CGAL Number types CGAL provides many different number types: Built in: int,double. Arbitrary precision rationals: Gmpq,MP Float. Algebraic numbers: Root of 2<Type>.

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-47
SLIDE 47

Kernels

  • You can use kernels with fixed number

types such as Cartesian<double>.

Thursday, April 7, 2011

slide-48
SLIDE 48
  • Or you can use predefined “Filtered Kernels”

that provide exact predicates, and even exact constructions, if desired.

  • Filtered Kernels use less computationally

intensive number types as default, and fall back to exact computation when required.

  • Exact_predicates_exact_constructions_kernel
  • Exact_predicates_inexact_constructions_kernel

Kernels

Thursday, April 7, 2011

slide-49
SLIDE 49

Algorithms and Data Structures

The main algorithms and data-structures appear outside the kernels.

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-50
SLIDE 50

Algorithms and Data Structures

The main algorithms and data-structures appear outside the kernels. They are also templates.

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-51
SLIDE 51

Algorithms and Data Structures

The main algorithms and data-structures appear outside the kernels. They are also templates. Example: template <typename Kernel> struct Triangulation 2 { typedef typename Kernel::Point Point; typedef typename Kernel::Segment Segment; typedef typename Kernel::Triangle Triangle; ... };

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-52
SLIDE 52

Let’s have a close look on the example program.

Constantinos Tsirogiannis Introduction to CGAL

Thursday, April 7, 2011

slide-53
SLIDE 53

#include <CGAL/basic.h> #include <CGAL/intersections.h> #include <CGAL/Exact_predicates_exact_constructions_kernel.h> #include <qapplication.h> #include <qmainwindow.h> #include <CGAL/IO/Qt_widget.h> #include <CGAL/IO/Qt_widget_standard_toolbar.h>

Thursday, April 7, 2011

slide-54
SLIDE 54

typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel; typedef Kernel::Point_2 Point; typedef Kernel::Segment_2 Segment; typedef Kernel::Line_2 Line;

Thursday, April 7, 2011

slide-55
SLIDE 55

Point a, b, c, d; Segment s; Line l; CGAL::Object o;

Thursday, April 7, 2011

slide-56
SLIDE 56

class My_window : public QMainWindow { Q_OBJECT public: My_window() { ............... }

  • private slots://functions

void redraw_win() { ............... }

  • private: //members

CGAL::Qt_widget *widget; CGAL::Qt_widget_standard_toolbar *std_toolbar; };

Thursday, April 7, 2011

slide-57
SLIDE 57

My_window() { widget = new CGAL::Qt_widget(this); setCentralWidget(widget); resize(3,3); widget->show(); widget->set_window(-1, 2, -1, 2); a = Point(0,0); b = Point(1,0); c = Point(1,1); d = Point(0,1); s = Segment(a,c); l = Line(b,d);

  • = CGAL::intersection(s, l);

//How to attach the standard toolbar std_toolbar = new CGAL::Qt_widget_standard_toolbar(widget, this,

  • "Standard Toolbar");

connect(widget, SIGNAL(redraw_on_back()),

  • this, SLOT(redraw_win()) );

}

Thursday, April 7, 2011

slide-58
SLIDE 58

void redraw_win() { *widget << a << b << c << d << CGAL::BLUE << s << l << CGAL::RED; if (const Point *ipoint = CGAL::object_cast<Point>(&o)) {

  • // handle the point intersection case with *ipoint.
  • *widget << *ipoint;

} else if (const Segment *iseg = CGAL::object_cast<Segment>(&o)) {

  • // handle the segment intersection case with *iseg.
  • *widget << *iseg;

} else {

  • // handle the no intersection case.

} }

Thursday, April 7, 2011

slide-59
SLIDE 59

int main( int argc, char **argv ) { QApplication app( argc, argv ); My_window W(); app.setMainWidget( &W ); W.show(); W.setCaption("Using the Standard Toolbar"); return app.exec(); }

Thursday, April 7, 2011

slide-60
SLIDE 60

Version of the program using new framework:

Thursday, April 7, 2011

slide-61
SLIDE 61

#include <CGAL/basic.h> #include <CGAL/intersections.h> #include <CGAL/Exact_predicates_exact_constructions_kernel.h> #include <CGAL/number_utils.h> #include <iostream> #include <boost/format.hpp> #include <QtGui> #include <CGAL/Qt/GraphicsViewNavigation.h>

Thursday, April 7, 2011

slide-62
SLIDE 62

typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel; typedef Kernel::Point_2 Point; typedef Kernel::Segment_2 Segment; typedef Kernel::Line_2 Line;

Thursday, April 7, 2011

slide-63
SLIDE 63

int main(int argc, char **argv) { QApplication app(argc, argv);

  • QGraphicsScene scene;
  • Point a(0,0), b(1,0), c(1,1), d(0,1);
  • Segment s(a,c);
  • Line l(b,d);
  • CGAL::Object o = CGAL::intersection(s,l);
  • scene.setSceneRect(-1, -1, 2, 2);
  • scene.addEllipse(CGAL::to_double(a.x()) - 0.01, CGAL::to_double(a.y()) - 0.01, 0.02, 0.02);
  • scene.addEllipse(CGAL::to_double(b.x()) - 0.01, CGAL::to_double(b.y()) - 0.01, 0.02, 0.02);
  • scene.addEllipse(CGAL::to_double(c.x()) - 0.01, CGAL::to_double(c.y()) - 0.01, 0.02, 0.02);
  • scene.addEllipse(CGAL::to_double(d.x()) - 0.01, CGAL::to_double(d.y()) - 0.01, 0.02, 0.02);
  • scene.addLine(CGAL::to_double(s.source().x()), CGAL::to_double(s.source().y()),
  • CGAL::to_double(s.target().x()), CGAL::to_double(s.target().y()), QPen(Qt::blue));
  • scene.addLine(-2, CGAL::to_double(l.y_at_x(-2)),
  • 3, CGAL::to_double(l.y_at_x(3)), QPen(Qt::blue));
  • if (const Point *ipoint = CGAL::object_cast<Point>(&o)) {
  • // handle the point intersection case with *ipoint.
  • scene.addEllipse(CGAL::to_double(ipoint->x()) - 0.01, CGAL::to_double(ipoint->y()) - 0.01, 0.02, 0.02, QPen(),

QBrush(Qt::red));

  • } else if (const Segment *iseg = CGAL::object_cast<Segment>(&o)) {
  • // handle the segment intersection case with *iseg.
  • scene.addLine(CGAL::to_double(iseg->source().x()), CGAL::to_double(iseg->source().y()),
  • CGAL::to_double(iseg->target().x()), CGAL::to_double(iseg->target().y()), QPen(Qt::red));
  • } else {
  • // handle the no intersection case.
  • }
  • QGraphicsView* view = new QGraphicsView(&scene);

CGAL::Qt::GraphicsViewNavigation navigation; view->installEventFilter(&navigation); view->viewport()->installEventFilter(&navigation); view->setRenderHint(QPainter::Antialiasing);

  • view->show();

return app.exec(); }

Thursday, April 7, 2011

slide-64
SLIDE 64

#include <CGAL/Exact_predicates_exact_constructions_kernel.h> #include <CGAL/Arr_segment_traits_2.h> #include <CGAL/Arrangement_2.h> #include <CGAL/Arr_default_dcel.h> typedef CGAL::Exact_predicates_exact_constructions_kernel

  • Kernel;

typedef CGAL::Arr_segment_traits_2<Kernel> Traits_2; typedef CGAL::Arr_default_dcel<Traits_2>

  • ArrangementDcel;

Arrangement DCEL

http://www.cgal.org/Manual/latest/doc_html/cgal_manual/ Arrangement_on_surface_2_ref/Concept_ArrangementDcel.html

Thursday, April 7, 2011

slide-65
SLIDE 65

Installing CGAL

  • Prerequisites: cmake, boost, GMP

, MPFR, Qt3 and/or Qt4.

  • cmake-gui .
  • make
  • sudo make install

Thursday, April 7, 2011

slide-66
SLIDE 66

Tips on using CGAL

  • Use predefined filtered kernels: These

define your geometric objects and predicates.

  • Documentation can be a hit or a miss,

when in doubt, look at example code, which is provided in the CGAL directory.

Thursday, April 7, 2011

slide-67
SLIDE 67

Further Reference

  • http://www.cgal.org/Manual/3.4/doc_html/

cgal_manual/contents.html

  • http://www.cgal.org/mailing_list.html

Thursday, April 7, 2011