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