Rerun C++ SDK
Loading...
Searching...
No Matches
transform3d.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/transform3d.fbs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../compiler_utils.hpp"
8#include "../component_batch.hpp"
9#include "../component_column.hpp"
10#include "../components/axis_length.hpp"
11#include "../components/rotation_axis_angle.hpp"
12#include "../components/rotation_quat.hpp"
13#include "../components/scale3d.hpp"
14#include "../components/transform_mat3x3.hpp"
15#include "../components/transform_relation.hpp"
16#include "../components/translation3d.hpp"
17#include "../rerun_sdk_export.hpp"
18#include "../result.hpp"
19#include "../rotation3d.hpp"
20
21#include <cstdint>
22#include <optional>
23#include <utility>
24#include <vector>
25
26namespace rerun::archetypes {
27 /// **Archetype**: A transform between two 3D spaces, i.e. a pose.
28 ///
29 /// From the point of view of the entity's coordinate system,
30 /// all components are applied in the inverse order they are listed here.
31 /// E.g. if both a translation and a max3x3 transform are present,
32 /// the 3x3 matrix is applied first, followed by the translation.
33 ///
34 /// Whenever you log this archetype, it will write all components, even if you do not explicitly set them.
35 /// This means that if you first log a transform with only a translation, and then log one with only a rotation,
36 /// it will be resolved to a transform with only a rotation.
37 ///
38 /// For transforms that affect only a single entity and do not propagate along the entity tree refer to `archetypes::InstancePoses3D`.
39 ///
40 /// ## Examples
41 ///
42 /// ### Variety of 3D transforms
43 /// ![image](https://static.rerun.io/transform3d_simple/141368b07360ce3fcb1553079258ae3f42bdb9ac/full.png)
44 ///
45 /// ```cpp
46 /// #include <rerun.hpp>
47 ///
48 /// constexpr float TAU = 6.28318530717958647692528676655900577f;
49 ///
50 /// int main() {
51 /// const auto rec = rerun::RecordingStream("rerun_example_transform3d");
52 /// rec.spawn().exit_on_failure();
53 ///
54 /// auto arrow =
55 /// rerun::Arrows3D::from_vectors({{0.0f, 1.0f, 0.0f}}).with_origins({{0.0f, 0.0f, 0.0f}});
56 ///
57 /// rec.log("base", arrow);
58 ///
59 /// rec.log("base/translated", rerun::Transform3D::from_translation({1.0f, 0.0f, 0.0f}));
60 /// rec.log("base/translated", arrow);
61 ///
62 /// rec.log(
63 /// "base/rotated_scaled",
64 /// rerun::Transform3D::from_rotation_scale(
65 /// rerun::RotationAxisAngle({0.0f, 0.0f, 1.0f}, rerun::Angle::radians(TAU / 8.0f)),
66 /// 2.0f
67 /// )
68 /// );
69 /// rec.log("base/rotated_scaled", arrow);
70 /// }
71 /// ```
72 ///
73 /// ### Transform hierarchy
74 /// ![image](https://static.rerun.io/transform_hierarchy/cb7be7a5a31fcb2efc02ba38e434849248f87554/full.png)
75 ///
76 /// ```cpp
77 /// #include <rerun.hpp>
78 ///
79 /// constexpr float TAU = 6.28318530717958647692528676655900577f;
80 ///
81 /// int main() {
82 /// const auto rec = rerun::RecordingStream("rerun_example_transform3d_hierarchy");
83 /// rec.spawn().exit_on_failure();
84 ///
85 /// // TODO(#5521): log two views as in the python example
86 ///
87 /// rec.set_time_duration_secs("sim_time", 0.0);
88 ///
89 /// // Planetary motion is typically in the XY plane.
90 /// rec.log_static("/", rerun::ViewCoordinates::RIGHT_HAND_Z_UP);
91 ///
92 /// // Setup points, all are in the center of their own space:
93 /// rec.log(
94 /// "sun",
95 /// rerun::Points3D({{0.0f, 0.0f, 0.0f}})
96 /// .with_radii({1.0f})
97 /// .with_colors({rerun::Color(255, 200, 10)})
98 /// );
99 /// rec.log(
100 /// "sun/planet",
101 /// rerun::Points3D({{0.0f, 0.0f, 0.0f}})
102 /// .with_radii({0.4f})
103 /// .with_colors({rerun::Color(40, 80, 200)})
104 /// );
105 /// rec.log(
106 /// "sun/planet/moon",
107 /// rerun::Points3D({{0.0f, 0.0f, 0.0f}})
108 /// .with_radii({0.15f})
109 /// .with_colors({rerun::Color(180, 180, 180)})
110 /// );
111 ///
112 /// // Draw fixed paths where the planet & moon move.
113 /// float d_planet = 6.0f;
114 /// float d_moon = 3.0f;
115 /// std::vector<std::array<float, 3>> planet_path, moon_path;
116 /// for (int i = 0; i <= 100; i++) {
117 /// float angle = static_cast<float>(i) * 0.01f * TAU;
118 /// float circle_x = std::sin(angle);
119 /// float circle_y = std::cos(angle);
120 /// planet_path.push_back({circle_x * d_planet, circle_y * d_planet, 0.0f});
121 /// moon_path.push_back({circle_x * d_moon, circle_y * d_moon, 0.0f});
122 /// }
123 /// rec.log("sun/planet_path", rerun::LineStrips3D(rerun::LineStrip3D(planet_path)));
124 /// rec.log("sun/planet/moon_path", rerun::LineStrips3D(rerun::LineStrip3D(moon_path)));
125 ///
126 /// // Movement via transforms.
127 /// for (int i = 0; i <6 * 120; i++) {
128 /// float time = static_cast<float>(i) / 120.0f;
129 /// rec.set_time_duration_secs("sim_time", time);
130 /// float r_moon = time * 5.0f;
131 /// float r_planet = time * 2.0f;
132 ///
133 /// rec.log(
134 /// "sun/planet",
135 /// rerun::Transform3D::from_translation_rotation(
136 /// {std::sin(r_planet) * d_planet, std::cos(r_planet) * d_planet, 0.0f},
137 /// rerun::RotationAxisAngle{
138 /// {1.0, 0.0f, 0.0f},
139 /// rerun::Angle::degrees(20.0f),
140 /// }
141 /// )
142 /// );
143 /// rec.log(
144 /// "sun/planet/moon",
145 /// rerun::Transform3D::from_translation(
146 /// {std::cos(r_moon) * d_moon, std::sin(r_moon) * d_moon, 0.0f}
147 /// )
148 /// .with_relation(rerun::components::TransformRelation::ChildFromParent)
149 /// );
150 /// }
151 /// }
152 /// ```
153 ///
154 /// ### Update a transform over time
155 /// ![image](https://static.rerun.io/transform3d_column_updates/80634e1c7c7a505387e975f25ea8b6bc1d4eb9db/full.png)
156 ///
157 /// ```cpp
158 /// #include <rerun.hpp>
159 ///
160 /// float truncated_radians(int deg) {
161 /// auto degf = static_cast<float>(deg);
162 /// const auto pi = 3.14159265358979323846f;
163 /// return static_cast<float>(static_cast<int>(degf * pi / 180.0f * 1000.0f)) / 1000.0f;
164 /// }
165 ///
166 /// int main() {
167 /// const auto rec = rerun::RecordingStream("rerun_example_transform3d_row_updates");
168 /// rec.spawn().exit_on_failure();
169 ///
170 /// rec.set_time_sequence("tick", 0);
171 /// rec.log(
172 /// "box",
173 /// rerun::Boxes3D::from_half_sizes({{4.f, 2.f, 1.0f}}).with_fill_mode(rerun::FillMode::Solid),
174 /// rerun::Transform3D().with_axis_length(10.0)
175 /// );
176 ///
177 /// for (int t = 0; t <100; t++) {
178 /// rec.set_time_sequence("tick", t + 1);
179 /// rec.log(
180 /// "box",
181 /// rerun::Transform3D()
182 /// .with_translation({0.0f, 0.0f, static_cast<float>(t) / 10.0f})
183 /// .with_rotation_axis_angle(rerun::RotationAxisAngle(
184 /// {0.0f, 1.0f, 0.0f},
185 /// rerun::Angle::radians(truncated_radians(t * 4))
186 /// ))
187 /// );
188 /// }
189 /// }
190 /// ```
191 ///
192 /// ### Update a transform over time, in a single operation
193 /// ![image](https://static.rerun.io/transform3d_column_updates/80634e1c7c7a505387e975f25ea8b6bc1d4eb9db/full.png)
194 ///
195 /// ```cpp
196 /// #include <cmath>
197 /// #include <numeric>
198 /// #include <vector>
199 ///
200 /// #include <rerun.hpp>
201 ///
202 /// float truncated_radians(int deg) {
203 /// auto degf = static_cast<float>(deg);
204 /// const auto pi = 3.14159265358979323846f;
205 /// return static_cast<float>(static_cast<int>(degf * pi / 180.0f * 1000.0f)) / 1000.0f;
206 /// }
207 ///
208 /// int main() {
209 /// const auto rec = rerun::RecordingStream("rerun_example_transform3d_column_updates");
210 /// rec.spawn().exit_on_failure();
211 ///
212 /// rec.set_time_sequence("tick", 0);
213 /// rec.log(
214 /// "box",
215 /// rerun::Boxes3D::from_half_sizes({{4.f, 2.f, 1.0f}}).with_fill_mode(rerun::FillMode::Solid),
216 /// rerun::Transform3D().with_axis_length(10.0)
217 /// );
218 ///
219 /// std::vector<std::array<float, 3>> translations;
220 /// std::vector<rerun::RotationAxisAngle> rotations;
221 /// for (int t = 0; t <100; t++) {
222 /// translations.push_back({0.0f, 0.0f, static_cast<float>(t) / 10.0f});
223 /// rotations.push_back(rerun::RotationAxisAngle(
224 /// {0.0f, 1.0f, 0.0f},
225 /// rerun::Angle::radians(truncated_radians(t * 4))
226 /// ));
227 /// }
228 ///
229 /// std::vector<int64_t> ticks(100);
230 /// std::iota(ticks.begin(), ticks.end(), 1);
231 ///
232 /// rec.send_columns(
233 /// "box",
234 /// rerun::TimeColumn::from_sequence("tick", ticks),
235 /// rerun::Transform3D()
236 /// .with_many_translation(translations)
237 /// .with_many_rotation_axis_angle(rotations)
238 /// .columns()
239 /// );
240 /// }
241 /// ```
242 ///
243 /// ### Update specific properties of a transform over time
244 /// ![image](https://static.rerun.io/transform3d_partial_updates/11815bebc69ae400847896372b496cdd3e9b19fb/full.png)
245 ///
246 /// ```cpp
247 /// #include <rerun.hpp>
248 ///
249 /// float truncated_radians(int deg) {
250 /// auto degf = static_cast<float>(deg);
251 /// const auto pi = 3.14159265358979323846f;
252 /// return static_cast<float>(static_cast<int>(degf * pi / 180.0f * 1000.0f)) / 1000.0f;
253 /// }
254 ///
255 /// int main() {
256 /// const auto rec = rerun::RecordingStream("rerun_example_transform3d_partial_updates");
257 /// rec.spawn().exit_on_failure();
258 ///
259 /// // Set up a 3D box.
260 /// rec.log(
261 /// "box",
262 /// rerun::Boxes3D::from_half_sizes({{4.f, 2.f, 1.0f}}).with_fill_mode(rerun::FillMode::Solid),
263 /// rerun::Transform3D().with_axis_length(10.0)
264 /// );
265 ///
266 /// // Update only the rotation of the box.
267 /// for (int deg = 0; deg <= 45; deg++) {
268 /// auto rad = truncated_radians(deg * 4);
269 /// rec.log(
270 /// "box",
271 /// rerun::Transform3D::update_fields().with_rotation_axis_angle(
272 /// rerun::RotationAxisAngle({0.0f, 1.0f, 0.0f}, rerun::Angle::radians(rad))
273 /// )
274 /// );
275 /// }
276 ///
277 /// // Update only the position of the box.
278 /// for (int t = 0; t <= 50; t++) {
279 /// rec.log(
280 /// "box",
281 /// rerun::Transform3D::update_fields().with_translation(
282 /// {0.0f, 0.0f, static_cast<float>(t) / 10.0f}
283 /// )
284 /// );
285 /// }
286 ///
287 /// // Update only the rotation of the box.
288 /// for (int deg = 0; deg <= 45; deg++) {
289 /// auto rad = truncated_radians((deg + 45) * 4);
290 /// rec.log(
291 /// "box",
292 /// rerun::Transform3D::update_fields().with_rotation_axis_angle(
293 /// rerun::RotationAxisAngle({0.0f, 1.0f, 0.0f}, rerun::Angle::radians(rad))
294 /// )
295 /// );
296 /// }
297 ///
298 /// // Clear all of the box's attributes, and reset its axis length.
299 /// rec.log("box", rerun::Transform3D::clear_fields().with_axis_length(15.0));
300 /// }
301 /// ```
302 struct Transform3D {
303 /// Translation vector.
304 std::optional<ComponentBatch> translation;
305
306 /// Rotation via axis + angle.
307 std::optional<ComponentBatch> rotation_axis_angle;
308
309 /// Rotation via quaternion.
310 std::optional<ComponentBatch> quaternion;
311
312 /// Scaling factor.
313 std::optional<ComponentBatch> scale;
314
315 /// 3x3 transformation matrix.
316 std::optional<ComponentBatch> mat3x3;
317
318 /// Specifies the relation this transform establishes between this entity and its parent.
319 std::optional<ComponentBatch> relation;
320
321 /// Visual length of the 3 axes.
322 ///
323 /// The length is interpreted in the local coordinate system of the transform.
324 /// If the transform is scaled, the axes will be scaled accordingly.
325 std::optional<ComponentBatch> axis_length;
326
327 public:
328 /// The name of the archetype as used in `ComponentDescriptor`s.
329 static constexpr const char ArchetypeName[] = "rerun.archetypes.Transform3D";
330
331 /// `ComponentDescriptor` for the `translation` field.
333 ArchetypeName, "Transform3D:translation",
335 );
336 /// `ComponentDescriptor` for the `rotation_axis_angle` field.
338 ArchetypeName, "Transform3D:rotation_axis_angle",
340 );
341 /// `ComponentDescriptor` for the `quaternion` field.
343 ArchetypeName, "Transform3D:quaternion",
345 );
346 /// `ComponentDescriptor` for the `scale` field.
347 static constexpr auto Descriptor_scale = ComponentDescriptor(
349 );
350 /// `ComponentDescriptor` for the `mat3x3` field.
351 static constexpr auto Descriptor_mat3x3 = ComponentDescriptor(
352 ArchetypeName, "Transform3D:mat3x3",
354 );
355 /// `ComponentDescriptor` for the `relation` field.
357 ArchetypeName, "Transform3D:relation",
359 );
360 /// `ComponentDescriptor` for the `axis_length` field.
362 ArchetypeName, "Transform3D:axis_length",
364 );
365
366 public: // START of extensions from transform3d_ext.cpp:
367 /// Identity transformation.
368 ///
369 /// Applying this transform does not alter an entity's transformation.
370 RERUN_SDK_EXPORT static const Transform3D IDENTITY;
371
372 /// Invalid transformation.
373 ///
374 /// Applying this transform will cause this entity and the entire subtree not to be visualized.
375 RERUN_SDK_EXPORT static const Transform3D INVALID;
376
377 /// Creates a new 3D transform from translation and matrix provided as 3 columns.
378 /// Clears out all other components like `Transform3D::clear_fields`.
379 ///
380 /// \param translation_ \çopydoc Transform3D::translation
381 /// \param columns Column vectors of 3x3 matrix.
382 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
383 ///
384 /// _Implementation note:_ This overload is necessary, otherwise the array may be
385 /// interpreted as bool and call the wrong overload.
387 const components::Translation3D& translation_, const datatypes::Vec3D (&columns)[3],
388 bool from_parent = false
389 )
390 : Transform3D(translation_, components::TransformMat3x3(columns), from_parent) {}
391
392 /// Creates a new 3D transform from translation/matrix.
393 /// Clears out all other components like `Transform3D::clear_fields`.
394 ///
395 /// \param translation_ \çopydoc Transform3D::translation
396 /// \param mat3x3_ \copydoc Transform3D::mat3x3
397 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
399 const components::Translation3D& translation_,
400 const components::TransformMat3x3& mat3x3_, bool from_parent = false
401 ) {
402 *this = Transform3D::clear_fields().with_translation(translation_).with_mat3x3(mat3x3_);
403 if (from_parent) {
404 *this =
406 }
407 }
408
409 /// From a translation applied after a 3x3 matrix.
410 /// Clears out all other components like `Transform3D::clear_fields`.
411 ///
412 /// \param translation \çopydoc Transform3D::translation
413 /// \param mat3x3 \copydoc Transform3D::mat3x3
416 ) {
417 return Transform3D(translation, mat3x3, false);
418 }
419
420 /// From a translation applied after a 3x3 matrix provided as 3 columns.
421 /// Clears out all other components like `Transform3D::clear_fields`.
422 ///
423 /// \param translation \çopydoc Transform3D::translation
424 /// \param columns Column vectors of 3x3 matrix.
427 ) {
431 );
432 }
433
434 /// From translation only.
435 /// Clears out all other components like `Transform3D::clear_fields`.
436 ///
437 /// \param translation_ \çopydoc Transform3D::translation
438 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
439 Transform3D(const components::Translation3D& translation_, bool from_parent = false) {
440 *this = Transform3D::clear_fields().with_translation(translation_);
441 if (from_parent) {
442 *this =
444 }
445 }
446
447 /// From a translation.
448 /// Clears out all other components like `Transform3D::clear_fields`.
449 ///
450 /// \param translation \çopydoc Transform3D::translation
452 return Transform3D(translation, false);
453 }
454
455 /// From 3x3 matrix only.
456 /// Clears out all other components like `Transform3D::clear_fields`.
457 ///
458 /// \param mat3x3_ \copydoc Transform3D::mat3x3
459 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
460 Transform3D(const components::TransformMat3x3& mat3x3_, bool from_parent = false) {
461 *this = Transform3D::clear_fields().with_mat3x3(mat3x3_);
462 if (from_parent) {
463 *this =
465 }
466 }
467
468 /// From 3x3 matrix only.
469 /// Clears out all other components like `Transform3D::clear_fields`.
470 ///
471 /// \param mat3x3 \copydoc Transform3D::mat3x3
473 return Transform3D(mat3x3, false);
474 }
475
476 /// From 3x3 matrix provided as 3 columns only.
477 /// Clears out all other components like `Transform3D::clear_fields`.
478 ///
479 /// \param columns Column vectors of 3x3 matrix.
480 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
481 Transform3D(const datatypes::Vec3D (&columns)[3], bool from_parent = false)
482 : Transform3D(components::TransformMat3x3(columns), from_parent) {}
483
484 /// From 3x3 matrix provided as 3 columns only.
485 /// Clears out all other components like `Transform3D::clear_fields`.
486 ///
487 /// \param columns Column vectors of 3x3 matrix.
490 }
491
492 /// Creates a new 3D transform from translation/rotation/scale.
493 /// Clears out all other components like `Transform3D::clear_fields`.
494 ///
495 /// \param translation_ \copydoc Transform3D::translation
496 /// \param rotation Rotation represented either as a quaternion or axis + angle rotation.
497 /// \param scale_ \copydoc Transform3D::scale
498 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
500 const components::Translation3D& translation_, const Rotation3D& rotation,
501 const components::Scale3D& scale_, bool from_parent = false
502 ) {
504 .with_translation(translation_)
505 .with_scale(scale_)
506 .with_rotation(rotation);
507 if (from_parent) {
508 *this =
510 }
511 }
512
513 /// Creates a new 3D transform from translation/rotation/uniform-scale.
514 /// Clears out all other components like `Transform3D::clear_fields`.
515 ///
516 /// \param translation_ \copydoc Transform3D::translation
517 /// \param rotation Rotation represented either as a quaternion or axis + angle rotation.
518 /// \param uniform_scale Uniform scale factor that is applied to all axis equally.
519 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
520 ///
521 /// _Implementation note:_ This explicit overload prevents interpretation of the float as
522 /// bool, leading to a call to the wrong overload.
524 const components::Translation3D& translation_, const Rotation3D& rotation,
525 float uniform_scale, bool from_parent = false
526 )
527 : Transform3D(translation_, rotation, components::Scale3D(uniform_scale), from_parent) {
528 }
529
530 /// From a translation, applied after a rotation & scale, known as an affine transformation.
531 /// Clears out all other components like `Transform3D::clear_fields`.
532 ///
533 /// \param translation \copydoc Transform3D::translation
534 /// \param rotation Rotation represented either as a quaternion or axis + angle rotation.
535 /// \param scale \copydoc Transform3D::scale
537 const components::Translation3D& translation, const Rotation3D& rotation,
539 ) {
540 return Transform3D(translation, rotation, scale, false);
541 }
542
543 /// From a translation, applied after a rotation & scale, known as an affine transformation.
544 /// Clears out all other components like `Transform3D::clear_fields`.
545 ///
546 /// \param translation \copydoc Transform3D::translation
547 /// \param rotation Rotation represented either as a quaternion or axis + angle rotation.
548 /// \param uniform_scale Uniform scale factor that is applied to all axis equally.
550 const components::Translation3D& translation, const Rotation3D& rotation,
551 float uniform_scale
552 ) {
553 return Transform3D(translation, rotation, components::Scale3D(uniform_scale), false);
554 }
555
556 /// Creates a new rigid transform (translation & rotation only).
557 /// Clears out all other components like `Transform3D::clear_fields`.
558 ///
559 /// \param translation_ \copydoc Transform3D::translation
560 /// \param rotation Rotation represented either as a quaternion or axis + angle rotation.
561 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
563 const components::Translation3D& translation_, const Rotation3D& rotation,
564 bool from_parent = false
565 ) {
566 *this =
568 if (from_parent) {
569 *this =
571 }
572 }
573
574 /// From a rotation & scale.
575 /// Clears out all other components like `Transform3D::clear_fields`.
576 ///
577 /// \param translation \copydoc Transform3D::translation
578 /// \param rotation Rotation represented either as a quaternion or axis + angle rotation.
580 const components::Translation3D& translation, const Rotation3D& rotation
581 ) {
582 return Transform3D(translation, rotation, false);
583 }
584
585 /// From translation & scale only.
586 /// Clears out all other components like `Transform3D::clear_fields`.
587 ///
588 /// \param translation_ \copydoc Transform3D::translation
589 /// \param scale_ Transform3D::scale
590 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
592 const components::Translation3D& translation_, const components::Scale3D& scale_,
593 bool from_parent = false
594 ) {
595 *this = Transform3D::clear_fields().with_translation(translation_).with_scale(scale_);
596 if (from_parent) {
597 *this =
599 }
600 }
601
602 /// From a translation applied after a scale.
603 /// Clears out all other components like `Transform3D::clear_fields`.
604 ///
605 /// \param translation \copydoc Transform3D::translation
606 /// \param scale Transform3D::scale
609 ) {
610 return Transform3D(translation, scale, false);
611 }
612
613 /// From translation & uniform scale only.
614 /// Clears out all other components like `Transform3D::clear_fields`.
615 ///
616 /// \param translation_ \copydoc Transform3D::translation
617 /// \param uniform_scale Uniform scale factor that is applied to all axis equally.
618 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
619 ///
620 /// _Implementation note:_ This explicit overload prevents interpretation of the float as
621 /// bool, leading to a call to the wrong overload.
623 const components::Translation3D& translation_, float uniform_scale,
624 bool from_parent = false
625 )
626 : Transform3D(translation_, components::Scale3D(uniform_scale), from_parent) {}
627
628 /// From rotation & scale.
629 /// Clears out all other components like `Transform3D::clear_fields`.
630 ///
631 /// \param rotation Rotation represented either as a quaternion or axis + angle rotation.
632 /// \param scale_ Transform3D::scale
633 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
635 const Rotation3D& rotation, const components::Scale3D& scale_, bool from_parent = false
636 ) {
637 *this = Transform3D::clear_fields().with_scale(scale_).with_rotation(rotation);
638 if (from_parent) {
639 *this =
641 }
642 }
643
644 /// From rotation & uniform scale.
645 /// Clears out all other components like `Transform3D::clear_fields`.
646 ///
647 /// \param rotation Rotation represented either as a quaternion or axis + angle rotation.
648 /// \param uniform_scale Uniform scale factor that is applied to all axis equally.
649 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
650 ///
651 /// _Implementation note:_ This explicit overload prevents interpretation of the float as
652 /// bool, leading to a call to the wrong overload.
653 Transform3D(const Rotation3D& rotation, float uniform_scale, bool from_parent = false)
654 : Transform3D(rotation, components::Scale3D(uniform_scale), from_parent) {}
655
656 /// From a rotation & scale.
657 /// Clears out all other components like `Transform3D::clear_fields`.
658 ///
659 /// \param rotation Rotation represented either as a quaternion or axis + angle rotation.
660 /// \param scale Transform3D::scale
662 const Rotation3D& rotation, const components::Scale3D& scale
663 ) {
664 return Transform3D(rotation, scale, false);
665 }
666
667 /// From a rotation & uniform scale.
668 /// Clears out all other components like `Transform3D::clear_fields`.
669 ///
670 /// \param rotation Rotation represented either as a quaternion or axis + angle rotation.
671 /// \param uniform_scale Uniform scale factor that is applied to all axis equally.
672 static Transform3D from_rotation_scale(const Rotation3D& rotation, float uniform_scale) {
673 return Transform3D(rotation, components::Scale3D(uniform_scale), false);
674 }
675
676 /// From rotation only.
677 /// Clears out all other components like `Transform3D::clear_fields`.
678 ///
679 /// \param rotation Rotation represented either as a quaternion or axis + angle rotation.
680 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
681 Transform3D(const Rotation3D& rotation, bool from_parent = false) {
682 *this = Transform3D::clear_fields().with_rotation(rotation);
683 if (from_parent) {
684 *this =
686 }
687 }
688
689 /// From rotation only.
690 /// Clears out all other components like `Transform3D::clear_fields`.
691 ///
692 /// \param rotation Rotation represented either as a quaternion or axis + angle rotation.
693 static Transform3D from_rotation(const Rotation3D& rotation) {
694 return Transform3D(rotation, false);
695 }
696
697 /// From scale only.
698 /// Clears out all other components like `Transform3D::clear_fields`.
699 ///
700 /// \param scale_ If true, the transform relation to `TransformRelation::ChildFromParent`.
701 /// \param from_parent \copydoc Transform3D::scale
702 Transform3D(const components::Scale3D& scale_, bool from_parent = false) {
703 *this = Transform3D::clear_fields().with_scale(scale_);
704 if (from_parent) {
705 *this =
707 }
708 }
709
710 /// From scale only.
711 /// Clears out all other components like `Transform3D::clear_fields`.
712 ///
713 /// \param scale Transform3D::scale
715 return Transform3D(scale, false);
716 }
717
718 /// From scale only.
719 /// Clears out all other components like `Transform3D::clear_fields`.
720 ///
721 /// \param uniform_scale Uniform scale factor that is applied to all axis equally.
722 static Transform3D from_scale(float uniform_scale) {
723 return Transform3D(components::Scale3D(uniform_scale), false);
724 }
725
726 /// Set the rotation component of the transform using the `rerun::Rotation3D` utility.
728 if (rotation.axis_angle.has_value()) {
729 *this = std::move(*this).with_rotation_axis_angle(rotation.axis_angle.value());
730 }
731 if (rotation.quaternion.has_value()) {
732 *this = std::move(*this).with_quaternion(rotation.quaternion.value());
733 }
734 return std::move(*this);
735 }
736
737 // END of extensions from transform3d_ext.cpp, start of generated code:
738
739 public:
740 Transform3D() = default;
741 Transform3D(Transform3D&& other) = default;
742 Transform3D(const Transform3D& other) = default;
743 Transform3D& operator=(const Transform3D& other) = default;
744 Transform3D& operator=(Transform3D&& other) = default;
745
746 /// Update only some specific fields of a `Transform3D`.
748 return Transform3D();
749 }
750
751 /// Clear all the fields of a `Transform3D`.
753
754 /// Translation vector.
757 .value_or_throw();
758 return std::move(*this);
759 }
760
761 /// This method makes it possible to pack multiple `translation` in a single component batch.
762 ///
763 /// This only makes sense when used in conjunction with `columns`. `with_translation` should
764 /// be used when logging a single row's worth of data.
767 ) && {
769 .value_or_throw();
770 return std::move(*this);
771 }
772
773 /// Rotation via axis + angle.
775 const rerun::components::RotationAxisAngle& _rotation_axis_angle
776 ) && {
779 .value_or_throw();
780 return std::move(*this);
781 }
782
783 /// This method makes it possible to pack multiple `rotation_axis_angle` in a single component batch.
784 ///
785 /// This only makes sense when used in conjunction with `columns`. `with_rotation_axis_angle` should
786 /// be used when logging a single row's worth of data.
788 const Collection<rerun::components::RotationAxisAngle>& _rotation_axis_angle
789 ) && {
792 .value_or_throw();
793 return std::move(*this);
794 }
795
796 /// Rotation via quaternion.
798 quaternion =
799 ComponentBatch::from_loggable(_quaternion, Descriptor_quaternion).value_or_throw();
800 return std::move(*this);
801 }
802
803 /// This method makes it possible to pack multiple `quaternion` in a single component batch.
804 ///
805 /// This only makes sense when used in conjunction with `columns`. `with_quaternion` should
806 /// be used when logging a single row's worth of data.
809 ) && {
810 quaternion =
811 ComponentBatch::from_loggable(_quaternion, Descriptor_quaternion).value_or_throw();
812 return std::move(*this);
813 }
814
815 /// Scaling factor.
817 scale = ComponentBatch::from_loggable(_scale, Descriptor_scale).value_or_throw();
818 return std::move(*this);
819 }
820
821 /// This method makes it possible to pack multiple `scale` in a single component batch.
822 ///
823 /// This only makes sense when used in conjunction with `columns`. `with_scale` should
824 /// be used when logging a single row's worth of data.
826 scale = ComponentBatch::from_loggable(_scale, Descriptor_scale).value_or_throw();
827 return std::move(*this);
828 }
829
830 /// 3x3 transformation matrix.
832 mat3x3 = ComponentBatch::from_loggable(_mat3x3, Descriptor_mat3x3).value_or_throw();
833 return std::move(*this);
834 }
835
836 /// This method makes it possible to pack multiple `mat3x3` in a single component batch.
837 ///
838 /// This only makes sense when used in conjunction with `columns`. `with_mat3x3` should
839 /// be used when logging a single row's worth of data.
841 ) && {
842 mat3x3 = ComponentBatch::from_loggable(_mat3x3, Descriptor_mat3x3).value_or_throw();
843 return std::move(*this);
844 }
845
846 /// Specifies the relation this transform establishes between this entity and its parent.
848 relation =
849 ComponentBatch::from_loggable(_relation, Descriptor_relation).value_or_throw();
850 return std::move(*this);
851 }
852
853 /// This method makes it possible to pack multiple `relation` in a single component batch.
854 ///
855 /// This only makes sense when used in conjunction with `columns`. `with_relation` should
856 /// be used when logging a single row's worth of data.
859 ) && {
860 relation =
861 ComponentBatch::from_loggable(_relation, Descriptor_relation).value_or_throw();
862 return std::move(*this);
863 }
864
865 /// Visual length of the 3 axes.
866 ///
867 /// The length is interpreted in the local coordinate system of the transform.
868 /// If the transform is scaled, the axes will be scaled accordingly.
871 .value_or_throw();
872 return std::move(*this);
873 }
874
875 /// This method makes it possible to pack multiple `axis_length` in a single component batch.
876 ///
877 /// This only makes sense when used in conjunction with `columns`. `with_axis_length` should
878 /// be used when logging a single row's worth of data.
881 ) && {
883 .value_or_throw();
884 return std::move(*this);
885 }
886
887 /// Partitions the component data into multiple sub-batches.
888 ///
889 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
890 /// instead, via `ComponentBatch::partitioned`.
891 ///
892 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
893 ///
894 /// The specified `lengths` must sum to the total length of the component batch.
896
897 /// Partitions the component data into unit-length sub-batches.
898 ///
899 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
900 /// where `n` is automatically guessed.
902 };
903
904} // namespace rerun::archetypes
905
906namespace rerun {
907 /// \private
908 template <typename T>
909 struct AsComponents;
910
911 /// \private
912 template <>
913 struct AsComponents<archetypes::Transform3D> {
914 /// Serialize all set component batches.
915 static Result<Collection<ComponentBatch>> as_batches(
916 const archetypes::Transform3D& archetype
917 );
918 };
919} // 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
TransformRelation
Component: Specifies relation a spatial transform describes.
Definition transform_relation.hpp:24
@ ChildFromParent
The transform describes how to transform into the child entity's space.
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
Utility for representing a single 3D rotation, agnostic to the underlying representation.
Definition rotation3d.hpp:14
Archetype: A transform between two 3D spaces, i.e.
Definition transform3d.hpp:302
static constexpr auto Descriptor_rotation_axis_angle
ComponentDescriptor for the rotation_axis_angle field.
Definition transform3d.hpp:337
static RERUN_SDK_EXPORT const Transform3D IDENTITY
Identity transformation.
Definition transform3d.hpp:370
std::optional< ComponentBatch > mat3x3
3x3 transformation matrix.
Definition transform3d.hpp:316
Transform3D with_many_axis_length(const Collection< rerun::components::AxisLength > &_axis_length) &&
This method makes it possible to pack multiple axis_length in a single component batch.
Definition transform3d.hpp:879
Transform3D(const datatypes::Vec3D(&columns)[3], bool from_parent=false)
From 3x3 matrix provided as 3 columns only.
Definition transform3d.hpp:481
Transform3D(const components::Translation3D &translation_, const components::TransformMat3x3 &mat3x3_, bool from_parent=false)
Creates a new 3D transform from translation/matrix.
Definition transform3d.hpp:398
static Transform3D from_translation_scale(const components::Translation3D &translation, const components::Scale3D &scale)
From a translation applied after a scale.
Definition transform3d.hpp:607
Transform3D with_relation(const rerun::components::TransformRelation &_relation) &&
Specifies the relation this transform establishes between this entity and its parent.
Definition transform3d.hpp:847
Transform3D(const components::Translation3D &translation_, const Rotation3D &rotation, float uniform_scale, bool from_parent=false)
Creates a new 3D transform from translation/rotation/uniform-scale.
Definition transform3d.hpp:523
std::optional< ComponentBatch > axis_length
Visual length of the 3 axes.
Definition transform3d.hpp:325
static Transform3D from_mat3x3(const components::TransformMat3x3 &mat3x3)
From 3x3 matrix only.
Definition transform3d.hpp:472
Transform3D(const components::Translation3D &translation_, const Rotation3D &rotation, const components::Scale3D &scale_, bool from_parent=false)
Creates a new 3D transform from translation/rotation/scale.
Definition transform3d.hpp:499
Transform3D(const Rotation3D &rotation, float uniform_scale, bool from_parent=false)
From rotation & uniform scale.
Definition transform3d.hpp:653
Transform3D(const components::Translation3D &translation_, float uniform_scale, bool from_parent=false)
From translation & uniform scale only.
Definition transform3d.hpp:622
Transform3D with_scale(const rerun::components::Scale3D &_scale) &&
Scaling factor.
Definition transform3d.hpp:816
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
static RERUN_SDK_EXPORT const Transform3D INVALID
Invalid transformation.
Definition transform3d.hpp:375
Transform3D with_quaternion(const rerun::components::RotationQuat &_quaternion) &&
Rotation via quaternion.
Definition transform3d.hpp:797
std::optional< ComponentBatch > translation
Translation vector.
Definition transform3d.hpp:304
Transform3D(const components::Translation3D &translation_, const Rotation3D &rotation, bool from_parent=false)
Creates a new rigid transform (translation & rotation only).
Definition transform3d.hpp:562
Transform3D(const components::Translation3D &translation_, const datatypes::Vec3D(&columns)[3], bool from_parent=false)
Creates a new 3D transform from translation and matrix provided as 3 columns.
Definition transform3d.hpp:386
Transform3D with_translation(const rerun::components::Translation3D &_translation) &&
Translation vector.
Definition transform3d.hpp:755
Transform3D(const Rotation3D &rotation, bool from_parent=false)
From rotation only.
Definition transform3d.hpp:681
Transform3D(const components::TransformMat3x3 &mat3x3_, bool from_parent=false)
From 3x3 matrix only.
Definition transform3d.hpp:460
Transform3D with_axis_length(const rerun::components::AxisLength &_axis_length) &&
Visual length of the 3 axes.
Definition transform3d.hpp:869
static Transform3D update_fields()
Update only some specific fields of a Transform3D.
Definition transform3d.hpp:747
static Transform3D from_rotation_scale(const Rotation3D &rotation, float uniform_scale)
From a rotation & uniform scale.
Definition transform3d.hpp:672
static Transform3D from_translation_mat3x3(const components::Translation3D &translation, const components::TransformMat3x3 &mat3x3)
From a translation applied after a 3x3 matrix.
Definition transform3d.hpp:414
static Transform3D from_rotation_scale(const Rotation3D &rotation, const components::Scale3D &scale)
From a rotation & scale.
Definition transform3d.hpp:661
static Transform3D from_translation(const components::Translation3D &translation)
From a translation.
Definition transform3d.hpp:451
static constexpr auto Descriptor_axis_length
ComponentDescriptor for the axis_length field.
Definition transform3d.hpp:361
Transform3D with_rotation(const Rotation3D &rotation) &&
Set the rotation component of the transform using the rerun::Rotation3D utility.
Definition transform3d.hpp:727
static Transform3D from_scale(float uniform_scale)
From scale only.
Definition transform3d.hpp:722
std::optional< ComponentBatch > rotation_axis_angle
Rotation via axis + angle.
Definition transform3d.hpp:307
Transform3D with_many_mat3x3(const Collection< rerun::components::TransformMat3x3 > &_mat3x3) &&
This method makes it possible to pack multiple mat3x3 in a single component batch.
Definition transform3d.hpp:840
static constexpr auto Descriptor_translation
ComponentDescriptor for the translation field.
Definition transform3d.hpp:332
Transform3D 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 transform3d.hpp:787
static constexpr auto Descriptor_quaternion
ComponentDescriptor for the quaternion field.
Definition transform3d.hpp:342
static Transform3D from_translation_rotation_scale(const components::Translation3D &translation, const Rotation3D &rotation, const components::Scale3D &scale)
From a translation, applied after a rotation & scale, known as an affine transformation.
Definition transform3d.hpp:536
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition transform3d.hpp:329
static constexpr auto Descriptor_scale
ComponentDescriptor for the scale field.
Definition transform3d.hpp:347
Transform3D(const components::Scale3D &scale_, bool from_parent=false)
From scale only.
Definition transform3d.hpp:702
static constexpr auto Descriptor_mat3x3
ComponentDescriptor for the mat3x3 field.
Definition transform3d.hpp:351
static Transform3D from_translation_mat3x3(const components::Translation3D &translation, const datatypes::Vec3D(&columns)[3])
From a translation applied after a 3x3 matrix provided as 3 columns.
Definition transform3d.hpp:425
static Transform3D from_translation_rotation(const components::Translation3D &translation, const Rotation3D &rotation)
From a rotation & scale.
Definition transform3d.hpp:579
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
std::optional< ComponentBatch > quaternion
Rotation via quaternion.
Definition transform3d.hpp:310
Transform3D(const Rotation3D &rotation, const components::Scale3D &scale_, bool from_parent=false)
From rotation & scale.
Definition transform3d.hpp:634
Transform3D with_many_relation(const Collection< rerun::components::TransformRelation > &_relation) &&
This method makes it possible to pack multiple relation in a single component batch.
Definition transform3d.hpp:857
Transform3D(const components::Translation3D &translation_, bool from_parent=false)
From translation only.
Definition transform3d.hpp:439
Transform3D with_many_quaternion(const Collection< rerun::components::RotationQuat > &_quaternion) &&
This method makes it possible to pack multiple quaternion in a single component batch.
Definition transform3d.hpp:807
Transform3D with_rotation_axis_angle(const rerun::components::RotationAxisAngle &_rotation_axis_angle) &&
Rotation via axis + angle.
Definition transform3d.hpp:774
Transform3D with_many_translation(const Collection< rerun::components::Translation3D > &_translation) &&
This method makes it possible to pack multiple translation in a single component batch.
Definition transform3d.hpp:765
Transform3D(const components::Translation3D &translation_, const components::Scale3D &scale_, bool from_parent=false)
From translation & scale only.
Definition transform3d.hpp:591
std::optional< ComponentBatch > relation
Specifies the relation this transform establishes between this entity and its parent.
Definition transform3d.hpp:319
static Transform3D clear_fields()
Clear all the fields of a Transform3D.
Transform3D with_many_scale(const Collection< rerun::components::Scale3D > &_scale) &&
This method makes it possible to pack multiple scale in a single component batch.
Definition transform3d.hpp:825
static Transform3D from_translation_rotation_scale(const components::Translation3D &translation, const Rotation3D &rotation, float uniform_scale)
From a translation, applied after a rotation & scale, known as an affine transformation.
Definition transform3d.hpp:549
Transform3D with_mat3x3(const rerun::components::TransformMat3x3 &_mat3x3) &&
3x3 transformation matrix.
Definition transform3d.hpp:831
static constexpr auto Descriptor_relation
ComponentDescriptor for the relation field.
Definition transform3d.hpp:356
static Transform3D from_scale(const components::Scale3D &scale)
From scale only.
Definition transform3d.hpp:714
static Transform3D from_mat3x3(const datatypes::Vec3D(&columns)[3])
From 3x3 matrix provided as 3 columns only.
Definition transform3d.hpp:488
std::optional< ComponentBatch > scale
Scaling factor.
Definition transform3d.hpp:313
static Transform3D from_rotation(const Rotation3D &rotation)
From rotation only.
Definition transform3d.hpp:693
Component: The length of an axis in local units of the space.
Definition axis_length.hpp:14
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 3D scale factor.
Definition scale3d.hpp:19
Component: A 3x3 transformation matrix Matrix.
Definition transform_mat3x3.hpp:27
Component: A translation vector in 3D space.
Definition translation3d.hpp:15
Datatype: A vector in 3D space.
Definition vec3d.hpp:20