Skip to content

Commit

Permalink
Merge pull request #678 from borglab/fix/better-printing
Browse files Browse the repository at this point in the history
Better printing
  • Loading branch information
varunagrawal authored Jan 20, 2021
2 parents e86e328 + 2168cd4 commit 229abc7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gtsam/base/Matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/* ************************************************************************* */
Expand Down
8 changes: 4 additions & 4 deletions gtsam/base/Testable.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@

#pragma once

#include <boost/shared_ptr.hpp>
#include <boost/concept_check.hpp>
#include <stdio.h>
#include <boost/shared_ptr.hpp>
#include <iostream>
#include <string>

#define GTSAM_PRINT(x)((x).print(#x))
Expand Down Expand Up @@ -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 */
Expand Down
8 changes: 7 additions & 1 deletion gtsam/geometry/Pose2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/* ************************************************************************* */
Expand Down
4 changes: 4 additions & 0 deletions gtsam/geometry/Pose2.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ class Pose2: public LieGroup<Pose2, 3> {
*/
static std::pair<size_t, size_t> rotationInterval() { return std::make_pair(2, 2); }

/// Output stream operator
GTSAM_EXPORT
friend std::ostream &operator<<(std::ostream &os, const Pose2& p);

/// @}

private:
Expand Down

0 comments on commit 229abc7

Please # to comment.