ITK  5.2.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  * 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 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:
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 
94 
96  using ScalesType = typename Superclass::ScalesType;
97 
99  using ParametersType = typename Superclass::ParametersType;
100 
102  using FloatType = typename Superclass::FloatType;
103 
104  using MetricType = TMetric;
105  using MetricPointer = typename MetricType::Pointer;
106  using MetricConstPointer = typename MetricType::ConstPointer;
107 
109  using FixedTransformType = typename MetricType::FixedTransformType;
110  using FixedTransformConstPointer = typename FixedTransformType::ConstPointer;
111 
112  using MovingTransformType = typename MetricType::MovingTransformType;
113  using MovingTransformConstPointer = typename MovingTransformType::ConstPointer;
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 
160  itkSetMacro(TransformForward, bool);
161  itkGetConstMacro(TransformForward, bool);
163 
165  itkSetObjectMacro(VirtualDomainPointSet, VirtualPointSetType);
166  itkSetConstObjectMacro(VirtualDomainPointSet, VirtualPointSetType);
167  itkGetConstObjectMacro(VirtualDomainPointSet, VirtualPointSetType);
169 
171  itkSetMacro(CentralRegionRadius, IndexValueType);
172 
174  void
175  EstimateScales(ScalesType & scales) override = 0;
176 
178  FloatType
179  EstimateStepScale(const ParametersType & step) override = 0;
180 
182  void
183  EstimateLocalStepScales(const ParametersType & step, ScalesType & localStepScales) override = 0;
184 
186  FloatType
187  EstimateMaximumStepSize() override;
188 
190  virtual void
191  SetScalesSamplingStrategy();
192 
194  virtual void
195  SetStepScaleSamplingStrategy();
196 
197 protected:
199  ~RegistrationParameterScalesEstimator() override = default;
200 
201  void
202  PrintSelf(std::ostream & os, Indent indent) const override;
203 
205  bool
206  CheckAndSetInputs();
207 
209  itkSetMacro(NumberOfRandomSamples, SizeValueType);
210 
214 
219  bool
220  CheckGeneralAffineTransform();
221 
227  template <typename TTransform>
228  bool
229  CheckGeneralAffineTransformTemplated();
230 
232  template <typename TTargetPointType>
233  void
234  TransformPoint(const VirtualPointType & point, TTargetPointType & mappedPoint);
235 
237  template <typename TContinuousIndexType>
238  void
239  TransformPointToContinuousIndex(const VirtualPointType & point, TContinuousIndexType & mappedIndex);
240 
242  void
243  ComputeSquaredJacobianNorms(const VirtualPointType & point, ParametersType & squareNorms);
244 
246  bool
247  TransformHasLocalSupportForScalesEstimation();
248 
250  bool
251  IsDisplacementFieldTransform();
252 
254  bool
255  IsBSplineTransform();
256 
259  GetNumberOfLocalParameters();
260 
262  void
263  UpdateTransformParameters(const ParametersType & deltaParameters);
264 
266  virtual void
267  SampleVirtualDomain();
268 
270  void
271  SampleVirtualDomainFully();
272 
274  void
275  SampleVirtualDomainWithCorners();
276 
278  void
279  SampleVirtualDomainRandomly();
280 
282  void
283  SampleVirtualDomainWithCentralRegion();
284 
286  void
287  SampleVirtualDomainWithRegion(VirtualRegionType region);
288 
290  void
291  SampleVirtualDomainWithPointSet();
292 
295  GetVirtualDomainCentralIndex();
296 
299  GetVirtualDomainCentralRegion();
300 
303  GetTransform();
304 
307  GetDimension();
308 
312 
315 
318 
321 
324 
327 
328  typename VirtualPointSetType::ConstPointer m_VirtualDomainPointSet;
329 
330  // the threshold to decide if the number of random samples uses logarithm
331  static constexpr SizeValueType SizeOfSmallDomain = 1000;
332 
333 private:
339 
340  // sampling strategy
342 
343 }; // class RegistrationParameterScalesEstimator
344 } // namespace itk
345 
346 
347 #ifndef ITK_MANUAL_INSTANTIATION
348 # include "itkRegistrationParameterScalesEstimator.hxx"
349 #endif
350 
351 #endif /* itkRegistrationParameterScalesEstimator_h */
itk::RegistrationParameterScalesEstimator::MovingTransformConstPointer
typename MovingTransformType::ConstPointer MovingTransformConstPointer
Definition: itkRegistrationParameterScalesEstimator.h:113
itk::OptimizerParameterScalesEstimatorTemplate
OptimizerParameterScalesEstimatorTemplate is the base class offering a empty method of estimating the...
Definition: itkOptimizerParameterScalesEstimator.h:39
itk::uint8_t
::uint8_t uint8_t
Definition: itkIntTypes.h:29
itk::SamplingStrategyEnum
RegistrationParameterScalesEstimatorEnums::SamplingStrategy SamplingStrategyEnum
Definition: itkRegistrationParameterScalesEstimator.h:54
itk::RegistrationParameterScalesEstimatorEnums::SamplingStrategy::CentralRegionSampling
itk::RegistrationParameterScalesEstimatorEnums::SamplingStrategy::RandomSampling
itkImageRegionConstIteratorWithIndex.h
itk::RegistrationParameterScalesEstimator::ParametersType
typename Superclass::ParametersType ParametersType
Definition: itkRegistrationParameterScalesEstimator.h:99
itk::operator<<
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:218
itk::RegistrationParameterScalesEstimator::SamplePointContainerType
std::vector< VirtualPointType > SamplePointContainerType
Definition: itkRegistrationParameterScalesEstimator.h:145
itk::RegistrationParameterScalesEstimator::VirtualSpacingType
typename TMetric::VirtualSpacingType VirtualSpacingType
Definition: itkRegistrationParameterScalesEstimator.h:123
itk::RegistrationParameterScalesEstimator::FloatType
typename Superclass::FloatType FloatType
Definition: itkRegistrationParameterScalesEstimator.h:102
itk::RegistrationParameterScalesEstimator::m_TransformForward
bool m_TransformForward
Definition: itkRegistrationParameterScalesEstimator.h:338
itk::RegistrationParameterScalesEstimator::MetricType
TMetric MetricType
Definition: itkRegistrationParameterScalesEstimator.h:104
itk::RegistrationParameterScalesEstimator::m_NumberOfRandomSamples
SizeValueType m_NumberOfRandomSamples
Definition: itkRegistrationParameterScalesEstimator.h:323
itk::RegistrationParameterScalesEstimator
Implements a registration helper class for estimating scales of transform parameters and step sizes.
Definition: itkRegistrationParameterScalesEstimator.h:80
itk::RegistrationParameterScalesEstimator::ScalesType
typename Superclass::ScalesType ScalesType
Definition: itkRegistrationParameterScalesEstimator.h:96
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
itkTranslationTransform.h
itk::RegistrationParameterScalesEstimator::VirtualPointSetType
typename TMetric::VirtualPointSetType VirtualPointSetType
Definition: itkRegistrationParameterScalesEstimator.h:129
itk::RegistrationParameterScalesEstimatorEnums::SamplingStrategy::CornerSampling
itk::RegistrationParameterScalesEstimatorEnums::SamplingStrategy::FullDomainSampling
itk::RegistrationParameterScalesEstimator::m_SamplingStrategy
SamplingStrategyType m_SamplingStrategy
Definition: itkRegistrationParameterScalesEstimator.h:341
itkImageRandomConstIteratorWithIndex.h
itkOptimizerParameterScalesEstimator.h
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::RegistrationParameterScalesEstimator::VirtualSizeType
typename TMetric::VirtualSizeType VirtualSizeType
Definition: itkRegistrationParameterScalesEstimator.h:125
itk::RegistrationParameterScalesEstimator::MovingTransformType
typename MetricType::MovingTransformType MovingTransformType
Definition: itkRegistrationParameterScalesEstimator.h:112
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::RegistrationParameterScalesEstimator::m_Metric
MetricPointer m_Metric
Definition: itkRegistrationParameterScalesEstimator.h:311
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::m_SamplePoints
SamplePointContainerType m_SamplePoints
Definition: itkRegistrationParameterScalesEstimator.h:317
itk::RegistrationParameterScalesEstimator::MetricPointer
typename MetricType::Pointer MetricPointer
Definition: itkRegistrationParameterScalesEstimator.h:105
itk::RegistrationParameterScalesEstimator::VirtualRegionType
typename TMetric::VirtualRegionType VirtualRegionType
Definition: itkRegistrationParameterScalesEstimator.h:124
itk::IndexValueType
signed long IndexValueType
Definition: itkIntTypes.h:90
SamplingStrategy
itk::RegistrationParameterScalesEstimator::m_SamplingTime
TimeStamp m_SamplingTime
Definition: itkRegistrationParameterScalesEstimator.h:320
itk::RegistrationParameterScalesEstimator::VirtualIndexType
typename TMetric::VirtualIndexType VirtualIndexType
Definition: itkRegistrationParameterScalesEstimator.h:127
itk::RegistrationParameterScalesEstimator::m_VirtualDomainPointSet
VirtualPointSetType::ConstPointer m_VirtualDomainPointSet
Definition: itkRegistrationParameterScalesEstimator.h:328
itk::RegistrationParameterScalesEstimator::VirtualImageConstPointer
typename TMetric::VirtualImageConstPointer VirtualImageConstPointer
Definition: itkRegistrationParameterScalesEstimator.h:121
itkTransform.h
itk::RegistrationParameterScalesEstimator::m_CentralRegionRadius
IndexValueType m_CentralRegionRadius
Definition: itkRegistrationParameterScalesEstimator.h:326
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