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 #include <boost/serialization/nvp.hpp>
25 
26 #include <gtsam/base/types.h>
27 #include <gtsam/base/FastVector.h>
28 #include <gtsam/inference/Key.h>
29 
30 namespace gtsam {
34 
54  class GTSAM_EXPORT Factor
55  {
56 
57  private:
58  // These typedefs are private because they must be overridden in derived classes.
59  typedef Factor This;
60  typedef boost::shared_ptr<Factor> shared_ptr;
61 
62  public:
64  typedef KeyVector::iterator iterator;
65 
67  typedef KeyVector::const_iterator const_iterator;
68 
69  protected:
70 
73 
76 
78  Factor() {}
79 
82  template<typename CONTAINER>
83  explicit Factor(const CONTAINER& keys) : keys_(keys.begin(), keys.end()) {}
84 
87  template<typename ITERATOR>
88  Factor(ITERATOR first, ITERATOR last) : keys_(first, last) {}
89 
92  template<typename CONTAINER>
93  static Factor FromKeys(const CONTAINER& keys) {
94  return Factor(keys.begin(), keys.end()); }
95 
98  template<typename ITERATOR>
99  static Factor FromIterators(ITERATOR first, ITERATOR last) {
100  return Factor(first, last); }
101 
103 
104  public:
106  // public since it is required for boost serialization and static methods.
107  // virtual since it is public.
108  // http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-dtor-virtual
109  virtual ~Factor() = default;
110 
113 
115  Key front() const { return keys_.front(); }
116 
118  Key back() const { return keys_.back(); }
119 
121  const_iterator find(Key key) const { return std::find(begin(), end(), key); }
122 
124  const KeyVector& keys() const { return keys_; }
125 
127  const_iterator begin() const { return keys_.begin(); }
128 
130  const_iterator end() const { return keys_.end(); }
131 
135  size_t size() const { return keys_.size(); }
136 
138 
141 
143  virtual void print(
144  const std::string& s = "Factor",
146 
148  virtual void printKeys(
149  const std::string& s = "Factor",
151 
152  protected:
154  bool equals(const This& other, double tol = 1e-9) const;
155 
157 
158  public:
161 
163  KeyVector& keys() { return keys_; }
164 
166  iterator begin() { return keys_.begin(); }
167 
169  iterator end() { return keys_.end(); }
170 
171  private:
173  friend class boost::serialization::access;
174  template<class Archive>
175  void serialize(Archive & ar, const unsigned int /*version*/) {
176  ar & BOOST_SERIALIZATION_NVP(keys_);
177  }
178 
180 
181  };
182 
183 }
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
constexpr int last(int, int result)
Typedefs for easier changing of types.
const_iterator find(Key key) const
find
Definition: Factor.h:121
FastSet< FactorIndex > FactorIndexSet
Definition: Factor.h:33
FastVector< FactorIndex > FactorIndices
Define collection types:
Definition: Factor.h:32
static Factor FromKeys(const CONTAINER &keys)
Definition: Factor.h:93
const_iterator end() const
Definition: Factor.h:130
KeyVector keys_
The keys involved in this factor.
Definition: Factor.h:72
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
const KeyFormatter & formatter
KeyVector & keys()
Definition: Factor.h:163
void serialize(Archive &ar, const unsigned int)
Definition: Factor.h:175
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
iterator end()
Definition: Factor.h:169
constexpr int first(int i)
Implementation details for constexpr functions.
Key back() const
Last key.
Definition: Factor.h:118
Key front() const
First key.
Definition: Factor.h:115
const_iterator begin() const
Definition: Factor.h:127
iterator begin()
Definition: Factor.h:166
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
KeyVector::iterator iterator
Iterator over keys.
Definition: Factor.h:64
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
Factor(ITERATOR first, ITERATOR last)
Definition: Factor.h:88
A thin wrapper around std::vector that uses a custom allocator.
traits
Definition: chartTesting.h:28
boost::shared_ptr< Factor > shared_ptr
A shared_ptr to this class.
Definition: Factor.h:60
size_t size() const
Definition: Factor.h:135
const KeyVector & keys() const
Access the factor&#39;s involved variable keys.
Definition: Factor.h:124
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
Definition: FastVector.h:34
const G double tol
Definition: Group.h:83
static Factor FromIterators(ITERATOR first, ITERATOR last)
Definition: Factor.h:99
KeyVector::const_iterator const_iterator
Const iterator over keys.
Definition: Factor.h:67
const KeyVector keys
Factor(const CONTAINER &keys)
Definition: Factor.h:83
Factor This
This class.
Definition: Factor.h:59
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:42:03