gtsam  4.0.0
gtsam
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 {
31 
51  class GTSAM_EXPORT Factor
52  {
53 
54  private:
55  // These typedefs are private because they must be overridden in derived classes.
56  typedef Factor This;
57  typedef boost::shared_ptr<Factor> shared_ptr;
58 
59  public:
62 
65 
66  protected:
67 
70 
73 
75  Factor() {}
76 
79  template<typename CONTAINER>
80  explicit Factor(const CONTAINER& keys) : keys_(keys.begin(), keys.end()) {}
81 
84  template<typename ITERATOR>
85  Factor(ITERATOR first, ITERATOR last) : keys_(first, last) {}
86 
89  template<typename CONTAINER>
90  static Factor FromKeys(const CONTAINER& keys) {
91  return Factor(keys.begin(), keys.end()); }
92 
95  template<typename ITERATOR>
96  static Factor FromIterators(ITERATOR first, ITERATOR last) {
97  return Factor(first, last); }
98 
100 
101  public:
104 
106  Key front() const { return keys_.front(); }
107 
109  Key back() const { return keys_.back(); }
110 
112  const_iterator find(Key key) const { return std::find(begin(), end(), key); }
113 
115  const FastVector<Key>& keys() const { return keys_; }
116 
118  const_iterator begin() const { return keys_.begin(); }
119 
121  const_iterator end() const { return keys_.end(); }
122 
126  size_t size() const { return keys_.size(); }
127 
129 
130 
133 
135  void print(const std::string& s = "Factor", const KeyFormatter& formatter = DefaultKeyFormatter) const;
136 
138  void printKeys(const std::string& s = "Factor", const KeyFormatter& formatter = DefaultKeyFormatter) const;
139 
140  protected:
142  bool equals(const This& other, double tol = 1e-9) const;
143 
145 
146  public:
149 
151  FastVector<Key>& keys() { return keys_; }
152 
154  iterator begin() { return keys_.begin(); }
155 
157  iterator end() { return keys_.end(); }
158 
159  private:
161  friend class boost::serialization::access;
162  template<class Archive>
163  void serialize(Archive & ar, const unsigned int /*version*/) {
164  ar & BOOST_SERIALIZATION_NVP(keys_);
165  }
166 
168 
169  };
170 
171 }
iterator end()
Iterator at end of involved variable keys.
Definition: Factor.h:157
This is the base class for all factor types.
Definition: Factor.h:51
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:140
Typedefs for easier changing of types.
static Factor FromKeys(const CONTAINER &keys)
Construct factor from container of keys.
Definition: Factor.h:90
Factor(const CONTAINER &keys)
Construct factor from container of keys.
Definition: Factor.h:80
const_iterator find(Key key) const
find
Definition: Factor.h:112
const_iterator end() const
Iterator at end of involved variable keys.
Definition: Factor.h:121
size_t size() const
Definition: Factor.h:126
Definition: FastVector.h:36
const_iterator begin() const
Iterator at beginning of involved variable keys.
Definition: Factor.h:118
Template to create a binary predicate.
Definition: Testable.h:110
FastVector< Key > keys_
The keys involved in this factor.
Definition: Factor.h:69
FastVector< Key >::const_iterator const_iterator
Const iterator over keys.
Definition: Factor.h:64
Key back() const
Last key.
Definition: Factor.h:109
const FastVector< Key > & keys() const
Access the factor&#39;s involved variable keys.
Definition: Factor.h:115
Key front() const
First key.
Definition: Factor.h:106
static Factor FromIterators(ITERATOR first, ITERATOR last)
Construct factor from iterator keys.
Definition: Factor.h:96
FastVector< Key >::iterator iterator
Iterator over keys.
Definition: Factor.h:61
Factor()
Default constructor for I/O.
Definition: Factor.h:75
A thin wrapper around std::vector that uses boost&#39;s pool_allocator.
iterator begin()
Iterator at beginning of involved variable keys.
Definition: Factor.h:154
Factor(ITERATOR first, ITERATOR last)
Construct factor from iterator keys.
Definition: Factor.h:85
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
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
FastVector< Key > & keys()
Definition: Factor.h:151