1212
some proper initilizations · FraunhoferIOSB/GreasePad@52ee017 · GitHub
Skip to content

Commit 52ee017

Browse files
committed
some proper initilizations
1 parent 25a063e commit 52ee017

File tree

13 files changed

+80
-79
lines changed

13 files changed

+80
-79
lines changed

src/adjustment.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818

1919
#include "adjustment.h"
20+
21+
#include <math.h>
2022
#include "constraints.h"
2123
#include "global.h"
2224
#include "matrix.h"
@@ -333,7 +335,7 @@ void AdjustmentFramework::check_constraints(
333335
const Eigen::RowVectorXi & maps,
334336
const Eigen::RowVectorXi & mapc) const
335337
{
336-
double d; // distance to be checked, d = 0?
338+
double d = NAN; // distance to be checked, d = 0?
337339
const Index C = mapc.size();
338340

339341
// check intrinsic constraints ..............................

src/conics.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ ConicBase::intersect( const Vector3d &l) const
201201
Matrix3d MM = skew(l);
202202
Matrix3d BB = MM.adjoint()*(*this)*MM;
203203

204-
int idx; // [den,idx] = max( abs(l) );
204+
int idx = 0; // [den,idx] = max( abs(l) );
205205
double den = l.array().abs().maxCoeff(&idx);
206206

207207
// minors ...............................................
@@ -225,8 +225,8 @@ ConicBase::intersect( const Vector3d &l) const
225225
Q_ASSERT( alpha <= 0 );
226226
Q_ASSERT( den > 0 );
227227
Matrix3d DD = BB +std::sqrt(-alpha)/den*MM;
228-
int r;
229-
int c;
228+
int r = 0;
229+
int c = 0;
230230
DD.array().abs().maxCoeff( &r, &c);
231231
Vector3d p = DD.row(r);
232232
Vector3d q = DD.col(c);

src/constraints.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,11 @@ MatrixXd ConstraintBase::null( const VectorXd & xs )
7878
return JJ;
7979
}
8080

