diff --git a/gtsam/base/Matrix.cpp b/gtsam/base/Matrix.cpp index 551bdac10..41a80629b 100644 --- a/gtsam/base/Matrix.cpp +++ b/gtsam/base/Matrix.cpp @@ -153,7 +153,7 @@ const Eigen::IOFormat& matlabFormat() { /* ************************************************************************* */ //3 argument call void print(const Matrix& A, const string &s, ostream& stream) { - cout << s << A.format(matlabFormat()) << endl; + stream << s << A.format(matlabFormat()) << endl; } /* ************************************************************************* */ diff --git a/gtsam/base/Testable.h b/gtsam/base/Testable.h index 92c464940..2145360df 100644 --- a/gtsam/base/Testable.h +++ b/gtsam/base/Testable.h @@ -33,9 +33,9 @@ #pragma once -#include #include -#include +#include +#include #include #define GTSAM_PRINT(x)((x).print(#x)) @@ -72,10 +72,10 @@ namespace gtsam { }; // \ Testable inline void print(float v, const std::string& s = "") { - printf("%s%f\n",s.c_str(),v); + std::cout << (s == "" ? s : s + " ") << v << std::endl; } inline void print(double v, const std::string& s = "") { - printf("%s%lf\n",s.c_str(),v); + std::cout << (s == "" ? s : s + " ") << v << std::endl; } /** Call equal on the object */ diff --git a/gtsam/geometry/Pose2.cpp b/gtsam/geometry/Pose2.cpp index 71df0f753..bebe53dfa 100644 --- a/gtsam/geometry/Pose2.cpp +++ b/gtsam/geometry/Pose2.cpp @@ -48,7 +48,13 @@ Matrix3 Pose2::matrix() const { /* ************************************************************************* */ void Pose2::print(const string& s) const { - cout << s << "(" << t_.x() << ", " << t_.y() << ", " << r_.theta() << ")" << endl; + cout << s << this << endl; +} + +/* ************************************************************************* */ +std::ostream &operator<<(std::ostream &os, const Pose2& pose) { + os << "(" << pose.x() << ", " << pose.y() << ", " << pose.theta() << ")"; + return os; } /* ************************************************************************* */ diff --git a/gtsam/geometry/Pose2.h b/gtsam/geometry/Pose2.h index 6372779c3..a54951728 100644 --- a/gtsam/geometry/Pose2.h +++ b/gtsam/geometry/Pose2.h @@ -287,6 +287,10 @@ public: */ static std::pair rotationInterval() { return std::make_pair(2, 2); } + /// Output stream operator + GTSAM_EXPORT + friend std::ostream &operator<<(std::ostream &os, const Pose2& p); + /// @} private: