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

itkNarrowBandImageFilterBase.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkNarrowBandImageFilterBase.h,v $
00005   Language:  C++
00006   Date:      $Date: 2003/09/10 14:28:52 $
00007   Version:   $Revision: 1.9 $
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 __itkNarrowBandImageFilterBase_h_
00018 #define __itkNarrowBandImageFilterBase_h_
00019 
00020 #include "itkFiniteDifferenceImageFilter.h"
00021 #include "itkMultiThreader.h"
00022 #include "itkNarrowBand.h"
00023 #include "itkBarrier.h"
00024 #include "itkObjectStore.h"
00025 
00026 namespace itk {
00027 
00065 template <class TInputImage, class TOutputImage>
00066 class NarrowBandImageFilterBase  
00067   : public FiniteDifferenceImageFilter<TInputImage, TOutputImage>
00068 {
00069 public:
00070 
00072   typedef NarrowBandImageFilterBase Self;
00073   typedef FiniteDifferenceImageFilter<TInputImage, TOutputImage> Superclass;
00074   typedef SmartPointer<Self>  Pointer;
00075   typedef SmartPointer<const Self>  ConstPointer;
00076 
00078   itkTypeMacro(NarrowBandImageFilterBase, ImageToImageFilter );
00079 
00081   typedef typename Superclass::InputImageType  InputImageType;
00082   typedef typename Superclass::OutputImageType OutputImageType;
00083   typedef typename Superclass::FiniteDifferenceFunctionType FiniteDifferenceFunctionType;
00084 
00087   itkStaticConstMacro(ImageDimension, unsigned int,Superclass::ImageDimension);
00088 
00091   typedef typename Superclass::PixelType PixelType;
00092 
00094   typedef typename Superclass::TimeStepType TimeStepType;
00095 
00097   typedef typename OutputImageType::IndexType IndexType;
00098 
00101   typedef typename OutputImageType::ValueType ValueType;
00102 
00104   typedef BandNode<IndexType,PixelType> BandNodeType;
00105 
00107   typedef NarrowBand<BandNodeType> NarrowBandType;
00108   typedef typename NarrowBandType::Pointer NarrowBandPointer;
00109   typedef typename NarrowBandType::RegionType RegionType;
00110 
00112   itkSetMacro( IsoSurfaceValue, ValueType);
00113   itkGetMacro( IsoSurfaceValue, ValueType);
00115 
00117   //  itkGetMacro( RMSChange, ValueType);
00118 
00123   void InsertNarrowBandNode (BandNodeType &node) 
00124   {
00125     m_NarrowBand->PushBack(node); // add new node 
00126     this->Modified();
00127   };
00128   void InsertNarrowBandNode (IndexType &index)
00129   {
00130     BandNodeType tmpnode;
00131     tmpnode.m_Index = index;
00132     m_NarrowBand->PushBack(tmpnode);
00133     this->Modified();
00134   };
00135   void InsertNarrowBandNode (IndexType &index, PixelType &value, signed char &nodestate)
00136   {
00137     BandNodeType tmpnode;
00138     tmpnode.m_Data = value;
00139     tmpnode.m_Index = index;
00140     tmpnode.m_NodeState = nodestate;
00142 
00143     m_NarrowBand->PushBack(tmpnode);
00144     this->Modified();
00145   }; 
00146   
00151   void SetNarrowBandTotalRadius (float val)
00152   {
00153     if (m_NarrowBand->GetTotalRadius() != val)
00154       {
00155       m_NarrowBand->SetTotalRadius(val);    
00156       this->Modified();
00157       }
00158   }
00160 
00162   float GetNarrowBandTotalRadius()
00163   {
00164     return m_NarrowBand->GetTotalRadius();
00165   }
00166 
00171   void SetNarrowBandInnerRadius (float val)
00172   {
00173     if (m_NarrowBand->GetInnerRadius() != val)
00174       {
00175       m_NarrowBand->SetInnerRadius(val);
00176       this->Modified();
00177       }
00178   }
00180 
00182   float GetNarrowBandInnerRadius()
00183   {
00184     return m_NarrowBand->GetInnerRadius();
00185   }
00186 
00192   virtual void CreateNarrowBand (){};
00193 
00194   virtual void SetNarrowBand(NarrowBandType * ptr)
00195   {
00196     
00197     if ( m_NarrowBand != ptr )
00198       {
00199       m_NarrowBand = ptr;
00200       this->Modified();
00201       }   
00202   };
00203   
00204   virtual void CopyInputToOutput ();
00205   
00206 protected:
00207   typename NarrowBandType::Pointer m_NarrowBand;
00208   NarrowBandImageFilterBase() 
00209   {
00210     m_NarrowBand = NarrowBandType::New();
00211     m_NarrowBand->SetTotalRadius(4);
00212     m_NarrowBand->SetInnerRadius(2);
00213     m_ReinitializationFrequency = 6;
00214     m_IsoSurfaceValue = 0.0;
00215     m_Step    = 0;
00216     m_Touched = false;
00217     m_Barrier = Barrier::New();
00218   }
00219   
00220   virtual ~NarrowBandImageFilterBase() {}
00221   void PrintSelf(std::ostream& os, Indent indent) const;
00222   
00225   struct ThreadRegionType 
00226   {
00227     typename NarrowBandType::Iterator first; // this is the actual first element
00228     typename NarrowBandType::Iterator last;  // this is one past the actual last //element
00229   };
00230 
00233   std::vector<RegionType> m_RegionList;
00234 
00237   void GetSplitRegion (int i, ThreadRegionType &splitRegion);
00238 
00243   virtual void Initialize();
00244 
00249   virtual void InitializeIteration();
00250 
00253   virtual void PostProcessOutput();
00254 
00255   /* This function clears all pixels from the narrow band */
00256   void ClearNarrowBand ();
00257   
00259   void WaitForAll();
00260 
00264   virtual void GenerateData();
00265 
00266   /* Variables to control reinitialization */
00267   unsigned int m_ReinitializationFrequency;
00268   unsigned int m_Step;
00269   bool m_Touched;
00270   bool * m_TouchedForThread;
00271   ValueType m_IsoSurfaceValue;
00272   
00273   typename Barrier::Pointer m_Barrier;
00274 
00275 private:
00276   NarrowBandImageFilterBase(const Self&); //purposely not implemented
00277   void operator=(const Self&); //purposely not implemented
00278 
00281   struct NarrowBandImageFilterBaseThreadStruct
00282   {
00283     NarrowBandImageFilterBase *Filter;
00284     TimeStepType TimeStep;
00285     TimeStepType *TimeStepList;
00286     bool *ValidTimeStepList;
00287   };
00288 
00289   /* This class does not use AllocateUpdateBuffer to allocate memory for its 
00290    * narrow band. This is taken care of in SetNarrowBand, and InsertNarrowBandNode
00291    * functions. This function is here for compatability with the 
00292    * FiniteDifferenceSolver framework.
00293    */
00294   virtual void AllocateUpdateBuffer() {};
00295   
00296   
00298   static ITK_THREAD_RETURN_TYPE IterateThreaderCallback( void *arg );
00299 
00303   virtual void ThreadedIterate(void *arg, int threadId);
00304 
00308   virtual void ThreadedApplyUpdate(TimeStepType dt,
00309                                    const ThreadRegionType &regionToProcess,
00310                                    int threadId);
00311   virtual void ApplyUpdate(TimeStepType){}
00312 
00316   virtual TimeStepType ThreadedCalculateChange(const ThreadRegionType &regionToProcess,
00317                                                int threadId);
00318   virtual TimeStepType CalculateChange() {return 0;}
00320 
00321 };
00322 
00323 }// end namespace itk
00324 
00325 #ifndef ITK_MANUAL_INSTANTIATION
00326 #include "itkNarrowBandImageFilterBase.txx"
00327 #endif
00328 
00329 #endif
00330 

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