Merge pull request #419 from borglab/feature/values-print

Values Print Formatting
release/4.3a0
Varun Agrawal 2020-08-01 02:15:15 -04:00 committed by GitHub
commit 8a3be052fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 7 deletions

View File

@ -84,7 +84,7 @@ public:
/// Virtual print function, uses traits /// Virtual print function, uses traits
void print(const std::string& str) const override { void print(const std::string& str) const override {
std::cout << "(" << demangle(typeid(T).name()) << ") "; std::cout << "(" << demangle(typeid(T).name()) << ")\n";
traits<T>::Print(value_, str); traits<T>::Print(value_, str);
} }

View File

@ -862,7 +862,14 @@ TEST( Pose3, stream)
Pose3 T; Pose3 T;
std::ostringstream os; std::ostringstream os;
os << T; os << T;
string expected = "R: [\n\t1, 0, 0;\n\t0, 1, 0;\n\t0, 0, 1\n]\nt: [0, 0, 0]'";
string expected;
#ifdef GTSAM_TYPEDEF_POINTS_TO_VECTORS
expected = "R: [\n\t1, 0, 0;\n\t0, 1, 0;\n\t0, 0, 1\n]\nt: 0\n0\n0";;
#else
expected = "R: [\n\t1, 0, 0;\n\t0, 1, 0;\n\t0, 0, 1\n]\nt: [0, 0, 0]'";
#endif
EXPECT(os.str() == expected); EXPECT(os.str() == expected);
} }
@ -1037,9 +1044,9 @@ TEST(Pose3, print) {
expected << "R: [\n\t1, 0, 0;\n\t0, 1, 0;\n\t0, 0, 1\n]\n"; expected << "R: [\n\t1, 0, 0;\n\t0, 1, 0;\n\t0, 0, 1\n]\n";
#ifdef GTSAM_TYPEDEF_POINTS_TO_VECTORS #ifdef GTSAM_TYPEDEF_POINTS_TO_VECTORS
expected << "1\n" expected << "t: 1\n"
"2\n" "2\n"
"3;\n"; "3\n";
#else #else
expected << "t: [" << translation.x() << ", " << translation.y() << ", " << translation.z() << "]'\n"; expected << "t: [" << translation.x() << ", " << translation.y() << ", " << translation.z() << "]'\n";
#endif #endif

View File

@ -244,7 +244,14 @@ TEST(NavState, Stream)
std::ostringstream os; std::ostringstream os;
os << state; os << state;
string expected = "R: [\n\t1, 0, 0;\n\t0, 1, 0;\n\t0, 0, 1\n]\np: [0, 0, 0]'\nv: [0, 0, 0]'";
string expected;
#ifdef GTSAM_TYPEDEF_POINTS_TO_VECTORS
expected = "R: [\n\t1, 0, 0;\n\t0, 1, 0;\n\t0, 0, 1\n]\np: 0\n0\n0\nv: 0\n0\n0";
#else
expected = "R: [\n\t1, 0, 0;\n\t0, 1, 0;\n\t0, 0, 1\n]\np: [0, 0, 0]'\nv: [0, 0, 0]'";
#endif
EXPECT(os.str() == expected); EXPECT(os.str() == expected);
} }

View File

@ -75,7 +75,8 @@ namespace gtsam {
/* ************************************************************************* */ /* ************************************************************************* */
void Values::print(const string& str, const KeyFormatter& keyFormatter) const { void Values::print(const string& str, const KeyFormatter& keyFormatter) const {
cout << str << "Values with " << size() << " values:" << endl; cout << str << (str == "" ? "" : "\n");
cout << "Values with " << size() << " values:\n";
for(const_iterator key_value = begin(); key_value != end(); ++key_value) { for(const_iterator key_value = begin(); key_value != end(); ++key_value) {
cout << "Value " << keyFormatter(key_value->key) << ": "; cout << "Value " << keyFormatter(key_value->key) << ": ";
key_value->value.print(""); key_value->value.print("");

View File

@ -593,7 +593,7 @@ TEST(Values, Demangle) {
Values values; Values values;
Matrix13 v; v << 5.0, 6.0, 7.0; Matrix13 v; v << 5.0, 6.0, 7.0;
values.insert(key1, v); values.insert(key1, v);
string expected = "Values with 1 values:\nValue v1: (Eigen::Matrix<double, 1, 3, 1, 1, 3>) [\n 5, 6, 7\n]\n\n"; string expected = "Values with 1 values:\nValue v1: (Eigen::Matrix<double, 1, 3, 1, 1, 3>)\n[\n 5, 6, 7\n]\n\n";
stringstream buffer; stringstream buffer;
streambuf * old = cout.rdbuf(buffer.rdbuf()); streambuf * old = cout.rdbuf(buffer.rdbuf());