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 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
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 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;
123 using PointType = typename CellTraits::PointType;
124 using PointsContainer = typename CellTraits::PointsContainer;
125 using UsingCellsContainer = typename CellTraits::UsingCellsContainer;
126
128 using VectorType = typename PointType::VectorType;
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
161 {
162 public:
166
170
172 // itkNewMacro(Self);
173 static Pointer
175 {
176 Pointer smartPtr = new Self;
177 smartPtr->UnRegister();
178 return smartPtr;
179 }
180
181
183 itkOverrideGetNameOfClassMacro(MultiVisitor);
184
187 using VisitorPointerValueType = typename std::map<CellGeometryEnum, VisitorPointer>::value_type;
188
189 public:
192 {
193 if (id < CellGeometryEnum::LAST_ITK_CELL)
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
213 if (id < CellGeometryEnum::LAST_ITK_CELL)
214 {
215 m_Visitors[static_cast<int>(id)] = v;
216 }
217 else
218 {
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
246
248 virtual unsigned int
249 GetDimension() const = 0;
250
252 virtual unsigned int
254
256 virtual unsigned int
257 GetNumberOfPoints() const = 0;
258
260 virtual CellFeatureCount
261 GetNumberOfBoundaryFeatures(int dimension) const = 0;
262
264 virtual bool
266
271 GetPointIds() const;
272
276 virtual void
278
283 virtual void
285
288 virtual void
289 SetPointId(int localId, PointIdentifier) = 0;
290
292 virtual PointIdIterator
294
298 PointIdsBegin() const = 0;
299
301 virtual PointIdIterator
303
307 PointIdsEnd() const = 0;
308
313 void
316
321 virtual bool
323 {
324 return false;
325 }
326
343 virtual bool
348 double *,
350 {
351 return bool();
352 }
353
357 virtual void
360
376 virtual bool
386
391 CoordinateType *
393 {
394 return nullptr;
395 }
396
397
399 CoordinateType
404
417 virtual bool
426
429
432 virtual bool
434
439 virtual void
441
445 virtual void
447
453 virtual bool
455
459 virtual unsigned int
461
462#if !defined(ITK_WRAPPING_PARSER)
468
474
475#endif
476
478 itkVirtualGetNameOfClassMacro(CellInterface);
479
480public:
481 CellInterface() = default;
482 virtual ~CellInterface() = default;
484
486 // bool GetPointPosition(PointsContainer*, int localId, Point*)=0;
487
488#if !defined(ITK_LEGACY_REMOVE)
498 static constexpr CommonEnums::CellGeometry QUADRATIC_TRIANGLE_CELL =
502#endif
503
504protected:
507};
508
527template <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>
536class ITK_TEMPLATE_EXPORT CellTraitsInfo
537{
538public:
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
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.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
CommonEnums::CellGeometry CellGeometryEnum