ITK  4.13.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) ITK_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 typedefs required by the
47 // classes deriving form CellInterface (included).
48 #define itkCellCommonTypedefs(celltype) \
49  typedef celltype Self; \
50  typedef AutoPointer< const Self > ConstSelfAutoPointer; \
51  typedef AutoPointer< Self > SelfAutoPointer; \
52  typedef Self * RawPointer; \
53  typedef const Self *ConstRawPointer
54 
55 // Define a macro for the common typedefs required by the
56 // classes deriving form CellInterface (excluded).
57 #define itkCellInheritedTypedefs(superclassArg) \
58  typedef superclassArg Superclass; \
59  typedef typename Superclass::PixelType PixelType; \
60  typedef typename Superclass::CellType CellType; \
61  typedef typename Superclass::CellAutoPointer CellAutoPointer; \
62  typedef typename Superclass::CellConstAutoPointer CellConstAutoPointer; \
63  typedef typename Superclass::CellRawPointer CellRawPointer; \
64  typedef typename Superclass::CellConstRawPointer CellConstRawPointer; \
65  typedef typename Superclass::CellTraits CellTraits; \
66  typedef typename Superclass::CoordRepType CoordRepType; \
67  typedef typename Superclass::InterpolationWeightType \
68  InterpolationWeightType; \
69  typedef typename Superclass::PointIdentifier PointIdentifier; \
70  typedef typename Superclass::PointIdIterator PointIdIterator; \
71  typedef typename Superclass::PointIdConstIterator PointIdConstIterator; \
72  typedef typename Superclass::CellIdentifier CellIdentifier; \
73  typedef typename Superclass::CellFeatureIdentifier CellFeatureIdentifier; \
74  typedef typename Superclass::CellFeatureIdentifier CellFeatureCount; \
75  typedef typename Superclass::PointType PointType; \
76  typedef typename Superclass::VectorType VectorType; \
77  typedef typename Superclass::PointsContainer PointsContainer; \
78  typedef typename Superclass::UsingCellsContainer UsingCellsContainer; \
79  typedef typename Superclass::CellGeometry CellGeometry; \
80  typedef typename Superclass::ParametricCoordArrayType \
81  ParametricCoordArrayType; \
82  typedef typename Superclass::ShapeFunctionsArrayType \
83  ShapeFunctionsArrayType; \
84  itkStaticConstMacro(PointDimension, unsigned int, Superclass::PointDimension)
85 
86 namespace itk
87 {
100 template<
101  typename TPixelType,
102  typename TCellTraits
103  >
104 class ITK_TEMPLATE_EXPORT CellInterface
105 {
106 public:
107 
110 
112  typedef TPixelType PixelType;
113 
115  typedef TCellTraits CellTraits;
116 
118  typedef typename CellTraits::CoordRepType CoordRepType;
119  typedef typename CellTraits::InterpolationWeightType InterpolationWeightType;
120  typedef typename CellTraits::PointIdentifier PointIdentifier;
121  typedef typename CellTraits::PointIdIterator PointIdIterator;
122  typedef typename CellTraits::PointIdConstIterator PointIdConstIterator;
123  typedef typename CellTraits::CellIdentifier CellIdentifier;
124  typedef typename CellTraits::CellFeatureIdentifier CellFeatureIdentifier;
126  typedef typename CellTraits::PointsContainer PointsContainer;
127  typedef typename CellTraits::UsingCellsContainer UsingCellsContainer;
128 
131 
133  itkStaticConstMacro(PointDimension, unsigned int, CellTraits::PointDimension);
134 
136  typedef typename UsingCellsContainer::iterator UsingCellsContainerIterator;
137 
140  typedef SelfAutoPointer CellAutoPointer;
141  typedef ConstSelfAutoPointer CellConstAutoPointer;
142  typedef RawPointer CellRawPointer;
143  typedef ConstRawPointer CellConstRawPointer;
144 
147 
149  enum CellGeometry { VERTEX_CELL = 0, LINE_CELL, TRIANGLE_CELL,
150  QUADRILATERAL_CELL, POLYGON_CELL, TETRAHEDRON_CELL, HEXAHEDRON_CELL,
151  QUADRATIC_EDGE_CELL, QUADRATIC_TRIANGLE_CELL,
152  LAST_ITK_CELL, MAX_ITK_CELLS = 255 };
153 
157 
158 // static int GetNextUserCellId(); // never return > MAX_INTERFACE
159 
169  {
170 public:
174 
178 
180  //itkNewMacro(Self);
181  static Pointer New(void) { Pointer smartPtr = new Self; smartPtr->UnRegister(); return smartPtr; }
183 
185  itkTypeMacro(MultiVisitor, LightObject);
186 
188  typedef typename VisitorType::Pointer VisitorPointer;
189  typedef typename std::map< int, VisitorPointer >::value_type
191 
192 public:
194  {
195  if ( id < LAST_ITK_CELL )
196  {
197  return m_Visitors[id];
198  }
199  else
200  {
201  typename std::map< int, typename VisitorType::Pointer >::iterator
202  pos = m_UserDefined.find(id);
203  if ( pos != m_UserDefined.end() )
204  {
205  return ( *pos ).second;
206  }
207  }
208  return ITK_NULLPTR;
209  }
210 
212  {
213  int id = v->GetCellTopologyId();
214 
215  if ( id < LAST_ITK_CELL )
216  {
217  m_Visitors[id] = v;
218  }
219  else
220  {
221  m_UserDefined.insert( VisitorPointerValueType(id, v) );
222  }
223  }
224 
225  virtual ~MultiVisitor() ITK_OVERRIDE {}
226 
227 protected:
228  VisitorPointer m_Visitors[LAST_ITK_CELL]; // fixed array set to the
229  // size
230  // from the enum
231  std::map< int, VisitorPointer > m_UserDefined; // user defined cell types
232  // go here
233  };
234 
236  virtual void Accept(CellIdentifier cellId, MultiVisitor *) = 0;
237 
240  virtual CellGeometry GetType(void) const = 0;
241 
244  virtual void MakeCopy(CellAutoPointer &) const = 0;
245 
247  virtual unsigned int GetDimension(void) const = 0;
248 
250  virtual unsigned int GetInterpolationOrder() const;
251 
253  virtual unsigned int GetNumberOfPoints(void) const = 0;
254 
256  virtual CellFeatureCount GetNumberOfBoundaryFeatures(int dimension) const = 0;
257 
259  virtual bool GetBoundaryFeature(int dimension, CellFeatureIdentifier,
260  CellAutoPointer &) = 0;
261 
265  virtual PointIdConstIterator GetPointIds() const;
266 
270  virtual void SetPointIds(PointIdConstIterator first) = 0;
271 
276  virtual void SetPointIds(PointIdConstIterator first,
277  PointIdConstIterator last) = 0;
278 
281  virtual void SetPointId(int localId, PointIdentifier) = 0;
282 
284  virtual PointIdIterator PointIdsBegin(void) = 0;
285 
288  virtual PointIdConstIterator PointIdsBegin(void) const = 0;
289 
291  virtual PointIdIterator PointIdsEnd(void) = 0;
292 
295  virtual PointIdConstIterator PointIdsEnd(void) const = 0;
296 
299  PointIdentifierContainerType GetPointIdsContainer() const;
300  void SetPointIdsContainer( const PointIdentifierContainerType & );
302 
308  { return false; }
309 
327  PointsContainer *,
328  CoordRepType *,
329  CoordRepType[],
330  double *,
332  { return bool(); }
333 
338  const ParametricCoordArrayType &,
339  ShapeFunctionsArrayType &) const {}
340 
356  virtual bool IntersectWithLine(CoordRepType[PointDimension],
357  CoordRepType[PointDimension],
358  CoordRepType,
359  CoordRepType[PointDimension],
360  CoordRepType *,
361  CoordRepType[]) { return bool(); }
362 
367  CoordRepType * GetBoundingBox(CoordRepType[PointDimension * 2]) { return ITK_NULLPTR; }
369 
372 
385  virtual bool IntersectBoundingBoxWithLine(CoordRepType[PointDimension * 2],
386  CoordRepType[PointDimension],
387  CoordRepType[PointDimension],
388  CoordRepType[PointDimension],
389  CoordRepType *) { return bool(); }
390 
396  virtual bool IsExplicitBoundary();
397 
402  virtual void AddUsingCell(CellIdentifier cellId);
403 
407  virtual void RemoveUsingCell(CellIdentifier cellId);
408 
414  virtual bool IsUsingCell(CellIdentifier cellId);
415 
419  virtual unsigned int GetNumberOfUsingCells();
420 
421 #if !defined( ITK_WRAPPING_PARSER )
422 
425  virtual UsingCellsContainerIterator UsingCellsBegin();
426 
430  virtual UsingCellsContainerIterator UsingCellsEnd();
431 
432 #endif
433 
435  itkTypeMacroNoParent(CellInterface);
436 
437 public:
439  virtual ~CellInterface() {}
443 // bool GetPointPosition(PointsContainer*, int localId, Point*)=0;
444 
445 protected:
448 
449 private:
450  ITK_DISALLOW_COPY_AND_ASSIGN(CellInterface);
451 };
452 
471 template< int VPointDimension, typename TCoordRep,
472  typename TInterpolationWeight, typename TPointIdentifier,
473  typename TCellIdentifier, typename TCellFeatureIdentifier,
474  typename TPoint, typename TPointsContainer,
475  typename TUsingCellsContainer >
476 class ITK_TEMPLATE_EXPORT CellTraitsInfo
477 {
478 public:
479  itkStaticConstMacro(PointDimension, unsigned int, VPointDimension);
480  typedef TCoordRep CoordRepType;
481  typedef TInterpolationWeight InterpolationWeightType;
482  typedef TPointIdentifier PointIdentifier;
483  typedef TCellIdentifier CellIdentifier;
484  typedef TCellFeatureIdentifier CellFeatureIdentifier;
485  typedef TPoint PointType;
486  typedef TPointsContainer PointsContainer;
487  typedef TUsingCellsContainer UsingCellsContainer;
489 
491 };
492 
493 #define itkMakeCellTraitsMacro \
494  CellTraitsInfo < itkGetStaticConstMacro(PointDimension), CoordRepType, \
495  InterpolationWeightType, \
496  PointIdentifier, CellIdentifier, CellFeatureIdentifier, \
497  PointType, PointsContainer, UsingCellsContainer >
498 } // end namespace itk
499 
500 #if !defined( ITK_WRAPPING_PARSER )
501 #ifndef ITK_MANUAL_INSTANTIATION
502 #include "itkCellInterface.hxx"
503 #endif
504 #endif
505 
506 #endif
Array class with size defined at construction time.
Definition: itkArray.h:50
const PointIdentifier * PointIdConstIterator
CellTraits::CellIdentifier CellIdentifier
itk::Array< PointIdentifier > PointIdentifierContainerType
void UnRegister() noexcept
CellInterfaceVisitor< TPixelType, TCellTraits > VisitorType
Light weight base class for most itk classes.
SelfAutoPointer CellAutoPointer
UsingCellsContainer m_UsingCells
virtual void EvaluateShapeFunctions(const ParametricCoordArrayType &, ShapeFunctionsArrayType &) const
CoordRepType * GetBoundingBox(CoordRepType[PointDimension *2])
TCellIdentifier CellIdentifier
TUsingCellsContainer UsingCellsContainer
A visitor that can visit different cell types in a mesh. CellInterfaceVisitor instances can be regist...
An abstract interface for cells.
CellTraits::PointType PointType
CellTraits::PointIdentifier PointIdentifier
TPointIdentifier PointIdentifier
CellTraits::InterpolationWeightType InterpolationWeightType
std::map< int, VisitorPointer > m_UserDefined
VisitorType * GetVisitor(int id)
Abstract interface for a visitor class that can visit the cells in a Mesh.
CellFeatureIdentifier CellFeatureCount
PointType::VectorType VectorType
NOTE: it should normally be defined in the traits.
#define itkCellCommonTypedefs(celltype)
virtual bool EvaluatePosition(CoordRepType *, PointsContainer *, CoordRepType *, CoordRepType[], double *, InterpolationWeightType *)
TCellFeatureIdentifier CellFeatureIdentifier
TInterpolationWeight InterpolationWeightType
CellTraits::CellFeatureIdentifier CellFeatureIdentifier
UsingCellsContainer::iterator UsingCellsContainerIterator
ConstSelfAutoPointer CellConstAutoPointer
virtual bool IntersectWithLine(CoordRepType[PointDimension], CoordRepType[PointDimension], CoordRepType, CoordRepType[PointDimension], CoordRepType *, CoordRepType[])
TPointsContainer PointsContainer
CellInterface CellType
CellTraits::PointIdIterator PointIdIterator
Array< InterpolationWeightType > ShapeFunctionsArrayType
ConstRawPointer CellConstRawPointer
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.
PointIdentifier * PointIdIterator
CoordRepType GetBoundingBoxDiagonalLength2(void)
Array< CoordRepType > ParametricCoordArrayType
CellTraits::PointsContainer PointsContainer
virtual bool IntersectBoundingBoxWithLine(CoordRepType[PointDimension *2], CoordRepType[PointDimension], CoordRepType[PointDimension], CoordRepType[PointDimension], CoordRepType *)
CellTraits::CoordRepType CoordRepType
CellTraits::PointIdConstIterator PointIdConstIterator
VisitorType::Pointer VisitorPointer
virtual bool GetClosestBoundary(CoordRepType[], bool *, CellAutoPointer &)
virtual int GetCellTopologyId()=0
CellTraits::UsingCellsContainer UsingCellsContainer
std::map< int, VisitorPointer >::value_type VisitorPointerValueType