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: 2009-04-25 12:27:38 $
00007   Version:   $Revision: 1.11 $
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   itkGetConstMacro( IsoSurfaceValue, ValueType);
00115 
00117   //  itkGetConstMacro( 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   
00150   void SetNarrowBandTotalRadius (float val)
00151     {
00152     if (m_NarrowBand->GetTotalRadius() != val)
00153       {
00154       m_NarrowBand->SetTotalRadius(val);
00155       this->Modified();
00156       }
00157     }
00159 
00161   float GetNarrowBandTotalRadius()
00162     {
00163     return m_NarrowBand->GetTotalRadius();
00164     }
00165 
00168   void SetNarrowBandInnerRadius (float val)
00169     {
00170     if (m_NarrowBand->GetInnerRadius() != val)
00171       {
00172       m_NarrowBand->SetInnerRadius(val);
00173       this->Modified();
00174       }
00175     }
00177 
00179   float GetNarrowBandInnerRadius()
00180     {
00181     return m_NarrowBand->GetInnerRadius();
00182     }
00183 
00189   virtual void CreateNarrowBand (){};
00190 
00191   virtual void SetNarrowBand(NarrowBandType * ptr)
00192     {
00193     if ( m_NarrowBand != ptr )
00194       {
00195       m_NarrowBand = ptr;
00196       this->Modified();
00197       }   
00198     }
00199   
00200   virtual void CopyInputToOutput ();
00201   
00202 protected:
00203   typename NarrowBandType::Pointer m_NarrowBand;
00204   NarrowBandImageFilterBase() 
00205     {
00206     m_NarrowBand = NarrowBandType::New();
00207     m_NarrowBand->SetTotalRadius(4);
00208     m_NarrowBand->SetInnerRadius(2);
00209     m_ReinitializationFrequency = 6;
00210     m_IsoSurfaceValue = 0.0;
00211     m_Step    = 0;
00212     m_Touched = false;
00213     m_Barrier = Barrier::New();
00214     }
00215   
00216   virtual ~NarrowBandImageFilterBase() {}
00217   void PrintSelf(std::ostream& os, Indent indent) const;
00218   
00221   struct ThreadRegionType 
00222     {
00223     typename NarrowBandType::Iterator first; // this is the actual first element
00224     typename NarrowBandType::Iterator last;  // this is one past the actual last //element
00225     };
00226 
00229   std::vector<RegionType> m_RegionList;
00230 
00233   void GetSplitRegion (int i, ThreadRegionType &splitRegion);
00234 
00239   virtual void Initialize();
00240 
00245   virtual void InitializeIteration();
00246 
00249   virtual void PostProcessOutput();
00250 
00251   /* This function clears all pixels from the narrow band */
00252   void ClearNarrowBand ();
00253   
00255   void WaitForAll();
00256 
00260   virtual void GenerateData();
00261 
00262   /* Variables to control reinitialization */
00263   unsigned int m_ReinitializationFrequency;
00264   unsigned int m_Step;
00265   bool         m_Touched;
00266   bool *       m_TouchedForThread;
00267   ValueType    m_IsoSurfaceValue;
00268   
00269   typename Barrier::Pointer m_Barrier;
00270 
00271 private:
00272   NarrowBandImageFilterBase(const Self&); //purposely not implemented
00273   void operator=(const Self&); //purposely not implemented
00274 
00277   struct NarrowBandImageFilterBaseThreadStruct
00278     {
00279     NarrowBandImageFilterBase *Filter;
00280     TimeStepType TimeStep;
00281     TimeStepType *TimeStepList;
00282     bool *ValidTimeStepList;
00283     };
00284 
00285   /* This class does not use AllocateUpdateBuffer to allocate memory for its 
00286    * narrow band. This is taken care of in SetNarrowBand, and InsertNarrowBandNode
00287    * functions. This function is here for compatability with the 
00288    * FiniteDifferenceSolver framework.
00289    */
00290   virtual void AllocateUpdateBuffer() {};
00291   
00292   
00294   static ITK_THREAD_RETURN_TYPE IterateThreaderCallback( void *arg );
00295 
00299   virtual void ThreadedIterate(void *arg, int threadId);
00300 
00304   virtual void ThreadedApplyUpdate(TimeStepType dt,
00305                                    const ThreadRegionType &regionToProcess,
00306                                    int threadId);
00307   virtual void ApplyUpdate(TimeStepType){}
00308 
00312   virtual TimeStepType ThreadedCalculateChange(const ThreadRegionType &regionToProcess,
00313                                                int threadId);
00314   virtual TimeStepType CalculateChange() {return 0;}
00316 
00317 };
00318 
00319 }// end namespace itk
00320 
00321 #ifndef ITK_MANUAL_INSTANTIATION
00322 #include "itkNarrowBandImageFilterBase.txx"
00323 #endif
00324 
00325 #endif
00326 

Generated at Mon Jul 12 2010 19:15:34 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000