Rerun C++ SDK
Loading...
Searching...
No Matches
grid_map.hpp
1// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/cpp/mod.rs
2// Based on "crates/build/re_type_definitions/rerun/archetypes/grid_map.def.rs".
3
4#pragma once
5
6#include "../archetype_utils.hpp"
7#include "../collection.hpp"
8#include "../component_batch.hpp"
9#include "../component_column.hpp"
10#include "../components/cell_size.hpp"
11#include "../components/colormap.hpp"
12#include "../components/draw_order.hpp"
13#include "../components/image_buffer.hpp"
14#include "../components/image_format.hpp"
15#include "../components/opacity.hpp"
16#include "../components/rotation_axis_angle.hpp"
17#include "../components/rotation_quat.hpp"
18#include "../components/translation3d.hpp"
19#include "../result.hpp"
20
21#include <cstdint>
22#include <optional>
23#include <utility>
24#include <vector>
25
26namespace rerun::archetypes {
27 /// **Archetype**: A 2D grid map stored as raster data in an image buffer, with a cell size in scene units and pose.
28 ///
29 /// This archetype is intended for robotics applications like occupancy maps or navigation costmaps,
30 /// but can also be useful for other use cases where an image buffer needs to be placed in a scene.
31 ///
32 /// ## Example
33 ///
34 /// ### Simple occupancy grid map
35 /// ```cpp
36 /// #include <rerun.hpp>
37 ///
38 /// #include <vector>
39 ///
40 /// int main(int argc, char* argv[]) {
41 /// const auto rec = rerun::RecordingStream("rerun_example_grid_map");
42 /// rec.spawn().exit_on_failure();
43 ///
44 /// const size_t width = 64;
45 /// const size_t height = 64;
46 /// const float cell_size = 0.1f;
47 ///
48 /// // Create a synthetic image with ROS `nav_msgs/OccupancyGrid` cell value conventions:
49 /// // -1 (255) unknown, 0 free, 100 occupied.
50 /// std::vector<uint8_t> grid(width * height, 255);
51 /// for (size_t y = 8; y <56; ++y) {
52 /// for (size_t x = 8; x <56; ++x) {
53 /// grid[y * width + x] = 0;
54 /// }
55 /// }
56 /// for (size_t y = 20; y <44; ++y) {
57 /// for (size_t x = 20; x <44; ++x) {
58 /// grid[y * width + x] = 100;
59 /// }
60 /// }
61 ///
62 /// rec.log(
63 /// "world/map",
64 /// rerun::archetypes::GridMap()
65 /// .with_data(rerun::ImageBuffer(grid))
66 /// .with_format(rerun::components::ImageFormat(
67 /// {width, height},
68 /// rerun::ColorModel::L,
69 /// rerun::ChannelDatatype::U8
70 /// ))
71 /// .with_cell_size(cell_size)
72 /// .with_translation(
73 /// {-(static_cast<float>(width) * cell_size) / 2.0f,
74 /// -(static_cast<float>(height) * cell_size) / 2.0f,
75 /// 0.0f}
76 /// )
77 /// .with_colormap(rerun::Colormap::RvizMap)
78 /// );
79 /// }
80 /// ```
81 struct GridMap {
82 /// The raw grid data.
83 std::optional<ComponentBatch> data;
84
85 /// The format of the grid's image data.
86 std::optional<ComponentBatch> format;
87
88 /// The scene unit size of a single grid cell (e.g. m / pixel).
89 ///
90 /// Defaults to 0.01 scene units per pixel.
91 std::optional<ComponentBatch> cell_size;
92
93 /// Translation of the lower-left corner of the grid map in space.
94 ///
95 /// Together with `components::RotationAxisAngle` or `components::RotationQuat`, this defines the pose of the
96 /// lower-left image corner relative to the map's parent coordinate frame.
97 ///
98 /// If not set, the lower-left image corner is placed at origin of the map's parent coordinate frame.
99 std::optional<ComponentBatch> translation;
100
101 /// Rotation of the lower-left corner of the grid map in space via axis + angle.
102 ///
103 /// Together with `components::Translation3D`, this defines the pose of the
104 /// lower-left image corner relative to the map's parent coordinate frame.
105 ///
106 /// Note: either this or `components::RotationQuat` can be set to specify the grid map's rotation, but not both.
107 /// If both this and `components::RotationQuat` are set, this is ignored in favor of the quaternion.
108 std::optional<ComponentBatch> rotation_axis_angle;
109
110 /// Rotation of the lower-left corner of the grid map in space via quaternion.
111 ///
112 /// Together with `components::Translation3D`, this defines the pose of the
113 /// lower-left image corner relative to the map's parent coordinate frame.
114 std::optional<ComponentBatch> quaternion;
115
116 /// Opacity of the grid map texture after all image decoding and colormap application.
117 ///
118 /// Defaults to 1.0 (fully opaque).
119 std::optional<ComponentBatch> opacity;
120
121 /// Optional draw order for layering multiple grid maps that overlap in space.
122 ///
123 /// Higher values are drawn on top of lower values.
124 std::optional<ComponentBatch> draw_order;
125
126 /// Colormap to use for rendering single-channel grid maps.
127 ///
128 /// If not set, the grid map is shown using the underlying `components::ImageFormat`
129 /// interpretation.
130 std::optional<ComponentBatch> colormap;
131
132 public:
133 /// The name of the archetype as used in `ComponentDescriptor`s.
134 static constexpr const char ArchetypeName[] = "rerun.archetypes.GridMap";
135
136 /// `ComponentDescriptor` for the `data` field.
137 static constexpr auto Descriptor_data = ComponentDescriptor(
139 );
140 /// `ComponentDescriptor` for the `format` field.
141 static constexpr auto Descriptor_format = ComponentDescriptor(
143 );
144 /// `ComponentDescriptor` for the `cell_size` field.
147 );
148 /// `ComponentDescriptor` for the `translation` field.
150 ArchetypeName, "GridMap:translation",
152 );
153 /// `ComponentDescriptor` for the `rotation_axis_angle` field.
155 ArchetypeName, "GridMap:rotation_axis_angle",
157 );
158 /// `ComponentDescriptor` for the `quaternion` field.
160 ArchetypeName, "GridMap:quaternion",
162 );
163 /// `ComponentDescriptor` for the `opacity` field.
166 );
167 /// `ComponentDescriptor` for the `draw_order` field.
169 ArchetypeName, "GridMap:draw_order",
171 );
172 /// `ComponentDescriptor` for the `colormap` field.
175 );
176
177 public:
178 GridMap() = default;
179 GridMap(GridMap&& other) = default;
180 GridMap(const GridMap& other) = default;
181 GridMap& operator=(const GridMap& other) = default;
182 GridMap& operator=(GridMap&& other) = default;
183
184 /// Update only some specific fields of a `GridMap`.
186 return GridMap();
187 }
188
189 /// Clear all the fields of a `GridMap`.
191
192 /// The raw grid data.
194 data = ComponentBatch::from_loggable(_data, Descriptor_data).value_or_throw();
195 return std::move(*this);
196 }
197
198 /// This method makes it possible to pack multiple `data` in a single component batch.
199 ///
200 /// This only makes sense when used in conjunction with `columns`. `with_data` should
201 /// be used when logging a single row's worth of data.
203 data = ComponentBatch::from_loggable(_data, Descriptor_data).value_or_throw();
204 return std::move(*this);
205 }
206
207 /// The format of the grid's image data.
209 format = ComponentBatch::from_loggable(_format, Descriptor_format).value_or_throw();
210 return std::move(*this);
211 }
212
213 /// This method makes it possible to pack multiple `format` in a single component batch.
214 ///
215 /// This only makes sense when used in conjunction with `columns`. `with_format` should
216 /// be used when logging a single row's worth of data.
218 format = ComponentBatch::from_loggable(_format, Descriptor_format).value_or_throw();
219 return std::move(*this);
220 }
221
222 /// The scene unit size of a single grid cell (e.g. m / pixel).
223 ///
224 /// Defaults to 0.01 scene units per pixel.
226 cell_size =
227 ComponentBatch::from_loggable(_cell_size, Descriptor_cell_size).value_or_throw();
228 return std::move(*this);
229 }
230
231 /// This method makes it possible to pack multiple `cell_size` in a single component batch.
232 ///
233 /// This only makes sense when used in conjunction with `columns`. `with_cell_size` should
234 /// be used when logging a single row's worth of data.
236 cell_size =
237 ComponentBatch::from_loggable(_cell_size, Descriptor_cell_size).value_or_throw();
238 return std::move(*this);
239 }
240
241 /// Translation of the lower-left corner of the grid map in space.
242 ///
243 /// Together with `components::RotationAxisAngle` or `components::RotationQuat`, this defines the pose of the
244 /// lower-left image corner relative to the map's parent coordinate frame.
245 ///
246 /// If not set, the lower-left image corner is placed at origin of the map's parent coordinate frame.
249 .value_or_throw();
250 return std::move(*this);
251 }
252
253 /// This method makes it possible to pack multiple `translation` in a single component batch.
254 ///
255 /// This only makes sense when used in conjunction with `columns`. `with_translation` should
256 /// be used when logging a single row's worth of data.
259 ) && {
261 .value_or_throw();
262 return std::move(*this);
263 }
264
265 /// Rotation of the lower-left corner of the grid map in space via axis + angle.
266 ///
267 /// Together with `components::Translation3D`, this defines the pose of the
268 /// lower-left image corner relative to the map's parent coordinate frame.
269 ///
270 /// Note: either this or `components::RotationQuat` can be set to specify the grid map's rotation, but not both.
271 /// If both this and `components::RotationQuat` are set, this is ignored in favor of the quaternion.
273 const rerun::components::RotationAxisAngle& _rotation_axis_angle
274 ) && {
277 .value_or_throw();
278 return std::move(*this);
279 }
280
281 /// This method makes it possible to pack multiple `rotation_axis_angle` in a single component batch.
282 ///
283 /// This only makes sense when used in conjunction with `columns`. `with_rotation_axis_angle` should
284 /// be used when logging a single row's worth of data.
286 const Collection<rerun::components::RotationAxisAngle>& _rotation_axis_angle
287 ) && {
290 .value_or_throw();
291 return std::move(*this);
292 }
293
294 /// Rotation of the lower-left corner of the grid map in space via quaternion.
295 ///
296 /// Together with `components::Translation3D`, this defines the pose of the
297 /// lower-left image corner relative to the map's parent coordinate frame.
299 quaternion =
300 ComponentBatch::from_loggable(_quaternion, Descriptor_quaternion).value_or_throw();
301 return std::move(*this);
302 }
303
304 /// This method makes it possible to pack multiple `quaternion` in a single component batch.
305 ///
306 /// This only makes sense when used in conjunction with `columns`. `with_quaternion` should
307 /// be used when logging a single row's worth of data.
309 ) && {
310 quaternion =
311 ComponentBatch::from_loggable(_quaternion, Descriptor_quaternion).value_or_throw();
312 return std::move(*this);
313 }
314
315 /// Opacity of the grid map texture after all image decoding and colormap application.
316 ///
317 /// Defaults to 1.0 (fully opaque).
319 opacity = ComponentBatch::from_loggable(_opacity, Descriptor_opacity).value_or_throw();
320 return std::move(*this);
321 }
322
323 /// This method makes it possible to pack multiple `opacity` in a single component batch.
324 ///
325 /// This only makes sense when used in conjunction with `columns`. `with_opacity` should
326 /// be used when logging a single row's worth of data.
328 opacity = ComponentBatch::from_loggable(_opacity, Descriptor_opacity).value_or_throw();
329 return std::move(*this);
330 }
331
332 /// Optional draw order for layering multiple grid maps that overlap in space.
333 ///
334 /// Higher values are drawn on top of lower values.
336 draw_order =
337 ComponentBatch::from_loggable(_draw_order, Descriptor_draw_order).value_or_throw();
338 return std::move(*this);
339 }
340
341 /// This method makes it possible to pack multiple `draw_order` in a single component batch.
342 ///
343 /// This only makes sense when used in conjunction with `columns`. `with_draw_order` should
344 /// be used when logging a single row's worth of data.
346 ) && {
347 draw_order =
348 ComponentBatch::from_loggable(_draw_order, Descriptor_draw_order).value_or_throw();
349 return std::move(*this);
350 }
351
352 /// Colormap to use for rendering single-channel grid maps.
353 ///
354 /// If not set, the grid map is shown using the underlying `components::ImageFormat`
355 /// interpretation.
357 colormap =
358 ComponentBatch::from_loggable(_colormap, Descriptor_colormap).value_or_throw();
359 return std::move(*this);
360 }
361
362 /// This method makes it possible to pack multiple `colormap` in a single component batch.
363 ///
364 /// This only makes sense when used in conjunction with `columns`. `with_colormap` should
365 /// be used when logging a single row's worth of data.
367 colormap =
368 ComponentBatch::from_loggable(_colormap, Descriptor_colormap).value_or_throw();
369 return std::move(*this);
370 }
371
372 /// Partitions the component data into multiple sub-batches.
373 ///
374 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
375 /// instead, via `ComponentBatch::partitioned`.
376 ///
377 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
378 ///
379 /// The specified `lengths` must sum to the total length of the component batch.
381 return detail::partition_batches(
382 {&data,
383 &format,
384 &cell_size,
387 &quaternion,
388 &opacity,
389 &draw_order,
390 &colormap},
391 lengths_
392 )
393 .value_or_throw();
394 }
395
396 /// Partitions the component data into unit-length sub-batches.
397 ///
398 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
399 /// where `n` is automatically guessed.
401 return detail::partition_batches_of_unit_length({&data,
402 &format,
403 &cell_size,
406 &quaternion,
407 &opacity,
408 &draw_order,
409 &colormap})
410 .value_or_throw();
411 }
412 };
413
414} // namespace rerun::archetypes
415
416namespace rerun {
417 /// \private
418 template <typename T>
419 struct AsComponents;
420
421 /// \private
422 template <>
423 struct AsComponents<archetypes::GridMap> {
424 /// Serialize all set component batches.
425 static Result<Collection<ComponentBatch>> as_batches(const archetypes::GridMap& archetype) {
426 return detail::collect_batches(
427 {&archetype.data,
428 &archetype.format,
429 &archetype.cell_size,
430 &archetype.translation,
431 &archetype.rotation_axis_angle,
432 &archetype.quaternion,
433 &archetype.opacity,
434 &archetype.draw_order,
435 &archetype.colormap}
436 );
437 }
438 };
439} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:49
All built-in archetypes. See Types in the Rerun manual.
Definition rerun.hpp:90
Colormap
Component: Colormap for mapping scalar values within a given range to a color.
Definition colormap.hpp:28
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:26
static Result< ComponentBatch > from_loggable(const rerun::Collection< T > &components, const ComponentDescriptor &descriptor)
Creates a new component batch from a collection of component instances.
Definition component_batch.hpp:46
A ComponentDescriptor fully describes the semantics of a column of data.
Definition component_descriptor.hpp:16
The Loggable trait is used by all built-in implementation of rerun::AsComponents to serialize a colle...
Definition loggable.hpp:11
Archetype: A 2D grid map stored as raster data in an image buffer, with a cell size in scene units an...
Definition grid_map.hpp:81
GridMap with_many_rotation_axis_angle(const Collection< rerun::components::RotationAxisAngle > &_rotation_axis_angle) &&
This method makes it possible to pack multiple rotation_axis_angle in a single component batch.
Definition grid_map.hpp:285
GridMap with_translation(const rerun::components::Translation3D &_translation) &&
Translation of the lower-left corner of the grid map in space.
Definition grid_map.hpp:247
std::optional< ComponentBatch > quaternion
Rotation of the lower-left corner of the grid map in space via quaternion.
Definition grid_map.hpp:114
static constexpr auto Descriptor_rotation_axis_angle
ComponentDescriptor for the rotation_axis_angle field.
Definition grid_map.hpp:154
std::optional< ComponentBatch > rotation_axis_angle
Rotation of the lower-left corner of the grid map in space via axis + angle.
Definition grid_map.hpp:108
static GridMap update_fields()
Update only some specific fields of a GridMap.
Definition grid_map.hpp:185
GridMap with_many_colormap(const Collection< rerun::components::Colormap > &_colormap) &&
This method makes it possible to pack multiple colormap in a single component batch.
Definition grid_map.hpp:366
GridMap with_many_quaternion(const Collection< rerun::components::RotationQuat > &_quaternion) &&
This method makes it possible to pack multiple quaternion in a single component batch.
Definition grid_map.hpp:308
std::optional< ComponentBatch > cell_size
The scene unit size of a single grid cell (e.g.
Definition grid_map.hpp:91
GridMap with_many_translation(const Collection< rerun::components::Translation3D > &_translation) &&
This method makes it possible to pack multiple translation in a single component batch.
Definition grid_map.hpp:257
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition grid_map.hpp:134
std::optional< ComponentBatch > colormap
Colormap to use for rendering single-channel grid maps.
Definition grid_map.hpp:130
static constexpr auto Descriptor_translation
ComponentDescriptor for the translation field.
Definition grid_map.hpp:149
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
Definition grid_map.hpp:400
GridMap with_many_opacity(const Collection< rerun::components::Opacity > &_opacity) &&
This method makes it possible to pack multiple opacity in a single component batch.
Definition grid_map.hpp:327
std::optional< ComponentBatch > format
The format of the grid's image data.
Definition grid_map.hpp:86
GridMap with_quaternion(const rerun::components::RotationQuat &_quaternion) &&
Rotation of the lower-left corner of the grid map in space via quaternion.
Definition grid_map.hpp:298
std::optional< ComponentBatch > translation
Translation of the lower-left corner of the grid map in space.
Definition grid_map.hpp:99
GridMap with_many_cell_size(const Collection< rerun::components::CellSize > &_cell_size) &&
This method makes it possible to pack multiple cell_size in a single component batch.
Definition grid_map.hpp:235
GridMap with_many_format(const Collection< rerun::components::ImageFormat > &_format) &&
This method makes it possible to pack multiple format in a single component batch.
Definition grid_map.hpp:217
static constexpr auto Descriptor_format
ComponentDescriptor for the format field.
Definition grid_map.hpp:141
std::optional< ComponentBatch > opacity
Opacity of the grid map texture after all image decoding and colormap application.
Definition grid_map.hpp:119
GridMap with_draw_order(const rerun::components::DrawOrder &_draw_order) &&
Optional draw order for layering multiple grid maps that overlap in space.
Definition grid_map.hpp:335
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
Definition grid_map.hpp:380
GridMap with_colormap(const rerun::components::Colormap &_colormap) &&
Colormap to use for rendering single-channel grid maps.
Definition grid_map.hpp:356
static constexpr auto Descriptor_quaternion
ComponentDescriptor for the quaternion field.
Definition grid_map.hpp:159
static constexpr auto Descriptor_draw_order
ComponentDescriptor for the draw_order field.
Definition grid_map.hpp:168
GridMap with_many_data(const Collection< rerun::components::ImageBuffer > &_data) &&
This method makes it possible to pack multiple data in a single component batch.
Definition grid_map.hpp:202
GridMap with_rotation_axis_angle(const rerun::components::RotationAxisAngle &_rotation_axis_angle) &&
Rotation of the lower-left corner of the grid map in space via axis + angle.
Definition grid_map.hpp:272
GridMap with_many_draw_order(const Collection< rerun::components::DrawOrder > &_draw_order) &&
This method makes it possible to pack multiple draw_order in a single component batch.
Definition grid_map.hpp:345
std::optional< ComponentBatch > data
The raw grid data.
Definition grid_map.hpp:83
GridMap with_format(const rerun::components::ImageFormat &_format) &&
The format of the grid's image data.
Definition grid_map.hpp:208
GridMap with_data(const rerun::components::ImageBuffer &_data) &&
The raw grid data.
Definition grid_map.hpp:193
static constexpr auto Descriptor_opacity
ComponentDescriptor for the opacity field.
Definition grid_map.hpp:164
static GridMap clear_fields()
Clear all the fields of a GridMap.
std::optional< ComponentBatch > draw_order
Optional draw order for layering multiple grid maps that overlap in space.
Definition grid_map.hpp:124
GridMap with_opacity(const rerun::components::Opacity &_opacity) &&
Opacity of the grid map texture after all image decoding and colormap application.
Definition grid_map.hpp:318
static constexpr auto Descriptor_colormap
ComponentDescriptor for the colormap field.
Definition grid_map.hpp:173
static constexpr auto Descriptor_data
ComponentDescriptor for the data field.
Definition grid_map.hpp:137
static constexpr auto Descriptor_cell_size
ComponentDescriptor for the cell_size field.
Definition grid_map.hpp:145
GridMap with_cell_size(const rerun::components::CellSize &_cell_size) &&
The scene unit size of a single grid cell (e.g.
Definition grid_map.hpp:225
Component: The metric size of one grid cell in local scene units.
Definition cell_size.hpp:16
Component: Draw order of 2D elements.
Definition draw_order.hpp:30
Component: A buffer that is known to store image data.
Definition image_buffer.hpp:18
Component: The metadata describing the contents of a components::ImageBuffer.
Definition image_format.hpp:14
Component: Degree of transparency ranging from 0.0 (fully transparent) to 1.0 (fully opaque).
Definition opacity.hpp:17
Component: 3D rotation represented by a rotation around a given axis.
Definition rotation_axis_angle.hpp:17
Component: A 3D rotation expressed as a quaternion.
Definition rotation_quat.hpp:18
Component: A translation vector in 3D space.
Definition translation3d.hpp:15