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 
29 namespace itk
30 {
31 
36 template <typename T>
38 {
39  using MyType = T;
40 };
41 
57 template <typename TDomainPartitioner, typename TImageToImageMetric, typename TNeighborhoodCorrelationMetric>
59  : public ImageToImageMetricv4GetValueAndDerivativeThreader<TDomainPartitioner, TImageToImageMetric>
60 {
61 public:
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
107  struct ScanMemType
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
138  SizeValueType numberOfFillZero; // for each queue
139  SizeValueType windowLength; // number of voxels in the scanning window
141 
146  };
147 
148 protected:
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
196  ProcessVirtualPoint_impl(IdentityHelper<ThreadedIndexedContainerPartitioner> itkNotUsed(self),
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
240  ThreadedExecution_impl(
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
254  InitializeScanning(const ImageRegionType & scanRegion,
255  ScanIteratorType & scanIt,
256  ScanMemType & scanMem,
257  ScanParametersType & scanParameters) const;
258 
261  void
262  UpdateQueues(const ScanIteratorType & scanIt,
263  ScanMemType & scanMem,
264  const ScanParametersType & scanParameters,
265  const ThreadIdType threadId) const;
266 
267  void
268  UpdateQueuesAtBeginningOfLine(const ScanIteratorType & scanIt,
269  ScanMemType & scanMem,
270  const ScanParametersType & scanParameters,
271  const ThreadIdType threadId) const;
272 
276  void
277  UpdateQueuesToNextScanWindow(const ScanIteratorType & scanIt,
278  ScanMemType & scanMem,
279  const ScanParametersType & scanParameters,
280  const ThreadIdType threadId) const;
281 
284  bool
285  ComputeInformationFromQueues(const ScanIteratorType & scanIt,
286  ScanMemType & scanMem,
287  const ScanParametersType & scanParameters,
288  const ThreadIdType threadId) const;
289 
290  void
291  ComputeMovingTransformDerivative(const ScanIteratorType & scanIt,
292  ScanMemType & scanMem,
293  const ScanParametersType & scanParameters,
294  DerivativeType & deriv,
295  MeasureType & localCC,
296  const ThreadIdType threadId) const;
297 
298 private:
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
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanMemType::sMovingMoving
QueueRealType sMovingMoving
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:123
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanParametersType::windowLength
SizeValueType windowLength
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:139
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanMemType::mappedMovingPoint
MovingImagePointType mappedMovingPoint
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:129
ConstPointer
SmartPointer< const Self > ConstPointer
Definition: itkAddImageFilter.h:94
itkThreadedIndexedContainerPartitioner.h
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanParametersType::radius
RadiusType radius
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:145
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanMemType::QsumFixed2
SumQueueType QsumFixed2
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:111
itkConstNeighborhoodIterator.h
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanParametersType::virtualImage
VirtualImageType::ConstPointer virtualImage
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:144
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::QueueRealType
InternalComputationValueType QueueRealType
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:102
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanMemType::movingA
QueueRealType movingA
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:120
itk::ImageToImageMetricv4GetValueAndDerivativeThreader
Provides threading for ImageToImageMetricv4::GetValueAndDerivative.
Definition: itkImageToImageMetricv4GetValueAndDerivativeThreader.h:44
itk::IdentityHelper::MyType
T MyType
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:39
itk::ThreadedImageRegionPartitioner
Class for partitioning of an ImageRegion.
Definition: itkThreadedImageRegionPartitioner.h:45
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ProcessPoint
bool ProcessPoint(const VirtualIndexType &, const VirtualPointType &, const FixedImagePointType &, const FixedImagePixelType &, const FixedImageGradientType &, const MovingImagePointType &, const MovingImagePixelType &, const MovingImageGradientType &, MeasureType &, DerivativeType &, const ThreadIdType) const override
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:217
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanMemType::movingImageGradient
MovingImageGradientType movingImageGradient
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:126
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanParametersType::numberOfFillZero
SizeValueType numberOfFillZero
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:138
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ImageDimensionType
typename NeighborhoodCorrelationMetricType::ImageDimensionType ImageDimensionType
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:94
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::RadiusType
typename NeighborhoodCorrelationMetricType::RadiusType RadiusType
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:99
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanMemType::QsumMoving2
SumQueueType QsumMoving2
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:113
itkImageToImageMetricv4GetValueAndDerivativeThreader.h
itk::SmartPointer< Self >
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanMemType::virtualPoint
VirtualPointType virtualPoint
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:130
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ProcessVirtualPoint_impl
bool ProcessVirtualPoint_impl(IdentityHelper< T >, const VirtualIndexType &virtualIndex, const VirtualPointType &virtualPoint, const ThreadIdType threadId)
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:204
itkThreadedImageRegionPartitioner.h
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanMemType::Qcount
SumQueueType Qcount
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:117
itk::IdentityHelper
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:37
itk::IndexValueType
long IndexValueType
Definition: itkIntTypes.h:93
itk::ThreadIdType
unsigned int ThreadIdType
Definition: itkIntTypes.h:102
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ThreadedExecution
void ThreadedExecution(const DomainType &domain, const ThreadIdType threadId) override
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:233
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanMemType::fixedImageGradient
FixedImageGradientType fixedImageGradient
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:125
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanParametersType::scanRegion
ImageRegionType scanRegion
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:137
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanParametersType::scanRegionBeginIndexDim0
IndexValueType scanRegionBeginIndexDim0
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:140
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::NeighborhoodCorrelationMetricType
TNeighborhoodCorrelationMetric NeighborhoodCorrelationMetricType
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:90
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::VirtualImageType
typename Superclass::VirtualImageType VirtualImageType
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:77
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::MovingImageType
typename NeighborhoodCorrelationMetricType::MovingImageType MovingImageType
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:98
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanMemType::mappedFixedPoint
FixedImagePointType mappedFixedPoint
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:128
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanMemType::sFixedMoving
QueueRealType sFixedMoving
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:121
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader
ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader()
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:149
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ProcessVirtualPoint
bool ProcessVirtualPoint(const VirtualIndexType &virtualIndex, const VirtualPointType &virtualPoint, const ThreadIdType threadId) override
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:187
itk::ConstNeighborhoodIterator
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
Definition: itkConstNeighborhoodIterator.h:51
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanMemType::QsumFixed
SumQueueType QsumFixed
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:114
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanParametersType::movingImage
MovingImageType::ConstPointer movingImage
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:143
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanMemType::QsumMoving
SumQueueType QsumMoving
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:115
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::InternalComputationValueType
typename NeighborhoodCorrelationMetricType::InternalComputationValueType InternalComputationValueType
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:93
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanParametersType
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:134
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::FixedImageType
typename NeighborhoodCorrelationMetricType::FixedImageType FixedImageType
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:97
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::SumQueueType
std::deque< QueueRealType > SumQueueType
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:103
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanMemType::sFixedFixed
QueueRealType sFixedFixed
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:122
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanMemType::fixedA
QueueRealType fixedA
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:119
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanMemType::QsumFixedMoving
SumQueueType QsumFixedMoving
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:116
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::JacobianType
typename NeighborhoodCorrelationMetricType::JacobianType JacobianType
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:95
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::NumberOfParametersType
typename NeighborhoodCorrelationMetricType::NumberOfParametersType NumberOfParametersType
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:96
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanMemType
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:107
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader
Threading implementation for ANTS CC metric ANTSNeighborhoodCorrelationImageToImageMetricv4 ....
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:58
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ImageRegionType
typename NeighborhoodCorrelationMetricType::ImageRegionType ImageRegionType
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:92
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86
itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader::ScanParametersType::fixedImage
FixedImageType::ConstPointer fixedImage
Definition: itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:142