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
27namespace itk
28{
55itkGPUKernelClassMacro(GPUDemonsRegistrationFunctionKernel);
56
57template <typename TFixedImage, typename TMovingImage, typename TDisplacementField>
58class ITK_TEMPLATE_EXPORT GPUDemonsRegistrationFunction
59 : public GPUPDEDeformableRegistrationFunction<TFixedImage, TMovingImage, TDisplacementField>
60{
61public:
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
178
180 void
182
188 ComputeUpdate(const NeighborhoodType & neighborhood,
189 void * globalData,
190 const FloatOffsetType & offset = FloatOffsetType(0.0)) override;
191
193 void
195
201 virtual double
202 GetMetric() const
203 {
204 return m_Metric;
205 }
206
208 virtual double
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
235
236 virtual double
238
239protected:
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
261private:
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
Calculate the derivative by central differencing.
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
A templated class holding a n-Dimensional covariant vector.
typename ConstNeighborhoodIterator< TDisplacementField >::RadiusType RadiusType
SmartPointer< Self > Pointer
void PrintSelf(std::ostream &os, Indent indent) const override
typename FixedImageType::IndexType IndexType
PixelType ComputeUpdate(const NeighborhoodType &neighborhood, void *globalData, const FloatOffsetType &offset=FloatOffsetType(0.0)) override
typename FixedImageType::SpacingType SpacingType
typename InterpolatorType::Pointer InterpolatorPointer
typename InterpolatorType::PointType PointType
void GPUAllocateMetricData(unsigned int numPixels) override
typename MovingImageGradientCalculatorType::Pointer MovingImageGradientCalculatorPointer
void ReleaseGlobalDataPointer(void *GlobalData) const override
typename FixedImageType::SizeType SizeType
itkGetOpenCLSourceFromKernelMacro(GPUDemonsRegistrationFunctionKernel)
void GPUComputeUpdate(const DisplacementFieldTypePointer output, DisplacementFieldTypePointer update, void *gd) override
~GPUDemonsRegistrationFunction() override=default
virtual void SetIntensityDifferenceThreshold(double)
virtual double GetIntensityDifferenceThreshold() const
typename GradientCalculatorType::Pointer GradientCalculatorPointer
TimeStepType ComputeGlobalTimeStep(void *) const override
typename DisplacementFieldType::Pointer DisplacementFieldTypePointer
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Base class for all image interpolators.
Light weight base class for most itk classes.
Linearly interpolate an image at specified positions.
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:63
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
itkGPUKernelClassMacro(GPUImageOpsKernel)
unsigned long SizeValueType
Definition: itkIntTypes.h:86