From 18c305f1985221a9c4999c53bd3b30fe107f24aa Mon Sep 17 00:00:00 2001 From: Scott Klum Date: Wed, 28 Jan 2015 15:06:39 -0500 Subject: [PATCH] Converted printEigen to a qDebug operator --- openbr/core/eigenutils.cpp | 19 ------------------- openbr/core/eigenutils.h | 29 +++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/openbr/core/eigenutils.cpp b/openbr/core/eigenutils.cpp index 85c49f1..58b46cc 100644 --- a/openbr/core/eigenutils.cpp +++ b/openbr/core/eigenutils.cpp @@ -45,25 +45,6 @@ void EigenUtils::writeEigen(VectorXf X, QString filename) { format->write(br::Template(m)); } -void EigenUtils::printEigen(Eigen::MatrixXd X) { - for (int i = 0; i < X.rows(); i++) { - QString str; - for (int j = 0; j < X.cols(); j++) { - str.append(QString::number(X(i,j)) + " "); - } - qDebug() << str; - } -} -void EigenUtils::printEigen(Eigen::MatrixXf X) { - for (int i = 0; i < X.rows(); i++) { - QString str; - for (int j = 0; j < X.cols(); j++) { - str.append(QString::number(X(i,j)) + " "); - } - qDebug() << str; - } -} - void EigenUtils::printSize(Eigen::MatrixXf X) { qDebug() << "Rows=" << X.rows() << "\tCols=" << X.cols(); } diff --git a/openbr/core/eigenutils.h b/openbr/core/eigenutils.h index 2ac14f3..427b497 100644 --- a/openbr/core/eigenutils.h +++ b/openbr/core/eigenutils.h @@ -18,6 +18,7 @@ #define EIGENUTILS_H #include +#include #include #include @@ -25,12 +26,29 @@ namespace EigenUtils { + template + QString matrixToString(const Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &mat) + { + QString result; + if (mat.rows() > 1) result += "{ "; + for (int r=0; r 1) && (r > 0)) result += " "; + if (mat.cols() > 1) result += "["; + for (int c=0; c 1) result += "]"; + if (r < mat.rows()-1) result += "\n"; + } + if (mat.rows() > 1) result += " }"; + return result; + } + void writeEigen(Eigen::MatrixXf X, QString filename); void writeEigen(Eigen::MatrixXd X, QString filename); void writeEigen(Eigen::VectorXd X, QString filename); void writeEigen(Eigen::VectorXf X, QString filename); - void printEigen(Eigen::MatrixXd X); - void printEigen(Eigen::MatrixXf X); void printSize(Eigen::MatrixXf X); // Converts x y points in a single vector to two column matrix @@ -52,6 +70,13 @@ namespace EigenUtils } template +inline QDebug operator<<(QDebug dbg, const Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &mat) +{ + dbg.nospace() << EigenUtils::matrixToString(mat); + return dbg.space(); +} + +template inline QDataStream &operator<<(QDataStream &stream, const Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &mat) { int r = mat.rows(); -- libgit2 0.21.4