00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkCellInterface_h
00018 #define __itkCellInterface_h
00019
00020 #include "itkObject.h"
00021 #include "itkObjectFactory.h"
00022 #include <map>
00023 #include "itkCellInterfaceVisitor.h"
00024 #include "itkAutoPointer.h"
00025 #include "itkArray.h"
00026
00027
00028
00029
00030
00031 #define itkCellVisitMacro(TopologyId) \
00032 static int GetTopologyId() {return TopologyId;}\
00033 virtual void Accept(unsigned long cellid, typename CellInterface<PixelType, CellTraits>::MultiVisitor* mv)\
00034 {\
00035 typename CellInterfaceVisitor<PixelType, CellTraits>::Pointer v = mv->GetVisitor(TopologyId);\
00036 if(v)\
00037 {\
00038 v->VisitFromCell(cellid, this);\
00039 }\
00040 }
00041
00042
00043
00044
00045
00046
00047
00048 #define itkCellCommonTypedefs( celltype ) \
00049 typedef celltype Self; \
00050 typedef AutoPointer<const Self> ConstSelfAutoPointer; \
00051 typedef AutoPointer<Self> SelfAutoPointer; \
00052 typedef Self * RawPointer; \
00053 typedef const Self * ConstRawPointer; \
00054 SelfAutoPointer New(void) { \
00055 SelfAutoPointer ptr( new celltype ); \
00056 ptr.TakeOwnership(); \
00057 return ptr; \
00058 } \
00059
00060
00061
00062
00063
00064
00065 #define itkCellInheritedTypedefs( superclassArg ) \
00066 typedef superclassArg Superclass; \
00067 typedef typename Superclass::PixelType PixelType; \
00068 typedef typename Superclass::CellType CellType; \
00069 typedef typename Superclass::CellAutoPointer CellAutoPointer; \
00070 typedef typename Superclass::CellConstAutoPointer CellConstAutoPointer; \
00071 typedef typename Superclass::CellRawPointer CellRawPointer; \
00072 typedef typename Superclass::CellConstRawPointer CellConstRawPointer; \
00073 typedef typename Superclass::CellTraits CellTraits; \
00074 typedef typename Superclass::CoordRepType CoordRepType; \
00075 typedef typename Superclass::InterpolationWeightType InterpolationWeightType; \
00076 typedef typename Superclass::PointIdentifier PointIdentifier; \
00077 typedef typename Superclass::PointIdIterator PointIdIterator; \
00078 typedef typename Superclass::PointIdConstIterator PointIdConstIterator; \
00079 typedef typename Superclass::CellIdentifier CellIdentifier; \
00080 typedef typename Superclass::CellFeatureIdentifier CellFeatureIdentifier; \
00081 typedef typename Superclass::CellFeatureIdentifier CellFeatureCount; \
00082 typedef typename Superclass::PointType PointType; \
00083 typedef typename Superclass::PointsContainer PointsContainer; \
00084 typedef typename Superclass::UsingCellsContainer UsingCellsContainer; \
00085 typedef typename Superclass::CellGeometry CellGeometry; \
00086 typedef typename Superclass::ParametricCoordArrayType ParametricCoordArrayType; \
00087 typedef typename Superclass::ShapeFunctionsArrayType ShapeFunctionsArrayType; \
00088 itkStaticConstMacro(PointDimension, unsigned int, Superclass::PointDimension)
00089
00090
00091
00092
00093 namespace itk
00094 {
00095
00111 template <
00112 typename TPixelType,
00113 typename TCellTraits
00114 >
00115 class CellInterface
00116 {
00117 public:
00118
00120 itkCellCommonTypedefs(CellInterface);
00121
00123 typedef TPixelType PixelType;
00124
00126 typedef TCellTraits CellTraits;
00127
00129 typedef typename CellTraits::CoordRepType CoordRepType;
00130 typedef typename CellTraits::InterpolationWeightType InterpolationWeightType;
00131 typedef typename CellTraits::PointIdentifier PointIdentifier;
00132 typedef typename CellTraits::PointIdIterator PointIdIterator;
00133 typedef typename CellTraits::PointIdConstIterator PointIdConstIterator;
00134 typedef typename CellTraits::CellIdentifier CellIdentifier;
00135 typedef typename CellTraits::CellFeatureIdentifier CellFeatureIdentifier;
00136 typedef typename CellTraits::PointType PointType;
00137 typedef typename CellTraits::PointsContainer PointsContainer;
00138 typedef typename CellTraits::UsingCellsContainer UsingCellsContainer;
00139
00141 itkStaticConstMacro(PointDimension, unsigned int,CellTraits::PointDimension);
00142
00144 typedef typename UsingCellsContainer::iterator UsingCellsContainerIterator;
00145
00147 typedef CellInterface CellType;
00148 typedef SelfAutoPointer CellAutoPointer;
00149 typedef ConstSelfAutoPointer CellConstAutoPointer;
00150 typedef RawPointer CellRawPointer;
00151 typedef ConstRawPointer CellConstRawPointer;
00152
00154 typedef CellFeatureIdentifier CellFeatureCount;
00155
00157 enum CellGeometry {VERTEX_CELL=0, LINE_CELL, TRIANGLE_CELL, QUADRILATERAL_CELL,
00158 POLYGON_CELL, TETRAHEDRON_CELL, HEXAHEDRON_CELL,
00159 QUADRATIC_EDGE_CELL, QUADRATIC_TRIANGLE_CELL,
00160 LAST_ITK_CELL, MAX_ITK_CELLS=255};
00161
00163 typedef Array<CoordRepType> ParametricCoordArrayType;
00164 typedef Array<InterpolationWeightType> ShapeFunctionsArrayType;
00165
00166 static int GetNextUserCellId();
00167
00173 class MultiVisitor : public LightObject
00174 {
00175 public:
00178 typedef CellInterfaceVisitor<TPixelType, TCellTraits> VisitorType;
00179
00181 typedef MultiVisitor Self;
00182 typedef SmartPointer<Self> Pointer;
00183
00185
00186 static Pointer New(void) { return new Self; }
00187
00189 itkTypeMacro(MultiVisitor,LightObject);
00190
00192 typedef typename VisitorType::Pointer VisitorPointer;
00193
00194 public:
00195 VisitorType * GetVisitor(int id)
00196 {
00197 if(id <= LAST_ITK_CELL)
00198 {
00199 return m_Visitors[id];
00200 }
00201 else
00202 {
00203 typename std::map<int, ITK_TYPENAME VisitorType::Pointer>::iterator
00204 pos = m_UserDefined.find(id);
00205 if(pos != m_UserDefined.end())
00206 {
00207 return (*pos).second;
00208 }
00209 }
00210 return 0;
00211 }
00212 void AddVisitor(VisitorType* v)
00213 {
00214 int id = v->GetCellTopologyId();
00215 if(id <= LAST_ITK_CELL)
00216 {
00217 m_Visitors[id] = v;
00218 }
00219 else
00220 {
00221 m_UserDefined.insert(std::map<int, VisitorPointer>::value_type(id,v));
00222 }
00223 }
00224 ~MultiVisitor() {}
00225 protected:
00226 VisitorPointer m_Visitors[LAST_ITK_CELL];
00227 std::map<int,VisitorPointer> m_UserDefined;
00228 };
00229
00231 virtual void Accept(unsigned long cellId, MultiVisitor*)= 0;
00232
00234 virtual CellGeometry GetType(void) const =0;
00235
00238 virtual void MakeCopy( CellAutoPointer & ) const = 0;
00239
00241 virtual unsigned int GetDimension(void) const=0;
00242
00244 virtual unsigned int GetInterpolationOrder(void) const;
00245
00247 virtual unsigned int GetNumberOfPoints(void) const=0;
00248
00250 virtual CellFeatureCount GetNumberOfBoundaryFeatures(int dimension) const =0;
00251
00253 virtual bool GetBoundaryFeature(int dimension, CellFeatureIdentifier, CellAutoPointer & )=0;
00254
00258 virtual PointIdConstIterator GetPointIds(void) const;
00259
00263 virtual void SetPointIds(PointIdConstIterator first)=0;
00264
00269 virtual void SetPointIds(PointIdConstIterator first,
00270 PointIdConstIterator last)=0;
00271
00273 virtual void SetPointId(int localId, PointIdentifier)=0;
00274
00276 virtual PointIdIterator PointIdsBegin(void)=0;
00277
00280 virtual PointIdConstIterator PointIdsBegin(void) const =0;
00281
00283 virtual PointIdIterator PointIdsEnd(void)=0;
00284
00287 virtual PointIdConstIterator PointIdsEnd(void) const =0;
00288
00293 virtual bool GetClosestBoundary(CoordRepType [], bool* , CellAutoPointer &)
00294 {return false;}
00295
00312 virtual bool EvaluatePosition(CoordRepType [PointDimension],
00313 CoordRepType [PointDimension],
00314 CoordRepType [],
00315 CoordRepType* ,
00316 InterpolationWeightType [])
00317 {return bool();}
00318
00322 virtual void EvaluateShapeFunctions(
00323 const ParametricCoordArrayType &,
00324 ShapeFunctionsArrayType &) const {}
00325
00341 virtual bool IntersectWithLine(CoordRepType [PointDimension],
00342 CoordRepType [PointDimension],
00343 CoordRepType ,
00344 CoordRepType [PointDimension],
00345 CoordRepType*,
00346 CoordRepType []) {return bool();}
00347
00352 CoordRepType* GetBoundingBox(CoordRepType [PointDimension*2]) {return NULL;}
00353
00355 CoordRepType GetBoundingBoxDiagonalLength2(void) {return NULL;}
00356
00369 virtual bool IntersectBoundingBoxWithLine(CoordRepType [PointDimension*2],
00370 CoordRepType [PointDimension],
00371 CoordRepType [PointDimension],
00372 CoordRepType [PointDimension],
00373 CoordRepType* ) {return bool();}
00374
00377 virtual bool IsBoundary(void);
00378 virtual void AddUsingCell(CellIdentifier);
00379 virtual void RemoveUsingCell(CellIdentifier);
00380 virtual bool IsUsingCell(CellIdentifier);
00381 virtual unsigned int GetNumberOfUsingCells(void);
00382 virtual UsingCellsContainerIterator UsingCellsBegin(void);
00383 virtual UsingCellsContainerIterator UsingCellsEnd(void);
00384
00386 itkTypeMacro(CellInterface, LightObject);
00387
00388 public:
00389 CellInterface() {}
00390 virtual ~CellInterface() {}
00394
00395 private:
00396 CellInterface(const Self&);
00397 void operator=(const Self&);
00398 };
00399
00400
00418 template <int VPointDimension, typename TCoordRep,
00419 typename TInterpolationWeight, typename TPointIdentifier,
00420 typename TCellIdentifier, typename TCellFeatureIdentifier,
00421 typename TPoint, typename TPointsContainer,
00422 typename TUsingCellsContainer>
00423 class CellTraitsInfo
00424 {
00425 public:
00426 itkStaticConstMacro(PointDimension, unsigned int, VPointDimension);
00427 typedef TCoordRep CoordRepType;
00428 typedef TInterpolationWeight InterpolationWeightType;
00429 typedef TPointIdentifier PointIdentifier;
00430 typedef TCellIdentifier CellIdentifier;
00431 typedef TCellFeatureIdentifier CellFeatureIdentifier;
00432 typedef TPoint PointType;
00433 typedef TPointsContainer PointsContainer;
00434 typedef TUsingCellsContainer UsingCellsContainer;
00435 typedef PointIdentifier* PointIdIterator;
00436 typedef const PointIdentifier* PointIdConstIterator;
00437 };
00438
00439 #define itkMakeCellTraitsMacro \
00440 CellTraitsInfo<itkGetStaticConstMacro(PointDimension), CoordRepType, \
00441 InterpolationWeightType, \
00442 PointIdentifier, CellIdentifier, CellFeatureIdentifier, \
00443 PointType, PointsContainer, UsingCellsContainer>
00444
00445 }
00446
00447 #ifndef ITK_MANUAL_INSTANTIATION
00448 #include "itkCellInterface.txx"
00449 #endif
00450
00451 #endif