|
| 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 |
0 commit comments