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

Move-only container that stores fixed-size clusters contiguously.

The pixel type, cluster dimensions, and coordinate type are determined by the Cluster specialization supplied as the template argument.

Note

push_back, reserve, and resize can invalidate pointers, references, and iterators 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

  • ClusterSizeX – cluster size in the x dimension

  • ClusterSizeY – cluster size in the y dimension

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

Public Types

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

Public Functions

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

Construct a new ClusterVector object.

Parameters:
  • capacity – minimum initial capacity 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

ClusterVector(ClusterVector &&other) noexcept = default
ClusterVector &operator=(ClusterVector &&other) noexcept = default
inline ClusterVector operator()(NDView<bool, 1> mask)

Return a filtered copy selected by a one-dimensional Boolean mask.

Parameters:

mask – boolean 1d mask true if element in ClusterVector will be included

Throws:

std::runtime_error – if the mask length differs from size()

Returns:

ClusterVector containing the selected clusters in their original order and with the original frame number

inline std::vector<T> sum()

Sum the pixels in each cluster.

Returns:

One sum for every cluster, in container order

inline std::vector<Sum_index_pair<T, corner>> sum_2x2()

Find the highest-sum center-adjacent 2x2 subcluster in each cluster.

Returns:

One sum and corner-index pair for every cluster, in container order

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)

Change the number of stored clusters.

Note

Growing the vector value-initializes new clusters and can invalidate pointers, references, and iterators.

Parameters:

size – new number of clusters

inline void push_back(const ClusterType &cluster)

Append a cluster to the vector.

Note

Reallocation invalidates pointers, references, iterators, and zero-copy NumPy views of the storage.

Parameters:

cluster – cluster to append

inline ClusterVector &operator+=(const ClusterVector &other)

Append all clusters from another vector.

Note

The frame number of this vector is unchanged.

Warning

other must not refer to this vector.

Parameters:

other – vector whose clusters are appended

Returns:

Reference to this vector

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

Return the cluster size in the x dimension.

inline uint8_t cluster_size_y() const

Return the cluster size in the y dimension.

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 one stored cluster, including padding.

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

Return a reference to the i-th cluster without bounds checking.

Parameters:

i – zero-based cluster index

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)

Set the signed 32-bit frame number associated with the clusters.

Parameters:

frame_number – frame number, or 0 for clusters from multiple frames

Private Members

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

Free Functions:

template<typename T, uint8_t ClusterSizeX, uint8_t ClusterSizeY, typename CoordType>
ClusterVector<Cluster<T, 3, 3, CoordType>> aare::reduce_to_3x3(const ClusterVector<Cluster<T, ClusterSizeX, ClusterSizeY, CoordType>> &cv)

Reduce every cluster to the 3x3 block around its center index.

Note

Coordinates are preserved.

Parameters:

cv – ClusterVector containing clusters to reduce

Pre:

ClusterSizeX and ClusterSizeY must both be at least 3, and at least one must be greater than 3.

Returns:

ClusterVector of 3x3 clusters in the original order and with the original frame number

template<typename T, uint8_t ClusterSizeX, uint8_t ClusterSizeY, typename CoordType>
ClusterVector<Cluster<T, 2, 2, CoordType>> aare::reduce_to_2x2(const ClusterVector<Cluster<T, ClusterSizeX, ClusterSizeY, CoordType>> &cv)

Reduce every cluster to its highest-sum center-adjacent 2x2 block.

Note

The cluster is filled using row major ordering starting at the top-left (thus for a max subcluster in the top left cornern the photon hit is at the fourth position)

Parameters:

cv – ClusterVector containing clusters to reduce

Returns:

ClusterVector of 2x2 clusters in the original order and with the original frame number