re_types/archetypes/
instance_poses3d.rs

1// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/rust/api.rs
2// Based on "crates/store/re_types/definitions/rerun/archetypes/instance_poses3d.fbs".
3
4#![allow(unused_braces)]
5#![allow(unused_imports)]
6#![allow(unused_parens)]
7#![allow(clippy::clone_on_copy)]
8#![allow(clippy::cloned_instead_of_copied)]
9#![allow(clippy::map_flatten)]
10#![allow(clippy::needless_question_mark)]
11#![allow(clippy::new_without_default)]
12#![allow(clippy::redundant_closure)]
13#![allow(clippy::too_many_arguments)]
14#![allow(clippy::too_many_lines)]
15
16use ::re_types_core::try_serialize_field;
17use ::re_types_core::SerializationResult;
18use ::re_types_core::{ComponentBatch as _, SerializedComponentBatch};
19use ::re_types_core::{ComponentDescriptor, ComponentType};
20use ::re_types_core::{DeserializationError, DeserializationResult};
21
22/// **Archetype**: One or more transforms between the current entity and its parent. Unlike [`archetypes::Transform3D`][crate::archetypes::Transform3D], it is *not* propagated in the transform hierarchy.
23///
24/// If both [`archetypes::InstancePoses3D`][crate::archetypes::InstancePoses3D] and [`archetypes::Transform3D`][crate::archetypes::Transform3D] are present,
25/// first the tree propagating [`archetypes::Transform3D`][crate::archetypes::Transform3D] is applied, then [`archetypes::InstancePoses3D`][crate::archetypes::InstancePoses3D].
26///
27/// From the point of view of the entity's coordinate system,
28/// all components are applied in the inverse order they are listed here.
29/// E.g. if both a translation and a max3x3 transform are present,
30/// the 3x3 matrix is applied first, followed by the translation.
31///
32/// Currently, many visualizers support only a single instance transform per entity.
33/// Check archetype documentations for details - if not otherwise specified, only the first instance transform is applied.
34/// Some visualizers like the mesh visualizer used for [`archetypes::Mesh3D`][crate::archetypes::Mesh3D],
35/// will draw an object for every pose, a behavior also known as "instancing".
36///
37/// ## Example
38///
39/// ### Regular & instance transforms in tandem
40/// ```ignore
41/// use rerun::{
42///     demo_util::grid,
43///     external::{anyhow, glam},
44/// };
45///
46/// fn main() -> anyhow::Result<()> {
47///     let rec =
48///         rerun::RecordingStreamBuilder::new("rerun_example_instance_pose3d_combined").spawn()?;
49///
50///     rec.set_time_sequence("frame", 0);
51///
52///     // Log a box and points further down in the hierarchy.
53///     rec.log(
54///         "world/box",
55///         &rerun::Boxes3D::from_half_sizes([[1.0, 1.0, 1.0]]),
56///     )?;
57///     rec.log(
58///         "world/box/points",
59///         &rerun::Points3D::new(grid(glam::Vec3::splat(-10.0), glam::Vec3::splat(10.0), 10)),
60///     )?;
61///
62///     for i in 0..180 {
63///         rec.set_time_sequence("frame", i);
64///
65///         // Log a regular transform which affects both the box and the points.
66///         rec.log(
67///             "world/box",
68///             &rerun::Transform3D::from_rotation(rerun::RotationAxisAngle {
69///                 axis: [0.0, 0.0, 1.0].into(),
70///                 angle: rerun::Angle::from_degrees(i as f32 * 2.0),
71///             }),
72///         )?;
73///
74///         // Log an instance pose which affects only the box.
75///         let translation = [0.0, 0.0, (i as f32 * 0.1 - 5.0).abs() - 5.0];
76///         rec.log(
77///             "world/box",
78///             &rerun::InstancePoses3D::new().with_translations([translation]),
79///         )?;
80///     }
81///
82///     Ok(())
83/// }
84/// ```
85/// <center>
86/// <picture>
87///   <source media="(max-width: 480px)" srcset="https://static.rerun.io/leaf_transform3d/41674f0082d6de489f8a1cd1583f60f6b5820ddf/480w.png">
88///   <source media="(max-width: 768px)" srcset="https://static.rerun.io/leaf_transform3d/41674f0082d6de489f8a1cd1583f60f6b5820ddf/768w.png">
89///   <source media="(max-width: 1024px)" srcset="https://static.rerun.io/leaf_transform3d/41674f0082d6de489f8a1cd1583f60f6b5820ddf/1024w.png">
90///   <source media="(max-width: 1200px)" srcset="https://static.rerun.io/leaf_transform3d/41674f0082d6de489f8a1cd1583f60f6b5820ddf/1200w.png">
91///   <img src="https://static.rerun.io/leaf_transform3d/41674f0082d6de489f8a1cd1583f60f6b5820ddf/full.png" width="640">
92/// </picture>
93/// </center>
94#[derive(Clone, Debug, PartialEq, Default)]
95pub struct InstancePoses3D {
96    /// Translation vectors.
97    pub translations: Option<SerializedComponentBatch>,
98
99    /// Rotations via axis + angle.
100    pub rotation_axis_angles: Option<SerializedComponentBatch>,
101
102    /// Rotations via quaternion.
103    pub quaternions: Option<SerializedComponentBatch>,
104
105    /// Scaling factors.
106    pub scales: Option<SerializedComponentBatch>,
107
108    /// 3x3 transformation matrices.
109    pub mat3x3: Option<SerializedComponentBatch>,
110}
111
112impl InstancePoses3D {
113    /// Returns the [`ComponentDescriptor`] for [`Self::translations`].
114    ///
115    /// The corresponding component is [`crate::components::PoseTranslation3D`].
116    #[inline]
117    pub fn descriptor_translations() -> ComponentDescriptor {
118        ComponentDescriptor {
119            archetype: Some("rerun.archetypes.InstancePoses3D".into()),
120            component: "InstancePoses3D:translations".into(),
121            component_type: Some("rerun.components.PoseTranslation3D".into()),
122        }
123    }
124
125    /// Returns the [`ComponentDescriptor`] for [`Self::rotation_axis_angles`].
126    ///
127    /// The corresponding component is [`crate::components::PoseRotationAxisAngle`].
128    #[inline]
129    pub fn descriptor_rotation_axis_angles() -> ComponentDescriptor {
130        ComponentDescriptor {
131            archetype: Some("rerun.archetypes.InstancePoses3D".into()),
132            component: "InstancePoses3D:rotation_axis_angles".into(),
133            component_type: Some("rerun.components.PoseRotationAxisAngle".into()),
134        }
135    }
136
137    /// Returns the [`ComponentDescriptor`] for [`Self::quaternions`].
138    ///
139    /// The corresponding component is [`crate::components::PoseRotationQuat`].
140    #[inline]
141    pub fn descriptor_quaternions() -> ComponentDescriptor {
142        ComponentDescriptor {
143            archetype: Some("rerun.archetypes.InstancePoses3D".into()),
144            component: "InstancePoses3D:quaternions".into(),
145            component_type: Some("rerun.components.PoseRotationQuat".into()),
146        }
147    }
148
149    /// Returns the [`ComponentDescriptor`] for [`Self::scales`].
150    ///
151    /// The corresponding component is [`crate::components::PoseScale3D`].
152    #[inline]
153    pub fn descriptor_scales() -> ComponentDescriptor {
154        ComponentDescriptor {
155            archetype: Some("rerun.archetypes.InstancePoses3D".into()),
156            component: "InstancePoses3D:scales".into(),
157            component_type: Some("rerun.components.PoseScale3D".into()),
158        }
159    }
160
161    /// Returns the [`ComponentDescriptor`] for [`Self::mat3x3`].
162    ///
163    /// The corresponding component is [`crate::components::PoseTransformMat3x3`].
164    #[inline]
165    pub fn descriptor_mat3x3() -> ComponentDescriptor {
166        ComponentDescriptor {
167            archetype: Some("rerun.archetypes.InstancePoses3D".into()),
168            component: "InstancePoses3D:mat3x3".into(),
169            component_type: Some("rerun.components.PoseTransformMat3x3".into()),
170        }
171    }
172}
173
174static REQUIRED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 0usize]> =
175    once_cell::sync::Lazy::new(|| []);
176
177static RECOMMENDED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 0usize]> =
178    once_cell::sync::Lazy::new(|| []);
179
180static OPTIONAL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 5usize]> =
181    once_cell::sync::Lazy::new(|| {
182        [
183            InstancePoses3D::descriptor_translations(),
184            InstancePoses3D::descriptor_rotation_axis_angles(),
185            InstancePoses3D::descriptor_quaternions(),
186            InstancePoses3D::descriptor_scales(),
187            InstancePoses3D::descriptor_mat3x3(),
188        ]
189    });
190
191static ALL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 5usize]> =
192    once_cell::sync::Lazy::new(|| {
193        [
194            InstancePoses3D::descriptor_translations(),
195            InstancePoses3D::descriptor_rotation_axis_angles(),
196            InstancePoses3D::descriptor_quaternions(),
197            InstancePoses3D::descriptor_scales(),
198            InstancePoses3D::descriptor_mat3x3(),
199        ]
200    });
201
202impl InstancePoses3D {
203    /// The total number of components in the archetype: 0 required, 0 recommended, 5 optional
204    pub const NUM_COMPONENTS: usize = 5usize;
205}
206
207impl ::re_types_core::Archetype for InstancePoses3D {
208    #[inline]
209    fn name() -> ::re_types_core::ArchetypeName {
210        "rerun.archetypes.InstancePoses3D".into()
211    }
212
213    #[inline]
214    fn display_name() -> &'static str {
215        "Instance poses 3D"
216    }
217
218    #[inline]
219    fn required_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
220        REQUIRED_COMPONENTS.as_slice().into()
221    }
222
223    #[inline]
224    fn recommended_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
225        RECOMMENDED_COMPONENTS.as_slice().into()
226    }
227
228    #[inline]
229    fn optional_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
230        OPTIONAL_COMPONENTS.as_slice().into()
231    }
232
233    #[inline]
234    fn all_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
235        ALL_COMPONENTS.as_slice().into()
236    }
237
238    #[inline]
239    fn from_arrow_components(
240        arrow_data: impl IntoIterator<Item = (ComponentDescriptor, arrow::array::ArrayRef)>,
241    ) -> DeserializationResult<Self> {
242        re_tracing::profile_function!();
243        use ::re_types_core::{Loggable as _, ResultExt as _};
244        let arrays_by_descr: ::nohash_hasher::IntMap<_, _> = arrow_data.into_iter().collect();
245        let translations = arrays_by_descr
246            .get(&Self::descriptor_translations())
247            .map(|array| {
248                SerializedComponentBatch::new(array.clone(), Self::descriptor_translations())
249            });
250        let rotation_axis_angles = arrays_by_descr
251            .get(&Self::descriptor_rotation_axis_angles())
252            .map(|array| {
253                SerializedComponentBatch::new(
254                    array.clone(),
255                    Self::descriptor_rotation_axis_angles(),
256                )
257            });
258        let quaternions = arrays_by_descr
259            .get(&Self::descriptor_quaternions())
260            .map(|array| {
261                SerializedComponentBatch::new(array.clone(), Self::descriptor_quaternions())
262            });
263        let scales = arrays_by_descr
264            .get(&Self::descriptor_scales())
265            .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_scales()));
266        let mat3x3 = arrays_by_descr
267            .get(&Self::descriptor_mat3x3())
268            .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_mat3x3()));
269        Ok(Self {
270            translations,
271            rotation_axis_angles,
272            quaternions,
273            scales,
274            mat3x3,
275        })
276    }
277}
278
279impl ::re_types_core::AsComponents for InstancePoses3D {
280    #[inline]
281    fn as_serialized_batches(&self) -> Vec<SerializedComponentBatch> {
282        use ::re_types_core::Archetype as _;
283        [
284            self.translations.clone(),
285            self.rotation_axis_angles.clone(),
286            self.quaternions.clone(),
287            self.scales.clone(),
288            self.mat3x3.clone(),
289        ]
290        .into_iter()
291        .flatten()
292        .collect()
293    }
294}
295
296impl ::re_types_core::ArchetypeReflectionMarker for InstancePoses3D {}
297
298impl InstancePoses3D {
299    /// Create a new `InstancePoses3D`.
300    #[inline]
301    pub fn new() -> Self {
302        Self {
303            translations: None,
304            rotation_axis_angles: None,
305            quaternions: None,
306            scales: None,
307            mat3x3: None,
308        }
309    }
310
311    /// Update only some specific fields of a `InstancePoses3D`.
312    #[inline]
313    pub fn update_fields() -> Self {
314        Self::default()
315    }
316
317    /// Clear all the fields of a `InstancePoses3D`.
318    #[inline]
319    pub fn clear_fields() -> Self {
320        use ::re_types_core::Loggable as _;
321        Self {
322            translations: Some(SerializedComponentBatch::new(
323                crate::components::PoseTranslation3D::arrow_empty(),
324                Self::descriptor_translations(),
325            )),
326            rotation_axis_angles: Some(SerializedComponentBatch::new(
327                crate::components::PoseRotationAxisAngle::arrow_empty(),
328                Self::descriptor_rotation_axis_angles(),
329            )),
330            quaternions: Some(SerializedComponentBatch::new(
331                crate::components::PoseRotationQuat::arrow_empty(),
332                Self::descriptor_quaternions(),
333            )),
334            scales: Some(SerializedComponentBatch::new(
335                crate::components::PoseScale3D::arrow_empty(),
336                Self::descriptor_scales(),
337            )),
338            mat3x3: Some(SerializedComponentBatch::new(
339                crate::components::PoseTransformMat3x3::arrow_empty(),
340                Self::descriptor_mat3x3(),
341            )),
342        }
343    }
344
345    /// Partitions the component data into multiple sub-batches.
346    ///
347    /// Specifically, this transforms the existing [`SerializedComponentBatch`]es data into [`SerializedComponentColumn`]s
348    /// instead, via [`SerializedComponentBatch::partitioned`].
349    ///
350    /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
351    ///
352    /// The specified `lengths` must sum to the total length of the component batch.
353    ///
354    /// [`SerializedComponentColumn`]: [::re_types_core::SerializedComponentColumn]
355    #[inline]
356    pub fn columns<I>(
357        self,
358        _lengths: I,
359    ) -> SerializationResult<impl Iterator<Item = ::re_types_core::SerializedComponentColumn>>
360    where
361        I: IntoIterator<Item = usize> + Clone,
362    {
363        let columns = [
364            self.translations
365                .map(|translations| translations.partitioned(_lengths.clone()))
366                .transpose()?,
367            self.rotation_axis_angles
368                .map(|rotation_axis_angles| rotation_axis_angles.partitioned(_lengths.clone()))
369                .transpose()?,
370            self.quaternions
371                .map(|quaternions| quaternions.partitioned(_lengths.clone()))
372                .transpose()?,
373            self.scales
374                .map(|scales| scales.partitioned(_lengths.clone()))
375                .transpose()?,
376            self.mat3x3
377                .map(|mat3x3| mat3x3.partitioned(_lengths.clone()))
378                .transpose()?,
379        ];
380        Ok(columns.into_iter().flatten())
381    }
382
383    /// Helper to partition the component data into unit-length sub-batches.
384    ///
385    /// This is semantically similar to calling [`Self::columns`] with `std::iter::take(1).repeat(n)`,
386    /// where `n` is automatically guessed.
387    #[inline]
388    pub fn columns_of_unit_batches(
389        self,
390    ) -> SerializationResult<impl Iterator<Item = ::re_types_core::SerializedComponentColumn>> {
391        let len_translations = self.translations.as_ref().map(|b| b.array.len());
392        let len_rotation_axis_angles = self.rotation_axis_angles.as_ref().map(|b| b.array.len());
393        let len_quaternions = self.quaternions.as_ref().map(|b| b.array.len());
394        let len_scales = self.scales.as_ref().map(|b| b.array.len());
395        let len_mat3x3 = self.mat3x3.as_ref().map(|b| b.array.len());
396        let len = None
397            .or(len_translations)
398            .or(len_rotation_axis_angles)
399            .or(len_quaternions)
400            .or(len_scales)
401            .or(len_mat3x3)
402            .unwrap_or(0);
403        self.columns(std::iter::repeat(1).take(len))
404    }
405
406    /// Translation vectors.
407    #[inline]
408    pub fn with_translations(
409        mut self,
410        translations: impl IntoIterator<Item = impl Into<crate::components::PoseTranslation3D>>,
411    ) -> Self {
412        self.translations = try_serialize_field(Self::descriptor_translations(), translations);
413        self
414    }
415
416    /// Rotations via axis + angle.
417    #[inline]
418    pub fn with_rotation_axis_angles(
419        mut self,
420        rotation_axis_angles: impl IntoIterator<
421            Item = impl Into<crate::components::PoseRotationAxisAngle>,
422        >,
423    ) -> Self {
424        self.rotation_axis_angles = try_serialize_field(
425            Self::descriptor_rotation_axis_angles(),
426            rotation_axis_angles,
427        );
428        self
429    }
430
431    /// Rotations via quaternion.
432    #[inline]
433    pub fn with_quaternions(
434        mut self,
435        quaternions: impl IntoIterator<Item = impl Into<crate::components::PoseRotationQuat>>,
436    ) -> Self {
437        self.quaternions = try_serialize_field(Self::descriptor_quaternions(), quaternions);
438        self
439    }
440
441    /// Scaling factors.
442    #[inline]
443    pub fn with_scales(
444        mut self,
445        scales: impl IntoIterator<Item = impl Into<crate::components::PoseScale3D>>,
446    ) -> Self {
447        self.scales = try_serialize_field(Self::descriptor_scales(), scales);
448        self
449    }
450
451    /// 3x3 transformation matrices.
452    #[inline]
453    pub fn with_mat3x3(
454        mut self,
455        mat3x3: impl IntoIterator<Item = impl Into<crate::components::PoseTransformMat3x3>>,
456    ) -> Self {
457        self.mat3x3 = try_serialize_field(Self::descriptor_mat3x3(), mat3x3);
458        self
459    }
460}
461
462impl ::re_byte_size::SizeBytes for InstancePoses3D {
463    #[inline]
464    fn heap_size_bytes(&self) -> u64 {
465        self.translations.heap_size_bytes()
466            + self.rotation_axis_angles.heap_size_bytes()
467            + self.quaternions.heap_size_bytes()
468            + self.scales.heap_size_bytes()
469            + self.mat3x3.heap_size_bytes()
470    }
471}