diff --git a/crates/store/re_types/definitions/rerun/archetypes/line_strips3d.fbs b/crates/store/re_types/definitions/rerun/archetypes/line_strips3d.fbs index 6984cdcd2334..3df0519c0b5d 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/line_strips3d.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/line_strips3d.fbs @@ -9,6 +9,7 @@ namespace rerun.archetypes; /// \example archetypes/line_strips3d_batch title="Many strips" image="https://static.rerun.io/line_strip3d_batch/15e8ff18a6c95a3191acb0eae6eb04adea3b4874/1200w.png" /// \example archetypes/line_strips3d_ui_radius title="Lines with scene & UI radius each" image="https://static.rerun.io/line_strip3d_ui_radius/36b98f47e45747b5a3601511ff39b8d74c61d120/1200w.png" table LineStrips3D ( + "attr.rust.archetype_eager": "", "attr.rust.derive": "PartialEq", "attr.docs.category": "Spatial 3D", "attr.docs.view_types": "Spatial3DView, Spatial2DView: if logged above active projection" diff --git a/crates/store/re_types/src/archetypes/line_strips3d.rs b/crates/store/re_types/src/archetypes/line_strips3d.rs index 761c01bb048d..308ae9c0fe83 100644 --- a/crates/store/re_types/src/archetypes/line_strips3d.rs +++ b/crates/store/re_types/src/archetypes/line_strips3d.rs @@ -98,30 +98,30 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; /// /// /// -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Default)] pub struct LineStrips3D { /// All the actual 3D line strips that make up the batch. - pub strips: Vec, + pub strips: Option, /// Optional radii for the line strips. - pub radii: Option>, + pub radii: Option, /// Optional colors for the line strips. - pub colors: Option>, + pub colors: Option, /// Optional text labels for the line strips. /// /// If there's a single label present, it will be placed at the center of the entity. /// Otherwise, each instance will have its own label. - pub labels: Option>, + pub labels: Option, /// Optional choice of whether the text labels should be shown by default. - pub show_labels: Option, + pub show_labels: Option, /// Optional [`components::ClassId`][crate::components::ClassId]s for the lines. /// /// The [`components::ClassId`][crate::components::ClassId] provides colors and labels if not specified explicitly. - pub class_ids: Option>, + pub class_ids: Option, } impl LineStrips3D { @@ -284,76 +284,28 @@ impl ::re_types_core::Archetype for LineStrips3D { re_tracing::profile_function!(); use ::re_types_core::{Loggable as _, ResultExt as _}; let arrays_by_descr: ::nohash_hasher::IntMap<_, _> = arrow_data.into_iter().collect(); - let strips = { - let array = arrays_by_descr - .get(&Self::descriptor_strips()) - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.LineStrips3D#strips")?; - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.LineStrips3D#strips")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.LineStrips3D#strips")? - }; - let radii = if let Some(array) = arrays_by_descr.get(&Self::descriptor_radii()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.LineStrips3D#radii")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.LineStrips3D#radii")? - }) - } else { - None - }; - let colors = if let Some(array) = arrays_by_descr.get(&Self::descriptor_colors()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.LineStrips3D#colors")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.LineStrips3D#colors")? - }) - } else { - None - }; - let labels = if let Some(array) = arrays_by_descr.get(&Self::descriptor_labels()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.LineStrips3D#labels")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.LineStrips3D#labels")? - }) - } else { - None - }; - let show_labels = if let Some(array) = arrays_by_descr.get(&Self::descriptor_show_labels()) - { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.LineStrips3D#show_labels")? - .into_iter() - .next() - .flatten() - } else { - None - }; - let class_ids = if let Some(array) = arrays_by_descr.get(&Self::descriptor_class_ids()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.LineStrips3D#class_ids")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.LineStrips3D#class_ids")? - }) - } else { - None - }; + let strips = arrays_by_descr + .get(&Self::descriptor_strips()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_strips())); + let radii = arrays_by_descr + .get(&Self::descriptor_radii()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_radii())); + let colors = arrays_by_descr + .get(&Self::descriptor_colors()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_colors())); + let labels = arrays_by_descr + .get(&Self::descriptor_labels()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_labels())); + let show_labels = arrays_by_descr + .get(&Self::descriptor_show_labels()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_show_labels()) + }); + let class_ids = arrays_by_descr + .get(&Self::descriptor_class_ids()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_class_ids()) + }); Ok(Self { strips, radii, @@ -366,57 +318,17 @@ impl ::re_types_core::Archetype for LineStrips3D { } impl ::re_types_core::AsComponents for LineStrips3D { - fn as_component_batches(&self) -> Vec> { - re_tracing::profile_function!(); + #[inline] + fn as_serialized_batches(&self) -> Vec { use ::re_types_core::Archetype as _; [ - Some(Self::indicator()), - (Some(&self.strips as &dyn ComponentBatch)).map(|batch| { - ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_strips()), - } - }), - (self - .radii - .as_ref() - .map(|comp_batch| (comp_batch as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_radii()), - }), - (self - .colors - .as_ref() - .map(|comp_batch| (comp_batch as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_colors()), - }), - (self - .labels - .as_ref() - .map(|comp_batch| (comp_batch as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_labels()), - }), - (self - .show_labels - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_show_labels()), - }), - (self - .class_ids - .as_ref() - .map(|comp_batch| (comp_batch as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_class_ids()), - }), + Self::indicator().serialized(), + self.strips.clone(), + self.radii.clone(), + self.colors.clone(), + self.labels.clone(), + self.show_labels.clone(), + self.class_ids.clone(), ] .into_iter() .flatten() @@ -433,7 +345,7 @@ impl LineStrips3D { strips: impl IntoIterator>, ) -> Self { Self { - strips: strips.into_iter().map(Into::into).collect(), + strips: try_serialize_field(Self::descriptor_strips(), strips), radii: None, colors: None, labels: None, @@ -442,13 +354,61 @@ impl LineStrips3D { } } + /// Update only some specific fields of a `LineStrips3D`. + #[inline] + pub fn update_fields() -> Self { + Self::default() + } + + /// Clear all the fields of a `LineStrips3D`. + #[inline] + pub fn clear_fields() -> Self { + use ::re_types_core::Loggable as _; + Self { + strips: Some(SerializedComponentBatch::new( + crate::components::LineStrip3D::arrow_empty(), + Self::descriptor_strips(), + )), + radii: Some(SerializedComponentBatch::new( + crate::components::Radius::arrow_empty(), + Self::descriptor_radii(), + )), + colors: Some(SerializedComponentBatch::new( + crate::components::Color::arrow_empty(), + Self::descriptor_colors(), + )), + labels: Some(SerializedComponentBatch::new( + crate::components::Text::arrow_empty(), + Self::descriptor_labels(), + )), + show_labels: Some(SerializedComponentBatch::new( + crate::components::ShowLabels::arrow_empty(), + Self::descriptor_show_labels(), + )), + class_ids: Some(SerializedComponentBatch::new( + crate::components::ClassId::arrow_empty(), + Self::descriptor_class_ids(), + )), + } + } + + /// All the actual 3D line strips that make up the batch. + #[inline] + pub fn with_strips( + mut self, + strips: impl IntoIterator>, + ) -> Self { + self.strips = try_serialize_field(Self::descriptor_strips(), strips); + self + } + /// Optional radii for the line strips. #[inline] pub fn with_radii( mut self, radii: impl IntoIterator>, ) -> Self { - self.radii = Some(radii.into_iter().map(Into::into).collect()); + self.radii = try_serialize_field(Self::descriptor_radii(), radii); self } @@ -458,7 +418,7 @@ impl LineStrips3D { mut self, colors: impl IntoIterator>, ) -> Self { - self.colors = Some(colors.into_iter().map(Into::into).collect()); + self.colors = try_serialize_field(Self::descriptor_colors(), colors); self } @@ -471,7 +431,7 @@ impl LineStrips3D { mut self, labels: impl IntoIterator>, ) -> Self { - self.labels = Some(labels.into_iter().map(Into::into).collect()); + self.labels = try_serialize_field(Self::descriptor_labels(), labels); self } @@ -481,7 +441,7 @@ impl LineStrips3D { mut self, show_labels: impl Into, ) -> Self { - self.show_labels = Some(show_labels.into()); + self.show_labels = try_serialize_field(Self::descriptor_show_labels(), [show_labels]); self } @@ -493,7 +453,7 @@ impl LineStrips3D { mut self, class_ids: impl IntoIterator>, ) -> Self { - self.class_ids = Some(class_ids.into_iter().map(Into::into).collect()); + self.class_ids = try_serialize_field(Self::descriptor_class_ids(), class_ids); self } } @@ -508,14 +468,4 @@ impl ::re_byte_size::SizeBytes for LineStrips3D { + self.show_labels.heap_size_bytes() + self.class_ids.heap_size_bytes() } - - #[inline] - fn is_pod() -> bool { - >::is_pod() - && >>::is_pod() - && >>::is_pod() - && >>::is_pod() - && >::is_pod() - && >>::is_pod() - } } diff --git a/crates/store/re_types/tests/types/line_strips3d.rs b/crates/store/re_types/tests/types/line_strips3d.rs index 444866508186..ae78d07dd2e7 100644 --- a/crates/store/re_types/tests/types/line_strips3d.rs +++ b/crates/store/re_types/tests/types/line_strips3d.rs @@ -1,7 +1,5 @@ use re_types::{ - archetypes::LineStrips3D, - components::{ClassId, Color, LineStrip3D, Radius}, - Archetype as _, AsComponents as _, + archetypes::LineStrips3D, components, Archetype as _, AsComponents as _, ComponentBatch, }; #[test] @@ -9,26 +7,35 @@ fn roundtrip() { let expected = LineStrips3D { #[rustfmt::skip] strips: vec![ - LineStrip3D::from_iter([[0., 0., 1.], [2., 1., 2.], [4., -1., 3.], [6., 0., 4.]]), - LineStrip3D::from_iter([[0., 3., 1.], [1., 4., 2.], [2., 2., 3.], [3., 4., 4.], [4., 2., 5.], [5., 4., 6.], [6., 3., 7.]]), - ], - radii: Some(vec![ - Radius::from(42.0), // - Radius::from(43.0), - ]), - colors: Some(vec![ - Color::from_unmultiplied_rgba(0xAA, 0x00, 0x00, 0xCC), // - Color::from_unmultiplied_rgba(0x00, 0xBB, 0x00, 0xDD), - ]), - labels: Some(vec![ - "hello".into(), // - "friend".into(), // - ]), - class_ids: Some(vec![ - ClassId::from(126), // - ClassId::from(127), // - ]), - show_labels: Some(true.into()), + components::LineStrip3D::from_iter([[0., 0., 1.], [2., 1., 2.], [4., -1., 3.], [6., 0., 4.]]), + components::LineStrip3D::from_iter([[0., 3., 1.], [1., 4., 2.], [2., 2., 3.], [3., 4., 4.], [4., 2., 5.], [5., 4., 6.], [6., 3., 7.]]), + ] + .serialized() + .map(|batch| batch.with_descriptor_override(LineStrips3D::descriptor_strips())), + radii: vec![ + components::Radius::from(42.0), // + components::Radius::from(43.0), + ] + .serialized() + .map(|batch| batch.with_descriptor_override(LineStrips3D::descriptor_radii())), + colors: vec![ + components::Color::from_unmultiplied_rgba(0xAA, 0x00, 0x00, 0xCC), // + components::Color::from_unmultiplied_rgba(0x00, 0xBB, 0x00, 0xDD), + ] + .serialized() + .map(|batch| batch.with_descriptor_override(LineStrips3D::descriptor_colors())), + labels: (vec!["hello".into(), "friend".into()] as Vec) + .serialized() + .map(|batch| batch.with_descriptor_override(LineStrips3D::descriptor_labels())), + class_ids: vec![ + components::ClassId::from(126), // + components::ClassId::from(127), // + ] + .serialized() + .map(|batch| batch.with_descriptor_override(LineStrips3D::descriptor_class_ids())), + show_labels: components::ShowLabels(true.into()) + .serialized() + .map(|batch| batch.with_descriptor_override(LineStrips3D::descriptor_show_labels())), }; #[rustfmt::skip] diff --git a/docs/snippets/all/archetypes/line_strips3d_simple.rs b/docs/snippets/all/archetypes/line_strips3d_simple.rs index 9c9e839f5cc6..3f691b0f2be6 100644 --- a/docs/snippets/all/archetypes/line_strips3d_simple.rs +++ b/docs/snippets/all/archetypes/line_strips3d_simple.rs @@ -15,5 +15,10 @@ fn main() -> Result<(), Box> { ]; rec.log("strip", &rerun::LineStrips3D::new([points]))?; + rec.log( + "strip", + &rerun::LineStrips3D::update_fields().with_radii([2.0]), + )?; + Ok(()) }