re_types/archetypes/
line_strips3d.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/line_strips3d.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**: 3D line strips with positions and optional colors, radii, labels, etc.
23///
24/// ## Examples
25///
26/// ### Many strips
27/// ```ignore
28/// fn main() -> Result<(), Box<dyn std::error::Error>> {
29///     let rec = rerun::RecordingStreamBuilder::new("rerun_example_line_strip3d_batch").spawn()?;
30///
31///     let strip1 = [[0., 0., 2.], [1., 0., 2.], [1., 1., 2.], [0., 1., 2.]];
32///     let strip2 = [
33///         [0., 0., 0.],
34///         [0., 0., 1.],
35///         [1., 0., 0.],
36///         [1., 0., 1.],
37///         [1., 1., 0.],
38///         [1., 1., 1.],
39///         [0., 1., 0.],
40///         [0., 1., 1.],
41///     ];
42///     rec.log(
43///         "strips",
44///         &rerun::LineStrips3D::new([strip1.to_vec(), strip2.to_vec()])
45///             .with_colors([0xFF0000FF, 0x00FF00FF])
46///             .with_radii([0.025, 0.005])
47///             .with_labels(["one strip here", "and one strip there"]),
48///     )?;
49///
50///     Ok(())
51/// }
52/// ```
53/// <center>
54/// <picture>
55///   <source media="(max-width: 480px)" srcset="https://static.rerun.io/line_strip3d_batch/15e8ff18a6c95a3191acb0eae6eb04adea3b4874/480w.png">
56///   <source media="(max-width: 768px)" srcset="https://static.rerun.io/line_strip3d_batch/15e8ff18a6c95a3191acb0eae6eb04adea3b4874/768w.png">
57///   <source media="(max-width: 1024px)" srcset="https://static.rerun.io/line_strip3d_batch/15e8ff18a6c95a3191acb0eae6eb04adea3b4874/1024w.png">
58///   <source media="(max-width: 1200px)" srcset="https://static.rerun.io/line_strip3d_batch/15e8ff18a6c95a3191acb0eae6eb04adea3b4874/1200w.png">
59///   <img src="https://static.rerun.io/line_strip3d_batch/15e8ff18a6c95a3191acb0eae6eb04adea3b4874/full.png" width="640">
60/// </picture>
61/// </center>
62///
63/// ### Lines with scene & UI radius each
64/// ```ignore
65/// fn main() -> Result<(), Box<dyn std::error::Error>> {
66///     let rec = rerun::RecordingStreamBuilder::new("rerun_example_line_strip3d_ui_radius").spawn()?;
67///
68///     // A blue line with a scene unit radii of 0.01.
69///     let points = [[0., 0., 0.], [0., 0., 1.], [1., 0., 0.], [1., 0., 1.]];
70///     rec.log(
71///         "scene_unit_line",
72///         &rerun::LineStrips3D::new([points])
73///             // By default, radii are interpreted as world-space units.
74///             .with_radii([0.01])
75///             .with_colors([rerun::Color::from_rgb(0, 0, 255)]),
76///     )?;
77///
78///     // A red line with a ui point radii of 5.
79///     // UI points are independent of zooming in Views, but are sensitive to the application UI scaling.
80///     // For 100 % ui scaling, UI points are equal to pixels.
81///     let points = [[3., 0., 0.], [3., 0., 1.], [4., 0., 0.], [4., 0., 1.]];
82///     rec.log(
83///         "ui_points_line",
84///         &rerun::LineStrips3D::new([points])
85///             // rerun::Radius::new_ui_points produces a radius that the viewer interprets as given in ui points.
86///             .with_radii([rerun::Radius::new_ui_points(5.0)])
87///             .with_colors([rerun::Color::from_rgb(255, 0, 0)]),
88///     )?;
89///
90///     Ok(())
91/// }
92/// ```
93/// <center>
94/// <picture>
95///   <source media="(max-width: 480px)" srcset="https://static.rerun.io/line_strip3d_ui_radius/36b98f47e45747b5a3601511ff39b8d74c61d120/480w.png">
96///   <source media="(max-width: 768px)" srcset="https://static.rerun.io/line_strip3d_ui_radius/36b98f47e45747b5a3601511ff39b8d74c61d120/768w.png">
97///   <source media="(max-width: 1024px)" srcset="https://static.rerun.io/line_strip3d_ui_radius/36b98f47e45747b5a3601511ff39b8d74c61d120/1024w.png">
98///   <source media="(max-width: 1200px)" srcset="https://static.rerun.io/line_strip3d_ui_radius/36b98f47e45747b5a3601511ff39b8d74c61d120/1200w.png">
99///   <img src="https://static.rerun.io/line_strip3d_ui_radius/36b98f47e45747b5a3601511ff39b8d74c61d120/full.png" width="640">
100/// </picture>
101/// </center>
102#[derive(Clone, Debug, PartialEq, Default)]
103pub struct LineStrips3D {
104    /// All the actual 3D line strips that make up the batch.
105    pub strips: Option<SerializedComponentBatch>,
106
107    /// Optional radii for the line strips.
108    pub radii: Option<SerializedComponentBatch>,
109
110    /// Optional colors for the line strips.
111    pub colors: Option<SerializedComponentBatch>,
112
113    /// Optional text labels for the line strips.
114    ///
115    /// If there's a single label present, it will be placed at the center of the entity.
116    /// Otherwise, each instance will have its own label.
117    pub labels: Option<SerializedComponentBatch>,
118
119    /// Whether the text labels should be shown.
120    ///
121    /// If not set, labels will automatically appear when there is exactly one label for this entity
122    /// or the number of instances on this entity is under a certain threshold.
123    pub show_labels: Option<SerializedComponentBatch>,
124
125    /// Optional [`components::ClassId`][crate::components::ClassId]s for the lines.
126    ///
127    /// The [`components::ClassId`][crate::components::ClassId] provides colors and labels if not specified explicitly.
128    pub class_ids: Option<SerializedComponentBatch>,
129}
130
131impl LineStrips3D {
132    /// Returns the [`ComponentDescriptor`] for [`Self::strips`].
133    ///
134    /// The corresponding component is [`crate::components::LineStrip3D`].
135    #[inline]
136    pub fn descriptor_strips() -> ComponentDescriptor {
137        ComponentDescriptor {
138            archetype: Some("rerun.archetypes.LineStrips3D".into()),
139            component: "LineStrips3D:strips".into(),
140            component_type: Some("rerun.components.LineStrip3D".into()),
141        }
142    }
143
144    /// Returns the [`ComponentDescriptor`] for [`Self::radii`].
145    ///
146    /// The corresponding component is [`crate::components::Radius`].
147    #[inline]
148    pub fn descriptor_radii() -> ComponentDescriptor {
149        ComponentDescriptor {
150            archetype: Some("rerun.archetypes.LineStrips3D".into()),
151            component: "LineStrips3D:radii".into(),
152            component_type: Some("rerun.components.Radius".into()),
153        }
154    }
155
156    /// Returns the [`ComponentDescriptor`] for [`Self::colors`].
157    ///
158    /// The corresponding component is [`crate::components::Color`].
159    #[inline]
160    pub fn descriptor_colors() -> ComponentDescriptor {
161        ComponentDescriptor {
162            archetype: Some("rerun.archetypes.LineStrips3D".into()),
163            component: "LineStrips3D:colors".into(),
164            component_type: Some("rerun.components.Color".into()),
165        }
166    }
167
168    /// Returns the [`ComponentDescriptor`] for [`Self::labels`].
169    ///
170    /// The corresponding component is [`crate::components::Text`].
171    #[inline]
172    pub fn descriptor_labels() -> ComponentDescriptor {
173        ComponentDescriptor {
174            archetype: Some("rerun.archetypes.LineStrips3D".into()),
175            component: "LineStrips3D:labels".into(),
176            component_type: Some("rerun.components.Text".into()),
177        }
178    }
179
180    /// Returns the [`ComponentDescriptor`] for [`Self::show_labels`].
181    ///
182    /// The corresponding component is [`crate::components::ShowLabels`].
183    #[inline]
184    pub fn descriptor_show_labels() -> ComponentDescriptor {
185        ComponentDescriptor {
186            archetype: Some("rerun.archetypes.LineStrips3D".into()),
187            component: "LineStrips3D:show_labels".into(),
188            component_type: Some("rerun.components.ShowLabels".into()),
189        }
190    }
191
192    /// Returns the [`ComponentDescriptor`] for [`Self::class_ids`].
193    ///
194    /// The corresponding component is [`crate::components::ClassId`].
195    #[inline]
196    pub fn descriptor_class_ids() -> ComponentDescriptor {
197        ComponentDescriptor {
198            archetype: Some("rerun.archetypes.LineStrips3D".into()),
199            component: "LineStrips3D:class_ids".into(),
200            component_type: Some("rerun.components.ClassId".into()),
201        }
202    }
203}
204
205static REQUIRED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 1usize]> =
206    once_cell::sync::Lazy::new(|| [LineStrips3D::descriptor_strips()]);
207
208static RECOMMENDED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 2usize]> =
209    once_cell::sync::Lazy::new(|| {
210        [
211            LineStrips3D::descriptor_radii(),
212            LineStrips3D::descriptor_colors(),
213        ]
214    });
215
216static OPTIONAL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 3usize]> =
217    once_cell::sync::Lazy::new(|| {
218        [
219            LineStrips3D::descriptor_labels(),
220            LineStrips3D::descriptor_show_labels(),
221            LineStrips3D::descriptor_class_ids(),
222        ]
223    });
224
225static ALL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 6usize]> =
226    once_cell::sync::Lazy::new(|| {
227        [
228            LineStrips3D::descriptor_strips(),
229            LineStrips3D::descriptor_radii(),
230            LineStrips3D::descriptor_colors(),
231            LineStrips3D::descriptor_labels(),
232            LineStrips3D::descriptor_show_labels(),
233            LineStrips3D::descriptor_class_ids(),
234        ]
235    });
236
237impl LineStrips3D {
238    /// The total number of components in the archetype: 1 required, 2 recommended, 3 optional
239    pub const NUM_COMPONENTS: usize = 6usize;
240}
241
242impl ::re_types_core::Archetype for LineStrips3D {
243    #[inline]
244    fn name() -> ::re_types_core::ArchetypeName {
245        "rerun.archetypes.LineStrips3D".into()
246    }
247
248    #[inline]
249    fn display_name() -> &'static str {
250        "Line strips 3D"
251    }
252
253    #[inline]
254    fn required_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
255        REQUIRED_COMPONENTS.as_slice().into()
256    }
257
258    #[inline]
259    fn recommended_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
260        RECOMMENDED_COMPONENTS.as_slice().into()
261    }
262
263    #[inline]
264    fn optional_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
265        OPTIONAL_COMPONENTS.as_slice().into()
266    }
267
268    #[inline]
269    fn all_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
270        ALL_COMPONENTS.as_slice().into()
271    }
272
273    #[inline]
274    fn from_arrow_components(
275        arrow_data: impl IntoIterator<Item = (ComponentDescriptor, arrow::array::ArrayRef)>,
276    ) -> DeserializationResult<Self> {
277        re_tracing::profile_function!();
278        use ::re_types_core::{Loggable as _, ResultExt as _};
279        let arrays_by_descr: ::nohash_hasher::IntMap<_, _> = arrow_data.into_iter().collect();
280        let strips = arrays_by_descr
281            .get(&Self::descriptor_strips())
282            .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_strips()));
283        let radii = arrays_by_descr
284            .get(&Self::descriptor_radii())
285            .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_radii()));
286        let colors = arrays_by_descr
287            .get(&Self::descriptor_colors())
288            .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_colors()));
289        let labels = arrays_by_descr
290            .get(&Self::descriptor_labels())
291            .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_labels()));
292        let show_labels = arrays_by_descr
293            .get(&Self::descriptor_show_labels())
294            .map(|array| {
295                SerializedComponentBatch::new(array.clone(), Self::descriptor_show_labels())
296            });
297        let class_ids = arrays_by_descr
298            .get(&Self::descriptor_class_ids())
299            .map(|array| {
300                SerializedComponentBatch::new(array.clone(), Self::descriptor_class_ids())
301            });
302        Ok(Self {
303            strips,
304            radii,
305            colors,
306            labels,
307            show_labels,
308            class_ids,
309        })
310    }
311}
312
313impl ::re_types_core::AsComponents for LineStrips3D {
314    #[inline]
315    fn as_serialized_batches(&self) -> Vec<SerializedComponentBatch> {
316        use ::re_types_core::Archetype as _;
317        [
318            self.strips.clone(),
319            self.radii.clone(),
320            self.colors.clone(),
321            self.labels.clone(),
322            self.show_labels.clone(),
323            self.class_ids.clone(),
324        ]
325        .into_iter()
326        .flatten()
327        .collect()
328    }
329}
330
331impl ::re_types_core::ArchetypeReflectionMarker for LineStrips3D {}
332
333impl LineStrips3D {
334    /// Create a new `LineStrips3D`.
335    #[inline]
336    pub fn new(
337        strips: impl IntoIterator<Item = impl Into<crate::components::LineStrip3D>>,
338    ) -> Self {
339        Self {
340            strips: try_serialize_field(Self::descriptor_strips(), strips),
341            radii: None,
342            colors: None,
343            labels: None,
344            show_labels: None,
345            class_ids: None,
346        }
347    }
348
349    /// Update only some specific fields of a `LineStrips3D`.
350    #[inline]
351    pub fn update_fields() -> Self {
352        Self::default()
353    }
354
355    /// Clear all the fields of a `LineStrips3D`.
356    #[inline]
357    pub fn clear_fields() -> Self {
358        use ::re_types_core::Loggable as _;
359        Self {
360            strips: Some(SerializedComponentBatch::new(
361                crate::components::LineStrip3D::arrow_empty(),
362                Self::descriptor_strips(),
363            )),
364            radii: Some(SerializedComponentBatch::new(
365                crate::components::Radius::arrow_empty(),
366                Self::descriptor_radii(),
367            )),
368            colors: Some(SerializedComponentBatch::new(
369                crate::components::Color::arrow_empty(),
370                Self::descriptor_colors(),
371            )),
372            labels: Some(SerializedComponentBatch::new(
373                crate::components::Text::arrow_empty(),
374                Self::descriptor_labels(),
375            )),
376            show_labels: Some(SerializedComponentBatch::new(
377                crate::components::ShowLabels::arrow_empty(),
378                Self::descriptor_show_labels(),
379            )),
380            class_ids: Some(SerializedComponentBatch::new(
381                crate::components::ClassId::arrow_empty(),
382                Self::descriptor_class_ids(),
383            )),
384        }
385    }
386
387    /// Partitions the component data into multiple sub-batches.
388    ///
389    /// Specifically, this transforms the existing [`SerializedComponentBatch`]es data into [`SerializedComponentColumn`]s
390    /// instead, via [`SerializedComponentBatch::partitioned`].
391    ///
392    /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
393    ///
394    /// The specified `lengths` must sum to the total length of the component batch.
395    ///
396    /// [`SerializedComponentColumn`]: [::re_types_core::SerializedComponentColumn]
397    #[inline]
398    pub fn columns<I>(
399        self,
400        _lengths: I,
401    ) -> SerializationResult<impl Iterator<Item = ::re_types_core::SerializedComponentColumn>>
402    where
403        I: IntoIterator<Item = usize> + Clone,
404    {
405        let columns = [
406            self.strips
407                .map(|strips| strips.partitioned(_lengths.clone()))
408                .transpose()?,
409            self.radii
410                .map(|radii| radii.partitioned(_lengths.clone()))
411                .transpose()?,
412            self.colors
413                .map(|colors| colors.partitioned(_lengths.clone()))
414                .transpose()?,
415            self.labels
416                .map(|labels| labels.partitioned(_lengths.clone()))
417                .transpose()?,
418            self.show_labels
419                .map(|show_labels| show_labels.partitioned(_lengths.clone()))
420                .transpose()?,
421            self.class_ids
422                .map(|class_ids| class_ids.partitioned(_lengths.clone()))
423                .transpose()?,
424        ];
425        Ok(columns.into_iter().flatten())
426    }
427
428    /// Helper to partition the component data into unit-length sub-batches.
429    ///
430    /// This is semantically similar to calling [`Self::columns`] with `std::iter::take(1).repeat(n)`,
431    /// where `n` is automatically guessed.
432    #[inline]
433    pub fn columns_of_unit_batches(
434        self,
435    ) -> SerializationResult<impl Iterator<Item = ::re_types_core::SerializedComponentColumn>> {
436        let len_strips = self.strips.as_ref().map(|b| b.array.len());
437        let len_radii = self.radii.as_ref().map(|b| b.array.len());
438        let len_colors = self.colors.as_ref().map(|b| b.array.len());
439        let len_labels = self.labels.as_ref().map(|b| b.array.len());
440        let len_show_labels = self.show_labels.as_ref().map(|b| b.array.len());
441        let len_class_ids = self.class_ids.as_ref().map(|b| b.array.len());
442        let len = None
443            .or(len_strips)
444            .or(len_radii)
445            .or(len_colors)
446            .or(len_labels)
447            .or(len_show_labels)
448            .or(len_class_ids)
449            .unwrap_or(0);
450        self.columns(std::iter::repeat(1).take(len))
451    }
452
453    /// All the actual 3D line strips that make up the batch.
454    #[inline]
455    pub fn with_strips(
456        mut self,
457        strips: impl IntoIterator<Item = impl Into<crate::components::LineStrip3D>>,
458    ) -> Self {
459        self.strips = try_serialize_field(Self::descriptor_strips(), strips);
460        self
461    }
462
463    /// Optional radii for the line strips.
464    #[inline]
465    pub fn with_radii(
466        mut self,
467        radii: impl IntoIterator<Item = impl Into<crate::components::Radius>>,
468    ) -> Self {
469        self.radii = try_serialize_field(Self::descriptor_radii(), radii);
470        self
471    }
472
473    /// Optional colors for the line strips.
474    #[inline]
475    pub fn with_colors(
476        mut self,
477        colors: impl IntoIterator<Item = impl Into<crate::components::Color>>,
478    ) -> Self {
479        self.colors = try_serialize_field(Self::descriptor_colors(), colors);
480        self
481    }
482
483    /// Optional text labels for the line strips.
484    ///
485    /// If there's a single label present, it will be placed at the center of the entity.
486    /// Otherwise, each instance will have its own label.
487    #[inline]
488    pub fn with_labels(
489        mut self,
490        labels: impl IntoIterator<Item = impl Into<crate::components::Text>>,
491    ) -> Self {
492        self.labels = try_serialize_field(Self::descriptor_labels(), labels);
493        self
494    }
495
496    /// Whether the text labels should be shown.
497    ///
498    /// If not set, labels will automatically appear when there is exactly one label for this entity
499    /// or the number of instances on this entity is under a certain threshold.
500    #[inline]
501    pub fn with_show_labels(
502        mut self,
503        show_labels: impl Into<crate::components::ShowLabels>,
504    ) -> Self {
505        self.show_labels = try_serialize_field(Self::descriptor_show_labels(), [show_labels]);
506        self
507    }
508
509    /// This method makes it possible to pack multiple [`crate::components::ShowLabels`] in a single component batch.
510    ///
511    /// This only makes sense when used in conjunction with [`Self::columns`]. [`Self::with_show_labels`] should
512    /// be used when logging a single row's worth of data.
513    #[inline]
514    pub fn with_many_show_labels(
515        mut self,
516        show_labels: impl IntoIterator<Item = impl Into<crate::components::ShowLabels>>,
517    ) -> Self {
518        self.show_labels = try_serialize_field(Self::descriptor_show_labels(), show_labels);
519        self
520    }
521
522    /// Optional [`components::ClassId`][crate::components::ClassId]s for the lines.
523    ///
524    /// The [`components::ClassId`][crate::components::ClassId] provides colors and labels if not specified explicitly.
525    #[inline]
526    pub fn with_class_ids(
527        mut self,
528        class_ids: impl IntoIterator<Item = impl Into<crate::components::ClassId>>,
529    ) -> Self {
530        self.class_ids = try_serialize_field(Self::descriptor_class_ids(), class_ids);
531        self
532    }
533}
534
535impl ::re_byte_size::SizeBytes for LineStrips3D {
536    #[inline]
537    fn heap_size_bytes(&self) -> u64 {
538        self.strips.heap_size_bytes()
539            + self.radii.heap_size_bytes()
540            + self.colors.heap_size_bytes()
541            + self.labels.heap_size_bytes()
542            + self.show_labels.heap_size_bytes()
543            + self.class_ids.heap_size_bytes()
544    }
545}