test_mesh_get_boundary.cpp
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 #include <gtest/gtest.h>
00042 
00043 #include <pcl/geometry/polygon_mesh.h>
00044 #include <pcl/geometry/get_boundary.h>
00045 #include "test_mesh_common_functions.h"
00046 
00048 
00049 template <bool IsManifoldT>
00050 struct MeshTraits
00051 {
00052     typedef pcl::geometry::NoData                        VertexData;
00053     typedef pcl::geometry::NoData                        HalfEdgeData;
00054     typedef pcl::geometry::NoData                        EdgeData;
00055     typedef pcl::geometry::NoData                        FaceData;
00056     typedef boost::integral_constant <bool, IsManifoldT> IsManifold;
00057 };
00058 
00059 typedef pcl::geometry::PolygonMesh <MeshTraits <true > > ManifoldMesh;
00060 typedef pcl::geometry::PolygonMesh <MeshTraits <false> > NonManifoldMesh;
00061 
00062 typedef testing::Types <ManifoldMesh, NonManifoldMesh> MeshTypes;
00063 
00064 template <class MeshT>
00065 class TestGetBoundary : public testing::Test
00066 {
00067   protected:
00068     typedef MeshT Mesh;
00069 };
00070 
00071 TYPED_TEST_CASE (TestGetBoundary, MeshTypes);
00072 
00074 
00075 TYPED_TEST (TestGetBoundary, GetBoundaryHalfEdges)
00076 {
00077   typedef typename TestFixture::Mesh Mesh;
00078 
00079 
00080   typedef typename Mesh::VertexIndices   VertexIndices;
00081   typedef typename Mesh::HalfEdgeIndices HalfEdgeIndices;
00082 
00083   //  0 -  1 -  2 -  3
00084   //  |    |    |    |
00085   //  4 -  5 -  6 -  7
00086   //  |    |    |    |
00087   //  8 -  9   10 - 11
00088   //  |    |    |    |
00089   // 12 - 13 - 14 - 15
00090   //  |    |    |    |
00091   // 16 - 17 - 18 - 19
00092 
00093   Mesh mesh;
00094   VertexIndices vi;
00095 
00096   for (int i=0; i<23; ++i) vi.push_back (mesh.addVertex ());
00097 
00098   ASSERT_TRUE (mesh.addFace (vi [ 0], vi [ 4], vi [ 5], vi [ 1]).isValid ());
00099   ASSERT_TRUE (mesh.addFace (vi [ 1], vi [ 5], vi [ 6], vi [ 2]).isValid ());
00100   ASSERT_TRUE (mesh.addFace (vi [ 2], vi [ 6], vi [ 7], vi [ 3]).isValid ());
00101   ASSERT_TRUE (mesh.addFace (vi [ 4], vi [ 8], vi [ 9], vi [ 5]).isValid ());
00102   ASSERT_TRUE (mesh.addFace (vi [ 6], vi [10], vi [11], vi [ 7]).isValid ());
00103   ASSERT_TRUE (mesh.addFace (vi [ 8], vi [12], vi [13], vi [ 9]).isValid ());
00104   ASSERT_TRUE (mesh.addFace (vi [10], vi [14], vi [15], vi [11]).isValid ());
00105   ASSERT_TRUE (mesh.addFace (vi [12], vi [16], vi [17], vi [13]).isValid ());
00106   ASSERT_TRUE (mesh.addFace (vi [14], vi [18], vi [19], vi [15]).isValid ());
00107   ASSERT_TRUE (mesh.addFace (vi [13], vi [17], vi [18], vi [14]).isValid ());
00108 
00109   std::vector <HalfEdgeIndices> expected_boundary_collection;
00110   HalfEdgeIndices               boundary;
00111 
00112   boundary.push_back (findHalfEdge (mesh, vi [ 0], vi [ 1]));
00113   boundary.push_back (findHalfEdge (mesh, vi [ 1], vi [ 2]));
00114   boundary.push_back (findHalfEdge (mesh, vi [ 2], vi [ 3]));
00115   boundary.push_back (findHalfEdge (mesh, vi [ 3], vi [ 7]));
00116   boundary.push_back (findHalfEdge (mesh, vi [ 7], vi [11]));
00117   boundary.push_back (findHalfEdge (mesh, vi [11], vi [15]));
00118   boundary.push_back (findHalfEdge (mesh, vi [15], vi [19]));
00119   boundary.push_back (findHalfEdge (mesh, vi [19], vi [18]));
00120   boundary.push_back (findHalfEdge (mesh, vi [18], vi [17]));
00121   boundary.push_back (findHalfEdge (mesh, vi [17], vi [16]));
00122   boundary.push_back (findHalfEdge (mesh, vi [16], vi [12]));
00123   boundary.push_back (findHalfEdge (mesh, vi [12], vi [ 8]));
00124   boundary.push_back (findHalfEdge (mesh, vi [ 8], vi [ 4]));
00125   boundary.push_back (findHalfEdge (mesh, vi [ 4], vi [ 0]));
00126   expected_boundary_collection.push_back (boundary);
00127   boundary.clear ();
00128 
00129   boundary.push_back (findHalfEdge (mesh, vi [ 5], vi [ 9]));
00130   boundary.push_back (findHalfEdge (mesh, vi [ 9], vi [13]));
00131   boundary.push_back (findHalfEdge (mesh, vi [13], vi [14]));
00132   boundary.push_back (findHalfEdge (mesh, vi [14], vi [10]));
00133   boundary.push_back (findHalfEdge (mesh, vi [10], vi [ 6]));
00134   boundary.push_back (findHalfEdge (mesh, vi [ 6], vi [ 5]));
00135   expected_boundary_collection.push_back (boundary);
00136   boundary.clear ();
00137 
00138   std::vector <HalfEdgeIndices> actual_boundary_collection;
00139 
00140   pcl::geometry::getBoundBoundaryHalfEdges (mesh, actual_boundary_collection);
00141   ASSERT_TRUE (isCircularPermutationVec (expected_boundary_collection, actual_boundary_collection));
00142 
00143   if (Mesh::IsManifold::value) return;
00144 
00145   //  0 -  1 -  2 -  3
00146   //  |    |    |    |
00147   //  4 -  5 -  6 -  7
00148   //  |    |    |    |
00149   //  8 -  9   10 - 11
00150   //  |    |    |    |
00151   // 12 - 13 - 14 - 15
00152   //  |    |    |    |
00153   // 16 - 17 - 18 - 19 - 20
00154   //                 |    |
00155   //                21 - 22
00156   ASSERT_TRUE (mesh.addFace (vi [ 5], vi [ 9], vi [10], vi [ 6]).isValid ());
00157   ASSERT_TRUE (mesh.addFace (vi [19], vi [21], vi [22], vi [20]).isValid ());
00158 
00159   expected_boundary_collection.clear ();
00160 
00161   boundary.push_back (findHalfEdge (mesh, vi [ 0], vi [ 1]));
00162   boundary.push_back (findHalfEdge (mesh, vi [ 1], vi [ 2]));
00163   boundary.push_back (findHalfEdge (mesh, vi [ 2], vi [ 3]));
00164   boundary.push_back (findHalfEdge (mesh, vi [ 3], vi [ 7]));
00165   boundary.push_back (findHalfEdge (mesh, vi [ 7], vi [11]));
00166   boundary.push_back (findHalfEdge (mesh, vi [11], vi [15]));
00167   boundary.push_back (findHalfEdge (mesh, vi [15], vi [19]));
00168   boundary.push_back (findHalfEdge (mesh, vi [19], vi [20]));
00169   boundary.push_back (findHalfEdge (mesh, vi [20], vi [22]));
00170   boundary.push_back (findHalfEdge (mesh, vi [22], vi [21]));
00171   boundary.push_back (findHalfEdge (mesh, vi [21], vi [19]));
00172   boundary.push_back (findHalfEdge (mesh, vi [19], vi [18]));
00173   boundary.push_back (findHalfEdge (mesh, vi [18], vi [17]));
00174   boundary.push_back (findHalfEdge (mesh, vi [17], vi [16]));
00175   boundary.push_back (findHalfEdge (mesh, vi [16], vi [12]));
00176   boundary.push_back (findHalfEdge (mesh, vi [12], vi [ 8]));
00177   boundary.push_back (findHalfEdge (mesh, vi [ 8], vi [ 4]));
00178   boundary.push_back (findHalfEdge (mesh, vi [ 4], vi [ 0]));
00179   expected_boundary_collection.push_back (boundary);
00180   boundary.clear ();
00181 
00182   boundary.push_back (findHalfEdge (mesh, vi [ 9], vi [13]));
00183   boundary.push_back (findHalfEdge (mesh, vi [13], vi [14]));
00184   boundary.push_back (findHalfEdge (mesh, vi [14], vi [10]));
00185   boundary.push_back (findHalfEdge (mesh, vi [10], vi [ 9]));
00186   expected_boundary_collection.push_back (boundary);
00187   boundary.clear ();
00188 
00189   pcl::geometry::getBoundBoundaryHalfEdges (mesh, actual_boundary_collection);
00190   ASSERT_TRUE (isCircularPermutationVec (expected_boundary_collection, actual_boundary_collection));
00191 }
00192 
00194 
00195 int
00196 main (int argc, char** argv)
00197 {
00198   testing::InitGoogleTest (&argc, argv);
00199   return (RUN_ALL_TESTS ());
00200 }


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:35:08