ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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 void Accept(CellIdentifier cellid, typename CellInterface<PixelType, CellTraits>::MultiVisitor * mv) override \
35 { \
36 typename CellInterfaceVisitor<PixelType, CellTraits>::Pointer v = mv->GetVisitor(TopologyId); \
37 if (v) \
38 { \
39 v->VisitFromCell(cellid, this); \
40 } \
41 } \
42 ITK_MACROEND_NOOP_STATEMENT
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 typename Superclass::PixelType; \
58 using CellType = typename Superclass::CellType; \
59 using typename Superclass::CellAutoPointer; \
60 using typename Superclass::CellConstAutoPointer; \
61 using typename Superclass::CellRawPointer; \
62 using typename Superclass::CellConstRawPointer; \
63 using typename Superclass::CellTraits; \
64 using typename Superclass::CoordinateType; \
65 using typename Superclass::InterpolationWeightType; \
66 using typename Superclass::PointIdentifier; \
67 using typename Superclass::PointIdIterator; \
68 using typename Superclass::PointIdConstIterator; \
69 using typename Superclass::CellIdentifier; \
70 using typename Superclass::CellFeatureIdentifier; \
71 using CellFeatureCount = typename Superclass::CellFeatureIdentifier; \
72 using typename Superclass::PointType; \
73 using typename Superclass::VectorType; \
74 using typename Superclass::PointsContainer; \
75 using typename Superclass::UsingCellsContainer; \
76 using typename Superclass::ParametricCoordArrayType; \
77 using typename Superclass::ShapeFunctionsArrayType; \
78 static constexpr unsigned int PointDimension = Superclass::PointDimension
79
80namespace itk
81{
82
95template <typename TPixelType, typename TCellTraits>
96class ITK_TEMPLATE_EXPORT CellInterface
97{
98public:
99 ITK_DISALLOW_COPY_AND_MOVE(CellInterface);
100
103
105 using PixelType = TPixelType;
106
108 using CellTraits = TCellTraits;
109
111 using CoordinateType = typename CellTraits::CoordinateType;
112#ifndef ITK_FUTURE_LEGACY_REMOVE
113 using CoordRepType ITK_FUTURE_DEPRECATED(
114 "ITK 6 discourages using `CoordRepType`. Please use `CoordinateType` instead!") = CoordinateType;
115#endif
116 using InterpolationWeightType = typename CellTraits::InterpolationWeightType;
117 using PointIdentifier = typename CellTraits::PointIdentifier;
118 using PointIdIterator = typename CellTraits::PointIdIterator;
119 using PointIdConstIterator = typename CellTraits::PointIdConstIterator;
120 using CellIdentifier = typename CellTraits::CellIdentifier;
121 using CellFeatureIdentifier = typename CellTraits::CellFeatureIdentifier;
122 using PointType = typename CellTraits::PointType;
123 using PointsContainer = typename CellTraits::PointsContainer;
124 using UsingCellsContainer = typename CellTraits::UsingCellsContainer;
125
127 using VectorType = typename PointType::VectorType;
128
130 static constexpr unsigned int PointDimension = CellTraits::PointDimension;
131
133 using UsingCellsContainerIterator = typename UsingCellsContainer::iterator;
134
137 using CellAutoPointer = SelfAutoPointer;
138 using CellConstAutoPointer = ConstSelfAutoPointer;
139 using CellRawPointer = RawPointer;
140 using CellConstRawPointer = ConstRawPointer;
141
144
148
149 // static int GetNextUserCellId(); // never return > MAX_INTERFACE
150
160 {
161 public:
165
169
171 // itkNewMacro(Self);
172 static Pointer
174 {
175 Pointer smartPtr = new Self;
176 smartPtr->UnRegister();
177 return smartPtr;
178 }
179
181 itkOverrideGetNameOfClassMacro(MultiVisitor);
182
185 using VisitorPointerValueType = typename std::map<CellGeometryEnum, VisitorPointer>::value_type;
186
187 public:
190 {
191 if (id < CellGeometryEnum::LAST_ITK_CELL)
192 {
193 return m_Visitors[static_cast<int>(id)];
194 }
195 else
196 {
197 auto pos = m_UserDefined.find(id);
198 if (pos != m_UserDefined.end())
199 {
200 return pos->second;
201 }
202 }
203 return nullptr;
204 }
205
206 void
208 {
209 const CellGeometryEnum id = v->GetCellTopologyId();
210
211 if (id < CellGeometryEnum::LAST_ITK_CELL)
212 {
213 m_Visitors[static_cast<int>(id)] = v;
214 }
215 else
216 {
218 }
219 }
220
221 ~MultiVisitor() override = default;
222
223 protected:
224 VisitorPointer m_Visitors[static_cast<int>(CellGeometryEnum::LAST_ITK_CELL)]; // fixed array set to the
225 // size
226 // from the enum
227 std::map<CellGeometryEnum, VisitorPointer> m_UserDefined; // user defined cell types
228 // go here
229 };
230
232 virtual void
233 Accept(CellIdentifier cellId, MultiVisitor *) = 0;
234
237 [[nodiscard]] virtual itk::CommonEnums::CellGeometry
238 GetType() const = 0;
239
242 virtual void
244
246 [[nodiscard]] virtual unsigned int
247 GetDimension() const = 0;
248
250 [[nodiscard]] virtual unsigned int
252
254 [[nodiscard]] virtual unsigned int
255 GetNumberOfPoints() const = 0;
256
258 [[nodiscard]] virtual CellFeatureCount
259 GetNumberOfBoundaryFeatures(int dimension) const = 0;
260
262 virtual bool
264
268 [[nodiscard]] virtual PointIdConstIterator
269 GetPointIds() const;
270
274 virtual void
276
281 virtual void
283
286 virtual void
287 SetPointId(int localId, PointIdentifier) = 0;
288
290 virtual PointIdIterator
292
295 [[nodiscard]] virtual PointIdConstIterator
296 PointIdsBegin() const = 0;
297
299 virtual PointIdIterator
301
304 [[nodiscard]] virtual PointIdConstIterator
305 PointIdsEnd() const = 0;
306
310 [[nodiscard]] PointIdentifierContainerType
312 void
319 virtual bool
321 {
322 return false;
323 }
324
341 virtual bool
346 double *,
348 {
349 return bool();
350 }
351
355 virtual void
358
374 virtual bool
384
389 CoordinateType *
391 {
392 return nullptr;
393 }
394
396 CoordinateType
401
414 virtual bool
423
426
429 virtual bool
431
436 virtual void
438
442 virtual void
444
450 virtual bool
452
456 virtual unsigned int
458
459#if !defined(ITK_WRAPPING_PARSER)
465
471
472#endif
473
475 itkVirtualGetNameOfClassMacro(CellInterface);
476
477public:
478 CellInterface() = default;
479 virtual ~CellInterface() = default;
481
483 // bool GetPointPosition(PointsContainer*, int localId, Point*)=0;
484
485#if !defined(ITK_LEGACY_REMOVE)
495 static constexpr CommonEnums::CellGeometry QUADRATIC_TRIANGLE_CELL =
499#endif
500
501protected:
504};
505
524template <int VPointDimension,
525 typename TCoordinate,
526 typename TInterpolationWeight,
527 typename TPointIdentifier,
528 typename TCellIdentifier,
529 typename TCellFeatureIdentifier,
530 typename TPoint,
531 typename TPointsContainer,
532 typename TUsingCellsContainer>
533class ITK_TEMPLATE_EXPORT CellTraitsInfo
534{
535public:
536 static constexpr unsigned int PointDimension = VPointDimension;
537 using CoordinateType = TCoordinate;
538#ifndef ITK_FUTURE_LEGACY_REMOVE
539 using CoordRepType ITK_FUTURE_DEPRECATED(
540 "ITK 6 discourages using `CoordRepType`. Please use `CoordinateType` instead!") = CoordinateType;
541#endif
542 using InterpolationWeightType = TInterpolationWeight;
543 using PointIdentifier = TPointIdentifier;
544 using CellIdentifier = TCellIdentifier;
545 using CellFeatureIdentifier = TCellFeatureIdentifier;
546 using PointType = TPoint;
547 using PointsContainer = TPointsContainer;
548 using UsingCellsContainer = TUsingCellsContainer;
550
552};
553
554#define itkMakeCellTraitsMacro \
555 CellTraitsInfo<Self::PointDimension, \
556 CoordinateType, \
557 InterpolationWeightType, \
558 PointIdentifier, \
559 CellIdentifier, \
560 CellFeatureIdentifier, \
561 PointType, \
562 PointsContainer, \
563 UsingCellsContainer>
564} // end namespace itk
565
566#if !defined(ITK_WRAPPING_PARSER)
567# ifndef ITK_MANUAL_INSTANTIATION
568# include "itkCellInterface.hxx"
569# endif
570#endif
571
572#endif
Array class with size defined at construction time.
Definition itkArray.h:48
Abstract interface for a visitor class that can visit the cells in a Mesh.
virtual CellGeometryEnum GetCellTopologyId()=0
A visitor that can visit different cell types in a mesh. CellInterfaceVisitor instances can be regist...
~MultiVisitor() override=default
typename VisitorType::Pointer VisitorPointer
VisitorType * GetVisitor(CellGeometryEnum id)
VisitorPointer m_Visitors[static_cast< int >(CellGeometryEnum::LAST_ITK_CELL)]
std::map< CellGeometryEnum, VisitorPointer > m_UserDefined
CellInterfaceVisitor< TPixelType, TCellTraits > VisitorType
typename std::map< CellGeometryEnum, VisitorPointer >::value_type VisitorPointerValueType
virtual itk::CommonEnums::CellGeometry GetType() const =0
typename CellTraits::CoordinateType CoordinateType
virtual unsigned int GetNumberOfPoints() const =0
virtual bool IsUsingCell(CellIdentifier cellId)
virtual void SetPointIds(PointIdConstIterator first)=0
virtual PointIdConstIterator PointIdsBegin() const =0
virtual bool IntersectWithLine(CoordinateType[PointDimension], CoordinateType[PointDimension], CoordinateType, CoordinateType[PointDimension], CoordinateType *, CoordinateType[])
typename CellTraits::PointIdentifier PointIdentifier
virtual void SetPointId(int localId, PointIdentifier)=0
virtual ~CellInterface()=default
PointIdentifierContainerType GetPointIdsContainer() const
Array< CoordinateType > ParametricCoordArrayType
virtual PointIdIterator PointIdsBegin()=0
virtual bool GetBoundaryFeature(int dimension, CellFeatureIdentifier, CellAutoPointer &)=0
typename CellTraits::PointIdConstIterator PointIdConstIterator
virtual CellFeatureCount GetNumberOfBoundaryFeatures(int dimension) const =0
virtual void RemoveUsingCell(CellIdentifier cellId)
typename CellTraits::InterpolationWeightType InterpolationWeightType
typename CellTraits::PointsContainer PointsContainer
ConstSelfAutoPointer CellConstAutoPointer
virtual void AddUsingCell(CellIdentifier cellId)
virtual UsingCellsContainerIterator UsingCellsEnd()
virtual PointIdConstIterator GetPointIds() const
virtual bool IsExplicitBoundary()
void SetPointIdsContainer(const PointIdentifierContainerType &)
SelfAutoPointer CellAutoPointer
ConstRawPointer CellConstRawPointer
typename PointType::VectorType VectorType
NOTE: it should normally be defined in the traits.
virtual void EvaluateShapeFunctions(const ParametricCoordArrayType &, ShapeFunctionsArrayType &) const
virtual bool GetClosestBoundary(CoordinateType[], bool *, CellAutoPointer &)
CellFeatureIdentifier CellFeatureCount
typename UsingCellsContainer::iterator UsingCellsContainerIterator
virtual void SetPointIds(PointIdConstIterator first, PointIdConstIterator last)=0
virtual void Accept(CellIdentifier cellId, MultiVisitor *)=0
virtual bool EvaluatePosition(CoordinateType *, PointsContainer *, CoordinateType *, CoordinateType[], double *, InterpolationWeightType *)
virtual PointIdIterator PointIdsEnd()=0
virtual bool IntersectBoundingBoxWithLine(CoordinateType[PointDimension *2], CoordinateType[PointDimension], CoordinateType[PointDimension], CoordinateType[PointDimension], CoordinateType *)
typename CellTraits::UsingCellsContainer UsingCellsContainer
Array< InterpolationWeightType > ShapeFunctionsArrayType
virtual unsigned int GetDimension() const =0
virtual PointIdConstIterator PointIdsEnd() const =0
typename CellTraits::PointIdIterator PointIdIterator
virtual UsingCellsContainerIterator UsingCellsBegin()
typename CellTraits::CellIdentifier CellIdentifier
typename CellTraits::PointType PointType
typename CellTraits::CellFeatureIdentifier CellFeatureIdentifier
itkCellCommonTypedefs(CellInterface)
virtual unsigned int GetInterpolationOrder() const
virtual unsigned int GetNumberOfUsingCells()
CellInterface()=default
itk::Array< PointIdentifier > PointIdentifierContainerType
virtual void MakeCopy(CellAutoPointer &) const =0
CoordinateType GetBoundingBoxDiagonalLength2()
CoordinateType * GetBoundingBox(CoordinateType[PointDimension *2])
A simple utility class to define the cell type inside a mesh type structure definition....
TCellFeatureIdentifier CellFeatureIdentifier
TPointsContainer PointsContainer
const PointIdentifier * PointIdConstIterator
TCellIdentifier CellIdentifier
TPointIdentifier PointIdentifier
TInterpolationWeight InterpolationWeightType
TUsingCellsContainer UsingCellsContainer
PointIdentifier * PointIdIterator
static constexpr unsigned int PointDimension
Implements transparent reference counting.
void UnRegister() noexcept
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
CommonEnums::CellGeometry CellGeometryEnum