1 /*=========================================================================
2  *
3  *  Copyright Insight Software Consortium
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *         http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  *=========================================================================*/
18 
19 #include "itkQuadEdgeMeshTopologyChecker.h"
20 
21 
itkQuadEdgeMeshAddFaceTest2(int,char * [])22 int itkQuadEdgeMeshAddFaceTest2(int , char *[])
23 {
24   using MeshType = itk::QuadEdgeMesh< double, 3 >;
25   using MeshPointer = MeshType::Pointer;
26   using CellType = MeshType::CellType;
27   using QEPolygonCellType = itk::QuadEdgeMeshPolygonCell< CellType >;
28 
29   int numPts = 7;
30   int numCells = 4;
31 
32   std::cout << "numPts= " << numPts << std::endl;
33   std::cout << "numCells= " << numCells << std::endl;
34 
35   int oddConnectivityCells[12] =
36   { 0, 1, 2,
37     3, 4, 5,
38     6, 4, 0,
39     0, 4, 6, };
40 
41   // Configuration of odd_connectivity mesh:
42   // numVertices=7, numEdges=9, numFaces=3, numBoundaries=1, Chi=2
43   //
44   //    5 ---------- 4 ---------- 0 ---------- 1
45   //    |  [2]   __/ |   [3]  __/   \__  [1]   |
46   //    |     __/    |     __/         \__     |
47   //    |  __/       |  __/               \__  |
48   //    | /          | /                     \ |
49   //    3            6                         2
50   //
51   // First we add the three triangles [0 1 2], [3 4 5], [6 4 0].
52   // Then we try to add a fourth triangle, which is the third triangle
53   // inverted i.e. [0 4 6]. This triangle can not be added.
54 
55   MeshPointer  mesh = MeshType::New();
56 
57   MeshType::PointType pts[7];
58 
59   pts[0][0] = 2.0;  pts[0][1] = 1.0;  pts[0][2] = 0.0;
60   pts[1][0] = 3.0;  pts[1][1] = 1.0;  pts[1][2] = 0.0;
61   pts[2][0] = 3.0;  pts[2][1] = 0.0;  pts[2][2] = 0.0;
62   pts[3][0] = 0.0;  pts[3][1] = 0.0;  pts[3][2] = 0.0;
63   pts[4][0] = 1.0;  pts[4][1] = 1.0;  pts[4][2] = 0.0;
64   pts[5][0] = 0.0;  pts[5][1] = 1.0;  pts[5][2] = 0.0;
65   pts[6][0] = 1.0;  pts[6][1] = 0.0;  pts[6][2] = 0.0;
66 
67   for(int i=0; i<numPts; i++)
68     {
69     mesh->SetPoint( i, pts[i] );
70     }
71 
72   int computedNumPts = mesh->GetNumberOfPoints();
73   std::cout << "computedNumPts= " << computedNumPts << std::endl;
74 
75   CellType::CellAutoPointer cellpointer;
76   QEPolygonCellType *poly;
77 
78   for(int i=0; i<numCells; i++)
79     {
80     poly = new QEPolygonCellType(3);
81     cellpointer.TakeOwnership( poly );
82     cellpointer->SetPointId( 0, oddConnectivityCells[3*i] );
83     cellpointer->SetPointId( 1, oddConnectivityCells[3*i+1] );
84     cellpointer->SetPointId( 2, oddConnectivityCells[3*i+2] );
85     mesh->SetCell( i, cellpointer );
86     }
87 
88   int computedNumFaces = mesh->ComputeNumberOfFaces();
89   std::cout << "computedNumFaces= " << computedNumFaces << std::endl;
90 
91   std::cout << "Test whether the fourth face was rejected" << std::endl;
92 
93   using TopologyCheckerType = itk::QuadEdgeMeshTopologyChecker< MeshType >;
94   TopologyCheckerType::Pointer checker = TopologyCheckerType::New();
95 
96   checker->SetMesh( mesh );
97   checker->SetExpectedNumberOfPoints( 7 );
98   checker->SetExpectedNumberOfEdges( 9 );
99   checker->SetExpectedNumberOfFaces( 3 );
100   checker->SetExpectedNumberOfBoundaries( 3 );
101   checker->SetExpectedGenus( 0 ); // FIXME find the correct genus value
102   checker->GetNameOfClass( );
103   std::cout << "Testing PrintSelf: " << std::endl;
104   std::cout << checker << std::endl;
105   std::cout << "[SUCCESS]" << std::endl;
106 
107   if( checker->ValidateEulerCharacteristic() )
108     {
109     std::cout << "Passed" << std::endl;
110     }
111   else
112     {
113     std::cout << "Failed" << std::endl;
114     return EXIT_FAILURE;
115     }
116 
117   return EXIT_SUCCESS;
118 }
119