ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkDenseFiniteDifferenceImageFilter.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 __itkDenseFiniteDifferenceImageFilter_h
00019 #define __itkDenseFiniteDifferenceImageFilter_h
00020 
00021 #include "itkFiniteDifferenceImageFilter.h"
00022 #include "itkMultiThreader.h"
00023 
00024 namespace itk
00025 {
00068 template< class TInputImage, class TOutputImage >
00069 class ITK_EXPORT DenseFiniteDifferenceImageFilter:
00070   public FiniteDifferenceImageFilter< TInputImage, TOutputImage >
00071 {
00072 public:
00073 
00075   typedef DenseFiniteDifferenceImageFilter Self;
00076   typedef FiniteDifferenceImageFilter<
00077     TInputImage, TOutputImage >                 Superclass;
00078 
00079   typedef SmartPointer< Self >       Pointer;
00080   typedef SmartPointer< const Self > ConstPointer;
00081 
00083   itkTypeMacro(DenseFiniteDifferenceImageFilter, ImageToImageFilter);
00084 
00086   typedef typename Superclass::InputImageType  InputImageType;
00087   typedef typename Superclass::OutputImageType OutputImageType;
00088   typedef typename Superclass::FiniteDifferenceFunctionType
00089   FiniteDifferenceFunctionType;
00090 
00093   itkStaticConstMacro(ImageDimension, unsigned int, Superclass::ImageDimension);
00094 
00097   typedef typename Superclass::PixelType PixelType;
00098 
00100   typedef typename Superclass::TimeStepType TimeStepType;
00101 
00103   typedef OutputImageType UpdateBufferType;
00104 
00105 #ifdef ITK_USE_CONCEPT_CHECKING
00106 
00107   itkConceptMacro( OutputTimesDoubleCheck,
00108                    ( Concept::MultiplyOperator< PixelType, double > ) );
00109   itkConceptMacro( OutputAdditiveOperatorsCheck,
00110                    ( Concept::AdditiveOperators< PixelType > ) );
00111   itkConceptMacro( OutputAdditiveAndAssignOperatorsCheck,
00112                    ( Concept::AdditiveAndAssignOperators< PixelType > ) );
00113   itkConceptMacro( InputConvertibleToOutputCheck,
00114                    ( Concept::Convertible< typename TInputImage::PixelType, PixelType > ) );
00115 
00117 #endif
00118 protected:
00119   DenseFiniteDifferenceImageFilter()
00120   { m_UpdateBuffer = UpdateBufferType::New(); }
00121   ~DenseFiniteDifferenceImageFilter() {}
00122   void PrintSelf(std::ostream & os, Indent indent) const;
00124 
00128   virtual void CopyInputToOutput();
00129 
00133   virtual void ApplyUpdate(const TimeStepType& dt);
00134 
00137   virtual UpdateBufferType * GetUpdateBuffer()
00138   { return m_UpdateBuffer; }
00139 
00143   virtual TimeStepType CalculateChange();
00144 
00147   virtual void AllocateUpdateBuffer();
00148 
00150   typedef typename UpdateBufferType::RegionType ThreadRegionType;
00151 
00156   virtual
00157   void ThreadedApplyUpdate(const TimeStepType& dt,
00158                            const ThreadRegionType & regionToProcess,
00159                            ThreadIdType threadId);
00160 
00165   virtual
00166   TimeStepType ThreadedCalculateChange(const ThreadRegionType & regionToProcess,
00167                                        ThreadIdType threadId);
00168 
00169 private:
00170   DenseFiniteDifferenceImageFilter(const Self &); //purposely not implemented
00171   void operator=(const Self &);                   //purposely not implemented
00172 
00175   struct DenseFDThreadStruct {
00176     DenseFiniteDifferenceImageFilter *Filter;
00177     TimeStepType TimeStep;
00178     std::vector< TimeStepType > TimeStepList;
00179     std::vector< bool > ValidTimeStepList;
00180   };
00181 
00184   static ITK_THREAD_RETURN_TYPE ApplyUpdateThreaderCallback(void *arg);
00185 
00188   static ITK_THREAD_RETURN_TYPE CalculateChangeThreaderCallback(void *arg);
00189 
00191   typename UpdateBufferType::Pointer m_UpdateBuffer;
00192 };
00193 } // end namespace itk
00194 
00195 // Define instantiation macro for this template.
00196 #define ITK_TEMPLATE_DenseFiniteDifferenceImageFilter(_, EXPORT, TypeX, TypeY)     \
00197   namespace itk                                                                    \
00198   {                                                                                \
00199   _( 2 ( class EXPORT DenseFiniteDifferenceImageFilter< ITK_TEMPLATE_2 TypeX > ) ) \
00200   namespace Templates                                                              \
00201   {                                                                                \
00202   typedef DenseFiniteDifferenceImageFilter< ITK_TEMPLATE_2 TypeX >                 \
00203   DenseFiniteDifferenceImageFilter##TypeY;                                       \
00204   }                                                                                \
00205   }
00206 
00207 #if ITK_TEMPLATE_EXPLICIT
00208 #include "Templates/itkDenseFiniteDifferenceImageFilter+-.h"
00209 #endif
00210 
00211 #if ITK_TEMPLATE_TXX
00212 #include "itkDenseFiniteDifferenceImageFilter.hxx"
00213 #endif
00214 
00215 #endif
00216