switchVariableLinear.h
Go to the documentation of this file.
1 /*
2  * switchVariableLinear.h
3  *
4  * Created on: 02.08.2012
5  * Author: niko
6  */
7 
8 #ifndef SWITCHVARIABLELINEAR_H_
9 #define SWITCHVARIABLELINEAR_H_
10 
11 #pragma once
12 
13 // DerivedValue2.h removed from gtsam repo (Dec 2018): https://github.com/borglab/gtsam/commit/e550f4f2aec423cb3f2791b81cb5858b8826ebac
14 #include "DerivedValue.h"
15 #include <gtsam/base/Lie.h>
16 
17 namespace vertigo {
18 
22  struct SwitchVariableLinear : public rtabmap::DerivedValue<SwitchVariableLinear> {
23 
25  SwitchVariableLinear() : d_(0.0) {};
26 
28  SwitchVariableLinear(double d) : d_(d) {
29  // if (d_ < 0.0) d_=0.0;
30  // else if(d_>1.0) d_=1.0;
31  };
32 
34  double value() const { return d_; }
35 
37  inline void print(const std::string& name="") const {
38  std::cout << name << ": " << d_ << std::endl;
39  }
40 
42  inline bool equals(const SwitchVariableLinear& expected, double tol=1e-5) const {
43  return fabs(expected.d_ - d_) <= tol;
44  }
45 
46  // Manifold requirements
47 
49  inline size_t dim() const { return 1; }
50  inline static size_t Dim() { return 1; }
51 
53  inline SwitchVariableLinear retract(const gtsam::Vector& v) const {
54  double x = value() + v(0);
55 
56  if (x>1.0) x=1.0;
57  else if (x<0.0) x=0.0;
58 
59  return SwitchVariableLinear(x);
60  }
61 
63  inline gtsam::Vector localCoordinates(const SwitchVariableLinear& t2) const { return gtsam::Vector1(t2.value() - value()); }
64 
65  // Group requirements
66 
68  inline static SwitchVariableLinear identity() {
69  return SwitchVariableLinear();
70  }
71 
74  return SwitchVariableLinear(d_ + p.d_);
75  }
76 
79  boost::optional<gtsam::Matrix&> H1=boost::none,
80  boost::optional<gtsam::Matrix&> H2=boost::none) const {
81  if(H1) *H1 = -gtsam::Matrix::Identity(1, 1);
82  if(H2) *H2 = gtsam::Matrix::Identity(1, 1);
83  return SwitchVariableLinear(l2.value() - value());
84  }
85 
87  inline SwitchVariableLinear inverse() const {
88  return SwitchVariableLinear(-1.0 * value());
89  }
90 
91  // Lie functions
92 
94  static inline SwitchVariableLinear Expmap(const gtsam::Vector& v) { return SwitchVariableLinear(v(0)); }
95 
97  static inline gtsam::Vector Logmap(const SwitchVariableLinear& p) { return gtsam::Vector1(p.value()); }
98 
99  private:
100  double d_;
101  };
102 }
103 
104 namespace gtsam {
105 // Define Key to be Testable by specializing gtsam::traits
106 template<typename T> struct traits;
107 template<> struct traits<vertigo::SwitchVariableLinear> {
108  static void Print(const vertigo::SwitchVariableLinear& key, const std::string& str = "") {
109  key.print(str);
110  }
111  static bool Equals(const vertigo::SwitchVariableLinear& key1, const vertigo::SwitchVariableLinear& key2, double tol = 1e-8) {
112  return key1.equals(key2, tol);
113  }
114  static int GetDimension(const vertigo::SwitchVariableLinear & key) {return key.Dim();}
115 
116  typedef OptionalJacobian<3, 3> ChartJacobian;
117  typedef gtsam::Vector TangentVector;
118  static TangentVector Local(const vertigo::SwitchVariableLinear& origin, const vertigo::SwitchVariableLinear& other,
119  ChartJacobian Horigin = boost::none, ChartJacobian Hother = boost::none) {
120  return origin.localCoordinates(other);
121  }
122  static vertigo::SwitchVariableLinear Retract(const vertigo::SwitchVariableLinear& g, const TangentVector& v,
123  ChartJacobian H1 = boost::none, ChartJacobian H2 = boost::none) {
124  return g.retract(v);
125  }
126 };
127 }
128 
129 
130 
131 #endif /* SWITCHVARIABLELINEAR_H_ */
void print(const std::string &name="") const
SwitchVariableLinear between(const SwitchVariableLinear &l2, boost::optional< gtsam::Matrix & > H1=boost::none, boost::optional< gtsam::Matrix & > H2=boost::none) const
bool equals(const SwitchVariableLinear &expected, double tol=1e-5) const
SwitchVariableLinear retract(const gtsam::Vector &v) const
GLM_FUNC_DECL genType e()
static gtsam::Vector Logmap(const SwitchVariableLinear &p)
SwitchVariableLinear compose(const SwitchVariableLinear &p) const
static vertigo::SwitchVariableLinear Retract(const vertigo::SwitchVariableLinear &g, const TangentVector &v, ChartJacobian H1=boost::none, ChartJacobian H2=boost::none)
static SwitchVariableLinear Expmap(const gtsam::Vector &v)
static void Print(const vertigo::SwitchVariableLinear &key, const std::string &str="")
static bool Equals(const vertigo::SwitchVariableLinear &key1, const vertigo::SwitchVariableLinear &key2, double tol=1e-8)
static int GetDimension(const vertigo::SwitchVariableLinear &key)
SwitchVariableLinear inverse() const
static SwitchVariableLinear identity()
gtsam::Vector localCoordinates(const SwitchVariableLinear &t2) const
static TangentVector Local(const vertigo::SwitchVariableLinear &origin, const vertigo::SwitchVariableLinear &other, ChartJacobian Horigin=boost::none, ChartJacobian Hother=boost::none)


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Dec 14 2020 03:37:06