3D Polyhedral Surfaces in Pierre Alliez.

63
3D Polyhedral Surfaces in 3D Polyhedral Surfaces in http://www.cgal.org http://www.cgal.org Pierre Alliez Pierre Alliez

Transcript of 3D Polyhedral Surfaces in Pierre Alliez.

Page 1: 3D Polyhedral Surfaces in  Pierre Alliez.

3D Polyhedral Surfaces in3D Polyhedral Surfaces in

http://www.cgal.orghttp://www.cgal.org

Pierre AlliezPierre Alliez

Page 2: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

OutlineOutline• MotivationsMotivations• DefinitionDefinition• Halfedge Data StructureHalfedge Data Structure• TraversalTraversal• Euler OperatorsEuler Operators• CustomizationCustomization• Incremental BuilderIncremental Builder• File I/OFile I/O• ExamplesExamples• ApplicationsApplications• ExercisesExercises

Page 3: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

MotivationsMotivations

From From renderingrendering......– StaticStatic– Compact storage in arrayCompact storage in array– Traversal over all facetsTraversal over all facets– Attributes per facet/vertexAttributes per facet/vertex

Page 4: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

MotivationsMotivations

...to ...to algorithmsalgorithms on meshes on meshes– Dynamic pointer updatesDynamic pointer updates– Dynamic storage in listsDynamic storage in lists– Traversal over incidencesTraversal over incidences

Page 5: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Design GoalDesign Goal

Method: paradigm of Method: paradigm of Generic ProgrammingGeneric Programming

Example: STLExample: STL

Page 6: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

DefinitionDefinition

Polyhedral SurfacePolyhedral Surface: boundary : boundary representation of a polyhedron in IRrepresentation of a polyhedron in IR33..

Page 7: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Polyhedral SurfacePolyhedral Surface

Represented by three sets Represented by three sets VV,,EE,,FF and an incidence and an incidence relation on them, restricted to orientable 2-relation on them, restricted to orientable 2-manifolds with boundary. manifolds with boundary.

VV = Vertices in IR = Vertices in IR33

EE = Edges, straight line segments. = Edges, straight line segments.

FF = Facets, simple, planar polygons without holes. = Facets, simple, planar polygons without holes.

Can be extended: edges to curves, facets to Can be extended: edges to curves, facets to curved surfaces.curved surfaces.

Page 8: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Polyhedral SurfacePolyhedral Surface

Represented by three sets Represented by three sets VV,,EE,,FF and an and an incidence relationincidence relation on them, restricted to on them, restricted to orientable 2-manifolds with boundary. orientable 2-manifolds with boundary.

Edge-based data structure ?Edge-based data structure ?

Page 9: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Edge-centered Data Edge-centered Data StructuresStructures

Page 10: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Winged-Edge Data Winged-Edge Data StructureStructure

Page 11: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Quad-Edge Data Quad-Edge Data StructureStructure

Page 12: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Halfedge Data Halfedge Data StructureStructure

Page 13: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

VE-StructureVE-Structure

Page 14: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

HalfedgesHalfedges

Require:Require:Oriented Oriented

surfacesurface

Idea:Idea:Consider 2/4 Consider 2/4

ways of ways of accessing an accessing an edgeedge

Page 15: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

HalfedgeHalfedgeAssociated with:Associated with:• 1 vertex1 vertex• 1 edge1 edge• 1 facet1 facet

3 references:3 references:• vertexvertex• opposite opposite

halfedgehalfedge• facetfacet

Page 16: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

HalfedgesHalfedgesGeometry:Geometry:• verticesvertices

Attributes:Attributes:• on verticeson vertices• on halfedgeson halfedges• on facetson facets

Connectivity:Connectivity:• halfedges onlyhalfedges only

Page 17: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Building BlocksBuilding Blocks

Page 18: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Building BlocksBuilding Blocks

Page 19: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Polyhedral SurfacesPolyhedral Surfaces

Building blocks assembled with C+Building blocks assembled with C++ templates+ templates

Page 20: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Polyhedral SurfacePolyhedral Surface

Page 21: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Default PolyhedronDefault Polyhedron

