Rerun C++ SDK
Loading...
Searching...
No Matches
boxes2d.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/store/re_types/definitions/rerun/archetypes/boxes2d.fbs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../component_batch.hpp"
8#include "../component_column.hpp"
9#include "../components/class_id.hpp"
10#include "../components/color.hpp"
11#include "../components/draw_order.hpp"
12#include "../components/half_size2d.hpp"
13#include "../components/position2d.hpp"
14#include "../components/radius.hpp"
15#include "../components/show_labels.hpp"
16#include "../components/text.hpp"
17#include "../result.hpp"
18
19#include <cstdint>
20#include <optional>
21#include <utility>
22#include <vector>
23
24namespace rerun::archetypes {
25 /// **Archetype**: 2D boxes with half-extents and optional center, colors etc.
26 ///
27 /// ## Example
28 ///
29 /// ### Simple 2D boxes
30 /// ![image](https://static.rerun.io/box2d_simple/ac4424f3cf747382867649610cbd749c45b2020b/full.png)
31 ///
32 /// ```cpp
33 /// #include <rerun.hpp>
34 ///
35 /// int main() {
36 /// const auto rec = rerun::RecordingStream("rerun_example_box2d");
37 /// rec.spawn().exit_on_failure();
38 ///
39 /// rec.log("simple", rerun::Boxes2D::from_mins_and_sizes({{-1.f, -1.f}}, {{2.f, 2.f}}));
40 /// }
41 /// ```
42 struct Boxes2D {
43 /// All half-extents that make up the batch of boxes.
44 std::optional<ComponentBatch> half_sizes;
45
46 /// Optional center positions of the boxes.
47 std::optional<ComponentBatch> centers;
48
49 /// Optional colors for the boxes.
50 std::optional<ComponentBatch> colors;
51
52 /// Optional radii for the lines that make up the boxes.
53 std::optional<ComponentBatch> radii;
54
55 /// Optional text labels for the boxes.
56 ///
57 /// If there's a single label present, it will be placed at the center of the entity.
58 /// Otherwise, each instance will have its own label.
59 std::optional<ComponentBatch> labels;
60
61 /// Whether the text labels should be shown.
62 ///
63 /// If not set, labels will automatically appear when there is exactly one label for this entity
64 /// or the number of instances on this entity is under a certain threshold.
65 std::optional<ComponentBatch> show_labels;
66
67 /// An optional floating point value that specifies the 2D drawing order.
68 ///
69 /// Objects with higher values are drawn on top of those with lower values.
70 /// Defaults to `10.0`.
71 std::optional<ComponentBatch> draw_order;
72
73 /// Optional `components::ClassId`s for the boxes.
74 ///
75 /// The `components::ClassId` provides colors and labels if not specified explicitly.
76 std::optional<ComponentBatch> class_ids;
77
78 public:
79 /// The name of the archetype as used in `ComponentDescriptor`s.
80 static constexpr const char ArchetypeName[] = "rerun.archetypes.Boxes2D";
81
82 /// `ComponentDescriptor` for the `half_sizes` field.
84 ArchetypeName, "Boxes2D:half_sizes",
86 );
87 /// `ComponentDescriptor` for the `centers` field.
88 static constexpr auto Descriptor_centers = ComponentDescriptor(
90 );
91 /// `ComponentDescriptor` for the `colors` field.
92 static constexpr auto Descriptor_colors = ComponentDescriptor(
94 );
95 /// `ComponentDescriptor` for the `radii` field.
96 static constexpr auto Descriptor_radii = ComponentDescriptor(
98 );
99 /// `ComponentDescriptor` for the `labels` field.
100 static constexpr auto Descriptor_labels = ComponentDescriptor(
102 );
103 /// `ComponentDescriptor` for the `show_labels` field.
105 ArchetypeName, "Boxes2D:show_labels",
107 );
108 /// `ComponentDescriptor` for the `draw_order` field.
110 ArchetypeName, "Boxes2D:draw_order",
112 );
113 /// `ComponentDescriptor` for the `class_ids` field.
116 );
117
118 public: // START of extensions from boxes2d_ext.cpp:
119 /// Creates new `Boxes2D` with `half_sizes` centered around the local origin.
121 return Boxes2D().with_half_sizes(std::move(half_sizes));
122 }
123
124 /// Creates new `Boxes2D` with `centers` and `half_sizes`.
128 ) {
129 return Boxes2D()
130 .with_half_sizes(std::move(half_sizes))
131 .with_centers(std::move(centers));
132 }
133
134 /// Creates new `Boxes2D` with `half_sizes` created from (full) sizes.
135 ///
136 /// TODO(#3285): Does *not* preserve data as-is and instead creates half-sizes from the
137 /// input data.
138 static Boxes2D from_sizes(const std::vector<datatypes::Vec2D>& sizes);
139
140 /// Creates new `Boxes2D` with `centers` and `half_sizes` created from centers and (full)
141 /// sizes.
142 ///
143 /// TODO(#3285): Does *not* preserve data as-is and instead creates centers and half-sizes
144 /// from the input data.
146 Collection<components::Position2D> centers, const std::vector<datatypes::Vec2D>& sizes
147 ) {
148 return from_sizes(std::move(sizes)).with_centers(std::move(centers));
149 }
150
151 /// Creates new `Boxes2D` with `half_sizes` and `centers` created from minimums and (full)
152 /// sizes.
153 ///
154 /// TODO(#3285): Does *not* preserve data as-is and instead creates centers and half-sizes
155 /// from the input data.
157 const std::vector<datatypes::Vec2D>& mins, const std::vector<datatypes::Vec2D>& sizes
158 );
159
160 // END of extensions from boxes2d_ext.cpp, start of generated code:
161
162 public:
163 Boxes2D() = default;
164 Boxes2D(Boxes2D&& other) = default;
165 Boxes2D(const Boxes2D& other) = default;
166 Boxes2D& operator=(const Boxes2D& other) = default;
167 Boxes2D& operator=(Boxes2D&& other) = default;
168
169 /// Update only some specific fields of a `Boxes2D`.
171 return Boxes2D();
172 }
173
174 /// Clear all the fields of a `Boxes2D`.
176
177 /// All half-extents that make up the batch of boxes.
179 half_sizes =
180 ComponentBatch::from_loggable(_half_sizes, Descriptor_half_sizes).value_or_throw();
181 return std::move(*this);
182 }
183
184 /// Optional center positions of the boxes.
186 centers = ComponentBatch::from_loggable(_centers, Descriptor_centers).value_or_throw();
187 return std::move(*this);
188 }
189
190 /// Optional colors for the boxes.
192 colors = ComponentBatch::from_loggable(_colors, Descriptor_colors).value_or_throw();
193 return std::move(*this);
194 }
195
196 /// Optional radii for the lines that make up the boxes.
198 radii = ComponentBatch::from_loggable(_radii, Descriptor_radii).value_or_throw();
199 return std::move(*this);
200 }
201
202 /// Optional text labels for the boxes.
203 ///
204 /// If there's a single label present, it will be placed at the center of the entity.
205 /// Otherwise, each instance will have its own label.
207 labels = ComponentBatch::from_loggable(_labels, Descriptor_labels).value_or_throw();
208 return std::move(*this);
209 }
210
211 /// Whether the text labels should be shown.
212 ///
213 /// If not set, labels will automatically appear when there is exactly one label for this entity
214 /// or the number of instances on this entity is under a certain threshold.
217 .value_or_throw();
218 return std::move(*this);
219 }
220
221 /// This method makes it possible to pack multiple `show_labels` in a single component batch.
222 ///
223 /// This only makes sense when used in conjunction with `columns`. `with_show_labels` should
224 /// be used when logging a single row's worth of data.
226 ) && {
228 .value_or_throw();
229 return std::move(*this);
230 }
231
232 /// An optional floating point value that specifies the 2D drawing order.
233 ///
234 /// Objects with higher values are drawn on top of those with lower values.
235 /// Defaults to `10.0`.
237 draw_order =
238 ComponentBatch::from_loggable(_draw_order, Descriptor_draw_order).value_or_throw();
239 return std::move(*this);
240 }
241
242 /// This method makes it possible to pack multiple `draw_order` in a single component batch.
243 ///
244 /// This only makes sense when used in conjunction with `columns`. `with_draw_order` should
245 /// be used when logging a single row's worth of data.
247 ) && {
248 draw_order =
249 ComponentBatch::from_loggable(_draw_order, Descriptor_draw_order).value_or_throw();
250 return std::move(*this);
251 }
252
253 /// Optional `components::ClassId`s for the boxes.
254 ///
255 /// The `components::ClassId` provides colors and labels if not specified explicitly.
257 class_ids =
258 ComponentBatch::from_loggable(_class_ids, Descriptor_class_ids).value_or_throw();
259 return std::move(*this);
260 }
261
262 /// Partitions the component data into multiple sub-batches.
263 ///
264 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
265 /// instead, via `ComponentBatch::partitioned`.
266 ///
267 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
268 ///
269 /// The specified `lengths` must sum to the total length of the component batch.
271
272 /// Partitions the component data into unit-length sub-batches.
273 ///
274 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
275 /// where `n` is automatically guessed.
277 };
278
279} // namespace rerun::archetypes
280
281namespace rerun {
282 /// \private
283 template <typename T>
284 struct AsComponents;
285
286 /// \private
287 template <>
288 struct AsComponents<archetypes::Boxes2D> {
289 /// Serialize all set component batches.
290 static Result<Collection<ComponentBatch>> as_batches(const archetypes::Boxes2D& archetype);
291 };
292} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:49
A class for representing either a usable value, or an error.
Definition result.hpp:14
All built-in archetypes. See Types in the Rerun manual.
Definition rerun.hpp:76
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:23
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: 2D boxes with half-extents and optional center, colors etc.
Definition boxes2d.hpp:42
static Boxes2D clear_fields()
Clear all the fields of a Boxes2D.
Boxes2D with_class_ids(const Collection< rerun::components::ClassId > &_class_ids) &&
Optional components::ClassIds for the boxes.
Definition boxes2d.hpp:256
static constexpr auto Descriptor_show_labels
ComponentDescriptor for the show_labels field.
Definition boxes2d.hpp:104
std::optional< ComponentBatch > centers
Optional center positions of the boxes.
Definition boxes2d.hpp:47
static Boxes2D update_fields()
Update only some specific fields of a Boxes2D.
Definition boxes2d.hpp:170
std::optional< ComponentBatch > draw_order
An optional floating point value that specifies the 2D drawing order.
Definition boxes2d.hpp:71
std::optional< ComponentBatch > show_labels
Whether the text labels should be shown.
Definition boxes2d.hpp:65
Boxes2D with_draw_order(const rerun::components::DrawOrder &_draw_order) &&
An optional floating point value that specifies the 2D drawing order.
Definition boxes2d.hpp:236
std::optional< ComponentBatch > radii
Optional radii for the lines that make up the boxes.
Definition boxes2d.hpp:53
std::optional< ComponentBatch > half_sizes
All half-extents that make up the batch of boxes.
Definition boxes2d.hpp:44
Boxes2D with_labels(const Collection< rerun::components::Text > &_labels) &&
Optional text labels for the boxes.
Definition boxes2d.hpp:206
Boxes2D with_colors(const Collection< rerun::components::Color > &_colors) &&
Optional colors for the boxes.
Definition boxes2d.hpp:191
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition boxes2d.hpp:80
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
Boxes2D with_half_sizes(const Collection< rerun::components::HalfSize2D > &_half_sizes) &&
All half-extents that make up the batch of boxes.
Definition boxes2d.hpp:178
static constexpr auto Descriptor_class_ids
ComponentDescriptor for the class_ids field.
Definition boxes2d.hpp:114
static constexpr auto Descriptor_radii
ComponentDescriptor for the radii field.
Definition boxes2d.hpp:96
static constexpr auto Descriptor_colors
ComponentDescriptor for the colors field.
Definition boxes2d.hpp:92
Boxes2D with_centers(const Collection< rerun::components::Position2D > &_centers) &&
Optional center positions of the boxes.
Definition boxes2d.hpp:185
static constexpr auto Descriptor_draw_order
ComponentDescriptor for the draw_order field.
Definition boxes2d.hpp:109
static Boxes2D from_centers_and_sizes(Collection< components::Position2D > centers, const std::vector< datatypes::Vec2D > &sizes)
Creates new Boxes2D with centers and half_sizes created from centers and (full) sizes.
Definition boxes2d.hpp:145
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
Boxes2D with_many_show_labels(const Collection< rerun::components::ShowLabels > &_show_labels) &&
This method makes it possible to pack multiple show_labels in a single component batch.
Definition boxes2d.hpp:225
static Boxes2D from_sizes(const std::vector< datatypes::Vec2D > &sizes)
Creates new Boxes2D with half_sizes created from (full) sizes.
static Boxes2D from_centers_and_half_sizes(Collection< components::Position2D > centers, Collection< components::HalfSize2D > half_sizes)
Creates new Boxes2D with centers and half_sizes.
Definition boxes2d.hpp:125
static constexpr auto Descriptor_labels
ComponentDescriptor for the labels field.
Definition boxes2d.hpp:100
static constexpr auto Descriptor_half_sizes
ComponentDescriptor for the half_sizes field.
Definition boxes2d.hpp:83
Boxes2D 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 boxes2d.hpp:246
std::optional< ComponentBatch > labels
Optional text labels for the boxes.
Definition boxes2d.hpp:59
std::optional< ComponentBatch > colors
Optional colors for the boxes.
Definition boxes2d.hpp:50
Boxes2D with_radii(const Collection< rerun::components::Radius > &_radii) &&
Optional radii for the lines that make up the boxes.
Definition boxes2d.hpp:197
static constexpr auto Descriptor_centers
ComponentDescriptor for the centers field.
Definition boxes2d.hpp:88
static Boxes2D from_half_sizes(Collection< components::HalfSize2D > half_sizes)
Creates new Boxes2D with half_sizes centered around the local origin.
Definition boxes2d.hpp:120
static Boxes2D from_mins_and_sizes(const std::vector< datatypes::Vec2D > &mins, const std::vector< datatypes::Vec2D > &sizes)
Creates new Boxes2D with half_sizes and centers created from minimums and (full) sizes.
Boxes2D with_show_labels(const rerun::components::ShowLabels &_show_labels) &&
Whether the text labels should be shown.
Definition boxes2d.hpp:215
std::optional< ComponentBatch > class_ids
Optional components::ClassIds for the boxes.
Definition boxes2d.hpp:76
Component: Draw order of 2D elements.
Definition draw_order.hpp:19
Component: Whether the entity's components::Text label is shown.
Definition show_labels.hpp:18