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

itkMultiphaseSparseFiniteDifferenceImageFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkMultiphaseSparseFiniteDifferenceImageFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-09-08 20:09:41 $
00007   Version:   $Revision: 1.14 $
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 
00018 #ifndef __itkMultiphaseSparseFiniteDifferenceImageFilter_h
00019 #define __itkMultiphaseSparseFiniteDifferenceImageFilter_h
00020 
00021 #include "itkMultiphaseFiniteDifferenceImageFilter.h"
00022 #include "itkMultiThreader.h"
00023 #include "itkSparseFieldLayer.h"
00024 #include "itkObjectStore.h"
00025 #include "itkNeighborhoodIterator.h"
00026 #include "itkZeroCrossingImageFilter.h"
00027 #include "itkImageRegionIterator.h"
00028 #include "itkImageRegionConstIterator.h"
00029 #include "itkShiftScaleImageFilter.h"
00030 #include "itkNeighborhoodAlgorithm.h"
00031 #include "itkSparseFieldLevelSetImageFilter.h"
00032 
00033 #include <vector>
00034 
00035 namespace itk {
00179 template < class TInputImage, class TFeatureImage, class TOutputImage, class TFunction,
00180   typename TIdCell = unsigned int >
00181 class ITK_EXPORT MultiphaseSparseFiniteDifferenceImageFilter :
00182   public MultiphaseFiniteDifferenceImageFilter< TInputImage,
00183   TFeatureImage, TOutputImage, TFunction, TIdCell >
00184 {
00185 public:
00186 
00188   typedef MultiphaseSparseFiniteDifferenceImageFilter     Self;
00189   typedef MultiphaseFiniteDifferenceImageFilter< TInputImage,
00190     TFeatureImage, TOutputImage, TFunction, TIdCell >     Superclass;
00191   typedef SmartPointer<Self>                              Pointer;
00192   typedef SmartPointer<const Self>                        ConstPointer;
00193 
00195   itkNewMacro(Self);
00196 
00198   itkTypeMacro( MultiphaseSparseFiniteDifferenceImageFilter, MultiphaseFiniteDifferenceImageFilter );
00199 
00200   itkStaticConstMacro( ImageDimension, unsigned int, Superclass::ImageDimension );
00201 
00203   typedef typename Superclass::TimeStepType               TimeStepType;
00204 
00206   typedef typename Superclass::InputImageType             InputImageType;
00207   typedef typename Superclass::InputImagePointer          InputImagePointer;
00208   typedef typename Superclass::InputRegionType            InputRegionType;
00209   typedef typename Superclass::InputSizeType              InputSizeType;
00210   typedef typename Superclass::InputSizeValueType         InputSizeValueType;
00211   typedef typename Superclass::InputIndexType             InputIndexType;
00212   typedef typename Superclass::InputIndexValueType        InputIndexValueType;
00213   typedef typename Superclass::InputPixelType             InputPixelType;
00214   typedef typename Superclass::InputPointType             InputPointType;
00215   typedef typename Superclass::InputSpacingType           InputSpacingType;
00216 
00217   typedef typename Superclass::FeatureImageType           FeatureImageType;
00218   typedef typename Superclass::FeatureSizeType            FeatureSizeType;
00219   typedef typename Superclass::FeatureImagePointer        FeatureImagePointer;
00220   typedef typename Superclass::FeatureRegionType          FeatureRegionType;
00221   typedef typename Superclass::FeatureSpacingType         FeatureSpacingType;
00222   typedef typename Superclass::FeaturePointType           FeaturePointType;
00223 
00224   typedef typename Superclass::OutputImageType            OutputImageType;
00225   typedef typename Superclass::OutputImagePointer         OutputImagePointer;
00226   typedef typename Superclass::OutputRegionType           OutputRegionType;
00227   typedef typename Superclass::OutputSizeType             OutputSizeType;
00228   typedef typename Superclass::OutputIndexType            OutputIndexType;
00229   typedef typename Superclass::OutputIndexValueType       OutputIndexValueType;
00230   typedef typename Superclass::OutputPixelType            OutputPixelType;
00231 
00232   typedef typename InputImageType::ValueType              ValueType;
00233   typedef typename Superclass::IdCellType                 IdCellType;
00234 
00235   typedef typename Superclass::FiniteDifferenceFunctionType
00236     FiniteDifferenceFunctionType;
00237   typedef typename Superclass::FiniteDifferenceFunctionPointer
00238     FiniteDifferenceFunctionPointer;
00239   typedef typename FiniteDifferenceFunctionType::FloatOffsetType
00240     FiniteDifferenceFunctionFloatOffsetType;
00241 
00243   typedef SparseFieldLevelSetNode< OutputIndexType >    LayerNodeType;
00244 
00246   typedef SparseFieldLayer< LayerNodeType >             LayerType;
00247   typedef typename LayerType::Pointer                   LayerPointerType;
00248   typedef typename LayerType::Iterator                  LayerIterator;
00249   typedef typename LayerType::ConstIterator             LayerConstIterator;
00250 
00252   typedef std::vector< LayerPointerType >               LayerListType;
00253   typedef typename LayerListType::iterator              LayerListIterator;
00254   typedef typename LayerListType::const_iterator        LayerListConstIterator;
00255 
00256 
00258   typedef signed char                                   StatusType;
00259 
00262   typedef Image< StatusType, itkGetStaticConstMacro(ImageDimension) >
00263                                                         StatusImageType;
00264   typedef typename StatusImageType::Pointer             StatusImagePointer;
00265 
00266   typedef ZeroCrossingImageFilter< InputImageType, InputImageType>
00267     ZeroCrossingFilterType;
00268   typedef typename ZeroCrossingFilterType::Pointer
00269     ZeroCrossingFilterPointer;
00270 
00271   typedef NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< StatusImageType > BFCType;
00272 
00275   typedef ObjectStore< LayerNodeType >            LayerNodeStorageType;
00276   typedef typename LayerNodeStorageType::Pointer  LayerNodeStoragePointer;
00277 
00279   typedef std::vector< ValueType >                  UpdateBufferType;
00280   typedef typename UpdateBufferType::const_iterator UpdateBufferConstIterator;
00281 
00282   typedef SparseFieldCityBlockNeighborList<
00283     NeighborhoodIterator<OutputImageType> >       NeighborListType;
00284   typedef typename NeighborListType::OffsetType   OffsetType;
00285 
00289   itkSetMacro( NumberOfLayers, unsigned int );
00290   itkGetConstMacro( NumberOfLayers, unsigned int );
00292 
00294   itkSetMacro( IsoSurfaceValue, ValueType );
00295   itkGetConstMacro( IsoSurfaceValue, ValueType );
00297 
00302   itkSetMacro(InterpolateSurfaceLocation, bool);
00303   itkGetConstMacro(InterpolateSurfaceLocation, bool);
00305 
00307   void InterpolateSurfaceLocationOn()
00308   { this->SetInterpolateSurfaceLocation( true ); }
00309   void InterpolateSurfaceLocationOff()
00310   { this->SetInterpolateSurfaceLocation( false ); }
00312 
00313   void SetFunctionCount( const IdCellType& n )
00314     {
00315     this->Superclass::SetFunctionCount( n );
00316 
00317     m_SparseData.resize( this->m_FunctionCount, 0 );
00318 
00319     for( IdCellType i = 0; i < this->m_FunctionCount; i++ )
00320       {
00321       m_SparseData[i] = new SparseDataStruct( i );
00322       }
00323     }
00324 
00325 
00326 #ifdef ITK_USE_CONCEPT_CHECKING
00327 
00328   itkConceptMacro(OutputEqualityComparableCheck,
00329     (Concept::EqualityComparable<typename TOutputImage::PixelType>));
00330   itkConceptMacro(DoubleConvertibleToOutputCheck,
00331     (Concept::Convertible<double, typename TOutputImage::PixelType>));
00332   itkConceptMacro(OutputOStreamWritableCheck,
00333     (Concept::OStreamWritable<typename TOutputImage::PixelType>));
00334 
00336 #endif
00337 
00338 protected:
00339   MultiphaseSparseFiniteDifferenceImageFilter();
00340   ~MultiphaseSparseFiniteDifferenceImageFilter()
00341     {
00342     while( !m_SparseData.empty() )
00343       {
00344       if( m_SparseData.back() )
00345         {
00346         delete m_SparseData.back();
00347         }
00348       m_SparseData.pop_back();
00349       }
00350     }
00351 
00352   virtual void PrintSelf(std::ostream& os, Indent indent) const;
00353 
00354   // This data structure is created for each phase
00355   struct SparseDataStruct
00356     {
00357     SparseDataStruct( const IdCellType& index )
00358       {
00359       m_LayerNodeStore = LayerNodeStorageType::New();
00360       m_LayerNodeStore->SetGrowthStrategyToExponential();
00361       m_Index = index;
00362       }
00363 
00368     LayerListType m_Layers;
00369 
00371     StatusImagePointer m_StatusImage;
00372 
00374     LayerNodeStoragePointer m_LayerNodeStore;
00375 
00378     UpdateBufferType m_UpdateBuffer;
00379 
00380     IdCellType m_Index;
00381     };
00382 
00384   NeighborListType m_NeighborList;
00385 
00387   std::vector< ValueType > m_PixelDistance;
00388 
00393   inline virtual ValueType CalculateUpdateValue(
00394     const OutputIndexType &itkNotUsed(idx),
00395     const TimeStepType &dt,
00396     const ValueType &value,
00397     const ValueType &change)
00398     {
00399     return (value + dt * change);
00400     }
00401 
00405   virtual void PostProcessOutput();
00406 
00411   virtual void InitializeBackgroundPixels();
00412 
00414   void Initialize();
00415 
00420   void CopyInputToOutput();
00421 
00423   void AllocateUpdateBuffer(){}
00424 
00427   void ApplyUpdate(TimeStepType dt);
00428 
00431   TimeStepType CalculateChange();
00432 
00436   void ConstructLayer(SparseDataStruct *sparsePtr, StatusType from, StatusType
00437 to);
00438 
00443   void ConstructActiveLayer();
00444 
00446   void InitializeActiveLayerValues();
00447 
00450   void InitializeBackgroundConstants();
00451 
00459   void PropagateLayerValues(SparseDataStruct *sparsePtr, StatusType from,
00460     StatusType to, StatusType promote, int InOrOut);
00461 
00466   void PropagateAllLayerValues();
00467 
00468   void PropagateFunctionLayerValues( unsigned int functionIndex );
00469 
00473   void UpdateActiveLayerValues( TimeStepType dt, LayerType *StatusUpList,
00474     LayerType *StatusDownList );
00475 
00477   void ProcessStatusList( LayerType *InputList, LayerType *OutputList,
00478     StatusType ChangeToStatus, StatusType SearchForStatus);
00479 
00481   void ProcessOutsideList(LayerType *OutsideList, StatusType ChangeToStatus);
00482 
00483   void InitializeIteration();
00484 
00485   virtual void UpdatePixel(unsigned int itkNotUsed(functionIndex), unsigned int itkNotUsed(idx),
00486     NeighborhoodIterator< InputImageType> & itkNotUsed(iterator), ValueType & itkNotUsed(newValue),
00487     bool & itkNotUsed(status) ){};
00488 
00489   itkGetConstMacro( ValueZero, ValueType );
00490   itkGetConstMacro( ValueOne, ValueType );
00491 
00494   static double m_ConstantGradientValue;
00495 
00497   static const ValueType m_ValueOne;
00498 
00500   static const ValueType m_ValueZero;
00501 
00504   static const StatusType m_StatusChanging;
00505 
00508   static const StatusType m_StatusActiveChangingUp;
00509 
00512   static const StatusType m_StatusActiveChangingDown;
00513 
00516   static const StatusType m_StatusBoundaryPixel;
00517 
00520   static const StatusType m_StatusNull;
00521 
00522   std::vector< SparseDataStruct* > m_SparseData;
00523 
00527   unsigned int m_NumberOfLayers;
00528 
00530   ValueType m_IsoSurfaceValue;
00531 
00533   ValueType m_BackgroundValue;
00534 
00539   bool m_InterpolateSurfaceLocation;
00540 
00541 private:
00542   MultiphaseSparseFiniteDifferenceImageFilter(const Self&);
00543   void operator=(const Self&);      //purposely not implemented
00544 
00545   unsigned int    m_CurrentFunctionIndex;
00546 
00547   double       m_RMSSum;
00548   unsigned int m_RMSCounter;
00549 
00552   bool m_BoundsCheckingActive;
00553 };
00554 
00555 
00556 } // end namespace itk
00557 
00558 #ifndef ITK_MANUAL_INSTANTIATION
00559 #include "itkMultiphaseSparseFiniteDifferenceImageFilter.txx"
00560 #endif
00561 
00562 #endif
00563 

Generated at Tue Sep 15 04:04:10 2009 for ITK by doxygen 1.5.8 written by Dimitri van Heesch, © 1997-2000