re_types/archetypes/
geo_line_strings.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/geo_line_strings.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**: Geospatial line strings with positions expressed in [EPSG:4326](https://epsg.io/4326) altitude and longitude (North/East-positive degrees), and optional colors and radii.
23///
24/// Also known as "line strips" or "polylines".
25///
26/// ## Example
27///
28/// ### Log a geospatial line string
29/// ```ignore
30/// fn main() -> Result<(), Box<dyn std::error::Error>> {
31///     let rec = rerun::RecordingStreamBuilder::new("rerun_example_geo_line_strings").spawn()?;
32///
33///     rec.log(
34///         "colorado",
35///         &rerun::GeoLineStrings::from_lat_lon([[
36///             [41.0000, -109.0452],
37///             [41.0000, -102.0415],
38///             [36.9931, -102.0415],
39///             [36.9931, -109.0452],
40///             [41.0000, -109.0452],
41///         ]])
42///         .with_radii([rerun::Radius::new_ui_points(2.0)])
43///         .with_colors([rerun::Color::from_rgb(0, 0, 255)]),
44///     )?;
45///
46///     Ok(())
47/// }
48/// ```
49/// <center>
50/// <picture>
51///   <source media="(max-width: 480px)" srcset="https://static.rerun.io/geo_line_strings_simple/5669983eb10906ace303755b5b5039cad75b917f/480w.png">
52///   <source media="(max-width: 768px)" srcset="https://static.rerun.io/geo_line_strings_simple/5669983eb10906ace303755b5b5039cad75b917f/768w.png">
53///   <source media="(max-width: 1024px)" srcset="https://static.rerun.io/geo_line_strings_simple/5669983eb10906ace303755b5b5039cad75b917f/1024w.png">
54///   <source media="(max-width: 1200px)" srcset="https://static.rerun.io/geo_line_strings_simple/5669983eb10906ace303755b5b5039cad75b917f/1200w.png">
55///   <img src="https://static.rerun.io/geo_line_strings_simple/5669983eb10906ace303755b5b5039cad75b917f/full.png" width="640">
56/// </picture>
57/// </center>
58#[derive(Clone, Debug, PartialEq, Default)]
59pub struct GeoLineStrings {
60    /// The line strings, expressed in [EPSG:4326](https://epsg.io/4326) coordinates (North/East-positive degrees).
61    pub line_strings: Option<SerializedComponentBatch>,
62
63    /// Optional radii for the line strings.
64    ///
65    /// *Note*: scene units radiii are interpreted as meters. Currently, the display scale only considers the latitude of
66    /// the first vertex of each line string (see [this issue](https://github.com/rerun-io/rerun/issues/8013)).
67    pub radii: Option<SerializedComponentBatch>,
68
69    /// Optional colors for the line strings.
70    pub colors: Option<SerializedComponentBatch>,
71}
72
73impl GeoLineStrings {
74    /// Returns the [`ComponentDescriptor`] for [`Self::line_strings`].
75    ///
76    /// The corresponding component is [`crate::components::GeoLineString`].
77    #[inline]
78    pub fn descriptor_line_strings() -> ComponentDescriptor {
79        ComponentDescriptor {
80            archetype: Some("rerun.archetypes.GeoLineStrings".into()),
81            component: "GeoLineStrings:line_strings".into(),
82            component_type: Some("rerun.components.GeoLineString".into()),
83        }
84    }
85
86    /// Returns the [`ComponentDescriptor`] for [`Self::radii`].
87    ///
88    /// The corresponding component is [`crate::components::Radius`].
89    #[inline]
90    pub fn descriptor_radii() -> ComponentDescriptor {
91        ComponentDescriptor {
92            archetype: Some("rerun.archetypes.GeoLineStrings".into()),
93            component: "GeoLineStrings:radii".into(),
94            component_type: Some("rerun.components.Radius".into()),
95        }
96    }
97
98    /// Returns the [`ComponentDescriptor`] for [`Self::colors`].
99    ///
100    /// The corresponding component is [`crate::components::Color`].
101    #[inline]
102    pub fn descriptor_colors() -> ComponentDescriptor {
103        ComponentDescriptor {
104            archetype: Some("rerun.archetypes.GeoLineStrings".into()),
105            component: "GeoLineStrings:colors".into(),
106            component_type: Some("rerun.components.Color".into()),
107        }
108    }
109}
110
111static REQUIRED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 1usize]> =
112    once_cell::sync::Lazy::new(|| [GeoLineStrings::descriptor_line_strings()]);
113
114static RECOMMENDED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 2usize]> =
115    once_cell::sync::Lazy::new(|| {
116        [
117            GeoLineStrings::descriptor_radii(),
118            GeoLineStrings::descriptor_colors(),
119        ]
120    });
121
122static OPTIONAL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 0usize]> =
123    once_cell::sync::Lazy::new(|| []);
124
125static ALL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 3usize]> =
126    once_cell::sync::Lazy::new(|| {
127        [
128            GeoLineStrings::descriptor_line_strings(),
129            GeoLineStrings::descriptor_radii(),
130            GeoLineStrings::descriptor_colors(),
131        ]
132    });
133
134impl GeoLineStrings {
135    /// The total number of components in the archetype: 1 required, 2 recommended, 0 optional
136    pub const NUM_COMPONENTS: usize = 3usize;
137}
138
139impl ::re_types_core::Archetype for GeoLineStrings {
140    #[inline]
141    fn name() -> ::re_types_core::ArchetypeName {
142        "rerun.archetypes.GeoLineStrings".into()
143    }
144
145    #[inline]
146    fn display_name() -> &'static str {
147        "Geo line strings"
148    }
149
150    #[inline]
151    fn required_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
152        REQUIRED_COMPONENTS.as_slice().into()
153    }
154
155    #[inline]
156    fn recommended_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
157        RECOMMENDED_COMPONENTS.as_slice().into()
158    }
159
160    #[inline]
161    fn optional_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
162        OPTIONAL_COMPONENTS.as_slice().into()
163    }
164
165    #[inline]
166    fn all_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
167        ALL_COMPONENTS.as_slice().into()
168    }
169
170    #[inline]
171    fn from_arrow_components(
172        arrow_data: impl IntoIterator<Item = (ComponentDescriptor, arrow::array::ArrayRef)>,
173    ) -> DeserializationResult<Self> {
174        re_tracing::profile_function!();
175        use ::re_types_core::{Loggable as _, ResultExt as _};
176        let arrays_by_descr: ::nohash_hasher::IntMap<_, _> = arrow_data.into_iter().collect();
177        let line_strings = arrays_by_descr
178            .get(&Self::descriptor_line_strings())
179            .map(|array| {
180                SerializedComponentBatch::new(array.clone(), Self::descriptor_line_strings())
181            });
182        let radii = arrays_by_descr
183            .get(&Self::descriptor_radii())
184            .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_radii()));
185        let colors = arrays_by_descr
186            .get(&Self::descriptor_colors())
187            .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_colors()));
188        Ok(Self {
189            line_strings,
190            radii,
191            colors,
192        })
193    }
194}
195
196impl ::re_types_core::AsComponents for GeoLineStrings {
197    #[inline]
198    fn as_serialized_batches(&self) -> Vec<SerializedComponentBatch> {
199        use ::re_types_core::Archetype as _;
200        [
201            self.line_strings.clone(),
202            self.radii.clone(),
203            self.colors.clone(),
204        ]
205        .into_iter()
206        .flatten()
207        .collect()
208    }
209}
210
211impl ::re_types_core::ArchetypeReflectionMarker for GeoLineStrings {}
212
213impl GeoLineStrings {
214    /// Create a new `GeoLineStrings`.
215    #[inline]
216    pub(crate) fn new(
217        line_strings: impl IntoIterator<Item = impl Into<crate::components::GeoLineString>>,
218    ) -> Self {
219        Self {
220            line_strings: try_serialize_field(Self::descriptor_line_strings(), line_strings),
221            radii: None,
222            colors: None,
223        }
224    }
225
226    /// Update only some specific fields of a `GeoLineStrings`.
227    #[inline]
228    pub fn update_fields() -> Self {
229        Self::default()
230    }
231
232    /// Clear all the fields of a `GeoLineStrings`.
233    #[inline]
234    pub fn clear_fields() -> Self {
235        use ::re_types_core::Loggable as _;
236        Self {
237            line_strings: Some(SerializedComponentBatch::new(
238                crate::components::GeoLineString::arrow_empty(),
239                Self::descriptor_line_strings(),
240            )),
241            radii: Some(SerializedComponentBatch::new(
242                crate::components::Radius::arrow_empty(),
243                Self::descriptor_radii(),
244            )),
245            colors: Some(SerializedComponentBatch::new(
246                crate::components::Color::arrow_empty(),
247                Self::descriptor_colors(),
248            )),
249        }
250    }
251
252    /// Partitions the component data into multiple sub-batches.
253    ///
254    /// Specifically, this transforms the existing [`SerializedComponentBatch`]es data into [`SerializedComponentColumn`]s
255    /// instead, via [`SerializedComponentBatch::partitioned`].
256    ///
257    /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
258    ///
259    /// The specified `lengths` must sum to the total length of the component batch.
260    ///
261    /// [`SerializedComponentColumn`]: [::re_types_core::SerializedComponentColumn]
262    #[inline]
263    pub fn columns<I>(
264        self,
265        _lengths: I,
266    ) -> SerializationResult<impl Iterator<Item = ::re_types_core::SerializedComponentColumn>>
267    where
268        I: IntoIterator<Item = usize> + Clone,
269    {
270        let columns = [
271            self.line_strings
272                .map(|line_strings| line_strings.partitioned(_lengths.clone()))
273                .transpose()?,
274            self.radii
275                .map(|radii| radii.partitioned(_lengths.clone()))
276                .transpose()?,
277            self.colors
278                .map(|colors| colors.partitioned(_lengths.clone()))
279                .transpose()?,
280        ];
281        Ok(columns.into_iter().flatten())
282    }
283
284    /// Helper to partition the component data into unit-length sub-batches.
285    ///
286    /// This is semantically similar to calling [`Self::columns`] with `std::iter::take(1).repeat(n)`,
287    /// where `n` is automatically guessed.
288    #[inline]
289    pub fn columns_of_unit_batches(
290        self,
291    ) -> SerializationResult<impl Iterator<Item = ::re_types_core::SerializedComponentColumn>> {
292        let len_line_strings = self.line_strings.as_ref().map(|b| b.array.len());
293        let len_radii = self.radii.as_ref().map(|b| b.array.len());
294        let len_colors = self.colors.as_ref().map(|b| b.array.len());
295        let len = None
296            .or(len_line_strings)
297            .or(len_radii)
298            .or(len_colors)
299            .unwrap_or(0);
300        self.columns(std::iter::repeat(1).take(len))
301    }
302
303    /// The line strings, expressed in [EPSG:4326](https://epsg.io/4326) coordinates (North/East-positive degrees).
304    #[inline]
305    pub fn with_line_strings(
306        mut self,
307        line_strings: impl IntoIterator<Item = impl Into<crate::components::GeoLineString>>,
308    ) -> Self {
309        self.line_strings = try_serialize_field(Self::descriptor_line_strings(), line_strings);
310        self
311    }
312
313    /// Optional radii for the line strings.
314    ///
315    /// *Note*: scene units radiii are interpreted as meters. Currently, the display scale only considers the latitude of
316    /// the first vertex of each line string (see [this issue](https://github.com/rerun-io/rerun/issues/8013)).
317    #[inline]
318    pub fn with_radii(
319        mut self,
320        radii: impl IntoIterator<Item = impl Into<crate::components::Radius>>,
321    ) -> Self {
322        self.radii = try_serialize_field(Self::descriptor_radii(), radii);
323        self
324    }
325
326    /// Optional colors for the line strings.
327    #[inline]
328    pub fn with_colors(
329        mut self,
330        colors: impl IntoIterator<Item = impl Into<crate::components::Color>>,
331    ) -> Self {
332        self.colors = try_serialize_field(Self::descriptor_colors(), colors);
333        self
334    }
335}
336
337impl ::re_byte_size::SizeBytes for GeoLineStrings {
338    #[inline]
339    fn heap_size_bytes(&self) -> u64 {
340        self.line_strings.heap_size_bytes()
341            + self.radii.heap_size_bytes()
342            + self.colors.heap_size_bytes()
343    }
344}