Subject: CGAL users discussion list
List archive
- From: "Andriy Fedorov" <>
- To: "CGAL discuss mail list" <>
- Subject: Re: [cgal-discuss] Saving surface mesh
- Date: Sun, 22 Oct 2006 18:20:48 -0400
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:in-reply-to:mime-version:content-type:references:x-google-sender-auth; b=X4lTiXeKMwfFUydlxIGkjdJJ5AqeCcaBuFlcXhWS83WVKcqlXjjCyRKKfD8CwPDWQn/i7mOulDhlO7tM+aTHtiHlWTlKQ+lLmJbmkNy7g/tme4CO55AhYQ0ne5PZh28VFuYRKUK8RWNQ11wz4m8HJ/LArvOp6rX23zQgvr6xnWU=
The example which is located in
CGAL/examples/Polyhedron_IO/triangulation_print_OFF.h shows how to
output a 3d triangulation into OFF format. I found that doing
something similar for 3d surface requires some (non-trivial for a
person not familiar with CGAL) changes to that code. I spent a lot of
time figuring out types and functions, so I attach the resulting code
in case someone else will be trying to solve a similar problem.
Andriy Fedorov
// Modified from $CGAL/examples/Polyhedron_IO/triangulation_print_OFF.h // to output surface triangulation // // Prints a Surface_mesh_complex_2_in_triangulation_3 with points in RAW format // // RAW format is (vertex numbering starts from 0): // <#points> <#faces> // point_0.x point_0.y point_0.z // ... // face0.firstPoint face1.firstPoint face2.firstPoint // ... // // Andriy Fedorov / fedorov at cs wm edu #ifndef CGAL_TRIANGULATION_PRINT_RAW_H #define CGAL_TRIANGULATION_PRINT_RAW_H 1 #ifndef CGAL_PROTECT_MAP #include <map> #define CGAL_PROTECT_MAP #endif CGAL_BEGIN_NAMESPACE template < class Triang > void triangulation_print_RAW( std::ostream& out, Triang& triang, bool binary = false, bool noc = false, bool verbose = false) { typedef typename Triang::Vertex_handle Vertex; typedef typename Triang::Vertex_iterator Vertex_iterator; typedef typename Triang::Facet_iterator Face_iterator; typedef typename Triang::Cell_handle Cell; // Build a map from vertex pointers to vertex indices. std::map<typename Triang::Triangulation::Point,std::size_t> mapping; std::size_t vn = 0; Vertex_iterator vi = triang.vertices_begin(); for ( ; vi != triang.vertices_end(); ++vi) { mapping[(*vi).point()] = vn; vn++; } /* AF: NB!!! from CGAL docs here http://www.cgal.org/Manual/3.2/doc_html/cgal_manual/TriangulationDS_3_ref/Concept_TriangulationDataStructure_3.html#Cross_link_anchor_780 "[...] Edges (1-faces) and facets (2-faces) are not explicitly represented: a facet is given by a cell and an index (the facet i of a cell c is the facet of c that is opposite to the vertex of index i) and an edge is given by a cell and two indices (the edge (i,j) of a cell c is the edge whose endpoints are the vertices of indices i and j of c).[...]" */ // Count faces std::size_t fn = 0; Face_iterator fi = triang.facets_begin(); for ( ; fi != triang.facets_end(); ++fi) fn++; out << vn << " " << fn << std::endl; vi = triang.vertices_begin(); for ( ; vi != triang.vertices_end(); ++vi) { out << to_double(vi->point().x()) << " " << to_double(vi->point().y()) << " " << to_double(vi->point().z()) << std::endl; } fi = triang.facets_begin(); while ( fi !=triang.facets_end() ) { const Cell& ch = (*fi).first; const int& i = (*fi).second; for(int j=0;j<3;j++){ const Vertex w = ch->vertex(triang.triangulation().vertex_triple_index(i,j)); assert(mapping.find(w->point())!=mapping.end()); out << mapping[w->point()] << " "; } out << std::endl; fi++; } } CGAL_END_NAMESPACE #endif // CGAL_TRIANGULATION_PRINT_RAW_H // // EOF //
- Saving surface mesh, Andriy Fedorov, 10/22/2006
- Re: [cgal-discuss] Saving surface mesh, Dominik Szczerba, 10/22/2006
- Re: [cgal-discuss] Saving surface mesh, Andriy Fedorov, 10/23/2006
- Re: [cgal-discuss] Saving surface mesh, Dominik Szczerba, 10/22/2006
Archive powered by MHonArc 2.6.16.