ITK  5.4.0
Insight Toolkit
itkRegistrationParameterScalesEstimator.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 itkRegistrationParameterScalesEstimator_h
19 #define itkRegistrationParameterScalesEstimator_h
20 
21 #include "itkTransform.h"
24 #include "itkIdentityTransform.h"
26 
30 #include "ITKOptimizersv4Export.h"
31 
32 namespace itk
33 {
39 {
40 public:
45  enum class SamplingStrategy : uint8_t
46  {
52  };
53 };
55 // Define how to print enumeration
56 extern ITKOptimizersv4_EXPORT std::ostream &
58 
79 template <typename TMetric>
80 class ITK_TEMPLATE_EXPORT RegistrationParameterScalesEstimator
81  : public OptimizerParameterScalesEstimatorTemplate<typename TMetric::ParametersValueType>
82 {
83 public:
84  ITK_DISALLOW_COPY_AND_MOVE(RegistrationParameterScalesEstimator);
85 
91 
93  itkOverrideGetNameOfClassMacro(RegistrationParameterScalesEstimator);
94 
96  using typename Superclass::ScalesType;
97 
99  using typename Superclass::ParametersType;
100 
102  using typename Superclass::FloatType;
103 
104  using MetricType = TMetric;
107 
109  using FixedTransformType = typename MetricType::FixedTransformType;
111 
112  using MovingTransformType = typename MetricType::MovingTransformType;
114 
116  static constexpr SizeValueType FixedDimension = TMetric::FixedDimension;
117  static constexpr SizeValueType MovingDimension = TMetric::MovingDimension;
118  static constexpr SizeValueType VirtualDimension = TMetric::VirtualDimension;
119 
120  using VirtualImageType = typename TMetric::VirtualImageType;
121  using VirtualImageConstPointer = typename TMetric::VirtualImageConstPointer;
122  using VirtualImagePointer = typename TMetric::VirtualImagePointer;
123  using VirtualSpacingType = typename TMetric::VirtualSpacingType;
124  using VirtualRegionType = typename TMetric::VirtualRegionType;
125  using VirtualSizeType = typename TMetric::VirtualSizeType;
126  using VirtualPointType = typename TMetric::VirtualPointType;
127  using VirtualIndexType = typename TMetric::VirtualIndexType;
128 
129  using VirtualPointSetType = typename TMetric::VirtualPointSetType;
130  using VirtualPointSetPointer = typename TMetric::VirtualPointSetPointer;
131 
134 #if !defined(ITK_LEGACY_REMOVE)
135  // We need to expose the enum values at the class level
136  // for backwards compatibility
137  static constexpr SamplingStrategyType FullDomainSampling = SamplingStrategyType::FullDomainSampling;
138  static constexpr SamplingStrategyType CornerSampling = SamplingStrategyType::CornerSampling;
139  static constexpr SamplingStrategyType RandomSampling = SamplingStrategyType::RandomSampling;
140  static constexpr SamplingStrategyType CentralRegionSampling = SamplingStrategyType::CentralRegionSampling;
141  static constexpr SamplingStrategyType VirtualDomainPointSetSampling =
142  SamplingStrategyType::VirtualDomainPointSetSampling;
143 #endif
144 
145  using SamplePointContainerType = std::vector<VirtualPointType>;
146 
148  using JacobianType = typename TMetric::JacobianType;
149 
154  itkSetObjectMacro(Metric, MetricType);
155  itkGetConstObjectMacro(Metric, MetricType);
162  itkSetMacro(TransformForward, bool);
163  itkGetConstMacro(TransformForward, bool);
164  itkBooleanMacro(TransformForward);
168 #ifndef ITK_FUTURE_LEGACY_REMOVE
169  virtual void
170  SetVirtualDomainPointSet(VirtualPointSetType * const arg)
171  {
172  const auto * const constArg = arg;
173  // Call the overload defined by itkSetConstObjectMacro, or an override.
174  this->SetVirtualDomainPointSet(constArg);
175  }
176 #endif
177  itkSetConstObjectMacro(VirtualDomainPointSet, VirtualPointSetType);
178  itkGetConstObjectMacro(VirtualDomainPointSet, VirtualPointSetType);
182  itkSetMacro(CentralRegionRadius, IndexValueType);
183  itkGetConstMacro(CentralRegionRadius, IndexValueType);
187  void
188  EstimateScales(ScalesType & scales) override = 0;
189 
191  FloatType
192  EstimateStepScale(const ParametersType & step) override = 0;
193 
195  void
196  EstimateLocalStepScales(const ParametersType & step, ScalesType & localStepScales) override = 0;
197 
199  FloatType
200  EstimateMaximumStepSize() override;
201 
203  virtual void
204  SetScalesSamplingStrategy();
205 
207  virtual void
208  SetStepScaleSamplingStrategy();
209 
210 protected:
212  ~RegistrationParameterScalesEstimator() override = default;
213 
214  void
215  PrintSelf(std::ostream & os, Indent indent) const override;
216 
218  bool
219  CheckAndSetInputs();
220 
222  itkSetMacro(NumberOfRandomSamples, SizeValueType);
223 
226  itkSetMacro(SamplingStrategy, SamplingStrategyType);
227 
232  bool
233  CheckGeneralAffineTransform();
234 
243  template <typename TTransform>
244  bool
245  CheckGeneralAffineTransformTemplated();
246 
252  template <typename TTargetPointType>
253  void
254  TransformPoint(const VirtualPointType & point, TTargetPointType & mappedPoint);
255 
257  template <typename TContinuousIndexType>
258  void
259  TransformPointToContinuousIndex(const VirtualPointType & point, TContinuousIndexType & mappedIndex);
260 
262  void
263  ComputeSquaredJacobianNorms(const VirtualPointType & point, ParametersType & squareNorms);
264 
266  bool
267  TransformHasLocalSupportForScalesEstimation();
268 
270  bool
271  IsDisplacementFieldTransform();
272 
274  bool
275  IsBSplineTransform();
276 
279  GetNumberOfLocalParameters();
280 
282  void
283  UpdateTransformParameters(const ParametersType & deltaParameters);
284 
286  virtual void
287  SampleVirtualDomain();
288 
290  void
291  SampleVirtualDomainFully();
292 
297  void
298  SampleVirtualDomainWithCorners();
299 
301  void
302  SampleVirtualDomainRandomly();
303 
308  void
309  SampleVirtualDomainWithCentralRegion();
310 
312  void
313  SampleVirtualDomainWithRegion(VirtualRegionType region);
314 
316  void
317  SampleVirtualDomainWithPointSet();
318 
323  VirtualIndexType
324  GetVirtualDomainCentralIndex();
325 
327  VirtualRegionType
328  GetVirtualDomainCentralRegion();
329 
332  GetTransform();
333 
336  GetDimension();
337 
340  itkGetMacro(SamplingStrategy, SamplingStrategyType);
341 
343  MetricPointer m_Metric{};
344 
346  SamplePointContainerType m_SamplePoints{};
347 
349  mutable TimeStamp m_SamplingTime{};
350 
352  SizeValueType m_NumberOfRandomSamples{};
353 
355  IndexValueType m_CentralRegionRadius{};
356 
357  typename VirtualPointSetType::ConstPointer m_VirtualDomainPointSet{};
358 
359  // the threshold to decide if the number of random samples uses logarithm
360  static constexpr SizeValueType SizeOfSmallDomain = 1000;
361 
362 private:
367  bool m_TransformForward{};
368 
369  // sampling strategy
370  SamplingStrategyType m_SamplingStrategy{};
371 
372 }; // class RegistrationParameterScalesEstimator
373 } // namespace itk
374 
375 
376 #ifndef ITK_MANUAL_INSTANTIATION
377 # include "itkRegistrationParameterScalesEstimator.hxx"
378 #endif
379 
380 #endif /* itkRegistrationParameterScalesEstimator_h */
itk::RegistrationParameterScalesEstimator::MovingTransformConstPointer
typename MovingTransformType::ConstPointer MovingTransformConstPointer
Definition: itkRegistrationParameterScalesEstimator.h:113
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::OptimizerParameterScalesEstimatorTemplate
OptimizerParameterScalesEstimatorTemplate is the base class offering a empty method of estimating the...
Definition: itkOptimizerParameterScalesEstimator.h:39
itk::SamplingStrategyEnum
RegistrationParameterScalesEstimatorEnums::SamplingStrategy SamplingStrategyEnum
Definition: itkRegistrationParameterScalesEstimator.h:54
itk::RegistrationParameterScalesEstimatorEnums::SamplingStrategy::CentralRegionSampling
itk::RegistrationParameterScalesEstimatorEnums::SamplingStrategy::RandomSampling
ConstPointer
SmartPointer< const Self > ConstPointer
Definition: itkAddImageFilter.h:94
itkImageRegionConstIteratorWithIndex.h
itk::operator<<
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:216
itk::RegistrationParameterScalesEstimator::SamplePointContainerType
std::vector< VirtualPointType > SamplePointContainerType
Definition: itkRegistrationParameterScalesEstimator.h:145
itk::RegistrationParameterScalesEstimator::VirtualSpacingType
typename TMetric::VirtualSpacingType VirtualSpacingType
Definition: itkRegistrationParameterScalesEstimator.h:123
itk::RegistrationParameterScalesEstimator::MetricType
TMetric MetricType
Definition: itkRegistrationParameterScalesEstimator.h:104
itk::RegistrationParameterScalesEstimator
Implements a registration helper class for estimating scales of transform parameters and step sizes.
Definition: itkRegistrationParameterScalesEstimator.h:80
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::RegistrationParameterScalesEstimator::JacobianType
typename TMetric::JacobianType JacobianType
Definition: itkRegistrationParameterScalesEstimator.h:148
itk::RegistrationParameterScalesEstimator::VirtualImagePointer
typename TMetric::VirtualImagePointer VirtualImagePointer
Definition: itkRegistrationParameterScalesEstimator.h:122
itk::RegistrationParameterScalesEstimator::VirtualPointType
typename TMetric::VirtualPointType VirtualPointType
Definition: itkRegistrationParameterScalesEstimator.h:126
itk::IndexValueType
long IndexValueType
Definition: itkIntTypes.h:90
itkTranslationTransform.h
itk::RegistrationParameterScalesEstimator::VirtualPointSetType
typename TMetric::VirtualPointSetType VirtualPointSetType
Definition: itkRegistrationParameterScalesEstimator.h:129
itk::RegistrationParameterScalesEstimatorEnums::SamplingStrategy::CornerSampling
itk::RegistrationParameterScalesEstimatorEnums::SamplingStrategy::FullDomainSampling
itkImageRandomConstIteratorWithIndex.h
itkOptimizerParameterScalesEstimator.h
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::RegistrationParameterScalesEstimator::VirtualSizeType
typename TMetric::VirtualSizeType VirtualSizeType
Definition: itkRegistrationParameterScalesEstimator.h:125
itk::RegistrationParameterScalesEstimator::MovingTransformType
typename MetricType::MovingTransformType MovingTransformType
Definition: itkRegistrationParameterScalesEstimator.h:112
itk::point
*par Constraints *The filter requires an image with at least two dimensions and a vector *length of at least The theory supports extension to scalar but *the implementation of the itk vector classes do not **The template parameter TRealType must be floating point(float or double) or *a user-defined "real" numerical type with arithmetic operations defined *sufficient to compute derivatives. **\par Performance *This filter will automatically multithread if run with *SetUsePrincipleComponents
itk::RegistrationParameterScalesEstimator::FixedTransformType
typename MetricType::FixedTransformType FixedTransformType
Definition: itkRegistrationParameterScalesEstimator.h:109
itkMatrixOffsetTransformBase.h
itk::RegistrationParameterScalesEstimatorEnums::SamplingStrategy
SamplingStrategy
Definition: itkRegistrationParameterScalesEstimator.h:45
itk::RegistrationParameterScalesEstimator::MetricConstPointer
typename MetricType::ConstPointer MetricConstPointer
Definition: itkRegistrationParameterScalesEstimator.h:106
itk::RegistrationParameterScalesEstimatorEnums::SamplingStrategy::VirtualDomainPointSetSampling
itk::TimeStamp
Generate a unique, increasing time value.
Definition: itkTimeStamp.h:60
itkIdentityTransform.h
itk::RegistrationParameterScalesEstimator::VirtualPointSetPointer
typename TMetric::VirtualPointSetPointer VirtualPointSetPointer
Definition: itkRegistrationParameterScalesEstimator.h:130
itk::RegistrationParameterScalesEstimatorEnums
This class contains all the enum classes used by RegistrationParameterScalesEstimator class.
Definition: itkRegistrationParameterScalesEstimator.h:38
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::RegistrationParameterScalesEstimator::MetricPointer
typename MetricType::Pointer MetricPointer
Definition: itkRegistrationParameterScalesEstimator.h:105
itk::RegistrationParameterScalesEstimator::VirtualRegionType
typename TMetric::VirtualRegionType VirtualRegionType
Definition: itkRegistrationParameterScalesEstimator.h:124
SamplingStrategy
itk::RegistrationParameterScalesEstimator::VirtualIndexType
typename TMetric::VirtualIndexType VirtualIndexType
Definition: itkRegistrationParameterScalesEstimator.h:127
itk::RegistrationParameterScalesEstimator::VirtualImageConstPointer
typename TMetric::VirtualImageConstPointer VirtualImageConstPointer
Definition: itkRegistrationParameterScalesEstimator.h:121
itkTransform.h
itk::RegistrationParameterScalesEstimator::VirtualImageType
typename TMetric::VirtualImageType VirtualImageType
Definition: itkRegistrationParameterScalesEstimator.h:120
itk::TransformBaseTemplate
Definition: itkTransformBase.h:68
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itkRigid3DPerspectiveTransform.h
itk::RegistrationParameterScalesEstimator::FixedTransformConstPointer
typename FixedTransformType::ConstPointer FixedTransformConstPointer
Definition: itkRegistrationParameterScalesEstimator.h:110