gtsam  3.2.1
gtsam
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PriorFactor.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 
19 #include <gtsam/base/Testable.h>
20 
21 namespace gtsam {
22 
27  template<class VALUE>
28  class PriorFactor: public NoiseModelFactor1<VALUE> {
29 
30  public:
31  typedef VALUE T;
32 
33  private:
34 
36 
37  VALUE prior_;
40  GTSAM_CONCEPT_TESTABLE_TYPE(T)
41 
42  public:
43 
45  typedef typename boost::shared_ptr<PriorFactor<VALUE> > shared_ptr;
46 
49 
52 
53  virtual ~PriorFactor() {}
54 
56  PriorFactor(Key key, const VALUE& prior, const SharedNoiseModel& model) :
57  Base(model, key), prior_(prior) {
58  }
59 
61  virtual gtsam::NonlinearFactor::shared_ptr clone() const {
62  return boost::static_pointer_cast<gtsam::NonlinearFactor>(
63  gtsam::NonlinearFactor::shared_ptr(new This(*this))); }
64 
68  virtual void print(const std::string& s, const KeyFormatter& keyFormatter = DefaultKeyFormatter) const {
69  std::cout << s << "PriorFactor on " << keyFormatter(this->key()) << "\n";
70  prior_.print(" prior mean: ");
71  this->noiseModel_->print(" noise model: ");
72  }
73 
75  virtual bool equals(const NonlinearFactor& expected, double tol=1e-9) const {
76  const This* e = dynamic_cast<const This*> (&expected);
77  return e != NULL && Base::equals(*e, tol) && this->prior_.equals(e->prior_, tol);
78  }
79 
83  Vector evaluateError(const T& p, boost::optional<Matrix&> H = boost::none) const {
84  if (H) (*H) = eye(p.dim());
85  // manifold equivalent of h(x)-z -> log(z,h(x))
86  return prior_.localCoordinates(p);
87  }
88 
89  const VALUE & prior() const { return prior_; }
90 
91  private:
92 
95  template<class ARCHIVE>
96  void serialize(ARCHIVE & ar, const unsigned int version) {
97  ar & boost::serialization::make_nvp("NoiseModelFactor1",
98  boost::serialization::base_object<Base>(*this));
99  ar & BOOST_SERIALIZATION_NVP(prior_);
100  }
101  };
102 
103 }
Non-linear factor base classes.
virtual bool equals(const NonlinearFactor &f, double tol=1e-9) const
Check if two factors are equal.
Definition: NonlinearFactor.h:239
PriorFactor< VALUE > This
Typedef to this class.
Definition: PriorFactor.h:48
PriorFactor()
default constructor - only use for serialization
Definition: PriorFactor.h:51
virtual bool equals(const NonlinearFactor &expected, double tol=1e-9) const
equals
Definition: PriorFactor.h:75
Matrix eye(size_t m, size_t n)
Creates an identity matrix, with matlab-like syntax.
Definition: Matrix.cpp:50
PriorFactor(Key key, const VALUE &prior, const SharedNoiseModel &model)
Constructor.
Definition: PriorFactor.h:56
This is the base class for all factor types.
Definition: Factor.h:51
virtual gtsam::NonlinearFactor::shared_ptr clone() const
Definition: PriorFactor.h:61
Concept check for values that can be used in unit tests.
Vector evaluateError(const T &p, boost::optional< Matrix & > H=boost::none) const
implement functions needed to derive from Factor
Definition: PriorFactor.h:83
size_t Key
Integer nonlinear key type.
Definition: types.h:59
friend class boost::serialization::access
Serialization function.
Definition: PriorFactor.h:94
A convenient base class for creating your own NoiseModelFactor with 1 variable.
Definition: NonlinearFactor.h:354
virtual void print(const std::string &s, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
implement functions needed for Testable
Definition: PriorFactor.h:68
boost::shared_ptr< PriorFactor< VALUE > > shared_ptr
The measurement.
Definition: PriorFactor.h:45
noiseModel::Base::shared_ptr SharedNoiseModel
Note, deliberately not in noiseModel namespace.
Definition: NoiseModel.h:884
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
Definition: PriorFactor.h:28