ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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#include <array>
24
25using IdentifierType = unsigned long;
26
27template <typename TMesh>
28bool
30 IdentifierType NumVertices,
31 IdentifierType NumFaces,
32 IdentifierType NumEdges,
33 IdentifierType NumBorders,
34 IdentifierType Genus)
35{
37 auto check = CheckerType::New();
38 check->SetMesh(mesh);
39 check->SetExpectedNumberOfPoints(NumVertices);
40 check->SetExpectedNumberOfEdges(NumFaces);
41 check->SetExpectedNumberOfFaces(NumEdges);
42 check->SetExpectedNumberOfBoundaries(NumBorders);
43 check->SetExpectedGenus(Genus);
44 return check->ValidateEulerCharacteristic();
45}
46
47//----------------------------------------------------------------------------
48template <typename TMesh>
49std::vector<typename TMesh::PointType>
50GeneratePointCoordinates(const unsigned int iN)
51{
52 using PointType = typename TMesh::PointType;
53 using CoordinateType = typename PointType::CoordinateType;
54 std::vector<PointType> oPt(iN * iN);
55
56 for (unsigned int i = 0; i < iN; ++i)
57 {
58 for (unsigned int j = 0; j < iN; ++j)
59 {
60 oPt[i * iN + j][0] = static_cast<CoordinateType>(j);
61 oPt[i * iN + j][1] = static_cast<CoordinateType>(i);
62 oPt[i * iN + j][2] = static_cast<CoordinateType>(0.);
63 }
64 }
65
66 return oPt;
67}
68
69//----------------------------------------------------------------------------
70template <typename TMesh>
71void
72CreateSquareQuadMesh(typename TMesh::Pointer mesh)
73{
74 using MeshType = TMesh;
75 using CellType = typename MeshType::CellType;
76
77 using QEPolygonCellType = itk::QuadEdgeMeshPolygonCell<CellType>;
78
79 if (mesh->GetNumberOfPoints())
80 {
81 mesh->Clear();
82 mesh->ClearFreePointAndCellIndexesLists();
83 }
84
86 constexpr int expectedNumPts = 25;
87 constexpr int expectedNumCells = 16;
88 const int simpleSquareCells[64] = { 0, 1, 6, 5, 1, 2, 7, 6, 2, 3, 8, 7, 3, 4, 9, 8,
89 5, 6, 11, 10, 6, 7, 12, 11, 7, 8, 13, 12, 8, 9, 14, 13,
90 10, 11, 16, 15, 11, 12, 17, 16, 12, 13, 18, 17, 13, 14, 19, 18,
91 15, 16, 21, 20, 16, 17, 22, 21, 17, 18, 23, 22, 18, 19, 24, 23 };
92
93 using PointType = typename MeshType::PointType;
94
95 std::vector<PointType> pts = GeneratePointCoordinates<MeshType>(5);
96
97 for (int i = 0; i < expectedNumPts; ++i)
98 {
99 mesh->SetPoint(i, pts[i]);
100 }
101
102 typename CellType::CellAutoPointer cellpointer;
103 for (int i = 0; i < expectedNumCells; ++i)
104 {
105 auto * 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
118CreateSquareTriangularMesh(typename TMesh::Pointer mesh)
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 constexpr int expectedNumPts = 25;
133 constexpr int expectedNumCells = 32;
134 const 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 for (int i = 0; i < expectedNumCells; ++i)
150 {
151 auto * poly = new QEPolygonCellType(3);
152 cellpointer.TakeOwnership(poly);
153 cellpointer->SetPointId(0, simpleSquareCells[3 * i]);
154 cellpointer->SetPointId(1, simpleSquareCells[3 * i + 1]);
155 cellpointer->SetPointId(2, simpleSquareCells[3 * i + 2]);
156 mesh->SetCell(i, cellpointer);
157 }
158}
159
160//----------------------------------------------------------------------------
161template <typename TMesh>
162void
163CreateTetraedronMesh(typename TMesh::Pointer mesh)
164{
165 using MeshType = TMesh;
166 using CellType = typename MeshType::CellType;
167
168 using QEPolygonCellType = itk::QuadEdgeMeshPolygonCell<CellType>;
169
170 if (mesh->GetNumberOfPoints())
171 {
172 mesh->Clear();
173 mesh->ClearFreePointAndCellIndexesLists();
174 }
175
177 constexpr int expectedNumPts = 4;
178 constexpr int expectedNumCells = 4;
179 const int simpleSquareCells[12] = { 0, 1, 2, 1, 0, 3, 1, 3, 2, 2, 3, 0 };
180
181 using PointType = typename TMesh::PointType;
182 std::array<PointType, 4> pts{};
183 {
184 int i(0);
185 pts[i][0] = 0.;
186 pts[i][1] = 1.;
187 pts[i++][2] = 0.;
188 pts[i][0] = 0.;
189 pts[i][1] = -1.;
190 pts[i++][2] = 0.;
191 pts[i][0] = -1.;
192 pts[i][1] = 0.;
193 pts[i++][2] = 0.;
194 pts[i][0] = 0.;
195 pts[i][1] = 0.;
196 pts[i++][2] = 1.;
197 }
198 for (int i = 0; i < expectedNumPts; ++i)
199 {
200 mesh->SetPoint(i, pts[i]);
201 }
202
203 typename CellType::CellAutoPointer cellpointer;
204
205 for (int i = 0; i < expectedNumCells; ++i)
206 {
207 auto * poly = new QEPolygonCellType(3);
208 cellpointer.TakeOwnership(poly);
209 cellpointer->SetPointId(0, simpleSquareCells[3 * i]);
210 cellpointer->SetPointId(1, simpleSquareCells[3 * i + 1]);
211 cellpointer->SetPointId(2, simpleSquareCells[3 * i + 2]);
212 mesh->SetCell(i, cellpointer);
213 }
214}
215
216
217//----------------------------------------------------------------------------
218template <typename TMesh>
219void
220CreateSamosa(typename TMesh::Pointer mesh)
221{
222 using MeshType = TMesh;
223 using CellType = typename MeshType::CellType;
224
225 using QEPolygonCellType = itk::QuadEdgeMeshPolygonCell<CellType>;
226
227 if (mesh->GetNumberOfPoints())
228 {
229 mesh->Clear();
230 mesh->ClearFreePointAndCellIndexesLists();
231 }
232
234 constexpr int expectedNumPts = 3;
235 constexpr int expectedNumCells = 2;
236 const int simpleSquareCells[6] = { 0, 1, 2, 1, 0, 2 };
237
238 using PointType = typename TMesh::PointType;
239 std::array<PointType, 3> pts{};
240 {
241 int i(0);
242 pts[i][0] = 0.;
243 pts[i][1] = 1.;
244 pts[i++][2] = 0.;
245 pts[i][0] = 0.;
246 pts[i][1] = -1.;
247 pts[i++][2] = 0.;
248 pts[i][0] = -1.;
249 pts[i][1] = 0.;
250 pts[i++][2] = 0.;
251 }
252 for (int i = 0; i < expectedNumPts; ++i)
253 {
254 mesh->SetPoint(i, pts[i]);
255 }
256
257 typename CellType::CellAutoPointer cellpointer;
258 for (int i = 0; i < expectedNumCells; ++i)
259 {
260 auto * poly = new QEPolygonCellType(3);
261 cellpointer.TakeOwnership(poly);
262 cellpointer->SetPointId(0, simpleSquareCells[3 * i]);
263 cellpointer->SetPointId(1, simpleSquareCells[3 * i + 1]);
264 cellpointer->SetPointId(2, simpleSquareCells[3 * i + 2]);
265 mesh->SetCell(i, cellpointer);
266 }
267}
268
269
270#endif
Make some basic checks in order to verify that the considered mesh is not degenerated and correctly r...
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)