Containersο
Bounded Vectorο
The bounded vector is a container structure that tries to combine the advantages of arrays and vectors. It can be used if the maximum size is known at compile time. It combines the efficiency of arrays (e.g. locality) with the syntax of vectors (e.g. push_back).
Quaternion Cacheο
This container can be used to store direction-dependent data. To store the data efficiently, the directions are discretized. Hector_math implements three modes: Spherical, Largest dim and Spherical Fibonacci. The level of discretization, how many bins there, are can selected as well as the discretization mode. The modes have different advantages and disadvantages:
Mode |
Speed |
Evenly Discretization |
---|---|---|
Spherical |
π‘ |
β |
Largest Dimension |
β |
π‘ |
Spherical Fibonacci |
β |
β |
It is impossible to achieve perfect evenly discretization for arbitrary many bins. The spherical fibonacci mode achieves the best discretization. The spherical mode is differently distributed near the poles and the equator while the largest dim mode doesnβt have a reduced resolution at the poles but at the cost of overlapping regions with increased bin resolution.
For more details, see Quaternion Binning.
Ring Bufferο
The Ring Buffer is a container with a limited size which is controlled with the template argument MaxSize. If the Ring Buffer is full, adding new elements will overwrite the oldest elements! It can be used as a FIFO data structure. The oldest element can be easily retrieved while adding new elements will append them to the container. The container keeps track of which element is the oldest and the newest without ever moving any elements. Additionally, the container support any algorithm that work with forward iterators, like std::for_each() and of course range loops.
APIο
Bounded Vectorο
-
template<typename T, int MaxSize>
class BoundedVectorο Public Types
Public Functions
-
inline std::size_t size() constο
-
inline void pop_back()ο
-
inline void erase(const_iterator position)ο
-
inline void erase(const_iterator first, const_iterator last)ο
-
inline void clear()ο
-
inline const_iterator begin() constο
-
inline const_iterator end() constο
-
inline void reserve(std::size_t size)ο
-
inline std::size_t size() constο
Quaternion Cacheο
-
template<typename Scalar, typename T, QuaternionBinningMode MODE = quaternion_binning_modes::LargestDim, int AXIS_BINS = 128, int ANGLE_COUNT = 512>
class QuaternionCacheο Public Types
Public Functions
-
inline std::pair<iterator, bool> insert(const Eigen::Quaternion<Scalar> &q, const T &val) noexceptο
-
inline const_iterator find(const Eigen::Quaternion<Scalar> &q) const noexceptο
-
inline const_iterator begin() const noexceptο
-
inline const_iterator cbegin() const noexceptο
-
inline const_iterator end() const noexceptο
-
inline const_iterator cend() const noexceptο
-
inline void clear() noexceptο
Public Static Functions
Private Types
-
using BinType = typename detail::QuaternionBinType<AXIS_BINS, ANGLE_COUNT>::BinTypeο
-
inline std::pair<iterator, bool> insert(const Eigen::Quaternion<Scalar> &q, const T &val) noexceptο
Ring Bufferο
-
template<typename T, std::size_t N>
class RingBufferο A RingBuffer is a limited size storage container that once full will overwrite the oldest elements when a new element is added.
- Template Parameters:
T β The type of the elements stored in this RingBuffer.
Nm β The maximum number of elements stored in the RingBuffer at any time.
Public Types
-
using pointer = value_type*ο
-
using const_pointer = const value_type*ο
-
using reference = value_type&ο
-
using const_reference = const value_type&ο
-
using size_type = std::size_tο
-
using difference_type = std::ptrdiff_tο
-
using iterator = ring_iterator<pointer>ο
-
using const_iterator = ring_iterator<const_pointer>ο
Public Functions
-
inline constexpr bool empty() constο
- Returns:
true if the container is empty, false otherwise
-
inline bool full() constο
- Returns:
true if the container is full, false otherwise. Appending to a full container will overwrite old elements.
-
inline constexpr std::size_t size() constο
- Returns:
the number of elements
-
inline constexpr std::size_t capacity() constο
- Returns:
the maximum number of elements which is equal to the template parameter TSize.
-
inline constexpr std::size_t max_size() constο
- Returns:
the maximum number of elements which is equal to the template parameter TSize.
-
inline void push_back(const_reference value)ο
Adds an element to the end of the RingBuffer. If the RingBuffer is full the oldest element will be overwritten.
- Parameters:
value β element to be appended.
-
inline void pop_front()ο
Deletes the oldest element in the RingBuffer.
-
inline value_type read_and_pop_front()ο
Reads and deletes the oldest element of the RingBuffer.
- Returns:
the oldest not yet overwritten element from The RingBuffer.
-
template<typename ...Args>
inline void emplace_back(Args&&... args)ο Constructs an element and appends it to the RingBuffer. If the RingBuffer is already full, the oldest element is overwritten.
- Parameters:
args β The arguments that are passed to the constructor of the element.
-
inline iterator begin() noexceptο
- Returns:
an iterator pointing to the oldest element in the ringbuffer.
-
inline iterator end() noexceptο
- Returns:
an iterator pointing to the position after the newest element in the ringbuffer.
-
inline const_iterator cbegin() noexceptο
- Returns:
a const iterator pointing to the oldest element in the ringbuffer.
-
inline const_iterator cend() noexceptο
- Returns:
a const iterator pointing to the position after the newest element in the ringbuffer.
-
inline const_reference front() constο
- Returns:
a const reference to the oldest element in the buffer.
-
inline const_reference back() constο
- Returns:
a const reference to the newest element in the buffer.
-
inline void clear()ο
Clears the contents of the RingBuffer.
-
inline const_reference operator[](std::size_t index) constο
Private Functions
-
inline std::size_t get_normalised_index(std::size_t index) constο
-
inline void added_element_tail_adapt_indices()ο
-
inline void removed_element_at_head_adapt_indices()ο
-
inline std::size_t get_head_index() constο
The index of the oldest element.
-
inline std::size_t get_last_index() constο
Private Members
-
std::array<value_type, Size> items_ο
-
std::size_t size_ = 0ο
-
std::size_t tail_index_ = 0ο
-
template<typename Iterator>
struct ring_iteratorο Public Types
-
using iterator_category = std::random_access_iterator_tagο
Public Functions
-
inline ring_iterator(RingBuffer<T, N> *buffer, int offset, int index = 0) noexceptο
-
inline ring_iterator<Iterator> &operator++() noexceptο
-
inline ring_iterator<Iterator> operator++(int) & noexceptο
-
inline ring_iterator<Iterator> &operator+=(int nums) noexceptο
-
inline ring_iterator<Iterator> &operator--() noexceptο
-
inline ring_iterator<Iterator> operator--(int) & noexceptο
-
inline ring_iterator<Iterator> &operator-=(int nums) noexceptο
-
inline difference_type operator-(const ring_iterator<Iterator> &other) const noexceptο
-
inline ring_iterator<Iterator> operator+(difference_type nums) const noexceptο
-
inline ring_iterator<Iterator> operator-(difference_type nums) const noexceptο
-
inline operator RingBuffer<T, N>::const_iterator() const noexceptο
-
template<typename IteratorR>
inline bool operator==(const ring_iterator<IteratorR> &other) const noexceptο
-
template<typename IteratorR>
inline bool operator!=(const ring_iterator<IteratorR> &other) const noexceptο
-
using iterator_category = std::random_access_iterator_tagο