81-
82-
83-
ConstraintBase::ConstraintBase() {
81+
ConstraintBase::ConstraintBase()
82+
: m_status(UNEVAL)
83+
, m_enforced(false)
84+
{
8485
// qDebug().noquote() << Q_FUNC_INFO;
85-
m_status = UNEVAL;
86-
m_enforced = false;
8786
}
8887

8988
std::shared_ptr<ConstraintBase> ConstraintBase::clone() const
@@ -229,8 +228,8 @@ MatrixXd Identical::Jacobian( const VectorXi & idx,
229228
Eigen::FullPivLU<MatrixXd> LU; // identical
230229
Matrix<double,3,2> JJ; // identical
231230

232-
int idx1;
233-
int idx2;
231+
int idx1 = 0;
232+
int idx2 = 0;
234233
a0.cwiseAbs().maxCoeff( &idx1 );
235234
b0.cwiseAbs().maxCoeff( &idx2 );
236235

@@ -257,8 +256,8 @@ VectorXd Identical::contradict( const VectorXi & idx,
257256
Eigen::FullPivLU<MatrixXd> LU;
258257

259258
// check sign ............................................
260-
int idx1;
261-
int idx2;
259+
int idx1 = 0;
260+
int idx2 = 0;
262261
a0.head(2).cwiseAbs().maxCoeff( &idx1 );
263262
b0.head(2).cwiseAbs().maxCoeff( &idx2 );
264263

src/mainscene.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ namespace GUI {
3737

3838
QPen MainScene::s_scribblePen = QPen( Qt::blue, 3, Qt::SolidLine, Qt::RoundCap );
3939

40-
MainScene::MainScene(QObject *parent) : QGraphicsScene (parent)
40+
MainScene::MainScene(QObject *parent)
41+
: QGraphicsScene(parent)
42+
, m_scribbling(false)
4143
{
42-
m_scribbling = false;
4344
// p.setCosmetic(true);
4445
m_path_item.setPen( s_scribblePen );
4546

src/mainwindow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ namespace GUI {
5858

5959
MainWindow::MainWindow(QWidget *parent)
6060
: QMainWindow(parent)
61+
, m_pixmap(nullptr)
6162
{
6263
qDebug() << Q_FUNC_INFO;
6364

@@ -79,7 +80,6 @@ MainWindow::MainWindow(QWidget *parent)
7980

8081
// curr_state = std::make_unique<State>();
8182
// curr_state = new State();
82-
m_pixmap = nullptr; // background
8383

8484
double alpha = 0.1;
8585
State::setAlphaRecognition( alpha );
@@ -939,7 +939,7 @@ void MainWindow::slotDeselectAll()
939939

940940
void MainWindow::slotSetFont()
941941
{
942-
bool ok;
942+
bool ok = false;
943943
QFont font = QFontDialog::getFont( &ok, QApplication::font(), this);
944944
// QApplication::setFont(QFontDialog::getFont(0, QApplication::font(), this));
945945
if (ok) {

src/matrix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ void IncidenceMatrix::remove_column( const int c) {
136136
Index C = cols()-1;
137137

138138
SparseMatrix<int> TT(C+1,C);
139-
Index c2;
139+
Index c2 = 0;
140140
for (c2=0; c2<c; c2++) {
141141
TT.insert(c2,c2) = 1;
142142
}
@@ -155,7 +155,7 @@ void IncidenceMatrix::remove_row(const int r)
155155

156156
Index R = rows()-1;
157157
SparseMatrix<int> SS(R,R+1);
158-
Index r2;
158+
Index r2 = 0;
159159
for (r2=0; r2<r; r2++) {
160160
SS.insert(r2,r2) = 1; // i.e., true
161161
}

src/qconstraints.cpp

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <QGraphicsSceneMouseEvent>
2727
#include <QMenu>
2828
#include <QPainter>
29+
#include <math.h>
2930
#include <qstyleoption.h>
3031

3132
#include <cfloat>
@@ -40,42 +41,37 @@ QPen QConstraintBase::s_defaultPenReq = QPen();
4041
QPen QConstraintBase::s_defaultPenRed = QPen();
4142
QPen QConstraintBase::s_penSelected = QPen();
4243

43-
4444
QConstraintBase::QConstraintBase()
45+
: m_pen_req(s_defaultPenReq)
46+
, m_pen_red(s_defaultPenRed)
47+
, m_is_required(false)
48+
, m_is_enforced(false)
4549
{
4650
// qDebug() << Q_FUNC_INFO;
47-
setVisible( s_show);
48-
49-
m_pen_req = s_defaultPenReq;
50-
m_pen_red = s_defaultPenRed;
51-
52-
m_is_required = false;
53-
m_is_enforced = false;
51+
setVisible(s_show);
5452

5553
// setHandlesChildEvents(false); // default is 'false'
5654
setFlag( ItemIsSelectable, true);
5755
setFlag( ItemIsMovable, false);
5856
setFlag( ItemSendsGeometryChanges, false);
5957
}
6058

61-
QConstraintBase::QConstraintBase( const QConstraintBase & other)
59+
QConstraintBase::QConstraintBase(const QConstraintBase &other)
60+
: m_altColor(other.m_altColor)
61+
, m_pen_req(other.m_pen_req)
62+
, m_pen_red(other.m_pen_red)
63+
, m_is_required(other.m_is_required)
64+
, m_is_enforced(other.m_is_enforced)
6265
{
6366
// qDebug() << Q_FUNC_INFO << m_sc;
6467
setVisible( s_show);
6568

66-
setFlag( ItemIsSelectable, true);
67-
setFlag( ItemIsMovable, false);
68-
setFlag( ItemSendsGeometryChanges, false);
69-
70-
m_altColor = other.m_altColor;
71-
m_pen_req = other.m_pen_req;
72-
m_pen_red = other.m_pen_red;
73-
74-
m_is_required = other.m_is_required;
75-
m_is_enforced = other.m_is_enforced ;
69+
setFlag(ItemIsSelectable, true);
70+
setFlag(ItemIsMovable, false);
71+
setFlag(ItemSendsGeometryChanges, false);
7672
}
7773

78-
void QConstraintBase::mousePressEvent( QGraphicsSceneMouseEvent * event )
74+
void QConstraintBase::mousePressEvent(QGraphicsSceneMouseEvent *event)
7975
{
8076
if ( event->button() == Qt::RightButton ) {
8177
setSelected( !isSelected() ); // toggle selection
@@ -110,12 +106,13 @@ bool QConstraintBase::deserialize( QDataStream &in )
110106
in >> m_pen_red;
111107

112108
in >> m_altColor;
113-
qreal s;
109+
qreal s = NAN;
114110
in >> s; // m_markerSize;
115111
setMarkerSize(s);
116112

117113
QPointF pos; in >> pos;
118-
qreal rot; in >> rot;
114+
qreal rot = NAN;
115+
in >> rot;
119116

120117
setRotation( rot );
121118
setPos( pos );
@@ -590,8 +587,8 @@ void QIdentical::setGeometry( QVector<std::shared_ptr<const uStraightLineSegment
590587
DD(l,l) = DBL_MAX;
591588
}
592589

593-
int ii;
594-
int jj;
590+
int ii = 0;
591+
int jj = 0;
595592
DD.minCoeff( &ii, &jj);
596593
QConstraintBase::setPos( m_sc*(xx(0,ii)+xx(0,jj))/2, m_sc*(xx(1,ii)+xx(1,jj))/2 );
597594
QConstraintBase::setRotation( s.at(i)->phi_deg() );

src/qsegment.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -344,24 +344,25 @@ QUnconstrained::QUnconstrained( QGraphicsItem * /* parent */ )
344344
}
345345

346346
QConstrained::QConstrained()
347+
: altColor(Qt::black)
347348
{
348349
// qDebug() << Q_FUNC_INFO;
349350
setVisible( QConstrained::show() );
350-
altColor = Qt::black;
351-
setPen( s_defaultPen );
351+
352+
setPen(s_defaultPen);
352353
}
353354

354-
QConstrained::QConstrained( const uPoint & ux,
355-
const uPoint & uy)
356-
: QSegment(ux,uy) {
355+
QConstrained::QConstrained(const uPoint &ux, const uPoint &uy)
356+
: QSegment(ux, uy)
357+
, altColor(Qt::black)
358+
{
357359
setVisible( QConstrained::show() );
358360
setPen( s_defaultPen );
359-
altColor = Qt::black;
360361
}
361362

362-
void QUnconstrained::paint( QPainter *painter,
363-
const QStyleOptionGraphicsItem *option,
364-
QWidget *widget)
363+
void QUnconstrained::paint(QPainter *painter,
364+
const QStyleOptionGraphicsItem *option,
365+
QWidget *widget)
365366
{
366367
Q_UNUSED(widget)
367368
Q_UNUSED(option)

src/qstroke.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,16 @@ QStroke::QStroke() {
5353
setFlag( ItemIsSelectable, true);
5454
}
5555

56-
QStroke::QStroke( const QPolygonF &p )
57-
: QGraphicsPolygonItem ( p)
56+
QStroke::QStroke(const QPolygonF &p)
57+
: QGraphicsPolygonItem(p)
58+
, m_pen(s_defaultPen)
5859
{
5960
// qDebug() << Q_FUNC_INFO << s_show;
6061
setVisible( s_show );
6162
setFlag( ItemIsSelectable, true);
62-
63-
m_pen = s_defaultPen;
6463
}
6564

66-
void QStroke::paint( QPainter *painter,
67-
const QStyleOptionGraphicsItem *option,
68-
QWidget *widget)
65+
void QStroke::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
6966
{
7067
Q_UNUSED(option)
7168
Q_UNUSED(widget)

src/state.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ bool impl::deserialize( QDataStream & in )
299299
for ( Index i=0; i<Bi.cols(); i++ ) {
300300
// auto c = ConstraintBase::deserialize(in); // calls 'create'
301301

302-
char* type_name;
302+
char *type_name = nullptr;
303303
in >> type_name;
304304
// qDebug() << Q_FUNC_INFO << type_name;
305305
if ( in.status()!=0) {
@@ -1064,7 +1064,7 @@ impl::a_Maker( const Eigen::RowVectorXi & maps_) const
10641064
SparseMatrix<double,ColMajor> Cov_ll(N,N); // covariance matrix observations
10651065
Cov_ll.setZero();
10661066
Cov_ll.reserve(3*N);
1067-
int idx; // [~,idx] = max( abs(l(1:2)) )
1067+
int idx = 0; // [~,idx] = max( abs(l(1:2)) )
10681068

10691069
for ( int s=0; s<S; s++ ) {
10701070

@@ -1538,15 +1538,15 @@ QDataStream & operator>> (QDataStream & in, IncidenceMatrix & AA)
15381538
{
15391539
qDebug() << Q_FUNC_INFO;
15401540

1541-
uint nrows;
1542-
uint ncols;
1543-
uint nnz;
1541+
uint nrows = 0;
1542+
uint ncols = 0;
1543+
uint nnz = 0;
15441544
in >> nrows >> ncols >> nnz;
15451545

15461546
std::vector< Eigen::Triplet<int> > tripletList;
15471547
tripletList.reserve( nnz );
1548-
int r;
1549-
int c;
1548+
int r = 0;
1549+
int c = 0;
15501550
for ( uint i=0; i<nnz; i++ ) {
15511551
in >> r >> c;
15521552
tripletList.emplace_back( Eigen::Triplet<int>(r, c, 1) );
@@ -1573,11 +1573,11 @@ QDataStream & operator<< ( QDataStream & out, const ConstraintBase & c)
15731573
QDataStream & operator>> ( QDataStream &in, ConstraintBase &c )
15741574
{
15751575
// qDebug() << Q_FUNC_INFO;
1576-
int status;
1576+
int status = 0;
15771577
in >> status;
15781578
c.setStatus( static_cast<ConstraintBase::Status>(status) );
15791579

1580-
bool enforced;
1580+
bool enforced = false;
15811581
in >> enforced;
15821582
c.setEnforced( enforced );
15831583

0 commit comments

Comments
 (0)