1818
1919#include " adjustment.h"
2020
21- #include < math.h>
2221#include " constraints.h"
2322#include " global.h"
2423#include " matrix.h"
24+ #include " qlogging.h"
25+ #include < algorithm>
26+ #include < cassert>
27+ #include < cmath>
28+ #include < iterator>
29+ #include < math.h>
30+ #include < memory>
31+ #include < utility>
2532
2633using Graph::IncidenceMatrix;
2734using Constraint::ConstraintBase;
@@ -30,8 +37,7 @@ using Constraint::ConstraintBase;
3037static const double T_ZERO = 1e-5 ;
3138#endif
3239
33- Index AdjustmentFramework::indexOf ( const Eigen::VectorXi & v,
34- const int x) const
40+ Index AdjustmentFramework::indexOf (const Eigen::VectorXi &v, const int x)
3541{
3642 // for ( Index j=0; j<v.size(); j++) {
3743 // if ( v(j)==x ) {
@@ -47,9 +53,7 @@ Index AdjustmentFramework::indexOf( const Eigen::VectorXi & v,
4753 return std::distance ( v.begin (), it);
4854}
4955
50-
51- MatrixXd AdjustmentFramework::Rot_ab ( const VectorXd &a,
52- const VectorXd &b) const
56+ MatrixXd AdjustmentFramework::Rot_ab (const VectorXd &a, const VectorXd &b)
5357{
5458 Q_ASSERT ( a.size ()==b.size ());
5559#ifdef QT_DEBUG
@@ -61,20 +65,18 @@ MatrixXd AdjustmentFramework::Rot_ab( const VectorXd &a,
6165 -(a+b)*(a+b).adjoint ()/(1 .+a.dot (b));
6266}
6367
64- MatrixXd AdjustmentFramework::null ( const VectorXd &xs ) const
68+ MatrixXd AdjustmentFramework::null (const VectorXd &xs)
6569{
6670 // cf. PCV, eq. (A.120)
6771
6872 // if ( fabs(xs.norm()-1.) > T_ZERO )
6973 // qDebug() << xs;
7074
7175#ifdef QT_DEBUG
72- QString what = QStringLiteral (" norm(x) = %1" ).arg ( QString::number (xs.norm ()) );
73- Q_ASSERT_X ( std::fabs (xs.norm ()-1 .) <= T_ZERO,
74- Q_FUNC_INFO,
75- what.toStdString ().data () ) ;
76+ QString const what = QStringLiteral (" norm(x) = %1" ).arg (QString::number (xs.norm ()));
77+ Q_ASSERT_X (std::fabs (xs.norm () - 1 .) <= T_ZERO, Q_FUNC_INFO, what.toStdString ().data ());
7678#endif
77- Eigen::Index N = xs.size ();
79+ Eigen::Index const N = xs.size ();
7880
7981 VectorXd x0 = xs.head (N-1 );
8082 double xN = xs (N-1 );
@@ -87,7 +89,7 @@ MatrixXd AdjustmentFramework::null( const VectorXd &xs ) const
8789 JJ.topRows (N-1 ) = MatrixXd::Identity (N-1 ,N-1 ) -x0*x0.adjoint ()/(1 .+xN);
8890 JJ.bottomRows (1 ) = -x0.adjoint ();
8991
90- VectorXd check = JJ.adjoint ()*xs;
92+ VectorXd const check = JJ.adjoint ()*xs;
9193#ifdef QT_DEBUG
9294 Q_ASSERT_X ( check.norm () <= T_ZERO, Q_FUNC_INFO, " not a zero vector" );
9395#endif
@@ -100,9 +102,9 @@ AdjustmentFramework::getEntity( const Index s,
100102{
101103 // qDebug() << Q_FUNC_INFO;
102104
103- Index offset = len*s;
105+ Index const offset = len*s;
104106 // vector must be the null space of the covariance matrix
105- MatrixXd RR = Rot_ab ( l_.segment (offset,len), l0_.segment (offset,len));
107+ MatrixXd const RR = Rot_ab ( l_.segment (offset,len), l0_.segment (offset,len));
106108
107109 return { l0_.segment (offset,len),
108110 RR*Cov_ll_.block (offset,offset,len,len)*RR.adjoint () };
@@ -121,13 +123,13 @@ void AdjustmentFramework::update( const Index start,
121123 // m.segment(idx3,3).normalize();
122124
123125 // (2) via retraction ......................................................
124- Eigen::Vector3d v = null ( l0_.segment (idx3,3 ) )* x.segment (2 * start,2 );
125- double nv = v.norm ();
126+ Eigen::Vector3d const v = null (l0_.segment (idx3, 3 )) * x.segment (2 * start, 2 );
127+ double const nv = v.norm ();
126128 if ( nv<=0.0 ) {
127129 return ;
128130 }
129131
130- Eigen::Vector3d p = l0_.segment ( idx3,3 );
132+ Eigen::Vector3d const p = l0_.segment (idx3, 3 );
131133 assert ( nv>0.0 );
132134 l0_.segment ( idx3,3 ) = cos ( nv)*p +sin (nv)*v/nv; // nv>0
133135 assert ( l0_.segment ( idx3,3 ).hasNaN ()==false );
@@ -193,19 +195,17 @@ bool AdjustmentFramework::enforce_constraints( const QVector<std::shared_ptr<Con
193195 // reduced coordinates: vector and covariance matrix .............
194196 for ( Index s=0 ; s<S; s++ )
195197 {
196- Index offset3 = 3 * s;
197- Index offset2 = 2 * s;
198+ Index const offset3 = 3 * s;
199+ Index const offset2 = 2 * s;
198200
199- Eigen::Matrix<double ,3 , 2 > NN = null ( l0_segment (offset3,3 ) );
201+ Eigen::Matrix<double , 3 , 2 > const NN = null (l0_segment (offset3, 3 ) );
200202
201203 // (i) reduced coordinates of observations
202204 lr.segment (offset2,2 ) = NN.adjoint () * l_segment (offset3,3 );
203205
204206 // (ii) covariance matrix, reduced coordinates
205- Eigen::Matrix3d RR = Rot_ab (
206- l_segment (offset3,3 ),
207- l0_segment (offset3,3 ) );
208- Eigen::Matrix<double ,2 ,3 > JJ = NN.adjoint ()*RR;
207+ Eigen::Matrix3d const RR = Rot_ab (l_segment (offset3, 3 ), l0_segment (offset3, 3 ));
208+ Eigen::Matrix<double , 2 , 3 > const JJ = NN.adjoint () * RR;
209209 Eigen::Matrix2d Cov_rr = JJ*Cov_ll_block ( offset3,3 )*JJ.adjoint ();
210210
211211 // rCov_ll.block(offset2, offset2, 2, 2) = Cov_rr; // not for sparse matrices
@@ -219,7 +219,7 @@ bool AdjustmentFramework::enforce_constraints( const QVector<std::shared_ptr<Con
219219 // check rank and condition .....................................
220220
221221 // rank-revealing decomposition
222- Eigen::FullPivLU<MatrixXd> lu_decomp2 ( BBr* rCov_ll* BBr.adjoint () );
222+ Eigen::FullPivLU<MatrixXd> const lu_decomp2 (BBr * rCov_ll * BBr.adjoint ());
223223 rcn = lu_decomp2.rcond ();
224224 if ( rcn < threshold_ReciprocalConditionNumber () ) {
225225 // redundant or contradictory constraint
@@ -313,7 +313,7 @@ void AdjustmentFramework::Jacobian(
313313 }
314314
315315 auto JJ = con->Jacobian ( idx, l0 (), l () );
316- int dof = con->dof ();
316+ int const dof = con->dof ();
317317 for ( int i=0 ; i< con->arity (); i++ ) {
318318 // dof rows for this constraint
319319 Q_ASSERT ( JJ.rows ()==dof );
@@ -377,17 +377,16 @@ void AdjustmentFramework::check_constraints(
377377
378378#ifdef QT_DEBUG
379379 if ( verbose ) {
380- QString msg1 = QString (" %1: " ).arg (
381- QString::fromLatin1 ( con->type_name ()), 12 );
382- QString msg2 = QString (" check = %2, \t " ).arg (d);
380+ QString const msg1 = QString (" %1: " ).arg (QString::fromLatin1 (con->type_name ()), 12 );
381+ QString const msg2 = QString (" check = %2, \t " ).arg (d);
383382 QDebug deb = qDebug ().noquote ();
384383 deb << QString (" constraint #%1: " ).arg (c+1 ,3 );
385384 deb << (con->required () ? green : blue) << msg1 << black;
386385 deb << (con->enforced () ? black : red) << msg2 << black;
387386
388387 auto idxx = bi->findInColumn ( mapc (c) );
389388 for ( Index i=0 ; i<idxx.size (); i++ ) {
390- int idxxx = indexOf ( maps, idxx (i) );
389+ int const idxxx = indexOf (maps, idxx (i));
391390 deb << idxxx+1 ;
392391 }
393392 }
0 commit comments