gtsam  4.0.0
gtsam
AntiFactor.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 
18 #include <ostream>
19 
22 
23 namespace gtsam {
24 
31  class AntiFactor: public NonlinearFactor {
32 
33  private:
34 
35  typedef AntiFactor This;
36  typedef NonlinearFactor Base;
37  typedef NonlinearFactor::shared_ptr sharedFactor;
38 
39  sharedFactor factor_;
40 
41  public:
42 
43  // shorthand for a smart pointer to a factor
44  typedef boost::shared_ptr<AntiFactor> shared_ptr;
45 
48 
50  AntiFactor(NonlinearFactor::shared_ptr factor) : Base(factor->keys()), factor_(factor) {}
51 
52  virtual ~AntiFactor() {}
53 
55  virtual gtsam::NonlinearFactor::shared_ptr clone() const {
56  return boost::static_pointer_cast<gtsam::NonlinearFactor>(
57  gtsam::NonlinearFactor::shared_ptr(new This(*this))); }
58 
62  virtual void print(const std::string& s, const KeyFormatter& keyFormatter = DefaultKeyFormatter) const {
63  std::cout << s << "AntiFactor version of:" << std::endl;
64  factor_->print(s, keyFormatter);
65  }
66 
68  virtual bool equals(const NonlinearFactor& expected, double tol=1e-9) const {
69  const This *e = dynamic_cast<const This*> (&expected);
70  return e != NULL && Base::equals(*e, tol) && this->factor_->equals(*e->factor_, tol);
71  }
72 
80  double error(const Values& c) const { return -factor_->error(c); }
81 
83  size_t dim() const { return factor_->dim(); }
84 
89  bool active(const Values& c) const { return factor_->active(c); }
90 
97  boost::shared_ptr<GaussianFactor> linearize(const Values& c) const {
98 
99  // Generate the linearized factor from the contained nonlinear factor
100  GaussianFactor::shared_ptr gaussianFactor = factor_->linearize(c);
101 
102  // return the negated version of the factor
103  return gaussianFactor->negate();
104  }
105 
106 
107  private:
108 
111  template<class ARCHIVE>
112  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
113  ar & boost::serialization::make_nvp("AntiFactor",
114  boost::serialization::base_object<Base>(*this));
115  ar & BOOST_SERIALIZATION_NVP(factor_);
116  }
117  }; // \class AntiFactor
118 
119 }
This is the base class for all factor types.
Definition: Factor.h:54
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:70
friend class boost::serialization::access
Serialization function.
Definition: AntiFactor.h:110
virtual bool equals(const NonlinearFactor &expected, double tol=1e-9) const
equals
Definition: AntiFactor.h:68
virtual bool equals(const NonlinearFactor &f, double tol=1e-9) const
Check if two factors are equal.
Definition: NonlinearFactor.cpp:36
boost::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:33
Nonlinear factor base class.
Definition: NonlinearFactor.h:50
boost::shared_ptr< GaussianFactor > linearize(const Values &c) const
Linearize to a GaussianFactor.
Definition: AntiFactor.h:97
Definition: AntiFactor.h:31
size_t dim() const
get the dimension of the factor (same as the original factor)
Definition: AntiFactor.h:83
AntiFactor()
default constructor - only use for serialization
Definition: AntiFactor.h:47
bool active(const Values &c) const
Checks whether this factor should be used based on a set of values.
Definition: AntiFactor.h:89
Non-linear factor base classes.
virtual void print(const std::string &s, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
implement functions needed for Testable
Definition: AntiFactor.h:62
A factor with a quadratic error function - a Gaussian.
double error(const Values &c) const
implement functions needed to derive from Factor
Definition: AntiFactor.h:80
const KeyVector & keys() const
Access the factor's involved variable keys.
Definition: Factor.h:118
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
AntiFactor(NonlinearFactor::shared_ptr factor)
constructor - Creates the equivalent AntiFactor from an existing factor
Definition: AntiFactor.h:50
virtual gtsam::NonlinearFactor::shared_ptr clone() const
Definition: AntiFactor.h:55
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: GaussianFactor.h:42