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  {
211  const CellGeometryEnum id = v->GetCellTopologyId();
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 *
392  GetBoundingBox(CoordinateType[PointDimension * 2])
393  {
394  return nullptr;
395  }
399  CoordinateType
401  {
402  return CoordinateType{};
403  }
404 
417  virtual bool
419  CoordinateType[PointDimension],
420  CoordinateType[PointDimension],
421  CoordinateType[PointDimension],
422  CoordinateType *)
423  {
424  return bool();
425  }
426 
432  virtual bool
433  IsExplicitBoundary();
434 
439  virtual void
440  AddUsingCell(CellIdentifier cellId);
441 
445  virtual void
446  RemoveUsingCell(CellIdentifier cellId);
447 
453  virtual bool
454  IsUsingCell(CellIdentifier cellId);
455 
459  virtual unsigned int
460  GetNumberOfUsingCells();
461 
462 #if !defined(ITK_WRAPPING_PARSER)
463 
466  virtual UsingCellsContainerIterator
467  UsingCellsBegin();
468 
472  virtual UsingCellsContainerIterator
473  UsingCellsEnd();
474 
475 #endif
476 
478  itkVirtualGetNameOfClassMacro(CellInterface);
479 
480 public:
481  CellInterface() = default;
482  virtual ~CellInterface() = default;
486  // bool GetPointPosition(PointsContainer*, int localId, Point*)=0;
487 
488 #if !defined(ITK_LEGACY_REMOVE)
489 
493  static constexpr CommonEnums::CellGeometry QUADRILATERAL_CELL = CommonEnums::CellGeometry::QUADRILATERAL_CELL;
497  static constexpr CommonEnums::CellGeometry QUADRATIC_EDGE_CELL = CommonEnums::CellGeometry::QUADRATIC_EDGE_CELL;
498  static constexpr CommonEnums::CellGeometry QUADRATIC_TRIANGLE_CELL =
502 #endif
503 
504 protected:
506  UsingCellsContainer m_UsingCells{};
507 };
508 
527 template <int VPointDimension,
528  typename TCoordinate,
529  typename TInterpolationWeight,
530  typename TPointIdentifier,
531  typename TCellIdentifier,
532  typename TCellFeatureIdentifier,
533  typename TPoint,
534  typename TPointsContainer,
535  typename TUsingCellsContainer>
536 class ITK_TEMPLATE_EXPORT CellTraitsInfo
537 {
538 public:
539  static constexpr unsigned int PointDimension = VPointDimension;
540  using CoordinateType = TCoordinate;
541 #ifndef ITK_FUTURE_LEGACY_REMOVE
542  using CoordRepType ITK_FUTURE_DEPRECATED(
543  "ITK 6 discourages using `CoordRepType`. Please use `CoordinateType` instead!") = CoordinateType;
544 #endif
545  using InterpolationWeightType = TInterpolationWeight;
546  using PointIdentifier = TPointIdentifier;
547  using CellIdentifier = TCellIdentifier;
548  using CellFeatureIdentifier = TCellFeatureIdentifier;
549  using PointType = TPoint;
550  using PointsContainer = TPointsContainer;
551  using UsingCellsContainer = TUsingCellsContainer;
553 
555 };
556 
557 #define itkMakeCellTraitsMacro \
558  CellTraitsInfo<Self::PointDimension, \
559  CoordinateType, \
560  InterpolationWeightType, \
561  PointIdentifier, \
562  CellIdentifier, \
563  CellFeatureIdentifier, \
564  PointType, \
565  PointsContainer, \
566  UsingCellsContainer>
567 } // end namespace itk
568 
569 #if !defined(ITK_WRAPPING_PARSER)
570 # ifndef ITK_MANUAL_INSTANTIATION
571 # include "itkCellInterface.hxx"
572 # endif
573 #endif
574 
575 #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:550
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:546
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:536
itk::CellInterface::IntersectBoundingBoxWithLine
virtual bool IntersectBoundingBoxWithLine(CoordinateType[PointDimension *2], CoordinateType[PointDimension], CoordinateType[PointDimension], CoordinateType[PointDimension], CoordinateType *)
Definition: itkCellInterface.h:418
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:549
itk::CellInterface::PointsContainer
typename CellTraits::PointsContainer PointsContainer
Definition: itkCellInterface.h:124
itk::CellTraitsInfo::CoordinateType
TCoordinate CoordinateType
Definition: itkCellInterface.h:540
itk::SmartPointer< Self >
itk::CellInterface::GetBoundingBox
CoordinateType * GetBoundingBox(CoordinateType[PointDimension *2])
Definition: itkCellInterface.h:392
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:547
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:551
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:548
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:234
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:400
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:552
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:545
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:554
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