Developer documentation
Version 3.0.3-105-gd3941f44
affine.h
Go to the documentation of this file.
1/* Copyright (c) 2008-2022 the MRtrix3 contributors.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 *
7 * Covered Software is provided under this License on an "as is"
8 * basis, without warranty of any kind, either expressed, implied, or
9 * statutory, including, without limitation, warranties that the
10 * Covered Software is free of defects, merchantable, fit for a
11 * particular purpose or non-infringing.
12 * See the Mozilla Public License v. 2.0 for more details.
13 *
14 * For more details, see http://www.mrtrix.org/.
15 */
16
17#ifndef __registration_transform_affine_h__
18#define __registration_transform_affine_h__
19
21#include "types.h"
22#include "file/config.h"
23#include "math/math.h"
24
25using namespace MR::Math;
26
27namespace MR
28{
29 namespace Registration
30 {
31 namespace Transform
32 {
34
35 class AffineUpdate { MEMALIGN(AffineUpdate)
36 public:
37 AffineUpdate (): use_convergence_check (false), projection_type (TransformProjectionType::affine) { }
38
39 bool operator() (Eigen::Matrix<default_type, Eigen::Dynamic, 1>& newx,
40 const Eigen::Matrix<default_type, Eigen::Dynamic, 1>& x,
41 const Eigen::Matrix<default_type, Eigen::Dynamic, 1>& g,
42 default_type step_size);
43
44 void set_control_points (
45 const Eigen::Matrix<default_type, Eigen::Dynamic, Eigen::Dynamic>& points,
46 const Eigen::Vector3d& coherence_dist,
47 const Eigen::Vector3d& stop_length,
48 const Eigen::Vector3d& voxel_spacing );
49
50 void set_projection_type (const TransformProjectionType& type) {
51 INFO ("projection type set to: " + str(type));
52 projection_type = type;
53 }
54
55 void set_convergence_check (const Eigen::Matrix<default_type, Eigen::Dynamic, 1>& slope_threshold,
56 default_type alpha,
57 default_type beta,
58 size_t buffer_len,
59 size_t min_iter) {
60 convergence_check.set_parameters (slope_threshold, alpha, beta, buffer_len, min_iter);
61 use_convergence_check = true;
62 new_control_points_vec.resize(12);
63 }
64
65 private:
66 bool use_convergence_check;
67 TransformProjectionType projection_type;
68 Eigen::Matrix<default_type, Eigen::Dynamic, Eigen::Dynamic> control_points;
69 Eigen::Vector3d coherence_distance;
70 Eigen::Matrix<default_type, 4, 1> stop_len, recip_spacing;
71 DoubleExpSmoothSlopeCheck convergence_check;
72 Eigen::Matrix<default_type, Eigen::Dynamic, 1> new_control_points_vec;
73 };
74
76 public:
77 inline bool operator() (Eigen::Matrix<default_type, Eigen::Dynamic, 1>& newx,
78 const Eigen::Matrix<default_type, Eigen::Dynamic, 1>& x,
79 const Eigen::Matrix<default_type, Eigen::Dynamic, 1>& g,
80 default_type step_size);
81 };
82
83
84
91 class Affine : public Base { MEMALIGN(Affine)
92 public:
93
94 using ParameterType = typename Base::ParameterType;
95 using UpdateType = AffineUpdate;
97 using has_robust_estimator = int;
98
99
100 Affine () : Base (12) {
101 //CONF option: RegGdWeightMatrix
102 //CONF default: 0.0003
103 //CONF Linear registration: weight for optimisation of linear (3x3) matrix parameters.
104 default_type w1 (MR::File::Config::get_float ("RegGdWeightMatrix", 0.0003f));
105 //CONF option: RegGdWeightTranslation
106 //CONF default: 1
107 //CONF Linear registration: weight for optimisation of translation parameters.
108 default_type w2 (MR::File::Config::get_float ("RegGdWeightTranslation", 1.0f));
109 const Eigen::Vector4d weights (w1, w1, w1, w2);
110 this->optimiser_weights << weights, weights, weights;
111 }
112
113 Eigen::Matrix<default_type, 4, 1> get_jacobian_vector_wrt_params (const Eigen::Vector3d& p) const ;
114
115 Eigen::MatrixXd get_jacobian_wrt_params (const Eigen::Vector3d& p) const ;
116
117 void set_parameter_vector (const Eigen::Matrix<ParameterType, Eigen::Dynamic, 1>& param_vector);
118
119 void get_parameter_vector (Eigen::Matrix<ParameterType, Eigen::Dynamic, 1>& param_vector) const;
120
121 UpdateType* get_gradient_descent_updator () {
123 }
124
125 bool robust_estimate (
126 Eigen::Matrix<default_type, Eigen::Dynamic, 1>& gradient,
127 vector<Eigen::Matrix<default_type, Eigen::Dynamic, 1>>& grad_estimates,
128 const Eigen::Matrix<default_type, 4, 4>& control_points,
129 const Eigen::Matrix<default_type, Eigen::Dynamic, 1>& parameter_vector,
130 const default_type& weiszfeld_precision,
131 const size_t& weiszfeld_iterations,
132 default_type learning_rate) const;
133
134 protected:
137 };
139 }
140 }
141}
142
143#endif
static float get_float(const std::string &key, float default_value)
RobustEstimatorType robust_estimator
Definition: affine.h:136
Eigen::VectorXd optimiser_weights
Definition: base.h:284
#define INFO(msg)
Definition: exception.h:74
Definition: base.h:24
double default_type
the default type used throughout MRtrix
Definition: types.h:228
std::string str(const T &value, int precision=0)
Definition: mrtrix.h:247
#define MEMALIGN(...)
Definition: types.h:185