ClusterVector

template<typename ClusterType, typename = std::enable_if_t<is_cluster_v<ClusterType>>>
class ClusterVector
template<typename T, uint8_t ClusterSizeX, uint8_t ClusterSizeY, typename CoordType>
class ClusterVector<Cluster<T, ClusterSizeX, ClusterSizeY, CoordType>>

ClusterVector is a container for clusters of various sizes. It uses a contiguous memory buffer to store the clusters. It is templated on the data type and the coordinate type of the clusters.

Note

push_back can invalidate pointers to elements in the container

Warning

ClusterVector is currently move only to catch unintended copies, but this might change since there are probably use cases where copying is needed.

Template Parameters:
  • T – data type of the pixels in the cluster

  • CoordType – data type of the x and y coordinates of the cluster (normally int16_t)

Public Types

using value_type = T
using ClusterType = Cluster<T, ClusterSizeX, ClusterSizeY, CoordType>

Public Functions

inline ClusterVector(size_t capacity = 1024, uint64_t frame_number = 0)

Construct a new ClusterVector object.

Parameters:
  • capacity – initial capacity of the buffer in number of clusters

  • frame_number – frame number of the clusters. Default is 0, which is also used to indicate that the clusters come from many frames

inline ClusterVector(ClusterVector &&other) noexcept
inline ClusterVector &operator=(ClusterVector &&other) noexcept
inline std::vector<T> sum()

Sum the pixels in each cluster.

Returns:

std::vector<T> vector of sums for each cluster

inline std::vector<T> sum_2x2()

Sum the pixels in the 2x2 subcluster with the biggest pixel sum in each cluster.

Returns:

std::vector<T> vector of sums for each cluster

inline void reserve(size_t capacity)

Reserve space for at least capacity clusters.

Note

If capacity is less than the current capacity, the function does nothing.

Parameters:

capacity – number of clusters to reserve space for

inline void resize(size_t size)
inline void push_back(const ClusterType &cluster)
inline ClusterVector &operator+=(const ClusterVector &other)
inline size_t size() const

Return the number of clusters in the vector.

inline bool empty() const

Check if the vector is empty.

inline uint8_t cluster_size_x() const
inline uint8_t cluster_size_y() const
inline size_t capacity() const

Return the capacity of the buffer in number of clusters. This is the number of clusters that can be stored in the current buffer without reallocation.

inline auto begin() const
inline auto end() const
inline size_t item_size() const

Return the size in bytes of a single cluster.

inline ClusterType *data()
inline ClusterType const *data() const
inline ClusterType &operator[](size_t i)

Return a reference to the i-th cluster casted to type V.

Template Parameters:

V – type of the cluster

inline const ClusterType &operator[](size_t i) const
inline int32_t frame_number() const

Return the frame number of the clusters. 0 is used to indicate that the clusters come from many frames.

inline void set_frame_number(int32_t frame_number)

Private Members

std::vector<Cluster<T, ClusterSizeX, ClusterSizeY, CoordType>> m_data = {}
int32_t m_frame_number = {0}