From 33ba34a1f686656004a313d751db6833ec84d31d Mon Sep 17 00:00:00 2001 From: Richard Roberts Date: Sun, 10 Jan 2010 17:26:44 +0000 Subject: [PATCH] Minimized headers included in Lie.h, removed print from testLieConfig --- cpp/LieConfig-inl.h | 50 ++++++++++++++++++++++++++++++++----------- cpp/LieConfig.h | 28 ++++++------------------ cpp/testLieConfig.cpp | 4 ++-- 3 files changed, 46 insertions(+), 36 deletions(-) diff --git a/cpp/LieConfig-inl.h b/cpp/LieConfig-inl.h index 4abb99771..3406ccce9 100644 --- a/cpp/LieConfig-inl.h +++ b/cpp/LieConfig-inl.h @@ -5,9 +5,15 @@ * Author: richard */ +#include "LieConfig.h" + #include #include -#include "LieConfig.h" +#include +#include +#include + +#include "VectorConfig.h" using namespace std; @@ -35,6 +41,26 @@ namespace gtsam { return true; } + template + const T& LieConfig::get(const std::string& key) const { + iterator it = values_.find(key); + if (it == values_.end()) throw std::invalid_argument("invalid key"); + else return it->second; + } + + template + boost::optional LieConfig::gettry(const std::string& key) const { + const_iterator it = values_.find(key); + if (it == values_.end()) return boost::optional(); + else return it->second; + } + + template + void LieConfig::insert(const std::string& name, const T& val) { + values_.insert(make_pair(name, val)); + dim_ += dim(val); + } + template LieConfig expmap(const LieConfig& c, const VectorConfig& delta) { LieConfig newConfig; @@ -52,16 +78,16 @@ namespace gtsam { // This version just creates a VectorConfig then calls function above template LieConfig expmap(const LieConfig& c, const Vector& delta) { - VectorConfig deltaConfig; - int delta_offset = 0; - string j; T pj; - FOREACH_PAIR(j, pj, c) { - int cur_dim = dim(pj); - Vector dj = sub(delta, delta_offset, delta_offset+cur_dim); - deltaConfig.insert(j,dj); - delta_offset += cur_dim; - } - return expmap(c,deltaConfig); - } + VectorConfig deltaConfig; + int delta_offset = 0; + string j; T pj; + FOREACH_PAIR(j, pj, c) { + int cur_dim = dim(pj); + Vector dj = sub(delta, delta_offset, delta_offset+cur_dim); + deltaConfig.insert(j,dj); + delta_offset += cur_dim; + } + return expmap(c,deltaConfig); + } } diff --git a/cpp/LieConfig.h b/cpp/LieConfig.h index f0d3ba78c..0813bae17 100644 --- a/cpp/LieConfig.h +++ b/cpp/LieConfig.h @@ -11,18 +11,13 @@ #include -#include -#include -#include -#include -#include -#include -#include "Testable.h" -#include "VectorConfig.h" #include "Vector.h" +#include "Testable.h" #include "Lie.h" +namespace boost { template class optional; } +namespace gtsam { class VectorConfig; } namespace gtsam { @@ -57,11 +52,7 @@ namespace gtsam { virtual ~LieConfig() {} /** Retrieve a variable by key, throws std::invalid_argument if not found */ - const T& get(const std::string& key) const { - iterator it = values_.find(key); - if (it == values_.end()) throw std::invalid_argument("invalid key"); - else return it->second; - } + const T& get(const std::string& key) const; /** operator[] syntax for get */ inline const T& operator[](const std::string& name) const { @@ -69,17 +60,10 @@ namespace gtsam { } /** Retrieve a variable by key, returns nothing if not found */ - boost::optional gettry(const std::string& key) const { - const_iterator it = values_.find(key); - if (it == values_.end()) return boost::optional(); - else return it->second; - } + boost::optional gettry(const std::string& key) const; /** Add a variable with the given key */ - void insert(const std::string& name, const T& val) { - values_.insert(make_pair(name, val)); - dim_ += dim(val); - } + void insert(const std::string& name, const T& val); /** Replace all keys and variables */ LieConfig& operator=(const LieConfig& rhs) { diff --git a/cpp/testLieConfig.cpp b/cpp/testLieConfig.cpp index 91d1017a2..c273bf9b2 100644 --- a/cpp/testLieConfig.cpp +++ b/cpp/testLieConfig.cpp @@ -109,12 +109,12 @@ TEST(LieConfig, expmap_d) LieConfig config0; config0.insert("v1", Vector_(3, 1.0, 2.0, 3.0)); config0.insert("v2", Vector_(3, 5.0, 6.0, 7.0)); - config0.print("config0"); + //config0.print("config0"); LieConfig poseconfig; poseconfig.insert("p1", Pose2(1,2,3)); poseconfig.insert("p2", Pose2(0.3, 0.4, 0.5)); - poseconfig.print("poseconfig"); + //poseconfig.print("poseconfig"); } /* ************************************************************************* */