ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkAutomaticTopologyMeshSource.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  * http://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 "itksys/hash_map.hxx"
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_ASSIGN(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 = itksys::hash_map<
149  PointType,
152 
154  static constexpr unsigned int PointDimension = MeshType::PointDimension;
155  static constexpr unsigned int MaxTopologicalDimension = MeshType::MaxTopologicalDimension;
156 
158  itkNewMacro(Self);
159 
162 
164  IdentifierType AddPoint(const PointType & p0);
165 
166  IdentifierType AddPoint(const CoordinateType *p0);
167 
173  IdentifierType AddPoint(CoordinateType x0 = 0, CoordinateType x1 = 0,
174  CoordinateType x2 = 0, CoordinateType x3 = 0,
175  CoordinateType x4 = 0, CoordinateType x5 = 0);
176 
178  IdentifierType AddVertex(const IdentifierArrayType & pointIds);
179 
180  IdentifierType AddVertex(IdentifierType pointId0);
181 
182  IdentifierType AddVertex(const PointType & p0);
183 
184  IdentifierType AddVertex(const CoordinateType *p0);
185 
190  IdentifierType AddLine(const IdentifierArrayType & pointIds);
191 
192  IdentifierType AddLine(
193  IdentifierType pointId0, IdentifierType pointId1);
194 
195  IdentifierType AddLine(const PointType & p0, const PointType & p1);
196 
197  IdentifierType AddLine(const CoordinateType *p0,
198  const CoordinateType *p1);
199 
210  IdentifierType AddTriangle(const IdentifierArrayType & pointIds);
211 
212  IdentifierType AddTriangle(
213  IdentifierType pointId0, IdentifierType pointId1,
214  IdentifierType pointId2);
215 
216  IdentifierType AddTriangle(const PointType & p0, const PointType & p1,
217  const PointType & p2);
218 
219  IdentifierType AddTriangle(const CoordinateType *p0,
220  const CoordinateType *p1,
221  const CoordinateType *p2);
222 
243  IdentifierType AddQuadrilateral(const IdentifierArrayType & pointIds);
244 
245  IdentifierType AddQuadrilateral(
246  IdentifierType pointId0, IdentifierType pointId1,
247  IdentifierType pointId2, IdentifierType pointId3);
248 
249  IdentifierType AddQuadrilateral(const PointType & p0, const PointType & p1,
250  const PointType & p2, const PointType & p3);
251 
252  IdentifierType AddQuadrilateral(const CoordinateType *p0,
253  const CoordinateType *p1,
254  const CoordinateType *p2,
255  const CoordinateType *p3);
256 
269  IdentifierType AddTetrahedron(const IdentifierArrayType & pointIds);
270 
271  IdentifierType AddTetrahedron(
272  IdentifierType pointId0, IdentifierType pointId1,
273  IdentifierType pointId2, IdentifierType pointId3);
274 
275  IdentifierType AddTetrahedron(const PointType & p0, const PointType & p1,
276  const PointType & p2, const PointType & p3);
277 
278  IdentifierType AddTetrahedron(const CoordinateType *p0,
279  const CoordinateType *p1,
280  const CoordinateType *p2,
281  const CoordinateType *p3);
282 
311  IdentifierType AddHexahedron(const IdentifierArrayType & pointIds);
312 
313  IdentifierType AddHexahedron(
314  IdentifierType pointId0, IdentifierType pointId1,
315  IdentifierType pointId2, IdentifierType pointId3,
316  IdentifierType pointId4, IdentifierType pointId5,
317  IdentifierType pointId6, IdentifierType pointId7);
318 
319  IdentifierType AddHexahedron(
320  const PointType & p0, const PointType & p1, const PointType & p2,
321  const PointType & p3, const PointType & p4, const PointType & p5,
322  const PointType & p6, const PointType & p7
323  );
324 
325  IdentifierType AddHexahedron(const CoordinateType *p0,
326  const CoordinateType *p1,
327  const CoordinateType *p2,
328  const CoordinateType *p3,
329  const CoordinateType *p4,
330  const CoordinateType *p5,
331  const CoordinateType *p6,
332  const CoordinateType *p7);
333 
335  {
336 public:
338  {
339  using IdType = IdentifierType;
340 
341  IdType size = identifierArray.Size();
342 
343  std::sort( identifierArray.begin(), identifierArray.end() );
344 
345  IdType hash = 0;
346  IdType *id = &identifierArray[0];
347 
348  while ( size-- )
349  {
350  hash += *id++;
351  hash = ( hash << 7 ) | ( hash >> 25 ); // Rotate left by 7.
352  }
353 
354  return hash;
355  }
356  };
357 
359  {
360 public:
362  Array< IdentifierType > identifierArray1,
363  Array< IdentifierType > identifierArray2
364  ) const
365  {
366  using IdType = IdentifierType;
367 
368  IdType size1 = identifierArray1.Size();
369  IdType size2 = identifierArray2.Size();
370 
371  if ( size1 != size2 )
372  {
373  return false;
374  }
375 
376  std::sort( identifierArray1.begin(), identifierArray1.end() );
377  std::sort( identifierArray2.begin(), identifierArray2.end() );
378 
379  return ( identifierArray1 == identifierArray2 );
380  }
381  };
382 
383 protected:
385  ~AutomaticTopologyMeshSource() override = default;
386 
387  void GenerateData() override {} // GenerateData is a no-op, since the entries override
388  // are controlled manually
389 
390 private:
391  using CellHashMap = itksys::hash_map<
394  IdentifierArrayHashFunction,
396 
399  MeshPointer m_OutputMesh; // Retained for convenience.
400 };
401 } // end namespace itk
402 
403 #ifndef ITK_MANUAL_INSTANTIATION
404 #include "itkAutomaticTopologyMeshSource.hxx"
405 #endif
406 
407 #endif // itkAutomaticTopologyMeshSource_h
Represents a line segment for a Mesh.
Definition: itkLineCell.h:42
Light weight base class for most itk classes.
itksys::hash_map< PointType, IdentifierType, StructHashFunction< PointHashType > > PointHashMap
Convenience class for generating meshes.
itksys::hash_map< Array< IdentifierType >, IdentifierType, IdentifierArrayHashFunction, IdentifierArrayEqualsFunction > CellHashMap
Base class for all process objects that output mesh data.
Definition: itkMeshSource.h:49
unsigned long IdentifierType
IdentifierType operator()(Array< IdentifierType > identifierArray) const
typename MeshType::PointHashType PointHashType
SizeValueType IdentifierType
Definition: itkIntTypes.h:87
SizeValueType Size() const
Definition: itkArray.h:120
Represents a hexahedron (cuboid) for a Mesh.
typename PointType::CoordRepType CoordinateType
TetrahedronCell represents a tetrahedron for a Mesh.
bool operator()(Array< IdentifierType > identifierArray1, Array< IdentifierType > identifierArray2) const
Represents a single vertex for a Mesh.
Definition: itkVertexCell.h:39
Generic hash function for an arbitrary struct (or class).
Represents a quadrilateral for a Mesh.
typename CellType::CellAutoPointer CellAutoPointer