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