Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] How to get Dual mesh of Polyhedron_3

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] How to get Dual mesh of Polyhedron_3


Chronological Thread 
  • From: Pierre Alliez <>
  • To:
  • Subject: Re: [cgal-discuss] How to get Dual mesh of Polyhedron_3
  • Date: Mon, 30 Nov 2009 18:24:46 -0800
  • Organization: INRIA

hello,

you can use the incremental builder and inspire from attached piece of code.

usage:
typedef CDualizer<Mesh,Mesh> Dualizer;
Dualizer dualizer;
dualizer.run(primal,dual);

pierre

Pierre Alliez
INRIA Sophia Antipolis - Mediterranee Project-team GEOMETRICA http://www-sop.inria.fr/members/Pierre.Alliez/
Tel: +33 4 92 38 76 77
Fax: +33 4 97 15 53 95



kyewong a écrit :
Is there any way to get the dual mesh of a polyhedron_3 in cgal?
The dual mesh should also be of polyhedron_3 data structure.

Waiting for your help...Thanks!
#ifndef _DUALIZER_
#define _DUALIZER_

#include <CGAL/Polyhedron_incremental_builder_3.h>

template <class HDS,class Polyhedron,class Kernel>
class CModifierDual : public CGAL::Modifier_base<HDS>
{
private:
typedef typename Kernel::Point_3 Point;
typedef typename Kernel::Plane_3 Plane;
typedef typename Kernel::Vector_3 Vector;

typedef typename HDS::Vertex Vertex;
typedef typename HDS::Face_handle Face_handle;
typedef typename HDS::Halfedge_handle Halfedge_handle;

typedef typename Polyhedron::Facet_iterator Facet_iterator;
typedef typename Polyhedron::Vertex_iterator Vertex_iterator;
typedef typename Polyhedron::Halfedge_around_vertex_circulator
HV_circulator;

typedef typename CGAL::Polyhedron_incremental_builder_3<HDS> builder;
Polyhedron *m_pMesh;

public:

// life cycle
CModifierDual(Polyhedron *pMesh)
{
CGAL_assertion(pMesh != NULL);
m_pMesh = pMesh;
}
~CModifierDual() {}

void operator()( HDS& hds)
{
builder B(hds,true);
B.begin_surface(3,1,6);
add_vertices(B);
add_facets(B);
B.end_surface();
}

// add vertices
void add_vertices(builder &B)
{
int index = 0;
Facet_iterator f;
for(f = m_pMesh->facets_begin();
f != m_pMesh->facets_end();
f++)
{
f->tag() = index++;
B.add_vertex(dual(f));
}
}

Point dual(Face_handle f)
{
Plane plane = m_pMesh->plane(f);
FT sqd = CGAL::squared_distance(Point(CGAL::ORIGIN),plane);
FT distance_to_origin = std::sqrt(sqd);
Vector normal = plane.orthogonal_vector();
normal = normal / std::sqrt(normal * normal);
return CGAL::ORIGIN + normal / distance_to_origin;
}

// add facets
void add_facets(builder &B)
{
Vertex_iterator v;
for(v = m_pMesh->vertices_begin();
v != m_pMesh->vertices_end();
v++)
{
B.begin_facet();
HV_circulator he = v->vertex_begin();
HV_circulator end = he;
CGAL_For_all(he,end)
B.add_vertex_to_facet(he->facet()->tag());
B.end_facet();
}
}

};

template <class Polyhedron,class Kernel>
class CDualizer
{
public:
typedef typename Polyhedron::HalfedgeDS HalfedgeDS;
CDualizer() {}
~CDualizer() {}

public:
void run(Polyhedron &input,Polyhedron &dual)
{
CModifierDual<HalfedgeDS,Polyhedron,Kernel> dualizer(&input);
dual.delegate(dualizer);
}
};

#endif // _DUALIZER_



Archive powered by MHonArc 2.6.16.

Top of Page