Page 22: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Default PolyhedronDefault Polyhedron

typedef CGAL::Simple_cartesian<double> typedef CGAL::Simple_cartesian<double> KernelKernel;;typedef typedef KernelKernel::Point_3 Point_3;::Point_3 Point_3;typedef typedef CGAL::Polyhedron_3CGAL::Polyhedron_3<<KernelKernel> > PolyhedronPolyhedron;;typedef typedef PolyhedronPolyhedron::Vertex_iterator Vertex_iterator;::Vertex_iterator Vertex_iterator;

intint main() { main() { Point_3 p( 1.0, 0.0, 0.0);Point_3 p( 1.0, 0.0, 0.0); Point_3 q( 0.0, 1.0, 0.0);Point_3 q( 0.0, 1.0, 0.0); Point_3 r( 0.0, 0.0, 1.0);Point_3 r( 0.0, 0.0, 1.0); Point_3 s( 0.0, 0.0, 0.0);Point_3 s( 0.0, 0.0, 0.0);

Polyhedron PPolyhedron P;; P.make_tetrahedron( p, q, r, s);P.make_tetrahedron( p, q, r, s); for (Vertex_iterator v = for (Vertex_iterator v = P.vertices_begin()P.vertices_begin(); ; v != v != P.vertices_end()P.vertices_end(); ++v); ++v) std::cout << v->point() << std::endl;std::cout << v->point() << std::endl;}}

Page 23: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Flexible Data StructureFlexible Data Structure

Page 24: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Flexible Polyhedral Flexible Polyhedral SurfacesSurfaces

template <template <

class class PolyhedronTraits_3PolyhedronTraits_3,,

class class PolyhedronItems_3PolyhedronItems_3 = CGAL::Polyhedron_items_3, = CGAL::Polyhedron_items_3,

template < class T, class I>template < class T, class I>

class class HalfedgeDSHalfedgeDS = CGAL::HalfedgeDS_default, = CGAL::HalfedgeDS_default,

class class AllocAlloc = CGAL_ALLOCATOR(int)> = CGAL_ALLOCATOR(int)>

class Polyhedron_3;class Polyhedron_3;

Page 25: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Default PolyhedronDefault Polyhedrontypedef CGAL::Simple_cartesian<double> Kernel;typedef CGAL::Simple_cartesian<double> Kernel;typedef Kernel::Point_3 Point_3;typedef Kernel::Point_3 Point_3;typedef typedef CGAL::Polyhedron_3CGAL::Polyhedron_3<Kernel> <Kernel> PolyhedronPolyhedron;;typedef typedef PolyhedronPolyhedron::Vertex_iterator Vertex_iterator;::Vertex_iterator Vertex_iterator;

int main() {int main() { Point_3 p( 1.0, 0.0, 0.0);Point_3 p( 1.0, 0.0, 0.0); Point_3 q( 0.0, 1.0, 0.0);Point_3 q( 0.0, 1.0, 0.0); Point_3 r( 0.0, 0.0, 1.0);Point_3 r( 0.0, 0.0, 1.0); Point_3 s( 0.0, 0.0, 0.0);Point_3 s( 0.0, 0.0, 0.0);

Polyhedron PPolyhedron P;; P.make_tetrahedron( p, q, r, s);P.make_tetrahedron( p, q, r, s); for ( Vertex_iterator v = for ( Vertex_iterator v = P.vertices_begin()P.vertices_begin(); ; v != v != P.vertices_end()P.vertices_end(); ++v); ++v) std::cout << v->point() << std::endl;std::cout << v->point() << std::endl;}}

Page 26: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Euler OperatorsEuler Operators

• Preserve the Euler-PoincarPreserve the Euler-Poincaré equationé equation• Abstract from direct pointer manipulations Abstract from direct pointer manipulations

Halfedge_handle P.split_facet(Halfedge_handle h,Halfedge_handle g)

Page 27: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Euler OperatorsEuler Operators

