Factor.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 
20 // \callgraph
21 
22 #pragma once
23 
24 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
25 #include <boost/serialization/nvp.hpp>
26 #endif
27 #include <memory>
28 
29 #include <gtsam/base/types.h>
30 #include <gtsam/base/FastVector.h>
31 #include <gtsam/inference/Key.h>
32 
33 namespace gtsam {
34 
38 
39  class HybridValues; // forward declaration of a Value type for error.
40 
69  class GTSAM_EXPORT Factor
70  {
71 
72  private:
73  // These typedefs are private because they must be overridden in derived classes.
74  typedef Factor This;
75  typedef std::shared_ptr<Factor> shared_ptr;
76 
77  public:
79  typedef KeyVector::iterator iterator;
80 
82  typedef KeyVector::const_iterator const_iterator;
83 
84  protected:
85 
88 
91 
93  Factor() {}
94 
97  template<typename CONTAINER>
98  explicit Factor(const CONTAINER& keys) : keys_(keys.begin(), keys.end()) {}
99 
102  template<typename ITERATOR>
103  Factor(ITERATOR first, ITERATOR last) : keys_(first, last) {}
104 
107  template<typename CONTAINER>
108  static Factor FromKeys(const CONTAINER& keys) {
109  return Factor(keys.begin(), keys.end()); }
110 
113  template<typename ITERATOR>
114  static Factor FromIterators(ITERATOR first, ITERATOR last) {
115  return Factor(first, last); }
116 
118 
119  public:
121  // public since it is required for boost serialization and static methods.
122  // virtual since it is public.
123  // http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-dtor-virtual
124  virtual ~Factor() = default;
125 
128 
130  bool empty() const { return keys_.empty(); }
131 
133  Key front() const { return keys_.front(); }
134 
136  Key back() const { return keys_.back(); }
137 
139  const_iterator find(Key key) const { return std::find(begin(), end(), key); }
140 
142  const KeyVector& keys() const { return keys_; }
143 
145  const_iterator begin() const { return keys_.begin(); }
146 
148  const_iterator end() const { return keys_.end(); }
149 
154  virtual double error(const HybridValues& c) const;
155 
159  size_t size() const { return keys_.size(); }
160 
162 
165 
167  virtual void print(
168  const std::string& s = "Factor",
170 
172  virtual void printKeys(
173  const std::string& s = "Factor",
175 
177  bool equals(const This& other, double tol = 1e-9) const;
178 
182 
184  KeyVector& keys() { return keys_; }
185 
187  iterator begin() { return keys_.begin(); }
188 
190  iterator end() { return keys_.end(); }
191 
193 
194  private:
195 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
196 
199  friend class boost::serialization::access;
200  template<class Archive>
201  void serialize(Archive & ar, const unsigned int /*version*/) {
202  ar & BOOST_SERIALIZATION_NVP(keys_);
203  }
204 #endif
205 
207 
208  };
209 
210 } // \namespace gtsam
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
const gtsam::Symbol key('X', 0)
bool empty() const
Whether the factor is empty (involves zero variables).
Definition: Factor.h:130
Typedefs for easier changing of types.
FastSet< FactorIndex > FactorIndexSet
Definition: Factor.h:37
std::string serialize(const T &input)
serializes to a string
size_t size() const
Definition: Factor.h:159
static Factor FromKeys(const CONTAINER &keys)
Definition: Factor.h:108
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
Definition: FastVector.h:34
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
KeyVector keys_
The keys involved in this factor.
Definition: Factor.h:87
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
static const symbolic::SymbolExpr< internal::symbolic_last_tag > last
const KeyFormatter & formatter
const_iterator find(Key key) const
find
Definition: Factor.h:139
Key back() const
Last key.
Definition: Factor.h:136
FastVector< FactorIndex > FactorIndices
Define collection types:
Definition: Factor.h:36
KeyVector & keys()
Definition: Factor.h:184
const_iterator end() const
Definition: Factor.h:148
iterator end()
Definition: Factor.h:190
iterator begin()
Definition: Factor.h:187
KeyVector::iterator iterator
Iterator over keys.
Definition: Factor.h:79
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
std::shared_ptr< Factor > shared_ptr
A shared_ptr to this class.
Definition: Factor.h:75
Factor(ITERATOR first, ITERATOR last)
Definition: Factor.h:103
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
A thin wrapper around std::vector that uses a custom allocator.
traits
Definition: chartTesting.h:28
Key front() const
First key.
Definition: Factor.h:133
static EIGEN_DEPRECATED const end_t end
const KeyVector & keys() const
Access the factor&#39;s involved variable keys.
Definition: Factor.h:142
static double error
Definition: testRot3.cpp:37
const G double tol
Definition: Group.h:86
static Factor FromIterators(ITERATOR first, ITERATOR last)
Definition: Factor.h:114
KeyVector::const_iterator const_iterator
Const iterator over keys.
Definition: Factor.h:82
const KeyVector keys
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
Factor(const CONTAINER &keys)
Definition: Factor.h:98
const_iterator begin() const
Definition: Factor.h:145
Factor This
This class.
Definition: Factor.h:74
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:13