Skip to content

Commit bfa2ceb

Browse files
committed
revision header include, const variables
1 parent af93fa2 commit bfa2ceb

34 files changed

+496
-485
lines changed

src/aabb.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "aabb.h"
2020

2121
#include <Eigen/Dense> // Eigen
22+
#include <cassert>
23+
#include <cmath>
2224

2325
Aabb::Aabb( const double x_min, const double x_max,
2426
const double y_min, const double y_max)

src/adjustment.cpp

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,17 @@
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

2633
using Graph::IncidenceMatrix;
2734
using Constraint::ConstraintBase;
@@ -30,8 +37,7 @@ using Constraint::ConstraintBase;
3037
static 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
}

src/adjustment.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121

2222
#include "matrix.h"
2323

24-
#include <Eigen/Sparse> // Eigen
2524
#include <Eigen/Dense>
2625

27-
#include <memory> // C++
26+
#include <memory> // C++
2827

2928
#include <QList> // Qt
29+
#include <utility>
3030

3131
namespace Constraint {
3232
class ConstraintBase;
@@ -111,12 +111,11 @@ class AdjustmentFramework
111111
} threshold_;
112112

113113
//! Rotation matrix for minimal rotation
114-
MatrixXd Rot_ab( const VectorXd & a,
115-
const VectorXd & b) const;
114+
static MatrixXd Rot_ab(const VectorXd &a, const VectorXd &b);
116115
//! Nullspace of row vector
117-
MatrixXd null( const VectorXd & xs ) const;
116+
static MatrixXd null(const VectorXd &xs);
118117

119-
Index indexOf( const Eigen::VectorXi & v, int x) const;
118+
static Index indexOf(const Eigen::VectorXi &v, int x);
120119
};
121120

122121
#endif // ADJUSTMENT_H

src/commands.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
#include "commands.h"
2020
#include "global.h"
2121
#include "mainscene.h"
22-
#include "mainwindow.h"
23-
// #include "uncertain.h"
22+
#include "state.h"
2423

2524
#include <QDebug>
2625
#include <QGraphicsItem>
26+
#include <memory>
27+
#include <utility>
2728

2829
namespace Cmd {
2930

src/conics.cpp

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@
1717
*/
1818

1919
#include "conics.h"
20+
#include "qlogging.h"
2021
#include "upoint.h"
2122
#include "ustraightline.h"
2223

2324
#include <QDebug>
25+
#include <cassert>
26+
#include <cmath>
27+
#include <utility>
2428

2529
namespace Conic {
2630

@@ -38,7 +42,7 @@ ConicBase::ConicBase( const Matrix3d& other) : Matrix3d(other)
3842
assert( isSymmetric()==true );
3943
}
4044

41-
Matrix3d ConicBase::skew( const Vector3d &x) const
45+
Matrix3d ConicBase::skew(const Vector3d &x)
4246
{
4347
return (Matrix3d() << 0.,-x(2),x(1), x(2),0.,-x(0), -x(1),x(0),0.).finished();
4448
}
@@ -60,7 +64,7 @@ ConicBase & ConicBase::operator=( const Matrix3d & other )
6064
return *this;
6165
}
6266

63-
Matrix3d ConicBase::cof3( const Matrix3d &MM ) const
67+
Matrix3d ConicBase::cof3(const Matrix3d &MM)
6468
{
6569
Matrix3d Cof;
6670

@@ -79,19 +83,17 @@ Matrix3d ConicBase::cof3( const Matrix3d &MM ) const
7983
return Cof;
8084
}
8185

82-
Ellipse::Ellipse( const uPoint & ux, const double k2 )
86+
Ellipse::Ellipse(const uPoint &ux, const double k2)
8387
{
84-
uPoint uy = ux.euclidean();
88+
uPoint const uy = ux.euclidean();
8589

8690
// cofactor matrix is adjugate due to symmetry
8791
*this = cof3( k2*uy.Cov() -uy.v()*uy.v().adjoint() );
8892
}
8993

90-
91-
92-
Hyperbola::Hyperbola( const uStraightLine & ul, const double k2 )
94+
Hyperbola::Hyperbola(const uStraightLine &ul, const double k2)
9395
{
94-
uStraightLine um = ul.euclidean();
96+
uStraightLine const um = ul.euclidean();
9597
*this = k2*um.Cov() -um.v()*um.v().adjoint();
9698
}
9799

@@ -121,12 +123,12 @@ std::pair<double,double>
121123
Hyperbola::lengthsSemiAxes() const
122124
{
123125
auto ev = eigenvalues();
124-
double Delta = determinant();
125-
double D = topLeftCorner(2,2).determinant();
126+
double const Delta = determinant();
127+
double const D = topLeftCorner(2, 2).determinant();
126128
assert( -Delta/( ev.first*D ) >= 0. );
127129
assert( +Delta/( ev.second*D) >= 0. );
128-
double a = std::sqrt( -Delta/( ev.first*D) );
129-
double b = std::sqrt( +Delta/( ev.second*D) );
130+
double const a = std::sqrt(-Delta / (ev.first * D));
131+
double const b = std::sqrt(+Delta / (ev.second * D));
130132

131133
return {a,b};
132134
}
@@ -166,13 +168,13 @@ bool ConicBase::isParabola() const
166168

