|
35 | 35 | #include "adjustment.h" |
36 | 36 | #include "conncomp.h" |
37 | 37 | #include "constraints.h" |
| 38 | +#include "geometry/aabb.h" |
38 | 39 | #include "geometry/acute.h" |
39 | 40 | #include "global.h" |
40 | 41 | #include "mainscene.h" |
|
61 | 62 |
|
62 | 63 | using Eigen::VectorXd; |
63 | 64 | using Eigen::VectorXi; |
| 65 | +using Eigen::Vector; |
64 | 66 | using Eigen::Vector3d; |
65 | 67 | using Eigen::Matrix3d; |
| 68 | +using Eigen::Matrix; |
| 69 | +using Eigen::MatrixBase; |
66 | 70 | using Eigen::Index; |
67 | 71 | using Eigen::SparseMatrix; |
68 | 72 | using Eigen::ColMajor; |
69 | 73 | using Eigen::indexing::last; |
| 74 | +using Eigen::Dynamic; |
| 75 | + |
| 76 | +using Geometry::Aabb; |
70 | 77 |
|
71 | 78 | using Constraint::ConstraintBase; |
72 | 79 | using Constraint::Parallel; |
73 | 80 | using Constraint::Orthogonal; |
74 | 81 | using Constraint::Copunctual; |
75 | | -// using Constraint::Identical; |
76 | 82 | using Constraint::Vertical; |
77 | 83 | using Constraint::Horizontal; |
78 | 84 | using Constraint::Diagonal; |
@@ -105,17 +111,192 @@ Quantiles::Recognition State::recogn_; |
105 | 111 | Quantiles::Snapping State::snap_; |
106 | 112 |
|
107 | 113 |
|
| 114 | + |
108 | 115 | namespace { |
109 | 116 |
|
| 117 | + |
110 | 118 | //! 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 | + |
112 | 137 | //! 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 | + |
114 | 165 |
|
115 | 166 | //! 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 | + |
117 | 177 | //! 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 | + |
119 | 300 | } // namespace |
120 | 301 |
|
121 | 302 |
|
@@ -282,7 +463,8 @@ bool impl::deserialize( QDataStream & in ) |
282 | 463 | qDebug().noquote() << "(2.1) reading uncertain straight line segments..."; |
283 | 464 | for ( Index s=0; s<Rel.rows(); s++ ) { |
284 | 465 | auto seg = uStraightLineSegment::create(); |
285 | | - if ( !seg->deserialize( in ) ) { |
| 466 | + in >> *seg; |
| 467 | + if ( in.status()!=0) { |
286 | 468 | return false; |
287 | 469 | } |
288 | 470 | m_segm.append( seg ); |
@@ -415,7 +597,8 @@ void impl::serialize( QDataStream &out ) const |
415 | 597 |
|
416 | 598 | // (2) geometry |
417 | 599 | for ( const auto & item : m_segm) { |
418 | | - item->serialize( out ); |
| 600 | + // item->serialize( out ); |
| 601 | + out << *item; |
419 | 602 | } |
420 | 603 | for ( const auto & item : m_constr) { |
421 | 604 | // item->serialize( out ); |
@@ -1445,80 +1628,19 @@ std::pair<uPoint,uPoint> impl::uEndPoints(const VectorXd &xi, |
1445 | 1628 | return { first_, second_}; |
1446 | 1629 | } |
1447 | 1630 |
|
1448 | | - |
1449 | | - |
1450 | 1631 | namespace { |
1451 | 1632 |
|
1452 | | -QDataStream & operator<< (QDataStream & out, const IncidenceMatrix & AA) |
1453 | | -{ |
1454 | | - // qDebug() << Q_FUNC_INFO; |
1455 | 1633 |
|
1456 | | - out << static_cast<uint>(AA.rows()); |
1457 | | - out << static_cast<uint>(AA.cols()); |
1458 | | - out << static_cast<uint>(AA.nonZeros()); |
1459 | 1634 |
|
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 | | -} |
1468 | 1635 |
|
1469 | 1636 |
|
1470 | | -QDataStream & operator>> (QDataStream & in, IncidenceMatrix & AA) |
1471 | | -{ |
1472 | | - // qDebug() << Q_FUNC_INFO; |
1473 | 1637 |
|
1474 | | - uint nrows = 0; |
1475 | | - uint ncols = 0; |
1476 | | - uint nnz = 0; |
1477 | | - in >> nrows >> ncols >> nnz; |
1478 | 1638 |
|
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 | | - } |
1488 | 1639 |
|
1489 | | - // fill sparse matrix |
1490 | | - AA.resize(static_cast<int>(nrows), static_cast<int>(ncols)); |
1491 | | - AA.setFromTriplets( tripletList.begin(), |
1492 | | - tripletList.end() ); |
1493 | 1640 |
|
1494 | | - return in; |
1495 | | -} |
1496 | 1641 |
|
1497 | 1642 |
|
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(); |
1504 | 1643 |
|
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 | | -} |
1522 | 1644 |
|
1523 | 1645 | } // namespace |
1524 | 1646 |
|
0 commit comments