Class AttributeLayout¶
Defined in File attribute_layout.h
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 attributeioccupiesspec.count * attribute_type_size(spec.type)bytes starting atbyte_offset(i). Records are packed without padding, so they are read and written throughstd::memcpyrather than by casting.The same layout also describes the double-valued view of a point used by the map’s
Eigen-based API: attributeicovers thecountdoubles starting atelement_offset(i)of the attribute portion of a point (i.e. column3 + 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_indexwithin a packed record.- Parameters:
spec_index[in] Index into specs.
- Throws:
std::out_of_range – if
spec_indexis 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_indexis 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'sfirst 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_indexis 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:
elements[in] Pointer to element_count doubles.
record[out] Pointer to stride writable bytes.
-
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
recordtoelementselement-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_indexis stored ascountscalars oftype.- 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_indexis 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_indexof every record from typed values.Point
i’scountvalues are read fromvalues[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 inrecordsare left untouched.- Template Parameters:
T – The C++ type the attribute is stored as — exactly, e.g.
std::uint32_tfor U32; a same-sizedfloatis 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_countvalues.value_count[in] Must equal
records.rows() * count.records[inout]
Nx stride packed records.
- Throws:
std::invalid_argument – if
spec_indexis out of range,Tis not the stored type,value_countis wrong, orrecordsis 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 ofrecords.rows() * countvalues.- Parameters:
spec_index[in] Which attribute to write.
values[in]
records.rows() * countvalues.records[inout]
Nx 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_indexof every record into typed values; the inverse ofpack(), 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]
Nx stride packed records.values[out]
value_countwritable 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.
-
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_countdouble attributes.- Parameters:
element_count[in] Number of double attributes.
- Returns:
The corresponding layout.
-
AttributeLayout() = default¶