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
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 CoordinateType = typename PointType::CoordinateType;
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<CoordinateType>(j);
60 oPt[i * iN + j][1] = static_cast<CoordinateType>(i);
61 oPt[i * iN + j][2] = static_cast<CoordinateType>(0.);
62 }
63 }
64
65 return oPt;
66}
67
68//----------------------------------------------------------------------------
69template <typename TMesh>
70void
71CreateSquareQuadMesh(typename TMesh::Pointer mesh)
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 constexpr int expectedNumPts = 25;
86 constexpr int expectedNumCells = 16;
87 const int simpleSquareCells[64] = { 0, 1, 6, 5, 1, 2, 7, 6, 2, 3, 8, 7, 3, 4, 9, 8,
88 5, 6, 11, 10, 6, 7, 12, 11, 7, 8, 13, 12, 8, 9, 14, 13,
89 10, 11, 16, 15, 11, 12, 17, 16, 12, 13, 18, 17, 13, 14, 19, 18,
90 15, 16, 21, 20, 16, 17, 22, 21, 17, 18, 23, 22, 18, 19, 24, 23 };
91
92 using PointType = typename MeshType::PointType;
93
94 std::vector<PointType> pts = GeneratePointCoordinates<MeshType>(5);
95
96 for (int i = 0; i < expectedNumPts; ++i)
97 {
98 mesh->SetPoint(i, pts[i]);
99 }
100
101 typename CellType::CellAutoPointer cellpointer;
102 for (int i = 0; i < expectedNumCells; ++i)
103 {
104 QEPolygonCellType * poly = new QEPolygonCellType(4);
105 cellpointer.TakeOwnership(poly);
106 cellpointer->SetPointId(0, simpleSquareCells[4 * i]);
107 cellpointer->SetPointId(1, simpleSquareCells[4 * i + 1]);
108 cellpointer->SetPointId(2, simpleSquareCells[4 * i + 2]);
109 cellpointer->SetPointId(3, simpleSquareCells[4 * i + 3]);
110 mesh->SetCell(i, cellpointer);
111 }
112}
113
114//----------------------------------------------------------------------------
115template <typename TMesh>
116void
117CreateSquareTriangularMesh(typename TMesh::Pointer mesh)
118{
119 using MeshType = TMesh;
120 using CellType = typename MeshType::CellType;
121
122 using QEPolygonCellType = itk::QuadEdgeMeshPolygonCell<CellType>;
123
124 if (mesh->GetNumberOfPoints())
125 {
126 mesh->Clear();
127 mesh->ClearFreePointAndCellIndexesLists();
128 }
129
131 constexpr int expectedNumPts = 25;
132 constexpr int expectedNumCells = 32;
133 const int simpleSquareCells[96] = { 0, 1, 6, 0, 6, 5, 1, 2, 7, 1, 7, 6, 2, 3, 8, 2, 8, 7, 3, 4,
134 9, 3, 9, 8, 5, 6, 11, 5, 11, 10, 6, 7, 12, 6, 12, 11, 7, 8, 13, 7,
135 13, 12, 8, 9, 14, 8, 14, 13, 10, 11, 16, 10, 16, 15, 11, 12, 17, 11, 17, 16,
136 12, 13, 18, 12, 18, 17, 13, 14, 19, 13, 19, 18, 15, 16, 21, 15, 21, 20, 16, 17,
137 22, 16, 22, 21, 17, 18, 23, 17, 23, 22, 18, 19, 24, 18, 24, 23 };
138
139 using PointType = typename TMesh::PointType;
140 std::vector<PointType> pts = GeneratePointCoordinates<TMesh>(5);
141
142 for (int i = 0; i < expectedNumPts; ++i)
143 {
144 mesh->SetPoint(i, pts[i]);
145 }
146
147 typename CellType::CellAutoPointer cellpointer;
148 for (int i = 0; i < expectedNumCells; ++i)
149 {
150 QEPolygonCellType * poly = new QEPolygonCellType(3);
151 cellpointer.TakeOwnership(poly);
152 cellpointer->SetPointId(0, simpleSquareCells[3 * i]);
153 cellpointer->SetPointId(1, simpleSquareCells[3 * i + 1]);
154 cellpointer->SetPointId(2, simpleSquareCells[3 * i + 2]);
155 mesh->SetCell(i, cellpointer);
156 }
157}
158
159//----------------------------------------------------------------------------
160template <typename TMesh>
161void
162CreateTetraedronMesh(typename TMesh::Pointer mesh)
163{
164 using MeshType = TMesh;
165 using CellType = typename MeshType::CellType;
166
167 using QEPolygonCellType = itk::QuadEdgeMeshPolygonCell<CellType>;
168
169 if (mesh->GetNumberOfPoints())
170 {
171 mesh->Clear();
172 mesh->ClearFreePointAndCellIndexesLists();
173 }
174
176 constexpr int expectedNumPts = 4;
177 constexpr int expectedNumCells = 4;
178 const int simpleSquareCells[12] = { 0, 1, 2, 1, 0, 3, 1, 3, 2, 2, 3, 0 };
179
180 using PointType = typename TMesh::PointType;
181 std::vector<PointType> pts(4);
182 {
183 int i(0);
184 pts[i][0] = 0.;
185 pts[i][1] = 1.;
186 pts[i++][2] = 0.;
187 pts[i][0] = 0.;
188 pts[i][1] = -1.;
189 pts[i++][2] = 0.;
190 pts[i][0] = -1.;
191 pts[i][1] = 0.;
192 pts[i++][2] = 0.;
193 pts[i][0] = 0.;
194 pts[i][1] = 0.;
195 pts[i++][2] = 1.;
196 }
197 for (int i = 0; i < expectedNumPts; ++i)
198 {
199 mesh->SetPoint(i, pts[i]);
200 }
201
202 typename CellType::CellAutoPointer cellpointer;
203
204 for (int i = 0; i < expectedNumCells; ++i)
205 {
206 QEPolygonCellType * poly = new QEPolygonCellType(3);
207 cellpointer.TakeOwnership(poly);
208 cellpointer->SetPointId(0, simpleSquareCells[3 * i]);
209 cellpointer->SetPointId(1, simpleSquareCells[3 * i + 1]);
210 cellpointer->SetPointId(2, simpleSquareCells[3 * i + 2]);
211 mesh->SetCell(i, cellpointer);
212 }
213}
214
215
216//----------------------------------------------------------------------------
217template <typename TMesh>
218void
219CreateSamosa(typename TMesh::Pointer mesh)
220{
221 using MeshType = TMesh;
222 using CellType = typename MeshType::CellType;
223
224 using QEPolygonCellType = itk::QuadEdgeMeshPolygonCell<CellType>;
225
226 if (mesh->GetNumberOfPoints())
227 {
228 mesh->Clear();
229 mesh->ClearFreePointAndCellIndexesLists();
230 }
231
233 constexpr int expectedNumPts = 3;
234 constexpr int expectedNumCells = 2;
235 const int simpleSquareCells[6] = { 0, 1, 2, 1, 0, 2 };
236
237 using PointType = typename TMesh::PointType;
238 std::vector<PointType> pts(3);
239 {
240 int i(0);
241 pts[i][0] = 0.;
242 pts[i][1] = 1.;
243 pts[i++][2] = 0.;
244 pts[i][0] = 0.;
245 pts[i][1] = -1.;
246 pts[i++][2] = 0.;
247 pts[i][0] = -1.;
248 pts[i][1] = 0.;
249 pts[i++][2] = 0.;
250 }
251 for (int i = 0; i < expectedNumPts; ++i)
252 {
253 mesh->SetPoint(i, pts[i]);
254 }
255
256 typename CellType::CellAutoPointer cellpointer;
257 for (int i = 0; i < expectedNumCells; ++i)
258 {
259 QEPolygonCellType * poly = new QEPolygonCellType(3);
260 cellpointer.TakeOwnership(poly);
261 cellpointer->SetPointId(0, simpleSquareCells[3 * i]);
262 cellpointer->SetPointId(1, simpleSquareCells[3 * i + 1]);
263 cellpointer->SetPointId(2, simpleSquareCells[3 * i + 2]);
264 mesh->SetCell(i, cellpointer);
265 }
266}
267
268
269#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)