BetweenFactor.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
16 #pragma once
17 
18 #include <ostream>
19 
20 #include <gtsam/base/Testable.h>
21 #include <gtsam/base/Lie.h>
23 
24 #ifdef _WIN32
25 #define BETWEENFACTOR_VISIBILITY
26 #else
27 // This will trigger a LNKxxxx on MSVC, so disable for MSVC build
28 // Please refer to https://github.com/borglab/gtsam/blob/develop/Using-GTSAM-EXPORT.md
29 #define BETWEENFACTOR_VISIBILITY GTSAM_EXPORT
30 #endif
31 
32 namespace gtsam {
33 
39  template<class VALUE>
40  class BetweenFactor: public NoiseModelFactor2<VALUE, VALUE> {
41 
42  // Check that VALUE type is a testable Lie group
45 
46  public:
47 
48  typedef VALUE T;
49 
50  private:
51 
54 
55  VALUE measured_;
57  public:
58 
59  // shorthand for a smart pointer to a factor
60  typedef typename boost::shared_ptr<BetweenFactor> shared_ptr;
61 
64 
67  const SharedNoiseModel& model = nullptr) :
68  Base(model, key1, key2), measured_(measured) {
69  }
70 
71  ~BetweenFactor() override {}
72 
75  return boost::static_pointer_cast<gtsam::NonlinearFactor>(
77 
81 
83  void print(const std::string& s, const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
84  std::cout << s << "BetweenFactor("
85  << keyFormatter(this->key1()) << ","
86  << keyFormatter(this->key2()) << ")\n";
87  traits<T>::Print(measured_, " measured: ");
88  this->noiseModel_->print(" noise model: ");
89  }
90 
92  bool equals(const NonlinearFactor& expected, double tol=1e-9) const override {
93  const This *e = dynamic_cast<const This*> (&expected);
94  return e != nullptr && Base::equals(*e, tol) && traits<T>::Equals(this->measured_, e->measured_, tol);
95  }
96 
100 
102  Vector evaluateError(const T& p1, const T& p2, boost::optional<Matrix&> H1 =
103  boost::none, boost::optional<Matrix&> H2 = boost::none) const override {
104  T hx = traits<T>::Between(p1, p2, H1, H2); // h(x)
105  // manifold equivalent of h(x)-z -> log(z,h(x))
106 #ifdef SLOW_BUT_CORRECT_BETWEENFACTOR
107  typename traits<T>::ChartJacobian::Jacobian Hlocal;
108  Vector rval = traits<T>::Local(measured_, hx, boost::none, (H1 || H2) ? &Hlocal : 0);
109  if (H1) *H1 = Hlocal * (*H1);
110  if (H2) *H2 = Hlocal * (*H2);
111  return rval;
112 #else
113  return traits<T>::Local(measured_, hx);
114 #endif
115  }
116 
120 
122  const VALUE& measured() const {
123  return measured_;
124  }
126 
127  private:
128 
131  template<class ARCHIVE>
132  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
133  ar & boost::serialization::make_nvp("NoiseModelFactor2",
134  boost::serialization::base_object<Base>(*this));
135  ar & BOOST_SERIALIZATION_NVP(measured_);
136  }
137 
138  // Alignment, see https://eigen.tuxfamily.org/dox/group__TopicStructHavingEigenMembers.html
139  enum { NeedsToAlign = (sizeof(VALUE) % 16) == 0 };
140  public:
142  }; // \class BetweenFactor
143 
145  template<class VALUE>
146  struct traits<BetweenFactor<VALUE> > : public Testable<BetweenFactor<VALUE> > {};
147 
153  template<class VALUE>
154  class BetweenConstraint : public BetweenFactor<VALUE> {
155  public:
156  typedef boost::shared_ptr<BetweenConstraint<VALUE> > shared_ptr;
157 
159  BetweenConstraint(const VALUE& measured, Key key1, Key key2, double mu = 1000.0) :
160  BetweenFactor<VALUE>(key1, key2, measured,
161  noiseModel::Constrained::All(traits<VALUE>::GetDimension(measured), std::abs(mu)))
162  {}
163 
164  private:
165 
167  friend class boost::serialization::access;
168  template<class ARCHIVE>
169  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
170  ar & boost::serialization::make_nvp("BetweenFactor",
171  boost::serialization::base_object<BetweenFactor<VALUE> >(*this));
172  }
173  }; // \class BetweenConstraint
174 
176  template<class VALUE>
177  struct traits<BetweenConstraint<VALUE> > : public Testable<BetweenConstraint<VALUE> > {};
178 
179 }
void serialize(ARCHIVE &ar, const unsigned int)
bool equals(const NonlinearFactor &f, double tol=1e-9) const override
Concept check for values that can be used in unit tests.
~BetweenFactor() override
Definition: BetweenFactor.h:71
Vector3f p1
noiseModel::Diagonal::shared_ptr model
Matrix expected
Definition: testMatrix.cpp:974
double mu
boost::shared_ptr< BetweenConstraint< VALUE > > shared_ptr
Definition: Half.h:150
const VALUE & measured() const
return the measurement
void serialize(ARCHIVE &ar, const unsigned int)
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
const SharedNoiseModel & noiseModel() const
access to the noise model
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: BetweenFactor.h:74
#define GTSAM_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign)
Definition: types.h:278
boost::shared_ptr< BetweenFactor > shared_ptr
Definition: BetweenFactor.h:60
Eigen::VectorXd Vector
Definition: Vector.h:38
BetweenConstraint(const VALUE &measured, Key key1, Key key2, double mu=1000.0)
boost::shared_ptr< This > shared_ptr
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:35
BetweenFactor< Rot3 > Between
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
Base class and basic functions for Lie types.
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
assert equality up to a tolerance
Definition: BetweenFactor.h:92
traits
Definition: chartTesting.h:28
BOOST_CONCEPT_ASSERT((IsTestable< VALUE >))
SharedNoiseModel noiseModel_
Non-linear factor base classes.
friend class boost::serialization::access
void print(const std::string &s, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print with optional string
Definition: BetweenFactor.h:83
NoiseModelFactor2< VALUE, VALUE > Base
Definition: BetweenFactor.h:53
BetweenFactor< VALUE > This
Definition: BetweenFactor.h:52
static Point3 p2
const G double tol
Definition: Group.h:83
Vector evaluateError(const T &p1, const T &p2, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const override
evaluate error, returns vector of errors size of tangent space
#define abs(x)
Definition: datatypes.h:17
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61
void Print(const CONTAINER &keys, const string &s, const KeyFormatter &keyFormatter)
Definition: Key.cpp:59
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:734
BetweenFactor(Key key1, Key key2, const VALUE &measured, const SharedNoiseModel &model=nullptr)
Definition: BetweenFactor.h:66


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:41:42