nonlinear/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 #include <string>
22 
23 namespace gtsam {
24 
29  template<class VALUE>
30  class PriorFactor: public NoiseModelFactor1<VALUE> {
31 
32  public:
33  typedef VALUE T;
34 
35  private:
36 
38 
39  VALUE prior_;
43 
44  public:
45 
47  typedef typename boost::shared_ptr<PriorFactor<VALUE> > shared_ptr;
48 
50  typedef PriorFactor<VALUE> This;
51 
54 
55  ~PriorFactor() override {}
56 
58  PriorFactor(Key key, const VALUE& prior, const SharedNoiseModel& model = nullptr) :
59  Base(model, key), prior_(prior) {
60  }
61 
63  PriorFactor(Key key, const VALUE& prior, const Matrix& covariance) :
64  Base(noiseModel::Gaussian::Covariance(covariance), key), prior_(prior) {
65  }
66 
69  return boost::static_pointer_cast<gtsam::NonlinearFactor>(
71 
75  void print(const std::string& s,
76  const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
77  std::cout << s << "PriorFactor on " << keyFormatter(this->key()) << "\n";
78  traits<T>::Print(prior_, " prior mean: ");
79  if (this->noiseModel_)
80  this->noiseModel_->print(" noise model: ");
81  else
82  std::cout << "no noise model" << std::endl;
83  }
84 
86  bool equals(const NonlinearFactor& expected, double tol=1e-9) const override {
87  const This* e = dynamic_cast<const This*> (&expected);
88  return e != nullptr && Base::equals(*e, tol) && traits<T>::Equals(prior_, e->prior_, tol);
89  }
90 
94  Vector evaluateError(const T& x, boost::optional<Matrix&> H = boost::none) const override {
95  if (H) (*H) = Matrix::Identity(traits<T>::GetDimension(x),traits<T>::GetDimension(x));
96  // manifold equivalent of z-x -> Local(x,z)
97  // TODO(ASL) Add Jacobians.
98  return -traits<T>::Local(x, prior_);
99  }
100 
101  const VALUE & prior() const { return prior_; }
102 
103  private:
104 
107  template<class ARCHIVE>
108  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
109  ar & boost::serialization::make_nvp("NoiseModelFactor1",
110  boost::serialization::base_object<Base>(*this));
111  ar & BOOST_SERIALIZATION_NVP(prior_);
112  }
113 
114  // Alignment, see https://eigen.tuxfamily.org/dox/group__TopicStructHavingEigenMembers.html
115  enum { NeedsToAlign = (sizeof(T) % 16) == 0 };
116  public:
118  };
119 
121  template<class VALUE>
122  struct traits<PriorFactor<VALUE> > : public Testable<PriorFactor<VALUE> > {};
123 
124 
125 }
NoiseModelFactor1< VALUE > Base
bool equals(const NonlinearFactor &f, double tol=1e-9) const override
Concept check for values that can be used in unit tests.
PriorFactor(Key key, const VALUE &prior, const Matrix &covariance)
noiseModel::Diagonal::shared_ptr model
Matrix expected
Definition: testMatrix.cpp:974
const VALUE & prior() const
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:43
PriorFactor(Key key, const VALUE &prior, const SharedNoiseModel &model=nullptr)
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate set rrange[*:*] noreverse nowriteback set trange[*:*] noreverse nowriteback set urange[*:*] noreverse nowriteback set vrange[*:*] noreverse nowriteback set xlabel matrix size set x2label set timefmt d m y n H
#define GTSAM_CONCEPT_TESTABLE_TYPE(T)
Definition: Testable.h:175
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
friend class boost::serialization::access
const SharedNoiseModel & noiseModel() const
access to the noise model
#define GTSAM_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign)
Definition: types.h:278
Eigen::VectorXd Vector
Definition: Vector.h:38
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
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
traits
Definition: chartTesting.h:28
boost::shared_ptr< Factor > shared_ptr
A shared_ptr to this class.
Definition: Factor.h:60
SharedNoiseModel noiseModel_
Non-linear factor base classes.
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
const G double tol
Definition: Group.h:83
Vector evaluateError(const T &x, boost::optional< Matrix & > H=boost::none) const override
PriorFactor< VALUE > This
Typedef to this class.
gtsam::NonlinearFactor::shared_ptr clone() const override
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61
void serialize(ARCHIVE &ar, const unsigned int)
void Print(const CONTAINER &keys, const string &s, const KeyFormatter &keyFormatter)
Definition: Key.cpp:59
void print(const std::string &s, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:734


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:43:29