Halfedge_handle P.split_vertex ( Halfedge_handle h, Halfedge_handle gHalfedge_handle P.split_vertex ( Halfedge_handle h, Halfedge_handle g

Halfedge_handle P.join_vertex ( Halfedge_handle h)Halfedge_handle P.join_vertex ( Halfedge_handle h)

Page 28: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Euler OperatorsEuler Operators

Page 29: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Modifying the GenusModifying the Genus

Page 30: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Modifying Facets & Modifying Facets & HolesHoles

Page 31: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Create a Cube with Euler Create a Cube with Euler OperatorOperator

Halfedge_handle h = P.make_tetrahedron( Halfedge_handle h = P.make_tetrahedron(

Point(1,0,0), Point(0,0,1),Point(1,0,0), Point(0,0,1),

Point(0,0,0), Point(0,1,0));Point(0,0,0), Point(0,1,0));

Halfedge_handle g = h->next()->opposite()->next();Halfedge_handle g = h->next()->opposite()->next(); (a)(a)

Page 32: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Create a Cube with Euler Create a Cube with Euler OperatorOperator

Halfedge_handle h = P.make_tetrahedron( Halfedge_handle h = P.make_tetrahedron(

Point(1,0,0), Point(0,0,1),Point(1,0,0), Point(0,0,1),

Point(0,0,0), Point(0,1,0));Point(0,0,0), Point(0,1,0));

Halfedge_handle g = h->next()->opposite()->next(); Halfedge_handle g = h->next()->opposite()->next(); (a)(a)

P.split_edge( h->next());P.split_edge( h->next());

P.split_edge( g->next());P.split_edge( g->next());

P.split_edge( g);P.split_edge( g); (b)(b)

Page 33: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Create a Cube with Euler Create a Cube with Euler OperatorOperator

h->next()->vertex()->point() = Point( 1, 0, 1);h->next()->vertex()->point() = Point( 1, 0, 1);

g->next()->vertex()->point() = Point( 0, 1, 1);g->next()->vertex()->point() = Point( 0, 1, 1);

g->opposite()->vertex()->point() = Point( 1, 1, 0);g->opposite()->vertex()->point() = Point( 1, 1, 0); (c)(c)

Page 34: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Create a Cube with Euler Create a Cube with Euler OperatorOperator

h->next()->vertex()->point() = Point( 1, 0, 1);h->next()->vertex()->point() = Point( 1, 0, 1);

g->next()->vertex()->point() = Point( 0, 1, 1);g->next()->vertex()->point() = Point( 0, 1, 1);

g->opposite()->vertex()->point() = Point( 1, 1, 0); g->opposite()->vertex()->point() = Point( 1, 1, 0); (c)(c)

Halfedge_handle f = P.split_facet( g->next(), Halfedge_handle f = P.split_facet( g->next(),

g->next()->next()->next());g->next()->next()->next()); (d)(d)

Page 35: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Create a Cube with Euler Create a Cube with Euler OperatorOperator

h->next()->vertex()->point() = Point( 1, 0, 1);h->next()->vertex()->point() = Point( 1, 0, 1);

g->next()->vertex()->point() = Point( 0, 1, 1);g->next()->vertex()->point() = Point( 0, 1, 1);

g->opposite()->vertex()->point() = Point( 1, 1, 0); g->opposite()->vertex()->point() = Point( 1, 1, 0); (c)(c)

Halfedge_handle f = P.split_facet( g->next(), Halfedge_handle f = P.split_facet( g->next(),

g->next()->next()->next()); g->next()->next()->next()); (d)(d)

Halfedge_handle e = P.split_edge( f);Halfedge_handle e = P.split_edge( f);

e->vertex()->point() = Point( 1, 1, 1);e->vertex()->point() = Point( 1, 1, 1); (e)(e)

Page 36: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Create a Cube with Euler Create a Cube with Euler OperatorOperator

h->next()->vertex()->point() = Point( 1, 0, 1);h->next()->vertex()->point() = Point( 1, 0, 1);

g->next()->vertex()->point() = Point( 0, 1, 1);g->next()->vertex()->point() = Point( 0, 1, 1);

g->opposite()->vertex()->point() = Point( 1, 1, 0); g->opposite()->vertex()->point() = Point( 1, 1, 0); (c)(c)

Halfedge_handle f = P.split_facet( g->next(), Halfedge_handle f = P.split_facet( g->next(),

g->next()->next()->next()); g->next()->next()->next()); (d)(d)

Halfedge_handle e = P.split_edge( f);Halfedge_handle e = P.split_edge( f);

e->vertex()->point() = Point( 1, 1, 1); e->vertex()->point() = Point( 1, 1, 1); (e)(e)

P.split_facet( e, f->next()->next());P.split_facet( e, f->next()->next()); (f)(f)

Page 37: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Extending PrimitivesExtending Primitives

typedef CGAL::Polyhedron_3< typedef CGAL::Polyhedron_3< Traits,Traits,

CGAL::Polyhedron_items_3,CGAL::Polyhedron_items_3,

CGAL::HalfedgeDS_default> Polyhedron;CGAL::HalfedgeDS_default> Polyhedron;

classclass Polyhedron_items_3 { Polyhedron_items_3 {

public:public:

template < class Refs, class Traits>template < class Refs, class Traits>

struct struct Vertex_wrapperVertex_wrapper { {

typedef typename Traits::Point_3 Point;typedef typename Traits::Point_3 Point;

typedef CGAL::HalfedgeDS_vertex_base<Refs, CGAL::Tag_true, Point> Vertex;typedef CGAL::HalfedgeDS_vertex_base<Refs, CGAL::Tag_true, Point> Vertex;

};};

template < class Refs, class Traits>template < class Refs, class Traits>

struct struct Halfedge_wrapperHalfedge_wrapper { {

typedef CGAL::HalfedgeDS_halfedge_base<Refs> Halfedge;typedef CGAL::HalfedgeDS_halfedge_base<Refs> Halfedge;

};};

template < class Refs, class Traits>template < class Refs, class Traits>

struct struct Face_wrapperFace_wrapper { {

typedef typename Traits::Plane_3 Plane;typedef typename Traits::Plane_3 Plane;

typedef CGAL::HalfedgeDS_face_base<Refs, CGAL::Tag_true, Plane> Face;typedef CGAL::HalfedgeDS_face_base<Refs, CGAL::Tag_true, Plane> Face;

};};

};};

Page 38: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Add Color to FacetsAdd Color to Facetstemplate <class Refs>template <class Refs>struct struct CFaceCFace : public CGAL::HalfedgeDS_face_base<Refs>{ : public CGAL::HalfedgeDS_face_base<Refs>{ CGAL::Color colorCGAL::Color color;;};};

// ...// ...

typedef CGAL::Simple_cartesian<double> Kernel;typedef CGAL::Simple_cartesian<double> Kernel;typedef CGAL::Polyhedron_3<Kernel, typedef CGAL::Polyhedron_3<Kernel, ......> Polyhedron;> Polyhedron;typedef Polyhedron::Halfedge_handle Halfedge_handle;typedef Polyhedron::Halfedge_handle Halfedge_handle;

int main() {int main() { Polyhedron P;Polyhedron P; Halfedge_handle h = P.make_tetrahedron();Halfedge_handle h = P.make_tetrahedron(); h->facet()->color = CGAL::RED;h->facet()->color = CGAL::RED; return 0;return 0;}}

Page 39: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Add Color to FacetsAdd Color to Facetstemplate <class Refs>template <class Refs>struct CFace : public CGAL::HalfedgeDS_face_base<Refs>{struct CFace : public CGAL::HalfedgeDS_face_base<Refs>{ CGAL::Color color;CGAL::Color color;};};

struct struct CItemsCItems : public CGAL::Polyhedron_items_3 { : public CGAL::Polyhedron_items_3 { template <class Refs, class Traits>template <class Refs, class Traits> struct Face_wrapper {struct Face_wrapper { typedef CFace<Refs> Face;typedef CFace<Refs> Face; };};};};

typedef CGAL::Simple_cartesian<double> Kernel;typedef CGAL::Simple_cartesian<double> Kernel;typedef CGAL::Polyhedron_3<Kernel, typedef CGAL::Polyhedron_3<Kernel, CItemsCItems> Polyhedron;> Polyhedron;

Page 40: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Add Vertex_handle to Add Vertex_handle to FacetsFacets

template <class template <class RefsRefs>>

struct VFace : public CGAL::HalfedgeDS_face_base<Refs>{struct VFace : public CGAL::HalfedgeDS_face_base<Refs>{

typedef typename typedef typename RefsRefs::::Vertex_handle Vertex_handleVertex_handle Vertex_handle;;

Vertex_handleVertex_handle vertex_ref; vertex_ref;

};};

Page 41: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Incremental BuilderIncremental Builder• Uses the modifier design to access the internal Uses the modifier design to access the internal

HDSHDS

Page 42: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Make Triangle with Incremental Make Triangle with Incremental BuilderBuilder

template <class HDS>template <class HDS>structstruct Mk_triangleMk_triangle : public : public CGAL::Modifier_base<HDS>CGAL::Modifier_base<HDS> { {

voidvoid operator()( HDS& hds)operator()( HDS& hds) {// Postcond: ‘hds' valid{// Postcond: ‘hds' valid

CGAL::Polyhedron_incremental_builder_3<HDS> B(hds);CGAL::Polyhedron_incremental_builder_3<HDS> B(hds); B.B.begin_surfacebegin_surface( 3, 1, 6);( 3, 1, 6); typedeftypedef typenametypename HDS::Vertex Vertex; HDS::Vertex Vertex; typedeftypedef typenametypename Vertex::Point Point; Vertex::Point Point; B.B.add_vertexadd_vertex( Point( 0, 0, 0));( Point( 0, 0, 0)); B.B.add_vertexadd_vertex( Point( 1, 0, 0));( Point( 1, 0, 0)); B.B.add_vertexadd_vertex( Point( 0, 1, 0));( Point( 0, 1, 0)); B.B.begin_facetbegin_facet();(); B.B.add_vertex_to_facetadd_vertex_to_facet( 0);( 0); B.B.add_vertex_to_facetadd_vertex_to_facet( 1);( 1); B.B.add_vertex_to_facetadd_vertex_to_facet( 2);( 2); B.B.end_facetend_facet();(); B.B.end_surfaceend_surface();(); }}};};

Page 43: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Make Triangle with Incremental Make Triangle with Incremental BuilderBuilder

main() {main() { Polyhedron P;Polyhedron P; Mk_triangle<HalfedgeDS> triangle;Mk_triangle<HalfedgeDS> triangle; P.delegateP.delegate( ( triangletriangle);); return 0;return 0;}}

Page 44: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

TraversalTraversal

Page 45: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

IteratorsIterators

Page 46: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Iterators and Iterators and CirculatorsCirculators

Page 47: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

IterationIteration

Vertex_iterator iter;Vertex_iterator iter;

forfor(( iter = polyhedron.vertices_begin();iter = polyhedron.vertices_begin();

iter != polyhedron.vertices_end();iter != polyhedron.vertices_end();

iter++)iter++)

{{

Vertex_handle hVertex = iter;Vertex_handle hVertex = iter;

// do something with hVertex// do something with hVertex

}}

Page 48: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

CirculationCirculation

// circulate around hFacet// circulate around hFacet

Halfedge_around_facet_circulator circ = Halfedge_around_facet_circulator circ =

hFacet->facet_begin();hFacet->facet_begin();

Halfedge_around_facet_circulator end = circ;Halfedge_around_facet_circulator end = circ;

CGAL_For_all(circ,end)CGAL_For_all(circ,end)

{{

Halfedge_handle hHalfedge = circ;Halfedge_handle hHalfedge = circ;

// do something with hHalfedge// do something with hHalfedge

}}

Page 49: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

CirculationCirculation

// circulate around hVertex// circulate around hVertex

Halfedge_around_vertex_circulator circ = Halfedge_around_vertex_circulator circ =

hVertex->vertex_begin();hVertex->vertex_begin();

Halfedge_around_vertex_circulator end = circ;Halfedge_around_vertex_circulator end = circ;

CGAL_For_all(circ,end)CGAL_For_all(circ,end)

{{

Halfedge_handle hHalfedge = circ;Halfedge_handle hHalfedge = circ;

// do something with hHalfedge// do something with hHalfedge

}}

Page 50: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

File I/OFile I/O

I/O: OFF indexed formatI/O: OFF indexed format

Output: vrml1-2, iv, geomviewOutput: vrml1-2, iv, geomview

OFFOFF6 6 06 6 00.000000 1.686000 0.0000000.000000 1.686000 0.0000001.192000 0.000000 -1.1920001.192000 0.000000 -1.192000-1.192000 0.000000 -1.192000-1.192000 0.000000 -1.192000-1.192000 0.000000 1.192000-1.192000 0.000000 1.1920001.192000 0.000000 1.1920001.192000 0.000000 1.1920000.000000 -1.68600 0.0000000.000000 -1.68600 0.0000003 0 4 1 3 0 4 1 3 1 5 2 3 1 5 2 3 2 3 0 3 2 3 0 3 1 2 0 3 1 2 0 3 3 4 0 3 3 4 0 3 3 2 53 3 2 5

Page 51: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

ApplicationsApplications

• RenderingRendering• Subdivision SurfacesSubdivision Surfaces• Algorithms on MeshesAlgorithms on Meshes

– SimplificationSimplification– ApproximationApproximation– RemeshingRemeshing– SmoothingSmoothing– CompressionCompression

• Etc.Etc.

Page 52: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Warm-Up ExercicesWarm-Up Exercices

Page 53: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Highlight Boundary Highlight Boundary EdgesEdges

Notes:Notes:

boolbool halfedge->is_border(); halfedge->is_border();

// change color// change color

::glColor3f(r,g,b); ::glColor3f(r,g,b); // in [0.0f-1.0f]// in [0.0f-1.0f]

// Assemble primitive// Assemble primitive

Page 54: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Render all Facets as Render all Facets as PolygonsPolygons

typedeftypedef Polyhedron::Facet_iterator Polyhedron::Facet_iterator Facet_iteratorFacet_iterator;;

typedeftypedef Polyhedron::Halfedge_around_facet_circulator Polyhedron::Halfedge_around_facet_circulator

Halfedge_facet_circulatorHalfedge_facet_circulator;;

forfor ( (Facet_iteratorFacet_iterator i = P.facets_begin(); i = P.facets_begin();

i != P.facets_end(); i != P.facets_end();

++i) ++i)

{{

Halfedge_facet_circulatorHalfedge_facet_circulator j = i->facet_begin(); j = i->facet_begin();

::::glBeginglBegin(GL_POLYGON);(GL_POLYGON);

dodo

::glVertex3d(j->vertex()->point().x(),::glVertex3d(j->vertex()->point().x(),

j->vertex()->point().y(),j->vertex()->point().y(),

j->vertex()->point().z());j->vertex()->point().z());

whilewhile( ++j != i->facet_begin());( ++j != i->facet_begin());

::::glEndglEnd();();

}}

Page 55: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Exercices Around Exercices Around CombinatoricsCombinatorics

Page 56: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Combinatorial GenusCombinatorial Genus

• Enumerate connected Enumerate connected componentscomponents

• Enumerate boundariesEnumerate boundaries• Deduce genus using Euler Deduce genus using Euler

formulaformula

Page 57: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Exercices Around Exercices Around GeometryGeometry

Page 58: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Discrete LaplacianDiscrete Laplacian

Page 59: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

valence(vertex)valence(vertex)

Page 60: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Discrete Discrete LaplacianLaplacian

intint nbv = size_of_vertices(); nbv = size_of_vertices();

std::vector<Vector_3> dx(nbv);std::vector<Vector_3> dx(nbv);

iterate on verticesiterate on vertices

dx[i] = Vector_3(0,0,0); dx[i] = Vector_3(0,0,0); // init // init

circulate around current vertexcirculate around current vertex

... ... // (compute displacements)// (compute displacements)

iterate on verticesiterate on vertices

apply displacementsapply displacements

Page 61: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

AdvancedAdvanced

Page 62: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

DualizationDualization

primalprimal dualdual

Page 63: 3D Polyhedral Surfaces in  Pierre Alliez.

http://http://www.cgal.orgwww.cgal.org

Dualization using Dualization using Incremental BuilderIncremental Builder