ITK  4.6.0
Insight Segmentation and Registration Toolkit
itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader_h
19 #define __itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader_h
20 
22 
23 namespace itk
24 {
25 
32 template < typename TDomainPartitioner, typename TImageToImageMetric, typename TCorrelationMetric >
34  : public ImageToImageMetricv4GetValueAndDerivativeThreader< TDomainPartitioner, TImageToImageMetric >
35 {
36 public:
42 
44 
45  itkNewMacro( Self );
46 
47  typedef typename Superclass::DomainType DomainType;
48  typedef typename Superclass::AssociateType AssociateType;
49 
50  typedef typename Superclass::ImageToImageMetricv4Type ImageToImageMetricv4Type;
51  typedef typename Superclass::VirtualIndexType VirtualIndexType;
52  typedef typename Superclass::VirtualPointType VirtualPointType;
53  typedef typename Superclass::FixedImagePointType FixedImagePointType;
54  typedef typename Superclass::FixedImagePixelType FixedImagePixelType;
55  typedef typename Superclass::FixedImageGradientType FixedImageGradientType;
56  typedef typename Superclass::MovingImagePointType MovingImagePointType;
57  typedef typename Superclass::MovingImagePixelType MovingImagePixelType;
58  typedef typename Superclass::MovingImageGradientType MovingImageGradientType;
59  typedef typename Superclass::MeasureType MeasureType;
60  typedef typename Superclass::DerivativeType DerivativeType;
61  typedef typename Superclass::DerivativeValueType DerivativeValueType;
62 
63  typedef typename ImageToImageMetricv4Type::FixedTransformType FixedTransformType;
64  typedef typename FixedTransformType::OutputPointType FixedOutputPointType;
65  typedef typename ImageToImageMetricv4Type::MovingTransformType MovingTransformType;
66  typedef typename MovingTransformType::OutputPointType MovingOutputPointType;
67 
68  typedef typename Superclass::InternalComputationValueType InternalComputationValueType;
69  typedef typename Superclass::NumberOfParametersType NumberOfParametersType;
70 
71 protected:
74 
80  virtual void BeforeThreadedExecution();
81 
89  virtual void AfterThreadedExecution();
90 
96  virtual bool ProcessVirtualPoint( const VirtualIndexType & virtualIndex,
97  const VirtualPointType & virtualPoint,
98  const ThreadIdType threadId );
99 
103  virtual bool ProcessPoint(const VirtualIndexType & virtualIndex,
104  const VirtualPointType & virtualPoint,
105  const FixedImagePointType & mappedFixedPoint,
106  const FixedImagePixelType & mappedFixedPixelValue,
107  const FixedImageGradientType & mappedFixedImageGradient,
108  const MovingImagePointType & mappedMovingPoint,
109  const MovingImagePixelType & mappedMovingPixelValue,
110  const MovingImageGradientType & mappedMovingImageGradient,
111  MeasureType & metricValueReturn,
112  DerivativeType & localDerivativeReturn,
113  const ThreadIdType threadId ) const;
114 
115 private:
116  CorrelationImageToImageMetricv4GetValueAndDerivativeThreader( const Self & ); // purposely not implemented
117  void operator=( const Self & ); // purposely not implemented
118 
119  /*
120  * the per-thread memory for computing the correlation and its derivatives
121  * \bar f (CorrelationImageToImageMetricv4::m_AverageFix ) and
122  * \bar m (CorrelationImageToImageMetricv4::m_AverageMov ), the average pixel
123  * intensity, computed using the helper
124  * class CorrelationHelperImageToImageMetricv4GetValueAndDerivativeThreader.
125  * say f_i is the i-th pixel of fixed image, m_i is the i-th pixel of moving
126  * image: see the comments below
127  */
128  struct CorrelationMetricValueDerivativePerThreadStruct{ // keep cumlative summation over points for:
129  InternalComputationValueType fm; // (f_i - \bar f) * (m_i - \bar m)
130  InternalComputationValueType m2; // (m_i - \bar m)^2
131  InternalComputationValueType f2; // (f_i - \bar m)^2
134  DerivativeType fdm; // (f_i - \bar f) * dm_i/dp
135  DerivativeType mdm; // (m_i - \bar m) * dm_i/dp
136  };
137 
139  PaddedCorrelationMetricValueDerivativePerThreadStruct);
140  itkAlignedTypedef( ITK_CACHE_LINE_ALIGNMENT, PaddedCorrelationMetricValueDerivativePerThreadStruct,
141  AlignedCorrelationMetricValueDerivativePerThreadStruct );
142  /* per thread variables for correlation and its derivatives */
143  mutable AlignedCorrelationMetricValueDerivativePerThreadStruct * m_CorrelationMetricValueDerivativePerThreadVariables;
144 
147  TCorrelationMetric * m_CorrelationAssociate;
148 };
149 
150 } // end namespace itk
151 
152 #ifndef ITK_MANUAL_INSTANTIATION
153 #include "itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.hxx"
154 #endif
155 
156 #endif
virtual bool ProcessVirtualPoint(const VirtualIndexType &virtualIndex, const VirtualPointType &virtualPoint, const ThreadIdType threadId)
itkPadStruct(ITK_CACHE_LINE_ALIGNMENT, CorrelationMetricValueDerivativePerThreadStruct, PaddedCorrelationMetricValueDerivativePerThreadStruct)
ImageToImageMetricv4GetValueAndDerivativeThreader< TDomainPartitioner, TImageToImageMetric > Superclass
virtual bool ProcessPoint(const VirtualIndexType &virtualIndex, const VirtualPointType &virtualPoint, const FixedImagePointType &mappedFixedPoint, const FixedImagePixelType &mappedFixedPixelValue, const FixedImageGradientType &mappedFixedImageGradient, const MovingImagePointType &mappedMovingPoint, const MovingImagePixelType &mappedMovingPixelValue, const MovingImageGradientType &mappedMovingImageGradient, MeasureType &metricValueReturn, DerivativeType &localDerivativeReturn, const ThreadIdType threadId) const
itkAlignedTypedef(ITK_CACHE_LINE_ALIGNMENT, PaddedCorrelationMetricValueDerivativePerThreadStruct, AlignedCorrelationMetricValueDerivativePerThreadStruct)
Provides threading for ImageToImageMetricv4::GetValueAndDerivative.
unsigned int ThreadIdType
Definition: itkIntTypes.h:159