gtsam  4.0.0
gtsam
gtsam::Values Class Reference

Detailed Description

A non-templated config holding any types of Manifold-group elements.

A values structure is a map from keys to values. It is used to specify the value of a bunch of variables in a factor graph. A Values is a values structure which can hold variables that are elements on manifolds, not just vectors. It then, as a whole, implements a aggregate type which is also a manifold element, and hence supports operations dim, retract, and localCoordinates.

Public Member Functions

 Values ()
 Default constructor creates an empty Values class.
 
 Values (const Values &other)
 Copy constructor duplicates all keys and values.
 
 Values (Values &&other)
 Move constructor.
 
 Values (const Values &other, const VectorValues &delta)
 Construct from a Values and an update vector: identical to other.retract(delta)
 
template<class ValueType >
 Values (const Filtered< ValueType > &view)
 Constructor from a Filtered view copies out all values.
 
template<class ValueType >
 Values (const ConstFiltered< ValueType > &view)
 Constructor from a Filtered or ConstFiltered view.
 
template<typename ValueType >
ValueType at (Key j) const
 Retrieve a variable by key j. More...
 
double atDouble (size_t key) const
 version for double
 
const Valueat (Key j) const
 Retrieve a variable by key j. More...
 
bool exists (Key j) const
 Check if a value exists with key j. More...
 
template<typename ValueType >
boost::optional< const ValueType & > exists (Key j) const
 Check if a value with key j exists, returns the value with type Value if the key does exist, or boost::none if it does not exist. More...
 
iterator find (Key j)
 Find an element by key, returning an iterator, or end() if the key was not found. More...
 
const_iterator find (Key j) const
 Find an element by key, returning an iterator, or end() if the key was not found. More...
 
iterator lower_bound (Key j)
 Find the element greater than or equal to the specified key. More...
 
const_iterator lower_bound (Key j) const
 Find the element greater than or equal to the specified key. More...
 
iterator upper_bound (Key j)
 Find the lowest-ordered element greater than the specified key. More...
 
const_iterator upper_bound (Key j) const
 Find the lowest-ordered element greater than the specified key. More...
 
size_t size () const
 The number of variables in this config.
 
bool empty () const
 whether the config is empty
 
const_iterator begin () const
 
const_iterator end () const
 
iterator begin ()
 
iterator end ()
 
const_reverse_iterator rbegin () const
 
const_reverse_iterator rend () const
 
reverse_iterator rbegin ()
 
reverse_iterator rend ()
 
void insert (Key j, const Value &val)
 Add a variable with the given j, throws KeyAlreadyExists<J> if j is already present.
 
void insert (const Values &values)
 Add a set of variables, throws KeyAlreadyExists<J> if a key is already present.
 
template<typename ValueType >
void insert (Key j, const ValueType &val)
 Templated version to add a variable with the given j, throws KeyAlreadyExists<J> if j is already present.
 
void insertDouble (Key j, double c)
 version for double
 
std::pair< iterator, bool > tryInsert (Key j, const Value &value)
 insert that mimics the STL map insert - if the value already exists, the map is not modified and an iterator to the existing value is returned, along with 'false'. More...
 
void update (Key j, const Value &val)
 single element change of existing element
 
template<typename T >
void update (Key j, const T &val)
 Templated version to update a variable with the given j, throws KeyAlreadyExists<J> if j is already present if no chart is specified, the DefaultChart<ValueType> is used.
 
void update (const Values &values)
 update the current available values without adding new ones
 
void erase (Key j)
 Remove a variable from the config, throws KeyDoesNotExist<J> if j is not present.
 
KeyVector keys () const
 Returns a set of keys in the config Note: by construction, the list is ordered.
 
Valuesoperator= (const Values &rhs)
 Replace all keys and variables.
 
void swap (Values &other)
 Swap the contents of two Values without copying data.
 
void clear ()
 Remove all variables from the config.
 
size_t dim () const
 Compute the total dimensionality of all values ( \( O(n) \))
 
VectorValues zeroVectors () const
 Return a VectorValues of zero vectors for each variable in this Values.
 
Filtered< Valuefilter (const boost::function< bool(Key)> &filterFcn)
 Return a filtered view of this Values class, without copying any data. More...
 
