ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkFiniteDifferenceSparseImageFilter.h
Go to the documentation of this file.
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 __itkFiniteDifferenceSparseImageFilter_h
00019 #define __itkFiniteDifferenceSparseImageFilter_h
00020 
00021 #include "itkFiniteDifferenceSparseImageFunction.h"
00022 #include "itkFiniteDifferenceImageFilter.h"
00023 #include "itkMultiThreader.h"
00024 #include "itkSparseImage.h"
00025 
00026 namespace itk
00027 {
00062 template< class TInputImageType, class TSparseOutputImageType >
00063 class FiniteDifferenceSparseImageFilter:
00064   public FiniteDifferenceImageFilter< TInputImageType,
00065                                       TSparseOutputImageType >
00066 {
00067 public:
00069   typedef FiniteDifferenceSparseImageFilter Self;
00070   typedef FiniteDifferenceImageFilter<
00071     TInputImageType, TSparseOutputImageType >      Superclass;
00072 
00073   typedef SmartPointer< Self >       Pointer;
00074   typedef SmartPointer< const Self > ConstPointer;
00075 
00077   itkTypeMacro(FiniteDifferenceSparseImageFilter, FiniteDifferenceImageFilter);
00078 
00080   typedef typename Superclass::InputImageType               InputImageType;
00081   typedef typename Superclass::OutputImageType              SparseOutputImageType;
00082   typedef typename Superclass::PixelType                    PixelType;
00083   typedef typename Superclass::TimeStepType                 TimeStepType;
00084   typedef typename Superclass::FiniteDifferenceFunctionType FiniteDifferenceFunctionType;
00085   // the PixelType is from output image; therefore, it is a pointer
00086 
00089   itkStaticConstMacro(ImageDimension, unsigned int, Superclass::ImageDimension);
00090 
00092   typedef typename SparseOutputImageType::IndexType    IndexType;
00093   typedef typename SparseOutputImageType::SizeType     SizeType;
00094   typedef typename SparseOutputImageType::NodeType     OutputNodeType;
00095   typedef typename SparseOutputImageType::NodeListType NodeListType;
00096 
00098   typedef typename OutputNodeType::NodeDataType NodeDataType;
00099 
00103   typedef typename OutputNodeType::NodeValueType NodeValueType;
00104 
00106   typedef FiniteDifferenceSparseImageFunction< SparseOutputImageType >
00107   SparseFunctionType;
00108 
00110   void SetSparseFunction(SparseFunctionType *sf);
00111 
00112   itkSetMacro(PrecomputeFlag, bool);
00113   itkGetConstMacro(PrecomputeFlag, bool);
00114 protected:
00115   FiniteDifferenceSparseImageFilter();
00116   ~FiniteDifferenceSparseImageFilter() {}
00117   void PrintSelf(std::ostream & os, Indent indent) const;
00118 
00122   virtual void Initialize();
00123 
00126   virtual void AllocateUpdateBuffer() {}
00127 
00130   virtual NodeDataType DataConstraint(const NodeDataType & data) const
00131   { return data; }
00132 private:
00133 
00135   struct ThreadRegionType {
00136     // this is the first element
00137     typename NodeListType::Iterator first;
00138     // this is one past the last element
00139     typename NodeListType::Iterator last;
00140   };
00141 protected:
00142 
00144   ThreadIdType GetSplitRegion(ThreadIdType i, ThreadIdType num, ThreadRegionType & splitRegion);
00145 
00148   virtual void ApplyUpdate(const TimeStepType& dt);
00149 
00151   static ITK_THREAD_RETURN_TYPE ApplyUpdateThreaderCallback(void *arg);
00152 
00153   virtual void ThreadedApplyUpdate(const TimeStepType& dt,
00154                                    const ThreadRegionType & regionToProcess,
00155                                    ThreadIdType threadId);
00156 
00159   virtual TimeStepType CalculateChange();
00160 
00162   static ITK_THREAD_RETURN_TYPE CalculateChangeThreaderCallback(void *arg);
00163 
00164   virtual TimeStepType ThreadedCalculateChange
00165     (const ThreadRegionType & regionToProcess, ThreadIdType threadId);
00166 
00170   virtual void PrecalculateChange();
00171 
00173   static ITK_THREAD_RETURN_TYPE PrecalculateChangeThreaderCallback(void *arg);
00174 
00175   virtual void ThreadedPrecalculateChange
00176     (const ThreadRegionType & regionToProcess, ThreadIdType threadId);
00177 
00180   struct FDThreadStruct {
00181     FiniteDifferenceSparseImageFilter *Filter;
00182     TimeStepType TimeStep;
00183     std::vector< TimeStepType > TimeStepList;
00184     std::vector< bool > ValidTimeStepList;
00185   };
00186 private:
00187 
00189   bool m_PrecomputeFlag;
00190 
00192   SparseFunctionType *m_SparseFunction;
00193 
00196   typename NodeListType::RegionListType m_RegionList;
00197 
00198   FiniteDifferenceSparseImageFilter(const Self &); //purposely not implemented
00199   void operator=(const Self &);                    //purposely not implemented
00200 };
00201 } // end namespace itk
00202 
00203 #ifndef ITK_MANUAL_INSTANTIATION
00204 #include "itkFiniteDifferenceSparseImageFilter.hxx"
00205 #endif
00206 
00207 #endif
00208