ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.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 __itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader_h
00019 #define __itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader_h
00020 
00021 #include "itkImageToImageMetricv4GetValueAndDerivativeThreader.h"
00022 
00023 namespace itk
00024 {
00025 
00032 template < class TDomainPartitioner, class TImageToImageMetric, class TCorrelationMetric >
00033 class CorrelationImageToImageMetricv4GetValueAndDerivativeThreader
00034   : public ImageToImageMetricv4GetValueAndDerivativeThreader< TDomainPartitioner, TImageToImageMetric >
00035 {
00036 public:
00038   typedef CorrelationImageToImageMetricv4GetValueAndDerivativeThreader                                      Self;
00039   typedef ImageToImageMetricv4GetValueAndDerivativeThreader< TDomainPartitioner, TImageToImageMetric > Superclass;
00040   typedef SmartPointer< Self >                                                                         Pointer;
00041   typedef SmartPointer< const Self >                                                                   ConstPointer;
00042 
00043   itkTypeMacro( CorrelationImageToImageMetricv4GetValueAndDerivativeThreader, ImageToImageMetricv4GetValueAndDerivativeThreader );
00044 
00045   itkNewMacro( Self );
00046 
00047   typedef typename Superclass::DomainType    DomainType;
00048   typedef typename Superclass::AssociateType AssociateType;
00049 
00050   typedef typename Superclass::ImageToImageMetricv4Type ImageToImageMetricv4Type;
00051   typedef typename Superclass::VirtualIndexType         VirtualIndexType;
00052   typedef typename Superclass::VirtualPointType         VirtualPointType;
00053   typedef typename Superclass::FixedImagePointType      FixedImagePointType;
00054   typedef typename Superclass::FixedImagePixelType      FixedImagePixelType;
00055   typedef typename Superclass::FixedImageGradientType   FixedImageGradientType;
00056   typedef typename Superclass::MovingImagePointType     MovingImagePointType;
00057   typedef typename Superclass::MovingImagePixelType     MovingImagePixelType;
00058   typedef typename Superclass::MovingImageGradientType  MovingImageGradientType;
00059   typedef typename Superclass::MeasureType              MeasureType;
00060   typedef typename Superclass::DerivativeType           DerivativeType;
00061   typedef typename Superclass::DerivativeValueType      DerivativeValueType;
00062 
00063   typedef typename ImageToImageMetricv4Type::FixedTransformType      FixedTransformType;
00064   typedef typename FixedTransformType::OutputPointType               FixedOutputPointType;
00065   typedef typename ImageToImageMetricv4Type::MovingTransformType     MovingTransformType;
00066   typedef typename MovingTransformType::OutputPointType              MovingOutputPointType;
00067 
00068   typedef typename Superclass::InternalComputationValueType InternalComputationValueType;
00069   typedef typename Superclass::NumberOfParametersType       NumberOfParametersType;
00070 
00071 protected:
00072   CorrelationImageToImageMetricv4GetValueAndDerivativeThreader() {}
00073 
00079   virtual void BeforeThreadedExecution();
00080 
00088   virtual void AfterThreadedExecution();
00089 
00095   virtual bool ProcessVirtualPoint( const VirtualIndexType & virtualIndex,
00096                                     const VirtualPointType & virtualPoint,
00097                                     const ThreadIdType threadId );
00098 
00102   virtual bool ProcessPoint(const VirtualIndexType &          virtualIndex,
00103         const VirtualPointType &          virtualPoint,
00104         const FixedImagePointType &       mappedFixedPoint,
00105         const FixedImagePixelType &       mappedFixedPixelValue,
00106         const FixedImageGradientType &    mappedFixedImageGradient,
00107         const MovingImagePointType &      mappedMovingPoint,
00108         const MovingImagePixelType &      mappedMovingPixelValue,
00109         const MovingImageGradientType &   mappedMovingImageGradient,
00110         MeasureType &                     metricValueReturn,
00111         DerivativeType &                  localDerivativeReturn,
00112         const ThreadIdType                threadID ) const;
00113 
00114 
00115 private:
00116   CorrelationImageToImageMetricv4GetValueAndDerivativeThreader( const Self & ); // purposely not implemented
00117   void operator=( const Self & ); // purposely not implemented
00118 
00119   /*
00120    * the per-thread memory for computing the correlation and its derivatives
00121    * \bar f (CorrelationImageToImageMetricv4::m_AverageFix ) and
00122    * \bar m (CorrelationImageToImageMetricv4::m_AverageMov ), the average pixel
00123    * intensity, computed using the helper
00124    * class CorrelationHelperImageToImageMetricv4GetValueAndDerivativeThreader.
00125    * say f_i is the i-th pixel of fixed image, m_i is the i-th pixel of moving
00126    * image: see the comments below
00127    */
00128   struct InternalCumSumType{    // keep cumlative summation over points for:
00129       InternalComputationValueType fm;  // (f_i - \bar f) * (m_i - \bar m)
00130       InternalComputationValueType m2;  // (m_i - \bar m)^2
00131       InternalComputationValueType f2;  // (f_i - \bar m)^2
00132       InternalComputationValueType m;   // m_i
00133       InternalComputationValueType f;   // f_i
00134       DerivativeType fdm; // (f_i - \bar f) * dm_i/dp
00135       DerivativeType mdm; // (m_i - \bar m) * dm_i/dp
00136   };
00137 
00138   /* per thread variables for correlation and its derivatives */
00139   mutable std::vector< InternalCumSumType > m_InternalCumSumPerThread;
00140 
00141 };
00142 
00143 } // end namespace itk
00144 
00145 #ifndef ITK_MANUAL_INSTANTIATION
00146 #include "itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.hxx"
00147 #endif
00148 
00149 #endif
00150