ITK  5.0.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:
38 
44 
46 
47  itkNewMacro( Self );
48 
49  using DomainType = typename Superclass::DomainType;
50  using AssociateType = typename Superclass::AssociateType;
51 
52  using ImageToImageMetricv4Type = typename Superclass::ImageToImageMetricv4Type;
53  using VirtualIndexType = typename Superclass::VirtualIndexType;
54  using VirtualPointType = typename Superclass::VirtualPointType;
55  using FixedImagePointType = typename Superclass::FixedImagePointType;
56  using FixedImagePixelType = typename Superclass::FixedImagePixelType;
57  using FixedImageGradientType = typename Superclass::FixedImageGradientType;
58  using MovingImagePointType = typename Superclass::MovingImagePointType;
59  using MovingImagePixelType = typename Superclass::MovingImagePixelType;
60  using MovingImageGradientType = typename Superclass::MovingImageGradientType;
61  using MeasureType = typename Superclass::MeasureType;
62  using DerivativeType = typename Superclass::DerivativeType;
63  using DerivativeValueType = typename Superclass::DerivativeValueType;
64 
65  using FixedTransformType = typename ImageToImageMetricv4Type::FixedTransformType;
66  using FixedOutputPointType = typename FixedTransformType::OutputPointType;
67  using MovingTransformType = typename ImageToImageMetricv4Type::MovingTransformType;
68  using MovingOutputPointType = typename MovingTransformType::OutputPointType;
69 
70  using InternalComputationValueType = typename Superclass::InternalComputationValueType;
71  using NumberOfParametersType = typename Superclass::NumberOfParametersType;
72 
73 protected:
76 
82  void BeforeThreadedExecution() override;
83 
91  void AfterThreadedExecution() override;
92 
98  bool ProcessVirtualPoint( const VirtualIndexType & virtualIndex,
99  const VirtualPointType & virtualPoint,
100  const ThreadIdType threadId ) override;
101 
105  bool ProcessPoint(const VirtualIndexType & virtualIndex,
106  const VirtualPointType & virtualPoint,
107  const FixedImagePointType & mappedFixedPoint,
108  const FixedImagePixelType & mappedFixedPixelValue,
109  const FixedImageGradientType & mappedFixedImageGradient,
110  const MovingImagePointType & mappedMovingPoint,
111  const MovingImagePixelType & mappedMovingPixelValue,
112  const MovingImageGradientType & mappedMovingImageGradient,
113  MeasureType & metricValueReturn,
114  DerivativeType & localDerivativeReturn,
115  const ThreadIdType threadId ) const override;
116 
117 private:
118  /*
119  * the per-thread memory for computing the correlation and its derivatives
120  * \bar f (CorrelationImageToImageMetricv4::m_AverageFix ) and
121  * \bar m (CorrelationImageToImageMetricv4::m_AverageMov ), the average pixel
122  * intensity, computed using the helper
123  * class CorrelationHelperImageToImageMetricv4GetValueAndDerivativeThreader.
124  * say f_i is the i-th pixel of fixed image, m_i is the i-th pixel of moving
125  * image: see the comments below
126  */
127  struct CorrelationMetricValueDerivativePerThreadStruct{ // keep cumlative summation over points for:
128  InternalComputationValueType fm; // (f_i - \bar f) * (m_i - \bar m)
129  InternalComputationValueType m2; // (m_i - \bar m)^2
130  InternalComputationValueType f2; // (f_i - \bar m)^2
133  DerivativeType fdm; // (f_i - \bar f) * dm_i/dp
134  DerivativeType mdm; // (m_i - \bar m) * dm_i/dp
135  };
136 
137  itkPadStruct( ITK_CACHE_LINE_ALIGNMENT, CorrelationMetricValueDerivativePerThreadStruct,
138  PaddedCorrelationMetricValueDerivativePerThreadStruct);
139  itkAlignedTypedef( ITK_CACHE_LINE_ALIGNMENT, PaddedCorrelationMetricValueDerivativePerThreadStruct,
140  AlignedCorrelationMetricValueDerivativePerThreadStruct );
141  /* per thread variables for correlation and its derivatives */
142  mutable AlignedCorrelationMetricValueDerivativePerThreadStruct * m_CorrelationMetricValueDerivativePerThreadVariables;
143 
146  TCorrelationMetric * m_CorrelationAssociate;
147 };
148 
149 } // end namespace itk
150 
151 #ifndef ITK_MANUAL_INSTANTIATION
152 #include "itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.hxx"
153 #endif
154 
155 #endif
unsigned int ThreadIdType
Definition: itkIntTypes.h:99
Provides threading for ImageToImageMetricv4::GetValueAndDerivative.