ITK  5.4.0
Insight Toolkit
itkMesh.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 /*=========================================================================
19  *
20  * Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21  *
22  * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23  *
24  * For complete copyright, license and disclaimer of warranty information
25  * please refer to the NOTICE file at the top of the ITK source tree.
26  *
27  *=========================================================================*/
28 #ifndef itkMesh_h
29 #define itkMesh_h
30 
31 
32 #include "itkPointSet.h"
33 
34 #include "itkBoundingBox.h"
35 #include "itkCellInterface.h"
36 #include "itkMapContainer.h"
37 #include "itkCommonEnums.h"
38 #include "ITKMeshExport.h"
39 #include <vector>
40 #include <set>
41 #include "itkVectorContainer.h"
42 #include "itkVertexCell.h"
43 #include "itkLineCell.h"
44 #include "itkPolyLineCell.h"
45 #include "itkTriangleCell.h"
46 #include "itkQuadrilateralCell.h"
47 #include "itkPolygonCell.h"
48 #include "itkTetrahedronCell.h"
49 #include "itkHexahedronCell.h"
50 #include "itkQuadraticEdgeCell.h"
52 
53 
54 namespace itk
55 {
56 
123 template <typename TPixelType,
124  unsigned int VDimension = 3,
125  typename TMeshTraits = DefaultStaticMeshTraits<TPixelType, VDimension, VDimension>>
126 class ITK_TEMPLATE_EXPORT Mesh : public PointSet<TPixelType, VDimension, TMeshTraits>
127 {
128 public:
129  ITK_DISALLOW_COPY_AND_MOVE(Mesh);
130 
132  using Self = Mesh;
136 
137  using typename Superclass::RegionType;
138 
140  itkNewMacro(Self);
141 
143  itkOverrideGetNameOfClassMacro(Mesh);
144 
146  using MeshTraits = TMeshTraits;
147  using PixelType = typename MeshTraits::PixelType;
148  using CellPixelType = typename MeshTraits::CellPixelType;
150 
152  static constexpr unsigned int PointDimension = TMeshTraits::PointDimension;
153  static constexpr unsigned int MaxTopologicalDimension = TMeshTraits::MaxTopologicalDimension;
154 
155 #if !defined(ITK_LEGACY_REMOVE)
156  using CellsAllocationMethodType = MeshClassCellsAllocationMethodEnum;
158  // We need to expose the enum values at the class level
159  // for backwards compatibility
160  static constexpr CellsAllocationMethodType CellsAllocationMethodUndefined =
161  MeshClassCellsAllocationMethodEnum::CellsAllocationMethodUndefined;
162  static constexpr CellsAllocationMethodType CellsAllocatedAsStaticArray =
164  static constexpr CellsAllocationMethodType CellsAllocatedAsADynamicArray =
166  static constexpr CellsAllocationMethodType CellsAllocatedDynamicallyCellByCell =
168 #endif
169 
171  using CoordRepType = typename MeshTraits::CoordRepType;
172  using InterpolationWeightType = typename MeshTraits::InterpolationWeightType;
173  using PointIdentifier = typename MeshTraits::PointIdentifier;
174  using CellIdentifier = typename MeshTraits::CellIdentifier;
175  using CellFeatureIdentifier = typename MeshTraits::CellFeatureIdentifier;
176  using PointHashType = typename MeshTraits::PointHashType;
178  using PointsContainer = typename MeshTraits::PointsContainer;
179  using CellTraits = typename MeshTraits::CellTraits;
180  using CellsContainer = typename MeshTraits::CellsContainer;
181  using PointCellLinksContainer = typename MeshTraits::PointCellLinksContainer;
182  using CellLinksContainer = typename MeshTraits::CellLinksContainer;
183  using PointDataContainer = typename MeshTraits::PointDataContainer;
184  using CellDataContainer = typename MeshTraits::CellDataContainer;
185 
189 
192 
203 
205  using PointsContainerConstIterator = typename PointsContainer::ConstIterator;
206  using PointsContainerIterator = typename PointsContainer::Iterator;
207  using CellsContainerConstIterator = typename CellsContainer::ConstIterator;
208  using CellsContainerIterator = typename CellsContainer::Iterator;
209  using CellLinksContainerIterator = typename CellLinksContainer::ConstIterator;
210  using PointDataContainerIterator = typename PointDataContainer::ConstIterator;
211  using CellDataContainerIterator = typename CellDataContainer::ConstIterator;
212  using PointCellLinksContainerIterator = typename PointCellLinksContainer::const_iterator;
213 
216 
230 
233 
245  {
246  public:
249 
252  BoundaryAssignmentIdentifier() = default;
254  : m_CellId(cellId)
255  , m_FeatureId(featureId)
256  {}
257 
260 
263 
266  bool
267  operator<(const Self & r) const
268  {
269  return ((m_CellId < r.m_CellId) || ((m_CellId == r.m_CellId) && (m_FeatureId < r.m_FeatureId)));
270  }
271 
274  bool
275  operator==(const Self & r) const
276  {
277  return ((m_CellId == r.m_CellId) && (m_FeatureId == r.m_FeatureId));
278  }
279  }; // End Class: Mesh::BoundaryAssignmentIdentifier
291  using BoundaryAssignmentsContainerVector = std::vector<BoundaryAssignmentsContainerPointer>;
292 
293 protected:
296  CellsContainerPointer m_CellsContainer{};
297 
303  CellDataContainerPointer m_CellDataContainer{};
304 
308  mutable CellLinksContainerPointer m_CellLinksContainer{};
309 
319  BoundaryAssignmentsContainerVector m_BoundaryAssignmentsContainers{};
320 
321 public:
323  CellIdentifier
324  GetNumberOfCells() const;
325 
329  void
330  PassStructure(Self * inputMesh);
331 
335  void
336  Initialize() override;
337 
339  void
340  CopyInformation(const DataObject * data) override;
341 
342  void
343  Graft(const DataObject * data) override;
344 
347  const BoundingBoxType *
348  GetBoundingBox() const;
349 
354  void
355  SetCellLinks(CellLinksContainer *);
356 
358  CellLinksContainer *
359  GetCellLinks();
360 
362  const CellLinksContainer *
363  GetCellLinks() const;
364 
367  void
368  SetCells(CellsContainer *);
369 
375  virtual void
376  SetCellsArray(CellsVectorContainer *);
377 
382  virtual void
383  SetCellsArray(CellsVectorContainer *, int cellType);
384 
388  virtual CellsVectorContainer *
389  GetCellsArray();
390 
392  CellsContainer *
393  GetCells();
394 
396  const CellsContainer *
397  GetCells() const;
398 
403  void
404  SetCellData(CellDataContainer *);
405 
407  CellDataContainer *
408  GetCellData();
409 
411  const CellDataContainer *
412  GetCellData() const;
413 
417  void
418  DeleteUnusedCellData();
419 
420 #if !defined(ITK_WRAPPING_PARSER)
421 
429  void
430  SetBoundaryAssignments(int dimension, BoundaryAssignmentsContainer *);
431 
433  BoundaryAssignmentsContainerPointer
434  GetBoundaryAssignments(int dimension);
435 
437  const BoundaryAssignmentsContainerPointer
438  GetBoundaryAssignments(int dimension) const;
439 #endif
440 
446  void
447  SetCell(CellIdentifier, CellAutoPointer &);
448 
455  bool
456  GetCell(CellIdentifier, CellAutoPointer &) const;
457 
462  void SetCellData(CellIdentifier, CellPixelType);
463 
470  bool
471  GetCellData(CellIdentifier, CellPixelType *) const;
472 
485  void
486  SetBoundaryAssignment(int dimension,
487  CellIdentifier cellId,
488  CellFeatureIdentifier featureId,
489  CellIdentifier boundaryId);
490 
499  bool
500  GetBoundaryAssignment(int dimension,
501  CellIdentifier cellId,
502  CellFeatureIdentifier featureId,
503  CellIdentifier * boundaryId) const;
504 
508  bool
509  RemoveBoundaryAssignment(int dimension, CellIdentifier cellId, CellFeatureIdentifier featureId);
510 
514  CellFeatureCount
515  GetNumberOfCellBoundaryFeatures(int dimension, CellIdentifier) const;
516 
525  bool
526  GetCellBoundaryFeature(int dimension, CellIdentifier, CellFeatureIdentifier, CellAutoPointer &) const;
527 
532  CellIdentifier
533  GetCellBoundaryFeatureNeighbors(int dimension,
534  CellIdentifier,
535  CellFeatureIdentifier,
536  std::set<CellIdentifier> * cellSet);
537 
542  CellIdentifier
543  GetCellNeighbors(CellIdentifier cellId, std::set<CellIdentifier> * cellSet);
544 
552  bool
553  GetAssignedCellBoundaryIfOneExists(int dimension, CellIdentifier, CellFeatureIdentifier, CellAutoPointer &) const;
554 
557  void
558  BuildCellLinks() const;
559 
565  virtual void
566  Accept(CellMultiVisitorType * mv) const;
567 
572  itkSetMacro(CellsAllocationMethod, MeshClassCellsAllocationMethodEnum);
573  itkGetConstReferenceMacro(CellsAllocationMethod, MeshClassCellsAllocationMethodEnum);
576 protected:
578  Mesh();
579  ~Mesh() override;
580  void
581  PrintSelf(std::ostream & os, Indent indent) const override;
588  void
589  ReleaseCellsMemory();
590 
593  BoundingBoxPointer m_BoundingBox{};
594 
595 private:
596  MeshClassCellsAllocationMethodEnum m_CellsAllocationMethod{};
597 
599  void
600  CreateCell(int cellType, CellAutoPointer &);
601 }; // End Class: Mesh
602 
604 extern ITKMesh_EXPORT std::ostream &
605  operator<<(std::ostream & out, const MeshEnums::MeshClassCellsAllocationMethod value);
606 } // end namespace itk
607 
608 #ifndef ITK_MANUAL_INSTANTIATION
609 # ifndef ITK_WRAPPING_PARSER
610 # include "itkMesh.hxx"
611 # endif
612 #endif
613 
614 #endif
itk::Mesh< TPixel, VDimension, TTraits >::PointCellLinksContainer
typename MeshTraits::PointCellLinksContainer PointCellLinksContainer
Definition: itkMesh.h:181
itk::Mesh< TPixel, VDimension, TTraits >::CellTraits
typename MeshTraits::CellTraits CellTraits
Definition: itkMesh.h:179
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::Mesh< TPixel, VDimension, TTraits >::CellMultiVisitorType
typename CellType::MultiVisitor CellMultiVisitorType
Definition: itkMesh.h:232
itkHexahedronCell.h
itk::VertexCell
Represents a single vertex for a Mesh.
Definition: itkVertexCell.h:42
ConstPointer
SmartPointer< const Self > ConstPointer
Definition: itkAddImageFilter.h:94
itk::QuadrilateralCell
Represents a quadrilateral for a Mesh.
Definition: itkQuadrilateralCell.h:42
itk::Mesh::BoundaryAssignmentIdentifier::operator==
bool operator==(const Self &r) const
Definition: itkMesh.h:275
itk::Mesh::BoundaryAssignmentIdentifier
Definition: itkMesh.h:244
itk::PolyLineCell
Represents a series of connected line segments for a Mesh.
Definition: itkPolyLineCell.h:41
itkQuadrilateralCell.h
itk::Mesh< TPixel, VDimension, TTraits >::CellDataContainerIterator
typename CellDataContainer::ConstIterator CellDataContainerIterator
Definition: itkMesh.h:211
itk::PointSet< TPixel, VDimension, TTraits >::PointsContainerIterator
typename PointsContainer::Iterator PointsContainerIterator
Definition: itkPointSet.h:125
itk::PointSet< TPixel, VDimension, TTraits >::PointDataContainerPointer
typename PointDataContainer::Pointer PointDataContainerPointer
Definition: itkPointSet.h:120
itk::operator<
bool operator<(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:559
itk::PointSet
A superclass of the N-dimensional mesh structure; supports point (geometric coordinate and attribute)...
Definition: itkPointSet.h:82
itk::Mesh< TPixel, VDimension, TTraits >::CellLinksContainer
typename MeshTraits::CellLinksContainer CellLinksContainer
Definition: itkMesh.h:182
itk::operator<<
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:216
itk::Mesh::cellOutputVectorContainer
CellsVectorContainerPointer cellOutputVectorContainer
Definition: itkMesh.h:298
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::Mesh< TPixel, VDimension, TTraits >::BoundingBoxPointer
typename BoundingBoxType::Pointer BoundingBoxPointer
Definition: itkMesh.h:201
itk::Mesh< TPixel, VDimension, TTraits >::CellLinksContainerPointer
typename CellLinksContainer::Pointer CellLinksContainerPointer
Definition: itkMesh.h:197
itkLineCell.h
itk::Mesh< TPixel, VDimension, TTraits >::CellsContainerPointer
typename CellsContainer::Pointer CellsContainerPointer
Definition: itkMesh.h:195
itk::MeshEnums::MeshClassCellsAllocationMethod::CellsAllocatedDynamicallyCellByCell
itk::PolygonCell
Represents a polygon in a Mesh.
Definition: itkPolygonCell.h:53
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::Mesh< TPixel, VDimension, TTraits >::CellsVectorContainerPointer
typename CellsVectorContainer::Pointer CellsVectorContainerPointer
Definition: itkMesh.h:188
itk::CellInterface::MultiVisitor
A visitor that can visit different cell types in a mesh. CellInterfaceVisitor instances can be regist...
Definition: itkCellInterface.h:155
itk::Mesh< TPixel, VDimension, TTraits >::CellDataContainerConstPointer
typename CellDataContainer::ConstPointer CellDataContainerConstPointer
Definition: itkMesh.h:200
itk::MapContainer
A wrapper of the STL "map" container.
Definition: itkMapContainer.h:45
itk::Mesh< TPixel, VDimension, TTraits >::CellAutoPointer
typename CellType::CellAutoPointer CellAutoPointer
Definition: itkMesh.h:229
itk::Mesh< TPixel, VDimension, TTraits >::CellLinksContainerConstPointer
typename CellLinksContainer::ConstPointer CellLinksContainerConstPointer
Definition: itkMesh.h:202
itk::Mesh< TPixel, VDimension, TTraits >::CellIdentifier
typename MeshTraits::CellIdentifier CellIdentifier
Definition: itkMesh.h:174
itk::QuadraticEdgeCell
Represents a second order line segment for a Mesh.
Definition: itkQuadraticEdgeCell.h:40
itk::TetrahedronCell
TetrahedronCell represents a tetrahedron for a Mesh.
Definition: itkTetrahedronCell.h:40
itk::MeshEnums::MeshClassCellsAllocationMethod
MeshClassCellsAllocationMethod
Definition: itkCommonEnums.h:198
itk::Mesh< TPixel, VDimension, TTraits >::CellsContainer
typename MeshTraits::CellsContainer CellsContainer
Definition: itkMesh.h:180
itk::PointSet< TPixel, VDimension, TTraits >::PointIdentifier
typename MeshTraits::PointIdentifier PointIdentifier
Definition: itkPointSet.h:105
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itkPolyLineCell.h
itk::PointSet< TPixel, VDimension, TTraits >::MeshTraits
TTraits MeshTraits
Definition: itkPointSet.h:100
itk::Mesh< TPixel, VDimension, TTraits >::CellsContainerConstPointer
typename CellsContainer::ConstPointer CellsContainerConstPointer
Definition: itkMesh.h:196
itk::CellInterface::CellAutoPointer
SelfAutoPointer CellAutoPointer
Definition: itkCellInterface.h:133
itk::PointSet< TPixel, VDimension, TTraits >::PixelType
typename MeshTraits::PixelType PixelType
Definition: itkPointSet.h:101
itk::PointSet< TPixel, VDimension, TTraits >::PointsContainerPointer
typename PointsContainer::Pointer PointsContainerPointer
Definition: itkPointSet.h:118
itk::HexahedronCell
Represents a hexahedron (cuboid) for a Mesh.
Definition: itkHexahedronCell.h:50
itk::TriangleCell
Definition: itkTriangleCell.h:46
itk::PointSet< TPixel, VDimension, TTraits >::CoordRepType
typename MeshTraits::CoordRepType CoordRepType
Definition: itkPointSet.h:104
itk::Mesh::BoundaryAssignmentIdentifier::m_FeatureId
CellFeatureIdentifier m_FeatureId
Definition: itkMesh.h:262
itk::Mesh< TPixel, VDimension, TTraits >::CellsContainerConstIterator
typename CellsContainer::ConstIterator CellsContainerConstIterator
Definition: itkMesh.h:207
itk::Mesh< TPixel, VDimension, TTraits >::InterpolationWeightType
typename MeshTraits::InterpolationWeightType InterpolationWeightType
Definition: itkMesh.h:172
itk::LineCell
Represents a line segment for a Mesh.
Definition: itkLineCell.h:45
itk::Mesh< TPixel, VDimension, TTraits >::CellsVectorContainer
typename itk::VectorContainer< IdentifierType, IdentifierType > CellsVectorContainer
Definition: itkMesh.h:187
itk::PointSet< TPixel, VDimension, TTraits >::PointDataContainerIterator
typename PointDataContainer::ConstIterator PointDataContainerIterator
Definition: itkPointSet.h:126
itkVertexCell.h
itk::PointSet< TPixel, VDimension, TTraits >::PointsContainer
typename MeshTraits::PointsContainer PointsContainer
Definition: itkPointSet.h:107
itk::CellInterface
An abstract interface for cells.
Definition: itkCellInterface.h:96
itkVectorContainer.h
itk::MeshEnums::MeshClassCellsAllocationMethod::CellsAllocatedAsStaticArray
itk::Mesh< TPixel, VDimension, TTraits >::CellFeatureIdentifier
typename MeshTraits::CellFeatureIdentifier CellFeatureIdentifier
Definition: itkMesh.h:175
itk::Mesh< TPixel, VDimension, TTraits >::CellLinksContainerIterator
typename CellLinksContainer::ConstIterator CellLinksContainerIterator
Definition: itkMesh.h:209
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itkCommonEnums.h
itk::Mesh
Implements the N-dimensional mesh structure.
Definition: itkMesh.h:126
itkPolygonCell.h
itkQuadraticEdgeCell.h
itk::Mesh< TPixel, VDimension, TTraits >::CellPixelType
typename MeshTraits::CellPixelType CellPixelType
Definition: itkMesh.h:148
itk::PointSet< TPixel, VDimension, TTraits >::PointDataContainer
typename MeshTraits::PointDataContainer PointDataContainer
Definition: itkPointSet.h:108
itk::Mesh< TPixel, VDimension, TTraits >::PointCellLinksContainerIterator
typename PointCellLinksContainer::const_iterator PointCellLinksContainerIterator
Definition: itkMesh.h:212
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itkCellInterface.h
itk::Mesh< TPixel, VDimension, TTraits >::BoundaryAssignmentsContainerVector
std::vector< BoundaryAssignmentsContainerPointer > BoundaryAssignmentsContainerVector
Definition: itkMesh.h:291
itk::Mesh< TPixel, VDimension, TTraits >::CellsContainerIterator
typename CellsContainer::Iterator CellsContainerIterator
Definition: itkMesh.h:208
itk::PointSet< TPixel, VDimension, TTraits >::PointType
typename MeshTraits::PointType PointType
Definition: itkPointSet.h:106
itkPointSet.h
itk::BoundingBox
Represent and compute information about bounding boxes.
Definition: itkBoundingBox.h:70
AddImageFilter
Definition: itkAddImageFilter.h:81
itkMapContainer.h
itkQuadraticTriangleCell.h
itk::Mesh< TPixel, VDimension, TTraits >::CellFeatureCount
CellFeatureIdentifier CellFeatureCount
Definition: itkMesh.h:215
itk::Mesh::BoundaryAssignmentIdentifier::m_CellId
CellIdentifier m_CellId
Definition: itkMesh.h:259
itk::QuadraticTriangleCell
Represents a second order triangular patch for a Mesh.
Definition: itkQuadraticTriangleCell.h:41
itk::PointSet< TPixel, VDimension, TTraits >::PointsContainerConstIterator
typename PointsContainer::ConstIterator PointsContainerConstIterator
Definition: itkPointSet.h:124
itk::Mesh< TPixel, VDimension, TTraits >::CellDataContainerPointer
typename CellDataContainer::Pointer CellDataContainerPointer
Definition: itkMesh.h:199
itkTriangleCell.h
itk::Mesh< TPixel, VDimension, TTraits >::BoundaryAssignmentsContainerPointer
typename BoundaryAssignmentsContainer::Pointer BoundaryAssignmentsContainerPointer
Definition: itkMesh.h:290
itk::Mesh::BoundaryAssignmentIdentifier::BoundaryAssignmentIdentifier
BoundaryAssignmentIdentifier(CellIdentifier cellId, CellFeatureIdentifier featureId)
Definition: itkMesh.h:253
itk::Mesh< TPixel, VDimension, TTraits >::PointHashType
typename MeshTraits::PointHashType PointHashType
Definition: itkMesh.h:176
itk::VectorContainer
Define a front-end to the STL "vector" container that conforms to the IndexedContainerInterface.
Definition: itkVectorContainer.h:48
itkTetrahedronCell.h
itk::Mesh< TPixel, VDimension, TTraits >::CellDataContainer
typename MeshTraits::CellDataContainer CellDataContainer
Definition: itkMesh.h:184
itkBoundingBox.h
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293
itk::MeshEnums::MeshClassCellsAllocationMethod::CellsAllocatedAsADynamicArray