Introduction to CGAL. Constantinos Tsirogiannis. TU/Eindhoven

Similar documents
Lab 12: GUI programming with Qt

PHY4321 Summary Notes

Project 1: Convex hulls and line segment intersection

GCC : From 2.95 to 3.2

CS 376b Computer Vision

My First Command-Line Program

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

Lecture 5 Files and Streams

PROGRAMMING IN C++ CVIČENÍ

C++14 Reflections Without Macros, Markup nor External Tooling

eingebetteter Systeme

Introduction to Programming

Professor Terje Haukaas University of British Columbia, Vancouver C++ Programming

C++ Namespaces, Exceptions

Introduction. Lecture 5 Files and Streams FILE * FILE *

Luis Ibáñez William Schroeder Insight Software Consortium. ITK and Graphical User Interface

Qt Essentials - Fundamentals of Qt Module

Function Templates. Consider the following function:

CAAM 420 Fall 2012 Lecture 29. Duncan Eddy

Informatik I (D-ITET) Übungsstunde 9, Hossein Shafagh

CS93SI Handout 04 Spring 2006 Apr Review Answers

CMSC 202 Midterm Exam 1 Fall 2015

CSCI-1200 Data Structures Fall 2017 Lecture 2 STL Strings & Vectors

Qt Essentials - Graphics View Module

Exercise 9 Pointers, Iterators and Recursion

Computational Geometry Algorithms Library. Pierre Alliez INRIA

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

General Computer Science II Course: B International University Bremen Date: Dr. Jürgen Schönwälder Deadline:

INSTRUCTIONS: GOOD LUCK! [TURN OVER]

Assignment #1 Advanced Programming in C /2018. NPRG051 Advanced programming in C++ - Assignment #1

ECE 462 Fall 2011, Third Exam

Announcements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy

Advanced Systems Programming

Biostatistics 615/815 - Lecture 2 Introduction to C++ Programming

Common Misunderstandings from Exam 1 Material

Lecture 2 Polymorphism, Traits, Policies, and Inheritance

Semantics of C++ Hauptseminar im Wintersemester 2009/10 Templates

CSE 333 Lecture 9 - intro to C++

Robustness in. Monique Teillaud. Robustness in

CS24 Week 3 Lecture 1

Homework 4. Any questions?

Abstract Data Types. Different Views of Data:

Programmazione. Prof. Marco Bertini

A506 / C201 Computer Programming II Placement Exam Sample Questions. For each of the following, choose the most appropriate answer (2pts each).

Project 1: Convex hulls and line segment intersection

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

W3101: Programming Languages C++ Ramana Isukapalli

Physics 234: Computational Physics

September 19,

struct Buffer { Buffer(int s) { buf = new char[s]; } ~Buffer() { delete [] buf; } char *buf; };

Procedures, Parameters, Values and Variables. Steven R. Bagley

Qt Introduction. Topics. C++ Build Process. Ch & Ch 3. 1) What's Qt? 2) How can we make a Qt console program? 3) How can we use dialogs?

4. C++ functions. 1. Library Function 2. User-defined Function

Pointers and scanf() Steven R. Bagley

Draw the basic Geometry Objects. Hanyang University

Lecture 3 (CGAL) Panos Giannopoulos, Dror Atariah AG TI WS 2012/13

Generic Programming in C++: A modest example

CSE 333 Midterm Exam 7/22/12

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

Linked List using a Sentinel

Structuur van Computerprogramma s 2

Introduction to C++ Systems Programming

Qt Essentials - Fundamentals of Qt Module

1d: tests knowing about bitwise fields and union/struct differences.

typedef Labeling<unsigned char,short> LabelingBS; typedef Labeling<unsigned char,short>::regioninfo RegionInfoBS;

General Advise: Don t reinvent the wheel

Solving problems with Cgal: an example using the 2D Apollonius package

Type Aliases. Examples: using newtype = existingtype; // C++11 typedef existingtype newtype; // equivalent, still works

Suppose that you want to use two libraries with a bunch of useful classes and functions, but some names collide:

UNDEFINED BEHAVIOR IS AWESOME

TDDD38 - Advanced programming in C++

Unified Modeling Language a case study

