Struct AttributedPointCloud

Struct Documentation

struct AttributedPointCloud

A pointcloud whose attributes keep their original types.

Returned by ouster::sdk::core::VoxelHashMap::pointcloud. The two members are parallel: row i of xyz is positioned by row i of attributes, whose bytes layout describes.

The accessors below decode attributes into typed C++ values, checking the requested types against layout at runtime; they never convert a value, only copy its bytes, so what comes out is bit-for-bit what went in.

Public Functions

std::size_t size() const

Number of points.

Returns:

The number of rows of xyz and attributes.

template<typename T>
inline void attribute(std::size_t spec_index, T *out, std::size_t out_count) const

Copy attribute spec_index of every point into out; see AttributeLayout::unpack().

Template Parameters:

T – The C++ type the attribute is stored as, e.g. std::uint32_t for an AttributeType::U32 attribute. It must match exactly: a same-sized but different type (float or std::int32_t for a U32) is rejected rather than reinterpreted.

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

  • out[out] out_count writable values, filled point by point: point i’s values start at out[i * count].

  • out_count[in] Must equal size() * count.

Throws:

std::invalid_argument – if spec_index is out of range, T is not the attribute’s stored type, out_count is wrong, or xyz and attributes disagree in shape.

template<typename T>
inline std::vector<T> attribute(std::size_t spec_index) const

Attribute spec_index of every point, in its stored type.

For a scalar attribute (count == 1) element i belongs to point i; for a multi-element one, e.g. NORMALS {F32, 3}, point i’s values are elements [i * count, (i + 1) * count).

Template Parameters:

T – The C++ type the attribute is stored as; see the overload above.

Parameters:

spec_index[in] Which attribute of layout to read.

Throws:

std::invalid_argument – if spec_index is out of range, T is not the attribute’s stored type, or xyz and attributes disagree in shape.

Returns:

size() * count values.

template<typename AttributesT, typename ...Fields>
inline std::vector<AttributesT> attributes_as(Fields AttributesT::*... fields) const

Every point’s attributes as a user-defined struct, verified field by field against layout.

fields lists the members of AttributesT that hold the layout’s attributes, in layout order. Each member must have the attribute’s stored type: a scalar for count == 1, or a C array / std::array of count scalars otherwise. Because every value is copied into its own member, AttributesT may have any padding or extra members:

struct Attrs { std::uint32_t range; std::uint8_t reflectivity; };
auto attrs = cloud.attributes_as<Attrs>(&Attrs::range, &Attrs::reflectivity);
Template Parameters:

AttributesT – Default-constructible struct to decode into.

Parameters:

fields[in] One pointer-to-member per attribute of layout.

Throws:

std::invalid_argument – if the number of fields, or any field’s type or element count, does not match layout, or xyz and attributes disagree in shape.

Returns:

One AttributesT per point.

template<typename AttributesT>
inline std::vector<AttributesT> attributes_as() const

Every point’s attributes as a packed struct mirroring the record.

Copies each record straight into an AttributesT, so the struct must reproduce the record byte for byte: the layout’s attributes in order, with no padding (records are packed, so {U32, U8} is 5 bytes, while a plain struct { std::uint32_t; std::uint8_t; } is usually 8). Declare it packed, e.g. with #pragma pack(push, 1). Only the size can be checked here; prefer the field-listing overload, which also checks every member’s type and needs no packing.

Template Parameters:

AttributesT – Trivially copyable struct of layout.stride() bytes.

Throws:

std::invalid_argument – if sizeof(AttributesT) != layout.stride(), or xyz and attributes disagree in shape.

Returns:

One AttributesT per point.

Public Members

AttributeLayout layout

Layout of each row of attributes.

ArrayX3dR xyz

N x 3 point positions.

AttributeRecords attributes

N x layout.stride() packed attribute records.