ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkFiniteDifferenceImageFilter.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 __itkFiniteDifferenceImageFilter_h
00019 #define __itkFiniteDifferenceImageFilter_h
00020 
00021 #include "itkInPlaceImageFilter.h"
00022 #include "itkFiniteDifferenceFunction.h"
00023 
00024 namespace itk
00025 {
00131 template< class TInputImage, class TOutputImage >
00132 class ITK_EXPORT FiniteDifferenceImageFilter:
00133   public InPlaceImageFilter< TInputImage, TOutputImage >
00134 {
00135 public:
00136 
00138   typedef FiniteDifferenceImageFilter                     Self;
00139   typedef InPlaceImageFilter< TInputImage, TOutputImage > Superclass;
00140   typedef SmartPointer< Self >                            Pointer;
00141   typedef SmartPointer< const Self >                      ConstPointer;
00142 
00144   itkTypeMacro(FiniteDifferenceImageFilter, InPlaceImageFilter);
00145 
00147   typedef TInputImage  InputImageType;
00148   typedef TOutputImage OutputImageType;
00149 
00151   itkStaticConstMacro(ImageDimension, unsigned int, OutputImageType::ImageDimension);
00152 
00154   typedef typename TOutputImage::PixelType OutputPixelType;
00155   typedef typename TInputImage::PixelType  InputPixelType;
00156   typedef OutputPixelType                  PixelType;
00157 
00159   typedef typename NumericTraits< OutputPixelType >::ValueType OutputPixelValueType;
00160   typedef typename NumericTraits< InputPixelType >::ValueType  InputPixelValueType;
00161 
00165   typedef FiniteDifferenceFunction< TOutputImage >            FiniteDifferenceFunctionType;
00166   typedef typename FiniteDifferenceFunctionType::TimeStepType TimeStepType;
00167 
00168   typedef typename FiniteDifferenceFunctionType::RadiusType             RadiusType;
00169   typedef typename FiniteDifferenceFunctionType::NeighborhoodScalesType NeighborhoodScalesType;
00170 
00172   itkGetConstReferenceMacro(ElapsedIterations, IdentifierType);
00173 
00177   itkGetConstReferenceObjectMacro(DifferenceFunction,
00178                                   FiniteDifferenceFunctionType);
00179 
00183   itkSetObjectMacro(DifferenceFunction, FiniteDifferenceFunctionType);
00184 
00186   itkSetMacro(NumberOfIterations, IdentifierType);
00187   itkGetConstReferenceMacro(NumberOfIterations, IdentifierType);
00189 
00192   itkSetMacro(UseImageSpacing, bool);
00193   itkBooleanMacro(UseImageSpacing);
00194   itkGetConstReferenceMacro(UseImageSpacing, bool);
00196 
00199   itkSetMacro(MaximumRMSError, double);
00200   itkGetConstReferenceMacro(MaximumRMSError, double);
00202 
00205   itkSetMacro(RMSChange, double);
00206   itkGetConstReferenceMacro(RMSChange, double);
00208 
00211   itkSetMacro(ManualReinitialization, bool);
00212   itkGetConstReferenceMacro(ManualReinitialization, bool);
00213   itkBooleanMacro(ManualReinitialization);
00215 
00216   itkSetMacro( IsInitialized, bool );
00217   itkGetMacro( IsInitialized, bool );
00218 
00219   void SetStateToUninitialized() { this->SetIsInitialized( false ); }
00220   void SetStateToInitialized() { this->SetIsInitialized( true ); }
00221 
00222 #ifdef ITK_USE_STRICT_CONCEPT_CHECKING
00223 
00224   itkConceptMacro( OutputPixelIsFloatingPointCheck,
00225                    ( Concept::IsFloatingPoint< OutputPixelValueType > ) );
00226 
00228 #endif
00229 
00230 protected:
00231 
00232   FiniteDifferenceImageFilter();
00233   virtual ~FiniteDifferenceImageFilter();
00234 
00236   bool m_IsInitialized;
00237 
00238   void PrintSelf(std::ostream & os, Indent indent) const;
00239 
00241   virtual void AllocateUpdateBuffer() = 0;
00242 
00246   virtual void ApplyUpdate(const TimeStepType& dt) = 0;
00247 
00253   virtual TimeStepType CalculateChange() = 0;
00254 
00258   virtual void CopyInputToOutput() = 0;
00259 
00263   virtual void GenerateData();
00264 
00276   virtual void GenerateInputRequestedRegion();
00277 
00280   virtual bool Halt();
00281 
00291   virtual bool ThreadedHalt( void *itkNotUsed(threadInfo) ) { return this->Halt(); }
00292 
00298   virtual void Initialize() {}
00299 
00306   virtual void InitializeIteration()
00307   { m_DifferenceFunction->InitializeIteration(); }
00308 
00321   virtual TimeStepType ResolveTimeStep(const std::vector< TimeStepType >& timeStepList,
00322                                        const std::vector< bool >& valid ) const;
00323 
00325   itkSetMacro(ElapsedIterations, IdentifierType);
00326 
00329   virtual void PostProcessOutput() {}
00330 
00332   IdentifierType m_NumberOfIterations;
00333 
00336   IdentifierType m_ElapsedIterations;
00337 
00340   bool m_ManualReinitialization;
00341 
00342   double m_RMSChange;
00343   double m_MaximumRMSError;
00344 
00345 private:
00346   FiniteDifferenceImageFilter(const Self &); //purposely not implemented
00347   void operator=(const Self &);              //purposely not implemented
00348 
00352   void InitializeFunctionCoefficients();
00353 
00356   bool m_UseImageSpacing;
00357 
00359   typename FiniteDifferenceFunctionType::Pointer m_DifferenceFunction;
00360 };
00361 } // end namespace itk
00362 
00363 // Define instantiation macro for this template.
00364 #define ITK_TEMPLATE_FiniteDifferenceImageFilter(_, EXPORT, TypeX, TypeY)     \
00365   namespace itk                                                               \
00366   {                                                                           \
00367   _( 2 ( class EXPORT FiniteDifferenceImageFilter< ITK_TEMPLATE_2 TypeX > ) ) \
00368   namespace Templates                                                         \
00369   {                                                                           \
00370   typedef FiniteDifferenceImageFilter< ITK_TEMPLATE_2 TypeX >                 \
00371   FiniteDifferenceImageFilter##TypeY;                                       \
00372   }                                                                           \
00373   }
00374 
00375 #if ITK_TEMPLATE_EXPLICIT
00376 #include "Templates/itkFiniteDifferenceImageFilter+-.h"
00377 #endif
00378 
00379 #if ITK_TEMPLATE_TXX
00380 #include "itkFiniteDifferenceImageFilter.hxx"
00381 #endif
00382 
00383 #endif
00384