KWStyle - itkDenseFiniteDifferenceImageFilter.h
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkDenseFiniteDifferenceImageFilter.h.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:34 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notices for more information.
15
16 =========================================================================*/
17 DEF #ifndef __itkDenseFiniteDifferenceImageFilter_h_
18 DEF #define __itkDenseFiniteDifferenceImageFilter_h_
19
20 #include "itkFiniteDifferenceImageFilter.h"
21 #include "itkMultiThreader.h"
22
23 namespace itk {
24
25 /**
26  * \class DenseFiniteDifferenceImageFilter
27  *
28  * This filter implements a layer of the finite difference solver hierarchy that
29  * performs ``dense'' iteration, ie. iteration over all pixels in the input and
30  * output at each change calculation and update step. Dense iteration is in
31  * contrast to a ``sparse'' iteration over a subset of the pixels.  See
32  * documenation for FiniteDifferenceImageFilter for an overview of the
33  * iterative finite difference algorithm:
34  *
35  * \par
36  * \f$u_{\mathbf{i}}^{n+1}=u^n_{\mathbf{i}}+\Delta u^n_{\mathbf{i}}\Delta t\f$ 
37  *
38  * \par
39  * The generic code for performing iterations and updates at each time
40  * step is inherited from the parent class.  This class defines an update
41  * buffer for \f$ \Delta \f$ and the methods CalculateChange() and
42  * ApplyUpdate(). These methods are designed to automatically thread their
43  * execution.  \f$ \Delta \f$ is defined as an image of identical size and type 
44  * as the output image.
45  *
46  * \par
47  * As we descend through each layer in the hierarchy, we know more and more
48  * about the specific application of our filter.  At this level, we
49  * have committed to iteration over each pixel in an image. We take advantage
50  * of that knowledge to multithread the iteration and update methods. 
51  *  
52  * \par Inputs and Outputs
53  * This is an image to image filter.  The specific types of the images are not
54  * fixed at this level in the hierarchy.
55  *
56  * \par How to use this class
57  * This filter is only one layer in a branch the finite difference solver
58  * hierarchy.  It does not define the function used in the CalculateChange() and
59  * it does not define the stopping criteria (Halt method).  To use this class,
60  * subclass it to a specific instance that supplies a function and Halt()
61  * method.
62  * 
63  * \ingroup ImageFilters
64  * \sa FiniteDifferenceImageFilter */
65 template <class TInputImage, class TOutputImage>
66 class ITK_EXPORT DenseFiniteDifferenceImageFilter  
67 IND **: public FiniteDifferenceImageFilter<TInputImage, TOutputImage>
68 {
69 public:
70   /** Standard class typedefs */
71   typedef DenseFiniteDifferenceImageFilter Self;
72 TDA   typedef FiniteDifferenceImageFilter<TInputImage, TOutputImage> Superclass;
73 TDA   typedef SmartPointer<Self>  Pointer;
74 TDA   typedef SmartPointer<const Self>  ConstPointer;
75   
76   /** Run-time type information (and related methods) */
77   itkTypeMacro(DenseFiniteDifferenceImageFilter, ImageToImageFilter );
78   
79   /** Convenient typedefs */
80   typedef typename Superclass::InputImageType  InputImageType;
81   typedef typename Superclass::OutputImageType OutputImageType;
82   typedef typename Superclass::FiniteDifferenceFunctionType
83 TDA,IND ***FiniteDifferenceFunctionType;
84   
85   /** Dimensionality of input and output data is assumed to be the same.
86    * It is inherited from the superclass. */
87   itkStaticConstMacro(ImageDimension, unsigned int,Superclass::ImageDimension);
88
89   /** The pixel type of the output image will be used in computations.
90    * Inherited from the superclass. */
91   typedef typename Superclass::PixelType PixelType;
92
93   /** The value type of a time step.  Inherited from the superclass. */
94   typedef typename Superclass::TimeStepType TimeStepType;
95
96   /** The container type for the update buffer. */
97   typedef OutputImageType UpdateBufferType;
98   
99 protected:
100   DenseFiniteDifferenceImageFilter()
101     { m_UpdateBuffer = UpdateBufferType::New(); }
102   ~DenseFiniteDifferenceImageFilter() {}
103   void PrintSelf(std::ostream& os, Indent indent) const;
104
105   /** A simple method to copy the data from the input to the output.  ( Supports
106    * "read-only" image adaptors in the case where the input image type converts
107    * to a different output image type. )  */
108   virtual void CopyInputToOutput();
109
110   /** This method applies changes from the m_UpdateBuffer to the output using
111    * the ThreadedAPplyUpdate() method and a multithreading mechanism.  "dt" is
112    * the time step to use for the update of each pixel. */
113   virtual void ApplyUpdate(TimeStepType dt);
114
115   /** Method to allow subclasses to get direct access to the update
116    * buffer */
117   virtual UpdateBufferType* GetUpdateBuffer()
118     { return m_UpdateBuffer; }
119   
120 private:
121   DenseFiniteDifferenceImageFilter(const Self&); //purposely not implemented
122   void operator=(const Self&); //purposely not implemented
123
124   /** Structure for passing information into static callback methods.  Used in
125    * the subclasses' threading mechanisms. */
126   struct DenseFDThreadStruct
127 IND **{
128     DenseFiniteDifferenceImageFilter *Filter;
129     TimeStepType TimeStep;
130     TimeStepType *TimeStepList;
131     bool *ValidTimeStepList;
132 IND **};
133   
134   /** The type of region used for multithreading */
135   typedef typename UpdateBufferType::RegionType ThreadRegionType;
136
137   /** This method allocates storage in m_UpdateBuffer.  It is called from
138    * Superclass::GenerateData(). */
139   virtual void AllocateUpdateBuffer();
140   
141   /** This callback method uses ImageSource::SplitRequestedRegion to acquire an
142    * output region that it passes to ThreadedApplyUpdate for processing. */
143   static ITK_THREAD_RETURN_TYPE ApplyUpdateThreaderCallback( void *arg );
144   
145   /** This method populates an update buffer with changes for each pixel in the
146    * output using the ThreadedCalculateChange() method and a multithreading
147    * mechanism. Returns value is a time step to be used for the update. */
148   virtual TimeStepType CalculateChange();
149
150   /** This callback method uses SplitUpdateContainer to acquire a region
151    * which it then passes to ThreadedCalculateChange for processing. */
152   static ITK_THREAD_RETURN_TYPE CalculateChangeThreaderCallback( void *arg );
153   
154   /** Split the UpdateBuffer into "num" pieces, returning region "i" as
155    * "splitRegion". This method is called "num" times to return non-overlapping
156    * regions. The method returns the number of pieces that the UpdateBuffer
157    * can be split into by the routine. i.e. return value is less than or equal
158    * to "num".
159    * \sa ImageSource */
160   //  virtual
161   //  int SplitUpdateContainer(int i, int num, ThreadRegionType& splitRegion);
162
163   /**  Does the actual work of updating the output from the UpdateContainer over
164    *  an output region supplied by the multithreading mechanism.
165    *  \sa ApplyUpdate
166    *  \sa ApplyUpdateThreaderCallback */ 
167   virtual
168   void ThreadedApplyUpdate(TimeStepType dt,
169                            const ThreadRegionType ®ionToProcess,
170                            int threadId);
171   // FOR ALL: iterator(output, splitRegion), iterator(update, splitRegion)
172
173   /** Does the actual work of calculating change over a region supplied by
174    * the multithreading mechanism.
175    * \sa CalculateChange
176    * \sa CalculateChangeThreaderCallback */
177   virtual
178   TimeStepType ThreadedCalculateChange(const ThreadRegionType ®ionToProcess,
179                                        int threadId);
180   // FOR ALL : iterator(input, splitRegion), iterator(update, splitRegion)
181
182   /** The buffer that holds the updates for an iteration of the algorithm. */
183   typename UpdateBufferType::Pointer m_UpdateBuffer;
184 };
185   
186
187 }// end namespace itk
188
189 #ifndef ITK_MANUAL_INSTANTIATION
190 #include "itkDenseFiniteDifferenceImageFilter.txx"
191 #endif
192
193 #endif
194

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:05PM
© Kitware Inc.