Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef PCL_GEOMETRY_MESH_CONVERSION_H
00042 #define PCL_GEOMETRY_MESH_CONVERSION_H
00043
00044 #include <pcl/PolygonMesh.h>
00045 #include <pcl/conversions.h>
00046
00047 namespace pcl
00048 {
00049 namespace geometry
00050 {
00057 template <class HalfEdgeMeshT> void
00058 toFaceVertexMesh (const HalfEdgeMeshT& half_edge_mesh, pcl::PolygonMesh& face_vertex_mesh)
00059 {
00060 typedef HalfEdgeMeshT HalfEdgeMesh;
00061 typedef typename HalfEdgeMesh::VertexAroundFaceCirculator VAFC;
00062 typedef typename HalfEdgeMesh::FaceIndex FaceIndex;
00063
00064 pcl::Vertices polygon;
00065 pcl::toPCLPointCloud2 (half_edge_mesh.getVertexDataCloud (), face_vertex_mesh.cloud);
00066
00067 face_vertex_mesh.polygons.reserve (half_edge_mesh.sizeFaces ());
00068 for (size_t i=0; i<half_edge_mesh.sizeFaces (); ++i)
00069 {
00070 VAFC circ = half_edge_mesh.getVertexAroundFaceCirculator (FaceIndex (i));
00071 const VAFC circ_end = circ;
00072 polygon.vertices.clear ();
00073 do
00074 {
00075 polygon.vertices.push_back (circ.getTargetIndex ().get ());
00076 } while (++circ != circ_end);
00077 face_vertex_mesh.polygons.push_back (polygon);
00078 }
00079 }
00080
00088 template <class HalfEdgeMeshT> int
00089 toHalfEdgeMesh (const pcl::PolygonMesh& face_vertex_mesh, HalfEdgeMeshT& half_edge_mesh)
00090 {
00091 typedef HalfEdgeMeshT HalfEdgeMesh;
00092 typedef typename HalfEdgeMesh::VertexDataCloud VertexDataCloud;
00093 typedef typename HalfEdgeMesh::VertexIndex VertexIndex;
00094 typedef typename HalfEdgeMesh::VertexIndices VertexIndices;
00095
00096 BOOST_STATIC_ASSERT (HalfEdgeMesh::HasVertexData::value);
00097
00098 VertexDataCloud vertices;
00099 pcl::fromPCLPointCloud2 (face_vertex_mesh.cloud, vertices);
00100
00101 half_edge_mesh.reserveVertices (vertices.size ());
00102 half_edge_mesh.reserveEdges (3 * face_vertex_mesh.polygons.size ());
00103 half_edge_mesh.reserveFaces ( face_vertex_mesh.polygons.size ());
00104
00105 for (typename VertexDataCloud::const_iterator it=vertices.begin (); it!=vertices.end (); ++it)
00106 {
00107 half_edge_mesh.addVertex (*it);
00108 }
00109
00110 assert (half_edge_mesh.sizeVertices () == vertices.size ());
00111
00112 int count_not_added = 0;
00113 VertexIndices vi;
00114 vi.reserve (3);
00115 for (size_t i=0; i<face_vertex_mesh.polygons.size (); ++i)
00116 {
00117 vi.clear ();
00118 for (size_t j=0; j<face_vertex_mesh.polygons [i].vertices.size (); ++j)
00119 {
00120 vi.push_back (VertexIndex (face_vertex_mesh.polygons [i].vertices [j]));
00121 }
00122
00123 if (!half_edge_mesh.addFace (vi).isValid ())
00124 {
00125 ++count_not_added;
00126 }
00127 }
00128
00129 return (count_not_added);
00130 }
00131 }
00132 }
00133
00134 #endif // PCL_GEOMETRY_MESH_CONVERSION_H