167169
std::pair<double, double> Hyperbola::eigenvalues() const
168170
{
169-
double p = -topLeftCorner(2,2).trace();
170-
double q = topLeftCorner(2,2).determinant();
171+
double const p = -topLeftCorner(2, 2).trace();
172+
double const q = topLeftCorner(2, 2).determinant();
171173

172174
Q_ASSERT_X( q<0.0, Q_FUNC_INFO, "no hyperbola");
173175
assert( q<0.0 );
174-
double ev0 = -p/2 -std::sqrt( p*p/4 -q);
175-
double ev1 = -p/2 +std::sqrt( p*p/4 -q);
176+
double const ev0 = -p / 2 - std::sqrt(p * p / 4 - q);
177+
double const ev1 = -p / 2 + std::sqrt(p * p / 4 - q);
176178

177179
return {ev0,ev1};
178180
}
@@ -182,8 +184,8 @@ Vector3d ConicBase::center() const
182184
{
183185
Vector3d xh;
184186
if ( isCentral() ) {
185-
Matrix2d C33 = topLeftCorner(2,2);
186-
Vector2d ch0 = topRightCorner(2,1);
187+
Matrix2d const C33 = topLeftCorner(2, 2);
188+
Vector2d const ch0 = topRightCorner(2, 1);
187189
Vector2d x0 = -C33.ldlt().solve(ch0);
188190
xh << x0(0), x0(1), 1.0;
189191
}
@@ -198,11 +200,11 @@ Vector3d ConicBase::center() const
198200
std::pair<Vector3d,Vector3d>
199201
ConicBase::intersect( const Vector3d &l) const
200202
{
201-
Matrix3d MM = skew(l);
203+
Matrix3d const MM = skew(l);
202204
Matrix3d BB = MM.adjoint()*(*this)*MM;
203205

204206
int idx = 0; // [den,idx] = max( abs(l) );
205-
double den = l.array().abs().maxCoeff(&idx);
207+
double const den = l.array().abs().maxCoeff(&idx);
206208

207209
// minors ...............................................
208210
double alpha=0;
@@ -228,8 +230,8 @@ ConicBase::intersect( const Vector3d &l) const
228230
int r = 0;
229231
int c = 0;
230232
DD.array().abs().maxCoeff( &r, &c);
231-
Vector3d p = DD.row(r);
232-
Vector3d q = DD.col(c);
233+
Vector3d const p = DD.row(r);
234+
Vector3d const q = DD.col(c);
233235

234236
return {p,q};
235237
}
@@ -259,16 +261,16 @@ void Ellipse::scale( const double s )
259261
std::pair<Eigen::VectorXd, Eigen::VectorXd>
260262
Ellipse::poly( const int N) const
261263
{
262-
Matrix2d Chh = topLeftCorner(2,2);
263-
Vector2d ch0 = topRightCorner(2,1);
264+
Matrix2d const Chh = topLeftCorner(2, 2);
265+
Vector2d const ch0 = topRightCorner(2, 1);
264266
Vector2d x0 = -Chh.ldlt().solve(ch0); // centre point
265-
double c00q = coeff(2,2) -ch0.dot( Chh.ldlt().solve(ch0));
267+
double const c00q = coeff(2, 2) - ch0.dot(Chh.ldlt().solve(ch0));
266268

267269
assert( std::fabs(c00q)>0. );
268270

269-
Eigen::EigenSolver<Matrix2d> eig( -Chh/c00q, true);
271+
Eigen::EigenSolver<Matrix2d> const eig(-Chh / c00q, true);
270272
Vector2d ev = eig.eigenvalues().real();
271-
Matrix2d RR = eig.eigenvectors().real();
273+
Matrix2d const RR = eig.eigenvectors().real();
272274

273275
if ( ev(0)<0.0 ) {
274276
ev *= -1;

src/conics.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define CONICS_H
2121

2222
#include <Eigen/Dense>
23+
#include <utility>
2324

2425
namespace Uncertain {
2526
class uPoint;
@@ -59,10 +60,10 @@ class ConicBase : public Matrix3d
5960

6061
protected:
6162
void transform( const Matrix3d & HH ); //!< Transformtion of conic according to x'=H*x
62-
Matrix3d cof3( const Matrix3d & MM ) const; //!< 3x3 cofactor matrix, i.e., transposed adjunct
63+
static Matrix3d cof3(const Matrix3d &MM); //!< 3x3 cofactor matrix, i.e., transposed adjunct
6364

6465
private:
65-
Matrix3d skew( const Vector3d & x ) const;
66+
static Matrix3d skew(const Vector3d &x);
6667
bool isSymmetric() const;
6768
};
6869

0 commit comments

Comments
 (0)