ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkCellInterface_h 00019 #define __itkCellInterface_h 00020 00021 #include "itkObject.h" 00022 #include <map> 00023 #include "itkCellInterfaceVisitor.h" 00024 #include "itkAutoPointer.h" 00025 #include "itkArray.h" 00026 00027 // Define a macro for CellInterface sub-classes to use 00028 // to define the Accept and GetTopologyId virtuals used 00029 // by the MultiVisitor class 00030 #define itkCellVisitMacro(TopologyId) \ 00031 static int GetTopologyId() \ 00032 { \ 00033 return TopologyId; \ 00034 } \ 00035 virtual void Accept(CellIdentifier cellid, typename CellInterface< PixelType, \ 00036 CellTraits >::MultiVisitor * mv) \ 00037 { \ 00038 typename CellInterfaceVisitor< PixelType, CellTraits >::Pointer v = \ 00039 mv->GetVisitor(TopologyId); \ 00040 if ( v ) \ 00041 { \ 00042 v->VisitFromCell(cellid, this); \ 00043 } \ 00044 } 00045 00046 // Define a macro for the common typedefs required by the 00047 // classes deriving form CellInterface (included). 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 00055 // Define a macro for the common typedefs required by the 00056 // classes deriving form CellInterface (excluded). 00057 #define itkCellInheritedTypedefs(superclassArg) \ 00058 typedef superclassArg Superclass; \ 00059 typedef typename Superclass::PixelType PixelType; \ 00060 typedef typename Superclass::CellType CellType; \ 00061 typedef typename Superclass::CellAutoPointer CellAutoPointer; \ 00062 typedef typename Superclass::CellConstAutoPointer CellConstAutoPointer; \ 00063 typedef typename Superclass::CellRawPointer CellRawPointer; \ 00064 typedef typename Superclass::CellConstRawPointer CellConstRawPointer; \ 00065 typedef typename Superclass::CellTraits CellTraits; \ 00066 typedef typename Superclass::CoordRepType CoordRepType; \ 00067 typedef typename Superclass::InterpolationWeightType \ 00068 InterpolationWeightType; \ 00069 typedef typename Superclass::PointIdentifier PointIdentifier; \ 00070 typedef typename Superclass::PointIdIterator PointIdIterator; \ 00071 typedef typename Superclass::PointIdConstIterator PointIdConstIterator; \ 00072 typedef typename Superclass::CellIdentifier CellIdentifier; \ 00073 typedef typename Superclass::CellFeatureIdentifier CellFeatureIdentifier; \ 00074 typedef typename Superclass::CellFeatureIdentifier CellFeatureCount; \ 00075 typedef typename Superclass::PointType PointType; \ 00076 typedef typename Superclass::VectorType VectorType; \ 00077 typedef typename Superclass::PointsContainer PointsContainer; \ 00078 typedef typename Superclass::UsingCellsContainer UsingCellsContainer; \ 00079 typedef typename Superclass::CellGeometry CellGeometry; \ 00080 typedef typename Superclass::ParametricCoordArrayType \ 00081 ParametricCoordArrayType; \ 00082 typedef typename Superclass::ShapeFunctionsArrayType \ 00083 ShapeFunctionsArrayType; \ 00084 itkStaticConstMacro(PointDimension, unsigned int, Superclass::PointDimension) 00085 00086 namespace itk 00087 { 00100 template< 00101 typename TPixelType, 00102 typename TCellTraits 00103 > 00104 class CellInterface 00105 { 00106 public: 00107 00109 itkCellCommonTypedefs(CellInterface); 00110 00112 typedef TPixelType PixelType; 00113 00115 typedef TCellTraits CellTraits; 00116 00118 typedef typename CellTraits::CoordRepType CoordRepType; 00119 typedef typename CellTraits::InterpolationWeightType InterpolationWeightType; 00120 typedef typename CellTraits::PointIdentifier PointIdentifier; 00121 typedef typename CellTraits::PointIdIterator PointIdIterator; 00122 typedef typename CellTraits::PointIdConstIterator PointIdConstIterator; 00123 typedef typename CellTraits::CellIdentifier CellIdentifier; 00124 typedef typename CellTraits::CellFeatureIdentifier CellFeatureIdentifier; 00125 typedef typename CellTraits::PointType PointType; 00126 typedef typename CellTraits::PointsContainer PointsContainer; 00127 typedef typename CellTraits::UsingCellsContainer UsingCellsContainer; 00128 00130 typedef typename PointType::VectorType VectorType; 00131 00133 itkStaticConstMacro(PointDimension, unsigned int, CellTraits::PointDimension); 00134 00136 typedef typename UsingCellsContainer::iterator UsingCellsContainerIterator; 00137 00139 typedef CellInterface CellType; 00140 typedef SelfAutoPointer CellAutoPointer; 00141 typedef ConstSelfAutoPointer CellConstAutoPointer; 00142 typedef RawPointer CellRawPointer; 00143 typedef ConstRawPointer CellConstRawPointer; 00144 00146 typedef CellFeatureIdentifier CellFeatureCount; 00147 00149 enum CellGeometry { VERTEX_CELL = 0, LINE_CELL, TRIANGLE_CELL, 00150 QUADRILATERAL_CELL, POLYGON_CELL, TETRAHEDRON_CELL, HEXAHEDRON_CELL, 00151 QUADRATIC_EDGE_CELL, QUADRATIC_TRIANGLE_CELL, 00152 LAST_ITK_CELL, MAX_ITK_CELLS = 255 }; 00153 00155 typedef Array< CoordRepType > ParametricCoordArrayType; 00156 typedef Array< InterpolationWeightType > ShapeFunctionsArrayType; 00157 00158 // static int GetNextUserCellId(); // never return > MAX_INTERFACE 00159 00168 class MultiVisitor:public LightObject 00169 { 00170 public: 00173 typedef CellInterfaceVisitor< TPixelType, TCellTraits > VisitorType; 00174 00176 typedef MultiVisitor Self; 00177 typedef SmartPointer< Self > Pointer; 00178 00180 //itkNewMacro(Self); 00181 static Pointer New(void) { Pointer smartPtr = new Self; smartPtr->UnRegister(); return smartPtr; } 00183 00185 itkTypeMacro(MultiVisitor, LightObject); 00186 00188 typedef typename VisitorType::Pointer VisitorPointer; 00189 typedef typename std::map< int, VisitorPointer >::value_type 00190 VisitorPointerValueType; 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, 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 } 00210 00211 void AddVisitor(VisitorType *v) 00212 { 00213 int id = v->GetCellTopologyId(); 00214 00215 if ( id <= LAST_ITK_CELL ) 00216 { 00217 m_Visitors[id] = v; 00218 } 00219 else 00220 { 00221 m_UserDefined.insert( VisitorPointerValueType(id, v) ); 00222 } 00223 } 00224 00225 virtual ~MultiVisitor() {} 00226 protected: 00227 VisitorPointer m_Visitors[LAST_ITK_CELL]; // fixed array set to the 00228 // size 00229 // from the enum 00230 std::map< int, VisitorPointer > m_UserDefined; // user defined cell types 00231 // go here 00232 }; 00233 00235 virtual void Accept(CellIdentifier cellId, MultiVisitor *) = 0; 00236 00239 virtual CellGeometry GetType(void) const = 0; 00240 00243 virtual void MakeCopy(CellAutoPointer &) const = 0; 00244 00246 virtual unsigned int GetDimension(void) const = 0; 00247 00249 virtual unsigned int GetInterpolationOrder(void) const; 00250 00252 virtual unsigned int GetNumberOfPoints(void) const = 0; 00253 00255 virtual CellFeatureCount GetNumberOfBoundaryFeatures(int dimension) const = 0; 00256 00258 virtual bool GetBoundaryFeature(int dimension, CellFeatureIdentifier, 00259 CellAutoPointer &) = 0; 00260 00264 virtual PointIdConstIterator GetPointIds(void) const; 00265 00269 virtual void SetPointIds(PointIdConstIterator first) = 0; 00270 00275 virtual void SetPointIds(PointIdConstIterator first, 00276 PointIdConstIterator last) = 0; 00277 00280 virtual void SetPointId(int localId, PointIdentifier) = 0; 00281 00283 virtual PointIdIterator PointIdsBegin(void) = 0; 00284 00287 virtual PointIdConstIterator PointIdsBegin(void) const = 0; 00288 00290 virtual PointIdIterator PointIdsEnd(void) = 0; 00291 00294 virtual PointIdConstIterator PointIdsEnd(void) const = 0; 00295 00297 typedef itk::Array<PointIdentifier> PointIdentifierContainerType; 00298 PointIdentifierContainerType GetPointIdsContainer() const; 00299 void SetPointIdsContainer( const PointIdentifierContainerType & ); 00301 00306 virtual bool GetClosestBoundary(CoordRepType[], bool *, CellAutoPointer &) 00307 { return false; } 00308 00325 virtual bool EvaluatePosition(CoordRepType *, 00326 PointsContainer *, 00327 CoordRepType *, 00328 CoordRepType[], 00329 double *, 00330 InterpolationWeightType *) 00331 { return bool(); } 00332 00336 virtual void EvaluateShapeFunctions( 00337 const ParametricCoordArrayType &, 00338 ShapeFunctionsArrayType &) const {} 00339 00355 virtual bool IntersectWithLine(CoordRepType[PointDimension], 00356 CoordRepType[PointDimension], 00357 CoordRepType, 00358 CoordRepType[PointDimension], 00359 CoordRepType *, 00360 CoordRepType[]) { return bool(); } 00361 00366 CoordRepType * GetBoundingBox(CoordRepType[PointDimension * 2]) { return NULL; } 00368 00370 CoordRepType GetBoundingBoxDiagonalLength2(void) { return NULL; } 00371 00384 virtual bool IntersectBoundingBoxWithLine(CoordRepType[PointDimension * 2], 00385 CoordRepType[PointDimension], 00386 CoordRepType[PointDimension], 00387 CoordRepType[PointDimension], 00388 CoordRepType *) { return bool(); } 00389 00395 virtual bool IsExplicitBoundary(void); 00396 00401 virtual void AddUsingCell(CellIdentifier cellId); 00402 00406 virtual void RemoveUsingCell(CellIdentifier cellId); 00407 00413 virtual bool IsUsingCell(CellIdentifier cellId); 00414 00418 virtual unsigned int GetNumberOfUsingCells(void); 00419 00420 #if !defined( CABLE_CONFIGURATION ) 00421 00424 virtual UsingCellsContainerIterator UsingCellsBegin(void); 00425 00429 virtual UsingCellsContainerIterator UsingCellsEnd(void); 00430 00431 #endif 00432 00434 itkTypeMacro(CellInterface, LightObject); 00435 public: 00436 CellInterface() {} 00437 virtual ~CellInterface() {} 00438 00442 // bool GetPointPosition(PointsContainer*, int localId, Point*)=0; 00443 protected: 00444 00446 UsingCellsContainer m_UsingCells; 00447 private: 00448 CellInterface(const Self &); //purposely not implemented 00449 void operator=(const Self &); //purposely not implemented 00450 }; 00452 00471 template< int VPointDimension, typename TCoordRep, 00472 typename TInterpolationWeight, typename TPointIdentifier, 00473 typename TCellIdentifier, typename TCellFeatureIdentifier, 00474 typename TPoint, typename TPointsContainer, 00475 typename TUsingCellsContainer > 00476 class CellTraitsInfo 00477 { 00478 public: 00479 itkStaticConstMacro(PointDimension, unsigned int, VPointDimension); 00480 typedef TCoordRep CoordRepType; 00481 typedef TInterpolationWeight InterpolationWeightType; 00482 typedef TPointIdentifier PointIdentifier; 00483 typedef TCellIdentifier CellIdentifier; 00484 typedef TCellFeatureIdentifier CellFeatureIdentifier; 00485 typedef TPoint PointType; 00486 typedef TPointsContainer PointsContainer; 00487 typedef TUsingCellsContainer UsingCellsContainer; 00488 typedef PointIdentifier * PointIdIterator; 00489 00490 typedef const PointIdentifier *PointIdConstIterator; 00491 }; 00492 00493 #define itkMakeCellTraitsMacro \ 00494 CellTraitsInfo < itkGetStaticConstMacro(PointDimension), CoordRepType, \ 00495 InterpolationWeightType, \ 00496 PointIdentifier, CellIdentifier, CellFeatureIdentifier, \ 00497 PointType, PointsContainer, UsingCellsContainer > 00498 } // end namespace itk 00499 00500 #if !defined( CABLE_CONFIGURATION ) 00501 #ifndef ITK_MANUAL_INSTANTIATION 00502 #include "itkCellInterface.hxx" 00503 #endif 00504 #endif 00505 00506 #endif 00507