Rerun C++ SDK
Loading...
Searching...
No Matches
arrows3d.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/arrows3d.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/position3d.hpp"
13#include "../components/radius.hpp"
14#include "../components/show_labels.hpp"
15#include "../components/text.hpp"
16#include "../components/vector3d.hpp"
17#include "../result.hpp"
18
19#include <cstdint>
20#include <optional>
21#include <utility>
22#include <vector>
23
24namespace rerun::archetypes {
25 /// **Archetype**: 3D arrows with optional colors, radii, labels, etc.
26 ///
27 /// ## Example
28 ///
29 /// ### Simple batch of 3D arrows
30 /// ![image](https://static.rerun.io/arrow3d_simple/55e2f794a520bbf7527d7b828b0264732146c5d0/full.png)
31 ///
32 /// ```cpp
33 /// #include <rerun.hpp>
34 ///
35 /// #include <cmath>
36 /// #include <vector>
37 ///
38 /// constexpr float TAU = 6.28318530717958647692528676655900577f;
39 ///
40 /// int main(int argc, char* argv[]) {
41 /// const auto rec = rerun::RecordingStream("rerun_example_arrow3d");
42 /// rec.spawn().exit_on_failure();
43 ///
44 /// std::vector<rerun::Position3D> origins;
45 /// std::vector<rerun::Vector3D> vectors;
46 /// std::vector<rerun::Color> colors;
47 ///
48 /// for (int i = 0; i <100; ++i) {
49 /// origins.push_back({0, 0, 0});
50 ///
51 /// float angle = TAU * static_cast<float>(i) * 0.01f;
52 /// float length = static_cast<float>(log2(i + 1));
53 /// vectors.push_back({length * sinf(angle), 0.0, length * cosf(angle)});
54 ///
55 /// uint8_t c = static_cast<uint8_t>(round(angle / TAU * 255.0f));
56 /// colors.push_back({static_cast<uint8_t>(255 - c), c, 128, 128});
57 /// }
58 ///
59 /// rec.log(
60 /// "arrows",
61 /// rerun::Arrows3D::from_vectors(vectors)
62 /// .with_origins(origins)
63 /// .with_colors(colors)
64 /// );
65 /// }
66 /// ```
67 struct Arrows3D {
68 /// All the vectors for each arrow in the batch.
69 std::optional<ComponentBatch> vectors;
70
71 /// All the origin (base) positions for each arrow in the batch.
72 ///
73 /// If no origins are set, (0, 0, 0) is used as the origin for each arrow.
74 std::optional<ComponentBatch> origins;
75
76 /// Optional radii for the arrows.
77 ///
78 /// The shaft is rendered as a line with `radius = 0.5 * radius`.
79 /// The tip is rendered with `height = 2.0 * radius` and `radius = 1.0 * radius`.
80 std::optional<ComponentBatch> radii;
81
82 /// Optional colors for the points.
83 std::optional<ComponentBatch> colors;
84
85 /// Optional text labels for the arrows.
86 ///
87 /// If there's a single label present, it will be placed at the center of the entity.
88 /// Otherwise, each instance will have its own label.
89 std::optional<ComponentBatch> labels;
90
91 /// Whether the text labels should be shown.
92 ///
93 /// If not set, labels will automatically appear when there is exactly one label for this entity
94 /// or the number of instances on this entity is under a certain threshold.
95 std::optional<ComponentBatch> show_labels;
96
97 /// Optional class Ids for the points.
98 ///
99 /// The `components::ClassId` provides colors and labels if not specified explicitly.
100 std::optional<ComponentBatch> class_ids;
101
102 public:
103 /// The name of the archetype as used in `ComponentDescriptor`s.
104 static constexpr const char ArchetypeName[] = "rerun.archetypes.Arrows3D";
105
106 /// `ComponentDescriptor` for the `vectors` field.
109 );
110 /// `ComponentDescriptor` for the `origins` field.
112 ArchetypeName, "Arrows3D:origins",
114 );
115 /// `ComponentDescriptor` for the `radii` field.
116 static constexpr auto Descriptor_radii = ComponentDescriptor(
118 );
119 /// `ComponentDescriptor` for the `colors` field.
120 static constexpr auto Descriptor_colors = ComponentDescriptor(
122 );
123 /// `ComponentDescriptor` for the `labels` field.
124 static constexpr auto Descriptor_labels = ComponentDescriptor(
126 );
127 /// `ComponentDescriptor` for the `show_labels` field.
129 ArchetypeName, "Arrows3D:show_labels",
131 );
132 /// `ComponentDescriptor` for the `class_ids` field.
135 );
136
137 public: // START of extensions from arrows3d_ext.cpp:
138 /// Creates new 3D arrows pointing in the given directions, with a base at the origin (0, 0,
139 /// 0).
141 return Arrows3D().with_vectors(vectors_);
142 }
143
144 // END of extensions from arrows3d_ext.cpp, start of generated code:
145
146 public:
147 Arrows3D() = default;
148 Arrows3D(Arrows3D&& other) = default;
149 Arrows3D(const Arrows3D& other) = default;
150 Arrows3D& operator=(const Arrows3D& other) = default;
151 Arrows3D& operator=(Arrows3D&& other) = default;
152
153 /// Update only some specific fields of a `Arrows3D`.
155 return Arrows3D();
156 }
157
158 /// Clear all the fields of a `Arrows3D`.
160
161 /// All the vectors for each arrow in the batch.
163 vectors = ComponentBatch::from_loggable(_vectors, Descriptor_vectors).value_or_throw();
164 return std::move(*this);
165 }
166
167 /// All the origin (base) positions for each arrow in the batch.
168 ///
169 /// If no origins are set, (0, 0, 0) is used as the origin for each arrow.
171 origins = ComponentBatch::from_loggable(_origins, Descriptor_origins).value_or_throw();
172 return std::move(*this);
173 }
174
175 /// Optional radii for the arrows.
176 ///
177 /// The shaft is rendered as a line with `radius = 0.5 * radius`.
178 /// The tip is rendered with `height = 2.0 * radius` and `radius = 1.0 * radius`.
180 radii = ComponentBatch::from_loggable(_radii, Descriptor_radii).value_or_throw();
181 return std::move(*this);
182 }
183
184 /// Optional colors for the points.
186 colors = ComponentBatch::from_loggable(_colors, Descriptor_colors).value_or_throw();
187 return std::move(*this);
188 }
189
190 /// Optional text labels for the arrows.
191 ///
192 /// If there's a single label present, it will be placed at the center of the entity.
193 /// Otherwise, each instance will have its own label.
195 labels = ComponentBatch::from_loggable(_labels, Descriptor_labels).value_or_throw();
196 return std::move(*this);
197 }
198
199 /// Whether the text labels should be shown.
200 ///
201 /// If not set, labels will automatically appear when there is exactly one label for this entity
202 /// or the number of instances on this entity is under a certain threshold.
205 .value_or_throw();
206 return std::move(*this);
207 }
208
209 /// This method makes it possible to pack multiple `show_labels` in a single component batch.
210 ///
211 /// This only makes sense when used in conjunction with `columns`. `with_show_labels` should
212 /// be used when logging a single row's worth of data.
214 ) && {
216 .value_or_throw();
217 return std::move(*this);
218 }
219
220 /// Optional class Ids for the points.
221 ///
222 /// The `components::ClassId` provides colors and labels if not specified explicitly.
224 class_ids =
225 ComponentBatch::from_loggable(_class_ids, Descriptor_class_ids).value_or_throw();
226 return std::move(*this);
227 }
228
229 /// Partitions the component data into multiple sub-batches.
230 ///
231 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
232 /// instead, via `ComponentBatch::partitioned`.
233 ///
234 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
235 ///
236 /// The specified `lengths` must sum to the total length of the component batch.
238 return detail::partition_batches(
240 lengths_
241 )
242 .value_or_throw();
243 }
244
245 /// Partitions the component data into unit-length sub-batches.
246 ///
247 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
248 /// where `n` is automatically guessed.
250 return detail::partition_batches_of_unit_length(
252 )
253 .value_or_throw();
254 }
255 };
256
257} // namespace rerun::archetypes
258
259namespace rerun {
260 /// \private
261 template <typename T>
262 struct AsComponents;
263
264 /// \private
265 template <>
266 struct AsComponents<archetypes::Arrows3D> {
267 /// Serialize all set component batches.
268 static Result<Collection<ComponentBatch>> as_batches(const archetypes::Arrows3D& archetype
269 ) {
270 return detail::collect_batches(
271 {&archetype.vectors,
272 &archetype.origins,
273 &archetype.radii,
274 &archetype.colors,
275 &archetype.labels,
276 &archetype.show_labels,
277 &archetype.class_ids}
278 );
279 }
280 };
281} // 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: 3D arrows with optional colors, radii, labels, etc.
Definition arrows3d.hpp:67
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
Definition arrows3d.hpp:237
static constexpr auto Descriptor_radii
ComponentDescriptor for the radii field.
Definition arrows3d.hpp:116
Arrows3D with_labels(const Collection< rerun::components::Text > &_labels) &&
Optional text labels for the arrows.
Definition arrows3d.hpp:194
Arrows3D with_origins(const Collection< rerun::components::Position3D > &_origins) &&
All the origin (base) positions for each arrow in the batch.
Definition arrows3d.hpp:170
static constexpr auto Descriptor_colors
ComponentDescriptor for the colors field.
Definition arrows3d.hpp:120
Arrows3D with_show_labels(const rerun::components::ShowLabels &_show_labels) &&
Whether the text labels should be shown.
Definition arrows3d.hpp:203
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition arrows3d.hpp:104
Arrows3D with_class_ids(const Collection< rerun::components::ClassId > &_class_ids) &&
Optional class Ids for the points.
Definition arrows3d.hpp:223
static constexpr auto Descriptor_show_labels
ComponentDescriptor for the show_labels field.
Definition arrows3d.hpp:128
std::optional< ComponentBatch > labels
Optional text labels for the arrows.
Definition arrows3d.hpp:89
std::optional< ComponentBatch > radii
Optional radii for the arrows.
Definition arrows3d.hpp:80
static Arrows3D update_fields()
Update only some specific fields of a Arrows3D.
Definition arrows3d.hpp:154
Arrows3D with_vectors(const Collection< rerun::components::Vector3D > &_vectors) &&
All the vectors for each arrow in the batch.
Definition arrows3d.hpp:162
static Arrows3D from_vectors(Collection< components::Vector3D > vectors_)
Creates new 3D arrows pointing in the given directions, with a base at the origin (0,...
Definition arrows3d.hpp:140
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
Definition arrows3d.hpp:249
std::optional< ComponentBatch > class_ids
Optional class Ids for the points.
Definition arrows3d.hpp:100
std::optional< ComponentBatch > origins
All the origin (base) positions for each arrow in the batch.
Definition arrows3d.hpp:74
Arrows3D 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 arrows3d.hpp:213
Arrows3D with_radii(const Collection< rerun::components::Radius > &_radii) &&
Optional radii for the arrows.
Definition arrows3d.hpp:179
static constexpr auto Descriptor_vectors
ComponentDescriptor for the vectors field.
Definition arrows3d.hpp:107
static constexpr auto Descriptor_labels
ComponentDescriptor for the labels field.
Definition arrows3d.hpp:124
static constexpr auto Descriptor_class_ids
ComponentDescriptor for the class_ids field.
Definition arrows3d.hpp:133
std::optional< ComponentBatch > show_labels
Whether the text labels should be shown.
Definition arrows3d.hpp:95
static constexpr auto Descriptor_origins
ComponentDescriptor for the origins field.
Definition arrows3d.hpp:111
static Arrows3D clear_fields()
Clear all the fields of a Arrows3D.
std::optional< ComponentBatch > colors
Optional colors for the points.
Definition arrows3d.hpp:83
std::optional< ComponentBatch > vectors
All the vectors for each arrow in the batch.
Definition arrows3d.hpp:69
Arrows3D with_colors(const Collection< rerun::components::Color > &_colors) &&
Optional colors for the points.
Definition arrows3d.hpp:185
Component: Whether the entity's components::Text label is shown.
Definition show_labels.hpp:18