ITK  6.0.0
Insight Toolkit
itkCellInterface.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 itkCellInterface_h
19 #define itkCellInterface_h
20 
21 #include "itkObject.h"
23 #include "itkAutoPointer.h"
24 #include "itkArray.h"
25 #include "itkCommonEnums.h"
26 
27 #include <map>
28 
29 // Define a macro for CellInterface sub-classes to use
30 // to define the Accept and GetTopologyId virtuals used
31 // by the MultiVisitor class
32 #define itkCellVisitMacro(TopologyId) \
33  static constexpr CellGeometryEnum GetTopologyId() { return TopologyId; } \
34  virtual void Accept(CellIdentifier cellid, typename CellInterface<PixelType, CellTraits>::MultiVisitor * mv) \
35  override \
36  { \
37  typename CellInterfaceVisitor<PixelType, CellTraits>::Pointer v = mv->GetVisitor(TopologyId); \
38  if (v) \
39  { \
40  v->VisitFromCell(cellid, this); \
41  } \
42  } \
43  ITK_MACROEND_NOOP_STATEMENT
44 
45 // Define a macro for the common type alias required by the
46 // classes deriving form CellInterface (included).
47 #define itkCellCommonTypedefs(celltype) \
48  using Self = celltype; \
49  using ConstSelfAutoPointer = AutoPointer<const Self>; \
50  using SelfAutoPointer = AutoPointer<Self>; \
51  using RawPointer = Self *; \
52  using ConstRawPointer = const Self *
53 
54 // Define a macro for the common type alias required by the
55 // classes deriving form CellInterface (excluded).
56 #define itkCellInheritedTypedefs(superclassArg) \
57  using Superclass = superclassArg; \
58  using typename Superclass::PixelType; \
59  using CellType = typename Superclass::CellType; \
60  using typename Superclass::CellAutoPointer; \
61  using typename Superclass::CellConstAutoPointer; \
62  using typename Superclass::CellRawPointer; \
63  using typename Superclass::CellConstRawPointer; \
64  using typename Superclass::CellTraits; \
65  using typename Superclass::CoordRepType; \
66  using typename Superclass::InterpolationWeightType; \
67  using typename Superclass::PointIdentifier; \
68  using typename Superclass::PointIdIterator; \
69  using typename Superclass::PointIdConstIterator; \
70  using typename Superclass::CellIdentifier; \
71  using typename Superclass::CellFeatureIdentifier; \
72  using CellFeatureCount = typename Superclass::CellFeatureIdentifier; \
73  using typename Superclass::PointType; \
74  using typename Superclass::VectorType; \
75  using typename Superclass::PointsContainer; \
76  using typename Superclass::UsingCellsContainer; \
77  using typename Superclass::ParametricCoordArrayType; \
78  using typename Superclass::ShapeFunctionsArrayType; \
79  static constexpr unsigned int PointDimension = Superclass::PointDimension
80 
81 namespace itk
82 {
83 
96 template <typename TPixelType, typename TCellTraits>
97 class ITK_TEMPLATE_EXPORT CellInterface
98 {
99 public:
100  ITK_DISALLOW_COPY_AND_MOVE(CellInterface);
101 
104 
106  using PixelType = TPixelType;
107 
109  using CellTraits = TCellTraits;
110 
112  using CoordRepType = typename CellTraits::CoordRepType;
113  using InterpolationWeightType = typename CellTraits::InterpolationWeightType;
114  using PointIdentifier = typename CellTraits::PointIdentifier;
115  using PointIdIterator = typename CellTraits::PointIdIterator;
116  using PointIdConstIterator = typename CellTraits::PointIdConstIterator;
117  using CellIdentifier = typename CellTraits::CellIdentifier;
118  using CellFeatureIdentifier = typename CellTraits::CellFeatureIdentifier;
120  using PointsContainer = typename CellTraits::PointsContainer;
121  using UsingCellsContainer = typename CellTraits::UsingCellsContainer;
122 
125 
127  static constexpr unsigned int PointDimension = CellTraits::PointDimension;
128 
130  using UsingCellsContainerIterator = typename UsingCellsContainer::iterator;
131 
134  using CellAutoPointer = SelfAutoPointer;
135  using CellConstAutoPointer = ConstSelfAutoPointer;
136  using CellRawPointer = RawPointer;
137  using CellConstRawPointer = ConstRawPointer;
138 
141 
145 
146  // static int GetNextUserCellId(); // never return > MAX_INTERFACE
147 
156  class MultiVisitor : public LightObject
157  {
158  public:
162 
166 
168  // itkNewMacro(Self);
169  static Pointer
170  New()
171  {
172  Pointer smartPtr = new Self;
173  smartPtr->UnRegister();
174  return smartPtr;
175  }
179  itkOverrideGetNameOfClassMacro(MultiVisitor);
180 
183  using VisitorPointerValueType = typename std::map<CellGeometryEnum, VisitorPointer>::value_type;
184 
185  public:
186  VisitorType *
188  {
190  {
191  return m_Visitors[static_cast<int>(id)];
192  }
193  else
194  {
195  auto pos = m_UserDefined.find(id);
196  if (pos != m_UserDefined.end())
197  {
198  return pos->second;
199  }
200  }
201  return nullptr;
202  }
203 
204  void
206  {
208 
210  {
211  m_Visitors[static_cast<int>(id)] = v;
212  }
213  else
214  {
215  m_UserDefined.insert(VisitorPointerValueType(id, v));
216  }
217  }
218 
219  ~MultiVisitor() override = default;
220 
221  protected:
222  VisitorPointer m_Visitors[static_cast<int>(CellGeometryEnum::LAST_ITK_CELL)]; // fixed array set to the
223  // size
224  // from the enum
225  std::map<CellGeometryEnum, VisitorPointer> m_UserDefined; // user defined cell types
226  // go here
227  };
228 
230  virtual void
231  Accept(CellIdentifier cellId, MultiVisitor *) = 0;
232 
236  GetType() const = 0;
237 
240  virtual void
241  MakeCopy(CellAutoPointer &) const = 0;
242 
244  virtual unsigned int
245  GetDimension() const = 0;
246 
248  virtual unsigned int
249  GetInterpolationOrder() const;
250 
252  virtual unsigned int
253  GetNumberOfPoints() const = 0;
254 
256  virtual CellFeatureCount
257  GetNumberOfBoundaryFeatures(int dimension) const = 0;
258 
260  virtual bool
261  GetBoundaryFeature(int dimension, CellFeatureIdentifier, CellAutoPointer &) = 0;
262 
266  virtual PointIdConstIterator
267  GetPointIds() const;
268 
272  virtual void
273  SetPointIds(PointIdConstIterator first) = 0;
274 
279  virtual void
280  SetPointIds(PointIdConstIterator first, PointIdConstIterator last) = 0;
281 
284  virtual void
285  SetPointId(int localId, PointIdentifier) = 0;
286 
288  virtual PointIdIterator
289  PointIdsBegin() = 0;
290 
293  virtual PointIdConstIterator
294  PointIdsBegin() const = 0;
295 
297  virtual PointIdIterator
298  PointIdsEnd() = 0;
299 
302  virtual PointIdConstIterator
303  PointIdsEnd() const = 0;
304 
308  GetPointIdsContainer() const;
309  void
310  SetPointIdsContainer(const PointIdentifierContainerType &);
317  virtual bool
319  {
320  return false;
321  }
322 
339  virtual bool
341  PointsContainer *,
342  CoordRepType *,
343  CoordRepType[],
344  double *,
346  {
347  return bool();
348  }
349 
353  virtual void
355  {}
356 
372  virtual bool
374  CoordRepType[PointDimension],
375  CoordRepType,
376  CoordRepType[PointDimension],
377  CoordRepType *,
378  CoordRepType[])
379  {
380  return bool();
381  }
382 
387  CoordRepType * GetBoundingBox(CoordRepType[PointDimension * 2]) { return nullptr; }
391  CoordRepType
393  {
394  return CoordRepType{};
395  }
396 
409  virtual bool IntersectBoundingBoxWithLine(CoordRepType[PointDimension * 2],
410  CoordRepType[PointDimension],
411  CoordRepType[PointDimension],
412  CoordRepType[PointDimension],
413  CoordRepType *)
414  {
415  return bool();
416  }
417 
423  virtual bool
424  IsExplicitBoundary();
425 
430  virtual void
431  AddUsingCell(CellIdentifier cellId);
432 
436  virtual void
437  RemoveUsingCell(CellIdentifier cellId);
438 
444  virtual bool
445  IsUsingCell(CellIdentifier cellId);
446 
450  virtual unsigned int
451  GetNumberOfUsingCells();
452 
453 #if !defined(ITK_WRAPPING_PARSER)
454 
457  virtual UsingCellsContainerIterator
458  UsingCellsBegin();
459 
463  virtual UsingCellsContainerIterator
464  UsingCellsEnd();
465 
466 #endif
467 
469  itkVirtualGetNameOfClassMacro(CellInterface);
470 
471 public:
472  CellInterface() = default;
473  virtual ~CellInterface() = default;
477  // bool GetPointPosition(PointsContainer*, int localId, Point*)=0;
478 
479 #if !defined(ITK_LEGACY_REMOVE)
480 
484  static constexpr CommonEnums::CellGeometry QUADRILATERAL_CELL = CommonEnums::CellGeometry::QUADRILATERAL_CELL;
488  static constexpr CommonEnums::CellGeometry QUADRATIC_EDGE_CELL = CommonEnums::CellGeometry::QUADRATIC_EDGE_CELL;
489  static constexpr CommonEnums::CellGeometry QUADRATIC_TRIANGLE_CELL =
493 #endif
494 
495 protected:
497  UsingCellsContainer m_UsingCells{};
498 };
499 
518 template <int VPointDimension,
519  typename TCoordRep,
520  typename TInterpolationWeight,
521  typename TPointIdentifier,
522  typename TCellIdentifier,
523  typename TCellFeatureIdentifier,
524  typename TPoint,
525  typename TPointsContainer,
526  typename TUsingCellsContainer>
527 class ITK_TEMPLATE_EXPORT CellTraitsInfo
528 {
529 public:
530  static constexpr unsigned int PointDimension = VPointDimension;
531  using CoordRepType = TCoordRep;
532  using InterpolationWeightType = TInterpolationWeight;
533  using PointIdentifier = TPointIdentifier;
534  using CellIdentifier = TCellIdentifier;
535  using CellFeatureIdentifier = TCellFeatureIdentifier;
536  using PointType = TPoint;
537  using PointsContainer = TPointsContainer;
538  using UsingCellsContainer = TUsingCellsContainer;
540 
542 };
543 
544 #define itkMakeCellTraitsMacro \
545  CellTraitsInfo<Self::PointDimension, \
546  CoordRepType, \
547  InterpolationWeightType, \
548  PointIdentifier, \
549  CellIdentifier, \
550  CellFeatureIdentifier, \
551  PointType, \
552  PointsContainer, \
553  UsingCellsContainer>
554 } // end namespace itk
555 
556 #if !defined(ITK_WRAPPING_PARSER)
557 # ifndef ITK_MANUAL_INSTANTIATION
558 # include "itkCellInterface.hxx"
559 # endif
560 #endif
561 
562 #endif
itk::CommonEnums::CellGeometry::LINE_CELL
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::CommonEnums::CellGeometry::POLYGON_CELL
itk::CellTraitsInfo::PointsContainer
TPointsContainer PointsContainer
Definition: itkCellInterface.h:537
itk::CellTraitsInfo::PointType
TPoint PointType
Definition: itkCellInterface.h:536
itk::CellInterface::GetClosestBoundary
virtual bool GetClosestBoundary(CoordRepType[], bool *, CellAutoPointer &)
Definition: itkCellInterface.h:318
itk::CellInterface::MultiVisitor::VisitorPointerValueType
typename std::map< CellGeometryEnum, VisitorPointer >::value_type VisitorPointerValueType
Definition: itkCellInterface.h:183
itk::CellInterface::MultiVisitor::m_UserDefined
std::map< CellGeometryEnum, VisitorPointer > m_UserDefined
Definition: itkCellInterface.h:225
itk::CellInterface::VectorType
typename PointType::VectorType VectorType
NOTE: it should normally be defined in the traits.
Definition: itkCellInterface.h:124
itk::CellInterface::PointIdentifier
typename CellTraits::PointIdentifier PointIdentifier
Definition: itkCellInterface.h:114
itk::CommonEnums::CellGeometry::QUADRATIC_EDGE_CELL
itk::CellInterface::IntersectWithLine
virtual bool IntersectWithLine(CoordRepType[PointDimension], CoordRepType[PointDimension], CoordRepType, CoordRepType[PointDimension], CoordRepType *, CoordRepType[])
Definition: itkCellInterface.h:373
itk::CellInterface::UsingCellsContainer
typename CellTraits::UsingCellsContainer UsingCellsContainer
Definition: itkCellInterface.h:121
itk::CommonEnums::CellGeometry::HEXAHEDRON_CELL
Self
AddImageFilter Self
Definition: itkAddImageFilter.h:89
itk::CellInterface::MultiVisitor::VisitorPointer
typename VisitorType::Pointer VisitorPointer
Definition: itkCellInterface.h:182
itkAutoPointer.h
itk::CellInterfaceVisitor
Abstract interface for a visitor class that can visit the cells in a Mesh.
Definition: itkCellInterfaceVisitor.h:45
itk::CellTraitsInfo
A simple utility class to define the cell type inside a mesh type structure definition....
Definition: itkCellInterface.h:527
itk::CellInterface::InterpolationWeightType
typename CellTraits::InterpolationWeightType InterpolationWeightType
Definition: itkCellInterface.h:113
itk::GTest::TypedefsAndConstructors::Dimension2::VectorType
ImageBaseType::SpacingType VectorType
Definition: itkGTestTypedefsAndConstructors.h:53
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::CellTraitsInfo::PointIdConstIterator
const PointIdentifier * PointIdConstIterator
Definition: itkCellInterface.h:541
itk::CellInterface::PointsContainer
typename CellTraits::PointsContainer PointsContainer
Definition: itkCellInterface.h:120
itk::SmartPointer< Self >
itk::CellInterface::PointType
typename CellTraits::PointType PointType
Definition: itkCellInterface.h:119
itk::CellInterface::CellConstAutoPointer
ConstSelfAutoPointer CellConstAutoPointer
Definition: itkCellInterface.h:135
itk::CellInterface::CoordRepType
typename CellTraits::CoordRepType CoordRepType
Definition: itkCellInterface.h:112
itk::CellInterface::MultiVisitor
A visitor that can visit different cell types in a mesh. CellInterfaceVisitor instances can be regist...
Definition: itkCellInterface.h:156
itk::CellInterface::PointIdConstIterator
typename CellTraits::PointIdConstIterator PointIdConstIterator
Definition: itkCellInterface.h:116
itk::CellTraitsInfo::CellIdentifier
TCellIdentifier CellIdentifier
Definition: itkCellInterface.h:534
itk::CellTraitsInfo::PointIdIterator
PointIdentifier * PointIdIterator
Definition: itkCellInterface.h:539
itk::CellInterface::MultiVisitor::GetVisitor
VisitorType * GetVisitor(CellGeometryEnum id)
Definition: itkCellInterface.h:187
itk::CommonEnums::CellGeometry
CellGeometry
Definition: itkCommonEnums.h:132
itk::CellInterface::UsingCellsContainerIterator
typename UsingCellsContainer::iterator UsingCellsContainerIterator
Definition: itkCellInterface.h:130
itk::CellInterface::PixelType
TPixelType PixelType
Definition: itkCellInterface.h:106
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::CellInterface::CellRawPointer
RawPointer CellRawPointer
Definition: itkCellInterface.h:136
itk::CellInterface::GetBoundingBox
CoordRepType * GetBoundingBox(CoordRepType[PointDimension *2])
Definition: itkCellInterface.h:387
itk::CellTraitsInfo::UsingCellsContainer
TUsingCellsContainer UsingCellsContainer
Definition: itkCellInterface.h:538
itk::CellInterface
class ITK_TEMPLATE_EXPORT CellInterface
Definition: itkCellInterfaceVisitor.h:29
itk::CellInterface::EvaluatePosition
virtual bool EvaluatePosition(CoordRepType *, PointsContainer *, CoordRepType *, CoordRepType[], double *, InterpolationWeightType *)
Definition: itkCellInterface.h:340
itk::CellInterface::CellAutoPointer
SelfAutoPointer CellAutoPointer
Definition: itkCellInterface.h:134
itk::CommonEnums::CellGeometry::MAX_ITK_CELLS
itk::SmartPointer::UnRegister
void UnRegister() noexcept
Definition: itkSmartPointer.h:221
itk::CellInterface::MultiVisitor::New
static Pointer New()
Definition: itkCellInterface.h:170
itk::CellInterface::CellIdentifier
typename CellTraits::CellIdentifier CellIdentifier
Definition: itkCellInterface.h:117
itk::CellInterface::CellConstRawPointer
ConstRawPointer CellConstRawPointer
Definition: itkCellInterface.h:137
itk::CellInterface::CellFeatureCount
CellFeatureIdentifier CellFeatureCount
Definition: itkCellInterface.h:140
itk::CommonEnums::CellGeometry::QUADRATIC_TRIANGLE_CELL
itkArray.h
itk::CommonEnums::CellGeometry::QUADRILATERAL_CELL
itkObject.h
itk::CellInterface
An abstract interface for cells.
Definition: itkCellInterface.h:97
itk::CellInterface::GetBoundingBoxDiagonalLength2
CoordRepType GetBoundingBoxDiagonalLength2()
Definition: itkCellInterface.h:392
itk::CommonEnums::CellGeometry::TRIANGLE_CELL
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itkCommonEnums.h
itk::CellInterface::PointIdIterator
typename CellTraits::PointIdIterator PointIdIterator
Definition: itkCellInterface.h:115
itk::CellInterface::EvaluateShapeFunctions
virtual void EvaluateShapeFunctions(const ParametricCoordArrayType &, ShapeFunctionsArrayType &) const
Definition: itkCellInterface.h:354
itk::Array
Array class with size defined at construction time.
Definition: itkArray.h:47
itk::CellTraitsInfo::InterpolationWeightType
TInterpolationWeight InterpolationWeightType
Definition: itkCellInterface.h:532
itk::CommonEnums::CellGeometry::TETRAHEDRON_CELL
itk::CellInterface::CellTraits
TCellTraits CellTraits
Definition: itkCellInterface.h:109
itk::CellInterface::CellFeatureIdentifier
typename CellTraits::CellFeatureIdentifier CellFeatureIdentifier
Definition: itkCellInterface.h:118
itk::CellTraitsInfo::CoordRepType
TCoordRep CoordRepType
Definition: itkCellInterface.h:531
itk::CellTraitsInfo::CellFeatureIdentifier
TCellFeatureIdentifier CellFeatureIdentifier
Definition: itkCellInterface.h:535
itkCellInterfaceVisitor.h
itk::CellInterface::MultiVisitor::AddVisitor
void AddVisitor(VisitorType *v)
Definition: itkCellInterface.h:205
itk::CellTraitsInfo::PointIdentifier
TPointIdentifier PointIdentifier
Definition: itkCellInterface.h:533
itk::CommonEnums::CellGeometry::VERTEX_CELL
itk::CellInterfaceVisitor::GetCellTopologyId
virtual CellGeometryEnum GetCellTopologyId()=0
itkCellCommonTypedefs
#define itkCellCommonTypedefs(celltype)
Definition: itkCellInterface.h:47
itk::CommonEnums::CellGeometry::LAST_ITK_CELL
itk::CellInterface::IntersectBoundingBoxWithLine
virtual bool IntersectBoundingBoxWithLine(CoordRepType[PointDimension *2], CoordRepType[PointDimension], CoordRepType[PointDimension], CoordRepType[PointDimension], CoordRepType *)
Definition: itkCellInterface.h:409