Go to the documentation of this file.
22 #ifndef STATE_VECTOR__GENERIC_STATE_HPP_
23 #define STATE_VECTOR__GENERIC_STATE_HPP_
32 #pragma GCC diagnostic push
33 #pragma GCC diagnostic ignored "-Wold-style-cast"
34 #pragma GCC diagnostic ignored "-Wsign-conversion"
35 #pragma GCC diagnostic ignored "-Wconversion"
36 #pragma GCC diagnostic ignored "-Wuseless-cast"
38 #pragma GCC diagnostic pop
46 namespace state_vector
50 template<
typename StateT>
59 template<
typename ScalarT,
typename ... VariableTs>
64 "\n\nState can only be generated from variables, i.e. types that inherit from Variable.\n\n");
66 std::is_arithmetic<ScalarT>::value,
"\n\nThe provided scalar type is not arithmetic.\n\n");
68 sizeof...(VariableTs) > 0,
"\n\nCannot create state without variables.\n\n");
70 constexpr
static std::int32_t kSize =
sizeof...(VariableTs);
73 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
75 using Vector = Eigen::Matrix<ScalarT, kSize, 1>;
76 using Matrix = Eigen::Matrix<ScalarT, kSize, kSize>;
129 template<
typename VariableT>
130 inline ScalarT &
at() noexcept
142 template<
typename VariableT>
143 inline ScalarT &
at(
const VariableT) noexcept
155 template<
typename VariableT>
156 inline const ScalarT &
at() const noexcept
168 template<
typename VariableT>
169 inline const ScalarT &
at(
const VariableT)
const noexcept
199 template<
typename OtherStateT>
200 inline OtherStateT
copy_into(OtherStateT other_state = OtherStateT{})
const noexcept
204 "\n\nOtherStateT is not a GenericState.\n\n");
205 auto copy_variables = [&other_state,
this](
auto variable) {
206 other_state.at(variable) = this->at(variable);
209 Variables,
typename OtherStateT::Variables>::type;
221 template<
typename VariableT>
243 return lhs.m_state.isApprox(rhs.m_state);
252 auto print = [&out, &state](
auto element) {
269 return this->operator+=(rhs.vector());
284 this->vector() += rhs;
297 return this->operator-=(rhs.vector());
312 this->vector() -= rhs;
357 const auto wrap_angles = [
this](
auto variable) {
358 using VariableT = decltype(variable);
381 template<
typename NewScalarT>
384 return GenericState<NewScalarT, VariableTs...>{m_state.template cast<NewScalarT>()};
389 Vector m_state{Vector::Zero()};
397 template<
typename StateT>
398 struct STATE_VECTOR_PUBLIC is_state :
public std::false_type {};
406 template<
typename ScalarT,
typename ... VariableTs>
408 :
public std::true_type {};
411 template<
typename ... Ts>
415 template<
typename ... Ts>
422 #endif // STATE_VECTOR__GENERIC_STATE_HPP_
This file defines the common variables used within the filter implementations.
GenericState & operator-=(const Vector &rhs) noexcept
Subtraction assignment operator.
Definition: generic_state.hpp:310
ScalarT Scalar
Definition: generic_state.hpp:77
ScalarT & at(const VariableT) noexcept
Get vector element at a given variable.
Definition: generic_state.hpp:143
A trait to check if a variable represents an angle.
Definition: variable.hpp:64
Forward-declare is_state trait.
Definition: generic_state.hpp:51
std::tuple< VariableTs... > Variables
Definition: generic_state.hpp:74
const ScalarT & at(const VariableT) const noexcept
Get vector element at a given variable.
Definition: generic_state.hpp:169
This file includes common type definition.
Eigen::Matrix< ScalarT, kSize, kSize > Matrix
Definition: generic_state.hpp:76
friend GenericState operator+(GenericState lhs, const T &rhs) noexcept
Addition operator.
Definition: generic_state.hpp:345
A trait to check if a type is a variable by checking if it inherits from Variable.
Definition: variable.hpp:55
constexpr static Eigen::Index size() noexcept
Get the size of the state.
Definition: generic_state.hpp:235
const Vector & vector() const noexcept
Get underlying Eigen vector.
Definition: generic_state.hpp:103
constexpr friend GenericState wrap_all_angles(GenericState state) noexcept
Wrap all variables that represent angles using the common::helper_functions::wrap_angle.
Definition: generic_state.hpp:370
A representation of a generic state vectors with specified variables.
Definition: generic_state.hpp:60
A class to compute a conjunction over given traits.
Definition: type_traits.hpp:119
OtherStateT copy_into(OtherStateT other_state=OtherStateT{}) const noexcept
Copy values of this state into another state.
Definition: generic_state.hpp:200
Vector & vector() noexcept
Get underlying Eigen vector.
Definition: generic_state.hpp:97
GenericState & operator+=(const GenericState &rhs) noexcept
Addition assignment operator.
Definition: generic_state.hpp:267
constexpr T wrap_angle(T angle) noexcept
Wrap angle to the [-pi, pi] range.
Definition: angle_utils.hpp:50
COMMON_PUBLIC std::string get_type_name()
Get a demangled name of a type.
Definition: type_name.hpp:36
friend GenericState operator-(GenericState lhs, const T &rhs) noexcept
Subtraction operator.
Definition: generic_state.hpp:328
const ScalarT & at() const noexcept
Get vector element at a given variable.
Definition: generic_state.hpp:156
This file defines the lanelet2_map_provider_node class.
Definition: quick_sort.hpp:24
Find an index of a type in a tuple.
Definition: type_traits.hpp:52
Eigen::Matrix< ScalarT, kSize, 1 > Vector
Definition: generic_state.hpp:75
ScalarT & operator[](const Eigen::Index idx)
Get an element of the vector.
Definition: generic_state.hpp:112
GenericState & operator-=(const GenericState &rhs) noexcept
Subtraction assignment operator.
Definition: generic_state.hpp:295
constexpr void wrap_all_angles() noexcept
Wrap all variables that represent angles using the common::helper_functions::wrap_angle.
Definition: generic_state.hpp:355
float float32_t
Definition: types.hpp:45
ScalarT & at() noexcept
Get vector element at a given variable.
Definition: generic_state.hpp:130
GenericState & operator+=(const Vector &rhs) noexcept
Addition assignment operator.
Definition: generic_state.hpp:282
constexpr friend bool operator==(const GenericState &lhs, const GenericState &rhs)
An equality operator.
Definition: generic_state.hpp:241
constexpr static Variables variables() noexcept
Get a variables tuple used for iteration over all variables.
Definition: generic_state.hpp:238
const ScalarT & operator[](const Eigen::Index idx) const
Get an element of the vector.
Definition: generic_state.hpp:120
GenericState< NewScalarT, VariableTs... > cast() const noexcept
Cast to another scalar type.
Definition: generic_state.hpp:382
A trait used to intersect types stored in tuples at compile time. The resulting typedef type will hol...
Definition: type_traits.hpp:180
constexpr static Eigen::Index index_of() noexcept
Get an index of the variable in the state.
Definition: generic_state.hpp:222
double float64_t
Definition: types.hpp:47
friend std::ostream & operator<<(std::ostream &out, const GenericState &state)
Allow using << operator with this class.
Definition: generic_state.hpp:249
GenericState(const Vector &vector)
Constructs a new instance from an Eigen vector.
Definition: generic_state.hpp:89
std::size_t Index
Index type for identifying bins of the hash/lattice.
Definition: spatial_hash_config.hpp:49
constexpr COMMON_PUBLIC std::enable_if_t< I==sizeof...(TypesT)> visit(std::tuple< TypesT... > &, Callable) noexcept
Visit every element in a tuple.
Definition: type_traits.hpp:80