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: 2009-08-08 20:13:35 $
00007   Version:   $Revision: 1.72 $
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 
00056 
00057 // Define a macro for the common typedefs required by the 
00058 // classes deriving form CellInterface (excluded).
00059 // This wouldn't be necessary if SGI compilers 
00060 // were able to inherit types.
00061 #define itkCellInheritedTypedefs( superclassArg ) \
00062   typedef superclassArg                                Superclass; \
00063   typedef typename Superclass::PixelType               PixelType;  \
00064   typedef typename Superclass::CellType                CellType;  \
00065   typedef typename Superclass::CellAutoPointer         CellAutoPointer;  \
00066   typedef typename Superclass::CellConstAutoPointer    CellConstAutoPointer;  \
00067   typedef typename Superclass::CellRawPointer          CellRawPointer;  \
00068   typedef typename Superclass::CellConstRawPointer     CellConstRawPointer;  \
00069   typedef typename Superclass::CellTraits              CellTraits;  \
00070   typedef typename Superclass::CoordRepType            CoordRepType;  \
00071   typedef typename Superclass::InterpolationWeightType \
00072                                                      InterpolationWeightType; \
00073   typedef typename Superclass::PointIdentifier         PointIdentifier; \
00074   typedef typename Superclass::PointIdIterator         PointIdIterator; \
00075   typedef typename Superclass::PointIdConstIterator    PointIdConstIterator; \
00076   typedef typename Superclass::CellIdentifier          CellIdentifier; \
00077   typedef typename Superclass::CellFeatureIdentifier   CellFeatureIdentifier; \
00078   typedef typename Superclass::CellFeatureIdentifier   CellFeatureCount; \
00079   typedef typename Superclass::PointType               PointType; \
00080   typedef typename Superclass::VectorType              VectorType; \
00081   typedef typename Superclass::PointsContainer         PointsContainer; \
00082   typedef typename Superclass::UsingCellsContainer     UsingCellsContainer; \
00083   typedef typename Superclass::CellGeometry            CellGeometry;  \
00084   typedef typename Superclass::ParametricCoordArrayType  \
00085                                                   ParametricCoordArrayType;  \
00086   typedef typename Superclass::ShapeFunctionsArrayType   \
00087                                                    ShapeFunctionsArrayType;  \
00088   itkStaticConstMacro(PointDimension, unsigned int, Superclass::PointDimension)
00089  
00090 
00091 namespace itk
00092 {
00093 
00106 template <
00107   typename TPixelType,
00108   typename TCellTraits
00109   >
00110 class CellInterface
00111 {
00112 public:
00113 
00115   itkCellCommonTypedefs(CellInterface);
00116 
00118   typedef TPixelType                                PixelType;
00119 
00121   typedef TCellTraits                                 CellTraits;
00122 
00124   typedef typename CellTraits::CoordRepType            CoordRepType;
00125   typedef typename CellTraits::InterpolationWeightType InterpolationWeightType;
00126   typedef typename CellTraits::PointIdentifier         PointIdentifier;
00127   typedef typename CellTraits::PointIdIterator         PointIdIterator;
00128   typedef typename CellTraits::PointIdConstIterator    PointIdConstIterator;
00129   typedef typename CellTraits::CellIdentifier          CellIdentifier;
00130   typedef typename CellTraits::CellFeatureIdentifier   CellFeatureIdentifier;
00131   typedef typename CellTraits::PointType               PointType;
00132   typedef typename CellTraits::PointsContainer         PointsContainer;
00133   typedef typename CellTraits::UsingCellsContainer     UsingCellsContainer;
00134 
00136   typedef typename PointType::VectorType               VectorType;
00137     
00139   itkStaticConstMacro(PointDimension, unsigned int,CellTraits::PointDimension);
00140 
00142   typedef typename UsingCellsContainer::iterator  UsingCellsContainerIterator;
00143 
00145   typedef CellInterface         CellType;
00146   typedef SelfAutoPointer       CellAutoPointer;
00147   typedef ConstSelfAutoPointer  CellConstAutoPointer;
00148   typedef RawPointer            CellRawPointer;
00149   typedef ConstRawPointer       CellConstRawPointer;
00150 
00152   typedef CellFeatureIdentifier  CellFeatureCount;
00153 
00155   enum CellGeometry {VERTEX_CELL=0, LINE_CELL, TRIANGLE_CELL, 
00156         QUADRILATERAL_CELL, POLYGON_CELL, TETRAHEDRON_CELL, HEXAHEDRON_CELL, 
00157         QUADRATIC_EDGE_CELL, QUADRATIC_TRIANGLE_CELL,
00158         LAST_ITK_CELL, MAX_ITK_CELLS=255};
00159 
00161   typedef Array<CoordRepType>                 ParametricCoordArrayType;
00162   typedef Array<InterpolationWeightType>      ShapeFunctionsArrayType;
00163 
00164 //  static int GetNextUserCellId(); // never return > MAX_INTERFACE
00165 
00172   class MultiVisitor : public LightObject
00173     {
00174     public:
00177     typedef CellInterfaceVisitor<TPixelType, TCellTraits> VisitorType;
00178 
00180     typedef MultiVisitor        Self;
00181     typedef SmartPointer<Self>  Pointer;
00182 
00184     //itkNewMacro(Self);
00185     static  Pointer New(void) { Pointer smartPtr = new Self; smartPtr->UnRegister(); return smartPtr;}
00187 
00189     itkTypeMacro(MultiVisitor,LightObject);
00190 
00192     typedef typename VisitorType::Pointer       VisitorPointer;
00193     typedef typename std::map<int, VisitorPointer>::value_type 
00194                                                 VisitorPointerValueType;
00195 
00196   public:
00197     VisitorType * GetVisitor(int id)
00198       {
00199       if(id <= LAST_ITK_CELL)
00200         {
00201         return m_Visitors[id];
00202         }
00203       else
00204         {
00205         typename std::map<int, ITK_TYPENAME VisitorType::Pointer>::iterator
00206             pos = m_UserDefined.find(id);
00207         if(pos != m_UserDefined.end())
00208           {
00209           return (*pos).second;
00210           }
00211         }
00212         return 0;
00213       }
00214 
00215     void AddVisitor(VisitorType* v)
00216       {
00217       int id = v->GetCellTopologyId();
00218       if(id <= LAST_ITK_CELL)
00219         {
00220         m_Visitors[id] = v;
00221         }
00222       else
00223         {
00224         m_UserDefined.insert(VisitorPointerValueType(id,v));
00225         }
00226       }
00227     virtual ~MultiVisitor() {}
00228 
00229   protected:
00230     VisitorPointer m_Visitors[LAST_ITK_CELL]; // fixed array set to the size 
00231                                               // from the enum
00232     std::map<int,VisitorPointer> m_UserDefined; // user defined cell types 
00233                                                 // go here
00234   };
00235 
00237   virtual void Accept(unsigned long cellId, MultiVisitor*)= 0; 
00238 
00241   virtual CellGeometry GetType(void) const =0;
00242 
00245   virtual void MakeCopy( CellAutoPointer & ) const = 0;
00246 
00248   virtual unsigned int GetDimension(void) const=0;
00249 
00251   virtual unsigned int GetInterpolationOrder(void) const;
00252 
00254   virtual unsigned int GetNumberOfPoints(void) const=0;
00255 
00257   virtual CellFeatureCount GetNumberOfBoundaryFeatures(int dimension) const =0;
00258 
00260   virtual bool GetBoundaryFeature(int dimension, CellFeatureIdentifier, 
00261                                                         CellAutoPointer & )=0;
00262 
00266   virtual PointIdConstIterator GetPointIds(void) const;
00267 
00271   virtual void SetPointIds(PointIdConstIterator first)=0;
00272 
00277   virtual void SetPointIds(PointIdConstIterator first,
00278                            PointIdConstIterator last)=0;
00279 
00282   virtual void SetPointId(int localId, PointIdentifier)=0;
00283 
00285   virtual PointIdIterator PointIdsBegin(void)=0;
00286 
00289   virtual PointIdConstIterator PointIdsBegin(void) const =0;
00290 
00292   virtual PointIdIterator PointIdsEnd(void)=0;
00293 
00296   virtual PointIdConstIterator PointIdsEnd(void) const =0;
00297 
00302   virtual bool GetClosestBoundary(CoordRepType [], bool* , CellAutoPointer &) 
00303     {return false;}
00304 
00321   virtual bool EvaluatePosition(CoordRepType* ,
00322                                 PointsContainer* ,
00323                                 CoordRepType* ,
00324                                 CoordRepType [],
00325                                 double *,
00326                                 InterpolationWeightType*)
00327     {return bool();}
00328 
00332   virtual void EvaluateShapeFunctions( 
00333                           const ParametricCoordArrayType &,
00334                                 ShapeFunctionsArrayType  &) const {}
00335 
00351   virtual bool IntersectWithLine(CoordRepType [PointDimension],
00352                                  CoordRepType [PointDimension],
00353                                  CoordRepType ,
00354                                  CoordRepType [PointDimension],
00355                                  CoordRepType*,
00356                                  CoordRepType []) {return bool();}
00357 
00362   CoordRepType* GetBoundingBox(CoordRepType [PointDimension*2]) {return NULL;}
00364 
00366   CoordRepType GetBoundingBoxDiagonalLength2(void) {return NULL;}
00367 
00380   virtual bool IntersectBoundingBoxWithLine(CoordRepType [PointDimension*2],
00381                                             CoordRepType [PointDimension],
00382                                             CoordRepType [PointDimension],
00383                                             CoordRepType [PointDimension],
00384                                             CoordRepType* ) {return bool();}
00385 
00391   virtual bool IsExplicitBoundary(void);
00392 
00397   virtual void AddUsingCell(CellIdentifier cellId);
00398 
00402   virtual void RemoveUsingCell(CellIdentifier cellId);
00403 
00409   virtual bool IsUsingCell(CellIdentifier cellId);
00410 
00414   virtual unsigned int GetNumberOfUsingCells(void);
00415 
00416 #if !defined(CABLE_CONFIGURATION)
00417 
00420   virtual UsingCellsContainerIterator UsingCellsBegin(void);
00421 
00425   virtual UsingCellsContainerIterator UsingCellsEnd(void);
00426 #endif
00427 
00429   itkTypeMacro(CellInterface, LightObject);
00430 
00431 public:
00432   CellInterface() {}
00433   virtual ~CellInterface() {}
00437 //  bool GetPointPosition(PointsContainer*, int localId, Point*)=0;
00438 
00439 protected:
00441   UsingCellsContainer m_UsingCells;
00442 
00443 private:
00444   CellInterface(const Self&); //purposely not implemented
00445   void operator=(const Self&); //purposely not implemented  
00446 };
00447 
00448 
00466 template <int VPointDimension, typename TCoordRep,
00467   typename TInterpolationWeight, typename TPointIdentifier,
00468   typename TCellIdentifier, typename TCellFeatureIdentifier,
00469   typename TPoint, typename TPointsContainer,
00470   typename TUsingCellsContainer>
00471 class CellTraitsInfo
00472 {
00473 public:
00474   itkStaticConstMacro(PointDimension, unsigned int, VPointDimension);
00475   typedef TCoordRep               CoordRepType;
00476   typedef TInterpolationWeight    InterpolationWeightType;
00477   typedef TPointIdentifier        PointIdentifier;
00478   typedef TCellIdentifier         CellIdentifier;
00479   typedef TCellFeatureIdentifier  CellFeatureIdentifier;
00480   typedef TPoint                  PointType;
00481   typedef TPointsContainer        PointsContainer;
00482   typedef TUsingCellsContainer    UsingCellsContainer;
00483   typedef PointIdentifier*        PointIdIterator;
00484   typedef const PointIdentifier*  PointIdConstIterator;  
00485 };
00486 
00487 #define itkMakeCellTraitsMacro \
00488   CellTraitsInfo<itkGetStaticConstMacro(PointDimension), CoordRepType, \
00489                InterpolationWeightType,  \
00490                PointIdentifier, CellIdentifier, CellFeatureIdentifier, \
00491                PointType, PointsContainer, UsingCellsContainer>
00492 
00493 } // end namespace itk
00494 
00495 #if !defined(CABLE_CONFIGURATION)
00496 # ifndef ITK_MANUAL_INSTANTIATION
00497 #include "itkCellInterface.txx"
00498 #endif
00499 #endif
00500 
00501 #endif
00502 

Generated at Mon Jul 12 2010 18:00:07 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000