60template <
typename R,
typename T>
86 : Base(model,
key), measured_(z), noiseModel_(model), func_(func) {}
91 NonlinearFactor::shared_ptr
clone()
const override {
92 return std::static_pointer_cast<NonlinearFactor>(
97#ifdef GTSAM_SLOW_BUT_CORRECT_BETWEENFACTOR
101 const R value = func_(params, &Hprojection);
105 *H = Hlocal * Hprojection;
110 R x = func_(params, H);
111 Vector
error = traits<R>::Local(measured_, x);
118 const std::string &s =
"",
121 std::cout << s << (s !=
"" ?
" " :
"") <<
"FunctorizedFactor("
122 << keyFormatter(this->key1()) <<
")" << std::endl;
124 std::cout <<
" noise model sigmas: " << noiseModel_->sigmas().transpose()
137#if GTSAM_ENABLE_BOOST_SERIALIZATION
139 friend class boost::serialization::access;
140 template <
class ARCHIVE>
141 void serialize(ARCHIVE &ar,
const unsigned int ) {
143 ar &boost::serialization::make_nvp(
144 "NoiseModelFactor1", boost::serialization::base_object<Base>(*
this));
145 ar &BOOST_SERIALIZATION_NVP(measured_);
146 ar &BOOST_SERIALIZATION_NVP(func_);
152template <
typename R,
typename T>
154 :
public Testable<FunctorizedFactor<R, T>> {};
162template <
typename T,
typename R,
typename FUNC>
178template <
typename R,
typename T1,
typename T2>
205 : Base(model, key1, key2),
213 NonlinearFactor::shared_ptr
clone()
const override {
214 return std::static_pointer_cast<NonlinearFactor>(
218 Vector evaluateError(
219 const T1 ¶ms1,
const T2 ¶ms2,
221#ifdef GTSAM_SLOW_BUT_CORRECT_BETWEENFACTOR
224 Matrix Hprojection1, Hprojection2;
225 const R value = func_(params1, params2,
226 H1 ? &Hprojection1 :
nullptr,
227 H2 ? &Hprojection2 :
nullptr);
231 if (H1) *H1 = Hlocal * Hprojection1;
232 if (H2) *H2 = Hlocal * Hprojection2;
237 R x = func_(params1, params2, H1, H2);
238 Vector
error = traits<R>::Local(measured_, x);
245 const std::string &s =
"",
248 std::cout << s << (s !=
"" ?
" " :
"") <<
"FunctorizedFactor2("
249 << keyFormatter(this->key1()) <<
", "
250 << keyFormatter(this->key2()) <<
")" << std::endl;
252 std::cout <<
" noise model sigmas: " << noiseModel_->sigmas().transpose()
265#if GTSAM_ENABLE_BOOST_SERIALIZATION
267 friend class boost::serialization::access;
268 template <
class ARCHIVE>
269 void serialize(ARCHIVE &ar,
const unsigned int ) {
271 ar &boost::serialization::make_nvp(
272 "NoiseModelFactor2", boost::serialization::base_object<Base>(*
this));
273 ar &BOOST_SERIALIZATION_NVP(measured_);
274 ar &BOOST_SERIALIZATION_NVP(func_);
280template <
typename R,
typename T1,
typename T2>
282 :
public Testable<FunctorizedFactor2<R, T1, T2>> {};
290template <
typename T1,
typename T2,
typename R,
typename FUNC>
Concept check for values that can be used in unit tests.
Base class and basic functions for Manifold types.
Base class for noise model factors with N variables.
Non-linear factor base classes.
#define OptionalNone
These typedefs and aliases will help with making the evaluateError interface independent of boost TOD...
Definition NonlinearFactor.h:51
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
FunctorizedFactor2< R, T1, T2 > MakeFunctorizedFactor2(Key key1, Key key2, const R &z, const SharedNoiseModel &model, const FUNC func)
Helper function to create a functorized factor.
Definition FunctorizedFactor.h:291
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
FunctorizedFactor< R, T > MakeFunctorizedFactor(Key key, const R &z, const SharedNoiseModel &model, const FUNC func)
Helper function to create a functorized factor.
Definition FunctorizedFactor.h:163
noiseModel::Base::shared_ptr SharedNoiseModel
Aliases.
Definition NoiseModel.h:846
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
Detect whether a traits type provides Local with Jacobians.
Definition Manifold.h:145
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
virtual void print(const std::string &s="Factor", const KeyFormatter &formatter=DefaultKeyFormatter) const
print
Definition Factor.cpp:29
bool equals(const This &other, double tol=1e-9) const
check equality
Definition Factor.cpp:42
virtual double error(const HybridValues &hybridValues) const
All factor types need to implement an error function.
Definition Factor.cpp:47
Factor which evaluates provided unary functor and uses the result to compute error with respect to th...
Definition FunctorizedFactor.h:61
FunctorizedFactor(Key key, const R &z, const SharedNoiseModel &model, const std::function< R(T, OptionalMatrixType)> func)
Construct with given x and the parameters of the basis.
Definition FunctorizedFactor.h:84
bool equals(const NonlinearFactor &other, double tol=1e-9) const override
Check if two factors are equal.
Definition FunctorizedFactor.h:128
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print
Definition FunctorizedFactor.h:117
FunctorizedFactor()
default constructor - only use for serialization
Definition FunctorizedFactor.h:75
NonlinearFactor::shared_ptr clone() const override
Definition FunctorizedFactor.h:91
Factor which evaluates provided binary functor and uses the result to compute error with respect to t...
Definition FunctorizedFactor.h:179
FunctorizedFactor2()
default constructor - only use for serialization
Definition FunctorizedFactor.h:194
NonlinearFactor::shared_ptr clone() const override
Definition FunctorizedFactor.h:213
FunctorizedFactor2(Key key1, Key key2, const R &z, const SharedNoiseModel &model, const FunctionType func)
Construct with given x and the parameters of the basis.
Definition FunctorizedFactor.h:203
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print
Definition FunctorizedFactor.h:244
bool equals(const NonlinearFactor &other, double tol=1e-9) const override
Check if two factors are equal.
Definition FunctorizedFactor.h:256
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
double error(const Values &c) const override
Calculate the error of the factor.
Definition NonlinearFactor.cpp:146