ClusterVector

template<typename T, typename CoordType = int16_t>
class ClusterVector

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 Functions

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

Construct a new ClusterVector object.

Parameters:
  • cluster_size_x – size of the cluster in x direction

  • cluster_size_y – size of the cluster in y direction

  • 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()
inline ClusterVector(ClusterVector &&other) noexcept
inline ClusterVector &operator=(ClusterVector &&other) noexcept
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 push_back(CoordType x, CoordType y, const std::byte *data)

Add a cluster to the vector.

Warning

The data pointer must point to a buffer of size cluster_size_x * cluster_size_y * sizeof(T)

Parameters:
  • x – x-coordinate of the cluster

  • y – y-coordinate of the cluster

  • data – pointer to the data of the cluster

inline ClusterVector &operator+=(const ClusterVector &other)
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()

Return the maximum sum of the 2x2 subclusters in each cluster.

Warning

Only 3x3 clusters are supported for the 2x2 sum.

Throws:

std::runtime_error – if the cluster size is not 3x3

Returns:

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

inline size_t size() const

Return the number of clusters in the vector.

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 size_t item_size() const

Return the size in bytes of a single cluster.

inline size_t element_offset(size_t i) const

Return the offset in bytes for the i-th cluster.

inline std::byte *element_ptr(size_t i)

Return a pointer to the i-th cluster.

inline const std::byte *element_ptr(size_t i) const

Return a pointer to the i-th cluster.

inline size_t cluster_size_x() const
inline size_t cluster_size_y() const
inline std::byte *data()
inline std::byte const *data() const
template<typename V>
inline V &at(size_t i)

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

Template Parameters:

V – type of the cluster

inline const std::string_view fmt_base() const
inline uint64_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(uint64_t frame_number)
inline void resize(size_t new_size)

Resize the vector to contain new_size clusters. If new_size is greater than the current capacity, a new buffer is allocated. If the size is smaller no memory is freed, size is just updated.

Warning

The additional clusters are not initialized

Parameters:

new_size – new size of the vector