gtsam
Loading...
Searching...
No Matches
PosePriorFactor.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>
23
24namespace gtsam {
25
30 template<class POSE>
31 class PosePriorFactor: public NoiseModelFactorN<POSE> {
32
33 private:
34
35 typedef PosePriorFactor<POSE> This;
36 typedef NoiseModelFactorN<POSE> Base;
37
38 POSE prior_;
39 std::optional<POSE> body_P_sensor_;
40
42 GTSAM_CONCEPT_TESTABLE_TYPE(POSE)
43 GTSAM_CONCEPT_POSE_TYPE(POSE)
44 public:
45
46 // Provide access to the Matrix& version of evaluateError:
48
50 typedef typename std::shared_ptr<PosePriorFactor<POSE> > shared_ptr;
51
54
55 ~PosePriorFactor() override {}
56
58 PosePriorFactor(Key key, const POSE& prior, const SharedNoiseModel& model,
59 std::optional<POSE> body_P_sensor = {}) :
60 Base(model, key), prior_(prior), body_P_sensor_(body_P_sensor) {
61 }
62
64 gtsam::NonlinearFactor::shared_ptr clone() const override {
65 return std::static_pointer_cast<gtsam::NonlinearFactor>(
66 gtsam::NonlinearFactor::shared_ptr(new This(*this))); }
67
69
71 void print(const std::string& s, const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
72 std::cout << s << "PriorFactor on " << keyFormatter(this->key()) << "\n";
73 prior_.print(" prior mean: ");
74 if(this->body_P_sensor_)
75 this->body_P_sensor_->print(" sensor pose in body frame: ");
76 this->noiseModel_->print(" noise model: ");
77 }
78
80 bool equals(const NonlinearFactor& expected, double tol=1e-9) const override {
81 const This* e = dynamic_cast<const This*> (&expected);
82 return e != nullptr
83 && Base::equals(*e, tol)
84 && this->prior_.equals(e->prior_, tol)
85 && ((!body_P_sensor_ && !e->body_P_sensor_) || (body_P_sensor_ && e->body_P_sensor_ && body_P_sensor_->equals(*e->body_P_sensor_)));
86 }
87
89
91 Vector evaluateError(const POSE& p, OptionalMatrixType H) const override {
92 if(body_P_sensor_) {
93 // manifold equivalent of h(x)-z -> log(z,h(x))
94 return prior_.localCoordinates(p.compose(*body_P_sensor_, H));
95 } else {
96 if(H) (*H) = I_6x6;
97 // manifold equivalent of h(x)-z -> log(z,h(x))
98 return prior_.localCoordinates(p);
99 }
100 }
101
102 const POSE& prior() const { return prior_; }
103
104 private:
105
106#if GTSAM_ENABLE_BOOST_SERIALIZATION
108 friend class boost::serialization::access;
109 template<class ARCHIVE>
110 void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
111 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
112 ar & BOOST_SERIALIZATION_NVP(prior_);
113 ar & BOOST_SERIALIZATION_NVP(body_P_sensor_);
114 }
115#endif
116 };
117
118}
Macros for Matrix constants to avoid excessive template instantiation.
Concept check for values that can be used in unit tests.
Base class for noise model factors with N variables.
Non-linear factor base classes.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
Matrix * OptionalMatrixType
This typedef will be used everywhere boost::optional<Matrix&> reference was used previously.
Definition NonlinearFactor.h:57
NoiseModelFactorT< Vector, ValueTypes... > NoiseModelFactorN
Noise model factor with N value types and dynamic-sized error vector.
Definition NoiseModelFactorN.h:561
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
noiseModel::Base::shared_ptr SharedNoiseModel
Aliases.
Definition NoiseModel.h:846
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
bool equals(const This &other, double tol=1e-9) const
check equality
Definition Factor.cpp:42
virtual Vector evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const=0
Key key() const
Definition NoiseModelFactorN.h:307
Nonlinear factor base class.
Definition NonlinearFactor.h:70
A class for a soft prior on any Value type.
Definition PosePriorFactor.h:31
PosePriorFactor(Key key, const POSE &prior, const SharedNoiseModel &model, std::optional< POSE > body_P_sensor={})
Constructor.
Definition PosePriorFactor.h:58
void print(const std::string &s, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
implement functions needed for Testable
Definition PosePriorFactor.h:71
PosePriorFactor()
default constructor - only use for serialization
Definition PosePriorFactor.h:53
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
equals
Definition PosePriorFactor.h:80
std::shared_ptr< PosePriorFactor< POSE > > shared_ptr
shorthand for a smart pointer to a factor
Definition PosePriorFactor.h:50
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition PosePriorFactor.h:64
Vector evaluateError(const POSE &p, OptionalMatrixType H) const override
implement functions needed to derive from Factor
Definition PosePriorFactor.h:91
Concept-checking macros for geometric objects Each macro instantiates a concept check structure,...