ITK  6.0.0
Insight Toolkit
itkESMDemonsRegistrationFunction.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 itkESMDemonsRegistrationFunction_h
19 #define itkESMDemonsRegistrationFunction_h
20 
23 #include "itkWarpImageFilter.h"
24 #include "ITKPDEDeformableRegistrationExport.h"
25 #include <mutex>
26 
27 namespace itk
28 {
34 {
35 public:
40  enum class Gradient : uint8_t
41  {
42  Symmetric = 0,
43  Fixed = 1,
44  WarpedMoving = 2,
45  MappedMoving = 3
46  };
47 };
48 // Define how to print enumeration
49 extern ITKPDEDeformableRegistration_EXPORT std::ostream &
50 operator<<(std::ostream & out, const ESMDemonsRegistrationFunctionEnums::Gradient value);
83 template <typename TFixedImage, typename TMovingImage, typename TDisplacementField>
84 class ITK_TEMPLATE_EXPORT ESMDemonsRegistrationFunction
85  : public PDEDeformableRegistrationFunction<TFixedImage, TMovingImage, TDisplacementField>
86 {
87 public:
88  ITK_DISALLOW_COPY_AND_MOVE(ESMDemonsRegistrationFunction);
89 
93 
96 
98  itkNewMacro(Self);
99 
101  itkOverrideGetNameOfClassMacro(ESMDemonsRegistrationFunction);
102 
104  using typename Superclass::MovingImageType;
105  using typename Superclass::MovingImagePointer;
106  using MovingPixelType = typename MovingImageType::PixelType;
107 
109  using typename Superclass::FixedImageType;
110  using typename Superclass::FixedImagePointer;
113  using SpacingType = typename FixedImageType::SpacingType;
115 
117  using typename Superclass::DisplacementFieldType;
118  using typename Superclass::DisplacementFieldTypePointer;
119 
121  static constexpr unsigned int ImageDimension = Superclass::ImageDimension;
122 
124  using typename Superclass::PixelType;
125  using typename Superclass::RadiusType;
126  using typename Superclass::NeighborhoodType;
127  using typename Superclass::FloatOffsetType;
128  using typename Superclass::TimeStepType;
129 
131  using CoordinateType = double;
132 #ifndef ITK_FUTURE_LEGACY_REMOVE
133  using CoordRepType ITK_FUTURE_DEPRECATED(
134  "ITK 6 discourages using `CoordRepType`. Please use `CoordinateType` instead!") = CoordinateType;
135 #endif
140 
143 
145 
148 
152 
156 
158  void
160  {
161  m_MovingImageInterpolator = ptr;
162  m_MovingImageWarper->SetInterpolator(ptr);
163  }
167  InterpolatorType *
169  {
170  return m_MovingImageInterpolator;
171  }
172 
174  TimeStepType
175  ComputeGlobalTimeStep(void * itkNotUsed(GlobalData)) const override
176  {
177  return m_TimeStep;
178  }
179 
182  void *
183  GetGlobalDataPointer() const override
184  {
185  auto * global = new GlobalDataStruct();
186 
187  global->m_SumOfSquaredDifference = 0.0;
188  global->m_NumberOfPixelsProcessed = 0L;
189  global->m_SumOfSquaredChange = 0;
190  return global;
191  }
192 
194  void
195  ReleaseGlobalDataPointer(void * gd) const override;
196 
198  void
199  InitializeIteration() override;
200 
203  PixelType
204  ComputeUpdate(const NeighborhoodType & it, void * gd, const FloatOffsetType & offset = FloatOffsetType(0.0)) override;
205 
209  virtual double
210  GetMetric() const
211  {
212  return m_Metric;
213  }
214 
216  virtual const double &
217  GetRMSChange() const
218  {
219  return m_RMSChange;
220  }
221 
226  virtual void
227  SetIntensityDifferenceThreshold(double);
228 
229  virtual double
230  GetIntensityDifferenceThreshold() const;
231 
235  virtual void
237  {
238  this->m_MaximumUpdateStepLength = sm;
239  }
240 
241  virtual double
243  {
244  return this->m_MaximumUpdateStepLength;
245  }
246 
248 #if !defined(ITK_LEGACY_REMOVE)
249 
250  static constexpr GradientEnum Symmetric = GradientEnum::Symmetric;
251  static constexpr GradientEnum Fixed = GradientEnum::Fixed;
252  static constexpr GradientEnum WarpedMoving = GradientEnum::WarpedMoving;
253  static constexpr GradientEnum MappedMoving = GradientEnum::MappedMoving;
254 #endif
255 
257  virtual void
259  {
260  m_UseGradientType = gtype;
261  }
262  virtual GradientEnum
264  {
265  return m_UseGradientType;
266  }
269 protected:
271  ~ESMDemonsRegistrationFunction() override = default;
272  void
273  PrintSelf(std::ostream & os, Indent indent) const override;
274 
277 
281  {
285  };
286 
287 private:
289  PointType m_FixedImageOrigin{};
290  SpacingType m_FixedImageSpacing{};
291  DirectionType m_FixedImageDirection{};
292  double m_Normalizer{};
293 
295  GradientCalculatorPointer m_FixedImageGradientCalculator{};
296 
298  MovingImageGradientCalculatorPointer m_MappedMovingImageGradientCalculator{};
299 
300  GradientEnum m_UseGradientType{};
301 
303  InterpolatorPointer m_MovingImageInterpolator{};
304 
306  WarperPointer m_MovingImageWarper{};
307 
308  MovingImageType * m_MovingImageWarperOutput{};
309 
311  TimeStepType m_TimeStep{};
312 
314  double m_DenominatorThreshold{};
315 
317  double m_IntensityDifferenceThreshold{};
318 
320  double m_MaximumUpdateStepLength{};
321 
325  mutable double m_Metric{};
326  mutable double m_SumOfSquaredDifference{};
327  mutable SizeValueType m_NumberOfPixelsProcessed{};
328  mutable double m_RMSChange{};
329  mutable double m_SumOfSquaredChange{};
330 
332  mutable std::mutex m_MetricCalculationMutex{};
333 };
334 } // end namespace itk
335 
336 #ifndef ITK_MANUAL_INSTANTIATION
337 # include "itkESMDemonsRegistrationFunction.hxx"
338 #endif
339 
340 #endif
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::FiniteDifferenceFunction< TDisplacementField >::RadiusType
typename ConstNeighborhoodIterator< TDisplacementField >::RadiusType RadiusType
Definition: itkFiniteDifferenceFunction.h:97
itk::ESMDemonsRegistrationFunctionEnums::Gradient::Symmetric
itk::ESMDemonsRegistrationFunction::MovingPixelType
typename MovingImageType::PixelType MovingPixelType
Definition: itkESMDemonsRegistrationFunction.h:106
itk::GTest::TypedefsAndConstructors::Dimension2::DirectionType
ImageBaseType::DirectionType DirectionType
Definition: itkGTestTypedefsAndConstructors.h:52
itk::ESMDemonsRegistrationFunction::IndexType
typename FixedImageType::IndexType IndexType
Definition: itkESMDemonsRegistrationFunction.h:111
itk::ESMDemonsRegistrationFunction::GetMaximumUpdateStepLength
virtual double GetMaximumUpdateStepLength() const
Definition: itkESMDemonsRegistrationFunction.h:242
itk::ESMDemonsRegistrationFunction::GradientCalculatorPointer
typename GradientCalculatorType::Pointer GradientCalculatorPointer
Definition: itkESMDemonsRegistrationFunction.h:151
itk::ESMDemonsRegistrationFunction::GetRMSChange
virtual const double & GetRMSChange() const
Definition: itkESMDemonsRegistrationFunction.h:217
itk::ESMDemonsRegistrationFunction::GlobalDataStruct
Definition: itkESMDemonsRegistrationFunction.h:280
itk::ESMDemonsRegistrationFunction::SetMovingImageInterpolator
void SetMovingImageInterpolator(InterpolatorType *ptr)
Definition: itkESMDemonsRegistrationFunction.h:159
GradientEnum
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itkPDEDeformableRegistrationFunction.h
itk::ESMDemonsRegistrationFunction::ComputeGlobalTimeStep
TimeStepType ComputeGlobalTimeStep(void *) const override
Definition: itkESMDemonsRegistrationFunction.h:175
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::ESMDemonsRegistrationFunction::GlobalDataStruct::m_NumberOfPixelsProcessed
SizeValueType m_NumberOfPixelsProcessed
Definition: itkESMDemonsRegistrationFunction.h:283
itk::operator<<
ITKCommon_EXPORT std::ostream & operator<<(std::ostream &out, typename AnatomicalOrientation::CoordinateEnum value)
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itkWarpImageFilter.h
itk::ESMDemonsRegistrationFunction::MovingImageGradientCalculatorPointer
typename MovingImageGradientCalculatorType::Pointer MovingImageGradientCalculatorPointer
Definition: itkESMDemonsRegistrationFunction.h:155
itk::ESMDemonsRegistrationFunction::WarperPointer
typename WarperType::Pointer WarperPointer
Definition: itkESMDemonsRegistrationFunction.h:144
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::ESMDemonsRegistrationFunction::SetUseGradientType
virtual void SetUseGradientType(GradientEnum gtype)
Definition: itkESMDemonsRegistrationFunction.h:258
itk::LinearInterpolateImageFunction
Linearly interpolate an image at specified positions.
Definition: itkLinearInterpolateImageFunction.h:51
itk::ESMDemonsRegistrationFunction::InterpolatorPointer
typename InterpolatorType::Pointer InterpolatorPointer
Definition: itkESMDemonsRegistrationFunction.h:137
itk::ESMDemonsRegistrationFunctionEnums
Contains all enum classes used by ESMDemonsRegistrationFunction class.
Definition: itkESMDemonsRegistrationFunction.h:33
itk::ESMDemonsRegistrationFunction::GlobalDataStruct::m_SumOfSquaredChange
double m_SumOfSquaredChange
Definition: itkESMDemonsRegistrationFunction.h:284
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itkCentralDifferenceImageFunction.h
itk::ESMDemonsRegistrationFunctionEnums::Gradient::Fixed
itk::ESMDemonsRegistrationFunction::DirectionType
typename FixedImageType::DirectionType DirectionType
Definition: itkESMDemonsRegistrationFunction.h:114
itk::ESMDemonsRegistrationFunction::SizeType
typename FixedImageType::SizeType SizeType
Definition: itkESMDemonsRegistrationFunction.h:112
itk::PDEDeformableRegistrationFunction
Definition: itkPDEDeformableRegistrationFunction.h:41
itk::FiniteDifferenceFunction< TDisplacementField >::PixelType
typename ImageType::PixelType PixelType
Definition: itkFiniteDifferenceFunction.h:83
itk::ESMDemonsRegistrationFunction::GetGlobalDataPointer
void * GetGlobalDataPointer() const override
Definition: itkESMDemonsRegistrationFunction.h:183
itk::ESMDemonsRegistrationFunction
Fast implementation of the symmetric demons registration force.
Definition: itkESMDemonsRegistrationFunction.h:84
itk::CovariantVector
A templated class holding a n-Dimensional covariant vector.
Definition: itkCovariantVector.h:70
itk::ESMDemonsRegistrationFunctionEnums::Gradient
Gradient
Definition: itkESMDemonsRegistrationFunction.h:40
itk::ESMDemonsRegistrationFunction::CoordinateType
double CoordinateType
Definition: itkESMDemonsRegistrationFunction.h:131
itk::WarpImageFilter
Warps an image using an input displacement field.
Definition: itkWarpImageFilter.h:85
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::ConstNeighborhoodIterator
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
Definition: itkConstNeighborhoodIterator.h:51
itk::ESMDemonsRegistrationFunctionEnums::Gradient::MappedMoving
itk::ESMDemonsRegistrationFunction::GlobalDataStruct::m_SumOfSquaredDifference
double m_SumOfSquaredDifference
Definition: itkESMDemonsRegistrationFunction.h:282
itk::FiniteDifferenceFunction< TDisplacementField >
itk::ESMDemonsRegistrationFunctionEnums::Gradient::WarpedMoving
itk::ESMDemonsRegistrationFunction::GetMovingImageInterpolator
InterpolatorType * GetMovingImageInterpolator()
Definition: itkESMDemonsRegistrationFunction.h:168
itk::ESMDemonsRegistrationFunction::SetMaximumUpdateStepLength
virtual void SetMaximumUpdateStepLength(double sm)
Definition: itkESMDemonsRegistrationFunction.h:236
itk::ESMDemonsRegistrationFunction::PointType
typename InterpolatorType::PointType PointType
Definition: itkESMDemonsRegistrationFunction.h:138
itk::ESMDemonsRegistrationFunction::GetMetric
virtual double GetMetric() const
Definition: itkESMDemonsRegistrationFunction.h:210
itk::ESMDemonsRegistrationFunction::SpacingType
typename FixedImageType::SpacingType SpacingType
Definition: itkESMDemonsRegistrationFunction.h:113
itk::ESMDemonsRegistrationFunction::GetUseGradientType
virtual GradientEnum GetUseGradientType() const
Definition: itkESMDemonsRegistrationFunction.h:263
itk::InterpolateImageFunction
Base class for all image interpolators.
Definition: itkInterpolateImageFunction.h:45
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86
itk::FiniteDifferenceFunction< TDisplacementField >::TimeStepType
double TimeStepType
Definition: itkFiniteDifferenceFunction.h:90