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