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: 2005/09/29 17:59:01 $
00007   Version:   $Revision: 1.62 $
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, 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 // Define a macro for the common typedefs required by the 
00045 // classes deriving form CellInterface (included).
00046 // This wouldn't be necessary if SGI compilers 
00047 // were able to inherit types.
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 // Define a macro for the common typedefs required by the 
00062 // classes deriving form CellInterface (excluded).
00063 // This wouldn't be necessary if SGI compilers 
00064 // were able to inherit types.
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(); // never return > MAX_INTERFACE
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     //itkNewMacro(Self);
00183     static  Pointer New(void) { return new Self; }
00184   
00186     itkTypeMacro(MultiVisitor,LightObject);
00187   
00189     typedef typename VisitorType::Pointer VisitorPointer;
00190     typedef typename std::map<int, VisitorPointer>::value_type VisitorPointerValueType;
00191 
00192   public:
00193     VisitorType * GetVisitor(int id)
00194       {
00195         if(id <= LAST_ITK_CELL)
00196           {
00197           return m_Visitors[id];
00198           }
00199         else
00200           {
00201           typename std::map<int, ITK_TYPENAME VisitorType::Pointer>::iterator
00202             pos = m_UserDefined.find(id);
00203           if(pos != m_UserDefined.end())
00204             {
00205             return (*pos).second;
00206             }
00207           }
00208         return 0;
00209       }
00210     void AddVisitor(VisitorType* v)
00211       {
00212         int id = v->GetCellTopologyId();
00213         if(id <= LAST_ITK_CELL)
00214           {
00215           m_Visitors[id] = v;
00216           }
00217         else
00218           {
00219           m_UserDefined.insert(VisitorPointerValueType(id,v));
00220           }
00221       }
00222     virtual ~MultiVisitor() {}
00223   protected:
00224     VisitorPointer m_Visitors[LAST_ITK_CELL]; // fixed array set to the size from the enum
00225     std::map<int,VisitorPointer> m_UserDefined; // user defined cell types go here
00226   };
00227 
00229   virtual void Accept(unsigned long cellId, MultiVisitor*)= 0; 
00230   
00232   virtual CellGeometry GetType(void) const =0;
00233 
00236   virtual void MakeCopy( CellAutoPointer & ) const = 0;
00237   
00239   virtual unsigned int GetDimension(void) const=0;
00240 
00242   virtual unsigned int GetInterpolationOrder(void) const;
00243   
00245   virtual unsigned int GetNumberOfPoints(void) const=0;
00246   
00248   virtual CellFeatureCount GetNumberOfBoundaryFeatures(int dimension) const =0;
00249   
00251   virtual bool GetBoundaryFeature(int dimension, CellFeatureIdentifier, CellAutoPointer & )=0;
00252 
00256   virtual PointIdConstIterator GetPointIds(void) const;
00257   
00261   virtual void SetPointIds(PointIdConstIterator first)=0;
00262   
00267   virtual void SetPointIds(PointIdConstIterator first,
00268                            PointIdConstIterator last)=0;
00269   
00271   virtual void SetPointId(int localId, PointIdentifier)=0;
00272   
00274   virtual PointIdIterator PointIdsBegin(void)=0;
00275 
00278   virtual PointIdConstIterator PointIdsBegin(void) const =0;
00279 
00281   virtual PointIdIterator PointIdsEnd(void)=0;
00282 
00285   virtual PointIdConstIterator PointIdsEnd(void) const =0;
00286 
00291   virtual bool GetClosestBoundary(CoordRepType [], bool* , CellAutoPointer &) 
00292     {return false;}
00293 
00310   virtual bool EvaluatePosition(CoordRepType* ,
00311                                 PointsContainer* ,
00312                                 CoordRepType* ,
00313                                 CoordRepType [],
00314                                 double *,
00315                                 InterpolationWeightType*)
00316     {return bool();}
00317   
00321   virtual void EvaluateShapeFunctions( 
00322                           const ParametricCoordArrayType &,
00323                                 ShapeFunctionsArrayType  &) const {}
00324 
00340   virtual bool IntersectWithLine(CoordRepType [PointDimension],
00341                                  CoordRepType [PointDimension],
00342                                  CoordRepType ,
00343                                  CoordRepType [PointDimension],
00344                                  CoordRepType*,
00345                                  CoordRepType []) {return bool();}
00346   
00351   CoordRepType* GetBoundingBox(CoordRepType [PointDimension*2]) {return NULL;}
00352 
00354   CoordRepType GetBoundingBoxDiagonalLength2(void) {return NULL;}
00355 
00368   virtual bool IntersectBoundingBoxWithLine(CoordRepType [PointDimension*2],
00369                                             CoordRepType [PointDimension],
00370                                             CoordRepType [PointDimension],
00371                                             CoordRepType [PointDimension],
00372                                             CoordRepType* ) {return bool();}
00373   
00379   virtual bool IsExplicitBoundary(void);
00380 
00385   virtual void AddUsingCell(CellIdentifier cellId);
00386 
00390   virtual void RemoveUsingCell(CellIdentifier cellId);
00391 
00397   virtual bool IsUsingCell(CellIdentifier cellId);
00398 
00402   virtual unsigned int GetNumberOfUsingCells(void);
00403 
00407   virtual UsingCellsContainerIterator UsingCellsBegin(void);
00408 
00412   virtual UsingCellsContainerIterator UsingCellsEnd(void);
00413     
00415   itkTypeMacro(CellInterface, LightObject);
00416 
00417 public:
00418   CellInterface() {}
00419   virtual ~CellInterface() {}
00423 //  bool GetPointPosition(PointsContainer*, int localId, Point*)=0;
00424 
00425 protected:
00427   UsingCellsContainer m_UsingCells;
00428 
00429 private:
00430   CellInterface(const Self&); //purposely not implemented
00431   void operator=(const Self&); //purposely not implemented  
00432 };
00433 
00434 
00452 template <int VPointDimension, typename TCoordRep,
00453   typename TInterpolationWeight, typename TPointIdentifier,
00454   typename TCellIdentifier, typename TCellFeatureIdentifier,
00455   typename TPoint, typename TPointsContainer,
00456   typename TUsingCellsContainer>
00457 class CellTraitsInfo
00458 {
00459 public:
00460   itkStaticConstMacro(PointDimension, unsigned int, VPointDimension);
00461   typedef TCoordRep               CoordRepType;
00462   typedef TInterpolationWeight    InterpolationWeightType;
00463   typedef TPointIdentifier        PointIdentifier;
00464   typedef TCellIdentifier         CellIdentifier;
00465   typedef TCellFeatureIdentifier  CellFeatureIdentifier;
00466   typedef TPoint                  PointType;
00467   typedef TPointsContainer        PointsContainer;
00468   typedef TUsingCellsContainer    UsingCellsContainer;
00469   typedef PointIdentifier*        PointIdIterator;
00470   typedef const PointIdentifier*  PointIdConstIterator;  
00471 };
00472 
00473 #define itkMakeCellTraitsMacro \
00474   CellTraitsInfo<itkGetStaticConstMacro(PointDimension), CoordRepType, \
00475                InterpolationWeightType,  \
00476                PointIdentifier, CellIdentifier, CellFeatureIdentifier, \
00477                PointType, PointsContainer, UsingCellsContainer>
00478 
00479 } // end namespace itk
00480 
00481 #ifndef ITK_MANUAL_INSTANTIATION
00482 #include "itkCellInterface.txx"
00483 #endif
00484 
00485 #endif

Generated at Wed May 24 22:54:17 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000