gtsam/gtsam/base/LieScalar.h

102 lines
2.9 KiB
C
Raw Normal View History

/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
* -------------------------------------------------------------------------- */
2010-09-30 11:37:15 +08:00
/**
* @file LieScalar.h
* @brief A wrapper around scalar providing Lie compatibility
* @author Kai Ni
*/
#pragma once
#include <gtsam/base/DerivedValue.h>
2010-09-30 11:37:15 +08:00
#include <gtsam/base/Lie.h>
namespace gtsam {
/**
* LieScalar is a wrapper around double to allow it to be a Lie type
*/
struct LieScalar : public DerivedValue<LieScalar> {
2010-09-30 11:37:15 +08:00
/** default constructor */
LieScalar() : d_(0.0) {}
2010-09-30 11:37:15 +08:00
/** wrap a double */
explicit LieScalar(double d) : d_(d) {}
2010-09-30 11:37:15 +08:00
/** access the underlying value */
double value() const { return d_; }
/** Automatic conversion to underlying value */
operator double() const { return d_; }
/** print @param name optional string naming the object */
inline void print(const std::string& name="") const {
std::cout << name << ": " << d_ << std::endl;
}
2010-09-30 11:37:15 +08:00
/** equality up to tolerance */
inline bool equals(const LieScalar& expected, double tol=1e-5) const {
return fabs(expected.d_ - d_) <= tol;
}
2010-09-30 11:37:15 +08:00
// Manifold requirements
/** Returns dimensionality of the tangent space */
inline size_t dim() const { return 1; }
inline static size_t Dim() { return 1; }
2010-09-30 11:37:15 +08:00
/** Update the LieScalar with a tangent space update */
inline LieScalar retract(const Vector& v) const { return LieScalar(value() + v(0)); }
2010-09-30 11:37:15 +08:00
/** @return the local coordinates of another object */
inline Vector localCoordinates(const LieScalar& t2) const { return Vector_(1,(t2.value() - value())); }
2010-09-30 11:37:15 +08:00
// Group requirements
2010-09-30 11:37:15 +08:00
/** identity */
inline static LieScalar identity() {
return LieScalar();
}
/** compose with another object */
inline LieScalar compose(const LieScalar& p) const {
return LieScalar(d_ + p.d_);
}
/** between operation */
inline LieScalar between(const LieScalar& l2,
boost::optional<Matrix&> H1=boost::none,
boost::optional<Matrix&> H2=boost::none) const {
if(H1) *H1 = -eye(1);
if(H2) *H2 = eye(1);
return LieScalar(l2.value() - value());
}
/** invert the object and yield a new one */
inline LieScalar inverse() const {
return LieScalar(-1.0 * value());
}
// Lie functions
/** Expmap around identity */
static inline LieScalar Expmap(const Vector& v) { return LieScalar(v(0)); }
/** Logmap around identity - just returns with default cast back */
static inline Vector Logmap(const LieScalar& p) { return Vector_(1,p.value()); }
2010-09-30 11:37:15 +08:00
private:
double d_;
};
2010-09-30 11:37:15 +08:00
} // \namespace gtsam