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 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
174
176 void
178
184 ComputeUpdate(const NeighborhoodType & neighborhood,
185 void * globalData,
186 const FloatOffsetType & offset = FloatOffsetType(0.0)) override;
187
189 void
191
197 virtual double
198 GetMetric() const
199 {
200 return m_Metric;
201 }
202
204 virtual double
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
231
232 virtual double
234
235protected:
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
257private:
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
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