ITK  4.2.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 public:
193  {
194  if ( id <= LAST_ITK_CELL )
195  {
196  return m_Visitors[id];
197  }
198  else
199  {
200  typename std::map< int, typename VisitorType::Pointer >::iterator
201  pos = m_UserDefined.find(id);
202  if ( pos != m_UserDefined.end() )
203  {
204  return ( *pos ).second;
205  }
206  }
207  return 0;
208  }
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 protected:
227  VisitorPointer m_Visitors[LAST_ITK_CELL]; // fixed array set to the
228  // size
229  // from the enum
230  std::map< int, VisitorPointer > m_UserDefined; // user defined cell types
231  // go here
232  };
233 
235  virtual void Accept(CellIdentifier cellId, MultiVisitor *) = 0;
236 
239  virtual CellGeometry GetType(void) const = 0;
240 
243  virtual void MakeCopy(CellAutoPointer &) const = 0;
244 
246  virtual unsigned int GetDimension(void) const = 0;
247 
249  virtual unsigned int GetInterpolationOrder(void) const;
250 
252  virtual unsigned int GetNumberOfPoints(void) const = 0;
253 
255  virtual CellFeatureCount GetNumberOfBoundaryFeatures(int dimension) const = 0;
256 
258  virtual bool GetBoundaryFeature(int dimension, CellFeatureIdentifier,
259  CellAutoPointer &) = 0;
260 
264  virtual PointIdConstIterator GetPointIds(void) const;
265 
269  virtual void SetPointIds(PointIdConstIterator first) = 0;
270 
275  virtual void SetPointIds(PointIdConstIterator first,
276  PointIdConstIterator last) = 0;
277 
280  virtual void SetPointId(int localId, PointIdentifier) = 0;
281 
283  virtual PointIdIterator PointIdsBegin(void) = 0;
284 
287  virtual PointIdConstIterator PointIdsBegin(void) const = 0;
288 
290  virtual PointIdIterator PointIdsEnd(void) = 0;
291 
294  virtual PointIdConstIterator PointIdsEnd(void) const = 0;
295 
301 
307  { return false; }
308 
326  PointsContainer *,
327  CoordRepType *,
328  CoordRepType[],
329  double *,
331  { return bool(); }
332 
337  const ParametricCoordArrayType &,
338  ShapeFunctionsArrayType &) const {}
339 
356  CoordRepType[PointDimension],
357  CoordRepType,
358  CoordRepType[PointDimension],
359  CoordRepType *,
360  CoordRepType[]) { return bool(); }
361 
368 
371 
385  CoordRepType[PointDimension],
386  CoordRepType[PointDimension],
387  CoordRepType[PointDimension],
388  CoordRepType *) { return bool(); }
389 
395  virtual bool IsExplicitBoundary(void);
396 
401  virtual void AddUsingCell(CellIdentifier cellId);
402 
406  virtual void RemoveUsingCell(CellIdentifier cellId);
407 
413  virtual bool IsUsingCell(CellIdentifier cellId);
414 
418  virtual unsigned int GetNumberOfUsingCells(void);
419 
420 #if !defined( CABLE_CONFIGURATION )
421 
425 
430 
431 #endif
432 
434  itkTypeMacro(CellInterface, LightObject);
435 public:
437  virtual ~CellInterface() {}
438 
442 // bool GetPointPosition(PointsContainer*, int localId, Point*)=0;
443 protected:
444 
447 private:
448  CellInterface(const Self &); //purposely not implemented
449  void operator=(const Self &); //purposely not implemented
450 };
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 >
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( CABLE_CONFIGURATION )
501 #ifndef ITK_MANUAL_INSTANTIATION
502 #include "itkCellInterface.hxx"
503 #endif
504 #endif
505 
506 #endif
507