ITK  6.0.0
Insight Toolkit
itkQuadEdgeMeshEulerOperatorsTestHelper.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
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 * https://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#ifndef itkQuadEdgeMeshEulerOperatorsTestHelper_h
19#define itkQuadEdgeMeshEulerOperatorsTestHelper_h
20
23
24using IdentifierType = unsigned long;
25
26template <typename TMesh>
27bool
29 IdentifierType NumVertices,
30 IdentifierType NumFaces,
31 IdentifierType NumEdges,
32 IdentifierType NumBorders,
33 IdentifierType Genus)
34{
36 auto check = CheckerType::New();
37 check->SetMesh(mesh);
38 check->SetExpectedNumberOfPoints(NumVertices);
39 check->SetExpectedNumberOfEdges(NumFaces);
40 check->SetExpectedNumberOfFaces(NumEdges);
41 check->SetExpectedNumberOfBoundaries(NumBorders);
42 check->SetExpectedGenus(Genus);
43 return (check->ValidateEulerCharacteristic());
44}
45
46//----------------------------------------------------------------------------
47template <typename TMesh>
48std::vector<typename TMesh::PointType>
49GeneratePointCoordinates(const unsigned int iN)
50{
51 using PointType = typename TMesh::PointType;
52 using CoordRepType = typename PointType::CoordRepType;
53 std::vector<PointType> oPt(iN * iN);
54
55 for (unsigned int i = 0; i < iN; ++i)
56 {
57 for (unsigned int j = 0; j < iN; ++j)
58 {
59 oPt[i * iN + j][0] = static_cast<CoordRepType>(j);
60 oPt[i * iN + j][1] = static_cast<CoordRepType>(i);
61 oPt[i * iN + j][2] = static_cast<CoordRepType>(0.);
62 }
63 }
64
65 return oPt;
66}
67
68//----------------------------------------------------------------------------
69template <typename TMesh>
70void
72{
73 using MeshType = TMesh;
74 using CellType = typename MeshType::CellType;
75
76 using QEPolygonCellType = itk::QuadEdgeMeshPolygonCell<CellType>;
77
78 if (mesh->GetNumberOfPoints())
79 {
80 mesh->Clear();
81 mesh->ClearFreePointAndCellIndexesLists();
82 }
83
85 int expectedNumPts = 25;
86 int expectedNumCells = 16;
87 int simpleSquareCells[64] = { 0, 1, 6, 5, 1, 2, 7, 6, 2, 3, 8, 7, 3, 4, 9, 8, 5, 6, 11, 10, 6, 7,
88 12, 11, 7, 8, 13, 12, 8, 9, 14, 13, 10, 11, 16, 15, 11, 12, 17, 16, 12, 13, 18, 17,
89 13, 14, 19, 18, 15, 16, 21, 20, 16, 17, 22, 21, 17, 18, 23, 22, 18, 19, 24, 23 };
90
91 using PointType = typename MeshType::PointType;
92
93 std::vector<PointType> pts = GeneratePointCoordinates<MeshType>(5);
94
95 for (int i = 0; i < expectedNumPts; ++i)
96 {
97 mesh->SetPoint(i, pts[i]);
98 }
99
100 typename CellType::CellAutoPointer cellpointer;
101 QEPolygonCellType * poly;
102
103 for (int i = 0; i < expectedNumCells; ++i)
104 {
105 poly = new QEPolygonCellType(4);
106 cellpointer.TakeOwnership(poly);
107 cellpointer->SetPointId(0, simpleSquareCells[4 * i]);
108 cellpointer->SetPointId(1, simpleSquareCells[4 * i + 1]);
109 cellpointer->SetPointId(2, simpleSquareCells[4 * i + 2]);
110 cellpointer->SetPointId(3, simpleSquareCells[4 * i + 3]);
111 mesh->SetCell(i, cellpointer);
112 }
113}
114
115//----------------------------------------------------------------------------
116template <typename TMesh>
117void
119{
120 using MeshType = TMesh;
121 using CellType = typename MeshType::CellType;
122
123 using QEPolygonCellType = itk::QuadEdgeMeshPolygonCell<CellType>;
124
125 if (mesh->GetNumberOfPoints())
126 {
127 mesh->Clear();
128 mesh->ClearFreePointAndCellIndexesLists();
129 }
130
132 int expectedNumPts = 25;
133 int expectedNumCells = 32;
134 int simpleSquareCells[96] = { 0, 1, 6, 0, 6, 5, 1, 2, 7, 1, 7, 6, 2, 3, 8, 2, 8, 7, 3, 4,
135 9, 3, 9, 8, 5, 6, 11, 5, 11, 10, 6, 7, 12, 6, 12, 11, 7, 8, 13, 7,
136 13, 12, 8, 9, 14, 8, 14, 13, 10, 11, 16, 10, 16, 15, 11, 12, 17, 11, 17, 16,
137 12, 13, 18, 12, 18, 17, 13, 14, 19, 13, 19, 18, 15, 16, 21, 15, 21, 20, 16, 17,
138 22, 16, 22, 21, 17, 18, 23, 17, 23, 22, 18, 19, 24, 18, 24, 23 };
139
140 using PointType = typename TMesh::PointType;
141 std::vector<PointType> pts = GeneratePointCoordinates<TMesh>(5);
142
143 for (int i = 0; i < expectedNumPts; ++i)
144 {
145 mesh->SetPoint(i, pts[i]);
146 }
147
148 typename CellType::CellAutoPointer cellpointer;
149 QEPolygonCellType * poly;
150
151 for (int i = 0; i < expectedNumCells; ++i)
152 {
153 poly = new QEPolygonCellType(3);
154 cellpointer.TakeOwnership(poly);
155 cellpointer->SetPointId(0, simpleSquareCells[3 * i]);
156 cellpointer->SetPointId(1, simpleSquareCells[3 * i + 1]);
157 cellpointer->SetPointId(2, simpleSquareCells[3 * i + 2]);
158 mesh->SetCell(i, cellpointer);
159 }
160}
161
162//----------------------------------------------------------------------------
163template <typename TMesh>
164void
166{
167 using MeshType = TMesh;
168 using CellType = typename MeshType::CellType;
169
170 using QEPolygonCellType = itk::QuadEdgeMeshPolygonCell<CellType>;
171
172 if (mesh->GetNumberOfPoints())
173 {
174 mesh->Clear();
175 mesh->ClearFreePointAndCellIndexesLists();
176 }
177
179 int expectedNumPts = 4;
180 int expectedNumCells = 4;
181 int simpleSquareCells[12] = { 0, 1, 2, 1, 0, 3, 1, 3, 2, 2, 3, 0 };
182
183 using PointType = typename TMesh::PointType;
184 std::vector<PointType> pts(4);
185 int i(0);
186 pts[i][0] = 0.;
187 pts[i][1] = 1.;
188 pts[i++][2] = 0.;
189 pts[i][0] = 0.;
190 pts[i][1] = -1.;
191 pts[i++][2] = 0.;
192 pts[i][0] = -1.;
193 pts[i][1] = 0.;
194 pts[i++][2] = 0.;
195 pts[i][0] = 0.;
196 pts[i][1] = 0.;
197 pts[i++][2] = 1.;
198
199 for (i = 0; i < expectedNumPts; ++i)
200 {
201 mesh->SetPoint(i, pts[i]);
202 }
203
204 typename CellType::CellAutoPointer cellpointer;
205 QEPolygonCellType * poly;
206
207 for (i = 0; i < expectedNumCells; ++i)
208 {
209 poly = new QEPolygonCellType(3);
210 cellpointer.TakeOwnership(poly);
211 cellpointer->SetPointId(0, simpleSquareCells[3 * i]);
212 cellpointer->SetPointId(1, simpleSquareCells[3 * i + 1]);
213 cellpointer->SetPointId(2, simpleSquareCells[3 * i + 2]);
214 mesh->SetCell(i, cellpointer);
215 }
216}
217
218
219//----------------------------------------------------------------------------
220template <typename TMesh>
221void
223{
224 using MeshType = TMesh;
225 using CellType = typename MeshType::CellType;
226
227 using QEPolygonCellType = itk::QuadEdgeMeshPolygonCell<CellType>;
228
229 if (mesh->GetNumberOfPoints())
230 {
231 mesh->Clear();
232 mesh->ClearFreePointAndCellIndexesLists();
233 }
234
236 int expectedNumPts = 3;
237 int expectedNumCells = 2;
238 int simpleSquareCells[6] = { 0, 1, 2, 1, 0, 2 };
239
240 using PointType = typename TMesh::PointType;
241 std::vector<PointType> pts(3);
242 int i(0);
243 pts[i][0] = 0.;
244 pts[i][1] = 1.;
245 pts[i++][2] = 0.;
246 pts[i][0] = 0.;
247 pts[i][1] = -1.;
248 pts[i++][2] = 0.;
249 pts[i][0] = -1.;
250 pts[i][1] = 0.;
251 pts[i++][2] = 0.;
252
253 for (i = 0; i < expectedNumPts; ++i)
254 {
255 mesh->SetPoint(i, pts[i]);
256 }
257
258 typename CellType::CellAutoPointer cellpointer;
259 QEPolygonCellType * poly;
260
261 for (i = 0; i < expectedNumCells; ++i)
262 {
263 poly = new QEPolygonCellType(3);
264 cellpointer.TakeOwnership(poly);
265 cellpointer->SetPointId(0, simpleSquareCells[3 * i]);
266 cellpointer->SetPointId(1, simpleSquareCells[3 * i + 1]);
267 cellpointer->SetPointId(2, simpleSquareCells[3 * i + 2]);
268 mesh->SetCell(i, cellpointer);
269 }
270}
271
272
273#endif
Make some basic checks in order to verify that the considered mesh is not degenerated and correctly r...
static Pointer New()
SmartPointer< Self > Pointer
void CreateSamosa(typename TMesh::Pointer mesh)
bool AssertTopologicalInvariants(TMesh *mesh, IdentifierType NumVertices, IdentifierType NumFaces, IdentifierType NumEdges, IdentifierType NumBorders, IdentifierType Genus)
void CreateSquareQuadMesh(typename TMesh::Pointer mesh)
std::vector< typename TMesh::PointType > GeneratePointCoordinates(const unsigned int iN)
void CreateTetraedronMesh(typename TMesh::Pointer mesh)
unsigned long IdentifierType
void CreateSquareTriangularMesh(typename TMesh::Pointer mesh)