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
81namespace itk
82{
83
96template <typename TPixelType, typename TCellTraits>
97class ITK_TEMPLATE_EXPORT CellInterface
98{
99public:
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
157 {
158 public:
162
166
168 // itkNewMacro(Self);
169 static Pointer
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:
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
232
236 GetType() const = 0;
237
240 virtual void
242
244 virtual unsigned int
245 GetDimension() const = 0;
246
248 virtual unsigned int
250
252 virtual unsigned int
253 GetNumberOfPoints() const = 0;
254
256 virtual CellFeatureCount
257 GetNumberOfBoundaryFeatures(int dimension) const = 0;
258
260 virtual bool
262
267 GetPointIds() const;
268
272 virtual void
274
279 virtual void
281
284 virtual void
285 SetPointId(int localId, PointIdentifier) = 0;
286
288 virtual PointIdIterator
290
294 PointIdsBegin() const = 0;
295
297 virtual PointIdIterator
299
303 PointIdsEnd() const = 0;
304
309 void
317 virtual bool
319 {
320 return false;
321 }
322
339 virtual bool
342 CoordRepType *,
343 CoordRepType[],
344 double *,
346 {
347 return bool();
348 }
349
353 virtual void
355 {}
356
372 virtual bool
374 CoordRepType[PointDimension],
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
425
430 virtual void
432
436 virtual void
438
444 virtual bool
446
450 virtual unsigned int
452
453#if !defined(ITK_WRAPPING_PARSER)
459
465
466#endif
467
469 itkVirtualGetNameOfClassMacro(CellInterface);
470
471public:
472 CellInterface() = default;
473 virtual ~CellInterface() = default;
477 // bool GetPointPosition(PointsContainer*, int localId, Point*)=0;
478
479#if !defined(ITK_LEGACY_REMOVE)
489 static constexpr CommonEnums::CellGeometry QUADRATIC_TRIANGLE_CELL =
493#endif
494
495protected:
497 UsingCellsContainer m_UsingCells{};
498};
499
518template <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>
527class ITK_TEMPLATE_EXPORT CellTraitsInfo
528{
529public:
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
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)
std::map< CellGeometryEnum, VisitorPointer > m_UserDefined
typename std::map< CellGeometryEnum, VisitorPointer >::value_type VisitorPointerValueType
An abstract interface for cells.
virtual itk::CommonEnums::CellGeometry GetType() const =0
virtual unsigned int GetNumberOfPoints() const =0
virtual bool IsUsingCell(CellIdentifier cellId)
virtual void SetPointIds(PointIdConstIterator first)=0
virtual PointIdConstIterator PointIdsBegin() const =0
CoordRepType GetBoundingBoxDiagonalLength2()
typename CellTraits::PointIdentifier PointIdentifier
virtual void SetPointId(int localId, PointIdentifier)=0
virtual ~CellInterface()=default
virtual bool IntersectBoundingBoxWithLine(CoordRepType[PointDimension *2], CoordRepType[PointDimension], CoordRepType[PointDimension], CoordRepType[PointDimension], CoordRepType *)
PointIdentifierContainerType GetPointIdsContainer() const
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
CellFeatureIdentifier CellFeatureCount
typename UsingCellsContainer::iterator UsingCellsContainerIterator
virtual void SetPointIds(PointIdConstIterator first, PointIdConstIterator last)=0
virtual void Accept(CellIdentifier cellId, MultiVisitor *)=0
virtual bool GetClosestBoundary(CoordRepType[], bool *, CellAutoPointer &)
virtual PointIdIterator PointIdsEnd()=0
typename CellTraits::UsingCellsContainer UsingCellsContainer
virtual bool IntersectWithLine(CoordRepType[PointDimension], CoordRepType[PointDimension], CoordRepType, CoordRepType[PointDimension], CoordRepType *, CoordRepType[])
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
virtual bool EvaluatePosition(CoordRepType *, PointsContainer *, CoordRepType *, CoordRepType[], double *, InterpolationWeightType *)
itkCellCommonTypedefs(CellInterface)
virtual unsigned int GetInterpolationOrder() const
CoordRepType * GetBoundingBox(CoordRepType[PointDimension *2])
virtual unsigned int GetNumberOfUsingCells()
CellInterface()=default
virtual void MakeCopy(CellAutoPointer &) const =0
typename CellTraits::CoordRepType CoordRepType
A simple utility class to define the cell type inside a mesh type structure definition....
TPointIdentifier PointIdentifier
PointIdentifier * PointIdIterator
TInterpolationWeight InterpolationWeightType
TUsingCellsContainer UsingCellsContainer
TPointsContainer PointsContainer
TCellFeatureIdentifier CellFeatureIdentifier
const PointIdentifier * PointIdConstIterator
TCellIdentifier CellIdentifier
Light weight base class for most itk classes.
SmartPointer< Self > Pointer
AddImageFilter Self
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
class ITK_TEMPLATE_EXPORT CellInterface