/* * BearingRangeFactor.h * * Created on: Apr 1, 2010 * Author: Kai Ni * Description: a single factor contains both the bearing and the range to prevent handle to pair bearing and range factors */ #pragma once #include "BearingFactor.h" #include "RangeFactor.h" namespace gtsam { /** * Binary factor for a bearing measurement */ template class BearingRangeFactor: public NonlinearFactor2 { private: // the bearing factor BearingFactor bearing_; // the range factor RangeFactor range_; typedef NonlinearFactor2 Base; public: BearingRangeFactor(); /* Default constructor */ BearingRangeFactor(const PoseKey& i, const PointKey& j, const std::pair& z, const SharedGaussian& model) : Base(model, i, j), bearing_(i, j, z.first, model), range_(i, j, z.second, model) { } /** h(x)-z -> between(z,h(x)) for Rot2 manifold */ Vector evaluateError(const Pose2& pose, const Point2& point, boost::optional H1, boost::optional H2) const { Matrix H11, H21, H12, H22; boost::optional H11_ = H1 ? boost::optional(H11) : boost::optional(); boost::optional H21_ = H1 ? boost::optional(H21) : boost::optional(); boost::optional H12_ = H2 ? boost::optional(H12) : boost::optional(); boost::optional H22_ = H2 ? boost::optional(H22) : boost::optional(); Vector e1 = bearing_.evaluateError(pose, point, H11_, H12_); Vector e2 = range_.evaluateError(pose, point, H21_, H22_); if (H1) *H1 = stack_matrices(H11, H21); if (H2) *H2 = stack_matrices(H12, H22); return concatVectors(2, &e1, &e2); } /** return the measured */ inline const std::pair measured() const { return concatVectors(2, bearing_.measured(), range_.measured()); } /** return the bearing factor */ const BearingFactor& bearing() const { return bearing_; } /** return the range factor */ const RangeFactor& range() const { return range_; } }; // BearingRangeFactor } // namespace gtsam