gtsam 4.1.1
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#include <boost/shared_ptr.hpp>
26
27#include <gtsam/base/types.h>
29#include <gtsam/inference/Key.h>
30
31namespace gtsam {
33typedef FastVector<FactorIndex> FactorIndices;
35
55 class GTSAM_EXPORT Factor
56 {
57
58 private:
59 // These typedefs are private because they must be overridden in derived classes.
60 typedef Factor This;
61 typedef boost::shared_ptr<Factor> shared_ptr;
62
63 public:
65 typedef KeyVector::iterator iterator;
66
68 typedef KeyVector::const_iterator const_iterator;
69
70 protected:
71
74
77
79 Factor() {}
80
83 template<typename CONTAINER>
84 explicit Factor(const CONTAINER& keys) : keys_(keys.begin(), keys.end()) {}
85
88 template<typename ITERATOR>
89 Factor(ITERATOR first, ITERATOR last) : keys_(first, last) {}
90
93 template<typename CONTAINER>
94 static Factor FromKeys(const CONTAINER& keys) {
95 return Factor(keys.begin(), keys.end()); }
96
99 template<typename ITERATOR>
100 static Factor FromIterators(ITERATOR first, ITERATOR last) {
101 return Factor(first, last); }
102
104
105 public:
107 // public since it is required for boost serialization and static methods.
108 // virtual since it is public.
109 // http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-dtor-virtual
110 virtual ~Factor() = default;
111
114
116 Key front() const { return keys_.front(); }
117
119 Key back() const { return keys_.back(); }
120
122 const_iterator find(Key key) const { return std::find(begin(), end(), key); }
123
125 const KeyVector& keys() const { return keys_; }
126
128 const_iterator begin() const { return keys_.begin(); }
129
131 const_iterator end() const { return keys_.end(); }
132
136 size_t size() const { return keys_.size(); }
137
139
142
144 virtual void print(
145 const std::string& s = "Factor",
146 const KeyFormatter& formatter = DefaultKeyFormatter) const;
147
149 virtual void printKeys(
150 const std::string& s = "Factor",
151 const KeyFormatter& formatter = DefaultKeyFormatter) const;
152
153 protected:
155 bool equals(const This& other, double tol = 1e-9) const;
156
158
159 public:
162
164 KeyVector& keys() { return keys_; }
165
167 iterator begin() { return keys_.begin(); }
168
170 iterator end() { return keys_.end(); }
171
172 private:
174 friend class boost::serialization::access;
175 template<class Archive>
176 void serialize(Archive & ar, const unsigned int /*version*/) {
177 ar & BOOST_SERIALIZATION_NVP(keys_);
178 }
179
181
182 };
183
184}
A thin wrapper around std::vector that uses a custom allocator.
Typedefs for easier changing of types.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
std::string serialize(const T &input)
serializes to a string
Definition: serialization.h:112
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:155
FastVector< FactorIndex > FactorIndices
Define collection types:
Definition: Factor.h:33
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:69
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
Definition: FastSet.h:46
Template to create a binary predicate.
Definition: Testable.h:111
This is the base class for all factor types.
Definition: Factor.h:56
const KeyVector & keys() const
Access the factor's involved variable keys.
Definition: Factor.h:125
KeyVector keys_
The keys involved in this factor.
Definition: Factor.h:73
const_iterator find(Key key) const
find
Definition: Factor.h:122
const_iterator begin() const
Iterator at beginning of involved variable keys.
Definition: Factor.h:128
Factor()
Default constructor for I/O.
Definition: Factor.h:79
iterator end()
Iterator at end of involved variable keys.
Definition: Factor.h:170
KeyVector & keys()
Definition: Factor.h:164
static Factor FromIterators(ITERATOR first, ITERATOR last)
Construct factor from iterator keys.
Definition: Factor.h:100
static Factor FromKeys(const CONTAINER &keys)
Construct factor from container of keys.
Definition: Factor.h:94
iterator begin()
Iterator at beginning of involved variable keys.
Definition: Factor.h:167
virtual ~Factor()=default
Default destructor.
Factor(ITERATOR first, ITERATOR last)
Construct factor from iterator keys.
Definition: Factor.h:89
KeyVector::const_iterator const_iterator
Const iterator over keys.
Definition: Factor.h:68
const_iterator end() const
Iterator at end of involved variable keys.
Definition: Factor.h:131
Factor(const CONTAINER &keys)
Construct factor from container of keys.
Definition: Factor.h:84
KeyVector::iterator iterator
Iterator over keys.
Definition: Factor.h:65
Key back() const
Last key.
Definition: Factor.h:119
Key front() const
First key.
Definition: Factor.h:116
size_t size() const
Definition: Factor.h:136