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::CoordinateType; \
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 CoordinateType = typename CellTraits::CoordinateType;
113 #ifndef ITK_FUTURE_LEGACY_REMOVE
114  using CoordRepType ITK_FUTURE_DEPRECATED(
115  "ITK 6 discourages using `CoordRepType`. Please use `CoordinateType` instead!") = CoordinateType;
116 #endif
117  using InterpolationWeightType = typename CellTraits::InterpolationWeightType;
118  using PointIdentifier = typename CellTraits::PointIdentifier;
119  using PointIdIterator = typename CellTraits::PointIdIterator;
120  using PointIdConstIterator = typename CellTraits::PointIdConstIterator;
121  using CellIdentifier = typename CellTraits::CellIdentifier;
122  using CellFeatureIdentifier = typename CellTraits::CellFeatureIdentifier;
124  using PointsContainer = typename CellTraits::PointsContainer;
125  using UsingCellsContainer = typename CellTraits::UsingCellsContainer;
126 
129 
131  static constexpr unsigned int PointDimension = CellTraits::PointDimension;
132 
134  using UsingCellsContainerIterator = typename UsingCellsContainer::iterator;
135 
138  using CellAutoPointer = SelfAutoPointer;
139  using CellConstAutoPointer = ConstSelfAutoPointer;
140  using CellRawPointer = RawPointer;
141  using CellConstRawPointer = ConstRawPointer;
142 
145 
149 
150  // static int GetNextUserCellId(); // never return > MAX_INTERFACE
151 
160  class MultiVisitor : public LightObject
161  {
162  public:
166 
170 
172  // itkNewMacro(Self);
173  static Pointer
174  New()
175  {
176  Pointer smartPtr = new Self;
177  smartPtr->UnRegister();
178  return smartPtr;
179  }
183  itkOverrideGetNameOfClassMacro(MultiVisitor);
184 
187  using VisitorPointerValueType = typename std::map<CellGeometryEnum, VisitorPointer>::value_type;
188 
189  public:
190  VisitorType *
192  {
194  {
195  return m_Visitors[static_cast<int>(id)];
196  }
197  else
198  {
199  auto pos = m_UserDefined.find(id);
200  if (pos != m_UserDefined.end())
201  {
202  return pos->second;
203  }
204  }
205  return nullptr;
206  }
207 
208  void
210  {
212 
214  {
215  m_Visitors[static_cast<int>(id)] = v;
216  }
217  else
218  {
219  m_UserDefined.insert(VisitorPointerValueType(id, v));
220  }
221  }
222 
223  ~MultiVisitor() override = default;
224 
225  protected:
226  VisitorPointer m_Visitors[static_cast<int>(CellGeometryEnum::LAST_ITK_CELL)]; // fixed array set to the
227  // size
228  // from the enum
229  std::map<CellGeometryEnum, VisitorPointer> m_UserDefined; // user defined cell types
230  // go here
231  };
232 
234  virtual void
235  Accept(CellIdentifier cellId, MultiVisitor *) = 0;
236 
240  GetType() const = 0;
241 
244  virtual void
245  MakeCopy(CellAutoPointer &) const = 0;
246 
248  virtual unsigned int
249  GetDimension() const = 0;
250 
252  virtual unsigned int
253  GetInterpolationOrder() const;
254 
256  virtual unsigned int
257  GetNumberOfPoints() const = 0;
258 
260  virtual CellFeatureCount
261  GetNumberOfBoundaryFeatures(int dimension) const = 0;
262 
264  virtual bool
265  GetBoundaryFeature(int dimension, CellFeatureIdentifier, CellAutoPointer &) = 0;
266 
270  virtual PointIdConstIterator
271  GetPointIds() const;
272 
276  virtual void
277  SetPointIds(PointIdConstIterator first) = 0;
278 
283  virtual void
284  SetPointIds(PointIdConstIterator first, PointIdConstIterator last) = 0;
285 
288  virtual void
289  SetPointId(int localId, PointIdentifier) = 0;
290 
292  virtual PointIdIterator
293  PointIdsBegin() = 0;
294 
297  virtual PointIdConstIterator
298  PointIdsBegin() const = 0;
299 
301  virtual PointIdIterator
302  PointIdsEnd() = 0;
303 
306  virtual PointIdConstIterator
307  PointIdsEnd() const = 0;
308 
312  GetPointIdsContainer() const;
313  void
314  SetPointIdsContainer(const PointIdentifierContainerType &);
321  virtual bool
323  {
324  return false;
325  }
326 
343  virtual bool
345  PointsContainer *,
346  CoordinateType *,
347  CoordinateType[],
348  double *,
350  {
351  return bool();
352  }
353 
357  virtual void
359  {}
360 
376  virtual bool
378  CoordinateType[PointDimension],
380  CoordinateType[PointDimension],
381  CoordinateType *,
382  CoordinateType[])
383  {
384  return bool();
385  }
386 
391  CoordinateType * GetBoundingBox(CoordinateType[PointDimension * 2]) { return nullptr; }
395  CoordinateType
397  {
398  return CoordinateType{};
399  }
400 
413  virtual bool IntersectBoundingBoxWithLine(CoordinateType[PointDimension * 2],
414  CoordinateType[PointDimension],
415  CoordinateType[PointDimension],
416  CoordinateType[PointDimension],
417  CoordinateType *)
418  {
419  return bool();
420  }
421 
427  virtual bool
428  IsExplicitBoundary();
429 
434  virtual void
435  AddUsingCell(CellIdentifier cellId);
436 
440  virtual void
441  RemoveUsingCell(CellIdentifier cellId);
442 
448  virtual bool
449  IsUsingCell(CellIdentifier cellId);
450 
454  virtual unsigned int
455  GetNumberOfUsingCells();
456 
457 #if !defined(ITK_WRAPPING_PARSER)
458 
461  virtual UsingCellsContainerIterator
462  UsingCellsBegin();
463 
467  virtual UsingCellsContainerIterator
468  UsingCellsEnd();
469 
470 #endif
471 
473  itkVirtualGetNameOfClassMacro(CellInterface);
474 
475 public:
476  CellInterface() = default;
477  virtual ~CellInterface() = default;
481  // bool GetPointPosition(PointsContainer*, int localId, Point*)=0;
482 
483 #if !defined(ITK_LEGACY_REMOVE)
484 
488  static constexpr CommonEnums::CellGeometry QUADRILATERAL_CELL = CommonEnums::CellGeometry::QUADRILATERAL_CELL;
492  static constexpr CommonEnums::CellGeometry QUADRATIC_EDGE_CELL = CommonEnums::CellGeometry::QUADRATIC_EDGE_CELL;
493  static constexpr CommonEnums::CellGeometry QUADRATIC_TRIANGLE_CELL =
497 #endif
498 
499 protected:
501  UsingCellsContainer m_UsingCells{};
502 };
503 
522 template <int VPointDimension,
523  typename TCoordinate,
524  typename TInterpolationWeight,
525  typename TPointIdentifier,
526  typename TCellIdentifier,
527  typename TCellFeatureIdentifier,
528  typename TPoint,
529  typename TPointsContainer,
530  typename TUsingCellsContainer>
531 class ITK_TEMPLATE_EXPORT CellTraitsInfo
532 {
533 public:
534  static constexpr unsigned int PointDimension = VPointDimension;
535  using CoordinateType = TCoordinate;
536 #ifndef ITK_FUTURE_LEGACY_REMOVE
537  using CoordRepType ITK_FUTURE_DEPRECATED(
538  "ITK 6 discourages using `CoordRepType`. Please use `CoordinateType` instead!") = CoordinateType;
539 #endif
540  using InterpolationWeightType = TInterpolationWeight;
541  using PointIdentifier = TPointIdentifier;
542  using CellIdentifier = TCellIdentifier;
543  using CellFeatureIdentifier = TCellFeatureIdentifier;
544  using PointType = TPoint;
545  using PointsContainer = TPointsContainer;
546  using UsingCellsContainer = TUsingCellsContainer;
548 
550 };
551 
552 #define itkMakeCellTraitsMacro \
553  CellTraitsInfo<Self::PointDimension, \
554  CoordinateType, \
555  InterpolationWeightType, \
556  PointIdentifier, \
557  CellIdentifier, \
558  CellFeatureIdentifier, \
559  PointType, \
560  PointsContainer, \
561  UsingCellsContainer>
562 } // end namespace itk
563 
564 #if !defined(ITK_WRAPPING_PARSER)
565 # ifndef ITK_MANUAL_INSTANTIATION
566 # include "itkCellInterface.hxx"
567 # endif
568 #endif
569 
570 #endif
itk::CommonEnums::CellGeometry::LINE_CELL
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::CommonEnums::CellGeometry::POLYGON_CELL
itk::CellInterface::MultiVisitor::VisitorPointerValueType
typename std::map< CellGeometryEnum, VisitorPointer >::value_type VisitorPointerValueType
Definition: itkCellInterface.h:187
itk::CellInterface::MultiVisitor::m_UserDefined
std::map< CellGeometryEnum, VisitorPointer > m_UserDefined
Definition: itkCellInterface.h:229
itk::CellInterface::VectorType
typename PointType::VectorType VectorType
NOTE: it should normally be defined in the traits.
Definition: itkCellInterface.h:128
itk::CellTraitsInfo::PointsContainer
TPointsContainer PointsContainer
Definition: itkCellInterface.h:545
itk::CellInterface::PointIdentifier
typename CellTraits::PointIdentifier PointIdentifier
Definition: itkCellInterface.h:118
itk::CommonEnums::CellGeometry::QUADRATIC_EDGE_CELL
itk::CellInterface::UsingCellsContainer
typename CellTraits::UsingCellsContainer UsingCellsContainer
Definition: itkCellInterface.h:125
itk::CommonEnums::CellGeometry::HEXAHEDRON_CELL
Self
AddImageFilter Self
Definition: itkAddImageFilter.h:89
itk::CellInterface::MultiVisitor::VisitorPointer
typename VisitorType::Pointer VisitorPointer
Definition: itkCellInterface.h:186
itkAutoPointer.h
itk::CellTraitsInfo::PointIdentifier
TPointIdentifier PointIdentifier
Definition: itkCellInterface.h:541
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:531
itk::CellInterface::IntersectBoundingBoxWithLine
virtual bool IntersectBoundingBoxWithLine(CoordinateType[PointDimension *2], CoordinateType[PointDimension], CoordinateType[PointDimension], CoordinateType[PointDimension], CoordinateType *)
Definition: itkCellInterface.h:413
itk::CellInterface::InterpolationWeightType
typename CellTraits::InterpolationWeightType InterpolationWeightType
Definition: itkCellInterface.h:117
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::PointType
TPoint PointType
Definition: itkCellInterface.h:544
itk::CellInterface::PointsContainer
typename CellTraits::PointsContainer PointsContainer
Definition: itkCellInterface.h:124
itk::CellTraitsInfo::CoordinateType
TCoordinate CoordinateType
Definition: itkCellInterface.h:535
itk::SmartPointer< Self >
itk::CellInterface::GetBoundingBox
CoordinateType * GetBoundingBox(CoordinateType[PointDimension *2])
Definition: itkCellInterface.h:391
itk::CellInterface::PointType
typename CellTraits::PointType PointType
Definition: itkCellInterface.h:123
itk::CellInterface::CellConstAutoPointer
ConstSelfAutoPointer CellConstAutoPointer
Definition: itkCellInterface.h:139
itk::CellInterface::MultiVisitor
A visitor that can visit different cell types in a mesh. CellInterfaceVisitor instances can be regist...
Definition: itkCellInterface.h:160
itk::CellInterface::PointIdConstIterator
typename CellTraits::PointIdConstIterator PointIdConstIterator
Definition: itkCellInterface.h:120
itk::CellTraitsInfo::CellIdentifier
TCellIdentifier CellIdentifier
Definition: itkCellInterface.h:542
itk::CellInterface::GetClosestBoundary
virtual bool GetClosestBoundary(CoordinateType[], bool *, CellAutoPointer &)
Definition: itkCellInterface.h:322
itk::CellInterface::MultiVisitor::GetVisitor
VisitorType * GetVisitor(CellGeometryEnum id)
Definition: itkCellInterface.h:191
itk::CommonEnums::CellGeometry
CellGeometry
Definition: itkCommonEnums.h:132
itk::CellTraitsInfo::UsingCellsContainer
TUsingCellsContainer UsingCellsContainer
Definition: itkCellInterface.h:546
itk::CellInterface::UsingCellsContainerIterator
typename UsingCellsContainer::iterator UsingCellsContainerIterator
Definition: itkCellInterface.h:134
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:140
itk::CellTraitsInfo::CellFeatureIdentifier
TCellFeatureIdentifier CellFeatureIdentifier
Definition: itkCellInterface.h:543
itk::CellInterface
class ITK_TEMPLATE_EXPORT CellInterface
Definition: itkCellInterfaceVisitor.h:29
itk::CellInterface::CellAutoPointer
SelfAutoPointer CellAutoPointer
Definition: itkCellInterface.h:138
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:174
itk::CellInterface::CellIdentifier
typename CellTraits::CellIdentifier CellIdentifier
Definition: itkCellInterface.h:121
itk::CellInterface::CellConstRawPointer
ConstRawPointer CellConstRawPointer
Definition: itkCellInterface.h:141
itk::CellInterface::GetBoundingBoxDiagonalLength2
CoordinateType GetBoundingBoxDiagonalLength2()
Definition: itkCellInterface.h:396
itk::CellInterface::CellFeatureCount
CellFeatureIdentifier CellFeatureCount
Definition: itkCellInterface.h:144
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::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:119
itk::CellTraitsInfo::PointIdIterator
PointIdentifier * PointIdIterator
Definition: itkCellInterface.h:547
itk::CellInterface::EvaluateShapeFunctions
virtual void EvaluateShapeFunctions(const ParametricCoordArrayType &, ShapeFunctionsArrayType &) const
Definition: itkCellInterface.h:358
itk::Array
Array class with size defined at construction time.
Definition: itkArray.h:47
itk::CellTraitsInfo::InterpolationWeightType
TInterpolationWeight InterpolationWeightType
Definition: itkCellInterface.h:540
itk::CommonEnums::CellGeometry::TETRAHEDRON_CELL
itk::CellInterface::EvaluatePosition
virtual bool EvaluatePosition(CoordinateType *, PointsContainer *, CoordinateType *, CoordinateType[], double *, InterpolationWeightType *)
Definition: itkCellInterface.h:344
itk::CellInterface::CellTraits
TCellTraits CellTraits
Definition: itkCellInterface.h:109
itk::CellInterface::CellFeatureIdentifier
typename CellTraits::CellFeatureIdentifier CellFeatureIdentifier
Definition: itkCellInterface.h:122
itk::CellInterface::IntersectWithLine
virtual bool IntersectWithLine(CoordinateType[PointDimension], CoordinateType[PointDimension], CoordinateType, CoordinateType[PointDimension], CoordinateType *, CoordinateType[])
Definition: itkCellInterface.h:377
itk::CellInterface::CoordinateType
typename CellTraits::CoordinateType CoordinateType
Definition: itkCellInterface.h:112
itkCellInterfaceVisitor.h
itk::CellInterface::MultiVisitor::AddVisitor
void AddVisitor(VisitorType *v)
Definition: itkCellInterface.h:209
itk::CellTraitsInfo::PointIdConstIterator
const PointIdentifier * PointIdConstIterator
Definition: itkCellInterface.h:549
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