ITK  4.6.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) \
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  >
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;
125  typedef typename CellTraits::PointType PointType;
126  typedef typename CellTraits::PointsContainer PointsContainer;
127  typedef typename CellTraits::UsingCellsContainer UsingCellsContainer;
128 
130  typedef typename PointType::VectorType VectorType;
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 
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() {}
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(void) 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(void) 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 
302 
308  { return false; }
309 
327  PointsContainer *,
328  CoordRepType *,
329  CoordRepType[],
330  double *,
332  { return bool(); }
333 
338  const ParametricCoordArrayType &,
339  ShapeFunctionsArrayType &) const {}
340 
357  CoordRepType[PointDimension],
358  CoordRepType,
359  CoordRepType[PointDimension],
360  CoordRepType *,
361  CoordRepType[]) { return bool(); }
362 
369 
372 
386  CoordRepType[PointDimension],
387  CoordRepType[PointDimension],
388  CoordRepType[PointDimension],
389  CoordRepType *) { return bool(); }
390 
396  virtual bool IsExplicitBoundary(void);
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(void);
420 
421 #if !defined( CABLE_CONFIGURATION )
422 
426 
431 
432 #endif
433 
435  itkTypeMacro(CellInterface, LightObject);
436 
437 public:
439  virtual ~CellInterface() {}
443 // bool GetPointPosition(PointsContainer*, int localId, Point*)=0;
444 
445 protected:
448 
449 private:
450  CellInterface(const Self &); //purposely not implemented
451  void operator=(const Self &); //purposely not implemented
452 };
453 
472 template< int VPointDimension, typename TCoordRep,
473  typename TInterpolationWeight, typename TPointIdentifier,
474  typename TCellIdentifier, typename TCellFeatureIdentifier,
475  typename TPoint, typename TPointsContainer,
476  typename TUsingCellsContainer >
478 {
479 public:
480  itkStaticConstMacro(PointDimension, unsigned int, VPointDimension);
481  typedef TCoordRep CoordRepType;
482  typedef TInterpolationWeight InterpolationWeightType;
483  typedef TPointIdentifier PointIdentifier;
484  typedef TCellIdentifier CellIdentifier;
485  typedef TCellFeatureIdentifier CellFeatureIdentifier;
486  typedef TPoint PointType;
487  typedef TPointsContainer PointsContainer;
488  typedef TUsingCellsContainer UsingCellsContainer;
490 
492 };
493 
494 #define itkMakeCellTraitsMacro \
495  CellTraitsInfo < itkGetStaticConstMacro(PointDimension), CoordRepType, \
496  InterpolationWeightType, \
497  PointIdentifier, CellIdentifier, CellFeatureIdentifier, \
498  PointType, PointsContainer, UsingCellsContainer >
499 } // end namespace itk
500 
501 #if !defined( CABLE_CONFIGURATION )
502 #ifndef ITK_MANUAL_INSTANTIATION
503 #include "itkCellInterface.hxx"
504 #endif
505 #endif
506 
507 #endif
Array class with size defined at construction time.
Definition: itkArray.h:50
const PointIdentifier * PointIdConstIterator
CellTraits::CellIdentifier CellIdentifier
virtual unsigned int GetDimension(void) const =0
itk::Array< PointIdentifier > PointIdentifierContainerType
CellInterfaceVisitor< TPixelType, TCellTraits > VisitorType
virtual UsingCellsContainerIterator UsingCellsBegin(void)
Light weight base class for most itk classes.
SelfAutoPointer CellAutoPointer
virtual bool IsUsingCell(CellIdentifier cellId)
UsingCellsContainer m_UsingCells
virtual void EvaluateShapeFunctions(const ParametricCoordArrayType &, ShapeFunctionsArrayType &) const
CoordRepType * GetBoundingBox(CoordRepType[PointDimension *2])
virtual CellFeatureCount GetNumberOfBoundaryFeatures(int dimension) const =0
virtual bool IsExplicitBoundary(void)
virtual PointIdConstIterator GetPointIds(void) const
TCellIdentifier CellIdentifier
itkCellCommonTypedefs(CellInterface)
TUsingCellsContainer UsingCellsContainer
VisitorPointer m_Visitors[LAST_ITK_CELL]
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
virtual void SetPointId(int localId, PointIdentifier)=0
VisitorType * GetVisitor(int id)
virtual unsigned int GetNumberOfUsingCells(void)
Abstract interface for a visitor class that can visit the cells in a Mesh.
virtual bool GetBoundaryFeature(int dimension, CellFeatureIdentifier, CellAutoPointer &)=0
CellFeatureIdentifier CellFeatureCount
PointType::VectorType VectorType
NOTE: it should normally be defined in the traits.
void operator=(const Self &)
virtual bool EvaluatePosition(CoordRepType *, PointsContainer *, CoordRepType *, CoordRepType[], double *, InterpolationWeightType *)
virtual unsigned int GetInterpolationOrder(void) const
TCellFeatureIdentifier CellFeatureIdentifier
virtual void Accept(CellIdentifier cellId, MultiVisitor *)=0
TInterpolationWeight InterpolationWeightType
CellTraits::CellFeatureIdentifier CellFeatureIdentifier
UsingCellsContainer::iterator UsingCellsContainerIterator
virtual PointIdIterator PointIdsEnd(void)=0
ConstSelfAutoPointer CellConstAutoPointer
virtual void MakeCopy(CellAutoPointer &) const =0
virtual bool IntersectWithLine(CoordRepType[PointDimension], CoordRepType[PointDimension], CoordRepType, CoordRepType[PointDimension], CoordRepType *, CoordRepType[])
virtual CellGeometry GetType(void) const =0
PointIdentifierContainerType GetPointIdsContainer() const
TPointsContainer PointsContainer
CellInterface CellType
static const unsigned int PointDimension
CellTraits::PointIdIterator PointIdIterator
Array< InterpolationWeightType > ShapeFunctionsArrayType
void SetPointIdsContainer(const PointIdentifierContainerType &)
virtual void RemoveUsingCell(CellIdentifier cellId)
virtual unsigned int GetNumberOfPoints(void) const =0
virtual void SetPointIds(PointIdConstIterator first)=0
ConstRawPointer CellConstRawPointer
virtual void AddUsingCell(CellIdentifier cellId)
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.
#define NULL
PointIdentifier * PointIdIterator
virtual UsingCellsContainerIterator UsingCellsEnd(void)
static const unsigned int PointDimension
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 PointIdIterator PointIdsBegin(void)=0
virtual int GetCellTopologyId()=0
CellTraits::UsingCellsContainer UsingCellsContainer
std::map< int, VisitorPointer >::value_type VisitorPointerValueType