ITK  6.0.0
Insight Toolkit
itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  * https://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 #include <memory> // For unique_ptr.
24 
25 namespace itk
26 {
27 
34 template <typename TDomainPartitioner, typename TImageToImageMetric, typename TCorrelationMetric>
36  : public ImageToImageMetricv4GetValueAndDerivativeThreader<TDomainPartitioner, TImageToImageMetric>
37 {
38 public:
40 
46 
48 
49  itkNewMacro(Self);
50 
51  using typename Superclass::DomainType;
52  using typename Superclass::AssociateType;
53 
54  using ImageToImageMetricv4Type = typename Superclass::ImageToImageMetricv4Type;
55  using typename Superclass::VirtualIndexType;
56  using typename Superclass::VirtualPointType;
57  using typename Superclass::FixedImagePointType;
58  using typename Superclass::FixedImagePixelType;
59  using typename Superclass::FixedImageGradientType;
60  using typename Superclass::MovingImagePointType;
61  using typename Superclass::MovingImagePixelType;
62  using typename Superclass::MovingImageGradientType;
63  using typename Superclass::MeasureType;
64  using typename Superclass::DerivativeType;
65  using typename Superclass::DerivativeValueType;
66 
67  using FixedTransformType = typename ImageToImageMetricv4Type::FixedTransformType;
68  using FixedOutputPointType = typename FixedTransformType::OutputPointType;
69  using MovingTransformType = typename ImageToImageMetricv4Type::MovingTransformType;
70  using MovingOutputPointType = typename MovingTransformType::OutputPointType;
71 
72  using typename Superclass::InternalComputationValueType;
73  using typename Superclass::NumberOfParametersType;
74 
75 protected:
78 
84  void
85  BeforeThreadedExecution() override;
86 
94  void
95  AfterThreadedExecution() override;
96 
102  bool
103  ProcessVirtualPoint(const VirtualIndexType & virtualIndex,
104  const VirtualPointType & virtualPoint,
105  const ThreadIdType threadId) override;
106 
110  bool
111  ProcessPoint(const VirtualIndexType & virtualIndex,
112  const VirtualPointType & virtualPoint,
113  const FixedImagePointType & mappedFixedPoint,
114  const FixedImagePixelType & fixedImageValue,
115  const FixedImageGradientType & mappedFixedImageGradient,
116  const MovingImagePointType & mappedMovingPoint,
117  const MovingImagePixelType & movingImageValue,
118  const MovingImageGradientType & movingImageGradient,
119  MeasureType & metricValueReturn,
120  DerivativeType & localDerivativeReturn,
121  const ThreadIdType threadId) const override;
122 
123 private:
124  /*
125  * the per-thread memory for computing the correlation and its derivatives
126  * \bar f (CorrelationImageToImageMetricv4::m_AverageFix ) and
127  * \bar m (CorrelationImageToImageMetricv4::m_AverageMov ), the average pixel
128  * intensity, computed using the helper
129  * class CorrelationHelperImageToImageMetricv4GetValueAndDerivativeThreader.
130  * say f_i is the i-th pixel of fixed image, m_i is the i-th pixel of moving
131  * image: see the comments below
132  */
134  { // keep cumulative summation over points for:
135  InternalComputationValueType fm; // (f_i - \bar f) * (m_i - \bar m)
136  InternalComputationValueType m2; // (m_i - \bar m)^2
137  InternalComputationValueType f2; // (f_i - \bar m)^2
138  InternalComputationValueType m; // m_i
139  InternalComputationValueType f; // f_i
140  DerivativeType fdm; // (f_i - \bar f) * dm_i/dp
141  DerivativeType mdm; // (m_i - \bar m) * dm_i/dp
142  };
143 
144  itkPadStruct(ITK_CACHE_LINE_ALIGNMENT,
146  PaddedCorrelationMetricValueDerivativePerThreadStruct);
147  itkAlignedTypedef(ITK_CACHE_LINE_ALIGNMENT,
148  PaddedCorrelationMetricValueDerivativePerThreadStruct,
149  AlignedCorrelationMetricValueDerivativePerThreadStruct);
150  /* per thread variables for correlation and its derivatives */
151  std::unique_ptr<AlignedCorrelationMetricValueDerivativePerThreadStruct[]>
153 
156  TCorrelationMetric * m_CorrelationAssociate{};
157 };
158 
159 } // end namespace itk
160 
161 #ifndef ITK_MANUAL_INSTANTIATION
162 # include "itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.hxx"
163 #endif
164 
165 #endif
itk::CorrelationImageToImageMetricv4GetValueAndDerivativeThreader::MovingOutputPointType
typename MovingTransformType::OutputPointType MovingOutputPointType
Definition: itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:70
itk::CorrelationImageToImageMetricv4GetValueAndDerivativeThreader::CorrelationMetricValueDerivativePerThreadStruct::fm
InternalComputationValueType fm
Definition: itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:135
itk::ImageToImageMetricv4GetValueAndDerivativeThreader
Provides threading for ImageToImageMetricv4::GetValueAndDerivative.
Definition: itkImageToImageMetricv4GetValueAndDerivativeThreader.h:44
itk::CorrelationImageToImageMetricv4GetValueAndDerivativeThreader::CorrelationMetricValueDerivativePerThreadStruct::f2
InternalComputationValueType f2
Definition: itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:137
itk::CorrelationImageToImageMetricv4GetValueAndDerivativeThreader
Processes points for CorrelationImageToImageMetricv4 GetValueAndDerivative.
Definition: itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:35
itk::CorrelationImageToImageMetricv4GetValueAndDerivativeThreader::CorrelationMetricValueDerivativePerThreadStruct::f
InternalComputationValueType f
Definition: itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:139
itkImageToImageMetricv4GetValueAndDerivativeThreader.h
itk::CorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ImageToImageMetricv4Type
typename Superclass::ImageToImageMetricv4Type ImageToImageMetricv4Type
Definition: itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:54
itk::CorrelationImageToImageMetricv4GetValueAndDerivativeThreader::MovingTransformType
typename ImageToImageMetricv4Type::MovingTransformType MovingTransformType
Definition: itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:69
itk::SmartPointer< Self >
itk::CorrelationImageToImageMetricv4GetValueAndDerivativeThreader::CorrelationMetricValueDerivativePerThreadStruct::m
InternalComputationValueType m
Definition: itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:138
itk::ThreadIdType
unsigned int ThreadIdType
Definition: itkIntTypes.h:102
itk::CorrelationImageToImageMetricv4GetValueAndDerivativeThreader::CorrelationMetricValueDerivativePerThreadStruct
Definition: itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:133
itk::CorrelationImageToImageMetricv4GetValueAndDerivativeThreader::CorrelationMetricValueDerivativePerThreadStruct::mdm
DerivativeType mdm
Definition: itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:141
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::CorrelationImageToImageMetricv4GetValueAndDerivativeThreader::CorrelationMetricValueDerivativePerThreadStruct::fdm
DerivativeType fdm
Definition: itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:140
itk::CorrelationImageToImageMetricv4GetValueAndDerivativeThreader::FixedTransformType
typename ImageToImageMetricv4Type::FixedTransformType FixedTransformType
Definition: itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:67
itk::CorrelationImageToImageMetricv4GetValueAndDerivativeThreader::m_CorrelationMetricValueDerivativePerThreadVariables
std::unique_ptr< AlignedCorrelationMetricValueDerivativePerThreadStruct[]> m_CorrelationMetricValueDerivativePerThreadVariables
Definition: itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:152
itk::CorrelationImageToImageMetricv4GetValueAndDerivativeThreader::CorrelationMetricValueDerivativePerThreadStruct::m2
InternalComputationValueType m2
Definition: itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:136
itk::CorrelationImageToImageMetricv4GetValueAndDerivativeThreader::FixedOutputPointType
typename FixedTransformType::OutputPointType FixedOutputPointType
Definition: itkCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:68