gtsam  4.1.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 {
32 typedef FastVector<FactorIndex> FactorIndices;
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:
107 
109  Key front() const { return keys_.front(); }
110 
112  Key back() const { return keys_.back(); }
113 
115  const_iterator find(Key key) const { return std::find(begin(), end(), key); }
116 
118  const KeyVector& keys() const { return keys_; }
119 
121  const_iterator begin() const { return keys_.begin(); }
122 
124  const_iterator end() const { return keys_.end(); }
125 
129  size_t size() const { return keys_.size(); }
130 
132 
133 
136 
138  void print(const std::string& s = "Factor", const KeyFormatter& formatter = DefaultKeyFormatter) const;
139 
141  void printKeys(const std::string& s = "Factor", const KeyFormatter& formatter = DefaultKeyFormatter) const;
142 
143  protected:
145  bool equals(const This& other, double tol = 1e-9) const;
146 
148 
149  public:
152 
154  KeyVector& keys() { return keys_; }
155 
157  iterator begin() { return keys_.begin(); }
158 
160  iterator end() { return keys_.end(); }
161 
162  private:
164  friend class boost::serialization::access;
165  template<class Archive>
166  void serialize(Archive & ar, const unsigned int /*version*/) {
167  ar & BOOST_SERIALIZATION_NVP(keys_);
168  }
169 
171 
172  };
173 
174 }
FastVector.h
A thin wrapper around std::vector that uses a custom allocator.
gtsam::equals
Template to create a binary predicate.
Definition: Testable.h:110
gtsam::Factor::end
iterator end()
Iterator at end of involved variable keys.
Definition: Factor.h:160
gtsam::Factor::keys
const KeyVector & keys() const
Access the factor's involved variable keys.
Definition: Factor.h:118
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61
gtsam::Factor::keys
KeyVector & keys()
Definition: Factor.h:154
gtsam::Factor::back
Key back() const
Last key.
Definition: Factor.h:112
gtsam::serialize
std::string serialize(const T &input)
serializes to a string
Definition: serialization.h:100
gtsam::Factor::keys_
KeyVector keys_
The keys involved in this factor.
Definition: Factor.h:72
gtsam::Factor::begin
const_iterator begin() const
Iterator at beginning of involved variable keys.
Definition: Factor.h:121
types.h
Typedefs for easier changing of types.
gtsam
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:155
gtsam::Factor::find
const_iterator find(Key key) const
find
Definition: Factor.h:115
gtsam::FactorIndices
FastVector< FactorIndex > FactorIndices
Define collection types:
Definition: Factor.h:32
gtsam::Factor::size
size_t size() const
Definition: Factor.h:129
Key.h
gtsam::FastSet
Definition: FastSet.h:46
gtsam::Factor::Factor
Factor(ITERATOR first, ITERATOR last)
Construct factor from iterator keys.
Definition: Factor.h:88
gtsam::Factor::begin
iterator begin()
Iterator at beginning of involved variable keys.
Definition: Factor.h:157
gtsam::KeyFormatter
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:35
gtsam::Factor::FromKeys
static Factor FromKeys(const CONTAINER &keys)
Construct factor from container of keys.
Definition: Factor.h:93
gtsam::Factor
This is the base class for all factor types.
Definition: Factor.h:55
gtsam::Factor::const_iterator
KeyVector::const_iterator const_iterator
Const iterator over keys.
Definition: Factor.h:67
gtsam::KeyVector
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
gtsam::Factor::end
const_iterator end() const
Iterator at end of involved variable keys.
Definition: Factor.h:124
gtsam::Factor::iterator
KeyVector::iterator iterator
Iterator over keys.
Definition: Factor.h:64
gtsam::Factor::Factor
Factor(const CONTAINER &keys)
Construct factor from container of keys.
Definition: Factor.h:83
gtsam::Factor::front
Key front() const
First key.
Definition: Factor.h:109
gtsam::Factor::Factor
Factor()
Default constructor for I/O.
Definition: Factor.h:78
gtsam::Factor::FromIterators
static Factor FromIterators(ITERATOR first, ITERATOR last)
Construct factor from iterator keys.
Definition: Factor.h:99