diff --git a/gtsam-broken.h b/gtsam-broken.h index 09113a695..6d7fbe4b0 100644 --- a/gtsam-broken.h +++ b/gtsam-broken.h @@ -1,6 +1,11 @@ // These are considered to be broken and will be added back as they start working // It's assumed that there have been interface changes that might break this +class Pose3 { + Point3* _translation() const; + Rot3* _rotation() const; +}; + class Ordering{ Ordering(string key); void print(string s) const; diff --git a/gtsam.h b/gtsam.h index 73c9cc207..9b4eb1437 100644 --- a/gtsam.h +++ b/gtsam.h @@ -42,6 +42,10 @@ class Rot2 { class Rot3 { Rot3(); Rot3(Matrix R); + Matrix matrix() const; + Matrix transpose() const; + Vector xyz() const; + Vector ypr() const; void print(string s) const; bool equals(const Rot3& rot, double tol) const; Rot3* compose_(const Rot3& p2); @@ -72,12 +76,14 @@ class Pose3 { Pose3(); Pose3(const Rot3& r, const Point3& t); Pose3(Vector v); + Pose3(Matrix t); void print(string s) const; bool equals(const Pose3& pose, double tol) const; double x() const; double y() const; double z() const; - int dim() const; + Matrix matrix() const; + Matrix adjointMap() const; Pose3* compose_(const Pose3& p2); Pose3* between_(const Pose3& p2); Vector localCoordinates(const Pose3& p); diff --git a/gtsam/base/TestableAssertions.h b/gtsam/base/TestableAssertions.h index 69fa02a45..46f738f7d 100644 --- a/gtsam/base/TestableAssertions.h +++ b/gtsam/base/TestableAssertions.h @@ -277,6 +277,18 @@ bool assert_container_equality(const V& expected, const V& actual) { return true; } +/** + * Compare strings for unit tests + */ +bool assert_equal(const std::string& expected, const std::string& actual) { + if (expected == actual) + return true; + printf("Not equal:\n"); + std::cout << "expected: [" << expected << "]\n"; + std::cout << "actual: [" << actual << "]" << std::endl; + return false; +} + /** * Allow for testing inequality */ diff --git a/gtsam/geometry/Pose3.cpp b/gtsam/geometry/Pose3.cpp index c600669b6..6c6860f0f 100644 --- a/gtsam/geometry/Pose3.cpp +++ b/gtsam/geometry/Pose3.cpp @@ -38,7 +38,7 @@ namespace gtsam { // Calculate Adjoint map // Ad_pose is 6*6 matrix that when applied to twist xi, returns Ad_pose(xi) // Experimental - unit tests of derivatives based on it do not check out yet - Matrix Pose3::AdjointMap() const { + Matrix Pose3::adjointMap() const { const Matrix R = R_.matrix(); const Vector t = t_.vector(); Matrix A = skewSymmetric(t)*R; @@ -188,7 +188,7 @@ namespace gtsam { boost::optional H1, boost::optional H2) const { if (H1) { #ifdef CORRECT_POSE3_EXMAP - *H1 = AdjointMap(inverse(p2)); // FIXME: this function doesn't exist with this interface + *H1 = adjointMap(inverse(p2)); // FIXME: this function doesn't exist with this interface #else const Rot3& R2 = p2.rotation(); const Point3& t2 = p2.translation(); @@ -216,8 +216,8 @@ namespace gtsam { Pose3 Pose3::inverse(boost::optional H1) const { if (H1) #ifdef CORRECT_POSE3_EXMAP - // FIXME: this function doesn't exist with this interface - should this be "*H1 = -AdjointMap();" ? - { *H1 = - AdjointMap(p); } + // FIXME: this function doesn't exist with this interface - should this be "*H1 = -adjointMap();" ? + { *H1 = - adjointMap(p); } #else { Matrix Rt = R_.transpose(); diff --git a/gtsam/geometry/Pose3.h b/gtsam/geometry/Pose3.h index 51f6f80a9..f8e40efd1 100644 --- a/gtsam/geometry/Pose3.h +++ b/gtsam/geometry/Pose3.h @@ -56,7 +56,14 @@ namespace gtsam { T(2, 1), T(2, 2)), t_(T(0, 3), T(1, 3), T(2, 3)) {} const Rot3& rotation() const { return R_; } + boost::shared_ptr _rotation() const { + return boost::shared_ptr(new Rot3(R_)); + } + const Point3& translation() const { return t_; } + boost::shared_ptr _translation() const { + return boost::shared_ptr(new Point3(t_)); + } double x() const { return t_.x(); } double y() const { return t_.y(); } @@ -104,7 +111,7 @@ namespace gtsam { /// @{ /// Dimensionality of tangent space = 6 DOF - used to autodetect sizes - static size_t Dim() { return dimension; } + static size_t Dim() { return dimension; } /// Dimensionality of the tangent space = 6 DOF size_t dim() const { return dimension; } @@ -163,8 +170,8 @@ namespace gtsam { * Calculate Adjoint map * Ad_pose is 6*6 matrix that when applied to twist xi, returns Ad_pose(xi) */ - Matrix AdjointMap() const; /// FIXME Not tested - marked as incorrect - Vector Adjoint(const Vector& xi) const {return AdjointMap()*xi; } /// FIXME Not tested - marked as incorrect + Matrix adjointMap() const; /// FIXME Not tested - marked as incorrect + Vector adjoint(const Vector& xi) const {return adjointMap()*xi; } /// FIXME Not tested - marked as incorrect /** * wedge for Pose3: diff --git a/gtsam/geometry/tests/testPose3.cpp b/gtsam/geometry/tests/testPose3.cpp index cb336bb7e..afc177256 100644 --- a/gtsam/geometry/tests/testPose3.cpp +++ b/gtsam/geometry/tests/testPose3.cpp @@ -195,15 +195,15 @@ TEST(Pose3, expmap_c_full) TEST(Pose3, Adjoint_full) { Pose3 expected = T * Pose3::Expmap(screw::xi) * T.inverse(); - Vector xiprime = T.Adjoint(screw::xi); + Vector xiprime = T.adjoint(screw::xi); EXPECT(assert_equal(expected, Pose3::Expmap(xiprime), 1e-6)); Pose3 expected2 = T2 * Pose3::Expmap(screw::xi) * T2.inverse(); - Vector xiprime2 = T2.Adjoint(screw::xi); + Vector xiprime2 = T2.adjoint(screw::xi); EXPECT(assert_equal(expected2, Pose3::Expmap(xiprime2), 1e-6)); Pose3 expected3 = T3 * Pose3::Expmap(screw::xi) * T3.inverse(); - Vector xiprime3 = T3.Adjoint(screw::xi); + Vector xiprime3 = T3.adjoint(screw::xi); EXPECT(assert_equal(expected3, Pose3::Expmap(xiprime3), 1e-6)); } @@ -259,7 +259,7 @@ TEST(Pose3, Adjoint_compose_full) const Pose3& T1 = T; Vector x = Vector_(6,0.1,0.1,0.1,0.4,0.2,0.8); Pose3 expected = T1 * Pose3::Expmap(x) * T2; - Vector y = T2.inverse().Adjoint(x); + Vector y = T2.inverse().adjoint(x); Pose3 actual = T1 * T2 * Pose3::Expmap(y); EXPECT(assert_equal(expected, actual, 1e-6)); } diff --git a/wrap/Module.cpp b/wrap/Module.cpp index 7e35b0d2b..7a01161e1 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -76,14 +76,14 @@ Module::Module(const string& interfacePath, Rule basisType_p = (str_p("string") | "bool" | "size_t" | "int" | "double"); - Rule ublasType = + Rule eigenType = (str_p("Vector") | "Matrix")[assign_a(arg.type)] >> !ch_p('*')[assign_a(arg.is_ptr,true)]; Rule name_p = lexeme_d[alpha_p >> *(alnum_p | '_')]; Rule argument_p = - ((basisType_p[assign_a(arg.type)] | ublasType | classPtr_p | classRef_p) >> name_p[assign_a(arg.name)]) + ((basisType_p[assign_a(arg.type)] | eigenType | classPtr_p | classRef_p) >> name_p[assign_a(arg.name)]) [push_back_a(args, arg)] [assign_a(arg,arg0)]; diff --git a/wrap/tests/testSpirit.cpp b/wrap/tests/testSpirit.cpp index 3f68952f3..a1862f439 100644 --- a/wrap/tests/testSpirit.cpp +++ b/wrap/tests/testSpirit.cpp @@ -54,7 +54,7 @@ TEST( spirit, sequence ) { CHECK(parse("int --- - -- -", str_p("int") >> *ch_p('-'), space_p).full); CHECK(parse("const \t string", str_p("const") >> str_p("string"), space_p).full); - // not that (see spirit FAQ) the vanilla rule<> does not deal with whitespace + // note that (see spirit FAQ) the vanilla rule<> does not deal with whitespace rule<>vanilla_p = str_p("const") >> str_p("string"); CHECK(!parse("const \t string", vanilla_p, space_p).full); diff --git a/wrap/tests/testWrap.cpp b/wrap/tests/testWrap.cpp index 0650538a5..e343aad16 100644 --- a/wrap/tests/testWrap.cpp +++ b/wrap/tests/testWrap.cpp @@ -112,6 +112,14 @@ TEST( wrap, matlab_code ) { EXPECT(files_equal(path + "/tests/expected/make_geometry.m" , "actual/make_geometry.m" )); } +///* ************************************************************************* */ +//TEST( wrap, strip_comments ) { +// string full_string = "This is the first line // comments\n// comments at beginning of line\n"; +// string act_string = strip_comments(full_string); +// string exp_string = "This is the first line \n\n"; +// EXPECT(assert_equal(exp_string, act_string)); +//} + /* ************************************************************************* */ int main() { TestResult tr; return TestRegistry::runAllTests(tr); } /* ************************************************************************* */ diff --git a/wrap/utilities.cpp b/wrap/utilities.cpp index 72833f79a..9ccdfc919 100644 --- a/wrap/utilities.cpp +++ b/wrap/utilities.cpp @@ -39,6 +39,16 @@ string file_contents(const string& filename, bool skipheader) { return ss.str(); } +/* ************************************************************************* */ +bool assert_equal(const std::string& expected, const std::string& actual) { + if (expected == actual) + return true; + printf("Not equal:\n"); + std::cout << "expected: [" << expected << "]\n"; + std::cout << "actual: [" << actual << "]" << std::endl; + return false; +} + /* ************************************************************************* */ bool files_equal(const string& expected, const string& actual, bool skipheader) { try { @@ -66,3 +76,8 @@ void emit_header_comment(ofstream& ofs, const string& delimiter) { } /* ************************************************************************* */ +std::string strip_comments(const std::string& full_string) { + return full_string; /// PLACEHOLDER +} + +/* ************************************************************************* */ diff --git a/wrap/utilities.h b/wrap/utilities.h index d3ab3e197..53f9c7414 100644 --- a/wrap/utilities.h +++ b/wrap/utilities.h @@ -38,7 +38,8 @@ class ParseFailed : public std::exception { ~ParseFailed() throw() {} virtual const char* what() const throw() { std::stringstream buf; - buf << "Parse failed at character " << (length_+1); + int len = length_+1; + buf << "Parse failed at character [" << len << "]"; return buf.str().c_str(); } }; @@ -54,7 +55,16 @@ std::string file_contents(const std::string& filename, bool skipheader=false); */ bool files_equal(const std::string& expected, const std::string& actual, bool skipheader=true); +/** + * Compare strings for unit tests + */ +bool assert_equal(const std::string& expected, const std::string& actual); /** * emit a header at the top of generated files */ void emit_header_comment(std::ofstream& ofs, const std::string& delimiter); + +/** + * Removes comments denoted with '//' from a string + */ +std::string strip_comments(const std::string& full_string); diff --git a/wrap/wrap.cpp b/wrap/wrap.cpp index d18664cda..51ba636c3 100644 --- a/wrap/wrap.cpp +++ b/wrap/wrap.cpp @@ -46,7 +46,7 @@ void generate_matlab_toolbox(const string& interfacePath, /** * main parses arguments and calls generate_matlab_toolbox above - * Typyically called from "make all" using appropriate arguments + * Typically called from "make all" using appropriate arguments */ int main(int argc, const char* argv[]) { if (argc<5 || argc>6) {