ITK  5.4.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
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::CoordRepType; \
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 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
156 {
157 public:
161
165
167 // itkNewMacro(Self);
168 static Pointer
170 {
171 Pointer smartPtr = new Self;
172 smartPtr->UnRegister();
173 return smartPtr;
174 }
178 itkOverrideGetNameOfClassMacro(MultiVisitor);
179
182 using VisitorPointerValueType = typename std::map<CellGeometryEnum, VisitorPointer>::value_type;
183
184 public:
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
231
235 GetType() const = 0;
236
239 virtual void
241
243 virtual unsigned int
244 GetDimension() const = 0;
245
247 virtual unsigned int
249
251 virtual unsigned int
252 GetNumberOfPoints() const = 0;
253
255 virtual CellFeatureCount
256 GetNumberOfBoundaryFeatures(int dimension) const = 0;
257
259 virtual bool
261
266 GetPointIds() const;
267
271 virtual void
273
278 virtual void
280
283 virtual void
284 SetPointId(int localId, PointIdentifier) = 0;
285
287 virtual PointIdIterator
289
293 PointIdsBegin() const = 0;
294
296 virtual PointIdIterator
298
302 PointIdsEnd() const = 0;
303
308 void
316 virtual bool
318 {
319 return false;
320 }
321
338 virtual bool
341 CoordRepType *,
342 CoordRepType[],
343 double *,
345 {
346 return bool();
347 }
348
352 virtual void
354 {}
355
371 virtual bool
373 CoordRepType[PointDimension],
375 CoordRepType[PointDimension],
376 CoordRepType *,
377 CoordRepType[])
378 {
379 return bool();
380 }
381
386 CoordRepType * GetBoundingBox(CoordRepType[PointDimension * 2]) { return nullptr; }
390 CoordRepType
392 {
393 return CoordRepType{};
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
424
429 virtual void
431
435 virtual void
437
443 virtual bool
445
449 virtual unsigned int
451
452#if !defined(ITK_WRAPPING_PARSER)
458
464
465#endif
466
468 itkVirtualGetNameOfClassMacro(CellInterface);
469
470public:
471 CellInterface() = default;
472 virtual ~CellInterface() = default;
476 // bool GetPointPosition(PointsContainer*, int localId, Point*)=0;
477
478#if !defined(ITK_LEGACY_REMOVE)
488 static constexpr CommonEnums::CellGeometry QUADRATIC_TRIANGLE_CELL =
492#endif
493
494protected:
496 UsingCellsContainer m_UsingCells{};
497};
498
517template <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>
526class ITK_TEMPLATE_EXPORT CellTraitsInfo
527{
528public:
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
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