OTB  10.0.0
Orfeo Toolbox
otbLeastSquareBilinearTransformEstimator.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbLeastSquareBilinearTransformEstimator_hxx
22 #define otbLeastSquareBilinearTransformEstimator_hxx
23 
24 #include <vnl/algo/vnl_lsqr.h>
25 #include <vnl/vnl_sparse_matrix_linear_system.h>
26 #include <vnl/vnl_least_squares_function.h>
27 #include <vnl/vnl_inverse.h>
28 #include <vnl/vnl_matrix.h>
29 
30 #include "otbMacro.h"
32 
33 namespace otb
34 {
35 
36 template <class TPoint>
38  : m_TiePointsContainer(), m_RMSError(), m_RelativeResidual(), bl_a(0.0), bl_b(0.0), bl_c(0.0), bl_d(0.0), Ata(), Atb()
39 {
40  Ata.fill(0.0);
41  Atb.fill(0.0);
42 }
43 
44 template <class TPoint>
46 {
47  // Clear the container
48  m_TiePointsContainer.clear();
49 }
50 
51 template <class TPoint>
53 {
54  vnl_matrix_fixed<double, 4, 1> Ata_layer;
55  Ata_layer(0,0) = 1.0;
56  Ata_layer(1,0) = src[0];
57  Ata_layer(2,0) = src[1];
58  Ata_layer(3,0) = src[0] * src[1];
59 
60  Ata += Ata_layer * Ata_layer.transpose();
61  Atb += Ata_layer * dst;
62 }
63 
64 
65 
66 
67 template <class TPoint>
69 {
70  vnl_matrix_fixed<double, 4, 1> soln;
71  // vnl_matrix_inverse<double> inv;
72  vnl_matrix<double> inv;
73  vnl_matrix_fixed<double, 4, 4> inv2;
74  vnl_matrix_fixed<double, 4, 4> id;
75 
76  // vnl_inverse
77  inv = vnl_matrix_inverse<double>(Ata);
78  inv2 = vnl_matrix_fixed<double, 4, 4>(inv);
79  soln = vnl_matrix_fixed<double, 4, 4>(vnl_matrix_inverse<double>(Ata)) * Atb;
80  bl_a = soln(0,0);
81  bl_b = soln(1,0);
82  bl_c = soln(2,0);
83  bl_d = soln(3,0);
84 
85  id = Ata * inv;
86 
87 }
88 
89 template <class TPoint>
91 {
92  dst = (bl_a + bl_b*point[0] + bl_c*point[1] + bl_d*point[0]*point[1]);
93 }
94 
95 template <class TPoint>
96 void LeastSquareBilinearTransformEstimator<TPoint>::PrintSelf(std::ostream& /*os*/, itk::Indent /*indent*/) const {}
97 
98 } // end namespace otb
99 
100 #endif
void lsFitValue(const PointType &point, PrecisionType &dst) const
void AddTiePoints(const PointType &src, const PrecisionType &dst)
void PrintSelf(std::ostream &os, itk::Indent indent) const override
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.