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