diff --git a/gtsam/slam/simulated2D.h b/gtsam/slam/simulated2D.h index e95f699f1..0442cbf9d 100644 --- a/gtsam/slam/simulated2D.h +++ b/gtsam/slam/simulated2D.h @@ -16,7 +16,6 @@ */ // \callgraph - #pragma once #include @@ -35,88 +34,110 @@ namespace gtsam { typedef LieValues PoseValues; typedef LieValues PointValues; + /** + * Custom Values class that holds poses and points + */ class Values: public TupleValues2 { public: - typedef TupleValues2 Base; - typedef boost::shared_ptr sharedPoint; + typedef TupleValues2 Base; ///< base class + typedef boost::shared_ptr sharedPoint; ///< shortcut to shared Point type - Values() {} - Values(const Base& base) : Base(base) {} + /// Constructor + Values() { + } + /// Copy constructor + Values(const Base& base) : + Base(base) { + } + + /// Insert a pose void insertPose(const simulated2D::PoseKey& i, const Point2& p) { insert(i, p); } + /// Insert a point void insertPoint(const simulated2D::PointKey& j, const Point2& p) { insert(j, p); } + /// Number of poses int nrPoses() const { return this->first_.size(); } + /// Number of points int nrPoints() const { return this->second_.size(); } + /// Return pose i sharedPoint pose(const simulated2D::PoseKey& i) { return sharedPoint(new Point2((*this)[i])); } + /// Return point j sharedPoint point(const simulated2D::PointKey& j) { return sharedPoint(new Point2((*this)[j])); } }; - /** - * Prior on a single pose, and optional derivative version - */ + /// Prior on a single pose inline Point2 prior(const Point2& x) { return x; } + + /// Prior on a single pose, optionally returns derivative Point2 prior(const Point2& x, boost::optional H = boost::none); - /** - * odometry between two poses, and optional derivative version - */ + /// odometry between two poses inline Point2 odo(const Point2& x1, const Point2& x2) { return x2 - x1; } + + /// odometry between two poses, optionally returns derivative Point2 odo(const Point2& x1, const Point2& x2, boost::optional H1 = boost::none, boost::optional H2 = boost::none); - /** - * measurement between landmark and pose, and optional derivative version - */ + /// measurement between landmark and pose inline Point2 mea(const Point2& x, const Point2& l) { return l - x; } + + /// measurement between landmark and pose, optionally returns derivative Point2 mea(const Point2& x, const Point2& l, boost::optional H1 = boost::none, boost::optional H2 = boost::none); /** - * Unary factor encoding a soft prior on a vector + * Unary factor encoding a soft prior on a vector */ template class GenericPrior: public NonlinearFactor1 { public: - typedef NonlinearFactor1 Base; + typedef NonlinearFactor1 Base; ///< base class typedef boost::shared_ptr > shared_ptr; - typedef typename KEY::Value Pose; - Pose z_; + typedef typename KEY::Value Pose; ///< shortcut to Pose type + Pose z_; ///< prior mean + + /// Create generic prior GenericPrior(const Pose& z, const SharedNoiseModel& model, const KEY& key) : - NonlinearFactor1 (model, key), z_(z) { + NonlinearFactor1(model, key), z_(z) { } + /// Return error and optional derivative Vector evaluateError(const Pose& x, boost::optional H = boost::none) const { return (prior(x, H) - z_).vector(); } private: - GenericPrior() {} - /** Serialization function */ + + /// Default constructor + GenericPrior() { + } + + /// Serialization function friend class boost::serialization::access; template void serialize(ARCHIVE & ar, const unsigned int version) { @@ -131,24 +152,32 @@ namespace gtsam { template class GenericOdometry: public NonlinearFactor2 { public: - typedef NonlinearFactor2 Base; + typedef NonlinearFactor2 Base; ///< base class typedef boost::shared_ptr > shared_ptr; - typedef typename KEY::Value Pose; - Pose z_; + typedef typename KEY::Value Pose; ///< shortcut to Pose type + Pose z_; ///< odometry measurement + + /// Create odometry GenericOdometry(const Pose& z, const SharedNoiseModel& model, const KEY& i1, const KEY& i2) : - NonlinearFactor2 (model, i1, i2), z_(z) { + NonlinearFactor2(model, i1, i2), z_(z) { } - Vector evaluateError(const Pose& x1, const Pose& x2, boost::optional< - Matrix&> H1 = boost::none, boost::optional H2 = boost::none) const { + /// Evaluate error and optionally return derivatives + Vector evaluateError(const Pose& x1, const Pose& x2, + boost::optional H1 = boost::none, + boost::optional H2 = boost::none) const { return (odo(x1, x2, H1, H2) - z_).vector(); } private: - GenericOdometry() {} - /** Serialization function */ + + /// Default constructor + GenericOdometry() { + } + + /// Serialization function friend class boost::serialization::access; template void serialize(ARCHIVE & ar, const unsigned int version) { @@ -163,26 +192,33 @@ namespace gtsam { template class GenericMeasurement: public NonlinearFactor2 { public: - typedef NonlinearFactor2 Base; + typedef NonlinearFactor2 Base; ///< base class typedef boost::shared_ptr > shared_ptr; - typedef typename XKEY::Value Pose; - typedef typename LKEY::Value Point; + typedef typename XKEY::Value Pose; ///< shortcut to Pose type + typedef typename LKEY::Value Point; ///< shortcut to Point type - Point z_; + Point z_; ///< Measurement + /// Create measurement factor GenericMeasurement(const Point& z, const SharedNoiseModel& model, const XKEY& i, const LKEY& j) : - NonlinearFactor2 (model, i, j), z_(z) { + NonlinearFactor2(model, i, j), z_(z) { } - Vector evaluateError(const Pose& x1, const Point& x2, boost::optional< - Matrix&> H1 = boost::none, boost::optional H2 = boost::none) const { + /// Evaluate error and optionally return derivatives + Vector evaluateError(const Pose& x1, const Point& x2, + boost::optional H1 = boost::none, + boost::optional H2 = boost::none) const { return (mea(x1, x2, H1, H2) - z_).vector(); } private: - GenericMeasurement() {} - /** Serialization function */ + + /// Default constructor + GenericMeasurement() { + } + + /// Serialization function friend class boost::serialization::access; template void serialize(ARCHIVE & ar, const unsigned int version) {