Commit 18c305f1985221a9c4999c53bd3b30fe107f24aa
1 parent
80f91a7c
Converted printEigen to a qDebug operator
Showing
2 changed files
with
27 additions
and
21 deletions
openbr/core/eigenutils.cpp
| @@ -45,25 +45,6 @@ void EigenUtils::writeEigen(VectorXf X, QString filename) { | @@ -45,25 +45,6 @@ void EigenUtils::writeEigen(VectorXf X, QString filename) { | ||
| 45 | format->write(br::Template(m)); | 45 | format->write(br::Template(m)); |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | -void EigenUtils::printEigen(Eigen::MatrixXd X) { | ||
| 49 | - for (int i = 0; i < X.rows(); i++) { | ||
| 50 | - QString str; | ||
| 51 | - for (int j = 0; j < X.cols(); j++) { | ||
| 52 | - str.append(QString::number(X(i,j)) + " "); | ||
| 53 | - } | ||
| 54 | - qDebug() << str; | ||
| 55 | - } | ||
| 56 | -} | ||
| 57 | -void EigenUtils::printEigen(Eigen::MatrixXf X) { | ||
| 58 | - for (int i = 0; i < X.rows(); i++) { | ||
| 59 | - QString str; | ||
| 60 | - for (int j = 0; j < X.cols(); j++) { | ||
| 61 | - str.append(QString::number(X(i,j)) + " "); | ||
| 62 | - } | ||
| 63 | - qDebug() << str; | ||
| 64 | - } | ||
| 65 | -} | ||
| 66 | - | ||
| 67 | void EigenUtils::printSize(Eigen::MatrixXf X) { | 48 | void EigenUtils::printSize(Eigen::MatrixXf X) { |
| 68 | qDebug() << "Rows=" << X.rows() << "\tCols=" << X.cols(); | 49 | qDebug() << "Rows=" << X.rows() << "\tCols=" << X.cols(); |
| 69 | } | 50 | } |
openbr/core/eigenutils.h
| @@ -18,6 +18,7 @@ | @@ -18,6 +18,7 @@ | ||
| 18 | #define EIGENUTILS_H | 18 | #define EIGENUTILS_H |
| 19 | 19 | ||
| 20 | #include <QDataStream> | 20 | #include <QDataStream> |
| 21 | +#include <QDebug> | ||
| 21 | #include <Eigen/Core> | 22 | #include <Eigen/Core> |
| 22 | #include <assert.h> | 23 | #include <assert.h> |
| 23 | 24 | ||
| @@ -25,12 +26,29 @@ | @@ -25,12 +26,29 @@ | ||
| 25 | 26 | ||
| 26 | namespace EigenUtils | 27 | namespace EigenUtils |
| 27 | { | 28 | { |
| 29 | + template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> | ||
| 30 | + QString matrixToString(const Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &mat) | ||
| 31 | + { | ||
| 32 | + QString result; | ||
| 33 | + if (mat.rows() > 1) result += "{ "; | ||
| 34 | + for (int r=0; r<mat.rows(); r++) { | ||
| 35 | + if ((mat.rows() > 1) && (r > 0)) result += " "; | ||
| 36 | + if (mat.cols() > 1) result += "["; | ||
| 37 | + for (int c=0; c<mat.cols(); c++) { | ||
| 38 | + result += QString::number(mat(r, c)); | ||
| 39 | + if (c < mat.cols() - 1) result += ", "; | ||
| 40 | + } | ||
| 41 | + if (mat.cols() > 1) result += "]"; | ||
| 42 | + if (r < mat.rows()-1) result += "\n"; | ||
| 43 | + } | ||
| 44 | + if (mat.rows() > 1) result += " }"; | ||
| 45 | + return result; | ||
| 46 | + } | ||
| 47 | + | ||
| 28 | void writeEigen(Eigen::MatrixXf X, QString filename); | 48 | void writeEigen(Eigen::MatrixXf X, QString filename); |
| 29 | void writeEigen(Eigen::MatrixXd X, QString filename); | 49 | void writeEigen(Eigen::MatrixXd X, QString filename); |
| 30 | void writeEigen(Eigen::VectorXd X, QString filename); | 50 | void writeEigen(Eigen::VectorXd X, QString filename); |
| 31 | void writeEigen(Eigen::VectorXf X, QString filename); | 51 | void writeEigen(Eigen::VectorXf X, QString filename); |
| 32 | - void printEigen(Eigen::MatrixXd X); | ||
| 33 | - void printEigen(Eigen::MatrixXf X); | ||
| 34 | void printSize(Eigen::MatrixXf X); | 52 | void printSize(Eigen::MatrixXf X); |
| 35 | 53 | ||
| 36 | // Converts x y points in a single vector to two column matrix | 54 | // Converts x y points in a single vector to two column matrix |
| @@ -52,6 +70,13 @@ namespace EigenUtils | @@ -52,6 +70,13 @@ namespace EigenUtils | ||
| 52 | } | 70 | } |
| 53 | 71 | ||
| 54 | template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> | 72 | template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> |
| 73 | +inline QDebug operator<<(QDebug dbg, const Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &mat) | ||
| 74 | +{ | ||
| 75 | + dbg.nospace() << EigenUtils::matrixToString(mat); | ||
| 76 | + return dbg.space(); | ||
| 77 | +} | ||
| 78 | + | ||
| 79 | +template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> | ||
| 55 | inline QDataStream &operator<<(QDataStream &stream, const Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &mat) | 80 | inline QDataStream &operator<<(QDataStream &stream, const Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &mat) |
| 56 | { | 81 | { |
| 57 | int r = mat.rows(); | 82 | int r = mat.rows(); |