mesh_conversion.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  * Point Cloud Library (PCL) - www.pointclouds.org
00005  * Copyright (c) 2009-2012, Willow Garage, Inc.
00006  * Copyright (c) 2012-, Open Perception, Inc.
00007  *
00008  * All rights reserved.
00009  *
00010  * Redistribution and use in source and binary forms, with or without
00011  * modification, are permitted provided that the following conditions
00012  * are met:
00013  *
00014  *  * Redistributions of source code must retain the above copyright
00015  *    notice, this list of conditions and the following disclaimer.
00016  *  * Redistributions in binary form must reproduce the above
00017  *    copyright notice, this list of conditions and the following
00018  *    disclaimer in the documentation and/or other materials provided
00019  *    with the distribution.
00020  *  * Neither the name of the copyright holder(s) nor the names of its
00021  *    contributors may be used to endorse or promote products derived
00022  *    from this software without specific prior written permission.
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00026  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00027  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00028  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00029  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00030  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00031  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00033  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00034  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00035  * POSSIBILITY OF SUCH DAMAGE.
00036  *
00037  * $Id$
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); // Output mesh must have data associated with the vertices!
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); // Minimum number (triangle)
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   } // End namespace geometry
00132 } // End namespace pcl
00133 
00134 #endif // PCL_GEOMETRY_MESH_CONVERSION_H


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:25:32