ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkCellInterface.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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"
22 #include <map>
24 #include "itkAutoPointer.h"
25 #include "itkArray.h"
26 
27 // Define a macro for CellInterface sub-classes to use
28 // to define the Accept and GetTopologyId virtuals used
29 // by the MultiVisitor class
30 #define itkCellVisitMacro(TopologyId) \
31  static int GetTopologyId() \
32  { \
33  return TopologyId; \
34  } \
35  virtual void Accept(CellIdentifier cellid, typename CellInterface< PixelType, \
36  CellTraits >::MultiVisitor * mv) override \
37  { \
38  typename CellInterfaceVisitor< PixelType, CellTraits >::Pointer v = \
39  mv->GetVisitor(TopologyId); \
40  if ( v ) \
41  { \
42  v->VisitFromCell(cellid, this); \
43  } \
44  }
45 
46 // Define a macro for the common type alias required by the
47 // classes deriving form CellInterface (included).
48 #define itkCellCommonTypedefs(celltype) \
49  using Self = celltype; \
50  using ConstSelfAutoPointer = AutoPointer< const Self >; \
51  using SelfAutoPointer = AutoPointer< Self >; \
52  using RawPointer = Self *; \
53  using ConstRawPointer = const Self *
54 
55 // Define a macro for the common type alias required by the
56 // classes deriving form CellInterface (excluded).
57 #define itkCellInheritedTypedefs(superclassArg) \
58  using Superclass = superclassArg; \
59  using PixelType = typename Superclass::PixelType; \
60  using CellType = typename Superclass::CellType; \
61  using CellAutoPointer = typename Superclass::CellAutoPointer; \
62  using CellConstAutoPointer = typename Superclass::CellConstAutoPointer; \
63  using CellRawPointer = typename Superclass::CellRawPointer; \
64  using CellConstRawPointer = typename Superclass::CellConstRawPointer; \
65  using CellTraits = typename Superclass::CellTraits; \
66  using CoordRepType = typename Superclass::CoordRepType; \
67  using InterpolationWeightType = typename Superclass::InterpolationWeightType; \
68  using PointIdentifier = typename Superclass::PointIdentifier; \
69  using PointIdIterator = typename Superclass::PointIdIterator; \
70  using PointIdConstIterator = typename Superclass::PointIdConstIterator; \
71  using CellIdentifier = typename Superclass::CellIdentifier; \
72  using CellFeatureIdentifier = typename Superclass::CellFeatureIdentifier; \
73  using CellFeatureCount = typename Superclass::CellFeatureIdentifier; \
74  using PointType = typename Superclass::PointType; \
75  using VectorType = typename Superclass::VectorType; \
76  using PointsContainer = typename Superclass::PointsContainer; \
77  using UsingCellsContainer = typename Superclass::UsingCellsContainer; \
78  using CellGeometry = typename Superclass::CellGeometry; \
79  using ParametricCoordArrayType = typename Superclass::ParametricCoordArrayType; \
80  using ShapeFunctionsArrayType = typename Superclass::ShapeFunctionsArrayType; \
81  static constexpr unsigned int PointDimension = Superclass::PointDimension
82 
83 namespace itk
84 {
97 template<
98  typename TPixelType,
99  typename TCellTraits
100  >
101 class ITK_TEMPLATE_EXPORT CellInterface
102 {
103 public:
104  ITK_DISALLOW_COPY_AND_ASSIGN(CellInterface);
105 
108 
110  using PixelType = TPixelType;
111 
113  using CellTraits = TCellTraits;
114 
116  using CoordRepType = typename CellTraits::CoordRepType;
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;
124  using PointsContainer = typename CellTraits::PointsContainer;
125  using UsingCellsContainer = typename CellTraits::UsingCellsContainer;
126 
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 
147  enum CellGeometry { VERTEX_CELL = 0, LINE_CELL, TRIANGLE_CELL,
148  QUADRILATERAL_CELL, POLYGON_CELL, TETRAHEDRON_CELL, HEXAHEDRON_CELL,
149  QUADRATIC_EDGE_CELL, QUADRATIC_TRIANGLE_CELL,
150  LAST_ITK_CELL, MAX_ITK_CELLS = 255 };
151 
155 
156 // static int GetNextUserCellId(); // never return > MAX_INTERFACE
157 
167  {
168 public:
172 
176 
178  //itkNewMacro(Self);
179  static Pointer New() { Pointer smartPtr = new Self; smartPtr->UnRegister(); return smartPtr; }
181 
183  itkTypeMacro(MultiVisitor, LightObject);
184 
187  using VisitorPointerValueType = typename std::map< int, VisitorPointer >::value_type;
188 
189 public:
191  {
192  if ( id < LAST_ITK_CELL )
193  {
194  return m_Visitors[id];
195  }
196  else
197  {
198  auto pos = m_UserDefined.find(id);
199  if ( pos != m_UserDefined.end() )
200  {
201  return ( *pos ).second;
202  }
203  }
204  return nullptr;
205  }
206 
208  {
209  int id = v->GetCellTopologyId();
210 
211  if ( id < LAST_ITK_CELL )
212  {
213  m_Visitors[id] = v;
214  }
215  else
216  {
217  m_UserDefined.insert( VisitorPointerValueType(id, v) );
218  }
219  }
220 
221  ~MultiVisitor() override = default;
222 
223 protected:
224  VisitorPointer m_Visitors[LAST_ITK_CELL]; // fixed array set to the
225  // size
226  // from the enum
227  std::map< int, VisitorPointer > m_UserDefined; // user defined cell types
228  // go here
229  };
230 
232  virtual void Accept(CellIdentifier cellId, MultiVisitor *) = 0;
233 
236  virtual CellGeometry GetType() const = 0;
237 
240  virtual void MakeCopy(CellAutoPointer &) const = 0;
241 
243  virtual unsigned int GetDimension() const = 0;
244 
246  virtual unsigned int GetInterpolationOrder() const;
247 
249  virtual unsigned int GetNumberOfPoints() const = 0;
250 
252  virtual CellFeatureCount GetNumberOfBoundaryFeatures(int dimension) const = 0;
253 
255  virtual bool GetBoundaryFeature(int dimension, CellFeatureIdentifier,
256  CellAutoPointer &) = 0;
257 
261  virtual PointIdConstIterator GetPointIds() const;
262 
266  virtual void SetPointIds(PointIdConstIterator first) = 0;
267 
272  virtual void SetPointIds(PointIdConstIterator first,
273  PointIdConstIterator last) = 0;
274 
277  virtual void SetPointId(int localId, PointIdentifier) = 0;
278 
280  virtual PointIdIterator PointIdsBegin() = 0;
281 
284  virtual PointIdConstIterator PointIdsBegin() const = 0;
285 
287  virtual PointIdIterator PointIdsEnd() = 0;
288 
291  virtual PointIdConstIterator PointIdsEnd() const = 0;
292 
295  PointIdentifierContainerType GetPointIdsContainer() const;
296  void SetPointIdsContainer( const PointIdentifierContainerType & );
298 
304  { return false; }
305 
323  PointsContainer *,
324  CoordRepType *,
325  CoordRepType[],
326  double *,
328  { return bool(); }
329 
334  const ParametricCoordArrayType &,
335  ShapeFunctionsArrayType &) const {}
336 
352  virtual bool IntersectWithLine(CoordRepType[PointDimension],
353  CoordRepType[PointDimension],
354  CoordRepType,
355  CoordRepType[PointDimension],
356  CoordRepType *,
357  CoordRepType[]) { return bool(); }
358 
363  CoordRepType * GetBoundingBox(CoordRepType[PointDimension * 2]) { return nullptr; }
365 
368 
381  virtual bool IntersectBoundingBoxWithLine(CoordRepType[PointDimension * 2],
382  CoordRepType[PointDimension],
383  CoordRepType[PointDimension],
384  CoordRepType[PointDimension],
385  CoordRepType *) { return bool(); }
386 
392  virtual bool IsExplicitBoundary();
393 
398  virtual void AddUsingCell(CellIdentifier cellId);
399 
403  virtual void RemoveUsingCell(CellIdentifier cellId);
404 
410  virtual bool IsUsingCell(CellIdentifier cellId);
411 
415  virtual unsigned int GetNumberOfUsingCells();
416 
417 #if !defined( ITK_WRAPPING_PARSER )
418 
421  virtual UsingCellsContainerIterator UsingCellsBegin();
422 
426  virtual UsingCellsContainerIterator UsingCellsEnd();
427 
428 #endif
429 
431  itkTypeMacroNoParent(CellInterface);
432 
433 public:
434  CellInterface() = default;
435  virtual ~CellInterface() = default;
439 // bool GetPointPosition(PointsContainer*, int localId, Point*)=0;
440 
441 protected:
444 };
445 
464 template< int VPointDimension, typename TCoordRep,
465  typename TInterpolationWeight, typename TPointIdentifier,
466  typename TCellIdentifier, typename TCellFeatureIdentifier,
467  typename TPoint, typename TPointsContainer,
468  typename TUsingCellsContainer >
469 class ITK_TEMPLATE_EXPORT CellTraitsInfo
470 {
471 public:
472  static constexpr unsigned int PointDimension = VPointDimension;
473  using CoordRepType = TCoordRep;
474  using InterpolationWeightType = TInterpolationWeight;
475  using PointIdentifier = TPointIdentifier;
476  using CellIdentifier = TCellIdentifier;
477  using CellFeatureIdentifier = TCellFeatureIdentifier;
478  using PointType = TPoint;
479  using PointsContainer = TPointsContainer;
480  using UsingCellsContainer = TUsingCellsContainer;
482 
484 };
485 
486 #define itkMakeCellTraitsMacro \
487  CellTraitsInfo < Self::PointDimension, CoordRepType, \
488  InterpolationWeightType, \
489  PointIdentifier, CellIdentifier, CellFeatureIdentifier, \
490  PointType, PointsContainer, UsingCellsContainer >
491 } // end namespace itk
492 
493 #if !defined( ITK_WRAPPING_PARSER )
494 #ifndef ITK_MANUAL_INSTANTIATION
495 #include "itkCellInterface.hxx"
496 #endif
497 #endif
498 
499 #endif
Array class with size defined at construction time.
Definition: itkArray.h:46
ConstSelfAutoPointer CellConstAutoPointer
void UnRegister() noexcept
Light weight base class for most itk classes.
class ITK_TEMPLATE_EXPORT CellInterface
TPointsContainer PointsContainer
UsingCellsContainer m_UsingCells
virtual void EvaluateShapeFunctions(const ParametricCoordArrayType &, ShapeFunctionsArrayType &) const
Define numeric traits for std::vector.
CoordRepType * GetBoundingBox(CoordRepType[PointDimension *2])
typename CellTraits::PointsContainer PointsContainer
TUsingCellsContainer UsingCellsContainer
SelfAutoPointer CellAutoPointer
TCellIdentifier CellIdentifier
typename CellTraits::PointIdConstIterator PointIdConstIterator
A visitor that can visit different cell types in a mesh. CellInterfaceVisitor instances can be regist...
TInterpolationWeight InterpolationWeightType
An abstract interface for cells.
std::map< int, VisitorPointer > m_UserDefined
typename CellTraits::PointIdIterator PointIdIterator
TCellFeatureIdentifier CellFeatureIdentifier
VisitorType * GetVisitor(int id)
typename CellTraits::PointIdentifier PointIdentifier
Abstract interface for a visitor class that can visit the cells in a Mesh.
typename CellTraits::CellFeatureIdentifier CellFeatureIdentifier
#define itkCellCommonTypedefs(celltype)
virtual bool EvaluatePosition(CoordRepType *, PointsContainer *, CoordRepType *, CoordRepType[], double *, InterpolationWeightType *)
PointIdentifier * PointIdIterator
typename UsingCellsContainer::iterator UsingCellsContainerIterator
typename VisitorType::Pointer VisitorPointer
typename PointType::VectorType VectorType
NOTE: it should normally be defined in the traits.
virtual bool IntersectWithLine(CoordRepType[PointDimension], CoordRepType[PointDimension], CoordRepType, CoordRepType[PointDimension], CoordRepType *, CoordRepType[])
typename CellTraits::UsingCellsContainer UsingCellsContainer
ConstRawPointer CellConstRawPointer
TPointIdentifier PointIdentifier
typename CellTraits::InterpolationWeightType InterpolationWeightType
const PointIdentifier * PointIdConstIterator
typename CellTraits::CoordRepType CoordRepType
A simple utility class to define the cell type inside a mesh type structure definition. This just makes a copy of existing type information that is needed for a cell type template parameter.
CoordRepType GetBoundingBoxDiagonalLength2()
typename CellTraits::CellIdentifier CellIdentifier
CellFeatureIdentifier CellFeatureCount
virtual bool IntersectBoundingBoxWithLine(CoordRepType[PointDimension *2], CoordRepType[PointDimension], CoordRepType[PointDimension], CoordRepType[PointDimension], CoordRepType *)
typename CellTraits::PointType PointType
typename std::map< int, VisitorPointer >::value_type VisitorPointerValueType
virtual bool GetClosestBoundary(CoordRepType[], bool *, CellAutoPointer &)
virtual int GetCellTopologyId()=0