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 #include <gtsam/base/DerivedValue.h>
14 #include <gtsam/base/Lie.h>
15 
16 namespace vertigo {
17 
21  struct SwitchVariableLinear : public gtsam::DerivedValue<SwitchVariableLinear> {
22 
24  SwitchVariableLinear() : d_(0.0) {};
25 
27  SwitchVariableLinear(double d) : d_(d) {
28  // if (d_ < 0.0) d_=0.0;
29  // else if(d_>1.0) d_=1.0;
30  };
31 
33  double value() const { return d_; }
34 
36  inline void print(const std::string& name="") const {
37  std::cout << name << ": " << d_ << std::endl;
38  }
39 
41  inline bool equals(const SwitchVariableLinear& expected, double tol=1e-5) const {
42  return fabs(expected.d_ - d_) <= tol;
43  }
44 
45  // Manifold requirements
46 
48  inline size_t dim() const { return 1; }
49  inline static size_t Dim() { return 1; }
50 
52  inline SwitchVariableLinear retract(const gtsam::Vector& v) const {
53  double x = value() + v(0);
54 
55  if (x>1.0) x=1.0;
56  else if (x<0.0) x=0.0;
57 
58  return SwitchVariableLinear(x);
59  }
60 
62  inline gtsam::Vector localCoordinates(const SwitchVariableLinear& t2) const { return gtsam::Vector1(t2.value() - value()); }
63 
64  // Group requirements
65 
67  inline static SwitchVariableLinear identity() {
68  return SwitchVariableLinear();
69  }
70 
73  return SwitchVariableLinear(d_ + p.d_);
74  }
75 
78  boost::optional<gtsam::Matrix&> H1=boost::none,
79  boost::optional<gtsam::Matrix&> H2=boost::none) const {
80  if(H1) *H1 = -gtsam::eye(1);
81  if(H2) *H2 = gtsam::eye(1);
82  return SwitchVariableLinear(l2.value() - value());
83  }
84 
86  inline SwitchVariableLinear inverse() const {
87  return SwitchVariableLinear(-1.0 * value());
88  }
89 
90  // Lie functions
91 
93  static inline SwitchVariableLinear Expmap(const gtsam::Vector& v) { return SwitchVariableLinear(v(0)); }
94 
96  static inline gtsam::Vector Logmap(const SwitchVariableLinear& p) { return gtsam::Vector1(p.value()); }
97 
98  private:
99  double d_;
100  };
101 }
102 
103 namespace gtsam {
104 // Define Key to be Testable by specializing gtsam::traits
105 template<typename T> struct traits;
106 template<> struct traits<vertigo::SwitchVariableLinear> {
107  static void Print(const vertigo::SwitchVariableLinear& key, const std::string& str = "") {
108  key.print(str);
109  }
110  static bool Equals(const vertigo::SwitchVariableLinear& key1, const vertigo::SwitchVariableLinear& key2, double tol = 1e-8) {
111  return key1.equals(key2, tol);
112  }
113  static int GetDimension(const vertigo::SwitchVariableLinear & key) {return key.Dim();}
114 
115  typedef OptionalJacobian<3, 3> ChartJacobian;
116  typedef gtsam::Vector TangentVector;
117  static TangentVector Local(const vertigo::SwitchVariableLinear& origin, const vertigo::SwitchVariableLinear& other,
118  ChartJacobian Horigin = boost::none, ChartJacobian Hother = boost::none) {
119  return origin.localCoordinates(other);
120  }
121  static vertigo::SwitchVariableLinear Retract(const vertigo::SwitchVariableLinear& g, const TangentVector& v,
122  ChartJacobian H1 = boost::none, ChartJacobian H2 = boost::none) {
123  return g.retract(v);
124  }
125 };
126 }
127 
128 
129 
130 #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 Wed Jun 5 2019 22:43:40