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"
28 #include "itkStructHashFunction.h"
29 #include "itkTetrahedronCell.h"
30 #include "itkVertexCell.h"
31 
32 namespace itk
33 {
110 template <typename TOutputMesh>
111 class ITK_TEMPLATE_EXPORT AutomaticTopologyMeshSource : public MeshSource<TOutputMesh>
112 {
113 public:
114  ITK_DISALLOW_COPY_AND_MOVE(AutomaticTopologyMeshSource);
115 
121 
123  using MeshType = TOutputMesh;
124  using PointHashType = typename MeshType::PointHashType;
125  using PointType = typename MeshType::PointType;
126  using CellType = typename MeshType::CellType;
127  using MeshPointer = typename MeshType::Pointer;
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 
165  AddPoint(const CoordinateType * p0);
166 
173  AddPoint(CoordinateType x0 = 0,
174  CoordinateType x1 = 0,
175  CoordinateType x2 = 0,
176  CoordinateType x3 = 0,
177  CoordinateType x4 = 0,
178  CoordinateType x5 = 0);
179 
182  AddVertex(const IdentifierArrayType & pointIDs);
183 
185  AddVertex(IdentifierType pointId0);
186 
188  AddVertex(const PointType & p0);
189 
191  AddVertex(const CoordinateType * p0);
192 
198  AddLine(const IdentifierArrayType & pointIDs);
199 
201  AddLine(IdentifierType pointId0, IdentifierType pointId1);
202 
204  AddLine(const PointType & p0, const PointType & p1);
205 
207  AddLine(const CoordinateType * p0, const CoordinateType * p1);
208 
220  AddTriangle(const IdentifierArrayType & pointIDs);
221 
223  AddTriangle(IdentifierType pointId0, IdentifierType pointId1, IdentifierType pointId2);
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 
252  AddQuadrilateral(const IdentifierArrayType & pointIDs);
253 
255  AddQuadrilateral(IdentifierType pointId0, IdentifierType pointId1, IdentifierType pointId2, IdentifierType pointId3);
256 
258  AddQuadrilateral(const PointType & p0, const PointType & p1, const PointType & p2, const PointType & p3);
259 
261  AddQuadrilateral(const CoordinateType * p0,
262  const CoordinateType * p1,
263  const CoordinateType * p2,
264  const CoordinateType * p3);
265 
279  AddTetrahedron(const IdentifierArrayType & pointIDs);
280 
282  AddTetrahedron(IdentifierType pointId0, IdentifierType pointId1, IdentifierType pointId2, IdentifierType pointId3);
283 
285  AddTetrahedron(const PointType & p0, const PointType & p1, const PointType & p2, const PointType & p3);
286 
288  AddTetrahedron(const CoordinateType * p0,
289  const CoordinateType * p1,
290  const CoordinateType * p2,
291  const CoordinateType * p3);
292 
322  AddHexahedron(const IdentifierArrayType & pointIDs);
323 
325  AddHexahedron(IdentifierType pointId0,
326  IdentifierType pointId1,
327  IdentifierType pointId2,
328  IdentifierType pointId3,
329  IdentifierType pointId4,
330  IdentifierType pointId5,
331  IdentifierType pointId6,
332  IdentifierType pointId7);
333 
335  AddHexahedron(const PointType & p0,
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 
345  AddHexahedron(const CoordinateType * p0,
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 
402 protected:
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 
411 private:
412  using CellHashMap = std::
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
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itkHexahedronCell.h
itk::VertexCell
Represents a single vertex for a Mesh.
Definition: itkVertexCell.h:37
itk::QuadrilateralCell
Represents a quadrilateral for a Mesh.
Definition: itkQuadrilateralCell.h:37
itk::AutomaticTopologyMeshSource::IdentifierType
itk::IdentifierType IdentifierType
Definition: itkAutomaticTopologyMeshSource.h:141
itk::AutomaticTopologyMeshSource::MeshPointer
typename MeshType::Pointer MeshPointer
Definition: itkAutomaticTopologyMeshSource.h:127
itk::AutomaticTopologyMeshSource::IdentifierArrayHashFunction
Definition: itkAutomaticTopologyMeshSource.h:354
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::SmartPointer< Self >
itk::AutomaticTopologyMeshSource
Convenience class for generating meshes.
Definition: itkAutomaticTopologyMeshSource.h:111
itk::AutomaticTopologyMeshSource::CellAutoPointer
typename CellType::CellAutoPointer CellAutoPointer
Definition: itkAutomaticTopologyMeshSource.h:129
itk::AutomaticTopologyMeshSource::CellHashMap
std::unordered_map< Array< IdentifierType >, IdentifierType, IdentifierArrayHashFunction, IdentifierArrayEqualsFunction > CellHashMap
Definition: itkAutomaticTopologyMeshSource.h:413
itk::AutomaticTopologyMeshSource::IdentifierArrayEqualsFunction
Definition: itkAutomaticTopologyMeshSource.h:379
itk::TetrahedronCell
TetrahedronCell represents a tetrahedron for a Mesh.
Definition: itkTetrahedronCell.h:36
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::MeshSource
Base class for all process objects that output mesh data.
Definition: itkMeshSource.h:49
itk::AutomaticTopologyMeshSource::IdentifierArrayHashFunction::operator()
IdentifierType operator()(Array< IdentifierType > identifierArray) const
Definition: itkAutomaticTopologyMeshSource.h:358
itkMeshSource.h
itkMesh.h
itk::AutomaticTopologyMeshSource::MeshType
TOutputMesh MeshType
Definition: itkAutomaticTopologyMeshSource.h:123
itk::HexahedronCell
Represents a hexahedron (cuboid) for a Mesh.
Definition: itkHexahedronCell.h:45
itk::TriangleCell
Definition: itkTriangleCell.h:46
itk::AutomaticTopologyMeshSource::PointType
typename MeshType::PointType PointType
Definition: itkAutomaticTopologyMeshSource.h:125
itkIntTypes.h
itk::LineCell
Represents a line segment for a Mesh.
Definition: itkLineCell.h:40
itkArray.h
itkVertexCell.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::AutomaticTopologyMeshSource::CoordinateType
typename PointType::CoordRepType CoordinateType
Definition: itkAutomaticTopologyMeshSource.h:128
itkDefaultStaticMeshTraits.h
itkStructHashFunction.h
itk::Array< IdentifierType >
itk::AutomaticTopologyMeshSource::IdentifierArrayEqualsFunction::operator()
bool operator()(Array< IdentifierType > identifierArray1, Array< IdentifierType > identifierArray2) const
Definition: itkAutomaticTopologyMeshSource.h:383
itk::Array::Size
SizeValueType Size() const
Definition: itkArray.h:128
itk::AutomaticTopologyMeshSource::PointHashMap
std::unordered_map< PointType, IdentifierType, StructHashFunction< PointHashType > > PointHashMap
Definition: itkAutomaticTopologyMeshSource.h:148
itk::AutomaticTopologyMeshSource::PointHashType
typename MeshType::PointHashType PointHashType
Definition: itkAutomaticTopologyMeshSource.h:124
itk::AutomaticTopologyMeshSource::GenerateData
void GenerateData() override
Definition: itkAutomaticTopologyMeshSource.h:407
itk::IdentifierType
SizeValueType IdentifierType
Definition: itkIntTypes.h:90
itk::AutomaticTopologyMeshSource::CellType
typename MeshType::CellType CellType
Definition: itkAutomaticTopologyMeshSource.h:126
itkTetrahedronCell.h