ITK  5.4.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 CoordRepType = double;
107 
110 
114 
118 
121 
123  itkGetOpenCLSourceFromKernelMacro(GPUDemonsRegistrationFunctionKernel);
124 
126  void
128  {
129  m_MovingImageInterpolator = ptr;
130  }
131 
133  InterpolatorType *
135  {
136  return m_MovingImageInterpolator;
137  }
138 
140  TimeStepType
141  ComputeGlobalTimeStep(void * itkNotUsed(GlobalData)) const override
142  {
143  return m_TimeStep;
144  }
145 
148  void *
149  GetGlobalDataPointer() const override
150  {
151  auto * global = new GlobalDataStruct();
152 
153  global->m_SumOfSquaredDifference = 0.0;
154  global->m_NumberOfPixelsProcessed = 0L;
155  global->m_SumOfSquaredChange = 0;
156  return global;
157  }
158 
163  void
164  ReleaseGlobalDataPointer(void * GlobalData) const override;
165 
168  void
169  GPUAllocateMetricData(unsigned int numPixels) override;
170 
172  void
173  GPUReleaseMetricData() override;
174 
176  void
177  InitializeIteration() override;
178 
183  PixelType
184  ComputeUpdate(const NeighborhoodType & neighborhood,
185  void * globalData,
186  const FloatOffsetType & offset = FloatOffsetType(0.0)) override;
187 
189  void
190  GPUComputeUpdate(const DisplacementFieldTypePointer output, DisplacementFieldTypePointer update, void * gd) override;
191 
197  virtual double
198  GetMetric() const
199  {
200  return m_Metric;
201  }
202 
204  virtual double
205  GetRMSChange() const
206  {
207  return m_RMSChange;
208  }
209 
213  virtual void
215  {
216  m_UseMovingImageGradient = flag;
217  }
218  virtual bool
220  {
221  return m_UseMovingImageGradient;
222  }
229  virtual void
230  SetIntensityDifferenceThreshold(double);
231 
232  virtual double
233  GetIntensityDifferenceThreshold() const;
234 
235 protected:
237  ~GPUDemonsRegistrationFunction() override = default;
238 
239  void
240  PrintSelf(std::ostream & os, Indent indent) const override;
241 
244 
248  {
252  };
253 
254  /* GPU kernel handle for GPUComputeUpdate */
255  int m_ComputeUpdateGPUKernelHandle{};
256 
257 private:
259  // SpacingType m_FixedImageSpacing;
260  // PointType m_FixedImageOrigin;
261  PixelType m_ZeroUpdateReturn{};
262  double m_Normalizer{};
263 
265  GradientCalculatorPointer m_FixedImageGradientCalculator{};
266 
268  MovingImageGradientCalculatorPointer m_MovingImageGradientCalculator{};
269  bool m_UseMovingImageGradient{};
270 
272  InterpolatorPointer m_MovingImageInterpolator{};
273 
275  TimeStepType m_TimeStep{};
276 
278  double m_DenominatorThreshold{};
279 
281  double m_IntensityDifferenceThreshold{};
282 
286  mutable double m_Metric{};
287  mutable double m_SumOfSquaredDifference{};
288  mutable SizeValueType m_NumberOfPixelsProcessed{};
289  mutable double m_RMSChange{};
290  mutable double m_SumOfSquaredChange{};
291 
292  mutable GPUReduction<int>::Pointer m_GPUPixelCounter{};
293  mutable GPUReduction<float>::Pointer m_GPUSquaredChange{};
294  mutable GPUReduction<float>::Pointer m_GPUSquaredDifference{};
295 
297  mutable std::mutex m_MetricCalculationMutex{};
298 };
299 } // end namespace itk
300 
301 #ifndef ITK_MANUAL_INSTANTIATION
302 # include "itkGPUDemonsRegistrationFunction.hxx"
303 #endif
304 
305 #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:249
itk::GPUDemonsRegistrationFunction::CoordRepType
double CoordRepType
Definition: itkGPUDemonsRegistrationFunction.h:102
itk::GPUDemonsRegistrationFunction::GradientCalculatorPointer
typename GradientCalculatorType::Pointer GradientCalculatorPointer
Definition: itkGPUDemonsRegistrationFunction.h:113
itkLinearInterpolateImageFunction.h
itkPoint.h
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:149
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:104
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:247
itk::GPUDemonsRegistrationFunction::ComputeGlobalTimeStep
TimeStepType ComputeGlobalTimeStep(void *) const override
Definition: itkGPUDemonsRegistrationFunction.h:141
itk::itkGPUKernelClassMacro
itkGPUKernelClassMacro(GPUImageOpsKernel)
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
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:127
itk::GPUDemonsRegistrationFunction::GlobalDataStruct::m_NumberOfPixelsProcessed
SizeValueType m_NumberOfPixelsProcessed
Definition: itkGPUDemonsRegistrationFunction.h:250
itk::GPUDemonsRegistrationFunction::GlobalDataStruct::m_SumOfSquaredChange
double m_SumOfSquaredChange
Definition: itkGPUDemonsRegistrationFunction.h:251
itk::GPUDemonsRegistrationFunction::GetUseMovingImageGradient
virtual bool GetUseMovingImageGradient() const
Definition: itkGPUDemonsRegistrationFunction.h:219
itk::GPUDemonsRegistrationFunction::SetUseMovingImageGradient
virtual void SetUseMovingImageGradient(bool flag)
Definition: itkGPUDemonsRegistrationFunction.h:214
itk::GPUDemonsRegistrationFunction::SpacingType
typename FixedImageType::SpacingType SpacingType
Definition: itkGPUDemonsRegistrationFunction.h:85
itkGPUReduction.h
itk::GPUDemonsRegistrationFunction::GetRMSChange
virtual double GetRMSChange() const
Definition: itkGPUDemonsRegistrationFunction.h:205
itk::GPUPDEDeformableRegistrationFunction
Definition: itkGPUPDEDeformableRegistrationFunction.h:41
itk::GPUDemonsRegistrationFunction::PointType
typename InterpolatorType::PointType PointType
Definition: itkGPUDemonsRegistrationFunction.h:105
itk::GPUDemonsRegistrationFunction::MovingImageGradientCalculatorPointer
typename MovingImageGradientCalculatorType::Pointer MovingImageGradientCalculatorPointer
Definition: itkGPUDemonsRegistrationFunction.h:117
itk::GPUDemonsRegistrationFunction
Definition: itkGPUDemonsRegistrationFunction.h:58
itk::GPUDemonsRegistrationFunction::GetMetric
virtual double GetMetric() const
Definition: itkGPUDemonsRegistrationFunction.h:198
itk::InterpolateImageFunction
Base class for all image interpolators.
Definition: itkInterpolateImageFunction.h:45
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itk::GPUDemonsRegistrationFunction::GetMovingImageInterpolator
InterpolatorType * GetMovingImageInterpolator()
Definition: itkGPUDemonsRegistrationFunction.h:134
itk::FiniteDifferenceFunction< TDisplacementField >::TimeStepType
double TimeStepType
Definition: itkFiniteDifferenceFunction.h:90