gtsam
Loading...
Searching...
No Matches
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
20namespace gtsam {
21
35template <class VALUE>
36class PriorFactor : public ExtendedPriorFactor<VALUE> {
37 public:
38 typedef VALUE T;
39 typedef ExtendedPriorFactor<VALUE> Base;
40
41 private:
43 GTSAM_CONCEPT_TESTABLE_TYPE(T)
44
45 public:
48
50 typedef typename std::shared_ptr<PriorFactor<VALUE>> shared_ptr;
51
54
57
59 PriorFactor(Key key, const VALUE& prior,
60 const SharedNoiseModel& model = nullptr)
61 : Base(key, prior, noiseModel::validOrDefault(prior, model)) {}
62
64 PriorFactor(Key key, const VALUE& prior, const Matrix& covariance)
65 : Base(key, prior, noiseModel::Gaussian::Covariance(covariance)) {}
66
70
71 ~PriorFactor() override {}
72
76
78 gtsam::NonlinearFactor::shared_ptr clone() const override {
79 return std::static_pointer_cast<gtsam::NonlinearFactor>(
80 gtsam::NonlinearFactor::shared_ptr(new This(*this)));
81 }
82
84 void print(const std::string& s, const KeyFormatter& keyFormatter =
85 DefaultKeyFormatter) const override {
86 std::cout << s << "PriorFactor on " << keyFormatter(this->key()) << "\n";
87 traits<T>::Print(this->origin(), " prior mean: ");
88 if (this->noiseModel_)
89 this->noiseModel_->print(" noise model: ");
90 else
91 std::cout << "no noise model" << std::endl;
92 }
93
95 bool equals(const NonlinearFactor& expected,
96 double tol = 1e-9) const override {
97 const auto* e = dynamic_cast<const This*>(&expected);
98 return e && Base::equals(*e, tol);
99 }
100
104
105 const VALUE& prior() const { return this->origin(); }
106
108
109 private:
110#if GTSAM_ENABLE_BOOST_SERIALIZATION
112 friend class boost::serialization::access;
113 template <class ARCHIVE>
114 void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
115 // For backwards compatibility, we manually serialize the base class members
116 // as if we were a PriorFactor from before the refactor.
117 ar& boost::serialization::make_nvp(
118 "NoiseModelFactor1",
119 boost::serialization::base_object<NoiseModelFactorN<VALUE>>(*this));
120 ar& boost::serialization::make_nvp("prior_", this->origin_);
121 }
122#endif
123};
124
126template <class VALUE>
127struct traits<PriorFactor<VALUE>> : public Testable<PriorFactor<VALUE>> {};
128
129} // namespace gtsam
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
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
All noise models live in the noiseModel namespace.
Definition LossFunctions.cpp:33
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
equals
Definition ExtendedPriorFactor.h:125
std::optional< Matrix > covariance(const std::string &method="<unknown>", bool throwOnFailure=false) const
Get Gaussian covariance, or return nullopt/throw if not Gaussian.
Definition ExtendedPriorFactor.h:217
std::pair< Vector, Matrix > Gaussian
Simple, non-templated Gaussian fusion in a common tangent space.
Definition ExtendedPriorFactor.h:225
ExtendedPriorFactor()
default constructor - only use for serialization
Definition ExtendedPriorFactor.h:67
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 PriorFactor.h:36
PriorFactor< VALUE > This
Typedef to this class.
Definition PriorFactor.h:53
PriorFactor()
default constructor - only use for serialization
Definition PriorFactor.h:56
PriorFactor(Key key, const VALUE &prior, const Matrix &covariance)
Convenience constructor that takes a full covariance argument.
Definition PriorFactor.h:64
void print(const std::string &s, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print
Definition PriorFactor.h:84
std::shared_ptr< PriorFactor< VALUE > > shared_ptr
shorthand for a smart pointer to a factor
Definition PriorFactor.h:50
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
equals
Definition PriorFactor.h:95
PriorFactor(Key key, const VALUE &prior, const SharedNoiseModel &model=nullptr)
Constructor.
Definition PriorFactor.h:59
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition PriorFactor.h:78