ITK  6.0.0
Insight Toolkit
itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.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 itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader_h
19#define itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader_h
20
25
26#include <deque>
27#include <mutex>
28
29namespace itk
30{
31
36template <typename T>
38{
39 using MyType = T;
40};
41
57template <typename TDomainPartitioner, typename TImageToImageMetric, typename TNeighborhoodCorrelationMetric>
59 : public ImageToImageMetricv4GetValueAndDerivativeThreader<TDomainPartitioner, TImageToImageMetric>
60{
61public:
63
69
71
72 itkNewMacro(Self);
73
74 using typename Superclass::DomainType;
75 using typename Superclass::AssociateType;
76
77 using VirtualImageType = typename Superclass::VirtualImageType;
78 using typename Superclass::VirtualPointType;
79 using typename Superclass::VirtualIndexType;
80 using typename Superclass::FixedImagePointType;
81 using typename Superclass::FixedImagePixelType;
82 using typename Superclass::FixedImageGradientType;
83 using typename Superclass::MovingImagePointType;
84 using typename Superclass::MovingImagePixelType;
85 using typename Superclass::MovingImageGradientType;
86 using typename Superclass::MeasureType;
87 using typename Superclass::DerivativeType;
88 using typename Superclass::DerivativeValueType;
89
90 using NeighborhoodCorrelationMetricType = TNeighborhoodCorrelationMetric;
91
92 using ImageRegionType = typename NeighborhoodCorrelationMetricType::ImageRegionType;
93 using InternalComputationValueType = typename NeighborhoodCorrelationMetricType::InternalComputationValueType;
94 using ImageDimensionType = typename NeighborhoodCorrelationMetricType::ImageDimensionType;
95 using JacobianType = typename NeighborhoodCorrelationMetricType::JacobianType;
96 using NumberOfParametersType = typename NeighborhoodCorrelationMetricType::NumberOfParametersType;
97 using FixedImageType = typename NeighborhoodCorrelationMetricType::FixedImageType;
98 using MovingImageType = typename NeighborhoodCorrelationMetricType::MovingImageType;
99 using RadiusType = typename NeighborhoodCorrelationMetricType::RadiusType;
100
101 // interested values here updated during scanning
103 using SumQueueType = std::deque<QueueRealType>;
105
106 // one ScanMemType for each thread
108 {
109 // queues used in the scanning
110 // sum of the fixed value squared
112 // sum of the moving value squared
118
124
125 FixedImageGradientType fixedImageGradient;
126 MovingImageGradientType movingImageGradient;
127
128 FixedImagePointType mappedFixedPoint;
129 MovingImagePointType mappedMovingPoint;
130 VirtualPointType virtualPoint;
131 };
132
133 // For dense scan over one image region
135 {
136 // const values during scanning
139 SizeValueType windowLength; // number of voxels in the scanning window
141
146 };
147
148protected:
150 : m_ANTSAssociate(nullptr)
151 {}
152
186 bool
187 ProcessVirtualPoint(const VirtualIndexType & virtualIndex,
188 const VirtualPointType & virtualPoint,
189 const ThreadIdType threadId) override
190 {
191 return ProcessVirtualPoint_impl(IdentityHelper<TDomainPartitioner>(), virtualIndex, virtualPoint, threadId);
192 }
193
194 /* specific overloading for sparse CC metric */
195 bool
197 const VirtualIndexType & virtualIndex,
198 const VirtualPointType & virtualPoint,
199 const ThreadIdType threadId);
200
201 /* for other default case */
202 template <typename T>
203 bool
205 const VirtualIndexType & virtualIndex,
206 const VirtualPointType & virtualPoint,
207 const ThreadIdType threadId)
208 {
209 return Superclass::ProcessVirtualPoint(virtualIndex, virtualPoint, threadId);
210 }
211
212
216 bool
217 ProcessPoint(const VirtualIndexType & itkNotUsed(virtualIndex),
218 const VirtualPointType & itkNotUsed(virtualPoint),
219 const FixedImagePointType & itkNotUsed(mappedFixedPoint),
220 const FixedImagePixelType & itkNotUsed(mappedFixedPixelValue),
221 const FixedImageGradientType & itkNotUsed(mappedFixedImageGradient),
222 const MovingImagePointType & itkNotUsed(mappedMovingPoint),
223 const MovingImagePixelType & itkNotUsed(mappedMovingPixelValue),
224 const MovingImageGradientType & itkNotUsed(mappedMovingImageGradient),
225 MeasureType & itkNotUsed(metricValueReturn),
226 DerivativeType & itkNotUsed(localDerivativeReturn),
227 const ThreadIdType itkNotUsed(threadId)) const override
228 {
229 itkExceptionMacro("ProcessPoint should never be reached in ANTS CC metric threader class.");
230 }
231
232 void
233 ThreadedExecution(const DomainType & domain, const ThreadIdType threadId) override
234 {
235 ThreadedExecution_impl(IdentityHelper<TDomainPartitioner>(), domain, threadId);
236 }
237
238 /* specific overloading for dense threader only based CC metric */
239 void
242 const DomainType & virtualImageSubRegion,
243 const ThreadIdType threadId);
244
245 /* for other default case */
246 template <typename T>
247 void
248 ThreadedExecution_impl(IdentityHelper<T> itkNotUsed(self), const DomainType & domain, const ThreadIdType threadId);
249
253 void
255 ScanIteratorType & scanIt,
256 ScanMemType & scanMem,
257 ScanParametersType & scanParameters) const;
258
261 void
263 ScanMemType & scanMem,
264 const ScanParametersType & scanParameters,
265 const ThreadIdType threadId) const;
266
267 void
269 ScanMemType & scanMem,
270 const ScanParametersType & scanParameters,
271 const ThreadIdType threadId) const;
272
276 void
278 ScanMemType & scanMem,
279 const ScanParametersType & scanParameters,
280 const ThreadIdType threadId) const;
281
284 bool
286 ScanMemType & scanMem,
287 const ScanParametersType & scanParameters,
288 const ThreadIdType threadId) const;
289
290 void
292 ScanMemType & scanMem,
293 const ScanParametersType & scanParameters,
294 DerivativeType & deriv,
295 MeasureType & localCC,
296 const ThreadIdType threadId) const;
297
298private:
301 TNeighborhoodCorrelationMetric * m_ANTSAssociate{};
302 std::once_flag m_ANTSAssociateOnceFlag{};
303};
304
305
306} // end namespace itk
307
308#ifndef ITK_MANUAL_INSTANTIATION
309# include "itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.hxx"
310#endif
311
312#endif
bool ComputeInformationFromQueues(const ScanIteratorType &scanIt, ScanMemType &scanMem, const ScanParametersType &scanParameters, const ThreadIdType threadId) const
void InitializeScanning(const ImageRegionType &scanRegion, ScanIteratorType &scanIt, ScanMemType &scanMem, ScanParametersType &scanParameters) const
bool ProcessVirtualPoint_impl(IdentityHelper< T >, const VirtualIndexType &virtualIndex, const VirtualPointType &virtualPoint, const ThreadIdType threadId)
bool ProcessVirtualPoint_impl(IdentityHelper< ThreadedIndexedContainerPartitioner >, const VirtualIndexType &virtualIndex, const VirtualPointType &virtualPoint, const ThreadIdType threadId)
void UpdateQueuesToNextScanWindow(const ScanIteratorType &scanIt, ScanMemType &scanMem, const ScanParametersType &scanParameters, const ThreadIdType threadId) const
void ComputeMovingTransformDerivative(const ScanIteratorType &scanIt, ScanMemType &scanMem, const ScanParametersType &scanParameters, DerivativeType &deriv, MeasureType &localCC, const ThreadIdType threadId) const
void UpdateQueuesAtBeginningOfLine(const ScanIteratorType &scanIt, ScanMemType &scanMem, const ScanParametersType &scanParameters, const ThreadIdType threadId) const
void UpdateQueues(const ScanIteratorType &scanIt, ScanMemType &scanMem, const ScanParametersType &scanParameters, const ThreadIdType threadId) const
void ThreadedExecution_impl(IdentityHelper< ThreadedImageRegionPartitioner< TImageToImageMetric::VirtualImageDimension > >, const DomainType &virtualImageSubRegion, const ThreadIdType threadId)
void ThreadedExecution_impl(IdentityHelper< T >, const DomainType &domain, const ThreadIdType threadId)
bool ProcessVirtualPoint(const VirtualIndexType &virtualIndex, const VirtualPointType &virtualPoint, const ThreadIdType threadId) override
bool ProcessPoint(const VirtualIndexType &, const VirtualPointType &, const FixedImagePointType &, const FixedImagePixelType &, const FixedImageGradientType &, const MovingImagePointType &, const MovingImagePixelType &, const MovingImageGradientType &, MeasureType &, DerivativeType &, const ThreadIdType) const override
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
Provides threading for ImageToImageMetricv4::GetValueAndDerivative.
Class for partitioning of an ImageRegion.
SmartPointer< const Self > ConstPointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned int ThreadIdType
Definition: itkIntTypes.h:102
long IndexValueType
Definition: itkIntTypes.h:93
unsigned long SizeValueType
Definition: itkIntTypes.h:86