-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadjustment.h
More file actions
127 lines (98 loc) · 5.09 KB
/
adjustment.h
File metadata and controls
127 lines (98 loc) · 5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* This file is part of the GreasePad distribution (https://github.com/FraunhoferIOSB/GreasePad).
* Copyright (c) 2022-2026 Jochen Meidow, Fraunhofer IOSB
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef ADJUSTMENT_H
#define ADJUSTMENT_H
#include <Eigen/Core>
#include <Eigen/SparseCore>
#include <memory>
#include <utility>
#include "qcontainerfwd.h"
#include "geometry/minrot.h"
namespace Constraint {class ConstraintBase;} // namespace Constraint
namespace Graph {class IncidenceMatrix;} // namespace Graph
enum class Attribute : int;
//! Adjustment framework: observations, Jacobians, optimization...
class AdjustmentFramework
{
private:
using VectorXidx = Eigen::Vector<Eigen::Index,Eigen::Dynamic>;
public:
AdjustmentFramework() = delete;
AdjustmentFramework( const AdjustmentFramework &) = delete;
//! Value constructor: vector of observations and covariance matrix
explicit AdjustmentFramework(const std::pair<Eigen::VectorXd, Eigen::SparseMatrix<double> > & p);
AdjustmentFramework ( AdjustmentFramework &&) = delete;
~AdjustmentFramework() = default;
void operator= ( const AdjustmentFramework &) = delete;
AdjustmentFramework & operator= ( AdjustmentFramework &&) = delete;
//! Enforce the constraints of a subtask (adjustment)
bool enforceConstraints(const QVector<std::shared_ptr<Constraint::ConstraintBase> > &constr,
const Graph::IncidenceMatrix &relsub,
const Eigen::ArrayXi &mapc,
Eigen::Array<Attribute,Eigen::Dynamic,1> & status,
Eigen::Array<bool,Eigen::Dynamic,1> & enforced);
//! Get i-th uncertain entity represented by N-vector and covariance matrix
template<typename T,int N>
std::pair< Eigen::Vector<T,N>, Eigen::Matrix<T,N,N> >
getEntity( Eigen::Index i) const;
private:
[[nodiscard]] static int nIterMax() { return nIterMax_; }
[[nodiscard]] static double threshold_convergence() { return convergence; }
[[nodiscard]] static double threshold_ReciprocalConditionNumber() { return ReciprocalConditionNumber; }
[[nodiscard]] static double threshold_rankEstimate() { return rankEstimate; }
[[nodiscard]] static double threshold_numericalCheck() { return numericalCheck; }
void update( const Eigen::VectorXd & x ); // update of adjusted observatons in l0_
void Jacobian(const QVector<std::shared_ptr<Constraint::ConstraintBase> > & constr,
const Graph::IncidenceMatrix & relsub,
Eigen::SparseMatrix<double, Eigen::ColMajor> & BBr,
const Eigen::ArrayXi & mapc,
const Eigen::Array<Attribute,Eigen::Dynamic,1> & status,
Eigen::VectorXd & g0 );
//! compute reduced coordinates
void reduce();
void checkConstraints( const QVector<std::shared_ptr<Constraint::ConstraintBase> > & constr,
const Graph::IncidenceMatrix & relsub,
const Eigen::ArrayXi & mapc,
const Eigen::Array<Attribute,Eigen::Dynamic,1> & status,
Eigen::Array<bool,Eigen::Dynamic,1> & enforced ) const;
bool verbose = true;
// observations
Eigen::VectorXd l0_; // vector of approximate/estimated observations
const Eigen::VectorXd l_; // vector of observations.
const Eigen::SparseMatrix<double> Sigma_ll_; // covariance matrix of vector of observations
// reduced coordinates obervations
Eigen::VectorXd lr;
Eigen::SparseMatrix<double,Eigen::ColMajor> rSigma_ll;
static constexpr int nIterMax_ = 10; // maximal number of iterations
static constexpr double convergence = 1e-7; // Threshold convergence
static constexpr double ReciprocalConditionNumber = 1e-4; // condition number
static constexpr double rankEstimate = 1e-6; // rank estimation
static constexpr double numericalCheck = 1e-5; // numerical check of constraints
};
//! Get i-th uncertain entity represented by N-vector and covariance matrix
template<typename T,int N>
std::pair< Eigen::Vector<T,N>, Eigen::Matrix<T,N,N> >
AdjustmentFramework::getEntity( const Eigen::Index i) const
{
const Eigen::Index offset = N*i; // start position
const Eigen::Matrix<T,N,N> RR = Geometry::Rot_ab<T,N>(
l_.segment<N>(offset), l0_.segment<N>(offset) );
return {l0_.segment<N>(offset),
RR*Sigma_ll_.block(offset,offset,N,N)*RR.transpose()};
}
#endif // ADJUSTMENT_H