ITK  5.2.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  * 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 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 
44 // Define a macro for the common type alias required by the
45 // classes deriving form CellInterface (included).
46 #define itkCellCommonTypedefs(celltype) \
47  using Self = celltype; \
48  using ConstSelfAutoPointer = AutoPointer<const Self>; \
49  using SelfAutoPointer = AutoPointer<Self>; \
50  using RawPointer = Self *; \
51  using ConstRawPointer = const Self *
52 
53 // Define a macro for the common type alias required by the
54 // classes deriving form CellInterface (excluded).
55 #define itkCellInheritedTypedefs(superclassArg) \
56  using Superclass = superclassArg; \
57  using PixelType = typename Superclass::PixelType; \
58  using CellType = typename Superclass::CellType; \
59  using CellAutoPointer = typename Superclass::CellAutoPointer; \
60  using CellConstAutoPointer = typename Superclass::CellConstAutoPointer; \
61  using CellRawPointer = typename Superclass::CellRawPointer; \
62  using CellConstRawPointer = typename Superclass::CellConstRawPointer; \
63  using CellTraits = typename Superclass::CellTraits; \
64  using CoordRepType = typename Superclass::CoordRepType; \
65  using InterpolationWeightType = typename Superclass::InterpolationWeightType; \
66  using PointIdentifier = typename Superclass::PointIdentifier; \
67  using PointIdIterator = typename Superclass::PointIdIterator; \
68  using PointIdConstIterator = typename Superclass::PointIdConstIterator; \
69  using CellIdentifier = typename Superclass::CellIdentifier; \
70  using CellFeatureIdentifier = typename Superclass::CellFeatureIdentifier; \
71  using CellFeatureCount = typename Superclass::CellFeatureIdentifier; \
72  using PointType = typename Superclass::PointType; \
73  using VectorType = typename Superclass::VectorType; \
74  using PointsContainer = typename Superclass::PointsContainer; \
75  using UsingCellsContainer = typename Superclass::UsingCellsContainer; \
76  using ParametricCoordArrayType = typename Superclass::ParametricCoordArrayType; \
77  using ShapeFunctionsArrayType = typename Superclass::ShapeFunctionsArrayType; \
78  static constexpr unsigned int PointDimension = Superclass::PointDimension
79 
80 namespace itk
81 {
82 
95 template <typename TPixelType, typename TCellTraits>
96 class ITK_TEMPLATE_EXPORT CellInterface
97 {
98 public:
99  ITK_DISALLOW_COPY_AND_ASSIGN(CellInterface);
100 
103 
105  using PixelType = TPixelType;
106 
108  using CellTraits = TCellTraits;
109 
111  using CoordRepType = typename CellTraits::CoordRepType;
112  using InterpolationWeightType = typename CellTraits::InterpolationWeightType;
113  using PointIdentifier = typename CellTraits::PointIdentifier;
114  using PointIdIterator = typename CellTraits::PointIdIterator;
115  using PointIdConstIterator = typename CellTraits::PointIdConstIterator;
116  using CellIdentifier = typename CellTraits::CellIdentifier;
117  using CellFeatureIdentifier = typename CellTraits::CellFeatureIdentifier;
119  using PointsContainer = typename CellTraits::PointsContainer;
120  using UsingCellsContainer = typename CellTraits::UsingCellsContainer;
121 
124 
126  static constexpr unsigned int PointDimension = CellTraits::PointDimension;
127 
129  using UsingCellsContainerIterator = typename UsingCellsContainer::iterator;
130 
133  using CellAutoPointer = SelfAutoPointer;
134  using CellConstAutoPointer = ConstSelfAutoPointer;
135  using CellRawPointer = RawPointer;
136  using CellConstRawPointer = ConstRawPointer;
137 
140 
144 
145  // static int GetNextUserCellId(); // never return > MAX_INTERFACE
146 
155  class MultiVisitor : public LightObject
156  {
157  public:
161 
165 
167  // itkNewMacro(Self);
168  static Pointer
169  New()
170  {
171  Pointer smartPtr = new Self;
172  smartPtr->UnRegister();
173  return smartPtr;
174  }
176 
178  itkTypeMacro(MultiVisitor, LightObject);
179 
182  using VisitorPointerValueType = typename std::map<CellGeometryEnum, VisitorPointer>::value_type;
183 
184  public:
185  VisitorType *
187  {
189  {
190  return m_Visitors[static_cast<int>(id)];
191  }
192  else
193  {
194  auto pos = m_UserDefined.find(id);
195  if (pos != m_UserDefined.end())
196  {
197  return (*pos).second;
198  }
199  }
200  return nullptr;
201  }
202 
203  void
205  {
207 
209  {
210  m_Visitors[static_cast<int>(id)] = v;
211  }
212  else
213  {
214  m_UserDefined.insert(VisitorPointerValueType(id, v));
215  }
216  }
217 
218  ~MultiVisitor() override = default;
219 
220  protected:
221  VisitorPointer m_Visitors[static_cast<int>(CellGeometryEnum::LAST_ITK_CELL)]; // fixed array set to the
222  // size
223  // from the enum
224  std::map<CellGeometryEnum, VisitorPointer> m_UserDefined; // user defined cell types
225  // go here
226  };
227 
229  virtual void
230  Accept(CellIdentifier cellId, MultiVisitor *) = 0;
231 
234  virtual ::itk::CommonEnums::CellGeometry
235  GetType() const = 0;
236 
239  virtual void
240  MakeCopy(CellAutoPointer &) const = 0;
241 
243  virtual unsigned int
244  GetDimension() const = 0;
245 
247  virtual unsigned int
248  GetInterpolationOrder() const;
249 
251  virtual unsigned int
252  GetNumberOfPoints() const = 0;
253 
255  virtual CellFeatureCount
256  GetNumberOfBoundaryFeatures(int dimension) const = 0;
257 
259  virtual bool
260  GetBoundaryFeature(int dimension, CellFeatureIdentifier, CellAutoPointer &) = 0;
261 
265  virtual PointIdConstIterator
266  GetPointIds() const;
267 
271  virtual void
272  SetPointIds(PointIdConstIterator first) = 0;
273 
278  virtual void
279  SetPointIds(PointIdConstIterator first, PointIdConstIterator last) = 0;
280 
283  virtual void
284  SetPointId(int localId, PointIdentifier) = 0;
285 
287  virtual PointIdIterator
288  PointIdsBegin() = 0;
289 
292  virtual PointIdConstIterator
293  PointIdsBegin() const = 0;
294 
296  virtual PointIdIterator
297  PointIdsEnd() = 0;
298 
301  virtual PointIdConstIterator
302  PointIdsEnd() const = 0;
303 
307  GetPointIdsContainer() const;
308  void
309  SetPointIdsContainer(const PointIdentifierContainerType &);
311 
316  virtual bool
318  {
319  return false;
320  }
321 
338  virtual bool
340  PointsContainer *,
341  CoordRepType *,
342  CoordRepType[],
343  double *,
345  {
346  return bool();
347  }
348 
352  virtual void
354  {}
355 
371  virtual bool
373  CoordRepType[PointDimension],
374  CoordRepType,
375  CoordRepType[PointDimension],
376  CoordRepType *,
377  CoordRepType[])
378  {
379  return bool();
380  }
381 
386  CoordRepType * GetBoundingBox(CoordRepType[PointDimension * 2]) { return nullptr; }
388 
390  CoordRepType
392  {
394  }
395 
408  virtual bool IntersectBoundingBoxWithLine(CoordRepType[PointDimension * 2],
409  CoordRepType[PointDimension],
410  CoordRepType[PointDimension],
411  CoordRepType[PointDimension],
412  CoordRepType *)
413  {
414  return bool();
415  }
416 
422  virtual bool
423  IsExplicitBoundary();
424 
429  virtual void
430  AddUsingCell(CellIdentifier cellId);
431 
435  virtual void
436  RemoveUsingCell(CellIdentifier cellId);
437 
443  virtual bool
444  IsUsingCell(CellIdentifier cellId);
445 
449  virtual unsigned int
450  GetNumberOfUsingCells();
451 
452 #if !defined(ITK_WRAPPING_PARSER)
453 
456  virtual UsingCellsContainerIterator
457  UsingCellsBegin();
458 
462  virtual UsingCellsContainerIterator
463  UsingCellsEnd();
464 
465 #endif
466 
468  itkTypeMacroNoParent(CellInterface);
469 
470 public:
471  CellInterface() = default;
472  virtual ~CellInterface() = default;
476  // bool GetPointPosition(PointsContainer*, int localId, Point*)=0;
477 
478 #if !defined(ITK_LEGACY_REMOVE)
479 
483  constexpr static CommonEnums::CellGeometry QUADRILATERAL_CELL = CommonEnums::CellGeometry::QUADRILATERAL_CELL;
487  constexpr static CommonEnums::CellGeometry QUADRATIC_EDGE_CELL = CommonEnums::CellGeometry::QUADRATIC_EDGE_CELL;
488  constexpr static CommonEnums::CellGeometry QUADRATIC_TRIANGLE_CELL =
492 #endif
493 
494 protected:
497 };
498 
517 template <int VPointDimension,
518  typename TCoordRep,
519  typename TInterpolationWeight,
520  typename TPointIdentifier,
521  typename TCellIdentifier,
522  typename TCellFeatureIdentifier,
523  typename TPoint,
524  typename TPointsContainer,
525  typename TUsingCellsContainer>
526 class ITK_TEMPLATE_EXPORT CellTraitsInfo
527 {
528 public:
529  static constexpr unsigned int PointDimension = VPointDimension;
530  using CoordRepType = TCoordRep;
531  using InterpolationWeightType = TInterpolationWeight;
532  using PointIdentifier = TPointIdentifier;
533  using CellIdentifier = TCellIdentifier;
534  using CellFeatureIdentifier = TCellFeatureIdentifier;
535  using PointType = TPoint;
536  using PointsContainer = TPointsContainer;
537  using UsingCellsContainer = TUsingCellsContainer;
539 
541 };
542 
543 #define itkMakeCellTraitsMacro \
544  CellTraitsInfo<Self::PointDimension, \
545  CoordRepType, \
546  InterpolationWeightType, \
547  PointIdentifier, \
548  CellIdentifier, \
549  CellFeatureIdentifier, \
550  PointType, \
551  PointsContainer, \
552  UsingCellsContainer>
553 } // end namespace itk
554 
555 #if !defined(ITK_WRAPPING_PARSER)
556 # ifndef ITK_MANUAL_INSTANTIATION
557 # include "itkCellInterface.hxx"
558 # endif
559 #endif
560 
561 #endif
itk::CellTraitsInfo::PointsContainer
TPointsContainer PointsContainer
Definition: itkCellInterface.h:536
itk::CellTraitsInfo::PointType
TPoint PointType
Definition: itkCellInterface.h:535
itk::CellInterface::GetClosestBoundary
virtual bool GetClosestBoundary(CoordRepType[], bool *, CellAutoPointer &)
Definition: itkCellInterface.h:317
itk::CellInterface::MultiVisitor::VisitorPointerValueType
typename std::map< CellGeometryEnum, VisitorPointer >::value_type VisitorPointerValueType
Definition: itkCellInterface.h:182
itk::CellInterface::MultiVisitor::m_UserDefined
std::map< CellGeometryEnum, VisitorPointer > m_UserDefined
Definition: itkCellInterface.h:224
itk::CellInterface::VectorType
typename PointType::VectorType VectorType
NOTE: it should normally be defined in the traits.
Definition: itkCellInterface.h:123
itk::CommonEnums::CellGeometry::MAX_ITK_CELLS
itk::CellInterface::PointIdentifier
typename CellTraits::PointIdentifier PointIdentifier
Definition: itkCellInterface.h:113
itk::CellInterface::IntersectWithLine
virtual bool IntersectWithLine(CoordRepType[PointDimension], CoordRepType[PointDimension], CoordRepType, CoordRepType[PointDimension], CoordRepType *, CoordRepType[])
Definition: itkCellInterface.h:372
itk::CellInterface::UsingCellsContainer
typename CellTraits::UsingCellsContainer UsingCellsContainer
Definition: itkCellInterface.h:120
itk::CommonEnums::CellGeometry::LINE_CELL
itk::CommonEnums::CellGeometry::VERTEX_CELL
itk::CellInterface::MultiVisitor::VisitorPointer
typename VisitorType::Pointer VisitorPointer
Definition: itkCellInterface.h:181
itkAutoPointer.h
itk::CommonEnums::CellGeometry::TRIANGLE_CELL
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:526
itk::CellInterface::InterpolationWeightType
typename CellTraits::InterpolationWeightType InterpolationWeightType
Definition: itkCellInterface.h:112
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:540
itk::CellInterface::PointsContainer
typename CellTraits::PointsContainer PointsContainer
Definition: itkCellInterface.h:119
itk::CommonEnums::CellGeometry::QUADRATIC_TRIANGLE_CELL
itk::SmartPointer< Self >
itk::CommonEnums::CellGeometry::HEXAHEDRON_CELL
itk::CellInterface::PointType
typename CellTraits::PointType PointType
Definition: itkCellInterface.h:118
itk::CellInterface::CellConstAutoPointer
ConstSelfAutoPointer CellConstAutoPointer
Definition: itkCellInterface.h:134
itk::CellInterface::CoordRepType
typename CellTraits::CoordRepType CoordRepType
Definition: itkCellInterface.h:111
itk::CellInterface::MultiVisitor
A visitor that can visit different cell types in a mesh. CellInterfaceVisitor instances can be regist...
Definition: itkCellInterface.h:155
itk::CellInterface::PointIdConstIterator
typename CellTraits::PointIdConstIterator PointIdConstIterator
Definition: itkCellInterface.h:115
itk::CellTraitsInfo::CellIdentifier
TCellIdentifier CellIdentifier
Definition: itkCellInterface.h:533
itk::CellTraitsInfo::PointIdIterator
PointIdentifier * PointIdIterator
Definition: itkCellInterface.h:538
itk::CellInterface::MultiVisitor::GetVisitor
VisitorType * GetVisitor(CellGeometryEnum id)
Definition: itkCellInterface.h:186
itk::CellInterface::UsingCellsContainerIterator
typename UsingCellsContainer::iterator UsingCellsContainerIterator
Definition: itkCellInterface.h:129
itk::CellInterface::PixelType
TPixelType PixelType
Definition: itkCellInterface.h:105
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::CommonEnums::CellGeometry::QUADRATIC_EDGE_CELL
itk::CellInterface::CellRawPointer
RawPointer CellRawPointer
Definition: itkCellInterface.h:135
itk::CellInterface::GetBoundingBox
CoordRepType * GetBoundingBox(CoordRepType[PointDimension *2])
Definition: itkCellInterface.h:386
itk::CellTraitsInfo::UsingCellsContainer
TUsingCellsContainer UsingCellsContainer
Definition: itkCellInterface.h:537
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:339
itk::CellInterface::CellAutoPointer
SelfAutoPointer CellAutoPointer
Definition: itkCellInterface.h:133
itk::SmartPointer::UnRegister
void UnRegister() noexcept
Definition: itkSmartPointer.h:220
itk::CellInterface::MultiVisitor::New
static Pointer New()
Definition: itkCellInterface.h:169
itk::CellInterface::CellIdentifier
typename CellTraits::CellIdentifier CellIdentifier
Definition: itkCellInterface.h:116
itk::CommonEnums::CellGeometry
CellGeometry
Definition: itkCommonEnums.h:138
itk::CellInterface::CellConstRawPointer
ConstRawPointer CellConstRawPointer
Definition: itkCellInterface.h:136
itk::CellInterface::CellFeatureCount
CellFeatureIdentifier CellFeatureCount
Definition: itkCellInterface.h:139
itkArray.h
itkObject.h
itk::CellInterface
An abstract interface for cells.
Definition: itkCellInterface.h:96
itk::NumericTraits::ZeroValue
static T ZeroValue()
Definition: itkNumericTraits.h:148
itk::CellInterface::GetBoundingBoxDiagonalLength2
CoordRepType GetBoundingBoxDiagonalLength2()
Definition: itkCellInterface.h:391
itk::CommonEnums::CellGeometry::TETRAHEDRON_CELL
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itkCommonEnums.h
itk::CellInterface::PointIdIterator
typename CellTraits::PointIdIterator PointIdIterator
Definition: itkCellInterface.h:114
itk::CellInterface::EvaluateShapeFunctions
virtual void EvaluateShapeFunctions(const ParametricCoordArrayType &, ShapeFunctionsArrayType &) const
Definition: itkCellInterface.h:353
itk::Array
Array class with size defined at construction time.
Definition: itkArray.h:47
itk::CellTraitsInfo::InterpolationWeightType
TInterpolationWeight InterpolationWeightType
Definition: itkCellInterface.h:531
itk::CellInterface::CellTraits
TCellTraits CellTraits
Definition: itkCellInterface.h:108
itk::CellInterface::CellFeatureIdentifier
typename CellTraits::CellFeatureIdentifier CellFeatureIdentifier
Definition: itkCellInterface.h:117
itk::CellTraitsInfo::CoordRepType
TCoordRep CoordRepType
Definition: itkCellInterface.h:530
itk::CellTraitsInfo::CellFeatureIdentifier
TCellFeatureIdentifier CellFeatureIdentifier
Definition: itkCellInterface.h:534
itkCellInterfaceVisitor.h
itk::CommonEnums::CellGeometry::POLYGON_CELL
itk::CellInterface::m_UsingCells
UsingCellsContainer m_UsingCells
Definition: itkCellInterface.h:496
itk::CellInterface::MultiVisitor::AddVisitor
void AddVisitor(VisitorType *v)
Definition: itkCellInterface.h:204
itk::CellTraitsInfo::PointIdentifier
TPointIdentifier PointIdentifier
Definition: itkCellInterface.h:532
itk::CellInterfaceVisitor::GetCellTopologyId
virtual CellGeometryEnum GetCellTopologyId()=0
itkCellCommonTypedefs
#define itkCellCommonTypedefs(celltype)
Definition: itkCellInterface.h:46
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:408
itk::CommonEnums::CellGeometry::QUADRILATERAL_CELL