ITK  5.2.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  * 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 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 
75 
77  using MovingImageType = typename Superclass::MovingImageType;
78  using MovingImagePointer = typename Superclass::MovingImagePointer;
79 
81  using FixedImageType = typename Superclass::FixedImageType;
82  using FixedImagePointer = typename Superclass::FixedImagePointer;
85  using SpacingType = typename FixedImageType::SpacingType;
86 
88  using DisplacementFieldType = typename Superclass::DisplacementFieldType;
89  using DisplacementFieldTypePointer = typename Superclass::DisplacementFieldTypePointer;
90 
92  static constexpr unsigned int ImageDimension = Superclass::ImageDimension;
93 
95  using PixelType = typename Superclass::PixelType;
99  using TimeStepType = 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 
160  void
161  ReleaseGlobalDataPointer(void * GlobalData) const override;
162 
165  void
166  GPUAllocateMetricData(unsigned int numPixels) override;
167 
170  void
171  GPUReleaseMetricData() override;
172 
174  void
175  InitializeIteration() override;
176 
179  PixelType
180  ComputeUpdate(const NeighborhoodType & neighborhood,
181  void * globalData,
182  const FloatOffsetType & offset = FloatOffsetType(0.0)) override;
183 
184  void
185  GPUComputeUpdate(const DisplacementFieldTypePointer output, DisplacementFieldTypePointer update, void * gd) override;
186 
190  virtual double
191  GetMetric() const
192  {
193  return m_Metric;
194  }
195 
197  virtual double
198  GetRMSChange() const
199  {
200  return m_RMSChange;
201  }
202 
206  virtual void
208  {
209  m_UseMovingImageGradient = flag;
210  }
211  virtual bool
213  {
214  return m_UseMovingImageGradient;
215  }
217 
222  virtual void
223  SetIntensityDifferenceThreshold(double);
224 
225  virtual double
226  GetIntensityDifferenceThreshold() const;
227 
228 protected:
230  ~GPUDemonsRegistrationFunction() override = default;
231 
232  void
233  PrintSelf(std::ostream & os, Indent indent) const override;
234 
237 
241  {
245  };
246 
247  /* GPU kernel handle for GPUComputeUpdate */
249 
250 private:
252  // SpacingType m_FixedImageSpacing;
253  // PointType m_FixedImageOrigin;
255  double m_Normalizer;
256 
259 
263 
266 
269 
272 
275 
279  mutable double m_Metric;
280  mutable double m_SumOfSquaredDifference;
282  mutable double m_RMSChange;
283  mutable double m_SumOfSquaredChange;
284 
288 
290  mutable std::mutex m_MetricCalculationLock;
291 };
292 } // end namespace itk
293 
294 #ifndef ITK_MANUAL_INSTANTIATION
295 # include "itkGPUDemonsRegistrationFunction.hxx"
296 #endif
297 
298 #endif
itk::GPUDemonsRegistrationFunction::m_ZeroUpdateReturn
PixelType m_ZeroUpdateReturn
Definition: itkGPUDemonsRegistrationFunction.h:254
itk::GPUDemonsRegistrationFunction::m_MetricCalculationLock
std::mutex m_MetricCalculationLock
Definition: itkGPUDemonsRegistrationFunction.h:290
itkGPUPDEDeformableRegistrationFunction.h
itk::GPUDemonsRegistrationFunction::GlobalDataStruct::m_SumOfSquaredDifference
double m_SumOfSquaredDifference
Definition: itkGPUDemonsRegistrationFunction.h:242
itk::GPUDemonsRegistrationFunction::CoordRepType
double CoordRepType
Definition: itkGPUDemonsRegistrationFunction.h:102
itk::DemonsRegistrationFunction
Definition: itkDemonsRegistrationFunction.h:54
itk::GPUPDEDeformableRegistrationFunction::DisplacementFieldTypePointer
typename DisplacementFieldType::Pointer DisplacementFieldTypePointer
Definition: itkGPUPDEDeformableRegistrationFunction.h:65
itk::GPUDemonsRegistrationFunction::GradientCalculatorPointer
typename GradientCalculatorType::Pointer GradientCalculatorPointer
Definition: itkGPUDemonsRegistrationFunction.h:113
itk::GPUDemonsRegistrationFunction::m_FixedImageGradientCalculator
GradientCalculatorPointer m_FixedImageGradientCalculator
Definition: itkGPUDemonsRegistrationFunction.h:258
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::GPUDemonsRegistrationFunction::PixelType
typename Superclass::PixelType PixelType
Definition: itkGPUDemonsRegistrationFunction.h:95
itk::GPUDemonsRegistrationFunction::TimeStepType
typename Superclass::TimeStepType TimeStepType
Definition: itkGPUDemonsRegistrationFunction.h:99
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::GPUDemonsRegistrationFunction::m_ComputeUpdateGPUKernelHandle
int m_ComputeUpdateGPUKernelHandle
Definition: itkGPUDemonsRegistrationFunction.h:248
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::m_Metric
double m_Metric
Definition: itkGPUDemonsRegistrationFunction.h:279
itk::GPUPDEDeformableRegistrationFunction::DisplacementFieldType
TDisplacementField DisplacementFieldType
Definition: itkGPUPDEDeformableRegistrationFunction.h:64
itk::GPUDemonsRegistrationFunction::IndexType
typename FixedImageType::IndexType IndexType
Definition: itkGPUDemonsRegistrationFunction.h:83
itk::GPUPDEDeformableRegistrationFunction::MovingImageType
TMovingImage MovingImageType
Definition: itkGPUPDEDeformableRegistrationFunction.h:56
itk::GPUDemonsRegistrationFunction::NeighborhoodType
typename Superclass::NeighborhoodType NeighborhoodType
Definition: itkGPUDemonsRegistrationFunction.h:97
itk::GPUDemonsRegistrationFunction::m_SumOfSquaredDifference
double m_SumOfSquaredDifference
Definition: itkGPUDemonsRegistrationFunction.h:280
itk::GPUDemonsRegistrationFunction::m_DenominatorThreshold
double m_DenominatorThreshold
Definition: itkGPUDemonsRegistrationFunction.h:271
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:50
itk::GPUDemonsRegistrationFunction::m_MovingImageGradientCalculator
MovingImageGradientCalculatorPointer m_MovingImageGradientCalculator
Definition: itkGPUDemonsRegistrationFunction.h:261
itk::GPUDemonsRegistrationFunction::m_NumberOfPixelsProcessed
SizeValueType m_NumberOfPixelsProcessed
Definition: itkGPUDemonsRegistrationFunction.h:281
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itkCentralDifferenceImageFunction.h
itk::GPUDemonsRegistrationFunction::m_GPUPixelCounter
GPUReduction< int >::Pointer m_GPUPixelCounter
Definition: itkGPUDemonsRegistrationFunction.h:285
itk::GPUDemonsRegistrationFunction::m_UseMovingImageGradient
bool m_UseMovingImageGradient
Definition: itkGPUDemonsRegistrationFunction.h:262
itk::GPUDemonsRegistrationFunction::m_TimeStep
TimeStepType m_TimeStep
Definition: itkGPUDemonsRegistrationFunction.h:268
itk::GPUFiniteDifferenceFunction< TDisplacementField >::NeighborhoodType
typename Superclass::NeighborhoodType NeighborhoodType
Definition: itkGPUFiniteDifferenceFunction.h:81
itk::GPUFiniteDifferenceFunction< TDisplacementField >
itk::GPUDemonsRegistrationFunction::RadiusType
typename Superclass::RadiusType RadiusType
Definition: itkGPUDemonsRegistrationFunction.h:96
itk::GPUDemonsRegistrationFunction::m_IntensityDifferenceThreshold
double m_IntensityDifferenceThreshold
Definition: itkGPUDemonsRegistrationFunction.h:274
itk::GPUDataManager::Pointer
SmartPointer< Self > Pointer
Definition: itkGPUDataManager.h:52
itk::GPUDemonsRegistrationFunction::InterpolatorPointer
typename InterpolatorType::Pointer InterpolatorPointer
Definition: itkGPUDemonsRegistrationFunction.h:104
itk::GPUDemonsRegistrationFunction::FloatOffsetType
typename Superclass::FloatOffsetType FloatOffsetType
Definition: itkGPUDemonsRegistrationFunction.h:98
itk::GPUReduction
Definition: itkGPUReduction.h:40
itk::GPUPDEDeformableRegistrationFunction::FixedImagePointer
typename FixedImageType::ConstPointer FixedImagePointer
Definition: itkGPUPDEDeformableRegistrationFunction.h:61
itk::GPUPDEDeformableRegistrationFunction::MovingImagePointer
typename MovingImageType::ConstPointer MovingImagePointer
Definition: itkGPUPDEDeformableRegistrationFunction.h:57
itk::GPUDemonsRegistrationFunction::m_GPUSquaredDifference
GPUReduction< float >::Pointer m_GPUSquaredDifference
Definition: itkGPUDemonsRegistrationFunction.h:287
itk::CovariantVector
A templated class holding a n-Dimensional covariant vector.
Definition: itkCovariantVector.h:70
itk::GPUDemonsRegistrationFunction::GlobalDataStruct
Definition: itkGPUDemonsRegistrationFunction.h:240
itk::GPUDemonsRegistrationFunction::m_RMSChange
double m_RMSChange
Definition: itkGPUDemonsRegistrationFunction.h:282
itk::GPUDemonsRegistrationFunction::ComputeGlobalTimeStep
TimeStepType ComputeGlobalTimeStep(void *) const override
Definition: itkGPUDemonsRegistrationFunction.h:141
itk::GPUDemonsRegistrationFunction::m_MovingImageInterpolator
InterpolatorPointer m_MovingImageInterpolator
Definition: itkGPUDemonsRegistrationFunction.h:265
itk::itkGPUKernelClassMacro
itkGPUKernelClassMacro(GPUImageOpsKernel)
itk::GPUDemonsRegistrationFunction::m_GPUSquaredChange
GPUReduction< float >::Pointer m_GPUSquaredChange
Definition: itkGPUDemonsRegistrationFunction.h:286
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ConstNeighborhoodIterator< FixedImageType >
itk::GPUDemonsRegistrationFunction::SetMovingImageInterpolator
void SetMovingImageInterpolator(InterpolatorType *ptr)
Definition: itkGPUDemonsRegistrationFunction.h:127
itk::GPUDemonsRegistrationFunction::GlobalDataStruct::m_NumberOfPixelsProcessed
SizeValueType m_NumberOfPixelsProcessed
Definition: itkGPUDemonsRegistrationFunction.h:243
itk::GPUDemonsRegistrationFunction::GlobalDataStruct::m_SumOfSquaredChange
double m_SumOfSquaredChange
Definition: itkGPUDemonsRegistrationFunction.h:244
itk::GPUDemonsRegistrationFunction::m_SumOfSquaredChange
double m_SumOfSquaredChange
Definition: itkGPUDemonsRegistrationFunction.h:283
itk::GPUDemonsRegistrationFunction::GetUseMovingImageGradient
virtual bool GetUseMovingImageGradient() const
Definition: itkGPUDemonsRegistrationFunction.h:212
itk::GPUDemonsRegistrationFunction::SetUseMovingImageGradient
virtual void SetUseMovingImageGradient(bool flag)
Definition: itkGPUDemonsRegistrationFunction.h:207
itk::GPUDemonsRegistrationFunction::m_Normalizer
double m_Normalizer
Definition: itkGPUDemonsRegistrationFunction.h:255
itk::GPUDemonsRegistrationFunction::SpacingType
typename FixedImageType::SpacingType SpacingType
Definition: itkGPUDemonsRegistrationFunction.h:85
itk::GPUFiniteDifferenceFunction< TDisplacementField >::PixelType
typename Superclass::PixelType PixelType
Definition: itkGPUFiniteDifferenceFunction.h:64
itkGPUReduction.h
itk::GPUDemonsRegistrationFunction::GetRMSChange
virtual double GetRMSChange() const
Definition: itkGPUDemonsRegistrationFunction.h:198
itk::GPUPDEDeformableRegistrationFunction
Definition: itkGPUPDEDeformableRegistrationFunction.h:41
itk::GPUPDEDeformableRegistrationFunction::FixedImageType
TFixedImage FixedImageType
Definition: itkGPUPDEDeformableRegistrationFunction.h:60
itk::GPUDemonsRegistrationFunction::PointType
typename InterpolatorType::PointType PointType
Definition: itkGPUDemonsRegistrationFunction.h:105
itk::GPUDemonsRegistrationFunction::MovingImageGradientCalculatorPointer
typename MovingImageGradientCalculatorType::Pointer MovingImageGradientCalculatorPointer
Definition: itkGPUDemonsRegistrationFunction.h:117
itk::GPUFiniteDifferenceFunction< TDisplacementField >::FloatOffsetType
typename Superclass::FloatOffsetType FloatOffsetType
Definition: itkGPUFiniteDifferenceFunction.h:85
itk::GPUDemonsRegistrationFunction
Definition: itkGPUDemonsRegistrationFunction.h:58
itk::GPUDemonsRegistrationFunction::GetMetric
virtual double GetMetric() const
Definition: itkGPUDemonsRegistrationFunction.h:191
itk::InterpolateImageFunction
Base class for all image interpolators.
Definition: itkInterpolateImageFunction.h:45
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itk::GPUFiniteDifferenceFunction< TDisplacementField >::RadiusType
typename Superclass::RadiusType RadiusType
Definition: itkGPUFiniteDifferenceFunction.h:78
itk::GPUDemonsRegistrationFunction::GetMovingImageInterpolator
InterpolatorType * GetMovingImageInterpolator()
Definition: itkGPUDemonsRegistrationFunction.h:134