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: 2007/04/06 12:50:58 $
00007   Version:   $Revision: 1.66 $
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::PointsContainer         PointsContainer; \
00086   typedef typename Superclass::UsingCellsContainer     UsingCellsContainer; \
00087   typedef typename Superclass::CellGeometry            CellGeometry;  \
00088   typedef typename Superclass::ParametricCoordArrayType  \
00089                                                   ParametricCoordArrayType;  \
00090   typedef typename Superclass::ShapeFunctionsArrayType   \
00091                                                    ShapeFunctionsArrayType;  \
00092   itkStaticConstMacro(PointDimension, unsigned int, Superclass::PointDimension)
00093  
00094 
00095 namespace itk
00096 {
00097 
00110 template <
00111   typename TPixelType,
00112   typename TCellTraits
00113   >
00114 class CellInterface
00115 {
00116 public:
00117 
00119   itkCellCommonTypedefs(CellInterface);
00120 
00122   typedef TPixelType                                PixelType;
00123 
00125   typedef TCellTraits                                 CellTraits;
00126 
00128   typedef typename CellTraits::CoordRepType            CoordRepType;
00129   typedef typename CellTraits::InterpolationWeightType InterpolationWeightType;
00130   typedef typename CellTraits::PointIdentifier         PointIdentifier;
00131   typedef typename CellTraits::PointIdIterator         PointIdIterator;
00132   typedef typename CellTraits::PointIdConstIterator    PointIdConstIterator;
00133   typedef typename CellTraits::CellIdentifier          CellIdentifier;
00134   typedef typename CellTraits::CellFeatureIdentifier   CellFeatureIdentifier;
00135   typedef typename CellTraits::PointType               PointType;
00136   typedef typename CellTraits::PointsContainer         PointsContainer;
00137   typedef typename CellTraits::UsingCellsContainer     UsingCellsContainer;
00138 
00140   itkStaticConstMacro(PointDimension, unsigned int,CellTraits::PointDimension);
00141 
00143   typedef typename UsingCellsContainer::iterator  UsingCellsContainerIterator;
00144 
00146   typedef CellInterface         CellType;
00147   typedef SelfAutoPointer       CellAutoPointer;
00148   typedef ConstSelfAutoPointer  CellConstAutoPointer;
00149   typedef RawPointer            CellRawPointer;
00150   typedef ConstRawPointer       CellConstRawPointer;
00151 
00153   typedef CellFeatureIdentifier  CellFeatureCount;
00154 
00156   enum CellGeometry {VERTEX_CELL=0, LINE_CELL, TRIANGLE_CELL, 
00157         QUADRILATERAL_CELL, POLYGON_CELL, TETRAHEDRON_CELL, HEXAHEDRON_CELL, 
00158         QUADRATIC_EDGE_CELL, QUADRATIC_TRIANGLE_CELL,
00159         LAST_ITK_CELL, MAX_ITK_CELLS=255};
00160 
00162   typedef Array<CoordRepType>                 ParametricCoordArrayType;
00163   typedef Array<InterpolationWeightType>      ShapeFunctionsArrayType;
00164 
00165   static int GetNextUserCellId(); // never return > MAX_INTERFACE
00166 
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     //itkNewMacro(Self);
00186     static  Pointer New(void) { Pointer smartPtr = new Self; smartPtr->UnRegister(); return smartPtr;}
00188 
00190     itkTypeMacro(MultiVisitor,LightObject);
00191 
00193     typedef typename VisitorType::Pointer       VisitorPointer;
00194     typedef typename std::map<int, VisitorPointer>::value_type 
00195                                                 VisitorPointerValueType;
00196 
00197   public:
00198     VisitorType * GetVisitor(int id)
00199       {
00200       if(id <= LAST_ITK_CELL)
00201         {
00202         return m_Visitors[id];
00203         }
00204       else
00205         {
00206         typename std::map<int, ITK_TYPENAME VisitorType::Pointer>::iterator
00207             pos = m_UserDefined.find(id);
00208         if(pos != m_UserDefined.end())
00209           {
00210           return (*pos).second;
00211           }
00212         }
00213         return 0;
00214       }
00215 
00216     void AddVisitor(VisitorType* v)
00217       {
00218       int id = v->GetCellTopologyId();
00219       if(id <= LAST_ITK_CELL)
00220         {
00221         m_Visitors[id] = v;
00222         }
00223       else
00224         {
00225         m_UserDefined.insert(VisitorPointerValueType(id,v));
00226         }
00227       }
00228     virtual ~MultiVisitor() {}
00229 
00230   protected:
00231     VisitorPointer m_Visitors[LAST_ITK_CELL]; // fixed array set to the size 
00232                                               // from the enum
00233     std::map<int,VisitorPointer> m_UserDefined; // user defined cell types 
00234                                                 // go here
00235   };
00236 
00238   virtual void Accept(unsigned long cellId, MultiVisitor*)= 0; 
00239 
00242   virtual CellGeometry GetType(void) const =0;
00243 
00246   virtual void MakeCopy( CellAutoPointer & ) const = 0;
00247 
00249   virtual unsigned int GetDimension(void) const=0;
00250 
00252   virtual unsigned int GetInterpolationOrder(void) const;
00253 
00255   virtual unsigned int GetNumberOfPoints(void) const=0;
00256 
00258   virtual CellFeatureCount GetNumberOfBoundaryFeatures(int dimension) const =0;
00259 
00261   virtual bool GetBoundaryFeature(int dimension, CellFeatureIdentifier, 
00262                                                         CellAutoPointer & )=0;
00263 
00267   virtual PointIdConstIterator GetPointIds(void) const;
00268 
00272   virtual void SetPointIds(PointIdConstIterator first)=0;
00273 
00278   virtual void SetPointIds(PointIdConstIterator first,
00279                            PointIdConstIterator last)=0;
00280 
00283   virtual void SetPointId(int localId, PointIdentifier)=0;
00284 
00286   virtual PointIdIterator PointIdsBegin(void)=0;
00287 
00290   virtual PointIdConstIterator PointIdsBegin(void) const =0;
00291 
00293   virtual PointIdIterator PointIdsEnd(void)=0;
00294 
00297   virtual PointIdConstIterator PointIdsEnd(void) const =0;
00298 
00303   virtual bool GetClosestBoundary(CoordRepType [], bool* , CellAutoPointer &) 
00304     {return false;}
00305 
00322   virtual bool EvaluatePosition(CoordRepType* ,
00323                                 PointsContainer* ,
00324                                 CoordRepType* ,
00325                                 CoordRepType [],
00326                                 double *,
00327                                 InterpolationWeightType*)
00328     {return bool();}
00329 
00333   virtual void EvaluateShapeFunctions( 
00334                           const ParametricCoordArrayType &,
00335                                 ShapeFunctionsArrayType  &) const {}
00336 
00352   virtual bool IntersectWithLine(CoordRepType [PointDimension],
00353                                  CoordRepType [PointDimension],
00354                                  CoordRepType ,
00355                                  CoordRepType [PointDimension],
00356                                  CoordRepType*,
00357                                  CoordRepType []) {return bool();}
00358 
00363   CoordRepType* GetBoundingBox(CoordRepType [PointDimension*2]) {return NULL;}
00365 
00367   CoordRepType GetBoundingBoxDiagonalLength2(void) {return NULL;}
00368 
00381   virtual bool IntersectBoundingBoxWithLine(CoordRepType [PointDimension*2],
00382                                             CoordRepType [PointDimension],
00383                                             CoordRepType [PointDimension],
00384                                             CoordRepType [PointDimension],
00385                                             CoordRepType* ) {return bool();}
00386 
00392   virtual bool IsExplicitBoundary(void);
00393 
00398   virtual void AddUsingCell(CellIdentifier cellId);
00399 
00403   virtual void RemoveUsingCell(CellIdentifier cellId);
00404 
00410   virtual bool IsUsingCell(CellIdentifier cellId);
00411 
00415   virtual unsigned int GetNumberOfUsingCells(void);
00416 
00420   virtual UsingCellsContainerIterator UsingCellsBegin(void);
00421 
00425   virtual UsingCellsContainerIterator UsingCellsEnd(void);
00426 
00428   itkTypeMacro(CellInterface, LightObject);
00429 
00430 public:
00431   CellInterface() {}
00432   virtual ~CellInterface() {}
00436 //  bool GetPointPosition(PointsContainer*, int localId, Point*)=0;
00437 
00438 protected:
00440   UsingCellsContainer m_UsingCells;
00441 
00442 private:
00443   CellInterface(const Self&); //purposely not implemented
00444   void operator=(const Self&); //purposely not implemented  
00445 };
00446 
00447 
00465 template <int VPointDimension, typename TCoordRep,
00466   typename TInterpolationWeight, typename TPointIdentifier,
00467   typename TCellIdentifier, typename TCellFeatureIdentifier,
00468   typename TPoint, typename TPointsContainer,
00469   typename TUsingCellsContainer>
00470 class CellTraitsInfo
00471 {
00472 public:
00473   itkStaticConstMacro(PointDimension, unsigned int, VPointDimension);
00474   typedef TCoordRep               CoordRepType;
00475   typedef TInterpolationWeight    InterpolationWeightType;
00476   typedef TPointIdentifier        PointIdentifier;
00477   typedef TCellIdentifier         CellIdentifier;
00478   typedef TCellFeatureIdentifier  CellFeatureIdentifier;
00479   typedef TPoint                  PointType;
00480   typedef TPointsContainer        PointsContainer;
00481   typedef TUsingCellsContainer    UsingCellsContainer;
00482   typedef PointIdentifier*        PointIdIterator;
00483   typedef const PointIdentifier*  PointIdConstIterator;  
00484 };
00485 
00486 #define itkMakeCellTraitsMacro \
00487   CellTraitsInfo<itkGetStaticConstMacro(PointDimension), CoordRepType, \
00488                InterpolationWeightType,  \
00489                PointIdentifier, CellIdentifier, CellFeatureIdentifier, \
00490                PointType, PointsContainer, UsingCellsContainer>
00491 
00492 } // end namespace itk
00493 
00494 #ifndef ITK_MANUAL_INSTANTIATION
00495 #include "itkCellInterface.txx"
00496 #endif
00497 
00498 #endif
00499 

Generated at Sun Sep 23 12:06:39 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000