Subject: CGAL users discussion list
List archive
- From: Zohar Levi <>
- To:
- Subject: [cgal-discuss] RE: Iterating over Polyhedron facets
- Date: Mon, 31 Aug 2009 02:50:23 -0700 (PDT)
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=Ehp4Ds6emLwi6tU5TfQ7xa2y1d5IpwVLkM7+rP7agRiEyIpdMf6SYAs1CPh+3T6FdpY/Znpj8NteW9ajjIDBkHTKRqFUmNH7g5a7RMo2i/JTY6QP9+ShgovzooLEdkFauW1vKG9ni5W9wITEdPaGUt5fkz64hHT3e/EFim0CwfU=;
An example converting Maya mesh (which one do you use?) to CGAL Polyhedron:
template <class Refs>
struct My_face : public CGAL::HalfedgeDS_face_base<Refs> {
unsigned id;
};
template <class Refs, class Point>
struct My_vertex : public CGAL::HalfedgeDS_vertex_base<Refs, CGAL::Tag_true, Point> {
My_vertex() {}
My_vertex(const Point& pt) : CGAL::HalfedgeDS_vertex_base<Refs, CGAL::Tag_true, Point>(pt) {}
unsigned id;
};
// An items type using my face and vertex.
struct My_items : public CGAL::Polyhedron_items_3 {
template <class Refs, class Traits>
struct Face_wrapper {
typedef My_face<Refs> Face;
};
template <class Refs, class Traits>
struct Vertex_wrapper {
typedef typename Traits::Point_3 Point;
typedef My_vertex<Refs, Point> Vertex;
};
};
typedef CGAL::Cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel, My_items> Polyhedron;
// A modifier converting a Maya mesh to CGAL Polyhedron_3
template <class HDS>
class Mesh_to_polyhedron : public CGAL::Modifier_base<HDS> {
public:
Mesh_to_polyhedron(MFnMesh &mesh) : m_mesh(mesh.object()) {}
void operator()(HDS& hds) {
// get mesh data
MFloatPointArray pts;
m_mesh.getPoints(pts);
MIntArray tcounts, tvers;
m_mesh.getTriangles(tcounts, tvers);
// Postcondition: `hds' is a valid polyhedral surface.
CGAL::Polyhedron_incremental_builder_3<HDS> B(hds, true);
B.begin_surface(pts.length(), tvers.length()/3);
// vertices
typedef typename HDS::Vertex::Point Vertex;
typedef typename Vertex Point;
for ( unsigned i = 0 ; i < pts.length() ; i++ ) {
HDS::Vertex_handle vh = B.add_vertex(Point(pts[i].x,pts[i].y,pts[i].z));
vh->id = i;
}
// triangles
for ( unsigned i = 0 ; i < tvers.length()/3 ; i++ ) {
HDS::Face_handle fh = B.begin_facet();
B.add_vertex_to_facet(tvers[3*i]);
B.add_vertex_to_facet(tvers[3*i+1]);
B.add_vertex_to_facet(tvers[3*i+2]);
B.end_facet();
fh->id = i;
}
B.end_surface();
}
private:
MFnMesh m_mesh;
};
void mesh2polyhedron(MFnMesh &mesh, Polyhedron &P)
{
Mesh_to_polyhedron<Polyhedron::HalfedgeDS> builder(mesh);
P.delegate(builder);
}
- [cgal-discuss] RE: Iterating over Polyhedron facets, Zohar Levi, 08/31/2009
Archive powered by MHonArc 2.6.16.