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 #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
00084
00085
00086
00087
00088
00089
00090
00091
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
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
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 }