template<class ValueType >
Filtered< ValueType > filter (const boost::function< bool(Key)> &filterFcn=&_truePredicate< Key >)
 Return a filtered view of this Values class, without copying any data. More...
 
ConstFiltered< Valuefilter (const boost::function< bool(Key)> &filterFcn) const
 Return a filtered view of this Values class, without copying any data. More...
 
template<class ValueType >
ConstFiltered< ValueType > filter (const boost::function< bool(Key)> &filterFcn=&_truePredicate< Key >) const
 Return a filtered view of this Values class, without copying any data. More...
 
template<class ValueType >
size_t count () const
 
template<typename ValueType >
void update (Key j, const ValueType &val)
 
Testable
void print (const std::string &str="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
 print method for testing and debugging
 
bool equals (const Values &other, double tol=1e-9) const
 Test whether the sets of keys and values are identical.
 
Manifold Operations
Values retract (const VectorValues &delta) const
 Add a delta config to current config and returns a new config.
 
VectorValues localCoordinates (const Values &cp) const
 Get a delta config about a linearization point c0 (*this)
 

Public Types

typedef boost::shared_ptr< Valuesshared_ptr
 A shared_ptr to this class.
 
typedef boost::shared_ptr< const Valuesconst_shared_ptr
 A const shared_ptr to this class.
 
typedef boost::transform_iterator< boost::function1< KeyValuePair, const KeyValuePtrPair & >, KeyValueMap::iterator > iterator
 Mutable forward iterator, with value type KeyValuePair.
 
typedef boost::transform_iterator< boost::function1< ConstKeyValuePair, const ConstKeyValuePtrPair & >, KeyValueMap::const_iterator > const_iterator
 Const forward iterator, with value type ConstKeyValuePair.
 
typedef boost::transform_iterator< boost::function1< KeyValuePair, const KeyValuePtrPair & >, KeyValueMap::reverse_iterator > reverse_iterator
 Mutable reverse iterator, with value type KeyValuePair.
 
typedef boost::transform_iterator< boost::function1< ConstKeyValuePair, const ConstKeyValuePtrPair & >, KeyValueMap::const_reverse_iterator > const_reverse_iterator
 Const reverse iterator, with value type ConstKeyValuePair.
 
typedef KeyValuePair value_type
 

Classes

class  ConstFiltered
 A filtered view of a const Values, returned from Values::filter. More...
 
struct  ConstKeyValuePair
 A key-value pair, which you get by dereferencing iterators. More...
 
class  Filtered
 A filtered view of a Values, returned from Values::filter. More...
 
struct  KeyValuePair
 A key-value pair, which you get by dereferencing iterators. More...
 

Friends

class boost::serialization::access
 Serialization function.
 

Member Function Documentation

◆ at() [1/2]

template<typename ValueType >
ValueType gtsam::Values::at ( Key  j) const

Retrieve a variable by key j.

The type of the value associated with this key is supplied as a template argument to this function.

Parameters
jRetrieve the value associated with this key
Template Parameters
ValueTypeThe type of the value stored with this key, this method Throws DynamicValuesIncorrectType if this requested type is not correct. Dynamic matrices/vectors can be retrieved as fixed-size, but not vice-versa.
Returns
The stored value

◆ at() [2/2]

const Value & gtsam::Values::at ( Key  j) const

Retrieve a variable by key j.

This version returns a reference to the base Value class, and needs to be casted before use.

Parameters
jRetrieve the value associated with this key
Returns
A const reference to the stored value

◆ exists() [1/2]

bool gtsam::Values::exists ( Key  j) const

Check if a value exists with key j.

See exists<>(Key j) and exists(const TypedKey& j) for versions that return the value if it exists.

◆ exists() [2/2]

template<typename ValueType >
boost::optional< const ValueType & > gtsam::Values::exists ( Key  j) const

Check if a value with key j exists, returns the value with type Value if the key does exist, or boost::none if it does not exist.

Throws DynamicValuesIncorrectType if the value type associated with the requested key does not match the stored value type.

◆ filter() [1/4]

Values::Filtered< Value > gtsam::Values::filter ( const boost::function< bool(Key)> &  filterFcn)
inline

Return a filtered view of this Values class, without copying any data.

When iterating over the filtered view, only the key-value pairs with a key causing filterFcn to return true are visited. Because the object Filtered<Value> returned from filter() is only a view the original Values object must not be deallocated or go out of scope as long as the view is needed.

Parameters
filterFcnThe function that determines which key-value pairs are included in the filtered view, for which this function returns true on their keys.
Returns
A filtered view of the original Values class, which references the original Values class.

◆ filter() [2/4]

template<class ValueType >
Values::Filtered< ValueType > gtsam::Values::filter ( const boost::function< bool(Key)> &  filterFcn = &_truePredicate<Key>)

Return a filtered view of this Values class, without copying any data.

In this templated version, only key-value pairs whose value matches the template argument ValueType and whose key causes the function argument filterFcn to return true are visited when iterating over the filtered view. Because the object Filtered<Value> returned from filter() is only a view the original Values object must not be deallocated or go out of scope as long as the view is needed.

Template Parameters
ValueTypeThe type that the value in a key-value pair must match to be included in the filtered view. Currently, base classes are not resolved so the type must match exactly, except if ValueType = Value, in which case no type filtering is done.
Parameters
filterFcnThe function that determines which key-value pairs are included in the filtered view, for which this function returns true on their keys (default: always return true so that filter() only filters by type, matching ValueType).
Returns
A filtered view of the original Values class, which references the original Values class.

◆ filter() [3/4]

Values::ConstFiltered< Value > gtsam::Values::filter ( const boost::function< bool(Key)> &  filterFcn) const
inline

Return a filtered view of this Values class, without copying any data.

When iterating over the filtered view, only the key-value pairs with a key causing filterFcn to return true are visited. Because the object Filtered<Value> returned from filter() is only a view the original Values object must not be deallocated or go out of scope as long as the view is needed.

Parameters
filterFcnThe function that determines which key-value pairs are included in the filtered view, for which this function returns true on their keys.
Returns
A filtered view of the original Values class, which references the original Values class.

◆ filter() [4/4]

template<class ValueType >
Values::ConstFiltered< ValueType > gtsam::Values::filter ( const boost::function< bool(Key)> &  filterFcn = &_truePredicate<Key>) const

Return a filtered view of this Values class, without copying any data.

In this templated version, only key-value pairs whose value matches the template argument ValueType and whose key causes the function argument filterFcn to return true are visited when iterating over the filtered view. Because the object Filtered<Value> returned from filter() is only a view the original Values object must not be deallocated or go out of scope as long as the view is needed.

Template Parameters
ValueTypeThe type that the value in a key-value pair must match to be included in the filtered view. Currently, base classes are not resolved so the type must match exactly, except if ValueType = Value, in which case no type filtering is done.
Parameters
filterFcnThe function that determines which key-value pairs are included in the filtered view, for which this function returns true on their keys.
Returns
A filtered view of the original Values class, which references the original Values class.

◆ find() [1/2]

iterator gtsam::Values::find ( Key  j)
inline

Find an element by key, returning an iterator, or end() if the key was not found.

◆ find() [2/2]

const_iterator gtsam::Values::find ( Key  j) const
inline

Find an element by key, returning an iterator, or end() if the key was not found.

◆ lower_bound() [1/2]

iterator gtsam::Values::lower_bound ( Key  j)
inline

Find the element greater than or equal to the specified key.

◆ lower_bound() [2/2]

const_iterator gtsam::Values::lower_bound ( Key  j) const
inline

Find the element greater than or equal to the specified key.

◆ tryInsert()

std::pair< Values::iterator, bool > gtsam::Values::tryInsert ( Key  j,
const Value value 
)

insert that mimics the STL map insert - if the value already exists, the map is not modified and an iterator to the existing value is returned, along with 'false'.

If the value did not exist, it is inserted and an iterator pointing to the new element, along with 'true', is returned.

◆ upper_bound() [1/2]

iterator gtsam::Values::upper_bound ( Key  j)
inline

Find the lowest-ordered element greater than the specified key.

◆ upper_bound() [2/2]

const_iterator gtsam::Values::upper_bound ( Key  j) const
inline

Find the lowest-ordered element greater than the specified key.


The documentation for this class was generated from the following files: