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: Kye Wong <>
  • To:
  • Subject: Re: [cgal-discuss] How to get Dual mesh of Polyhedron_3
  • Date: Tue, 1 Dec 2009 16:16:59 +0800
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=mhBjIImES3cpZBW7K+1uXovQq08Qwa1j403lS3bxMc26Ax1jW86uvS8pKmE4yUsuPT LSPMZQe3KDBcRXS2cqAmbszcO3k2+V2bGyBELruD/mZuWgGuTMsqlrWO8NY4Cx4UbT+Z uEY8aoszGffyzMqBZa0O3gqfG+8s/7h/6oZjs=

Hi Pierre

The code is quite nice and helpful!
Thanks very much!

On Tue, Dec 1, 2009 at 10:24 AM, Pierre Alliez <> wrote:
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!
 

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss


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




--
Kye Wong



Archive powered by MHonArc 2.6.16.

Top of Page