ITK  6.0.0
Insight Toolkit
itkGPUDemonsRegistrationFunction.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 itkGPUDemonsRegistrationFunction_h
19 #define itkGPUDemonsRegistrationFunction_h
20 
22 #include "itkPoint.h"
25 #include "itkGPUReduction.h"
26 
27 namespace itk
28 {
55 itkGPUKernelClassMacro(GPUDemonsRegistrationFunctionKernel);
56 
57 template <typename TFixedImage, typename TMovingImage, typename TDisplacementField>
58 class ITK_TEMPLATE_EXPORT GPUDemonsRegistrationFunction
59  : public GPUPDEDeformableRegistrationFunction<TFixedImage, TMovingImage, TDisplacementField>
60 {
61 public:
62  ITK_DISALLOW_COPY_AND_MOVE(GPUDemonsRegistrationFunction);
63 
69 
71  itkNewMacro(Self);
72 
74  itkOverrideGetNameOfClassMacro(GPUDemonsRegistrationFunction);
75 
77  using typename Superclass::MovingImageType;
78  using typename Superclass::MovingImagePointer;
79 
81  using typename Superclass::FixedImageType;
82  using typename Superclass::FixedImagePointer;
85  using SpacingType = typename FixedImageType::SpacingType;
86 
88  using typename Superclass::DisplacementFieldType;
89  using typename Superclass::DisplacementFieldTypePointer;
90 
92  static constexpr unsigned int ImageDimension = Superclass::ImageDimension;
93 
95  using typename Superclass::PixelType;
96  using typename Superclass::RadiusType;
97  using typename Superclass::NeighborhoodType;
98  using typename Superclass::FloatOffsetType;
99  using typename Superclass::TimeStepType;
100 
102  using CoordinateType = double;
103 #ifndef ITK_FUTURE_LEGACY_REMOVE
104  using CoordRepType ITK_FUTURE_DEPRECATED(
105  "ITK 6 discourages using `CoordRepType`. Please use `CoordinateType` instead!") = CoordinateType;
106 #endif
111 
114 
118 
122 
125 
127  itkGetOpenCLSourceFromKernelMacro(GPUDemonsRegistrationFunctionKernel);
128 
130  void
132  {
133  m_MovingImageInterpolator = ptr;
134  }
135 
137  InterpolatorType *
139  {
140  return m_MovingImageInterpolator;
141  }
142 
144  TimeStepType
145  ComputeGlobalTimeStep(void * itkNotUsed(GlobalData)) const override
146  {
147  return m_TimeStep;
148  }
149 
152  void *
153  GetGlobalDataPointer() const override
154  {
155  auto * global = new GlobalDataStruct();
156 
157  global->m_SumOfSquaredDifference = 0.0;
158  global->m_NumberOfPixelsProcessed = 0L;
159  global->m_SumOfSquaredChange = 0;
160  return global;
161  }
162 
167  void
168  ReleaseGlobalDataPointer(void * GlobalData) const override;
169 
172  void
173  GPUAllocateMetricData(unsigned int numPixels) override;
174 
176  void
177  GPUReleaseMetricData() override;
178 
180  void
181  InitializeIteration() override;
182 
187  PixelType
188  ComputeUpdate(const NeighborhoodType & neighborhood,
189  void * globalData,
190  const FloatOffsetType & offset = FloatOffsetType(0.0)) override;
191 
193  void
194  GPUComputeUpdate(const DisplacementFieldTypePointer output, DisplacementFieldTypePointer update, void * gd) override;
195 
201  virtual double
202  GetMetric() const
203  {
204  return m_Metric;
205  }
206 
208  virtual double
209  GetRMSChange() const
210  {
211  return m_RMSChange;
212  }
213 
217  virtual void
219  {
220  m_UseMovingImageGradient = flag;
221  }
222  virtual bool
224  {
225  return m_UseMovingImageGradient;
226  }
233  virtual void
234  SetIntensityDifferenceThreshold(double);
235 
236  virtual double
237  GetIntensityDifferenceThreshold() const;
238 
239 protected:
241  ~GPUDemonsRegistrationFunction() override = default;
242 
243  void
244  PrintSelf(std::ostream & os, Indent indent) const override;
245 
248 
252  {
256  };
257 
258  /* GPU kernel handle for GPUComputeUpdate */
259  int m_ComputeUpdateGPUKernelHandle{};
260 
261 private:
263  // SpacingType m_FixedImageSpacing;
264  // PointType m_FixedImageOrigin;
265  PixelType m_ZeroUpdateReturn{};
266  double m_Normalizer{};
267 
269  GradientCalculatorPointer m_FixedImageGradientCalculator{};
270 
272  MovingImageGradientCalculatorPointer m_MovingImageGradientCalculator{};
273  bool m_UseMovingImageGradient{};
274 
276  InterpolatorPointer m_MovingImageInterpolator{};
277 
279  TimeStepType m_TimeStep{};
280 
282  double m_DenominatorThreshold{};
283 
285  double m_IntensityDifferenceThreshold{};
286 
290  mutable double m_Metric{};
291  mutable double m_SumOfSquaredDifference{};
292  mutable SizeValueType m_NumberOfPixelsProcessed{};
293  mutable double m_RMSChange{};
294  mutable double m_SumOfSquaredChange{};
295 
296  mutable GPUReduction<int>::Pointer m_GPUPixelCounter{};
297  mutable GPUReduction<float>::Pointer m_GPUSquaredChange{};
298  mutable GPUReduction<float>::Pointer m_GPUSquaredDifference{};
299 
301  mutable std::mutex m_MetricCalculationMutex{};
302 };
303 } // end namespace itk
304 
305 #ifndef ITK_MANUAL_INSTANTIATION
306 # include "itkGPUDemonsRegistrationFunction.hxx"
307 #endif
308 
309 #endif
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::FiniteDifferenceFunction< TDisplacementField >::RadiusType
typename ConstNeighborhoodIterator< TDisplacementField >::RadiusType RadiusType
Definition: itkFiniteDifferenceFunction.h:97
itkGPUPDEDeformableRegistrationFunction.h
itk::GPUDemonsRegistrationFunction::GlobalDataStruct::m_SumOfSquaredDifference
double m_SumOfSquaredDifference
Definition: itkGPUDemonsRegistrationFunction.h:253
itk::GPUDemonsRegistrationFunction::GradientCalculatorPointer
typename GradientCalculatorType::Pointer GradientCalculatorPointer
Definition: itkGPUDemonsRegistrationFunction.h:117
itkLinearInterpolateImageFunction.h
itkPoint.h
itk::GPUDemonsRegistrationFunction::CoordinateType
double CoordinateType
Definition: itkGPUDemonsRegistrationFunction.h:102
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::CentralDifferenceImageFunction
Calculate the derivative by central differencing.
Definition: itkCentralDifferenceImageFunction.h:76
itk::Vector
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::GPUDemonsRegistrationFunction::SizeType
typename FixedImageType::SizeType SizeType
Definition: itkGPUDemonsRegistrationFunction.h:84
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::GPUDemonsRegistrationFunction::IndexType
typename FixedImageType::IndexType IndexType
Definition: itkGPUDemonsRegistrationFunction.h:83
itk::GPUDemonsRegistrationFunction::GetGlobalDataPointer
void * GetGlobalDataPointer() const override
Definition: itkGPUDemonsRegistrationFunction.h:153
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::LinearInterpolateImageFunction
Linearly interpolate an image at specified positions.
Definition: itkLinearInterpolateImageFunction.h:51
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itkCentralDifferenceImageFunction.h
itk::GPUFiniteDifferenceFunction< TDisplacementField >
itk::FiniteDifferenceFunction< TDisplacementField >::PixelType
typename ImageType::PixelType PixelType
Definition: itkFiniteDifferenceFunction.h:83
itk::GPUDataManager::Pointer
SmartPointer< Self > Pointer
Definition: itkGPUDataManager.h:52
itk::GPUDemonsRegistrationFunction::InterpolatorPointer
typename InterpolatorType::Pointer InterpolatorPointer
Definition: itkGPUDemonsRegistrationFunction.h:108
itk::GPUReduction
Definition: itkGPUReduction.h:40
itk::CovariantVector
A templated class holding a n-Dimensional covariant vector.
Definition: itkCovariantVector.h:70
itk::GPUDemonsRegistrationFunction::GlobalDataStruct
Definition: itkGPUDemonsRegistrationFunction.h:251
itk::GPUDemonsRegistrationFunction::ComputeGlobalTimeStep
TimeStepType ComputeGlobalTimeStep(void *) const override
Definition: itkGPUDemonsRegistrationFunction.h:145
itk::itkGPUKernelClassMacro
itkGPUKernelClassMacro(GPUImageOpsKernel)
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::ConstNeighborhoodIterator
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
Definition: itkConstNeighborhoodIterator.h:51
itk::GPUDemonsRegistrationFunction::SetMovingImageInterpolator
void SetMovingImageInterpolator(InterpolatorType *ptr)
Definition: itkGPUDemonsRegistrationFunction.h:131
itk::GPUDemonsRegistrationFunction::GlobalDataStruct::m_NumberOfPixelsProcessed
SizeValueType m_NumberOfPixelsProcessed
Definition: itkGPUDemonsRegistrationFunction.h:254
itk::GPUDemonsRegistrationFunction::GlobalDataStruct::m_SumOfSquaredChange
double m_SumOfSquaredChange
Definition: itkGPUDemonsRegistrationFunction.h:255
itk::GPUDemonsRegistrationFunction::GetUseMovingImageGradient
virtual bool GetUseMovingImageGradient() const
Definition: itkGPUDemonsRegistrationFunction.h:223
itk::GPUDemonsRegistrationFunction::SetUseMovingImageGradient
virtual void SetUseMovingImageGradient(bool flag)
Definition: itkGPUDemonsRegistrationFunction.h:218
itk::GPUDemonsRegistrationFunction::SpacingType
typename FixedImageType::SpacingType SpacingType
Definition: itkGPUDemonsRegistrationFunction.h:85
itkGPUReduction.h
itk::GPUDemonsRegistrationFunction::GetRMSChange
virtual double GetRMSChange() const
Definition: itkGPUDemonsRegistrationFunction.h:209
itk::GPUPDEDeformableRegistrationFunction
Definition: itkGPUPDEDeformableRegistrationFunction.h:41
itk::GPUDemonsRegistrationFunction::PointType
typename InterpolatorType::PointType PointType
Definition: itkGPUDemonsRegistrationFunction.h:109
itk::GPUDemonsRegistrationFunction::MovingImageGradientCalculatorPointer
typename MovingImageGradientCalculatorType::Pointer MovingImageGradientCalculatorPointer
Definition: itkGPUDemonsRegistrationFunction.h:121
itk::GPUDemonsRegistrationFunction
Definition: itkGPUDemonsRegistrationFunction.h:58
itk::GPUDemonsRegistrationFunction::GetMetric
virtual double GetMetric() const
Definition: itkGPUDemonsRegistrationFunction.h:202
itk::InterpolateImageFunction
Base class for all image interpolators.
Definition: itkInterpolateImageFunction.h:45
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86
itk::GPUDemonsRegistrationFunction::GetMovingImageInterpolator
InterpolatorType * GetMovingImageInterpolator()
Definition: itkGPUDemonsRegistrationFunction.h:138
itk::FiniteDifferenceFunction< TDisplacementField >::TimeStepType
double TimeStepType
Definition: itkFiniteDifferenceFunction.h:90