re_types_core/archetypes/
clear.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/clear.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 crate::try_serialize_field;
17use crate::SerializationResult;
18use crate::{ComponentBatch as _, SerializedComponentBatch};
19use crate::{ComponentDescriptor, ComponentType};
20use crate::{DeserializationError, DeserializationResult};
21
22/// **Archetype**: Empties all the components of an entity.
23///
24/// The presence of a clear means that a latest-at query of components at a given path(s)
25/// will not return any components that were logged at those paths before the clear.
26/// Any logged components after the clear are unaffected by the clear.
27///
28/// This implies that a range query that includes time points that are before the clear,
29/// still returns all components at the given path(s).
30/// Meaning that in practice clears are ineffective when making use of visible time ranges.
31/// Scalar plots are an exception: they track clears and use them to represent holes in the
32/// data (i.e. discontinuous lines).
33///
34/// ## Example
35///
36/// ### Flat
37/// ```ignore
38/// use rerun::external::glam;
39///
40/// fn main() -> Result<(), Box<dyn std::error::Error>> {
41///     let rec = rerun::RecordingStreamBuilder::new("rerun_example_clear").spawn()?;
42///
43///     #[rustfmt::skip]
44///     let (vectors, origins, colors) = (
45///         [glam::Vec3::X,    glam::Vec3::NEG_Y, glam::Vec3::NEG_X, glam::Vec3::Y],
46///         [(-0.5, 0.5, 0.0), (0.5, 0.5, 0.0),   (0.5, -0.5, 0.0),  (-0.5, -0.5, 0.0)],
47///         [(200, 0, 0),      (0, 200, 0),       (0, 0, 200),       (200, 0, 200)],
48///     );
49///
50///     // Log a handful of arrows.
51///     for (i, ((vector, origin), color)) in vectors.into_iter().zip(origins).zip(colors).enumerate() {
52///         rec.log(
53///             format!("arrows/{i}"),
54///             &rerun::Arrows3D::from_vectors([vector])
55///                 .with_origins([origin])
56///                 .with_colors([rerun::Color::from_rgb(color.0, color.1, color.2)]),
57///         )?;
58///     }
59///
60///     // Now clear them, one by one on each tick.
61///     for i in 0..vectors.len() {
62///         rec.log(format!("arrows/{i}"), &rerun::Clear::flat())?;
63///     }
64///
65///     Ok(())
66/// }
67/// ```
68/// <center>
69/// <picture>
70///   <source media="(max-width: 480px)" srcset="https://static.rerun.io/clear_simple/2f5df95fcc53e9f0552f65670aef7f94830c5c1a/480w.png">
71///   <source media="(max-width: 768px)" srcset="https://static.rerun.io/clear_simple/2f5df95fcc53e9f0552f65670aef7f94830c5c1a/768w.png">
72///   <source media="(max-width: 1024px)" srcset="https://static.rerun.io/clear_simple/2f5df95fcc53e9f0552f65670aef7f94830c5c1a/1024w.png">
73///   <source media="(max-width: 1200px)" srcset="https://static.rerun.io/clear_simple/2f5df95fcc53e9f0552f65670aef7f94830c5c1a/1200w.png">
74///   <img src="https://static.rerun.io/clear_simple/2f5df95fcc53e9f0552f65670aef7f94830c5c1a/full.png" width="640">
75/// </picture>
76/// </center>
77#[derive(Clone, Debug, PartialEq, Default)]
78pub struct Clear {
79    pub is_recursive: Option<SerializedComponentBatch>,
80}
81
82impl Clear {
83    /// Returns the [`ComponentDescriptor`] for [`Self::is_recursive`].
84    ///
85    /// The corresponding component is [`crate::components::ClearIsRecursive`].
86    #[inline]
87    pub fn descriptor_is_recursive() -> ComponentDescriptor {
88        ComponentDescriptor {
89            archetype: Some("rerun.archetypes.Clear".into()),
90            component: "Clear:is_recursive".into(),
91            component_type: Some("rerun.components.ClearIsRecursive".into()),
92        }
93    }
94}
95
96static REQUIRED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 1usize]> =
97    once_cell::sync::Lazy::new(|| [Clear::descriptor_is_recursive()]);
98
99static RECOMMENDED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 0usize]> =
100    once_cell::sync::Lazy::new(|| []);
101
102static OPTIONAL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 0usize]> =
103    once_cell::sync::Lazy::new(|| []);
104
105static ALL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 1usize]> =
106    once_cell::sync::Lazy::new(|| [Clear::descriptor_is_recursive()]);
107
108impl Clear {
109    /// The total number of components in the archetype: 1 required, 0 recommended, 0 optional
110    pub const NUM_COMPONENTS: usize = 1usize;
111}
112
113impl crate::Archetype for Clear {
114    #[inline]
115    fn name() -> crate::ArchetypeName {
116        "rerun.archetypes.Clear".into()
117    }
118
119    #[inline]
120    fn display_name() -> &'static str {
121        "Clear"
122    }
123
124    #[inline]
125    fn required_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
126        REQUIRED_COMPONENTS.as_slice().into()
127    }
128
129    #[inline]
130    fn recommended_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
131        RECOMMENDED_COMPONENTS.as_slice().into()
132    }
133
134    #[inline]
135    fn optional_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
136        OPTIONAL_COMPONENTS.as_slice().into()
137    }
138
139    #[inline]
140    fn all_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
141        ALL_COMPONENTS.as_slice().into()
142    }
143
144    #[inline]
145    fn from_arrow_components(
146        arrow_data: impl IntoIterator<Item = (ComponentDescriptor, arrow::array::ArrayRef)>,
147    ) -> DeserializationResult<Self> {
148        re_tracing::profile_function!();
149        use crate::{Loggable as _, ResultExt as _};
150        let arrays_by_descr: ::nohash_hasher::IntMap<_, _> = arrow_data.into_iter().collect();
151        let is_recursive = arrays_by_descr
152            .get(&Self::descriptor_is_recursive())
153            .map(|array| {
154                SerializedComponentBatch::new(array.clone(), Self::descriptor_is_recursive())
155            });
156        Ok(Self { is_recursive })
157    }
158}
159
160impl crate::AsComponents for Clear {
161    #[inline]
162    fn as_serialized_batches(&self) -> Vec<SerializedComponentBatch> {
163        use crate::Archetype as _;
164        std::iter::once(self.is_recursive.clone())
165            .flatten()
166            .collect()
167    }
168}
169
170impl crate::ArchetypeReflectionMarker for Clear {}
171
172impl Clear {
173    /// Create a new `Clear`.
174    #[inline]
175    pub fn new(is_recursive: impl Into<crate::components::ClearIsRecursive>) -> Self {
176        Self {
177            is_recursive: try_serialize_field(Self::descriptor_is_recursive(), [is_recursive]),
178        }
179    }
180
181    /// Update only some specific fields of a `Clear`.
182    #[inline]
183    pub fn update_fields() -> Self {
184        Self::default()
185    }
186
187    /// Clear all the fields of a `Clear`.
188    #[inline]
189    pub fn clear_fields() -> Self {
190        use crate::Loggable as _;
191        Self {
192            is_recursive: Some(SerializedComponentBatch::new(
193                crate::components::ClearIsRecursive::arrow_empty(),
194                Self::descriptor_is_recursive(),
195            )),
196        }
197    }
198
199    /// Partitions the component data into multiple sub-batches.
200    ///
201    /// Specifically, this transforms the existing [`SerializedComponentBatch`]es data into [`SerializedComponentColumn`]s
202    /// instead, via [`SerializedComponentBatch::partitioned`].
203    ///
204    /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
205    ///
206    /// The specified `lengths` must sum to the total length of the component batch.
207    ///
208    /// [`SerializedComponentColumn`]: [crate::SerializedComponentColumn]
209    #[inline]
210    pub fn columns<I>(
211        self,
212        _lengths: I,
213    ) -> SerializationResult<impl Iterator<Item = crate::SerializedComponentColumn>>
214    where
215        I: IntoIterator<Item = usize> + Clone,
216    {
217        let columns = [self
218            .is_recursive
219            .map(|is_recursive| is_recursive.partitioned(_lengths.clone()))
220            .transpose()?];
221        Ok(columns.into_iter().flatten())
222    }
223
224    /// Helper to partition the component data into unit-length sub-batches.
225    ///
226    /// This is semantically similar to calling [`Self::columns`] with `std::iter::take(1).repeat(n)`,
227    /// where `n` is automatically guessed.
228    #[inline]
229    pub fn columns_of_unit_batches(
230        self,
231    ) -> SerializationResult<impl Iterator<Item = crate::SerializedComponentColumn>> {
232        let len_is_recursive = self.is_recursive.as_ref().map(|b| b.array.len());
233        let len = None.or(len_is_recursive).unwrap_or(0);
234        self.columns(std::iter::repeat(1).take(len))
235    }
236
237    #[inline]
238    pub fn with_is_recursive(
239        mut self,
240        is_recursive: impl Into<crate::components::ClearIsRecursive>,
241    ) -> Self {
242        self.is_recursive = try_serialize_field(Self::descriptor_is_recursive(), [is_recursive]);
243        self
244    }
245
246    /// This method makes it possible to pack multiple [`crate::components::ClearIsRecursive`] in a single component batch.
247    ///
248    /// This only makes sense when used in conjunction with [`Self::columns`]. [`Self::with_is_recursive`] should
249    /// be used when logging a single row's worth of data.
250    #[inline]
251    pub fn with_many_is_recursive(
252        mut self,
253        is_recursive: impl IntoIterator<Item = impl Into<crate::components::ClearIsRecursive>>,
254    ) -> Self {
255        self.is_recursive = try_serialize_field(Self::descriptor_is_recursive(), is_recursive);
256        self
257    }
258}
259
260impl ::re_byte_size::SizeBytes for Clear {
261    #[inline]
262    fn heap_size_bytes(&self) -> u64 {
263        self.is_recursive.heap_size_bytes()
264    }
265}