ITK  6.0.0
Insight Toolkit
itkAutomaticTopologyMeshSource.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 itkAutomaticTopologyMeshSource_h
19#define itkAutomaticTopologyMeshSource_h
20
21#include "itkArray.h"
23#include <unordered_map>
24#include "itkHexahedronCell.h"
25#include "itkIntTypes.h"
26#include "itkMesh.h"
27#include "itkMeshSource.h"
29#include "itkTetrahedronCell.h"
30#include "itkVertexCell.h"
31
32namespace itk
33{
110template <typename TOutputMesh>
111class ITK_TEMPLATE_EXPORT AutomaticTopologyMeshSource : public MeshSource<TOutputMesh>
112{
113public:
114 ITK_DISALLOW_COPY_AND_MOVE(AutomaticTopologyMeshSource);
115
121
123 using MeshType = TOutputMesh;
124 using PointHashType = typename MeshType::PointHashType;
126 using CellType = typename MeshType::CellType;
128 using CoordinateType = typename PointType::CoordRepType;
129 using CellAutoPointer = typename CellType::CellAutoPointer;
130
138
142
145
148 using PointHashMap = std::unordered_map<PointType, IdentifierType, StructHashFunction<PointHashType>>;
149
151 static constexpr unsigned int PointDimension = MeshType::PointDimension;
152 static constexpr unsigned int MaxTopologicalDimension = MeshType::MaxTopologicalDimension;
153
155 itkNewMacro(Self);
156
158 itkOverrideGetNameOfClassMacro(AutomaticTopologyMeshSource);
159
162 AddPoint(const PointType & p0);
163
166
174 CoordinateType x1 = 0,
175 CoordinateType x2 = 0,
176 CoordinateType x3 = 0,
177 CoordinateType x4 = 0,
178 CoordinateType x5 = 0);
179
183
186
188 AddVertex(const PointType & p0);
189
192
198 AddLine(const IdentifierArrayType & pointIDs);
199
202
204 AddLine(const PointType & p0, const PointType & p1);
205
207 AddLine(const CoordinateType * p0, const CoordinateType * p1);
208
221
224
226 AddTriangle(const PointType & p0, const PointType & p1, const PointType & p2);
227
229 AddTriangle(const CoordinateType * p0, const CoordinateType * p1, const CoordinateType * p2);
230
253
256
258 AddQuadrilateral(const PointType & p0, const PointType & p1, const PointType & p2, const PointType & p3);
259
262 const CoordinateType * p1,
263 const CoordinateType * p2,
264 const CoordinateType * p3);
265
280
283
285 AddTetrahedron(const PointType & p0, const PointType & p1, const PointType & p2, const PointType & p3);
286
289 const CoordinateType * p1,
290 const CoordinateType * p2,
291 const CoordinateType * p3);
292
323
326 IdentifierType pointId1,
327 IdentifierType pointId2,
328 IdentifierType pointId3,
329 IdentifierType pointId4,
330 IdentifierType pointId5,
331 IdentifierType pointId6,
332 IdentifierType pointId7);
333
336 const PointType & p1,
337 const PointType & p2,
338 const PointType & p3,
339 const PointType & p4,
340 const PointType & p5,
341 const PointType & p6,
342 const PointType & p7);
343
346 const CoordinateType * p1,
347 const CoordinateType * p2,
348 const CoordinateType * p3,
349 const CoordinateType * p4,
350 const CoordinateType * p5,
351 const CoordinateType * p6,
352 const CoordinateType * p7);
353
355 {
356 public:
358 operator()(Array<IdentifierType> identifierArray) const
359 {
360 using IdType = IdentifierType;
361
362 IdType size = identifierArray.Size();
363
364 std::sort(identifierArray.begin(), identifierArray.end());
365
366 IdType hash = 0;
367 IdType * id = &identifierArray[0];
368
369 while (size--)
370 {
371 hash += *id++;
372 hash = (hash << 7) | (hash >> 25); // Rotate left by 7.
373 }
374
375 return hash;
376 }
377 };
378
380 {
381 public:
382 bool
383 operator()(Array<IdentifierType> identifierArray1, Array<IdentifierType> identifierArray2) const
384 {
385 using IdType = IdentifierType;
386
387 IdType size1 = identifierArray1.Size();
388 IdType size2 = identifierArray2.Size();
389
390 if (size1 != size2)
391 {
392 return false;
393 }
394
395 std::sort(identifierArray1.begin(), identifierArray1.end());
396 std::sort(identifierArray2.begin(), identifierArray2.end());
397
398 return (identifierArray1 == identifierArray2);
399 }
400 };
401
402protected:
404 ~AutomaticTopologyMeshSource() override = default;
405
406 void
407 GenerateData() override
408 {} // GenerateData is a no-op, since the entries override
409 // are controlled manually
410
411private:
412 using CellHashMap = std::
413 unordered_map<Array<IdentifierType>, IdentifierType, IdentifierArrayHashFunction, IdentifierArrayEqualsFunction>;
414
415 PointHashMap m_PointsHashTable{};
416 CellHashMap m_CellsHashTable{};
417 MeshPointer m_OutputMesh{}; // Retained for convenience.
418};
419} // end namespace itk
420
421#ifndef ITK_MANUAL_INSTANTIATION
422# include "itkAutomaticTopologyMeshSource.hxx"
423#endif
424
425#endif // itkAutomaticTopologyMeshSource_h
SizeValueType Size() const
Definition: itkArray.h:128
bool operator()(Array< IdentifierType > identifierArray1, Array< IdentifierType > identifierArray2) const
IdentifierType operator()(Array< IdentifierType > identifierArray) const
Convenience class for generating meshes.
typename MeshType::PointHashType PointHashType
IdentifierType AddVertex(const CoordinateType *p0)
IdentifierType AddVertex(IdentifierType pointId0)
typename PointType::CoordRepType CoordinateType
IdentifierType AddTriangle(const PointType &p0, const PointType &p1, const PointType &p2)
IdentifierType AddPoint(const PointType &p0)
IdentifierType AddTriangle(IdentifierType pointId0, IdentifierType pointId1, IdentifierType pointId2)
IdentifierType AddVertex(const IdentifierArrayType &pointIDs)
IdentifierType AddTriangle(const CoordinateType *p0, const CoordinateType *p1, const CoordinateType *p2)
IdentifierType AddHexahedron(IdentifierType pointId0, IdentifierType pointId1, IdentifierType pointId2, IdentifierType pointId3, IdentifierType pointId4, IdentifierType pointId5, IdentifierType pointId6, IdentifierType pointId7)
IdentifierType AddHexahedron(const IdentifierArrayType &pointIDs)
IdentifierType AddLine(const IdentifierArrayType &pointIDs)
~AutomaticTopologyMeshSource() override=default
IdentifierType AddLine(const PointType &p0, const PointType &p1)
IdentifierType AddHexahedron(const CoordinateType *p0, const CoordinateType *p1, const CoordinateType *p2, const CoordinateType *p3, const CoordinateType *p4, const CoordinateType *p5, const CoordinateType *p6, const CoordinateType *p7)
IdentifierType AddQuadrilateral(const PointType &p0, const PointType &p1, const PointType &p2, const PointType &p3)
IdentifierType AddPoint(CoordinateType x0=0, CoordinateType x1=0, CoordinateType x2=0, CoordinateType x3=0, CoordinateType x4=0, CoordinateType x5=0)
IdentifierType AddVertex(const PointType &p0)
IdentifierType AddTetrahedron(const PointType &p0, const PointType &p1, const PointType &p2, const PointType &p3)
IdentifierType AddQuadrilateral(IdentifierType pointId0, IdentifierType pointId1, IdentifierType pointId2, IdentifierType pointId3)
IdentifierType AddLine(IdentifierType pointId0, IdentifierType pointId1)
IdentifierType AddHexahedron(const PointType &p0, const PointType &p1, const PointType &p2, const PointType &p3, const PointType &p4, const PointType &p5, const PointType &p6, const PointType &p7)
IdentifierType AddLine(const CoordinateType *p0, const CoordinateType *p1)
IdentifierType AddTetrahedron(IdentifierType pointId0, IdentifierType pointId1, IdentifierType pointId2, IdentifierType pointId3)
IdentifierType AddTetrahedron(const IdentifierArrayType &pointIDs)
std::unordered_map< Array< IdentifierType >, IdentifierType, IdentifierArrayHashFunction, IdentifierArrayEqualsFunction > CellHashMap
std::unordered_map< PointType, IdentifierType, StructHashFunction< PointHashType > > PointHashMap
IdentifierType AddTetrahedron(const CoordinateType *p0, const CoordinateType *p1, const CoordinateType *p2, const CoordinateType *p3)
typename CellType::CellAutoPointer CellAutoPointer
IdentifierType AddQuadrilateral(const CoordinateType *p0, const CoordinateType *p1, const CoordinateType *p2, const CoordinateType *p3)
IdentifierType AddPoint(const CoordinateType *p0)
IdentifierType AddTriangle(const IdentifierArrayType &pointIDs)
IdentifierType AddQuadrilateral(const IdentifierArrayType &pointIDs)
Represents a hexahedron (cuboid) for a Mesh.
Light weight base class for most itk classes.
Represents a line segment for a Mesh.
Definition: itkLineCell.h:41
Base class for all process objects that output mesh data.
Definition: itkMeshSource.h:50
Represents a quadrilateral for a Mesh.
TetrahedronCell represents a tetrahedron for a Mesh.
Represents a single vertex for a Mesh.
Definition: itkVertexCell.h:38
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
SizeValueType IdentifierType
Definition: itkIntTypes.h:90