BASIC ELEMENTS OF A COMPUTER PROGRAM

Fast Introduction to Object Oriented Programming and C++

Tools, Generic Programming, CGAL, and 2D Arrangement of CGAL

CSE 333 Lecture smart pointers

How the Adapters and Binders Work

Lambda functions. Zoltán Porkoláb: C++11/14 1

CSI33 Data Structures

CHAPTER 1.2 INTRODUCTION TO C++ PROGRAMMING. Dr. Shady Yehia Elmashad

A package for exact kinetic data structures and sweepline algorithms

Streams. Ali Malik

Overview. 1. Expression Value Categories 2. Rvalue References 3. Templates 4. Miscellaneous Hilarity 2/43

C++ Basics. Brian A. Malloy. References Data Expressions Control Structures Functions. Slide 1 of 24. Go Back. Full Screen. Quit.

C++ Exception Handling 1

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts

Lecture on pointers, references, and arrays and vectors

C++ (Non for C Programmer) (BT307) 40 Hours

PRINCIPLES OF OPERATING SYSTEMS

BSc (Hons) Computer Science. with Network Security. Examinations for / Semester1

So far, system calls have had easy syntax. Integer, character string, and structure arguments.

Abstraction and Encapsulation. Benefits of Abstraction & Encapsulation. Concrete Types. Using Typedefs to streamline classes.

C Language Advanced Concepts. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

Part XI. Algorithms and Templates. Philip Blakely (LSC) C++ Introduction 314 / 370

Computational Physics Operating systems

CSCI 102L - Data Structures Midterm Exam #1 Fall 2011

Integrating QML with C++

ME240 Computation for Mechanical Engineering. Lecture 4. C++ Data Types

Chapter 15 - C++ As A "Better C"

SCIRun Developer Guide

Transcription:

TU/Eindhoven

CGAL? CGAL = Computational Geometry Algorithms Library:

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

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

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

C++ C++ = C +ObjectOrientedProgramming

C++ C++ = C +ObjectOrientedProgramming Traditional C code:

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

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

C++ Basics Here follow few basic concepts of C++

Classes/Structures Class:

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

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

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

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

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

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

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

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;

Iterators An iterator is a substitute of a pointer.

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.

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;

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

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

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++ ) os << *it << std::endl;

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

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

Templates Example: A function that computes a power of a given object 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; }

CGAL CGAL provides implementations of:

CGAL CGAL provides implementations of: Triangulations.

CGAL CGAL provides implementations of: Triangulations. Voronoi diagrams.

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

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

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

CGAL Concepts The concepts provided by CGAL are categorized as:

CGAL Concepts The concepts provided by CGAL are categorized as: Geometric Objects

CGAL Concepts The concepts provided by CGAL are categorized as: Geometric Objects Geometric Predicates/Constructions

CGAL Concepts The concepts provided by CGAL are categorized as: Geometric Objects Geometric Predicates/Constructions Geometric Algorithms/Data-Structures

Kernel Geometric objects and predicates appear inside a kernel.

Kernel Geometric objects and predicates appear inside a kernel. A kernel is more or less a large class the encapsulates objects and predicates that fall in the same general category.

Kernel Geometric objects and predicates appear inside a kernel. A kernel is more or less a large class the encapsulates objects and predicates that fall in the same general category. struct Cartesian kernel { class Point {...}; class Segment {...}; class Triangle {...};... class Do intersect predicate {...}; };

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

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

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

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

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

Kernels You can use kernels with fixed number types such as Cartesian<double>.

Kernels 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

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

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

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

Let s have a close look on the example program.

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

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

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

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

! 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);!!!! o = 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()) );! }

! 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.!! }! }

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

Version of the program using new framework:

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

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

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

Arrangement DCEL #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; http://www.cgal.org/manual/latest/doc_html/cgal_manual/ Arrangement_on_surface_2_ref/Concept_ArrangementDcel.html

Installing CGAL Prerequisites: cmake, boost, GMP, MPFR, Qt3 and/or Qt4. cmake-gui. make sudo make install

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.

Further Reference http://www.cgal.org/manual/3.4/doc_html/ cgal_manual/contents.html http://www.cgal.org/mailing_list.html