gtsam  3.2.1
gtsam
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ReferenceFrameFactor.h
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 
12 /*
13  * @file ReferenceFrameFactor.h
14  * @brief A constraint for combining graphs by common landmarks and a transform node
15  * @author Alex Cunningham
16  */
17 
18 #pragma once
19 
21 
22 namespace gtsam {
23 
29 template<class T, class P>
31  const T& trans, const P& global,
32  boost::optional<Matrix&> Dtrans,
33  boost::optional<Matrix&> Dglobal) {
34  return trans.transform_from(global, Dtrans, Dglobal);
35 }
36 
56 template<class POINT, class TRANSFORM>
57 class ReferenceFrameFactor : public NoiseModelFactor3<POINT, TRANSFORM, POINT> {
58 protected:
61 
62 public:
65 
66  typedef POINT Point;
67  typedef TRANSFORM Transform;
68 
72  ReferenceFrameFactor(Key globalKey, Key transKey, Key localKey, const noiseModel::Base::shared_ptr& model)
73  : Base(model,globalKey, transKey, localKey) {}
74 
79  ReferenceFrameFactor(double mu, Key globalKey, Key transKey, Key localKey)
80  : Base(globalKey, transKey, localKey, Point().dim(), mu) {}
81 
86  ReferenceFrameFactor(Key globalKey, Key transKey, Key localKey, double sigma = 1e-2)
87  : Base(noiseModel::Isotropic::Sigma(POINT().dim(), sigma),
88  globalKey, transKey, localKey) {}
89 
90  virtual ~ReferenceFrameFactor(){}
91 
92  virtual NonlinearFactor::shared_ptr clone() const {
93  return boost::static_pointer_cast<NonlinearFactor>(
94  NonlinearFactor::shared_ptr(new This(*this))); }
95 
97  virtual Vector evaluateError(const Point& global, const Transform& trans, const Point& local,
98  boost::optional<Matrix&> Dforeign = boost::none,
99  boost::optional<Matrix&> Dtrans = boost::none,
100  boost::optional<Matrix&> Dlocal = boost::none) const {
101  Point newlocal = transform_point<Transform,Point>(trans, global, Dtrans, Dforeign);
102  if (Dlocal) {
103  Point dummy;
104  *Dlocal = -1* gtsam::eye(dummy.dim());
105  }
106  return local.localCoordinates(newlocal);
107  }
108 
109  virtual void print(const std::string& s="",
110  const gtsam::KeyFormatter& keyFormatter = DefaultKeyFormatter) const {
111  std::cout << s << ": ReferenceFrameFactor("
112  << "Global: " << keyFormatter(this->key1()) << ","
113  << " Transform: " << keyFormatter(this->key2()) << ","
114  << " Local: " << keyFormatter(this->key3()) << ")\n";
115  this->noiseModel_->print(" noise model");
116  }
117 
118  // access - convenience functions
119  Key global_key() const { return this->key1(); }
120  Key transform_key() const { return this->key2(); }
121  Key local_key() const { return this->key3(); }
122 
123 private:
126  template<class ARCHIVE>
127  void serialize(ARCHIVE & ar, const unsigned int version) {
128  ar & boost::serialization::make_nvp("NonlinearFactor3",
129  boost::serialization::base_object<Base>(*this));
130  }
131 };
132 
133 } // \namespace gtsam
Non-linear factor base classes.
P transform_point(const T &trans, const P &global, boost::optional< Matrix & > Dtrans, boost::optional< Matrix & > Dglobal)
Transform function that must be specialized specific domains.
Definition: ReferenceFrameFactor.h:30
virtual size_t dim() const
get the dimension of the factor (number of rows on linearization)
Definition: NonlinearFactor.h:247
Matrix eye(size_t m, size_t n)
Creates an identity matrix, with matlab-like syntax.
Definition: Matrix.cpp:50
Matrix trans(const Matrix &A)
static transpose function, just calls Eigen transpose member function
Definition: Matrix.h:279
friend class boost::serialization::access
Serialization function.
Definition: ReferenceFrameFactor.h:125
This is the base class for all factor types.
Definition: Factor.h:51
virtual void print(const std::string &s="", const gtsam::KeyFormatter &keyFormatter=DefaultKeyFormatter) const
Print.
Definition: ReferenceFrameFactor.h:109
ReferenceFrameFactor(Key globalKey, Key transKey, Key localKey, double sigma=1e-2)
Simple soft constraint constructor for frame of reference, with equal weighting for each degree of fr...
Definition: ReferenceFrameFactor.h:86
ReferenceFrameFactor(double mu, Key globalKey, Key transKey, Key localKey)
Construct a hard frame of reference reference constraint with equal mu values for each degree of free...
Definition: ReferenceFrameFactor.h:79
size_t Key
Integer nonlinear key type.
Definition: types.h:59
ReferenceFrameFactor(Key globalKey, Key transKey, Key localKey, const noiseModel::Base::shared_ptr &model)
General constructor with arbitrary noise model (constrained or otherwise)
Definition: ReferenceFrameFactor.h:72
A constraint between two landmarks in separate maps Templated on: Point : Type of landmark Transform ...
Definition: ReferenceFrameFactor.h:57
Key key1() const
methods to retrieve keys
Definition: NonlinearFactor.h:532
virtual NonlinearFactor::shared_ptr clone() const
Create a symbolic factor using the given ordering to determine the variable indices.
Definition: ReferenceFrameFactor.h:92
ReferenceFrameFactor()
default constructor for serialization only
Definition: ReferenceFrameFactor.h:60
virtual Vector evaluateError(const Point &global, const Transform &trans, const Point &local, boost::optional< Matrix & > Dforeign=boost::none, boost::optional< Matrix & > Dtrans=boost::none, boost::optional< Matrix & > Dlocal=boost::none) const
Combined cost and derivative function using boost::optional.
Definition: ReferenceFrameFactor.h:97
Nonlinear factor base class.
Definition: NonlinearFactor.h:54
boost::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: types.h:62
A convenient base class for creating your own NoiseModelFactor with 3 variables.
Definition: NonlinearFactor.h:498