Added more functions to wrap, started going though wrap tests

release/4.3a0
Alex Cunningham 2011-12-01 18:57:32 +00:00
parent ec4cfdf065
commit 4b4815e97f
12 changed files with 80 additions and 17 deletions

View File

@ -1,6 +1,11 @@
// These are considered to be broken and will be added back as they start working // 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 // It's assumed that there have been interface changes that might break this
class Pose3 {
Point3* _translation() const;
Rot3* _rotation() const;
};
class Ordering{ class Ordering{
Ordering(string key); Ordering(string key);
void print(string s) const; void print(string s) const;

View File

@ -42,6 +42,10 @@ class Rot2 {
class Rot3 { class Rot3 {
Rot3(); Rot3();
Rot3(Matrix R); Rot3(Matrix R);
Matrix matrix() const;
Matrix transpose() const;
Vector xyz() const;
Vector ypr() const;
void print(string s) const; void print(string s) const;
bool equals(const Rot3& rot, double tol) const; bool equals(const Rot3& rot, double tol) const;
Rot3* compose_(const Rot3& p2); Rot3* compose_(const Rot3& p2);
@ -72,12 +76,14 @@ class Pose3 {
Pose3(); Pose3();
Pose3(const Rot3& r, const Point3& t); Pose3(const Rot3& r, const Point3& t);
Pose3(Vector v); Pose3(Vector v);
Pose3(Matrix t);
void print(string s) const; void print(string s) const;
bool equals(const Pose3& pose, double tol) const; bool equals(const Pose3& pose, double tol) const;
double x() const; double x() const;
double y() const; double y() const;
double z() const; double z() const;
int dim() const; Matrix matrix() const;
Matrix adjointMap() const;
Pose3* compose_(const Pose3& p2); Pose3* compose_(const Pose3& p2);
Pose3* between_(const Pose3& p2); Pose3* between_(const Pose3& p2);
Vector localCoordinates(const Pose3& p); Vector localCoordinates(const Pose3& p);

View File

@ -277,6 +277,18 @@ bool assert_container_equality(const V& expected, const V& actual) {
return true; 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 * Allow for testing inequality
*/ */

View File

@ -38,7 +38,7 @@ namespace gtsam {
// Calculate Adjoint map // Calculate Adjoint map
// Ad_pose is 6*6 matrix that when applied to twist xi, returns Ad_pose(xi) // 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 // 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 Matrix R = R_.matrix();
const Vector t = t_.vector(); const Vector t = t_.vector();
Matrix A = skewSymmetric(t)*R; Matrix A = skewSymmetric(t)*R;
@ -188,7 +188,7 @@ namespace gtsam {
boost::optional<Matrix&> H1, boost::optional<Matrix&> H2) const { boost::optional<Matrix&> H1, boost::optional<Matrix&> H2) const {
if (H1) { if (H1) {
#ifdef CORRECT_POSE3_EXMAP #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 #else
const Rot3& R2 = p2.rotation(); const Rot3& R2 = p2.rotation();
const Point3& t2 = p2.translation(); const Point3& t2 = p2.translation();
@ -216,8 +216,8 @@ namespace gtsam {
Pose3 Pose3::inverse(boost::optional<Matrix&> H1) const { Pose3 Pose3::inverse(boost::optional<Matrix&> H1) const {
if (H1) if (H1)
#ifdef CORRECT_POSE3_EXMAP #ifdef CORRECT_POSE3_EXMAP
// FIXME: this function doesn't exist with this interface - should this be "*H1 = -AdjointMap();" ? // FIXME: this function doesn't exist with this interface - should this be "*H1 = -adjointMap();" ?
{ *H1 = - AdjointMap(p); } { *H1 = - adjointMap(p); }
#else #else
{ {
Matrix Rt = R_.transpose(); Matrix Rt = R_.transpose();

View File

@ -56,7 +56,14 @@ namespace gtsam {
T(2, 1), T(2, 2)), t_(T(0, 3), T(1, 3), T(2, 3)) {} T(2, 1), T(2, 2)), t_(T(0, 3), T(1, 3), T(2, 3)) {}
const Rot3& rotation() const { return R_; } const Rot3& rotation() const { return R_; }
boost::shared_ptr<Rot3> _rotation() const {
return boost::shared_ptr<Rot3>(new Rot3(R_));
}
const Point3& translation() const { return t_; } const Point3& translation() const { return t_; }
boost::shared_ptr<Point3> _translation() const {
return boost::shared_ptr<Point3>(new Point3(t_));
}
double x() const { return t_.x(); } double x() const { return t_.x(); }
double y() const { return t_.y(); } double y() const { return t_.y(); }
@ -163,8 +170,8 @@ namespace gtsam {
* Calculate Adjoint map * Calculate Adjoint map
* Ad_pose is 6*6 matrix that when applied to twist xi, returns Ad_pose(xi) * 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 Matrix adjointMap() const; /// FIXME Not tested - marked as incorrect
Vector Adjoint(const Vector& xi) const {return AdjointMap()*xi; } /// FIXME Not tested - marked as incorrect Vector adjoint(const Vector& xi) const {return adjointMap()*xi; } /// FIXME Not tested - marked as incorrect
/** /**
* wedge for Pose3: * wedge for Pose3:

View File

@ -195,15 +195,15 @@ TEST(Pose3, expmap_c_full)
TEST(Pose3, Adjoint_full) TEST(Pose3, Adjoint_full)
{ {
Pose3 expected = T * Pose3::Expmap(screw::xi) * T.inverse(); 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)); EXPECT(assert_equal(expected, Pose3::Expmap(xiprime), 1e-6));
Pose3 expected2 = T2 * Pose3::Expmap(screw::xi) * T2.inverse(); 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)); EXPECT(assert_equal(expected2, Pose3::Expmap(xiprime2), 1e-6));
Pose3 expected3 = T3 * Pose3::Expmap(screw::xi) * T3.inverse(); 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)); EXPECT(assert_equal(expected3, Pose3::Expmap(xiprime3), 1e-6));
} }
@ -259,7 +259,7 @@ TEST(Pose3, Adjoint_compose_full)
const Pose3& T1 = T; const Pose3& T1 = T;
Vector x = Vector_(6,0.1,0.1,0.1,0.4,0.2,0.8); Vector x = Vector_(6,0.1,0.1,0.1,0.4,0.2,0.8);
Pose3 expected = T1 * Pose3::Expmap(x) * T2; 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); Pose3 actual = T1 * T2 * Pose3::Expmap(y);
EXPECT(assert_equal(expected, actual, 1e-6)); EXPECT(assert_equal(expected, actual, 1e-6));
} }

View File

@ -76,14 +76,14 @@ Module::Module(const string& interfacePath,
Rule basisType_p = Rule basisType_p =
(str_p("string") | "bool" | "size_t" | "int" | "double"); (str_p("string") | "bool" | "size_t" | "int" | "double");
Rule ublasType = Rule eigenType =
(str_p("Vector") | "Matrix")[assign_a(arg.type)] >> (str_p("Vector") | "Matrix")[assign_a(arg.type)] >>
!ch_p('*')[assign_a(arg.is_ptr,true)]; !ch_p('*')[assign_a(arg.is_ptr,true)];
Rule name_p = lexeme_d[alpha_p >> *(alnum_p | '_')]; Rule name_p = lexeme_d[alpha_p >> *(alnum_p | '_')];
Rule argument_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)] [push_back_a(args, arg)]
[assign_a(arg,arg0)]; [assign_a(arg,arg0)];

View File

@ -54,7 +54,7 @@ TEST( spirit, sequence ) {
CHECK(parse("int --- - -- -", str_p("int") >> *ch_p('-'), space_p).full); 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); 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"); rule<>vanilla_p = str_p("const") >> str_p("string");
CHECK(!parse("const \t string", vanilla_p, space_p).full); CHECK(!parse("const \t string", vanilla_p, space_p).full);

View File

@ -112,6 +112,14 @@ TEST( wrap, matlab_code ) {
EXPECT(files_equal(path + "/tests/expected/make_geometry.m" , "actual/make_geometry.m" )); 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); } int main() { TestResult tr; return TestRegistry::runAllTests(tr); }
/* ************************************************************************* */ /* ************************************************************************* */

View File

@ -39,6 +39,16 @@ string file_contents(const string& filename, bool skipheader) {
return ss.str(); 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) { bool files_equal(const string& expected, const string& actual, bool skipheader) {
try { 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
}
/* ************************************************************************* */

View File

@ -38,7 +38,8 @@ class ParseFailed : public std::exception {
~ParseFailed() throw() {} ~ParseFailed() throw() {}
virtual const char* what() const throw() { virtual const char* what() const throw() {
std::stringstream buf; 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(); 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); 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 * emit a header at the top of generated files
*/ */
void emit_header_comment(std::ofstream& ofs, const std::string& delimiter); 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);

View File

@ -46,7 +46,7 @@ void generate_matlab_toolbox(const string& interfacePath,
/** /**
* main parses arguments and calls generate_matlab_toolbox above * 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[]) { int main(int argc, const char* argv[]) {
if (argc<5 || argc>6) { if (argc<5 || argc>6) {