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