2015-09-02 17:51:43 -04:00
|
|
|
/*
|
|
|
|
|
* switchVariableLinear.h
|
|
|
|
|
*
|
|
|
|
|
* Created on: 02.08.2012
|
|
|
|
|
* Author: niko
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef SWITCHVARIABLELINEAR_H_
|
|
|
|
|
#define SWITCHVARIABLELINEAR_H_
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2019-01-29 19:06:28 -05:00
|
|
|
// DerivedValue2.h removed from gtsam repo (Dec 2018): https://github.com/borglab/gtsam/commit/e550f4f2aec423cb3f2791b81cb5858b8826ebac
|
2019-01-29 18:00:57 -05:00
|
|
|
#include "DerivedValue.h"
|
2015-09-02 17:51:43 -04:00
|
|
|
#include <gtsam/base/Lie.h>
|
2026-09-30 21:03:04 -07:00
|
|
|
#include <gtsam/base/Manifold.h>
|
2026-04-27 06:33:05 +08:00
|
|
|
#include <gtsam/nonlinear/NonlinearFactor.h>
|
2015-09-02 17:51:43 -04:00
|
|
|
|
|
|
|
|
namespace vertigo {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* SwitchVariableLinear is a wrapper around double to allow it to be a Lie type
|
|
|
|
|
*/
|
2019-01-29 19:06:28 -05:00
|
|
|
struct SwitchVariableLinear : public rtabmap::DerivedValue<SwitchVariableLinear> {
|
2015-09-02 17:51:43 -04:00
|
|
|
|
|
|
|
|
/** default constructor */
|
|
|
|
|
SwitchVariableLinear() : d_(0.0) {};
|
|
|
|
|
|
|
|
|
|
/** wrap a double */
|
|
|
|
|
SwitchVariableLinear(double d) : d_(d) {
|
|
|
|
|
// if (d_ < 0.0) d_=0.0;
|
|
|
|
|
// else if(d_>1.0) d_=1.0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** access the underlying value */
|
|
|
|
|
double value() const { return d_; }
|
|
|
|
|
|
|
|
|
|
/** print @param s optional string naming the object */
|
|
|
|
|
inline void print(const std::string& name="") const {
|
|
|
|
|
std::cout << name << ": " << d_ << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** equality up to tolerance */
|
|
|
|
|
inline bool equals(const SwitchVariableLinear& expected, double tol=1e-5) const {
|
|
|
|
|
return fabs(expected.d_ - d_) <= tol;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Manifold requirements
|
2026-09-30 21:03:04 -07:00
|
|
|
static constexpr int dimension = 1;
|
2015-09-02 17:51:43 -04:00
|
|
|
|
|
|
|
|
/** Returns dimensionality of the tangent space */
|
|
|
|
|
inline size_t dim() const { return 1; }
|
|
|
|
|
inline static size_t Dim() { return 1; }
|
|
|
|
|
|
|
|
|
|
/** Update the SwitchVariableLinear with a tangent space update */
|
|
|
|
|
inline SwitchVariableLinear retract(const gtsam::Vector& v) const {
|
|
|
|
|
double x = value() + v(0);
|
|
|
|
|
|
|
|
|
|
if (x>1.0) x=1.0;
|
|
|
|
|
else if (x<0.0) x=0.0;
|
|
|
|
|
|
|
|
|
|
return SwitchVariableLinear(x);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @return the local coordinates of another object */
|
2026-09-30 21:03:04 -07:00
|
|
|
inline gtsam::Vector1 localCoordinates(const SwitchVariableLinear& t2,
|
|
|
|
|
gtsam::OptionalJacobian<1, 1> H1 = {},
|
|
|
|
|
gtsam::OptionalJacobian<1, 1> H2 = {}) const {
|
|
|
|
|
if (H1) *H1 = -gtsam::Matrix11::Identity();
|
|
|
|
|
if (H2) *H2 = gtsam::Matrix11::Identity();
|
|
|
|
|
return gtsam::Vector1(t2.value() - value());
|
|
|
|
|
}
|
2015-09-02 17:51:43 -04:00
|
|
|
|
|
|
|
|
// Group requirements
|
|
|
|
|
|
|
|
|
|
/** identity */
|
|
|
|
|
inline static SwitchVariableLinear identity() {
|
|
|
|
|
return SwitchVariableLinear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** compose with another object */
|
|
|
|
|
inline SwitchVariableLinear compose(const SwitchVariableLinear& p) const {
|
|
|
|
|
return SwitchVariableLinear(d_ + p.d_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** between operation */
|
|
|
|
|
inline SwitchVariableLinear between(const SwitchVariableLinear& l2,
|
2023-08-07 22:33:23 +08:00
|
|
|
#if GTSAM_VERSION_NUMERIC >= 40300
|
2026-04-27 06:33:05 +08:00
|
|
|
gtsam::OptionalMatrixType H1=OptionalNone,
|
|
|
|
|
gtsam::OptionalMatrixType H2=OptionalNone) const {
|
2023-05-14 13:14:53 -07:00
|
|
|
#else
|
2015-09-02 17:51:43 -04:00
|
|
|
boost::optional<gtsam::Matrix&> H1=boost::none,
|
|
|
|
|
boost::optional<gtsam::Matrix&> H2=boost::none) const {
|
2023-05-14 13:14:53 -07:00
|
|
|
#endif
|
2020-11-22 14:29:05 -05:00
|
|
|
if(H1) *H1 = -gtsam::Matrix::Identity(1, 1);
|
|
|
|
|
if(H2) *H2 = gtsam::Matrix::Identity(1, 1);
|
2015-09-02 17:51:43 -04:00
|
|
|
return SwitchVariableLinear(l2.value() - value());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** invert the object and yield a new one */
|
|
|
|
|
inline SwitchVariableLinear inverse() const {
|
|
|
|
|
return SwitchVariableLinear(-1.0 * value());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Lie functions
|
|
|
|
|
|
|
|
|
|
/** Expmap around identity */
|
|
|
|
|
static inline SwitchVariableLinear Expmap(const gtsam::Vector& v) { return SwitchVariableLinear(v(0)); }
|
|
|
|
|
|
|
|
|
|
/** Logmap around identity - just returns with default cast back */
|
|
|
|
|
static inline gtsam::Vector Logmap(const SwitchVariableLinear& p) { return gtsam::Vector1(p.value()); }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
double d_;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace gtsam {
|
2026-09-30 21:03:04 -07:00
|
|
|
// Use the scalar manifold's dimension, category and chart operations.
|
|
|
|
|
template<> struct traits<vertigo::SwitchVariableLinear>
|
|
|
|
|
: internal::Manifold<vertigo::SwitchVariableLinear> {};
|
2015-09-02 17:51:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* SWITCHVARIABLELINEAR_H_ */
|