test_triangle_mesh.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 <vector>
00042 #include <typeinfo>
00043 
00044 #include <gtest/gtest.h>
00045 
00046 #include <pcl/geometry/triangle_mesh.h>
00047 
00048 #include "test_mesh_common_functions.h"
00049 
00051 
00052 typedef pcl::geometry::VertexIndex   VertexIndex;
00053 typedef pcl::geometry::HalfEdgeIndex HalfEdgeIndex;
00054 typedef pcl::geometry::EdgeIndex     EdgeIndex;
00055 typedef pcl::geometry::FaceIndex     FaceIndex;
00056 
00057 typedef std::vector <VertexIndex>   VertexIndices;
00058 typedef std::vector <HalfEdgeIndex> HalfEdgeIndices;
00059 typedef std::vector <FaceIndex>     FaceIndices;
00060 
00061 template <bool IsManifoldT>
00062 struct MeshTraits
00063 {
00064     typedef int                                          VertexData;
00065     typedef pcl::geometry::NoData                        HalfEdgeData;
00066     typedef pcl::geometry::NoData                        EdgeData;
00067     typedef pcl::geometry::NoData                        FaceData;
00068     typedef boost::integral_constant <bool, IsManifoldT> IsManifold;
00069 };
00070 
00071 typedef pcl::geometry::TriangleMesh <MeshTraits <true > > ManifoldTriangleMesh;
00072 typedef pcl::geometry::TriangleMesh <MeshTraits <false> > NonManifoldTriangleMesh;
00073 
00074 typedef testing::Types <ManifoldTriangleMesh, NonManifoldTriangleMesh> TriangleMeshTypes;
00075 
00076 template <class MeshT>
00077 class TestTriangleMesh : public testing::Test
00078 {
00079   protected:
00080     typedef MeshT Mesh;
00081 };
00082 
00083 TYPED_TEST_CASE (TestTriangleMesh, TriangleMeshTypes);
00084 
00086 
00087 TYPED_TEST (TestTriangleMesh, CorrectMeshTag)
00088 {
00089   typedef typename TestFixture::Mesh Mesh;
00090   typedef typename Mesh::MeshTag     MeshTag;
00091 
00092   ASSERT_EQ (typeid (pcl::geometry::TriangleMeshTag), typeid (MeshTag));
00093 }
00094 
00096 
00097 TYPED_TEST (TestTriangleMesh, CorrectNumberOfVertices)
00098 {
00099   // Make sure that only quads can be added
00100   typedef typename TestFixture::Mesh Mesh;
00101 
00102   for (unsigned int n=1; n<=5; ++n)
00103   {
00104     Mesh mesh;
00105     VertexIndices vi;
00106     for (unsigned int i=0; i<n; ++i)
00107     {
00108       vi.push_back (VertexIndex (i));
00109       mesh.addVertex (i);
00110     }
00111 
00112     const FaceIndex index = mesh.addFace (vi);
00113     if (n==3) EXPECT_TRUE  (index.isValid ()) << "Number of vertices in the face: " << n;
00114     else      EXPECT_FALSE (index.isValid ()) << "Number of vertices in the face: " << n;
00115   }
00116 }
00117 
00119 
00120 TYPED_TEST (TestTriangleMesh, OneTriangle)
00121 {
00122   typedef typename TestFixture::Mesh Mesh;
00123 
00124   //   2   //
00125   //  / \  //
00126   // 0 - 1 //
00127   Mesh mesh;
00128   VertexIndices vi;
00129   for (unsigned int i=0; i<3; ++i) vi.push_back (mesh.addVertex (i));
00130 
00131   const FaceIndex fi = mesh.addFace (vi);
00132   ASSERT_TRUE (fi.isValid ());
00133 
00134   const HalfEdgeIndex he_10 = mesh.getOutgoingHalfEdgeIndex (vi [1]);
00135   const HalfEdgeIndex he_21 = mesh.getOutgoingHalfEdgeIndex (vi [2]);
00136   const HalfEdgeIndex he_02 = mesh.getOutgoingHalfEdgeIndex (vi [0]);
00137 
00138   const HalfEdgeIndex he_01 = mesh.getOppositeHalfEdgeIndex (he_10);
00139   const HalfEdgeIndex he_12 = mesh.getOppositeHalfEdgeIndex (he_21);
00140   const HalfEdgeIndex he_20 = mesh.getOppositeHalfEdgeIndex (he_02);
00141 
00142   EXPECT_TRUE (checkHalfEdge (mesh, he_10, vi [1], vi[0]));
00143   EXPECT_TRUE (checkHalfEdge (mesh, he_21, vi [2], vi[1]));
00144   EXPECT_TRUE (checkHalfEdge (mesh, he_02, vi [0], vi[2]));
00145 
00146   EXPECT_TRUE (checkHalfEdge (mesh, he_01, vi [0], vi[1]));
00147   EXPECT_TRUE (checkHalfEdge (mesh, he_12, vi [1], vi[2]));
00148   EXPECT_TRUE (checkHalfEdge (mesh, he_20, vi [2], vi[0]));
00149 
00150   EXPECT_EQ (he_01, mesh.getIncomingHalfEdgeIndex (vi [1]));
00151   EXPECT_EQ (he_12, mesh.getIncomingHalfEdgeIndex (vi [2]));
00152   EXPECT_EQ (he_20, mesh.getIncomingHalfEdgeIndex (vi [0]));
00153 
00154   EXPECT_EQ (he_12, mesh.getNextHalfEdgeIndex (he_01));
00155   EXPECT_EQ (he_20, mesh.getNextHalfEdgeIndex (he_12));
00156   EXPECT_EQ (he_01, mesh.getNextHalfEdgeIndex (he_20));
00157 
00158   EXPECT_EQ (he_20, mesh.getPrevHalfEdgeIndex (he_01));
00159   EXPECT_EQ (he_01, mesh.getPrevHalfEdgeIndex (he_12));
00160   EXPECT_EQ (he_12, mesh.getPrevHalfEdgeIndex (he_20));
00161 
00162   EXPECT_EQ (he_02, mesh.getNextHalfEdgeIndex (he_10));
00163   EXPECT_EQ (he_21, mesh.getNextHalfEdgeIndex (he_02));
00164   EXPECT_EQ (he_10, mesh.getNextHalfEdgeIndex (he_21));
00165 
00166   EXPECT_EQ (he_21, mesh.getPrevHalfEdgeIndex (he_10));
00167   EXPECT_EQ (he_10, mesh.getPrevHalfEdgeIndex (he_02));
00168   EXPECT_EQ (he_02, mesh.getPrevHalfEdgeIndex (he_21));
00169 
00170   EXPECT_EQ (fi, mesh.getFaceIndex (he_01));
00171   EXPECT_EQ (fi, mesh.getFaceIndex (he_12));
00172   EXPECT_EQ (fi, mesh.getFaceIndex (he_20));
00173 
00174   EXPECT_FALSE (mesh.getOppositeFaceIndex (he_01).isValid ());
00175   EXPECT_FALSE (mesh.getOppositeFaceIndex (he_12).isValid ());
00176   EXPECT_FALSE (mesh.getOppositeFaceIndex (he_20).isValid ());
00177 
00178   EXPECT_FALSE (mesh.getFaceIndex (he_10).isValid ());
00179   EXPECT_FALSE (mesh.getFaceIndex (he_21).isValid ());
00180   EXPECT_FALSE (mesh.getFaceIndex (he_02).isValid ());
00181 
00182   EXPECT_EQ (fi, mesh.getOppositeFaceIndex (he_10));
00183   EXPECT_EQ (fi, mesh.getOppositeFaceIndex (he_21));
00184   EXPECT_EQ (fi, mesh.getOppositeFaceIndex (he_02));
00185 
00186   EXPECT_EQ (he_20, mesh.getInnerHalfEdgeIndex (fi));
00187   EXPECT_EQ (he_02, mesh.getOuterHalfEdgeIndex (fi));
00188 
00189   EXPECT_FALSE (mesh.isBoundary (he_01));
00190   EXPECT_FALSE (mesh.isBoundary (he_12));
00191   EXPECT_FALSE (mesh.isBoundary (he_20));
00192 
00193   EXPECT_TRUE (mesh.isBoundary (he_10));
00194   EXPECT_TRUE (mesh.isBoundary (he_21));
00195   EXPECT_TRUE (mesh.isBoundary (he_02));
00196 
00197   EXPECT_TRUE (mesh.isBoundary (vi [0]));
00198   EXPECT_TRUE (mesh.isBoundary (vi [1]));
00199   EXPECT_TRUE (mesh.isBoundary (vi [2]));
00200 
00201   EXPECT_TRUE (mesh.isBoundary (fi));
00202 }
00203 
00205 
00206 TYPED_TEST (TestTriangleMesh, TwoTriangles)
00207 {
00208   typedef typename TestFixture::Mesh Mesh;
00209 
00210   // 3 - 2   //
00211   //  \ / \  //
00212   //   0 - 1 //
00213   Mesh mesh;
00214   VertexIndex vi_0 = mesh.addVertex (0);
00215   VertexIndex vi_1 = mesh.addVertex (1);
00216   VertexIndex vi_2 = mesh.addVertex (2);
00217   VertexIndex vi_3 = mesh.addVertex (3);
00218 
00219   // First face
00220   VertexIndices vi;
00221   vi.push_back (vi_0);
00222   vi.push_back (vi_1);
00223   vi.push_back (vi_2);
00224   const FaceIndex fi_0 = mesh.addFace (vi);
00225   ASSERT_TRUE (fi_0.isValid ());
00226 
00227   const HalfEdgeIndex he_10 = mesh.getOutgoingHalfEdgeIndex (vi_1);
00228   const HalfEdgeIndex he_21 = mesh.getOutgoingHalfEdgeIndex (vi_2);
00229   const HalfEdgeIndex he_02 = mesh.getOutgoingHalfEdgeIndex (vi_0);
00230 
00231   const HalfEdgeIndex he_01 = mesh.getOppositeHalfEdgeIndex (he_10);
00232   const HalfEdgeIndex he_12 = mesh.getOppositeHalfEdgeIndex (he_21);
00233   const HalfEdgeIndex he_20 = mesh.getOppositeHalfEdgeIndex (he_02);
00234 
00235   // Second face
00236   vi.clear ();
00237   vi.push_back (vi_0);
00238   vi.push_back (vi_2);
00239   vi.push_back (vi_3);
00240   const FaceIndex fi_1 = mesh.addFace (vi);
00241   ASSERT_TRUE (fi_1.isValid ());
00242 
00243   const HalfEdgeIndex he_03 = mesh.getOutgoingHalfEdgeIndex (vi_0);
00244   const HalfEdgeIndex he_32 = mesh.getOutgoingHalfEdgeIndex (vi_3);
00245 
00246   const HalfEdgeIndex he_30 = mesh.getOppositeHalfEdgeIndex (he_03);
00247   const HalfEdgeIndex he_23 = mesh.getOppositeHalfEdgeIndex (he_32);
00248 
00249   // Tests
00250   EXPECT_TRUE (checkHalfEdge (mesh, he_01, vi_0, vi_1));
00251   EXPECT_TRUE (checkHalfEdge (mesh, he_12, vi_1, vi_2));
00252   EXPECT_TRUE (checkHalfEdge (mesh, he_20, vi_2, vi_0));
00253 
00254   EXPECT_TRUE (checkHalfEdge (mesh, he_02, vi_0, vi_2));
00255   EXPECT_TRUE (checkHalfEdge (mesh, he_23, vi_2, vi_3));
00256   EXPECT_TRUE (checkHalfEdge (mesh, he_30, vi_3, vi_0));
00257 
00258   EXPECT_TRUE (checkHalfEdge (mesh, he_03, vi_0, vi_3));
00259   EXPECT_TRUE (checkHalfEdge (mesh, he_32, vi_3, vi_2));
00260   EXPECT_TRUE (checkHalfEdge (mesh, he_21, vi_2, vi_1));
00261   EXPECT_TRUE (checkHalfEdge (mesh, he_10, vi_1, vi_0));
00262 
00263   EXPECT_EQ (he_12, mesh.getNextHalfEdgeIndex (he_01));
00264   EXPECT_EQ (he_20, mesh.getNextHalfEdgeIndex (he_12));
00265   EXPECT_EQ (he_01, mesh.getNextHalfEdgeIndex (he_20));
00266 
00267   EXPECT_EQ (he_20, mesh.getPrevHalfEdgeIndex (he_01));
00268   EXPECT_EQ (he_01, mesh.getPrevHalfEdgeIndex (he_12));
00269   EXPECT_EQ (he_12, mesh.getPrevHalfEdgeIndex (he_20));
00270 
00271   EXPECT_EQ (he_23, mesh.getNextHalfEdgeIndex (he_02));
00272   EXPECT_EQ (he_30, mesh.getNextHalfEdgeIndex (he_23));
00273   EXPECT_EQ (he_02, mesh.getNextHalfEdgeIndex (he_30));
00274 
00275   EXPECT_EQ (he_30, mesh.getPrevHalfEdgeIndex (he_02));
00276   EXPECT_EQ (he_02, mesh.getPrevHalfEdgeIndex (he_23));
00277   EXPECT_EQ (he_23, mesh.getPrevHalfEdgeIndex (he_30));
00278 
00279   EXPECT_EQ (he_03, mesh.getNextHalfEdgeIndex (he_10));
00280   EXPECT_EQ (he_32, mesh.getNextHalfEdgeIndex (he_03));
00281   EXPECT_EQ (he_21, mesh.getNextHalfEdgeIndex (he_32));
00282   EXPECT_EQ (he_10, mesh.getNextHalfEdgeIndex (he_21));
00283 
00284   EXPECT_EQ (he_21, mesh.getPrevHalfEdgeIndex (he_10));
00285   EXPECT_EQ (he_10, mesh.getPrevHalfEdgeIndex (he_03));
00286   EXPECT_EQ (he_03, mesh.getPrevHalfEdgeIndex (he_32));
00287   EXPECT_EQ (he_32, mesh.getPrevHalfEdgeIndex (he_21));
00288 
00289   EXPECT_EQ (fi_0, mesh.getFaceIndex (he_01));
00290   EXPECT_EQ (fi_0, mesh.getFaceIndex (he_12));
00291   EXPECT_EQ (fi_0, mesh.getFaceIndex (he_20));
00292 
00293   EXPECT_EQ (fi_1, mesh.getFaceIndex (he_02));
00294   EXPECT_EQ (fi_1, mesh.getFaceIndex (he_23));
00295   EXPECT_EQ (fi_1, mesh.getFaceIndex (he_30));
00296 
00297   EXPECT_FALSE (mesh.getFaceIndex (he_10).isValid ());
00298   EXPECT_FALSE (mesh.getFaceIndex (he_03).isValid ());
00299   EXPECT_FALSE (mesh.getFaceIndex (he_32).isValid ());
00300   EXPECT_FALSE (mesh.getFaceIndex (he_21).isValid ());
00301 
00302   EXPECT_FALSE (mesh.getOppositeFaceIndex (he_01).isValid ());
00303   EXPECT_FALSE (mesh.getOppositeFaceIndex (he_12).isValid ());
00304   EXPECT_FALSE (mesh.getOppositeFaceIndex (he_23).isValid ());
00305   EXPECT_FALSE (mesh.getOppositeFaceIndex (he_30).isValid ());
00306 
00307   EXPECT_EQ (fi_0, mesh.getOppositeFaceIndex (he_21));
00308   EXPECT_EQ (fi_0, mesh.getOppositeFaceIndex (he_10));
00309   EXPECT_EQ (fi_1, mesh.getOppositeFaceIndex (he_03));
00310   EXPECT_EQ (fi_1, mesh.getOppositeFaceIndex (he_32));
00311 
00312   EXPECT_EQ (he_20, mesh.getInnerHalfEdgeIndex (fi_0));
00313   EXPECT_EQ (he_30, mesh.getInnerHalfEdgeIndex (fi_1));
00314 
00315   EXPECT_EQ (he_02, mesh.getOuterHalfEdgeIndex (fi_0));
00316   EXPECT_EQ (he_03, mesh.getOuterHalfEdgeIndex (fi_1));
00317 
00318   EXPECT_FALSE (mesh.isBoundary (he_01));
00319   EXPECT_FALSE (mesh.isBoundary (he_12));
00320   EXPECT_FALSE (mesh.isBoundary (he_20));
00321 
00322   EXPECT_FALSE (mesh.isBoundary (he_02));
00323   EXPECT_FALSE (mesh.isBoundary (he_23));
00324   EXPECT_FALSE (mesh.isBoundary (he_30));
00325 
00326   EXPECT_TRUE (mesh.isBoundary (he_10));
00327   EXPECT_TRUE (mesh.isBoundary (he_03));
00328   EXPECT_TRUE (mesh.isBoundary (he_32));
00329   EXPECT_TRUE (mesh.isBoundary (he_21));
00330 
00331   EXPECT_TRUE (mesh.isBoundary (vi_0));
00332   EXPECT_TRUE (mesh.isBoundary (vi_1));
00333   EXPECT_TRUE (mesh.isBoundary (vi_2));
00334   EXPECT_TRUE (mesh.isBoundary (vi_3));
00335 
00336   EXPECT_TRUE (mesh.isBoundary (fi_0));
00337   EXPECT_TRUE (mesh.isBoundary (fi_1));
00338 }
00339 
00341 
00342 TYPED_TEST (TestTriangleMesh, ThreeTriangles)
00343 {
00344   typedef typename TestFixture::Mesh Mesh;
00345 
00346   //  1 ----- 3  //
00347   //  \ \   / /  //
00348   //   \  0  /   //
00349   //    \ | /    //
00350   //      2      //
00351   Mesh mesh;
00352   VertexIndex vi_0 = mesh.addVertex (0);
00353   VertexIndex vi_1 = mesh.addVertex (1);
00354   VertexIndex vi_2 = mesh.addVertex (2);
00355   VertexIndex vi_3 = mesh.addVertex (3);
00356 
00357   // First face
00358   VertexIndices vi;
00359   vi.push_back (vi_0);
00360   vi.push_back (vi_1);
00361   vi.push_back (vi_2);
00362   const FaceIndex fi_0 = mesh.addFace (vi);
00363   ASSERT_TRUE (fi_0.isValid ());
00364 
00365   const HalfEdgeIndex he_10 = mesh.getOutgoingHalfEdgeIndex (vi_1);
00366   const HalfEdgeIndex he_21 = mesh.getOutgoingHalfEdgeIndex (vi_2);
00367   const HalfEdgeIndex he_02 = mesh.getOutgoingHalfEdgeIndex (vi_0);
00368 
00369   const HalfEdgeIndex he_01 = mesh.getOppositeHalfEdgeIndex (he_10);
00370   const HalfEdgeIndex he_12 = mesh.getOppositeHalfEdgeIndex (he_21);
00371   const HalfEdgeIndex he_20 = mesh.getOppositeHalfEdgeIndex (he_02);
00372 
00373   // Second face
00374   vi.clear ();
00375   vi.push_back (vi_0);
00376   vi.push_back (vi_2);
00377   vi.push_back (vi_3);
00378   const FaceIndex fi_1 = mesh.addFace (vi);
00379   ASSERT_TRUE (fi_1.isValid ());
00380 
00381   const HalfEdgeIndex he_03 = mesh.getOutgoingHalfEdgeIndex (vi_0);
00382   const HalfEdgeIndex he_32 = mesh.getOutgoingHalfEdgeIndex (vi_3);
00383 
00384   const HalfEdgeIndex he_30 = mesh.getOppositeHalfEdgeIndex (he_03);
00385   const HalfEdgeIndex he_23 = mesh.getOppositeHalfEdgeIndex (he_32);
00386 
00387   // Third face
00388   vi.clear ();
00389   vi.push_back (vi_0);
00390   vi.push_back (vi_3);
00391   vi.push_back (vi_1);
00392   const FaceIndex fi_2 = mesh.addFace (vi);
00393   ASSERT_TRUE (fi_2.isValid ());
00394 
00395   const HalfEdgeIndex he_13 = mesh.getOutgoingHalfEdgeIndex (vi_1);
00396 
00397   const HalfEdgeIndex he_31 = mesh.getOppositeHalfEdgeIndex (he_13);
00398 
00399   // Tests
00400   EXPECT_TRUE (checkHalfEdge (mesh, he_01, vi_0, vi_1));
00401   EXPECT_TRUE (checkHalfEdge (mesh, he_12, vi_1, vi_2));
00402   EXPECT_TRUE (checkHalfEdge (mesh, he_20, vi_2, vi_0));
00403 
00404   EXPECT_TRUE (checkHalfEdge (mesh, he_02, vi_0, vi_2));
00405   EXPECT_TRUE (checkHalfEdge (mesh, he_23, vi_2, vi_3));
00406   EXPECT_TRUE (checkHalfEdge (mesh, he_30, vi_3, vi_0));
00407 
00408   EXPECT_TRUE (checkHalfEdge (mesh, he_03, vi_0, vi_3));
00409   EXPECT_TRUE (checkHalfEdge (mesh, he_31, vi_3, vi_1));
00410   EXPECT_TRUE (checkHalfEdge (mesh, he_10, vi_1, vi_0));
00411 
00412   EXPECT_TRUE (checkHalfEdge (mesh, he_32, vi_3, vi_2));
00413   EXPECT_TRUE (checkHalfEdge (mesh, he_21, vi_2, vi_1));
00414   EXPECT_TRUE (checkHalfEdge (mesh, he_13, vi_1, vi_3));
00415 
00416   EXPECT_EQ (he_12, mesh.getNextHalfEdgeIndex (he_01));
00417   EXPECT_EQ (he_20, mesh.getNextHalfEdgeIndex (he_12));
00418   EXPECT_EQ (he_01, mesh.getNextHalfEdgeIndex (he_20));
00419 
00420   EXPECT_EQ (he_23, mesh.getNextHalfEdgeIndex (he_02));
00421   EXPECT_EQ (he_30, mesh.getNextHalfEdgeIndex (he_23));
00422   EXPECT_EQ (he_02, mesh.getNextHalfEdgeIndex (he_30));
00423 
00424   EXPECT_EQ (he_31, mesh.getNextHalfEdgeIndex (he_03));
00425   EXPECT_EQ (he_10, mesh.getNextHalfEdgeIndex (he_31));
00426   EXPECT_EQ (he_03, mesh.getNextHalfEdgeIndex (he_10));
00427 
00428   EXPECT_EQ (he_21, mesh.getNextHalfEdgeIndex (he_32));
00429   EXPECT_EQ (he_13, mesh.getNextHalfEdgeIndex (he_21));
00430   EXPECT_EQ (he_32, mesh.getNextHalfEdgeIndex (he_13));
00431 
00432   EXPECT_EQ (he_20, mesh.getPrevHalfEdgeIndex (he_01));
00433   EXPECT_EQ (he_01, mesh.getPrevHalfEdgeIndex (he_12));
00434   EXPECT_EQ (he_12, mesh.getPrevHalfEdgeIndex (he_20));
00435 
00436   EXPECT_EQ (he_30, mesh.getPrevHalfEdgeIndex (he_02));
00437   EXPECT_EQ (he_02, mesh.getPrevHalfEdgeIndex (he_23));
00438   EXPECT_EQ (he_23, mesh.getPrevHalfEdgeIndex (he_30));
00439 
00440   EXPECT_EQ (he_10, mesh.getPrevHalfEdgeIndex (he_03));
00441   EXPECT_EQ (he_03, mesh.getPrevHalfEdgeIndex (he_31));
00442   EXPECT_EQ (he_31, mesh.getPrevHalfEdgeIndex (he_10));
00443 
00444   EXPECT_EQ (he_13, mesh.getPrevHalfEdgeIndex (he_32));
00445   EXPECT_EQ (he_32, mesh.getPrevHalfEdgeIndex (he_21));
00446   EXPECT_EQ (he_21, mesh.getPrevHalfEdgeIndex (he_13));
00447 
00448   EXPECT_EQ (fi_0, mesh.getFaceIndex (he_01));
00449   EXPECT_EQ (fi_0, mesh.getFaceIndex (he_12));
00450   EXPECT_EQ (fi_0, mesh.getFaceIndex (he_20));
00451 
00452   EXPECT_EQ (fi_1, mesh.getFaceIndex (he_02));
00453   EXPECT_EQ (fi_1, mesh.getFaceIndex (he_23));
00454   EXPECT_EQ (fi_1, mesh.getFaceIndex (he_30));
00455 
00456   EXPECT_EQ (fi_2, mesh.getFaceIndex (he_03));
00457   EXPECT_EQ (fi_2, mesh.getFaceIndex (he_31));
00458   EXPECT_EQ (fi_2, mesh.getFaceIndex (he_10));
00459 
00460   EXPECT_FALSE (mesh.getFaceIndex (he_32).isValid ());
00461   EXPECT_FALSE (mesh.getFaceIndex (he_21).isValid ());
00462   EXPECT_FALSE (mesh.getFaceIndex (he_13).isValid ());
00463 
00464   EXPECT_EQ (fi_2, mesh.getOppositeFaceIndex (he_01));
00465   EXPECT_FALSE    (mesh.getOppositeFaceIndex (he_12).isValid ());
00466   EXPECT_EQ (fi_1, mesh.getOppositeFaceIndex (he_20));
00467 
00468   EXPECT_EQ (fi_0, mesh.getOppositeFaceIndex (he_02));
00469   EXPECT_FALSE    (mesh.getOppositeFaceIndex (he_23).isValid ());
00470   EXPECT_EQ (fi_2, mesh.getOppositeFaceIndex (he_30));
00471 
00472   EXPECT_EQ (fi_1, mesh.getOppositeFaceIndex (he_03));
00473   EXPECT_FALSE    (mesh.getOppositeFaceIndex (he_31).isValid ());
00474   EXPECT_EQ (fi_0, mesh.getOppositeFaceIndex (he_10));
00475 
00476   EXPECT_EQ (fi_1, mesh.getOppositeFaceIndex (he_32));
00477   EXPECT_EQ (fi_0, mesh.getOppositeFaceIndex (he_21));
00478   EXPECT_EQ (fi_2, mesh.getOppositeFaceIndex (he_13));
00479 
00480   EXPECT_EQ (he_20, mesh.getInnerHalfEdgeIndex (fi_0));
00481   EXPECT_EQ (he_30, mesh.getInnerHalfEdgeIndex (fi_1));
00482   EXPECT_EQ (he_10, mesh.getInnerHalfEdgeIndex (fi_2));
00483 
00484   EXPECT_EQ (he_02, mesh.getOuterHalfEdgeIndex (fi_0));
00485   EXPECT_EQ (he_03, mesh.getOuterHalfEdgeIndex (fi_1));
00486   EXPECT_EQ (he_01, mesh.getOuterHalfEdgeIndex (fi_2));
00487 
00488   EXPECT_FALSE (mesh.isBoundary (he_01));
00489   EXPECT_FALSE (mesh.isBoundary (he_12));
00490   EXPECT_FALSE (mesh.isBoundary (he_20));
00491 
00492   EXPECT_FALSE (mesh.isBoundary (he_02));
00493   EXPECT_FALSE (mesh.isBoundary (he_23));
00494   EXPECT_FALSE (mesh.isBoundary (he_30));
00495 
00496   EXPECT_FALSE (mesh.isBoundary (he_03));
00497   EXPECT_FALSE (mesh.isBoundary (he_31));
00498   EXPECT_FALSE (mesh.isBoundary (he_10));
00499 
00500   EXPECT_TRUE  (mesh.isBoundary (he_32));
00501   EXPECT_TRUE  (mesh.isBoundary (he_21));
00502   EXPECT_TRUE  (mesh.isBoundary (he_13));
00503 
00504   EXPECT_FALSE (mesh.isBoundary (vi_0));
00505   EXPECT_TRUE  (mesh.isBoundary (vi_1));
00506   EXPECT_TRUE  (mesh.isBoundary (vi_2));
00507   EXPECT_TRUE  (mesh.isBoundary (vi_3));
00508 
00509   EXPECT_TRUE (mesh.isBoundary (fi_0));
00510   EXPECT_TRUE (mesh.isBoundary (fi_1));
00511   EXPECT_TRUE (mesh.isBoundary (fi_2));
00512 }
00513 
00515 
00516 TEST (TestManifoldTriangleMesh, addTrianglePair)
00517 {
00518   ManifoldTriangleMesh mesh;
00519   VertexIndices vi;
00520   for (unsigned int i=0; i<16; ++i)
00521   {
00522     vi.push_back (mesh.addVertex ());
00523   }
00524 
00525   // 00 - 01 - 02 - 03 // X means that both connections / and \ are possible.
00526   //  | X  | X  | X  | //
00527   // 04 - 05 - 06 - 07 //
00528   //  | X  | X  | X  | //
00529   // 08 - 09 - 10 - 11 //
00530   //  | X  | X  | X  | //
00531   // 12 - 13 - 14 - 15 //
00532   VertexIndices tmp;
00533   std::vector <VertexIndices> faces;
00534   tmp.push_back (vi [ 0]); tmp.push_back (vi [ 4]); tmp.push_back (vi [ 5]); tmp.push_back (vi [ 1]); faces.push_back (tmp); tmp.clear ();
00535   tmp.push_back (vi [ 2]); tmp.push_back (vi [ 6]); tmp.push_back (vi [ 7]); tmp.push_back (vi [ 3]); faces.push_back (tmp); tmp.clear ();
00536   tmp.push_back (vi [ 1]); tmp.push_back (vi [ 5]); tmp.push_back (vi [ 6]); tmp.push_back (vi [ 2]); faces.push_back (tmp); tmp.clear ();
00537   tmp.push_back (vi [ 8]); tmp.push_back (vi [12]); tmp.push_back (vi [13]); tmp.push_back (vi [ 9]); faces.push_back (tmp); tmp.clear ();
00538   tmp.push_back (vi [10]); tmp.push_back (vi [14]); tmp.push_back (vi [15]); tmp.push_back (vi [11]); faces.push_back (tmp); tmp.clear ();
00539   tmp.push_back (vi [ 9]); tmp.push_back (vi [13]); tmp.push_back (vi [14]); tmp.push_back (vi [10]); faces.push_back (tmp); tmp.clear ();
00540   tmp.push_back (vi [ 4]); tmp.push_back (vi [ 8]); tmp.push_back (vi [ 9]); tmp.push_back (vi [ 5]); faces.push_back (tmp); tmp.clear ();
00541   tmp.push_back (vi [ 6]); tmp.push_back (vi [10]); tmp.push_back (vi [11]); tmp.push_back (vi [ 7]); faces.push_back (tmp); tmp.clear ();
00542   tmp.push_back (vi [ 5]); tmp.push_back (vi [ 9]); tmp.push_back (vi [10]); tmp.push_back (vi [ 6]); faces.push_back (tmp); tmp.clear ();
00543 
00544   for (unsigned int i=0; i<faces.size (); ++i)
00545   {
00546     std::pair <FaceIndex, FaceIndex> fip;
00547     fip = mesh.addTrianglePair (faces [i]);
00548     ASSERT_TRUE (fip.first.isValid ());
00549     ASSERT_TRUE (fip.second.isValid ());
00550   }
00551 
00552   for (unsigned int i=0; i<faces.size (); ++i)
00553   {
00554     VertexIndices actual_1, actual_2;
00555 
00556     ManifoldTriangleMesh::VertexAroundFaceCirculator circ     = mesh.getVertexAroundFaceCirculator (FaceIndex (2*i));
00557     ManifoldTriangleMesh::VertexAroundFaceCirculator circ_end = circ;
00558     do
00559     {
00560       actual_1.push_back (circ.getTargetIndex ());
00561     } while (++circ != circ_end);
00562 
00563     circ     = mesh.getVertexAroundFaceCirculator (FaceIndex (2*i + 1));
00564     circ_end = circ;
00565     do
00566     {
00567       actual_2.push_back (circ.getTargetIndex ());
00568     } while (++circ != circ_end);
00569 
00570     VertexIndices expected_1, expected_2, expected_3, expected_4;
00571     tmp = faces [i];
00572     expected_1.push_back (tmp [0]); expected_1.push_back (tmp [1]); expected_1.push_back (tmp [2]);
00573     expected_2.push_back (tmp [0]); expected_2.push_back (tmp [2]); expected_2.push_back (tmp [3]);
00574     expected_3.push_back (tmp [0]); expected_3.push_back (tmp [1]); expected_3.push_back (tmp [3]);
00575     expected_4.push_back (tmp [1]); expected_4.push_back (tmp [2]); expected_4.push_back (tmp [3]);
00576 
00577     EXPECT_TRUE ((isCircularPermutation (expected_1, actual_1) && isCircularPermutation (expected_2, actual_2)) ||
00578                  (isCircularPermutation (expected_2, actual_1) && isCircularPermutation (expected_1, actual_2)) ||
00579                  (isCircularPermutation (expected_3, actual_1) && isCircularPermutation (expected_4, actual_2)) ||
00580                  (isCircularPermutation (expected_4, actual_1) && isCircularPermutation (expected_3, actual_2)));
00581   }
00582 }
00583 
00585 
00586 int
00587 main (int argc, char** argv)
00588 {
00589   testing::InitGoogleTest (&argc, argv);
00590   return (RUN_ALL_TESTS ());
00591 }


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:36:16