From ab1f4c1e32db3236ad65dc52a0a7e43e3674411b Mon Sep 17 00:00:00 2001 From: dellaert Date: Sat, 27 Sep 2014 16:08:59 +0200 Subject: [PATCH] keys now functional --- gtsam_unstable/base/tests/testBAD.cpp | 52 +++++++++++++++++++-------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/gtsam_unstable/base/tests/testBAD.cpp b/gtsam_unstable/base/tests/testBAD.cpp index 8443114cc..a6e9469e2 100644 --- a/gtsam_unstable/base/tests/testBAD.cpp +++ b/gtsam_unstable/base/tests/testBAD.cpp @@ -44,7 +44,11 @@ protected: public: virtual ~ExpressionNode() { } - virtual void getKeys(std::set& keys) const = 0; + + /// Return keys that play in this expression as a set + virtual std::set keys() const = 0; + + /// Return value and optional derivatives virtual T value(const Values& values, boost::optional&> = boost::none) const = 0; }; @@ -70,8 +74,13 @@ public: virtual ~ConstantExpression() { } - virtual void getKeys(std::set& /* keys */) const { + /// Return keys that play in this expression, i.e., the empty set + virtual std::set keys() const { + std::set keys; + return keys; } + + /// Return value and optional derivatives virtual T value(const Values& values, boost::optional&> jacobians = boost::none) const { return value_; @@ -97,9 +106,14 @@ public: virtual ~LeafExpression() { } - virtual void getKeys(std::set& keys) const { + /// Return keys that play in this expression + virtual std::set keys() const { + std::set keys; keys.insert(key_); + return keys; } + + /// Return value and optional derivatives virtual T value(const Values& values, boost::optional&> jacobians = boost::none) const { const T& value = values.at(key_); @@ -143,9 +157,12 @@ public: virtual ~UnaryExpression() { } - virtual void getKeys(std::set& keys) const { - expression_->getKeys(keys); + /// Return keys that play in this expression + virtual std::set keys() const { + return expression_->keys(); } + + /// Return value and optional derivatives virtual T value(const Values& values, boost::optional&> jacobians = boost::none) const { @@ -195,10 +212,15 @@ public: virtual ~BinaryExpression() { } - virtual void getKeys(std::set& keys) const { - expression1_->getKeys(keys); - expression2_->getKeys(keys); + /// Return keys that play in this expression + virtual std::set keys() const { + std::set keys1 = expression1_->keys(); + std::set keys2 = expression2_->keys(); + keys1.insert(keys2.begin(), keys2.end()); + return keys1; } + + /// Return value and optional derivatives virtual T value(const Values& values, boost::optional&> jacobians = boost::none) const { T val; @@ -266,8 +288,8 @@ public: root_.reset(new BinaryExpression(f, expression1, expression2)); } - void getKeys(std::set& keys) const { - root_->getKeys(keys); + std::set keys() const { + return root_->keys(); } T value(const Values& values, boost::optional&> jacobians = boost::none) const { @@ -397,10 +419,12 @@ TEST(BAD, test) { Expression projection(project, p_cam); Expression uv_hat(uncalibrate, K, projection); - // Check getKeys - std::set keys; - uv_hat.getKeys(keys); - EXPECT_LONGS_EQUAL(3, keys.size()); + // Check keys + std::set expectedKeys; + expectedKeys.insert(1); + expectedKeys.insert(2); + expectedKeys.insert(3); + EXPECT(expectedKeys == uv_hat.keys()); // Create factor BADFactor f(measured, uv_hat);