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 itkRegistrationParameterScalesFromShiftBase_h
19 #define itkRegistrationParameterScalesFromShiftBase_h
20 
21 #include "itkRegistrationParameterScalesEstimator.h"
22 
23 namespace itk
24 {
25 
26 /** \class RegistrationParameterScalesFromShiftBase
27  *  \brief Registration helper base class for estimating scales of
28  * transform parameters from the maximum voxel shift caused by a parameter
29  * change.
30  *
31  * Derived classes provide estimation using physical or index space.
32  *
33  * The scale of a parameter is estimated from the maximum voxel shift produced
34  * from a small variation of this parameter. The maximization is done by checking
35  * sample points within the metric's virtual domain. Sample points are generated
36  * differently depending on the type of metric transform or metric type.
37  * See RegistrationParameterScalesEstimator documentation.
38  *
39  * \sa RegistrationParameterScalesEstimator
40  * \ingroup ITKOptimizersv4
41  */
42 template < typename TMetric >
43 class ITK_TEMPLATE_EXPORT RegistrationParameterScalesFromShiftBase :
44   public RegistrationParameterScalesEstimator< TMetric >
45 {
46 public:
47   ITK_DISALLOW_COPY_AND_ASSIGN(RegistrationParameterScalesFromShiftBase);
48 
49   /** Standard class type aliases. */
50   using Self = RegistrationParameterScalesFromShiftBase;
51   using Superclass = RegistrationParameterScalesEstimator< TMetric >;
52   using Pointer = SmartPointer<Self>;
53   using ConstPointer = SmartPointer<const Self>;
54 
55   /** Run-time type information (and related methods). */
56   itkTypeMacro( RegistrationParameterScalesFromShiftBase, RegistrationParameterScalesEstimator );
57 
58   /** Type of scales */
59   using ScalesType = typename Superclass::ScalesType;
60   /** Type of parameters of the optimizer */
61   using ParametersType = typename Superclass::ParametersType;
62   using ParametersValueType = typename ParametersType::ValueType;
63   /** Type of float */
64   using FloatType = typename Superclass::FloatType;
65 
66   using VirtualPointType = typename Superclass::VirtualPointType;
67   using VirtualIndexType = typename Superclass::VirtualIndexType;
68   using MovingTransformType = typename Superclass::MovingTransformType;
69   using FixedTransformType = typename Superclass::FixedTransformType;
70   using JacobianType = typename Superclass::JacobianType;
71   using VirtualImageConstPointer = typename Superclass::VirtualImageConstPointer;
72 
73   /** Estimate parameter scales */
74   void EstimateScales(ScalesType &scales) override;
75 
76   /** Estimate the scale of a step */
77   FloatType EstimateStepScale(const ParametersType &step) override;
78 
79   /** Estimate the scales of local steps */
80   void EstimateLocalStepScales(const ParametersType &step,
81     ScalesType &localStepScales) override;
82 
83   /** Set/get small parameter variation */
84   itkSetMacro( SmallParameterVariation, ParametersValueType );
85   itkGetConstMacro( SmallParameterVariation, ParametersValueType );
86 
87 protected:
88   RegistrationParameterScalesFromShiftBase();
89   ~RegistrationParameterScalesFromShiftBase() override = default;
90 
91   void PrintSelf(std::ostream & os, Indent indent) const override;
92 
93   /** Compute the shift in voxels when deltaParameters is applied onto the
94    * current parameters. */
95   virtual FloatType ComputeMaximumVoxelShift(const ParametersType &deltaParameters);
96 
97   /** Compute the sample shifts.
98    */
99   virtual void ComputeSampleShifts(const ParametersType &deltaParameters, ScalesType &localShifts) = 0;
100 
101 private:
102   //A small variation of parameters
103   ParametersValueType  m_SmallParameterVariation;
104 
105 }; //class RegistrationParameterScalesFromShiftBase
106 
107 
108 }  // namespace itk
109 
110 
111 #ifndef ITK_MANUAL_INSTANTIATION
112 #include "itkRegistrationParameterScalesFromShiftBase.hxx"
113 #endif
114 
115 #endif /* itkRegistrationParameterScalesFromShiftBase_h */
116