29#include <gtsam/base/GenericValue.h>
30#include <gtsam/base/VectorSpace.h>
32#if GTSAM_ENABLE_BOOST_SERIALIZATION
33#include <boost/serialization/unique_ptr.hpp>
45 class ValueAutomaticCasting;
46 template<
typename T>
static bool _truePredicate(
const T&) {
return true; }
49 class GTSAM_EXPORT ValueCloneAllocator {
53 ValueCloneAllocator() {}
75 std::map<Key, std::unique_ptr<Value>, std::less<Key>,
76 std::allocator<std::pair<const Key, std::unique_ptr<Value>>>>;
82 friend class NonlinearMultifrontalSolver;
93 struct GTSAM_EXPORT KeyValuePair {
101 struct GTSAM_EXPORT ConstKeyValuePair {
105 ConstKeyValuePair(
Key _key,
const Value& _value) :
key(_key),
value(_value) {}
109 typedef KeyValuePair value_type;
128 Values(std::initializer_list<ConstKeyValuePair> init);
141 bool equals(
const Values& other,
double tol=1e-9)
const;
155 template <
typename ValueType>
156 const ValueType
at(
Key j)
const;
162 template <
typename ValueType>
163 const ValueType&
atRef(
Key j)
const;
178 bool exists(
Key j)
const;
184 template<
typename ValueType>
185 const ValueType * exists(
Key j)
const;
188 size_t size()
const {
return values_.size(); }
191 bool empty()
const {
return values_.empty(); }
197 struct deref_iterator {
198 using const_iterator_type =
typename KeyValueMap::const_iterator;
199 const_iterator_type it_;
200 deref_iterator(const_iterator_type it) : it_(it) {}
202 std::unique_ptr<ConstKeyValuePair> operator->()
const {
203 return std::make_unique<ConstKeyValuePair>(it_->first, *(it_->second));
205 bool operator==(
const deref_iterator& other)
const {
206 return it_ == other.it_;
208 bool operator!=(
const deref_iterator& other)
const {
return it_ != other.it_; }
209 deref_iterator& operator++() {
216 deref_iterator end()
const {
return deref_iterator(values_.end()); }
251 void retractMasked(
const VectorValues& delta,
const KeySet& mask);
259 void insert(
Key j,
const Value& val);
262 void insert(
const Values& values);
267 template <
typename ValueType>
268 void insert(
Key j,
const ValueType& val);
279 template <
typename UnaryOp,
typename ValueType>
280 void insert(
Key j,
const Eigen::CwiseUnaryOp<UnaryOp, const ValueType>& val);
292 template <
typename BinaryOp,
typename ValueType1,
typename ValueType2>
293 void insert(
Key j,
const Eigen::CwiseBinaryOp<BinaryOp, const ValueType1, const ValueType2>& val);
304 void update(
Key j,
const Value& val);
310 template <
typename T>
316 template <
typename UnaryOp,
typename ValueType>
317 void update(
Key j,
const Eigen::CwiseUnaryOp<UnaryOp, const ValueType>& val);
322 template <
typename BinaryOp,
typename ValueType1,
typename ValueType2>
323 void update(
Key j,
const Eigen::CwiseBinaryOp<BinaryOp, const ValueType1, const ValueType2>& val);
338 template <
typename ValueType>
344 template <
typename UnaryOp,
typename ValueType>
350 template <
typename BinaryOp,
typename ValueType1,
typename ValueType2>
351 void insert_or_assign(
Key j,
const Eigen::CwiseBinaryOp<BinaryOp, const ValueType1, const ValueType2>& val);
390 std::map<Key,size_t> dims()
const;
396 template <
class ValueType>
397 size_t count()
const;
418 template <
class ValueType>
419 std::map<Key, ValueType>
420 extract(
const std::function<
bool(
Key)>& filterFcn = &_truePredicate<Key>)
const;
425 template<
class ValueType>
426 static bool filterHelper(
const std::function<
bool(
Key)> filter,
const ConstKeyValuePair& key_value) {
428 static_assert(!std::is_same<Value, ValueType>::value,
"ValueType must not be type: Value to use this filter");
433#if GTSAM_ENABLE_BOOST_SERIALIZATION
435 friend class boost::serialization::access;
436 template<
class ARCHIVE>
437 void serialize(ARCHIVE & ar,
const unsigned int ) {
438 ar & BOOST_SERIALIZATION_NVP(values_);
450 mutable std::string message_;
463 GTSAM_EXPORT
const char*
what() const noexcept override;
473 mutable std::string message_;
486 GTSAM_EXPORT
const char*
what() const noexcept override;
493 const std::type_info& storedTypeId_;
494 const std::type_info& requestedTypeId_;
497 mutable std::string message_;
517 GTSAM_EXPORT
const char*
what() const noexcept override;
521 class DynamicValuesMismatched : public
std::exception {
524 DynamicValuesMismatched()
noexcept {}
526 ~DynamicValuesMismatched()
noexcept override {}
528 const char*
what()
const noexcept override {
529 return "The Values 'this' and the argument passed to Values::localCoordinates have mismatched keys and values";
534 class NoMatchFoundForFixed:
public std::exception {
537 const size_t M1_, N1_;
538 const size_t M2_, N2_;
541 mutable std::string message_;
544 NoMatchFoundForFixed(
size_t M1,
size_t N1,
size_t M2,
size_t N2) noexcept :
545 M1_(M1), N1_(N1), M2_(M2), N2_(N2) {
548 ~NoMatchFoundForFixed()
noexcept override {
551 GTSAM_EXPORT
const char* what()
const noexcept override;
563#include <gtsam/nonlinear/Values-inl.h>
An easy way to control which allocator is used for Fast* collections.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:91
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
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
Default allocator for list, map, and set types.
Definition FastDefaultAllocator.h:50
Wraps any type T so it can play as a Value.
Definition GenericValue.h:48
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
This is the base class for any type to be stored in Values.
Definition Value.h:39
virtual void deallocate_() const =0
Deallocate a raw pointer of this value.
virtual Value * clone_() const =0
Clone this value in a special memory pool, must be deleted with Value::deallocate_,...
VectorValues represents a collection of vector-valued variables associated each with a unique integer...
Definition VectorValues.h:73
A non-templated config holding any types of Manifold-group elements.
Definition Values.h:65
void update(Key j, const T &val)
Templated version to update a variable with the given j, throws KeyDoesNotExist<J> if j is not presen...
bool empty() const
whether the config is empty
Definition Values.h:191
void update(Key j, const Value &val)
single element change of existing element
Definition Values.cpp:186
std::shared_ptr< const Values > const_shared_ptr
A const shared_ptr to this class.
Definition Values.h:90
bool equals(const Values &other, double tol=1e-9) const
Test whether the sets of keys and values are identical.
Definition Values.cpp:79
deref_iterator upper_bound(Key j) const
Find the lowest-ordered element greater than the specified key.
Definition Values.h:226
void insertPoint3(Key j, const Vector3 &point3)
Insert a fixed-size 3-vector without Python overload ambiguity.
Definition Values.h:299
Values & operator=(const Values &rhs)
Replace all keys and variables.
Definition Values.cpp:259
const ValueType at(Key j) const
Retrieve a variable by key j.
Definition Values-inl.h:260
void clear()
Remove all variables from the config.
Definition Values.h:384
std::shared_ptr< Values > shared_ptr
A shared_ptr to this class.
Definition Values.h:87
void swap(Values &other)
Swap the contents of two Values without copying data.
Definition Values.h:381
void insertDouble(Key j, double c)
version for double
Definition Values.h:296
void insert(Key j, const Value &val)
Add a variable with the given j, throws KeyAlreadyExists<J> if j is already present.
Definition Values.cpp:170
size_t size() const
The number of variables in this config.
Definition Values.h:188
deref_iterator find(Key j) const
Find an element by key, returning an iterator, or end() if the key was not found.
Definition Values.h:220
KeyVector keys() const
Returns a vector of keys in the config.
Definition Values.cpp:235
const ValueType & atRef(Key j) const
Retrieve a variable by key j without copying.
Definition Values-inl.h:275
KeySet keySet() const
Returns a set of keys in the config.
Definition Values.cpp:244
void insert_or_assign(Key j, const Value &val)
If key j exists, update value, else perform an insert.
Definition Values.cpp:209
Values extract(const KeyVector &keys) const
Returns a new Values holding copies of the values at the given keys, whatever their types.
Definition Values.cpp:252
void print(const std::string &str="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
print method for testing and debugging
Definition Values.cpp:68
Values()=default
Default constructor creates an empty Values class.
void erase(Key j)
Remove a variable from the config, throws KeyDoesNotExist<J> if j is not present.
Definition Values.cpp:227
deref_iterator lower_bound(Key j) const
Find the element greater than or equal to the specified key.
Definition Values.h:223
double atDouble(size_t key) const
version for double
Definition Values.h:166
A key-value pair, which you get by dereferencing iterators.
Definition Values.h:93
Value & value
The value.
Definition Values.h:95
const Key key
The key.
Definition Values.h:94
A key-value pair, which you get by dereferencing iterators.
Definition Values.h:101
const Key key
The key.
Definition Values.h:102
const Value & value
The value.
Definition Values.h:103
const Key key_
The key that already existed.
Definition Values.h:447
GTSAM_EXPORT const char * what() const noexcept override
The message to be displayed to the user.
Definition Values.cpp:292
ValuesKeyAlreadyExists(Key key) noexcept
Construct with the key-value pair attempted to be added.
Definition Values.h:454
Key key() const noexcept
The duplicate key that was attempted to be added.
Definition Values.h:460
ValuesKeyDoesNotExist(const char *operation, Key key) noexcept
Construct with the key that does not exist in the values.
Definition Values.h:477
const Key key_
The key that does not exist.
Definition Values.h:470
Key key() const noexcept
The key that was attempted to be accessed that does not exist.
Definition Values.h:483
const char * operation_
The operation that attempted to access the key.
Definition Values.h:469
const std::type_info & storedTypeId() const
The typeid of the value stores in the Values.
Definition Values.h:511
Key key() const noexcept
The key that was attempted to be accessed that does not exist.
Definition Values.h:508
const Key key_
The key requested.
Definition Values.h:492
ValuesIncorrectType(Key key, const std::type_info &storedTypeId, const std::type_info &requestedTypeId) noexcept
Construct with the key that does not exist in the values.
Definition Values.h:501
const std::type_info & requestedTypeId() const
The requested typeid.
Definition Values.h:514