Skip to content

Commit 6fe5fe0

Browse files
committed
serialization in new implementation file
1 parent c7cc3e2 commit 6fe5fe0

File tree

3 files changed

+120
-66
lines changed

3 files changed

+120
-66
lines changed

src/greasepad.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ SOURCES += \
4040
qstroke.cpp \
4141
quantiles.cpp \
4242
state.cpp \
43+
uncertain/quncertain.cpp \
4344
uncertain/uncertain.cpp \
4445
uncertain/upoint.cpp \
4546
uncertain/usegment.cpp \

src/uncertain/quncertain.cpp

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* This file is part of the GreasePad distribution (https://github.com/FraunhoferIOSB/GreasePad).
3+
* Copyright (c) 2022-2026 Jochen Meidow, Fraunhofer IOSB
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
20+
#include "uncertain/quncertain.h"
21+
#include "uncertain/usegment.h"
22+
23+
#include <Eigen/Core>
24+
25+
using Eigen::Matrix;
26+
27+
28+
namespace Uncertain {
29+
30+
//! Overloaded operator>> for matrices
31+
template <typename T>
32+
QDataStream & operator>> ( QDataStream & in, MatrixBase<T> & MM)
33+
{
34+
for ( int r=0; r<MM.rows(); r++) {
35+
for ( int c=0; c<MM.cols(); c++) {
36+
in >> MM(r,c);
37+
}
38+
}
39+
40+
return in;
41+
}
42+
43+
44+
//! Overloaded operator<< for matrices
45+
template <typename T>
46+
QDataStream & operator<< ( QDataStream & out, const MatrixBase<T> &MM)
47+
{
48+
//qDebug() << Q_FUNC_INFO;
49+
for ( int r=0; r<MM.rows(); r++) {
50+
for (int c=0; c<MM.cols(); c++) {
51+
out << MM(r,c);
52+
}
53+
}
54+
55+
return out;
56+
}
57+
58+
59+
//! Overloaded operator<< for vectors
60+
template <typename T>
61+
QDataStream & operator<< ( QDataStream & out, const Vector<T,Dynamic> &v)
62+
{
63+
//qDebug() << Q_FUNC_INFO;
64+
for (const T val : v) {
65+
out << val;
66+
}
67+
68+
return out;
69+
}
70+
71+
72+
//! Overloaded operator>> for vectors
73+
template <typename T, int N>
74+
QDataStream & operator>> ( QDataStream & in, Vector<T,N> & v)
75+
{
76+
for (T & val : v ) {
77+
in >> val;
78+
}
79+
80+
return in;
81+
}
82+
83+
84+
//! Deserialization of uncertain straight line segment and its bounding box
85+
QDataStream & operator>> ( QDataStream & in, uStraightLineSegment & us)
86+
{
87+
// qDebug() << Q_FUNC_INFO;
88+
Vector<double,9> t;
89+
Matrix<double,9,9> Sigma_tt;
90+
in >> t;
91+
in >> Sigma_tt;
92+
us = uStraightLineSegment(t, Sigma_tt);
93+
94+
return in;
95+
}
96+
97+
98+
QDataStream & operator<< ( QDataStream & out, const uStraightLineSegment & us)
99+
{
100+
//qDebug() << Q_FUNC_INFO;
101+
out << us.t();
102+
out << us.Cov_tt();
103+
104+
return out;
105+
}
106+
107+
} // namespace Uncertain

src/uncertain/quncertain.h

Lines changed: 12 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -24,93 +24,39 @@
2424

2525
#include <QDataStream>
2626

27-
using Uncertain::uStraightLineSegment;
27+
#include <Eigen/Core>
28+
29+
30+
namespace Uncertain {
2831

29-
using Eigen::Vector;
30-
using Eigen::Matrix;
3132
using Eigen::MatrixBase;
3233
using Eigen::Dynamic;
34+
using Eigen::Vector;
3335

3436

35-
namespace {
36-
3737
//! Overloaded operator>> for matrices
3838
template <typename T>
39-
QDataStream & operator>> ( QDataStream & in, MatrixBase<T> & MM)
40-
{
41-
for ( int r=0; r<MM.rows(); r++) {
42-
for ( int c=0; c<MM.cols(); c++) {
43-
in >> MM(r,c);
44-
}
45-
}
46-
47-
return in;
48-
}
49-
39+
QDataStream & operator>> ( QDataStream & in, MatrixBase<T> & MM);
5040

5141
//! Overloaded operator<< for matrices
5242
template <typename T>
53-
QDataStream & operator<< ( QDataStream & out, const MatrixBase<T> &MM)
54-
{
55-
//qDebug() << Q_FUNC_INFO;
56-
for ( int r=0; r<MM.rows(); r++) {
57-
for (int c=0; c<MM.cols(); c++) {
58-
out << MM(r,c);
59-
}
60-
}
61-
62-
return out;
63-
}
64-
43+
QDataStream & operator<< ( QDataStream & out, const MatrixBase<T> &MM);
6544

6645
//! Overloaded operator<< for vectors
6746
template <typename T>
68-
QDataStream & operator<< ( QDataStream & out, const Vector<T,Dynamic> &v)
69-
{
70-
//qDebug() << Q_FUNC_INFO;
71-
for (const T val : v) {
72-
out << val;
73-
}
74-
75-
return out;
76-
}
77-
47+
QDataStream & operator<< ( QDataStream & out, const Vector<T,Dynamic> &v);
7848

7949
//! Overloaded operator>> for vectors
8050
template <typename T, int N>
81-
QDataStream & operator>> ( QDataStream & in, Vector<T,N> & v)
82-
{
83-
for (T & val : v ) {
84-
in >> val;
85-
}
86-
87-
return in;
88-
}
51+
QDataStream & operator>> ( QDataStream & in, Vector<T,N> & v);
8952

9053

9154
//! Deserialization of uncertain straight line segment and its bounding box
92-
QDataStream & operator>> ( QDataStream & in, uStraightLineSegment & us)
93-
{
94-
// qDebug() << Q_FUNC_INFO;
95-
Vector<double,9> t;
96-
Matrix<double,9,9> Sigma_tt;
97-
in >> t;
98-
in >> Sigma_tt;
99-
us = uStraightLineSegment(t, Sigma_tt);
55+
QDataStream & operator>> ( QDataStream & in, uStraightLineSegment & us);
56+
QDataStream & operator<< ( QDataStream & out, const uStraightLineSegment & us);
10057

101-
return in;
102-
}
103-
104-
105-
QDataStream & operator<< ( QDataStream & out, const uStraightLineSegment & us)
106-
{
107-
//qDebug() << Q_FUNC_INFO;
108-
out << us.t();
109-
out << us.Cov_tt();
58+
} // namespace
11059

111-
return out;
112-
}
11360

114-
} // namespace
11561

11662
#endif // QUNCERTAIN_H

0 commit comments

Comments
 (0)