Struct Grid

Struct Documentation

struct Grid

A 2D grid of data.

Public Functions

FoxgloveError encode(uint8_t *ptr, size_t len, size_t *encoded_len)

Encoded the Grid as protobuf to the provided buffer.

On success, writes the serialized length to *encoded_len. If the provided buffer has insufficient capacity, writes the required capacity to *encoded_len and returns FoxgloveError::BufferTooShort. If the message cannot be encoded, writes the reason to stderr and returns FoxgloveError::EncodeError.

Parameters:
  • ptr – the destination buffer. must point to at least len valid bytes.

  • len – the length of the destination buffer.

  • encoded_len – where the serialized length or required capacity will be written to.

Public Members

std::optional<Timestamp> timestamp

Timestamp of grid.

std::string frame_id

Frame of reference.

std::optional<Pose> pose

Origin of grid’s corner relative to frame of reference; grid is positioned in the x-y plane relative to this origin.

uint32_t column_count = 0

Number of grid columns.

std::optional<Vector2> cell_size

Size of single grid cell along x and y axes, relative to pose

uint32_t row_stride = 0

Number of bytes between rows in data

uint32_t cell_stride = 0

Number of bytes between cells within a row in data

std::vector<PackedElementField> fields

Fields in data. red, green, blue, and alpha are optional for customizing the grid’s color.

To enable RGB color visualization in the 3D panel, include all four of these fields in your fields array:

  • red - Red channel value

  • green - Green channel value

  • blue - Blue channel value

  • alpha - Alpha/transparency channel value

note: All four fields must be present with these exact names for RGB visualization to work. The order of fields doesn’t matter, but the names must match exactly.

Recommended type: UINT8 (0-255 range) for standard 8-bit color channels.

Example field definitions:

RGB color only:

javascript @brief fields: [ @brief { name: "red", offset: 0, type: NumericType.UINT8 }, @brief { name: "green", offset: 1, type: NumericType.UINT8 }, @brief { name: "blue", offset: 2, type: NumericType.UINT8 }, @brief { name: "alpha", offset: 3, type: NumericType.UINT8 }, @brief ]; @brief

RGB color with elevation (for 3D terrain visualization):

javascript @brief fields: [ @brief { name: "red", offset: 0, type: NumericType.UINT8 }, @brief { name: "green", offset: 1, type: NumericType.UINT8 }, @brief { name: "blue", offset: 2, type: NumericType.UINT8 }, @brief { name: "alpha", offset: 3, type: NumericType.UINT8 }, @brief { name: "elevation", offset: 4, type: NumericType.FLOAT32 }, @brief ]; @brief

When these fields are present, the 3D panel will offer additional “Color Mode” options including “RGBA (separate fields)” to visualize the RGB data directly. For elevation visualization, set the “Elevation field” to your elevation layer name.

std::vector<std::byte> data

Grid cell data, interpreted using fields, in row-major (y-major) order.

For the data element starting at byte offset i, the coordinates of its corner closest to the origin will be:

  • y = i / row_stride * cell_size.y

  • x = (i % row_stride) / cell_stride * cell_size.x

Public Static Functions

static Schema schema()

Get the Grid schema.

The schema data returned is statically allocated.