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
00108
template <
00109
typename TPixelType,
00110
typename TCellTraits
00111 >
00112 class CellInterface
00113 {
00114
public:
00115
00117
itkCellCommonTypedefs(
CellInterface);
00118
00120 typedef TPixelType
PixelType;
00121
00123 typedef TCellTraits
CellTraits;
00124
00126 typedef typename CellTraits::CoordRepType
CoordRepType;
00127 typedef typename CellTraits::InterpolationWeightType
InterpolationWeightType;
00128 typedef typename CellTraits::PointIdentifier
PointIdentifier;
00129 typedef typename CellTraits::PointIdIterator
PointIdIterator;
00130 typedef typename CellTraits::PointIdConstIterator
PointIdConstIterator;
00131 typedef typename CellTraits::CellIdentifier
CellIdentifier;
00132 typedef typename CellTraits::CellFeatureIdentifier
CellFeatureIdentifier;
00133 typedef typename CellTraits::PointType
PointType;
00134 typedef typename CellTraits::PointsContainer
PointsContainer;
00135 typedef typename CellTraits::UsingCellsContainer
UsingCellsContainer;
00136
00138
itkStaticConstMacro(PointDimension,
unsigned int,CellTraits::PointDimension);
00139
00141 typedef typename UsingCellsContainer::iterator
UsingCellsContainerIterator;
00142
00144 typedef CellInterface CellType;
00145 typedef SelfAutoPointer
CellAutoPointer;
00146 typedef ConstSelfAutoPointer
CellConstAutoPointer;
00147 typedef RawPointer
CellRawPointer;
00148 typedef ConstRawPointer
CellConstRawPointer;
00149
00151 typedef CellFeatureIdentifier CellFeatureCount;
00152
00154 enum CellGeometry {
VERTEX_CELL=0,
LINE_CELL,
TRIANGLE_CELL,
QUADRILATERAL_CELL,
00155
POLYGON_CELL,
TETRAHEDRON_CELL,
HEXAHEDRON_CELL,
00156
QUADRATIC_EDGE_CELL,
QUADRATIC_TRIANGLE_CELL,
00157
LAST_ITK_CELL,
MAX_ITK_CELLS=255};
00158
00160 typedef Array<CoordRepType> ParametricCoordArrayType;
00161 typedef Array<InterpolationWeightType> ShapeFunctionsArrayType;
00162
00163
static int GetNextUserCellId();
00164
00170 class MultiVisitor :
public LightObject
00171 {
00172
public:
00175 typedef CellInterfaceVisitor<TPixelType, TCellTraits> VisitorType;
00176
00178 typedef MultiVisitor Self;
00179 typedef SmartPointer<Self> Pointer;
00180
00182
00183 static Pointer New(
void) {
return new Self; }
00184
00186
itkTypeMacro(
MultiVisitor,
LightObject);
00187
00189
typedef typename VisitorType::Pointer VisitorPointer;
00190
00191
public:
00192
VisitorType *
GetVisitor(
int id)
00193 {
00194
if(
id <= LAST_ITK_CELL)
00195 {
00196
return m_Visitors[
id];
00197 }
00198
else
00199 {
00200
typename std::map<int, ITK_TYPENAME VisitorType::Pointer>::iterator
00201 pos =
m_UserDefined.find(
id);
00202
if(pos !=
m_UserDefined.end())
00203 {
00204
return (*pos).second;
00205 }
00206 }
00207
return 0;
00208 }
00209
void AddVisitor(VisitorType* v)
00210 {
00211
int id = v->GetCellTopologyId();
00212
if(
id <= LAST_ITK_CELL)
00213 {
00214
m_Visitors[
id] = v;
00215 }
00216
else
00217 {
00218
m_UserDefined.insert(std::map<int, VisitorPointer>::
value_type(
id,v));
00219 }
00220 }
00221
~MultiVisitor() {}
00222 protected:
00223
VisitorPointer m_Visitors[LAST_ITK_CELL];
00224 std::map<int,VisitorPointer>
m_UserDefined;
00225 };
00226
00228
virtual void Accept(
unsigned long cellId,
MultiVisitor*)= 0;
00229
00231
virtual CellGeometry GetType(
void) const =0;
00232
00235 virtual
void MakeCopy(
CellAutoPointer & ) const = 0;
00236
00238 virtual
unsigned int GetDimension(
void) const=0;
00239
00241 virtual
unsigned int GetInterpolationOrder(
void) const;
00242
00244 virtual
unsigned int GetNumberOfPoints(
void) const=0;
00245
00247 virtual
CellFeatureCount GetNumberOfBoundaryFeatures(
int dimension) const =0;
00248
00250 virtual
bool GetBoundaryFeature(
int dimension,
CellFeatureIdentifier,
CellAutoPointer & )=0;
00251
00255 virtual
PointIdConstIterator GetPointIds(
void) const;
00256
00260 virtual
void SetPointIds(
PointIdConstIterator first)=0;
00261
00266 virtual
void SetPointIds(
PointIdConstIterator first,
00267
PointIdConstIterator last)=0;
00268
00270 virtual
void SetPointId(
int localId,
PointIdentifier)=0;
00271
00273 virtual
PointIdIterator PointIdsBegin(
void)=0;
00274
00277 virtual
PointIdConstIterator PointIdsBegin(
void) const =0;
00278
00280 virtual
PointIdIterator PointIdsEnd(
void)=0;
00281
00284 virtual
PointIdConstIterator PointIdsEnd(
void) const =0;
00285
00290 virtual
bool GetClosestBoundary(
CoordRepType [],
bool* , CellAutoPointer &)
00291 {
return false;}
00292
00309
virtual bool EvaluatePosition(CoordRepType [PointDimension],
00310 CoordRepType [PointDimension],
00311
CoordRepType [],
00312
CoordRepType* ,
00313
InterpolationWeightType [])
00314 {
return bool();}
00315
00319
virtual void EvaluateShapeFunctions(
00320 const ParametricCoordArrayType &,
00321
ShapeFunctionsArrayType &)
const {}
00322
00338
virtual bool IntersectWithLine(CoordRepType [PointDimension],
00339 CoordRepType [PointDimension],
00340
CoordRepType ,
00341
CoordRepType [PointDimension],
00342
CoordRepType*,
00343
CoordRepType []) {
return bool();}
00344
00349 CoordRepType*
GetBoundingBox(CoordRepType [PointDimension*2]) {
return NULL;}
00350
00352
CoordRepType GetBoundingBoxDiagonalLength2(
void) {
return NULL;}
00353
00366
virtual bool IntersectBoundingBoxWithLine(CoordRepType [PointDimension*2],
00367 CoordRepType [PointDimension],
00368 CoordRepType [PointDimension],
00369
CoordRepType [PointDimension],
00370
CoordRepType* ) {
return bool();}
00371
00377
virtual bool IsExplicitBoundary(
void);
00378
00383
virtual void AddUsingCell(CellIdentifier cellId);
00384
00388
virtual void RemoveUsingCell(CellIdentifier cellId);
00389
00395
virtual bool IsUsingCell(CellIdentifier cellId);
00396
00400
virtual unsigned int GetNumberOfUsingCells(
void);
00401
00405
virtual UsingCellsContainerIterator
UsingCellsBegin(
void);
00406
00410
virtual UsingCellsContainerIterator
UsingCellsEnd(
void);
00411
00413
itkTypeMacro(
CellInterface,
LightObject);
00414
00415
public:
00416
CellInterface() {}
00417
virtual ~CellInterface() {}
00421
00422
00423
protected:
00425
UsingCellsContainer m_UsingCells;
00426
00427 private:
00428
CellInterface(
const Self&);
00429
void operator=(
const Self&);
00430 };
00431
00432
00450
template <
int VPointDimension,
typename TCoordRep,
00451
typename TInterpolationWeight,
typename TPointIdentifier,
00452
typename TCellIdentifier,
typename TCellFeatureIdentifier,
00453
typename TPoint,
typename TPointsContainer,
00454
typename TUsingCellsContainer>
00455
class CellTraitsInfo
00456 {
00457 public:
00458
itkStaticConstMacro(PointDimension,
unsigned int, VPointDimension);
00459
typedef TCoordRep
CoordRepType;
00460
typedef TInterpolationWeight
InterpolationWeightType;
00461 typedef TPointIdentifier
PointIdentifier;
00462 typedef TCellIdentifier
CellIdentifier;
00463 typedef TCellFeatureIdentifier
CellFeatureIdentifier;
00464 typedef TPoint
PointType;
00465 typedef TPointsContainer
PointsContainer;
00466 typedef TUsingCellsContainer
UsingCellsContainer;
00467 typedef PointIdentifier*
PointIdIterator;
00468 typedef const PointIdentifier*
PointIdConstIterator;
00469 };
00470
00471
#define itkMakeCellTraitsMacro \
00472
CellTraitsInfo<itkGetStaticConstMacro(PointDimension), CoordRepType, \
00473 InterpolationWeightType, \
00474
PointIdentifier, CellIdentifier, CellFeatureIdentifier, \
00475
PointType, PointsContainer, UsingCellsContainer>
00476
00477 }
00478
00479
#ifndef ITK_MANUAL_INSTANTIATION
00480
#include "itkCellInterface.txx"
00481
#endif
00482
00483
#endif