Class AttributeLayout

Class Documentation

class AttributeLayout

Runtime description of the attribute payload a ouster::sdk::core::VoxelHashMap stores next to each point’s position.

A layout turns an ordered list of AttributeSpec into a packed record: every point in the map owns stride() contiguous bytes, and attribute i occupies spec.count * attribute_type_size(spec.type) bytes starting at byte_offset(i). Records are packed without padding, so they are read and written through std::memcpy rather than by casting.

The same layout also describes the double-valued view of a point used by the map’s Eigen-based API: attribute i covers the count doubles starting at element_offset(i) of the attribute portion of a point (i.e. column 3 + element_offset(i) of a pointcloud row). encode and decode convert between the two views.

A default-constructed layout has no attributes.

Public Functions

AttributeLayout() = default

Construct an empty layout (no attributes).

explicit AttributeLayout(std::vector<AttributeSpec> specs)

Construct a layout from an ordered list of attributes.

Parameters:

specs[in] The attributes, in the order they appear in a record.

Throws:

std::invalid_argument – if any spec has a count of 0.

inline const std::vector<AttributeSpec> &specs() const

The attributes making up this layout.

Returns:

The attribute specs, in record order.

inline std::size_t byte_offset(std::size_t spec_index) const

Byte offset of attribute spec_index within a packed record.

Parameters:

spec_index[in] Index into specs.

Throws:

std::out_of_range – if spec_index is out of range.

Returns:

Offset in bytes from the start of the record.

inline std::size_t byte_size(std::size_t spec_index) const

Size in bytes of attribute spec_index.

Parameters:

spec_index[in] Index into specs.

Throws:

std::out_of_range – if spec_index is out of range.

Returns:

Size in bytes of the attribute’s elements.

inline std::size_t element_offset(std::size_t spec_index) const

Index of attribute spec_index's first scalar in the double-valued view of a point’s attributes.

Parameters:

spec_index[in] Index into specs.

Throws:

std::out_of_range – if spec_index is out of range.

Returns:

Offset in scalars from the start of the attribute block.

inline std::size_t stride() const

Size in bytes of one packed attribute record.

Returns:

The record stride; 0 when the layout has no attributes.

inline std::size_t element_count() const

Total number of scalars across all attributes.

Returns:

The number of doubles the attributes occupy in a point vector.

inline bool empty() const

Whether the layout has no attributes at all.

Returns:

True when there are no attributes.

inline bool all_double() const

Whether every attribute is a double.

True for empty layouts and for those built by all_double; encode and decode then reduce to a single memcpy.

Returns:

True when no narrowing conversion is involved.

void encode(const double *elements, std::uint8_t *record) const

Pack element_count doubles into a record of stride bytes.

Values are converted to each attribute’s type; integer attributes are rounded to nearest and clamped to the type’s range, so averaging modes produce a representable value rather than wrapping.

Parameters:
void decode(const std::uint8_t *record, double *elements) const

Unpack a record of stride bytes into element_count doubles.

Parameters:
  • record[in] Pointer to stride readable bytes.

  • elements[out] Pointer to element_count writable doubles.

void decode_add(const std::uint8_t *record, double *elements) const

Add the values in record to elements element-wise.

Used by the averaging bucket, which accumulates in double regardless of the stored attribute types.

Parameters:
  • record[in] Pointer to stride readable bytes.

  • elements[inout] Pointer to element_count doubles to add into.

void check_attribute(std::size_t spec_index, AttributeType type, std::size_t count) const

Throw unless attribute spec_index is stored as count scalars of type.

Parameters:
  • spec_index[in] Index into specs.

  • type[in] The expected scalar type.

  • count[in] The expected number of scalars per point.

Throws:

std::invalid_argument – if spec_index is out of range, or the attribute’s type or count differs.

template<typename T>
inline void pack(std::size_t spec_index, const T *values, std::size_t value_count, Eigen::Ref<AttributeRecords> records) const

Write attribute spec_index of every record from typed values.

Point i’s count values are read from values[i * count] onward, so a scalar attribute is one value per point and e.g. NORMALS {F32, 3} is three consecutive floats per point. The other attributes’ bytes in records are left untouched.

Template Parameters:

T – The C++ type the attribute is stored as &#8212; exactly, e.g. std::uint32_t for U32; a same-sized float is rejected. One of the eleven types AttributeType lists; any other type fails to compile.

Parameters:
  • spec_index[in] Which attribute to write.

  • values[in] value_count values.

  • value_count[in] Must equal records.rows() * count.

  • records[inout] N x stride packed records.

Throws:

std::invalid_argument – if spec_index is out of range, T is not the stored type, value_count is wrong, or records is not stride bytes wide.

template<typename T>
inline void pack(std::size_t spec_index, const std::vector<T> &values, Eigen::Ref<AttributeRecords> records) const

pack() from a vector of records.rows() * count values.

Parameters:
  • spec_index[in] Which attribute to write.

  • values[in] records.rows() * count values.

  • records[inout] N x stride packed records.

Throws:

std::invalid_argument – as the pointer overload.

template<typename T>
inline void unpack(std::size_t spec_index, const Eigen::Ref<const AttributeRecords> &records, T *values, std::size_t value_count) const

Read attribute spec_index of every record into typed values; the inverse of pack(), with the same value order.

Template Parameters:

T – The C++ type the attribute is stored as; see pack().

Parameters:
  • spec_index[in] Which attribute to read.

  • records[in] N x stride packed records.

  • values[out] value_count writable values.

  • value_count[in] Must equal records.rows() * count.

Throws:

std::invalid_argument – as pack().

template<typename T>
inline std::vector<T> unpack(std::size_t spec_index, const Eigen::Ref<const AttributeRecords> &records) const

unpack() into a new vector.

Parameters:
  • spec_index[in] Which attribute to read.

  • records[in] N x stride packed records.

Throws:

std::invalid_argument – as pack().

Returns:

records.rows() * count values.

bool operator==(const AttributeLayout &other) const

Equality: same attributes in the same order.

Parameters:

other[in] Layout to compare against.

Returns:

True when the layouts are identical.

inline bool operator!=(const AttributeLayout &other) const

Inequality; see operator==.

Parameters:

other[in] Layout to compare against.

Returns:

True when the layouts differ.

Public Static Functions

static AttributeLayout all_double(std::size_t element_count)

Build a layout of element_count double attributes.

Parameters:

element_count[in] Number of double attributes.

Returns:

The corresponding layout.