Skip to content

Commit 1fe1f59

Browse files
committed
class uStraightLineSegment now 'Q-free'
1 parent 342fd71 commit 1fe1f59

File tree

4 files changed

+207
-171
lines changed

4 files changed

+207
-171
lines changed

src/geometry/aabb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#include <cassert>
2323

24-
#include <Eigen/core>
24+
#include <Eigen/Core>
2525

2626
namespace Geometry {
2727

src/state.cpp

Lines changed: 190 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "adjustment.h"
3636
#include "conncomp.h"
3737
#include "constraints.h"
38+
#include "geometry/aabb.h"
3839
#include "geometry/acute.h"
3940
#include "global.h"
4041
#include "mainscene.h"
@@ -61,18 +62,23 @@
6162

6263
using Eigen::VectorXd;
6364
using Eigen::VectorXi;
65+
using Eigen::Vector;
6466
using Eigen::Vector3d;
6567
using Eigen::Matrix3d;
68+
using Eigen::Matrix;
69+
using Eigen::MatrixBase;
6670
using Eigen::Index;
6771
using Eigen::SparseMatrix;
6872
using Eigen::ColMajor;
6973
using Eigen::indexing::last;
74+
using Eigen::Dynamic;
75+
76+
using Geometry::Aabb;
7077

7178
using Constraint::ConstraintBase;
7279
using Constraint::Parallel;
7380
using Constraint::Orthogonal;
7481
using Constraint::Copunctual;
75-
// using Constraint::Identical;
7682
using Constraint::Vertical;
7783
using Constraint::Horizontal;
7884
using Constraint::Diagonal;
@@ -105,17 +111,192 @@ Quantiles::Recognition State::recogn_;
105111
Quantiles::Snapping State::snap_;
106112

107113

114+
108115
namespace {
109116

117+
110118
//! Serialization of sparse incidence matrix
111-
static QDataStream & operator<< ( QDataStream & out, const IncidenceMatrix & AA);
119+
static QDataStream & operator<< (QDataStream & out, const IncidenceMatrix & AA)
120+
{
121+
// qDebug() << Q_FUNC_INFO;
122+
123+
out << static_cast<uint>(AA.rows());
124+
out << static_cast<uint>(AA.cols());
125+
out << static_cast<uint>(AA.nonZeros());
126+
127+
for( Index c=0; c<AA.outerSize(); ++c) {
128+
SparseMatrix<int,ColMajor>::InnerIterator it( AA, c);
129+
for( ; it; ++it) {
130+
out << static_cast<int>(it.row()) << static_cast<int>(it.col());
131+
}
132+
}
133+
return out;
134+
}
135+
136+
112137
//! Deserialization of sparse incidence matrix
113-
static QDataStream & operator>> ( QDataStream & in, IncidenceMatrix & AA);
138+
QDataStream & operator>> (QDataStream & in, IncidenceMatrix & AA)
139+
{
140+
// qDebug() << Q_FUNC_INFO;
141+
142+
uint nrows = 0;
143+
uint ncols = 0;
144+
uint nnz = 0;
145+
in >> nrows >> ncols >> nnz;
146+
147+
// fill vector with triplets (i,j,value)
148+
std::vector< Eigen::Triplet<int> > tripletList;
149+
tripletList.reserve( nnz );
150+
int r = 0;
151+
int c = 0;
152+
for ( uint i=0; i<nnz; i++ ) {
153+
in >> r >> c;
154+
tripletList.emplace_back( r, c, 1 );
155+
}
156+
157+
// fill sparse matrix
158+
AA.resize(static_cast<int>(nrows), static_cast<int>(ncols));
159+
AA.setFromTriplets( tripletList.begin(),
160+
tripletList.end() );
161+
162+
return in;
163+
}
164+
114165

115166
//! Serialization of geometric constraint
116-
static QDataStream & operator<< ( QDataStream & out, const ConstraintBase & c);
167+
QDataStream & operator<< ( QDataStream & out, const ConstraintBase & c)
168+
{
169+
// qDebug() << Q_FUNC_INFO << c.type_name() << c.type_name()[0];
170+
out << c.type_name()[0]; // first character, {'v','h','d','o','p','c'}
171+
out << c.status(); // { UNEVAL=0 | REQUIRED | OBSOLETE };
172+
out << c.enforced();
173+
174+
return out;
175+
}
176+
117177
//! Deserialization of geometric constraint
118-
static QDataStream & operator>> ( QDataStream & in, ConstraintBase & c);
178+
QDataStream & operator>> ( QDataStream &in, ConstraintBase &c )
179+
{
180+
// qDebug() << Q_FUNC_INFO;
181+
int status = 0; // underlying type of enum
182+
in >> status;
183+
c.setStatus( static_cast<ConstraintBase::Status>(status) );
184+
185+
bool enforced = false;
186+
in >> enforced;
187+
c.setEnforced( enforced );
188+
189+
return in;
190+
}
191+
192+
193+
//! Overloaded operator<< for vectors
194+
template <typename T>
195+
QDataStream & operator<< ( QDataStream & out, const Vector<T,Dynamic> &v)
196+
{
197+
//qDebug() << Q_FUNC_INFO;
198+
for (const T val : v) {
199+
out << val;
200+
}
201+
202+
return out;
203+
}
204+
205+
206+
//! Overloaded operator>> for vectors
207+
template <typename T, int N>
208+
QDataStream & operator>> ( QDataStream & in, Vector<T,N> & v)
209+
{
210+
for (T & val : v ) {
211+
in >> val;
212+
}
213+
214+
return in;
215+
}
216+
217+
218+
//! Overloaded operator>> for matrices
219+
template <typename T>
220+
QDataStream & operator>> ( QDataStream & in, MatrixBase<T> & MM)
221+
{
222+
for ( int r=0; r<MM.rows(); r++) {
223+
for ( int c=0; c<MM.cols(); c++) {
224+
in >> MM(r,c);
225+
}
226+
}
227+
228+
return in;
229+
}
230+
231+
232+
//! Overloaded operator<< for matrices
233+
template <typename T>
234+
QDataStream & operator<< ( QDataStream & out, const MatrixBase<T> &MM)
235+
{
236+
//qDebug() << Q_FUNC_INFO;
237+
for ( int r=0; r<MM.rows(); r++) {
238+
for (int c=0; c<MM.cols(); c++) {
239+
out << MM(r,c);
240+
}
241+
}
242+
243+
return out;
244+
}
245+
246+
247+
template <typename T>
248+
QDataStream & operator<< (QDataStream & out, const Aabb<T> & bbox)
249+
{
250+
for (int i=0; i<bbox.dim(); i++) {
251+
out << bbox.min(i) << bbox.max(i);
252+
}
253+
254+
return out;
255+
}
256+
257+
258+
template <typename T>
259+
QDataStream & operator>> (QDataStream & in, Aabb<T> & bbox)
260+
{
261+
T x_min = 0;
262+
T x_max = 0;
263+
T y_min = 0;
264+
T y_max = 0;
265+
in >> x_min >> x_max >> y_min >> y_max;
266+
267+
// bad design: just 2D boxes:
268+
bbox = Aabb<T>( Vector<T,2>(x_min, y_min), Vector<T,2>(x_max, y_max) );
269+
270+
return in;
271+
}
272+
273+
274+
//! Deserialization of uncertain straight line segment and its bounding box
275+
QDataStream & operator>> ( QDataStream & in, uStraightLineSegment & us)
276+
{
277+
// qDebug() << Q_FUNC_INFO;
278+
Vector<double,9> t;
279+
Matrix<double,9,9> Sigma_tt;
280+
Aabb<double> bbox;
281+
in >> t;
282+
in >> Sigma_tt;
283+
in >> bbox;
284+
us = uStraightLineSegment(t, Sigma_tt);
285+
286+
return in;
287+
}
288+
289+
290+
QDataStream & operator<< ( QDataStream & out, const uStraightLineSegment & us)
291+
{
292+
//qDebug() << Q_FUNC_INFO;
293+
out << us.t();
294+
out << us.Cov_tt();
295+
out << us.bounding_box();
296+
297+
return out;
298+
}
299+
119300
} // namespace
120301

121302

@@ -282,7 +463,8 @@ bool impl::deserialize( QDataStream & in )
282463
qDebug().noquote() << "(2.1) reading uncertain straight line segments...";
283464
for ( Index s=0; s<Rel.rows(); s++ ) {
284465
auto seg = uStraightLineSegment::create();
285-
if ( !seg->deserialize( in ) ) {
466+
in >> *seg;
467+
if ( in.status()!=0) {
286468
return false;
287469
}
288470
m_segm.append( seg );
@@ -415,7 +597,8 @@ void impl::serialize( QDataStream &out ) const
415597

416598
// (2) geometry
417599
for ( const auto & item : m_segm) {
418-
item->serialize( out );
600+
// item->serialize( out );
601+
out << *item;
419602
}
420603
for ( const auto & item : m_constr) {
421604
// item->serialize( out );
@@ -1445,80 +1628,19 @@ std::pair<uPoint,uPoint> impl::uEndPoints(const VectorXd &xi,
14451628
return { first_, second_};
14461629
}
14471630

1448-
1449-
14501631
namespace {
14511632

1452-
QDataStream & operator<< (QDataStream & out, const IncidenceMatrix & AA)
1453-
{
1454-
// qDebug() << Q_FUNC_INFO;
14551633

1456-
out << static_cast<uint>(AA.rows());
1457-
out << static_cast<uint>(AA.cols());
1458-
out << static_cast<uint>(AA.nonZeros());
14591634

1460-
for( Index c=0; c<AA.outerSize(); ++c) {
1461-
SparseMatrix<int,ColMajor>::InnerIterator it( AA, c);
1462-
for( ; it; ++it) {
1463-
out << static_cast<int>(it.row()) << static_cast<int>(it.col());
1464-
}
1465-
}
1466-
return out;
1467-
}
14681635

14691636

1470-
QDataStream & operator>> (QDataStream & in, IncidenceMatrix & AA)
1471-
{
1472-
// qDebug() << Q_FUNC_INFO;
14731637

1474-
uint nrows = 0;
1475-
uint ncols = 0;
1476-
uint nnz = 0;
1477-
in >> nrows >> ncols >> nnz;
14781638

1479-
// fill vector with triplets (i,j,value)
1480-
std::vector< Eigen::Triplet<int> > tripletList;
1481-
tripletList.reserve( nnz );
1482-
int r = 0;
1483-
int c = 0;
1484-
for ( uint i=0; i<nnz; i++ ) {
1485-
in >> r >> c;
1486-
tripletList.emplace_back( r, c, 1 );
1487-
}
14881639

1489-
// fill sparse matrix
1490-
AA.resize(static_cast<int>(nrows), static_cast<int>(ncols));
1491-
AA.setFromTriplets( tripletList.begin(),
1492-
tripletList.end() );
14931640

1494-
return in;
1495-
}
14961641

14971642

1498-
QDataStream & operator<< ( QDataStream & out, const ConstraintBase & c)
1499-
{
1500-
// qDebug() << Q_FUNC_INFO << c.type_name() << c.type_name()[0];
1501-
out << c.type_name()[0]; // first character, {'v','h','d','o','p','c'}
1502-
out << c.status(); // { UNEVAL=0 | REQUIRED | OBSOLETE };
1503-
out << c.enforced();
15041643

1505-
return out;
1506-
}
1507-
1508-
1509-
QDataStream & operator>> ( QDataStream &in, ConstraintBase &c )
1510-
{
1511-
// qDebug() << Q_FUNC_INFO;
1512-
int status = 0; // underlying type of enum
1513-
in >> status;
1514-
c.setStatus( static_cast<ConstraintBase::Status>(status) );
1515-
1516-
bool enforced = false;
1517-
in >> enforced;
1518-
c.setEnforced( enforced );
1519-
1520-
return in;
1521-
}
15221644

15231645
} // namespace
15241646

0 commit comments

Comments
 (0)