ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkGPUDemonsRegistrationFunction.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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,
60  TMovingImage,
61  TDisplacementField >
62 {
63 public:
64  ITK_DISALLOW_COPY_AND_ASSIGN(GPUDemonsRegistrationFunction);
65 
68  using Superclass = GPUPDEDeformableRegistrationFunction< TFixedImage, TMovingImage,
69  TDisplacementField>;
72 
74  itkNewMacro(Self);
75 
77  itkTypeMacro(GPUDemonsRegistrationFunction,
79 
81  using MovingImageType = typename Superclass::MovingImageType;
82  using MovingImagePointer = typename Superclass::MovingImagePointer;
83 
85  using FixedImageType = typename Superclass::FixedImageType;
86  using FixedImagePointer = typename Superclass::FixedImagePointer;
89  using SpacingType = typename FixedImageType::SpacingType;
90 
92  using DisplacementFieldType = typename Superclass::DisplacementFieldType;
93  using DisplacementFieldTypePointer = typename Superclass::DisplacementFieldTypePointer;
94 
96  static constexpr unsigned int ImageDimension = Superclass::ImageDimension;
97 
99  using PixelType = typename Superclass::PixelType;
103  using TimeStepType = typename Superclass::TimeStepType;
104 
106  using CoordRepType = double;
111 
114 
118 
123 
126 
128  itkGetOpenCLSourceFromKernelMacro(GPUDemonsRegistrationFunctionKernel);
129 
132  {
133  m_MovingImageInterpolator = ptr;
134  }
135 
138  {
139  return m_MovingImageInterpolator;
140  }
141 
143  virtual TimeStepType ComputeGlobalTimeStep( void *itkNotUsed(GlobalData) )
144  const override
145  {
146  return m_TimeStep;
147  }
148 
151  void * GetGlobalDataPointer() const override
152  {
153  GlobalDataStruct *global = new GlobalDataStruct();
154 
155  global->m_SumOfSquaredDifference = 0.0;
156  global->m_NumberOfPixelsProcessed = 0L;
157  global->m_SumOfSquaredChange = 0;
158  return global;
159  }
160 
162  void ReleaseGlobalDataPointer(void *GlobalData) const override;
163 
166  void GPUAllocateMetricData(unsigned int numPixels) override;
167 
170  void GPUReleaseMetricData() override;
171 
173  void InitializeIteration() override;
174 
177  virtual PixelType ComputeUpdate( const NeighborhoodType & neighborhood,
178  void *globalData,
179  const FloatOffsetType & offset =
180  FloatOffsetType(0.0) ) override;
181 
182  virtual void GPUComputeUpdate( const DisplacementFieldTypePointer output,
183  DisplacementFieldTypePointer update,
184  void *gd) override;
185 
189  virtual double GetMetric() const
190  {
191  return m_Metric;
192  }
193 
195  virtual double GetRMSChange() const
196  {
197  return m_RMSChange;
198  }
199 
203  virtual void SetUseMovingImageGradient(bool flag)
204  {
205  m_UseMovingImageGradient = flag;
206  }
207  virtual bool GetUseMovingImageGradient() const
208  {
209  return m_UseMovingImageGradient;
210  }
212 
217  virtual void SetIntensityDifferenceThreshold(double);
218 
219  virtual double GetIntensityDifferenceThreshold() const;
220 
221 protected:
224 
225  void PrintSelf(std::ostream & os, Indent indent) const override;
226 
228  using FixedImageNeighborhoodIteratorType =
230 
237  };
238 
239  /* GPU kernel handle for GPUComputeUpdate */
241 
242 private:
244  //SpacingType m_FixedImageSpacing;
245  //PointType m_FixedImageOrigin;
247  double m_Normalizer;
248 
251 
255 
258 
261 
264 
267 
271  mutable double m_Metric;
272  mutable double m_SumOfSquaredDifference;
274  mutable double m_RMSChange;
275  mutable double m_SumOfSquaredChange;
276 
280 
282  mutable std::mutex m_MetricCalculationLock;
283 
284 };
285 } // end namespace itk
286 
287 #ifndef ITK_MANUAL_INSTANTIATION
288 #include "itkGPUDemonsRegistrationFunction.hxx"
289 #endif
290 
291 #endif
typename InterpolatorType::PointType PointType
GPUReduction< float >::Pointer m_GPUSquaredDifference
Light weight base class for most itk classes.
typename InterpolatorType::Pointer InterpolatorPointer
unsigned long SizeValueType
Definition: itkIntTypes.h:83
typename Superclass::NeighborhoodType NeighborhoodType
Calculate the derivative by central differencing.
itkGPUKernelClassMacro(GPUImageOpsKernel)
typename DisplacementFieldType::Pointer DisplacementFieldTypePointer
typename FixedImageType::SpacingType SpacingType
typename FixedImageType::IndexType IndexType
MovingImageGradientCalculatorPointer m_MovingImageGradientCalculator
Linearly interpolate an image at specified positions.
Base class for all image interpolaters.
typename Superclass::FloatOffsetType FloatOffsetType
typename FixedImageType::SizeType SizeType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
virtual TimeStepType ComputeGlobalTimeStep(void *) const override
typename MovingImageGradientCalculatorType::Pointer MovingImageGradientCalculatorPointer
typename Superclass::TimeStepType TimeStepType
typename GradientCalculatorType::Pointer GradientCalculatorPointer
A templated class holding a n-Dimensional covariant vector.
SmartPointer< Self > Pointer