Loading...
Searching...
No Matches
AntiFactor.h
Go to the documentation of this file.
/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
* -------------------------------------------------------------------------- */
#pragma once
#include <ostream>
#include <gtsam/nonlinear/NonlinearFactor.h>
#include <gtsam/linear/GaussianFactor.h>
namespace gtsam {
class AntiFactor: public NonlinearFactor {
private:
typedef AntiFactor This;
typedef NonlinearFactor Base;
typedef NonlinearFactor::shared_ptr sharedFactor;
sharedFactor factor_;
public:
// shorthand for a smart pointer to a factor
typedef boost::shared_ptr<AntiFactor> shared_ptr;
AntiFactor() {}
AntiFactor(NonlinearFactor::shared_ptr factor) : Base(factor->keys()), factor_(factor) {}
~AntiFactor() override {}
gtsam::NonlinearFactor::shared_ptr clone() const override {
return boost::static_pointer_cast<gtsam::NonlinearFactor>(
gtsam::NonlinearFactor::shared_ptr(new This(*this))); }
void print(const std::string& s, const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
std::cout << s << "AntiFactor version of:" << std::endl;
factor_->print(s, keyFormatter);
}
bool equals(const NonlinearFactor& expected, double tol=1e-9) const override {
const This *e = dynamic_cast<const This*> (&expected);
return e != nullptr && Base::equals(*e, tol) && this->factor_->equals(*e->factor_, tol);
}
double error(const Values& c) const override { return -factor_->error(c); }
size_t dim() const override { return factor_->dim(); }
bool active(const Values& c) const override { return factor_->active(c); }
boost::shared_ptr<GaussianFactor> linearize(const Values& c) const override {
// Generate the linearized factor from the contained nonlinear factor
GaussianFactor::shared_ptr gaussianFactor = factor_->linearize(c);
// return the negated version of the factor
return gaussianFactor->negate();
}
private:
friend class boost::serialization::access;
template<class ARCHIVE>
void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
ar & boost::serialization::make_nvp("AntiFactor",
boost::serialization::base_object<Base>(*this));
ar & BOOST_SERIALIZATION_NVP(factor_);
}
}; // \class AntiFactor
}
GaussianFactor.h
A factor with a quadratic error function - a Gaussian.
NonlinearFactor.h
Non-linear factor base classes.
gtsam
Global functions in a separate testing namespace.
Definition chartTesting.h:28
gtsam::KeyFormatter
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
gtsam::Factor::keys
const KeyVector & keys() const
Access the factor's involved variable keys.
Definition Factor.h:140
gtsam::GaussianFactor::shared_ptr
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition GaussianFactor.h:42
gtsam::NonlinearFactor::equals
virtual bool equals(const NonlinearFactor &f, double tol=1e-9) const
Check if two factors are equal.
Definition NonlinearFactor.cpp:47
gtsam::NonlinearFactor::NonlinearFactor
NonlinearFactor()
Default constructor for I/O only.
Definition NonlinearFactor.h:58
gtsam::Values
A non-templated config holding any types of Manifold-group elements.
Definition Values.h:65
gtsam::AntiFactor
A class for downdating an existing factor from a graph.
Definition AntiFactor.h:31
gtsam::AntiFactor::AntiFactor
AntiFactor(NonlinearFactor::shared_ptr factor)
constructor - Creates the equivalent AntiFactor from an existing factor
Definition AntiFactor.h:50
gtsam::AntiFactor::equals
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
equals
Definition AntiFactor.h:68
gtsam::AntiFactor::AntiFactor
AntiFactor()
default constructor - only use for serialization
Definition AntiFactor.h:47
gtsam::AntiFactor::linearize
boost::shared_ptr< GaussianFactor > linearize(const Values &c) const override
Linearize to a GaussianFactor.
Definition AntiFactor.h:97
gtsam::AntiFactor::active
bool active(const Values &c) const override
Checks whether this factor should be used based on a set of values.
Definition AntiFactor.h:89
gtsam::AntiFactor::dim
size_t dim() const override
get the dimension of the factor (same as the original factor)
Definition AntiFactor.h:83
gtsam::AntiFactor::print
void print(const std::string &s, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
implement functions needed for Testable
Definition AntiFactor.h:62
gtsam::AntiFactor::error
double error(const Values &c) const override
implement functions needed to derive from Factor
Definition AntiFactor.h:80
gtsam::AntiFactor::clone
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition AntiFactor.h:55
gtsam::AntiFactor::access
friend class boost::serialization::access
Serialization function.
Definition AntiFactor.h:110