ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.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 itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader_h
19 #define itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader_h
20 
25 
26 #include <deque>
27 
28 namespace itk
29 {
30 
35 template<typename T>
37 {
38  using MyType = T;
39 };
40 
56 template< typename TDomainPartitioner, typename TImageToImageMetric, typename TNeighborhoodCorrelationMetric >
58  : public ImageToImageMetricv4GetValueAndDerivativeThreader< TDomainPartitioner, TImageToImageMetric >
59 {
60 public:
62 
65  using Superclass =
69 
71 
72  itkNewMacro( Self );
73 
74  using DomainType = typename Superclass::DomainType;
75  using AssociateType = typename Superclass::AssociateType;
76 
77  using VirtualImageType = typename Superclass::VirtualImageType;
78  using VirtualPointType = typename Superclass::VirtualPointType;
79  using VirtualIndexType = typename Superclass::VirtualIndexType;
80  using FixedImagePointType = typename Superclass::FixedImagePointType;
81  using FixedImagePixelType = typename Superclass::FixedImagePixelType;
82  using FixedImageGradientType = typename Superclass::FixedImageGradientType;
83  using MovingImagePointType = typename Superclass::MovingImagePointType;
84  using MovingImagePixelType = typename Superclass::MovingImagePixelType;
85  using MovingImageGradientType = typename Superclass::MovingImageGradientType;
86  using MeasureType = typename Superclass::MeasureType;
87  using DerivativeType = typename Superclass::DerivativeType;
88  using DerivativeValueType = 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  typedef struct ScanMemType {
108  // queues used in the scanning
109  // sum of the fixed value squared
111  // sum of the moving value squared
117 
123 
126 
130  } ScanMemType;
131 
132  // For dense scan over one image region
133  typedef struct ScanParametersType {
134  // const values during scanning
136  SizeValueType numberOfFillZero; // for each queue
137  SizeValueType windowLength; // number of voxels in the scanning window
139 
140  typename FixedImageType::ConstPointer fixedImage;
141  typename MovingImageType::ConstPointer movingImage;
142  typename VirtualImageType::ConstPointer virtualImage;
144 
146 
147 protected:
149  m_ANTSAssociate(nullptr)
150  {}
151 
185  bool ProcessVirtualPoint( const VirtualIndexType & virtualIndex,
186  const VirtualPointType & virtualPoint,
187  const ThreadIdType threadId ) override {
188  return ProcessVirtualPoint_impl(IdentityHelper<TDomainPartitioner>(), virtualIndex, virtualPoint, threadId );
189  }
190 
191  /* specific overloading for sparse CC metric */
192  bool ProcessVirtualPoint_impl(
194  const VirtualIndexType & virtualIndex,
195  const VirtualPointType & virtualPoint,
196  const ThreadIdType threadId );
197 
198  /* for other default case */
199  template<typename T>
201  IdentityHelper<T> itkNotUsed(self),
202  const VirtualIndexType & virtualIndex,
203  const VirtualPointType & virtualPoint,
204  const ThreadIdType threadId ) {
205  return Superclass::ProcessVirtualPoint(virtualIndex, virtualPoint, threadId);
206  }
207 
208 
213  const VirtualIndexType & itkNotUsed(virtualIndex),
214  const VirtualPointType & itkNotUsed(virtualPoint),
215  const FixedImagePointType & itkNotUsed(mappedFixedPoint),
216  const FixedImagePixelType & itkNotUsed(mappedFixedPixelValue),
217  const FixedImageGradientType & itkNotUsed(mappedFixedImageGradient),
218  const MovingImagePointType & itkNotUsed(mappedMovingPoint),
219  const MovingImagePixelType & itkNotUsed(mappedMovingPixelValue),
220  const MovingImageGradientType & itkNotUsed(mappedMovingImageGradient),
221  MeasureType & itkNotUsed(metricValueReturn),
222  DerivativeType & itkNotUsed(localDerivativeReturn),
223  const ThreadIdType itkNotUsed(threadId) ) const override
224  {
225  itkExceptionMacro("ProcessPoint should never be reached in ANTS CC metric threader class.");
226  }
227 
228  void ThreadedExecution( const DomainType& domain,
229  const ThreadIdType threadId ) override
230  {
231  ThreadedExecution_impl(IdentityHelper<TDomainPartitioner>(), domain, threadId );
232  }
233 
234  /* specific overloading for dense threader only based CC metric */
235  void ThreadedExecution_impl(
237  const DomainType& domain,
238  const ThreadIdType threadId );
239 
240  /* for other default case */
241  template<typename T>
242  void ThreadedExecution_impl(
243  IdentityHelper<T> itkNotUsed(self),
244  const DomainType& domain,
245  const ThreadIdType threadId );
246 
250  void InitializeScanning(const ImageRegionType &scanRegion,
251  ScanIteratorType &scanIt, ScanMemType &scanMem,
252  ScanParametersType &scanParameters ) const;
253 
256  void UpdateQueues(const ScanIteratorType &scanIt,
257  ScanMemType &scanMem, const ScanParametersType &scanParameters,
258  const ThreadIdType threadId) const;
259 
260  void UpdateQueuesAtBeginningOfLine(
261  const ScanIteratorType &scanIt, ScanMemType &scanMem,
262  const ScanParametersType &scanParameters,
263  const ThreadIdType threadId) const;
264 
268  void UpdateQueuesToNextScanWindow(
269  const ScanIteratorType &scanIt, ScanMemType &scanMem,
270  const ScanParametersType &scanParameters,
271  const ThreadIdType threadId) const;
272 
275  bool ComputeInformationFromQueues(
276  const ScanIteratorType &scanIt, ScanMemType &scanMem,
277  const ScanParametersType &scanParameters,
278  const ThreadIdType threadId) const;
279 
280  void ComputeMovingTransformDerivative(
281  const ScanIteratorType &scanIt, ScanMemType &scanMem,
282  const ScanParametersType &scanParameters, DerivativeType &deriv,
283  MeasureType &local_cc, const ThreadIdType threadId) const;
284 
285 private:
288  TNeighborhoodCorrelationMetric * m_ANTSAssociate;
289 };
290 
291 
292 } // end namespace itk
293 
294 #ifndef ITK_MANUAL_INSTANTIATION
295 #include "itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.hxx"
296 #endif
297 
298 #endif
bool ProcessPoint(const VirtualIndexType &, const VirtualPointType &, const FixedImagePointType &, const FixedImagePixelType &, const FixedImageGradientType &, const MovingImagePointType &, const MovingImagePixelType &, const MovingImageGradientType &, MeasureType &, DerivativeType &, const ThreadIdType) const override
unsigned long SizeValueType
Definition: itkIntTypes.h:83
Class for partitioning of an ImageRegion.
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
bool ProcessVirtualPoint_impl(IdentityHelper< T >, const VirtualIndexType &virtualIndex, const VirtualPointType &virtualPoint, const ThreadIdType threadId)
signed long IndexValueType
Definition: itkIntTypes.h:90
unsigned int ThreadIdType
Definition: itkIntTypes.h:99
Provides threading for ImageToImageMetricv4::GetValueAndDerivative.
bool ProcessVirtualPoint(const VirtualIndexType &virtualIndex, const VirtualPointType &virtualPoint, const ThreadIdType threadId) override