00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkFiniteDifferenceSparseImageFilter_h_
00018 #define __itkFiniteDifferenceSparseImageFilter_h_
00019
00020 #include "itkFiniteDifferenceSparseImageFunction.h"
00021 #include "itkFiniteDifferenceImageFilter.h"
00022 #include "itkMultiThreader.h"
00023 #include "itkSparseImage.h"
00024
00025 namespace itk {
00026
00060 template <class TInputImageType, class TSparseOutputImageType>
00061 class FiniteDifferenceSparseImageFilter
00062 : public FiniteDifferenceImageFilter <TInputImageType,
00063 TSparseOutputImageType>
00064 {
00065 public:
00067 typedef FiniteDifferenceSparseImageFilter Self;
00068 typedef FiniteDifferenceImageFilter<TInputImageType,
00069 TSparseOutputImageType> Superclass;
00070 typedef SmartPointer<Self> Pointer;
00071 typedef SmartPointer<const Self> ConstPointer;
00072
00074 itkTypeMacro(FiniteDifferenceSparseImageFilter, FiniteDifferenceImageFilter);
00075
00077 typedef typename Superclass::InputImageType InputImageType;
00078 typedef typename Superclass::OutputImageType SparseOutputImageType;
00079 typedef typename Superclass::PixelType PixelType;
00080 typedef typename Superclass::TimeStepType TimeStepType;
00081 typedef typename Superclass::FiniteDifferenceFunctionType
00082 FiniteDifferenceFunctionType;
00083
00084
00087 itkStaticConstMacro(ImageDimension, unsigned int,Superclass::ImageDimension);
00088
00090 typedef typename SparseOutputImageType::IndexType IndexType;
00091 typedef typename SparseOutputImageType::NodeType OutputNodeType;
00092 typedef typename SparseOutputImageType::NodeListType NodeListType;
00093
00095 typedef typename OutputNodeType::NodeDataType NodeDataType;
00096
00100 typedef typename OutputNodeType::NodeValueType NodeValueType;
00101
00103 typedef FiniteDifferenceSparseImageFunction <SparseOutputImageType>
00104 SparseFunctionType;
00105
00107 void SetSparseFunction( SparseFunctionType *sf );
00108
00109 itkSetMacro(PrecomputeFlag, bool);
00110 itkGetMacro(PrecomputeFlag, bool);
00111
00112 protected:
00113 FiniteDifferenceSparseImageFilter();
00114 ~FiniteDifferenceSparseImageFilter() {}
00115 void PrintSelf(std::ostream& os, Indent indent) const;
00116
00120 virtual void Initialize();
00121
00124 virtual void AllocateUpdateBuffer() {};
00125
00128 virtual NodeDataType DataConstraint( const NodeDataType &data ) const
00129 { return data; }
00130
00131 private:
00133 struct ThreadRegionType
00134 {
00135
00136 typename NodeListType::Iterator first;
00137
00138 typename NodeListType::Iterator last;
00139 };
00140
00141 protected:
00143 int GetSplitRegion( int i, int num, ThreadRegionType &splitRegion );
00144
00147 virtual void ApplyUpdate( TimeStepType dt );
00148
00150 static ITK_THREAD_RETURN_TYPE ApplyUpdateThreaderCallback( void *arg );
00151 virtual void ThreadedApplyUpdate(TimeStepType dt,
00152 const ThreadRegionType ®ionToProcess,
00153 int threadId);
00154
00157 virtual TimeStepType CalculateChange();
00158
00160 static ITK_THREAD_RETURN_TYPE CalculateChangeThreaderCallback( void *arg );
00161 virtual TimeStepType ThreadedCalculateChange
00162 (const ThreadRegionType ®ionToProcess, int threadId);
00163
00167 virtual void PrecalculateChange();
00168
00170 static ITK_THREAD_RETURN_TYPE PrecalculateChangeThreaderCallback( void *arg );
00171 virtual void ThreadedPrecalculateChange
00172 (const ThreadRegionType ®ionToProcess, int threadId);
00173
00176 struct FDThreadStruct
00177 {
00178 FiniteDifferenceSparseImageFilter *Filter;
00179 TimeStepType TimeStep;
00180 TimeStepType *TimeStepList;
00181 bool *ValidTimeStepList;
00182 };
00183
00184 private:
00186 bool m_PrecomputeFlag;
00187
00189 SparseFunctionType *m_SparseFunction;
00190
00193 typename NodeListType::RegionListType m_RegionList;
00194
00195 FiniteDifferenceSparseImageFilter(const Self&);
00196 void operator=(const Self&);
00197 };
00198
00199 }
00200
00201 #ifndef ITK_MANUAL_INSTANTIATION
00202 #include "itkFiniteDifferenceSparseImageFilter.txx"
00203 #endif
00204
00205 #endif