Rename and reformat

release/4.3a0
dellaert 2014-12-04 13:51:51 +01:00
parent fa66762394
commit add93f19a6
1 changed files with 81 additions and 74 deletions

View File

@ -16,99 +16,106 @@
#pragma once #pragma once
#include <boost/lexical_cast.hpp>
#include <gtsam/geometry/concepts.h>
#include <gtsam/nonlinear/NonlinearFactor.h> #include <gtsam/nonlinear/NonlinearFactor.h>
#include <gtsam/geometry/concepts.h>
#include <boost/lexical_cast.hpp>
namespace gtsam { namespace gtsam {
/** /**
* Binary factor for a range measurement * Binary factor for a range measurement
* @addtogroup SLAM * @addtogroup SLAM
*/ */
template<class POSE, class POINT> template<class T1, class T2>
class RangeFactor: public NoiseModelFactor2<POSE, POINT> { class RangeFactor: public NoiseModelFactor2<T1, T2> {
private: private:
double measured_; /** measurement */ double measured_; /** measurement */
boost::optional<POSE> body_P_sensor_; ///< The pose of the sensor in the body frame boost::optional<T1> body_P_sensor_; ///< The pose of the sensor in the body frame
typedef RangeFactor<POSE, POINT> This; typedef RangeFactor<T1, T2> This;
typedef NoiseModelFactor2<POSE, POINT> Base; typedef NoiseModelFactor2<T1, T2> Base;
typedef POSE Pose; // Concept requirements for this factor
typedef POINT Point; GTSAM_CONCEPT_RANGE_MEASUREMENT_TYPE(T1, T2)
// Concept requirements for this factor public:
GTSAM_CONCEPT_RANGE_MEASUREMENT_TYPE(POSE, POINT)
public: RangeFactor() {
} /* Default constructor */
RangeFactor() {} /* Default constructor */ RangeFactor(Key key1, Key key2, double measured,
const SharedNoiseModel& model, boost::optional<T1> body_P_sensor =
boost::none) :
Base(model, key1, key2), measured_(measured), body_P_sensor_(
body_P_sensor) {
}
RangeFactor(Key poseKey, Key pointKey, double measured, virtual ~RangeFactor() {
const SharedNoiseModel& model, boost::optional<POSE> body_P_sensor = boost::none) : }
Base(model, poseKey, pointKey), measured_(measured), body_P_sensor_(body_P_sensor) {
}
virtual ~RangeFactor() {} /// @return a deep copy of this factor
virtual gtsam::NonlinearFactor::shared_ptr clone() const {
return boost::static_pointer_cast<gtsam::NonlinearFactor>(
gtsam::NonlinearFactor::shared_ptr(new This(*this)));
}
/// @return a deep copy of this factor /** h(x)-z */
virtual gtsam::NonlinearFactor::shared_ptr clone() const { Vector evaluateError(const T1& t1, const T2& t2, boost::optional<Matrix&> H1 =
return boost::static_pointer_cast<gtsam::NonlinearFactor>( boost::none, boost::optional<Matrix&> H2 = boost::none) const {
gtsam::NonlinearFactor::shared_ptr(new This(*this))); } double hx;
if (body_P_sensor_) {
/** h(x)-z */ if (H1) {
Vector evaluateError(const POSE& pose, const POINT& point, Matrix H0;
boost::optional<Matrix&> H1 = boost::none, boost::optional<Matrix&> H2 = boost::none) const { hx = t1.compose(*body_P_sensor_, H0).range(t2, H1, H2);
double hx; *H1 = *H1 * H0;
if(body_P_sensor_) {
if(H1) {
Matrix H0;
hx = pose.compose(*body_P_sensor_, H0).range(point, H1, H2);
*H1 = *H1 * H0;
} else {
hx = pose.compose(*body_P_sensor_).range(point, H1, H2);
}
} else { } else {
hx = pose.range(point, H1, H2); hx = t1.compose(*body_P_sensor_).range(t2, H1, H2);
} }
return (Vector(1) << hx - measured_).finished(); } else {
hx = t1.range(t2, H1, H2);
} }
return (Vector(1) << hx - measured_).finished();
}
/** return the measured */ /** return the measured */
double measured() const { double measured() const {
return measured_; return measured_;
} }
/** equals specialized to this factor */ /** equals specialized to this factor */
virtual bool equals(const NonlinearFactor& expected, double tol=1e-9) const { virtual bool equals(const NonlinearFactor& expected,
const This *e = dynamic_cast<const This*> (&expected); double tol = 1e-9) const {
return e != NULL const This *e = dynamic_cast<const This*>(&expected);
&& Base::equals(*e, tol) return e != NULL && Base::equals(*e, tol)
&& fabs(this->measured_ - e->measured_) < tol && fabs(this->measured_ - e->measured_) < tol
&& ((!body_P_sensor_ && !e->body_P_sensor_) || (body_P_sensor_ && e->body_P_sensor_ && body_P_sensor_->equals(*e->body_P_sensor_))); && ((!body_P_sensor_ && !e->body_P_sensor_)
} || (body_P_sensor_ && e->body_P_sensor_
&& body_P_sensor_->equals(*e->body_P_sensor_)));
}
/** print contents */ /** print contents */
void print(const std::string& s="", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const { void print(const std::string& s = "", const KeyFormatter& keyFormatter =
std::cout << s << "RangeFactor, range = " << measured_ << std::endl; DefaultKeyFormatter) const {
if(this->body_P_sensor_) std::cout << s << "RangeFactor, range = " << measured_ << std::endl;
this->body_P_sensor_->print(" sensor pose in body frame: "); if (this->body_P_sensor_)
Base::print("", keyFormatter); this->body_P_sensor_->print(" sensor pose in body frame: ");
} Base::print("", keyFormatter);
}
private: private:
/** Serialization function */ /** Serialization function */
friend class boost::serialization::access; friend class boost::serialization::access;
template<class ARCHIVE> template<class ARCHIVE>
void serialize(ARCHIVE & ar, const unsigned int version) { void serialize(ARCHIVE & ar, const unsigned int version) {
ar & boost::serialization::make_nvp("NoiseModelFactor2", ar
boost::serialization::base_object<Base>(*this)); & boost::serialization::make_nvp("NoiseModelFactor2",
ar & BOOST_SERIALIZATION_NVP(measured_); boost::serialization::base_object<Base>(*this));
ar & BOOST_SERIALIZATION_NVP(body_P_sensor_); ar & BOOST_SERIALIZATION_NVP(measured_);
} ar & BOOST_SERIALIZATION_NVP(body_P_sensor_);
}; // RangeFactor }
};
// RangeFactor
} // namespace gtsam }// namespace gtsam