Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkCellInterface.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkCellInterface.h,v $
00005   Language:  C++
00006   Date:      $Date: 2008-07-10 19:09:39 $
00007   Version:   $Revision: 1.67 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
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 // Define a macro for CellInterface sub-classes to use
00029 // to define the Accept and GetTopologyId virtuals used
00030 // by the MultiVisitor class
00031 #define itkCellVisitMacro(TopologyId) \
00032 static int GetTopologyId() {return TopologyId;}\
00033 virtual void Accept(unsigned long cellid, typename CellInterface<PixelType,\
00034                                                CellTraits>::MultiVisitor* mv)\
00035 {\
00036   typename CellInterfaceVisitor<PixelType, CellTraits>::Pointer v = \
00037                                            mv->GetVisitor(TopologyId);\
00038   if(v)\
00039     {\
00040     v->VisitFromCell(cellid, this);\
00041     }\
00042 }
00043 
00044 
00045 // Define a macro for the common typedefs required by the 
00046 // classes deriving form CellInterface (included).
00047 // This wouldn't be necessary if SGI compilers 
00048 // were able to inherit types.
00049 #define itkCellCommonTypedefs( celltype ) \
00050   typedef celltype                  Self;   \
00051   typedef AutoPointer<const Self>   ConstSelfAutoPointer;  \
00052   typedef AutoPointer<Self>         SelfAutoPointer;   \
00053   typedef Self *                    RawPointer;        \
00054   typedef const Self *              ConstRawPointer;   \
00055   SelfAutoPointer   New(void) {                        \
00056                 SelfAutoPointer ptr( new celltype );   \
00057                 ptr.TakeOwnership();                   \
00058                 return ptr;                            \
00059                 }                                      \
00060 
00061 
00062 // Define a macro for the common typedefs required by the 
00063 // classes deriving form CellInterface (excluded).
00064 // This wouldn't be necessary if SGI compilers 
00065 // were able to inherit types.
00066 #define itkCellInheritedTypedefs( superclassArg ) \
00067   typedef superclassArg                                Superclass; \
00068   typedef typename Superclass::PixelType               PixelType;  \
00069   typedef typename Superclass::CellType                CellType;  \
00070   typedef typename Superclass::CellAutoPointer         CellAutoPointer;  \
00071   typedef typename Superclass::CellConstAutoPointer    CellConstAutoPointer;  \
00072   typedef typename Superclass::CellRawPointer          CellRawPointer;  \
00073   typedef typename Superclass::CellConstRawPointer     CellConstRawPointer;  \
00074   typedef typename Superclass::CellTraits              CellTraits;  \
00075   typedef typename Superclass::CoordRepType            CoordRepType;  \
00076   typedef typename Superclass::InterpolationWeightType \
00077                                                      InterpolationWeightType; \
00078   typedef typename Superclass::PointIdentifier         PointIdentifier; \
00079   typedef typename Superclass::PointIdIterator         PointIdIterator; \
00080   typedef typename Superclass::PointIdConstIterator    PointIdConstIterator; \
00081   typedef typename Superclass::CellIdentifier          CellIdentifier; \
00082   typedef typename Superclass::CellFeatureIdentifier   CellFeatureIdentifier; \
00083   typedef typename Superclass::CellFeatureIdentifier   CellFeatureCount; \
00084   typedef typename Superclass::PointType               PointType; \
00085   typedef typename Superclass::VectorType              VectorType; \
00086   typedef typename Superclass::PointsContainer         PointsContainer; \
00087   typedef typename Superclass::UsingCellsContainer     UsingCellsContainer; \
00088   typedef typename Superclass::CellGeometry            CellGeometry;  \
00089   typedef typename Superclass::ParametricCoordArrayType  \
00090                                                   ParametricCoordArrayType;  \
00091   typedef typename Superclass::ShapeFunctionsArrayType   \
00092                                                    ShapeFunctionsArrayType;  \
00093   itkStaticConstMacro(PointDimension, unsigned int, Superclass::PointDimension)
00094  
00095 
00096 namespace itk
00097 {
00098 
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   typedef typename PointType::VectorType               VectorType;
00142     
00144   itkStaticConstMacro(PointDimension, unsigned int,CellTraits::PointDimension);
00145 
00147   typedef typename UsingCellsContainer::iterator  UsingCellsContainerIterator;
00148 
00150   typedef CellInterface         CellType;
00151   typedef SelfAutoPointer       CellAutoPointer;
00152   typedef ConstSelfAutoPointer  CellConstAutoPointer;
00153   typedef RawPointer            CellRawPointer;
00154   typedef ConstRawPointer       CellConstRawPointer;
00155 
00157   typedef CellFeatureIdentifier  CellFeatureCount;
00158 
00160   enum CellGeometry {VERTEX_CELL=0, LINE_CELL, TRIANGLE_CELL, 
00161         QUADRILATERAL_CELL, POLYGON_CELL, TETRAHEDRON_CELL, HEXAHEDRON_CELL, 
00162         QUADRATIC_EDGE_CELL, QUADRATIC_TRIANGLE_CELL,
00163         LAST_ITK_CELL, MAX_ITK_CELLS=255};
00164 
00166   typedef Array<CoordRepType>                 ParametricCoordArrayType;
00167   typedef Array<InterpolationWeightType>      ShapeFunctionsArrayType;
00168 
00169   static int GetNextUserCellId(); // never return > MAX_INTERFACE
00170 
00177   class MultiVisitor : public LightObject
00178     {
00179     public:
00182     typedef CellInterfaceVisitor<TPixelType, TCellTraits> VisitorType;
00183 
00185     typedef MultiVisitor        Self;
00186     typedef SmartPointer<Self>  Pointer;
00187 
00189     //itkNewMacro(Self);
00190     static  Pointer New(void) { Pointer smartPtr = new Self; smartPtr->UnRegister(); return smartPtr;}
00192 
00194     itkTypeMacro(MultiVisitor,LightObject);
00195 
00197     typedef typename VisitorType::Pointer       VisitorPointer;
00198     typedef typename std::map<int, VisitorPointer>::value_type 
00199                                                 VisitorPointerValueType;
00200 
00201   public:
00202     VisitorType * GetVisitor(int id)
00203       {
00204       if(id <= LAST_ITK_CELL)
00205         {
00206         return m_Visitors[id];
00207         }
00208       else
00209         {
00210         typename std::map<int, ITK_TYPENAME VisitorType::Pointer>::iterator
00211             pos = m_UserDefined.find(id);
00212         if(pos != m_UserDefined.end())
00213           {
00214           return (*pos).second;
00215           }
00216         }
00217         return 0;
00218       }
00219 
00220     void AddVisitor(VisitorType* v)
00221       {
00222       int id = v->GetCellTopologyId();
00223       if(id <= LAST_ITK_CELL)
00224         {
00225         m_Visitors[id] = v;
00226         }
00227       else
00228         {
00229         m_UserDefined.insert(VisitorPointerValueType(id,v));
00230         }
00231       }
00232     virtual ~MultiVisitor() {}
00233 
00234   protected:
00235     VisitorPointer m_Visitors[LAST_ITK_CELL]; // fixed array set to the size 
00236                                               // from the enum
00237     std::map<int,VisitorPointer> m_UserDefined; // user defined cell types 
00238                                                 // go here
00239   };
00240 
00242   virtual void Accept(unsigned long cellId, MultiVisitor*)= 0; 
00243 
00246   virtual CellGeometry GetType(void) const =0;
00247 
00250   virtual void MakeCopy( CellAutoPointer & ) const = 0;
00251 
00253   virtual unsigned int GetDimension(void) const=0;
00254 
00256   virtual unsigned int GetInterpolationOrder(void) const;
00257 
00259   virtual unsigned int GetNumberOfPoints(void) const=0;
00260 
00262   virtual CellFeatureCount GetNumberOfBoundaryFeatures(int dimension) const =0;
00263 
00265   virtual bool GetBoundaryFeature(int dimension, CellFeatureIdentifier, 
00266                                                         CellAutoPointer & )=0;
00267 
00271   virtual PointIdConstIterator GetPointIds(void) const;
00272 
00276   virtual void SetPointIds(PointIdConstIterator first)=0;
00277 
00282   virtual void SetPointIds(PointIdConstIterator first,
00283                            PointIdConstIterator last)=0;
00284 
00287   virtual void SetPointId(int localId, PointIdentifier)=0;
00288 
00290   virtual PointIdIterator PointIdsBegin(void)=0;
00291 
00294   virtual PointIdConstIterator PointIdsBegin(void) const =0;
00295 
00297   virtual PointIdIterator PointIdsEnd(void)=0;
00298 
00301   virtual PointIdConstIterator PointIdsEnd(void) const =0;
00302 
00307   virtual bool GetClosestBoundary(CoordRepType [], bool* , CellAutoPointer &) 
00308     {return false;}
00309 
00326   virtual bool EvaluatePosition(CoordRepType* ,
00327                                 PointsContainer* ,
00328                                 CoordRepType* ,
00329                                 CoordRepType [],
00330                                 double *,
00331                                 InterpolationWeightType*)
00332     {return bool();}
00333 
00337   virtual void EvaluateShapeFunctions( 
00338                           const ParametricCoordArrayType &,
00339                                 ShapeFunctionsArrayType  &) const {}
00340 
00356   virtual bool IntersectWithLine(CoordRepType [PointDimension],
00357                                  CoordRepType [PointDimension],
00358                                  CoordRepType ,
00359                                  CoordRepType [PointDimension],
00360                                  CoordRepType*,
00361                                  CoordRepType []) {return bool();}
00362 
00367   CoordRepType* GetBoundingBox(CoordRepType [PointDimension*2]) {return NULL;}
00369 
00371   CoordRepType GetBoundingBoxDiagonalLength2(void) {return NULL;}
00372 
00385   virtual bool IntersectBoundingBoxWithLine(CoordRepType [PointDimension*2],
00386                                             CoordRepType [PointDimension],
00387                                             CoordRepType [PointDimension],
00388                                             CoordRepType [PointDimension],
00389                                             CoordRepType* ) {return bool();}
00390 
00396   virtual bool IsExplicitBoundary(void);
00397 
00402   virtual void AddUsingCell(CellIdentifier cellId);
00403 
00407   virtual void RemoveUsingCell(CellIdentifier cellId);
00408 
00414   virtual bool IsUsingCell(CellIdentifier cellId);
00415 
00419   virtual unsigned int GetNumberOfUsingCells(void);
00420 
00424   virtual UsingCellsContainerIterator UsingCellsBegin(void);
00425 
00429   virtual UsingCellsContainerIterator UsingCellsEnd(void);
00430 
00432   itkTypeMacro(CellInterface, LightObject);
00433 
00434 public:
00435   CellInterface() {}
00436   virtual ~CellInterface() {}
00440 //  bool GetPointPosition(PointsContainer*, int localId, Point*)=0;
00441 
00442 protected:
00444   UsingCellsContainer m_UsingCells;
00445 
00446 private:
00447   CellInterface(const Self&); //purposely not implemented
00448   void operator=(const Self&); //purposely not implemented  
00449 };
00450 
00451 
00469 template <int VPointDimension, typename TCoordRep,
00470   typename TInterpolationWeight, typename TPointIdentifier,
00471   typename TCellIdentifier, typename TCellFeatureIdentifier,
00472   typename TPoint, typename TPointsContainer,
00473   typename TUsingCellsContainer>
00474 class CellTraitsInfo
00475 {
00476 public:
00477   itkStaticConstMacro(PointDimension, unsigned int, VPointDimension);
00478   typedef TCoordRep               CoordRepType;
00479   typedef TInterpolationWeight    InterpolationWeightType;
00480   typedef TPointIdentifier        PointIdentifier;
00481   typedef TCellIdentifier         CellIdentifier;
00482   typedef TCellFeatureIdentifier  CellFeatureIdentifier;
00483   typedef TPoint                  PointType;
00484   typedef TPointsContainer        PointsContainer;
00485   typedef TUsingCellsContainer    UsingCellsContainer;
00486   typedef PointIdentifier*        PointIdIterator;
00487   typedef const PointIdentifier*  PointIdConstIterator;  
00488 };
00489 
00490 #define itkMakeCellTraitsMacro \
00491   CellTraitsInfo<itkGetStaticConstMacro(PointDimension), CoordRepType, \
00492                InterpolationWeightType,  \
00493                PointIdentifier, CellIdentifier, CellFeatureIdentifier, \
00494                PointType, PointsContainer, UsingCellsContainer>
00495 
00496 } // end namespace itk
00497 
00498 #ifndef ITK_MANUAL_INSTANTIATION
00499 #include "itkCellInterface.txx"
00500 #endif
00501 
00502 #endif
00503 

Generated at Sat Feb 28 12:09:27 2009 for ITK by doxygen 1.5.6 written by Dimitri van Heesch, © 1997-2000