From 850c8a792105fd2d6ceca59b3000de0ea7ba7b75 Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Sun, 12 Jul 2015 20:51:01 -0700 Subject: [PATCH] Fixed BearingRangeFactor --- gtsam/sam/BearingRangeFactor.h | 92 +++------------------- gtsam/sam/tests/testBearingRangeFactor.cpp | 2 - 2 files changed, 13 insertions(+), 81 deletions(-) diff --git a/gtsam/sam/BearingRangeFactor.h b/gtsam/sam/BearingRangeFactor.h index 6ef1d7e55..1f4122255 100644 --- a/gtsam/sam/BearingRangeFactor.h +++ b/gtsam/sam/BearingRangeFactor.h @@ -20,50 +20,11 @@ #pragma once #include -#include +#include #include namespace gtsam { -// forward declaration of Bearing functor, assumed partially specified -template -struct Bearing; - -// forward declaration of Range functor, assumed partially specified -template -struct Range; - -template -struct BearingRange : public ProductManifold { - BearingRange() {} - BearingRange(const ProductManifold& br) : ProductManifold(br) {} - BearingRange(const B& b, const R& r) : ProductManifold(b, r) {} - - private: - /// Serialization function - template - void serialize(ARCHIVE& ar, const unsigned int /*version*/) { - ar& boost::serialization::make_nvp("bearing", this->first); - ar& boost::serialization::make_nvp("range", this->second); - } - - friend class boost::serialization::access; -}; - -template -struct traits > - : internal::ManifoldTraits > { - static void Print(const BearingRange& m, const std::string& str = "") { - traits::Print(m.first, str); - traits::Print(m.second, str); - } - static bool Equals(const BearingRange& m1, const BearingRange& m2, - double tol = 1e-8) { - return traits::Equals(m1.first, m2.first, tol) && - traits::Equals(m1.second, m2.second, tol); - } -}; - /** * Binary factor for a bearing/range measurement * @addtogroup SLAM @@ -72,25 +33,21 @@ template ::result_type, typename R = typename Range::result_type> class BearingRangeFactor - : public SerializableExpressionFactor2, A1, A2> { - public: - typedef BearingRange T; + : public SerializableExpressionFactor2, A1, A2> { + private: + typedef BearingRange T; typedef SerializableExpressionFactor2 Base; typedef BearingRangeFactor This; - typedef boost::shared_ptr shared_ptr; - - private: - /** concept check by type */ - BOOST_CONCEPT_ASSERT((IsTestable)); - BOOST_CONCEPT_ASSERT((IsTestable)); public: + typedef boost::shared_ptr shared_ptr; + /// default constructor BearingRangeFactor() {} /// primary constructor BearingRangeFactor(Key key1, Key key2, const B& measuredBearing, - const R measuredRange, const SharedNoiseModel& model) + const R& measuredRange, const SharedNoiseModel& model) : Base(key1, key2, model, T(measuredBearing, measuredRange)) { this->initialize(expression(key1, key2)); } @@ -105,37 +62,14 @@ class BearingRangeFactor // Return measurement expression virtual Expression expression(Key key1, Key key2) const { - Expression a1_(key1); - Expression a2_(key2); - return Expression(This::Predict, a1_, a2_); + return Expression(T::Measure, Expression(key1), Expression(key2)); } - /** Print */ - virtual void print( - const std::string& s = "", - const KeyFormatter& keyFormatter = DefaultKeyFormatter) const { - std::cout << s << "BearingRangeFactor(" << keyFormatter(this->keys_[0]) - << "," << keyFormatter(this->keys_[1]) << ")\n"; - traits::Print(this->measured_.first, "measured bearing: "); - traits::Print(this->measured_.second, "measured range: "); - this->noiseModel_->print("noise model:\n"); - } - - /// Prediction function that stacks measurements - static T Predict(const A1& pose, const A2& point, - typename MakeOptionalJacobian::type H1, - typename MakeOptionalJacobian::type H2) { - typename MakeJacobian::type HB1; - typename MakeJacobian::type HB2; - typename MakeJacobian::type HR1; - typename MakeJacobian::type HR2; - - B b = Bearing()(pose, point, H1 ? &HB1 : 0, H2 ? &HB2 : 0); - R r = Range()(pose, point, H1 ? &HR1 : 0, H2 ? &HR2 : 0); - - if (H1) *H1 << HB1, HR1; - if (H2) *H2 << HB2, HR2; - return T(b, r); + /// print + virtual void print(const std::string& s = "", + const KeyFormatter& kf = DefaultKeyFormatter) const { + std::cout << s << "BearingRangeFactor" << std::endl; + Base::print(s, kf); } }; // BearingRangeFactor diff --git a/gtsam/sam/tests/testBearingRangeFactor.cpp b/gtsam/sam/tests/testBearingRangeFactor.cpp index 8f12988b4..dfc782838 100644 --- a/gtsam/sam/tests/testBearingRangeFactor.cpp +++ b/gtsam/sam/tests/testBearingRangeFactor.cpp @@ -34,12 +34,10 @@ Key poseKey(1); Key pointKey(2); typedef BearingRangeFactor BearingRangeFactor2D; -BearingRangeFactor2D::T measurement2D(1, 2); static SharedNoiseModel model2D(noiseModel::Isotropic::Sigma(2, 0.5)); BearingRangeFactor2D factor2D(poseKey, pointKey, 1, 2, model2D); typedef BearingRangeFactor BearingRangeFactor3D; -BearingRangeFactor3D::T measurement3D(Pose3().bearing(Point3(1, 0, 0)), 0); static SharedNoiseModel model3D(noiseModel::Isotropic::Sigma(3, 0.5)); BearingRangeFactor3D factor3D(poseKey, pointKey, Pose3().bearing(Point3(1, 0, 0)), 1, model3D);