24 #include <gtsam/dllexport.h> 26 #include <boost/optional/optional.hpp> 27 #include <boost/smart_ptr/shared_ptr.hpp> 46 typedef boost::shared_ptr<VariableIndex> shared_ptr;
48 typedef Factors::iterator Factor_iterator;
49 typedef Factors::const_iterator Factor_const_iterator;
58 typedef KeyMap::const_iterator const_iterator;
59 typedef KeyMap::const_iterator iterator;
60 typedef KeyMap::value_type value_type;
75 VariableIndex(
const FG& factorGraph) : nFactors_(0), nEntries_(0) { augment(factorGraph); }
82 size_t size()
const {
return index_.size(); }
92 KeyMap::const_iterator item = index_.find(variable);
93 if(item == index_.end())
94 throw std::invalid_argument(
"Requested non-existent variable from VariableIndex");
107 void print(
const std::string& str =
"VariableIndex: ",
108 const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const;
114 void outputMetisFormat(std::ostream& os)
const;
126 void augment(
const FG& factors, boost::optional<const FactorIndices&> newFactorIndices = boost::none);
138 template<
typename ITERATOR,
class FG>
139 void remove(ITERATOR firstFactor, ITERATOR lastFactor,
const FG& factors);
142 template<
typename ITERATOR>
143 void removeUnusedVariables(ITERATOR firstKey, ITERATOR lastKey);
146 const_iterator
begin()
const {
return index_.begin(); }
149 const_iterator
end()
const {
return index_.end(); }
152 const_iterator
find(
Key key)
const {
return index_.find(key); }
155 Factor_iterator factorsBegin(
Key variable) {
return internalAt(variable).begin(); }
156 Factor_iterator factorsEnd(
Key variable) {
return internalAt(variable).end(); }
158 Factor_const_iterator factorsBegin(
Key variable)
const {
return internalAt(variable).begin(); }
159 Factor_const_iterator factorsEnd(
Key variable)
const {
return internalAt(variable).end(); }
163 const KeyMap::const_iterator item = index_.find(variable);
164 assert(item != index_.end());
165 return item->second; }
169 const KeyMap::iterator item = index_.find(variable);
170 assert(item != index_.end());
171 return item->second; }
const Factors & operator[](Key variable) const
Access a list of factors by variable.
Definition: VariableIndex.h:91
A thin wrapper around std::vector that uses a custom allocator.
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:141
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
const_iterator find(Key key) const
Find the iterator for the requested variable entry.
Definition: VariableIndex.h:152
Template to create a binary predicate.
Definition: Testable.h:110
The VariableIndex class computes and stores the block column structure of a factor graph.
Definition: VariableIndex.h:43
const Factors & internalAt(Key variable) const
Internal version of 'at' that asserts existence.
Definition: VariableIndex.h:162
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:150
size_t nEntries() const
The number of nonzero blocks, i.e. the number of variable-factor entries.
Definition: VariableIndex.h:88
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
VariableIndex()
Default constructor, creates an empty VariableIndex.
Definition: VariableIndex.h:68
A thin wrapper around std::map that uses boost's fast_pool_allocator.
size_t nFactors() const
The number of factors in the original factor graph.
Definition: VariableIndex.h:85
size_t size() const
The number of variable entries. This is equal to the number of unique variable Keys.
Definition: VariableIndex.h:82
Factors & internalAt(Key variable)
Internal version of 'at' that asserts existence.
Definition: VariableIndex.h:168
VariableIndex(const FG &factorGraph)
Create a VariableIndex that computes and stores the block column structure of a factor graph.
Definition: VariableIndex.h:75
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
FastVector< FactorIndex > FactorIndices
Define collection types:
Definition: Factor.h:32
The base class for all factors.
const_iterator end() const
Iterator to the first variable entry.
Definition: VariableIndex.h:149
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
const_iterator begin() const
Iterator to the first variable entry.
Definition: VariableIndex.h:146