From 18ce378eac0502a394e5351b1b2597c1c565f8b6 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Fri, 17 Jan 2025 18:38:17 +0100 Subject: [PATCH] Port over most Rust types to use eager serialization (#8703) --- .../re_data_loader/src/loader_archetype.rs | 4 +- crates/store/re_entity_db/tests/clear.rs | 21 +- .../re_log_types/src/example_components.rs | 53 ++- crates/store/re_log_types/src/lib.rs | 45 ++ .../rerun/archetypes/annotation_context.fbs | 1 + .../definitions/rerun/archetypes/arrows2d.fbs | 1 + .../definitions/rerun/archetypes/arrows3d.fbs | 1 + .../definitions/rerun/archetypes/asset3d.fbs | 1 + .../rerun/archetypes/asset_video.fbs | 1 + .../rerun/archetypes/bar_chart.fbs | 1 + .../definitions/rerun/archetypes/boxes2d.fbs | 1 + .../definitions/rerun/archetypes/boxes3d.fbs | 1 + .../rerun/archetypes/capsules3d.fbs | 1 + .../definitions/rerun/archetypes/clear.fbs | 3 +- .../rerun/archetypes/depth_image.fbs | 1 + .../rerun/archetypes/ellipsoids3d.fbs | 1 + .../rerun/archetypes/encoded_image.fbs | 1 + .../rerun/archetypes/geo_line_strings.fbs | 1 + .../rerun/archetypes/geo_points.fbs | 1 + .../rerun/archetypes/graph_edges.fbs | 3 +- .../rerun/archetypes/graph_nodes.fbs | 1 + .../definitions/rerun/archetypes/image.fbs | 1 + .../rerun/archetypes/instance_poses3d.fbs | 1 + .../definitions/rerun/archetypes/mesh3d.fbs | 1 + .../definitions/rerun/archetypes/pinhole.fbs | 1 + .../definitions/rerun/archetypes/points2d.fbs | 1 + .../definitions/rerun/archetypes/scalar.fbs | 1 + .../rerun/archetypes/segmentation_image.fbs | 1 + .../rerun/archetypes/series_line.fbs | 1 + .../rerun/archetypes/series_point.fbs | 1 + .../definitions/rerun/archetypes/tensor.fbs | 1 + .../rerun/archetypes/text_document.fbs | 3 +- .../definitions/rerun/archetypes/text_log.fbs | 3 +- .../archetypes/video_frame_reference.fbs | 1 + .../rerun/archetypes/view_coordinates.fbs | 1 + .../store/re_types/src/archetypes/arrows2d.rs | 299 ++++++-------- .../store/re_types/src/archetypes/arrows3d.rs | 267 +++++------- .../re_types/src/archetypes/bar_chart.rs | 94 ++--- .../re_types/src/archetypes/capsules3d.rs | 357 +++++++--------- .../re_types/src/archetypes/capsules3d_ext.rs | 1 + .../re_types/src/archetypes/depth_image.rs | 263 +++++------- .../src/archetypes/depth_image_ext.rs | 20 +- .../re_types/src/archetypes/ellipsoids3d.rs | 384 +++++++----------- .../re_types/src/archetypes/encoded_image.rs | 159 ++++---- .../src/archetypes/encoded_image_ext.rs | 18 +- .../src/archetypes/geo_line_strings.rs | 135 +++--- .../re_types/src/archetypes/geo_points.rs | 170 ++++---- .../re_types/src/archetypes/graph_edges.rs | 99 ++--- .../src/archetypes/graph_edges_ext.rs | 10 +- .../re_types/src/archetypes/graph_nodes.rs | 234 +++++------ .../src/archetypes/instance_poses3d.rs | 207 ++++------ .../store/re_types/src/archetypes/points2d.rs | 304 ++++++-------- .../store/re_types/src/archetypes/scalar.rs | 72 ++-- .../src/archetypes/segmentation_image.rs | 166 ++++---- .../src/archetypes/segmentation_image_ext.rs | 7 +- .../re_types/src/archetypes/series_line.rs | 148 +++---- .../re_types/src/archetypes/series_point.rs | 147 +++---- .../re_types/src/archetypes/text_document.rs | 96 +++-- .../src/archetypes/text_document_ext.rs | 12 +- .../store/re_types/src/archetypes/text_log.rs | 125 +++--- .../src/archetypes/video_frame_reference.rs | 111 ++--- crates/store/re_types/tests/types/arrows3d.rs | 46 ++- crates/store/re_types/tests/types/clear.rs | 12 +- .../store/re_types/tests/types/depth_image.rs | 22 +- crates/store/re_types/tests/types/points2d.rs | 52 ++- .../tests/types/segmentation_image.rs | 17 +- .../re_types/tests/types/text_document.rs | 11 +- .../re_types_core/src/archetypes/clear.rs | 76 ++-- crates/store/re_types_core/src/lib.rs | 3 +- crates/viewer/re_data_ui/src/instance_path.rs | 6 +- crates/viewer/re_view_spatial/src/lib.rs | 3 +- 71 files changed, 1928 insertions(+), 2387 deletions(-) diff --git a/crates/store/re_data_loader/src/loader_archetype.rs b/crates/store/re_data_loader/src/loader_archetype.rs index 3e830c8ab776..bb302d5865d6 100644 --- a/crates/store/re_data_loader/src/loader_archetype.rs +++ b/crates/store/re_data_loader/src/loader_archetype.rs @@ -3,7 +3,7 @@ use re_log_types::{EntityPath, TimeInt, TimePoint}; use re_types::archetypes::{AssetVideo, VideoFrameReference}; use re_types::components::VideoTimestamp; use re_types::Archetype; -use re_types::{components::MediaType, ComponentBatch}; +use re_types::ComponentBatch; use arrow2::Either; @@ -162,7 +162,7 @@ fn load_image( let mut arch = re_types::archetypes::EncodedImage::from_file_contents(contents); if let Ok(format) = image::ImageFormat::from_path(filepath) { - arch.media_type = Some(MediaType::from(format.to_mime_type())); + arch = arch.with_media_type(format.to_mime_type()); } Chunk::builder(entity_path) diff --git a/crates/store/re_entity_db/tests/clear.rs b/crates/store/re_entity_db/tests/clear.rs index dbbb4a78927b..6b03995c0a3b 100644 --- a/crates/store/re_entity_db/tests/clear.rs +++ b/crates/store/re_entity_db/tests/clear.rs @@ -10,6 +10,7 @@ use re_log_types::{ example_components::{MyColor, MyIndex, MyPoint}, EntityPath, StoreId, TimeInt, TimePoint, Timeline, }; +use re_types::ComponentBatch; use re_types_core::{archetypes::Clear, components::ClearIsRecursive, AsComponents}; // --- @@ -137,7 +138,10 @@ fn clears() -> anyhow::Result<()> { let (_, _, got_clear) = query_latest_component::(&db, &entity_path_parent, &query) .unwrap(); - similar_asserts::assert_eq!(clear.is_recursive, got_clear); + similar_asserts::assert_eq!( + clear.is_recursive.map(|batch| batch.array), + got_clear.serialized().map(|batch| batch.array) + ); // child1 assert!(query_latest_component::(&db, &entity_path_child1, &query).is_some()); @@ -171,7 +175,10 @@ fn clears() -> anyhow::Result<()> { let (_, _, got_clear) = query_latest_component::(&db, &entity_path_parent, &query) .unwrap(); - similar_asserts::assert_eq!(clear.is_recursive, got_clear); + similar_asserts::assert_eq!( + clear.is_recursive.map(|batch| batch.array), + got_clear.serialized().map(|batch| batch.array) + ); // child1 assert!(query_latest_component::(&db, &entity_path_child1, &query).is_none()); @@ -356,7 +363,10 @@ fn clears_respect_index_order() -> anyhow::Result<()> { // the `Clear` component itself doesn't get cleared! let (_, _, got_clear) = query_latest_component::(&db, &entity_path, &query).unwrap(); - similar_asserts::assert_eq!(clear.is_recursive, got_clear); + similar_asserts::assert_eq!( + clear.is_recursive.map(|batch| batch.array), + got_clear.serialized().map(|batch| batch.array) + ); } let clear = Clear::recursive(); @@ -378,7 +388,10 @@ fn clears_respect_index_order() -> anyhow::Result<()> { // the `Clear` component itself doesn't get cleared! let (_, _, got_clear) = query_latest_component::(&db, &entity_path, &query).unwrap(); - similar_asserts::assert_eq!(clear.is_recursive, got_clear); + similar_asserts::assert_eq!( + clear.is_recursive.map(|batch| batch.array), + got_clear.serialized().map(|batch| batch.array) + ); } Ok(()) diff --git a/crates/store/re_log_types/src/example_components.rs b/crates/store/re_log_types/src/example_components.rs index 06e1da14a4c8..a0566ae99b49 100644 --- a/crates/store/re_log_types/src/example_components.rs +++ b/crates/store/re_log_types/src/example_components.rs @@ -4,17 +4,66 @@ use std::sync::Arc; use re_arrow_util::ArrowArrayDowncastRef as _; use re_byte_size::SizeBytes; -use re_types_core::{Component, ComponentDescriptor, DeserializationError, Loggable}; +use re_types_core::{ + Component, ComponentDescriptor, DeserializationError, Loggable, SerializedComponentBatch, +}; // ---------------------------------------------------------------------------- #[derive(Debug)] -pub struct MyPoints; +pub struct MyPoints { + pub points: Option, + pub colors: Option, + pub labels: Option, +} impl MyPoints { pub const NUM_COMPONENTS: usize = 5; } +impl MyPoints { + pub fn descriptor_points() -> ComponentDescriptor { + ComponentDescriptor { + archetype_name: Some("example.MyPoints".into()), + archetype_field_name: Some("points".into()), + component_name: MyPoint::name(), + } + } + + pub fn descriptor_colors() -> ComponentDescriptor { + ComponentDescriptor { + archetype_name: Some("example.MyPoints".into()), + archetype_field_name: Some("colors".into()), + component_name: MyColor::name(), + } + } + + pub fn descriptor_labels() -> ComponentDescriptor { + ComponentDescriptor { + archetype_name: Some("example.MyPoints".into()), + archetype_field_name: Some("labels".into()), + component_name: MyLabel::name(), + } + } + + pub fn clear_fields() -> Self { + Self { + points: Some(SerializedComponentBatch::new( + MyPoint::arrow_empty(), + Self::descriptor_points(), + )), + colors: Some(SerializedComponentBatch::new( + MyColor::arrow_empty(), + Self::descriptor_colors(), + )), + labels: Some(SerializedComponentBatch::new( + MyLabel::arrow_empty(), + Self::descriptor_labels(), + )), + } + } +} + impl re_types_core::Archetype for MyPoints { type Indicator = re_types_core::GenericIndicatorComponent; diff --git a/crates/store/re_log_types/src/lib.rs b/crates/store/re_log_types/src/lib.rs index cb4509f9594b..8d8e98199194 100644 --- a/crates/store/re_log_types/src/lib.rs +++ b/crates/store/re_log_types/src/lib.rs @@ -808,6 +808,51 @@ pub fn strip_arrow_extension_types_from_batch(batch: &mut ArrowRecordBatch) { } } +// ---------------------------------------------------------------------------- + +/// Runtime asserts that an archetype has the given components. +/// +/// In particular, this is useful to statically check that an archetype +/// has a specific component. +/// +/// ``` +/// # #[macro_use] extern crate re_log_types; +/// # use re_log_types::example_components::*; +/// debug_assert_archetype_has_components!(MyPoints, colors: MyColor); +/// ``` +/// +/// This will panic because the type is wrong: +/// +/// ```should_panic +/// # #[macro_use] extern crate re_log_types; +/// # use re_log_types::example_components::*; +/// debug_assert_archetype_has_components!(MyPoints, colors: MyPoint); +/// ``` +/// +/// This will fail to compile because the field is missing: +/// +/// ```compile_fail +/// # #[macro_use] extern crate re_log_types; +/// # use re_log_types::example_components::*; +/// debug_assert_archetype_has_components!(MyPoints, colours: MyColor); +/// ``` +/// +#[macro_export] +macro_rules! debug_assert_archetype_has_components { + ($arch:ty, $($field:ident: $field_typ:ty),+ $(,)?) => { + #[cfg(debug_assertions)] + { + use re_log_types::external::re_types_core::{Component as _}; + let archetype = <$arch>::clear_fields(); + $( + assert_eq!(archetype.$field.map(|batch| batch.descriptor.component_name), Some(<$field_typ>::name())); + )+ + } + }; +} + +// ---------------------------------------------------------------------------- + #[cfg(test)] mod tests { use super::*; diff --git a/crates/store/re_types/definitions/rerun/archetypes/annotation_context.fbs b/crates/store/re_types/definitions/rerun/archetypes/annotation_context.fbs index 069859ac3617..bd7442723f31 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/annotation_context.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/annotation_context.fbs @@ -15,6 +15,7 @@ namespace rerun.archetypes; /// \example archetypes/annotation_context_segmentation title="Segmentation" image="https://static.rerun.io/annotation_context_segmentation/6c9e88fc9d44a08031cadd444c2e58a985cc1208/1200w.png"" /// \example archetypes/annotation_context_connections !api title="Connections" image="https://static.rerun.io/annotation_context_connections/4a8422bc154699c5334f574ff01b55c5cd1748e3/1200w.png" table AnnotationContext ( + // TODO(#7245): "attr.rust.archetype_eager", "attr.rust.derive": "Eq, PartialEq", "attr.docs.view_types": "Spatial2DView, Spatial3DView" ) { diff --git a/crates/store/re_types/definitions/rerun/archetypes/arrows2d.fbs b/crates/store/re_types/definitions/rerun/archetypes/arrows2d.fbs index 20f87c0e6a8b..56854ae5b6a4 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/arrows2d.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/arrows2d.fbs @@ -7,6 +7,7 @@ namespace rerun.archetypes; /// /// \example archetypes/arrows2d_simple title="Simple batch of 2D arrows" image="https://static.rerun.io/arrow2d_simple/59f044ccc03f7bc66ee802288f75706618b29a6e/1200w.png" table Arrows2D ( + "attr.rust.archetype_eager", "attr.rust.derive": "PartialEq", "attr.rust.new_pub_crate", "attr.cpp.no_field_ctors", diff --git a/crates/store/re_types/definitions/rerun/archetypes/arrows3d.fbs b/crates/store/re_types/definitions/rerun/archetypes/arrows3d.fbs index 24b3ea1e336e..b07c94130e93 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/arrows3d.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/arrows3d.fbs @@ -6,6 +6,7 @@ namespace rerun.archetypes; /// /// \example archetypes/arrows3d_simple title="Simple batch of 3D arrows" image="https://static.rerun.io/arrow3d_simple/55e2f794a520bbf7527d7b828b0264732146c5d0/1200w.png" table Arrows3D ( + "attr.rust.archetype_eager", "attr.rust.derive": "PartialEq", "attr.rust.new_pub_crate", "attr.cpp.no_field_ctors", diff --git a/crates/store/re_types/definitions/rerun/archetypes/asset3d.fbs b/crates/store/re_types/definitions/rerun/archetypes/asset3d.fbs index b0625fbf2ff6..d230ad0fb42a 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/asset3d.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/asset3d.fbs @@ -11,6 +11,7 @@ namespace rerun.archetypes; /// /// \example archetypes/asset3d_simple title="Simple 3D asset" image="https://static.rerun.io/asset3d_simple/af238578188d3fd0de3e330212120e2842a8ddb2/1200w.png" table Asset3D ( + // TODO(#7245): "attr.rust.archetype_eager", "attr.rust.derive": "PartialEq, Eq", "attr.docs.category": "Spatial 3D", "attr.docs.view_types": "Spatial3DView, Spatial2DView: if logged above active projection" diff --git a/crates/store/re_types/definitions/rerun/archetypes/asset_video.fbs b/crates/store/re_types/definitions/rerun/archetypes/asset_video.fbs index bf4fcbb7fcb3..2d5209ac1c45 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/asset_video.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/asset_video.fbs @@ -12,6 +12,7 @@ namespace rerun.archetypes; /// \example archetypes/video_auto_frames title="Video with automatically determined frames" image="https://static.rerun.io/video_manual_frames/320a44e1e06b8b3a3161ecbbeae3e04d1ccb9589/1200w.png" /// \example archetypes/video_manual_frames title="Demonstrates manual use of video frame references" image="https://static.rerun.io/video_manual_frames/9f41c00f84a98cc3f26875fba7c1d2fa2bad7151/1200w.png" table AssetVideo ( + // TODO(#7245): "attr.rust.archetype_eager", "attr.docs.category": "Video", "attr.docs.view_types": "Spatial2DView, Spatial3DView: if logged under a projection" ) { diff --git a/crates/store/re_types/definitions/rerun/archetypes/bar_chart.fbs b/crates/store/re_types/definitions/rerun/archetypes/bar_chart.fbs index 77037d719cea..60dcc0775d9b 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/bar_chart.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/bar_chart.fbs @@ -8,6 +8,7 @@ namespace rerun.archetypes; /// /// \example archetypes/bar_chart title="Simple bar chart" image="https://static.rerun.io/barchart_simple/cf6014b18265edfcaa562c06526c0716b296b193/1200w.png" table BarChart ( + "attr.rust.archetype_eager", "attr.rust.derive": "PartialEq", "attr.docs.category": "Plotting", "attr.docs.view_types": "BarChartView" diff --git a/crates/store/re_types/definitions/rerun/archetypes/boxes2d.fbs b/crates/store/re_types/definitions/rerun/archetypes/boxes2d.fbs index fc8c1b96eb24..8c2ca8bd82e6 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/boxes2d.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/boxes2d.fbs @@ -6,6 +6,7 @@ namespace rerun.archetypes; /// /// \example archetypes/boxes2d_simple title="Simple 2D boxes" image="https://static.rerun.io/box2d_simple/ac4424f3cf747382867649610cbd749c45b2020b/1200w.png" table Boxes2D ( + // TODO(#7245): "attr.rust.archetype_eager", "attr.rust.derive": "PartialEq", "attr.rust.new_pub_crate", "attr.cpp.no_field_ctors", diff --git a/crates/store/re_types/definitions/rerun/archetypes/boxes3d.fbs b/crates/store/re_types/definitions/rerun/archetypes/boxes3d.fbs index bb2552778c40..a690eb659903 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/boxes3d.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/boxes3d.fbs @@ -11,6 +11,7 @@ namespace rerun.archetypes; /// \example archetypes/boxes3d_simple !api title="Simple 3D boxes" image="https://static.rerun.io/box3d_simple/d6a3f38d2e3360fbacac52bb43e44762635be9c8/1200w.png" /// \example archetypes/boxes3d_batch title="Batch of 3D boxes" image="https://static.rerun.io/box3d_batch/5aac5b5d29c9f2ecd572c93f6970fcec17f4984b/1200w.png" table Boxes3D ( + // TODO(#7245): "attr.rust.archetype_eager", "attr.rust.derive": "PartialEq", "attr.rust.new_pub_crate", "attr.cpp.no_field_ctors", diff --git a/crates/store/re_types/definitions/rerun/archetypes/capsules3d.fbs b/crates/store/re_types/definitions/rerun/archetypes/capsules3d.fbs index 2b7f4434b272..5c5ffc5f8f60 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/capsules3d.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/capsules3d.fbs @@ -14,6 +14,7 @@ namespace rerun.archetypes; // TODO(#1361): This archetype should eventually generalize to cylinders without caps, truncated // cones, and tapered capsules -- all common shapes based on expanding a line segment circularly. table Capsules3D ( + "attr.rust.archetype_eager", "attr.rust.derive": "PartialEq", "attr.rust.new_pub_crate", "attr.cpp.no_field_ctors", diff --git a/crates/store/re_types/definitions/rerun/archetypes/clear.fbs b/crates/store/re_types/definitions/rerun/archetypes/clear.fbs index ad8ec3f81759..91a21227110e 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/clear.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/clear.fbs @@ -17,7 +17,8 @@ namespace rerun.archetypes; /// \example archetypes/clear_simple title="Flat" image="https://static.rerun.io/clear_simple/2f5df95fcc53e9f0552f65670aef7f94830c5c1a/1200w.png" /// \example archetypes/clear_recursive !api "Recursive" table Clear ( - "attr.rust.derive": "PartialEq, Eq", + "attr.rust.archetype_eager", + "attr.rust.derive": "PartialEq", "attr.rust.override_crate": "re_types_core", "attr.docs.view_types": "Spatial2DView, Spatial3DView, TimeSeriesView" ) { diff --git a/crates/store/re_types/definitions/rerun/archetypes/depth_image.fbs b/crates/store/re_types/definitions/rerun/archetypes/depth_image.fbs index 24d63fa7c9e3..754d6883615b 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/depth_image.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/depth_image.fbs @@ -12,6 +12,7 @@ namespace rerun.archetypes; /// \example archetypes/depth_image_simple !api title="Simple example" image="https://static.rerun.io/depth_image_simple/77a6fa4f938a742bdc7c5350f668c4f31eed4d01/1200w.png" /// \example archetypes/depth_image_3d title="Depth to 3D example" image="https://static.rerun.io/depth_image_3d/924e9d4d6a39d63d4fdece82582855fdaa62d15e/1200w.png" table DepthImage ( + "attr.rust.archetype_eager", "attr.rust.derive": "PartialEq", "attr.cpp.no_field_ctors", "attr.docs.category": "Image & tensor", diff --git a/crates/store/re_types/definitions/rerun/archetypes/ellipsoids3d.fbs b/crates/store/re_types/definitions/rerun/archetypes/ellipsoids3d.fbs index 469ff7009186..49a775ca6e24 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/ellipsoids3d.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/ellipsoids3d.fbs @@ -14,6 +14,7 @@ namespace rerun.archetypes; /// /// \example archetypes/ellipsoids3d_simple title="Covariance ellipsoid" image="https://static.rerun.io/elliopsoid3d_simple/bd5d46e61b80ae44792b52ee07d750a7137002ea/1200w.png" table Ellipsoids3D ( + "attr.rust.archetype_eager", "attr.rust.derive": "PartialEq", "attr.rust.new_pub_crate", "attr.cpp.no_field_ctors", diff --git a/crates/store/re_types/definitions/rerun/archetypes/encoded_image.fbs b/crates/store/re_types/definitions/rerun/archetypes/encoded_image.fbs index 654b846e77ff..9b3ce810d01b 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/encoded_image.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/encoded_image.fbs @@ -10,6 +10,7 @@ namespace rerun.archetypes; /// /// \example archetypes/encoded_image table EncodedImage ( + "attr.rust.archetype_eager", "attr.cpp.no_field_ctors", "attr.docs.category": "Image & tensor", "attr.docs.view_types": "Spatial2DView, Spatial3DView: if logged under a projection", diff --git a/crates/store/re_types/definitions/rerun/archetypes/geo_line_strings.fbs b/crates/store/re_types/definitions/rerun/archetypes/geo_line_strings.fbs index 37eb4e831e8e..9c34f0d269cf 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/geo_line_strings.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/geo_line_strings.fbs @@ -8,6 +8,7 @@ namespace rerun.archetypes; /// /// \example archetypes/geo_line_strings_simple title="Log a geospatial line string" image="https://static.rerun.io/geo_line_strings_simple/5669983eb10906ace303755b5b5039cad75b917f/1200w.png" table GeoLineStrings ( + "attr.rust.archetype_eager", "attr.rust.derive": "PartialEq", "attr.rust.new_pub_crate", "attr.docs.category": "Geospatial", diff --git a/crates/store/re_types/definitions/rerun/archetypes/geo_points.fbs b/crates/store/re_types/definitions/rerun/archetypes/geo_points.fbs index 2c23035f084b..2824f5cae568 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/geo_points.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/geo_points.fbs @@ -4,6 +4,7 @@ namespace rerun.archetypes; /// /// \example archetypes/geo_points_simple title="Log a geospatial point" image="https://static.rerun.io/geopoint_simple/b86ce83e5871837587bd33a0ad639358b96e9010/1200w.png" table GeoPoints ( + "attr.rust.archetype_eager", "attr.rust.derive": "PartialEq", "attr.rust.new_pub_crate", "attr.docs.category": "Geospatial", diff --git a/crates/store/re_types/definitions/rerun/archetypes/graph_edges.fbs b/crates/store/re_types/definitions/rerun/archetypes/graph_edges.fbs index c85a4e58e4bb..bc946fed67d6 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/graph_edges.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/graph_edges.fbs @@ -9,9 +9,10 @@ namespace rerun.archetypes; /// \example archetypes/graph_undirected !api title="Simple undirected graph" image="https://static.rerun.io/graph_undirected/15f46bec77452a8c6220558e4403b99cac188e2e/1200w.png" /// \example archetypes/graph_directed title="Simple directed graph" image="https://static.rerun.io/graph_directed/ca29a37b65e1e0b6482251dce401982a0bc568fa/1200w.png" table GraphEdges ( + "attr.rust.archetype_eager", "attr.docs.category": "Graph", "attr.docs.view_types": "GraphView", - "attr.rust.derive": "PartialEq, Eq" + "attr.rust.derive": "PartialEq" ) { // --- Required --- diff --git a/crates/store/re_types/definitions/rerun/archetypes/graph_nodes.fbs b/crates/store/re_types/definitions/rerun/archetypes/graph_nodes.fbs index d169b97bd25b..beca6808d500 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/graph_nodes.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/graph_nodes.fbs @@ -7,6 +7,7 @@ namespace rerun.archetypes; /// \example archetypes/graph_undirected !api title="Simple undirected graph" image="https://static.rerun.io/graph_undirected/15f46bec77452a8c6220558e4403b99cac188e2e/1200w.png" /// \example archetypes/graph_directed title="Simple directed graph" image="https://static.rerun.io/graph_directed/ca29a37b65e1e0b6482251dce401982a0bc568fa/1200w.png" table GraphNodes ( + "attr.rust.archetype_eager", "attr.docs.category": "Graph", "attr.docs.view_types": "GraphView", "attr.rust.derive": "PartialEq" diff --git a/crates/store/re_types/definitions/rerun/archetypes/image.fbs b/crates/store/re_types/definitions/rerun/archetypes/image.fbs index 0617aac1d6ce..bd73ee273b01 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/image.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/image.fbs @@ -24,6 +24,7 @@ namespace rerun.archetypes; /// \example archetypes/image_formats title="Logging images with various formats" image="https://static.rerun.io/image_formats/7b8a162fcfd266f303980439beea997dc8544c24/full.png" /// \example archetypes/image_send_columns !api title="Image from file, PIL & OpenCV" image="https://static.rerun.io/image_advanced/81fc8a255488615510790ee41be314e054978d51/full.png" table Image ( + // TODO(#7245): "attr.rust.archetype_eager", "attr.rust.derive": "PartialEq", "attr.cpp.no_field_ctors", "attr.docs.category": "Image & tensor", diff --git a/crates/store/re_types/definitions/rerun/archetypes/instance_poses3d.fbs b/crates/store/re_types/definitions/rerun/archetypes/instance_poses3d.fbs index d7ffbabe01ea..2ed7104b8f85 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/instance_poses3d.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/instance_poses3d.fbs @@ -19,6 +19,7 @@ namespace rerun.archetypes; /// \example archetypes/instance_poses3d_combined title="Regular & instance transforms in tandem" image="https://static.rerun.io/leaf_transform3d/41674f0082d6de489f8a1cd1583f60f6b5820ddf/1200w.png" /// \example archetypes/mesh3d_instancing !api title="3D mesh with instancing" image="https://static.rerun.io/mesh3d_leaf_transforms3d/c2d0ee033129da53168f5705625a9b033f3a3d61/1200w.png" table InstancePoses3D ( + "attr.rust.archetype_eager", "attr.docs.category": "Spatial 3D", "attr.docs.view_types": "Spatial3DView, Spatial2DView: if logged above active projection", "attr.rust.derive": " PartialEq" diff --git a/crates/store/re_types/definitions/rerun/archetypes/mesh3d.fbs b/crates/store/re_types/definitions/rerun/archetypes/mesh3d.fbs index 8b003db691bb..a3472cefb4b9 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/mesh3d.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/mesh3d.fbs @@ -13,6 +13,7 @@ namespace rerun.archetypes; /// \example archetypes/mesh3d_partial_updates !api title="3D mesh with partial updates" image="https://static.rerun.io/mesh3d_partial_updates/7de33d26220585691a403098c953cd46f94c3262/1200w.png" /// \example archetypes/mesh3d_instancing title="3D mesh with instancing" image="https://static.rerun.io/mesh3d_leaf_transforms3d/c2d0ee033129da53168f5705625a9b033f3a3d61/1200w.png" table Mesh3D ( + // TODO(#7245): "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/definitions/rerun/archetypes/pinhole.fbs b/crates/store/re_types/definitions/rerun/archetypes/pinhole.fbs index e5071aacb00f..bd13d712c4f8 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/pinhole.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/pinhole.fbs @@ -6,6 +6,7 @@ namespace rerun.archetypes; /// \example archetypes/pinhole_simple title="Simple pinhole camera" image="https://static.rerun.io/pinhole_simple/9af9441a94bcd9fd54e1fea44fb0c59ff381a7f2/1200w.png" /// \example archetypes/pinhole_perspective title="Perspective pinhole camera" image="https://static.rerun.io/pinhole_perspective/317e2de6d212b238dcdad5b67037e9e2a2afafa0/1200w.png" table Pinhole ( + // TODO(#7245): "attr.rust.archetype_eager" "attr.rust.derive": "PartialEq", "attr.docs.category": "Spatial 3D", "attr.docs.view_types": "Spatial2DView, Spatial2DView" diff --git a/crates/store/re_types/definitions/rerun/archetypes/points2d.fbs b/crates/store/re_types/definitions/rerun/archetypes/points2d.fbs index 33bffc2991d2..8f1e33c093c3 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/points2d.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/points2d.fbs @@ -10,6 +10,7 @@ namespace rerun.archetypes; /// \example archetypes/points2d_random title="Randomly distributed 2D points with varying color and radius" image="https://static.rerun.io/point2d_random/8e8ac75373677bd72bd3f56a15e44fcab309a168/1200w.png" /// \example archetypes/points2d_ui_radius title="Log points with radii given in UI points" image="https://static.rerun.io/point2d_ui_radius/ce804fc77300d89c348b4ab5960395171497b7ac/1200w.png" table Points2D ( + "attr.rust.archetype_eager", "attr.rust.derive": "PartialEq", "attr.docs.category": "Spatial 2D", "attr.docs.view_types": "Spatial2DView, Spatial3DView: if logged under a projection" diff --git a/crates/store/re_types/definitions/rerun/archetypes/scalar.fbs b/crates/store/re_types/definitions/rerun/archetypes/scalar.fbs index 70e700176e8c..773a3a8a7331 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/scalar.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/scalar.fbs @@ -16,6 +16,7 @@ namespace rerun.archetypes; /// \example archetypes/scalar_multiple_plots !api title="Multiple time series plots" image="https://static.rerun.io/scalar_multiple/15845c2a348f875248fbd694e03eabd922741c4c/1200w.png" /// \example archetypes/scalar_send_columns !api title="Multiple scalars in a single `send_columns` call" image="https://static.rerun.io/scalar_send_columns/b4bf172256f521f4851dfec5c2c6e3143f5d6923/1200w.png" table Scalar ( + "attr.rust.archetype_eager", "attr.rust.derive": "PartialEq", "attr.docs.category": "Plotting", "attr.docs.view_types": "TimeSeriesView" diff --git a/crates/store/re_types/definitions/rerun/archetypes/segmentation_image.fbs b/crates/store/re_types/definitions/rerun/archetypes/segmentation_image.fbs index 8aa0e2048c28..e4097e683b74 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/segmentation_image.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/segmentation_image.fbs @@ -16,6 +16,7 @@ namespace rerun.archetypes; /// /// \example archetypes/segmentation_image_simple title="Simple segmentation image" image="https://static.rerun.io/segmentation_image_simple/f8aac62abcf4c59c5d62f9ebc2d86fd0285c1736/1200w.png" table SegmentationImage ( + "attr.rust.archetype_eager", "attr.rust.derive": "PartialEq", "attr.cpp.no_field_ctors", "attr.docs.category": "Image & tensor", diff --git a/crates/store/re_types/definitions/rerun/archetypes/series_line.fbs b/crates/store/re_types/definitions/rerun/archetypes/series_line.fbs index afbcc4921963..73defca058b3 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/series_line.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/series_line.fbs @@ -10,6 +10,7 @@ namespace rerun.archetypes; /// /// \example archetypes/series_line_style title="Line series" image="https://static.rerun.io/series_line_style/d2616d98b1e46bdb85849b8669154fdf058e3453/1200w.png" table SeriesLine ( + "attr.rust.archetype_eager", "attr.docs.category": "Plotting", "attr.docs.view_types": "TimeSeriesView" ) { diff --git a/crates/store/re_types/definitions/rerun/archetypes/series_point.fbs b/crates/store/re_types/definitions/rerun/archetypes/series_point.fbs index bf918e89867e..f3d475c46136 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/series_point.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/series_point.fbs @@ -10,6 +10,7 @@ namespace rerun.archetypes; /// /// \example archetypes/series_point_style title="Point series" image="https://static.rerun.io/series_point_style/82207a705da6c086b28ce161db1db9e8b12258b7/1200w.png" table SeriesPoint ( + "attr.rust.archetype_eager", "attr.docs.category": "Plotting", "attr.docs.view_types": "TimeSeriesView" ) { diff --git a/crates/store/re_types/definitions/rerun/archetypes/tensor.fbs b/crates/store/re_types/definitions/rerun/archetypes/tensor.fbs index 00ea0344f112..0976fa1fe0bb 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/tensor.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/tensor.fbs @@ -13,6 +13,7 @@ namespace rerun.archetypes; /// /// \example archetypes/tensor_simple title="Simple tensor" image="https://static.rerun.io/tensor_simple/baacb07712f7b706e3c80e696f70616c6c20b367/1200w.png" table Tensor ( + // TODO(#7245): "attr.rust.archetype_eager", "attr.rust.derive": "PartialEq", "attr.docs.category": "Image & tensor", "attr.docs.view_types": "TensorView, BarChartView: for 1D tensors" diff --git a/crates/store/re_types/definitions/rerun/archetypes/text_document.fbs b/crates/store/re_types/definitions/rerun/archetypes/text_document.fbs index d5224bc8f201..5259f16f09dc 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/text_document.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/text_document.fbs @@ -8,7 +8,8 @@ namespace rerun.archetypes; /// /// \example archetypes/text_document title="Markdown text document" image="https://static.rerun.io/textdocument/babda19558ee32ed8d730495b595aee7a5e2c174/1200w.png" table TextDocument ( - "attr.rust.derive": "PartialEq, Eq", + "attr.rust.archetype_eager", + "attr.rust.derive": "PartialEq", "attr.docs.category": "Text", "attr.docs.view_types": "TextDocumentView" ) { diff --git a/crates/store/re_types/definitions/rerun/archetypes/text_log.fbs b/crates/store/re_types/definitions/rerun/archetypes/text_log.fbs index 9646ba0654cd..6ed31795cd15 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/text_log.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/text_log.fbs @@ -6,7 +6,8 @@ namespace rerun.archetypes; /// /// \example archetypes/text_log_integration text="Logging text directly or via a logger" image="https://static.rerun.io/text_log_integration/9737d0c986325802a9885499d6fcc773b1736488/1200w.png" table TextLog ( - "attr.rust.derive": "PartialEq, Eq", + "attr.rust.archetype_eager", + "attr.rust.derive": "PartialEq", "attr.docs.category": "Text", "attr.docs.view_types": "TextLogView" ) { diff --git a/crates/store/re_types/definitions/rerun/archetypes/video_frame_reference.fbs b/crates/store/re_types/definitions/rerun/archetypes/video_frame_reference.fbs index 0bf9de7af449..a423a147a73d 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/video_frame_reference.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/video_frame_reference.fbs @@ -10,6 +10,7 @@ namespace rerun.archetypes; /// \example archetypes/video_auto_frames title="Video with automatically determined frames" image="https://static.rerun.io/video_manual_frames/320a44e1e06b8b3a3161ecbbeae3e04d1ccb9589/1200w.png" /// \example archetypes/video_manual_frames title="Demonstrates manual use of video frame references" image="https://static.rerun.io/video_manual_frames/9f41c00f84a98cc3f26875fba7c1d2fa2bad7151/1200w.png" table VideoFrameReference ( + "attr.rust.archetype_eager", "attr.docs.category": "Video", "attr.docs.view_types": "Spatial2DView, Spatial3DView: if logged under a projection" ){ diff --git a/crates/store/re_types/definitions/rerun/archetypes/view_coordinates.fbs b/crates/store/re_types/definitions/rerun/archetypes/view_coordinates.fbs index 88cf09f52a40..49ebdd02d0bc 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/view_coordinates.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/view_coordinates.fbs @@ -17,6 +17,7 @@ namespace rerun.archetypes; /// /// \example archetypes/view_coordinates_simple title="View coordinates for adjusting the eye camera" image="https://static.rerun.io/viewcoordinates/0833f0dc8616a676b7b2c566f2a6f613363680c5/1200w.png" table ViewCoordinates ( + // TODO(#7245): "attr.rust.archetype_eager", "attr.rust.derive": "Copy, PartialEq, Eq, bytemuck::Pod, bytemuck::Zeroable", "attr.rust.repr": "transparent", "attr.docs.category": "Spatial 3D", diff --git a/crates/store/re_types/src/archetypes/arrows2d.rs b/crates/store/re_types/src/archetypes/arrows2d.rs index 6afea171fe0b..e34a17d00a8b 100644 --- a/crates/store/re_types/src/archetypes/arrows2d.rs +++ b/crates/store/re_types/src/archetypes/arrows2d.rs @@ -48,43 +48,43 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; /// /// /// -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Default)] pub struct Arrows2D { /// All the vectors for each arrow in the batch. - pub vectors: Vec, + pub vectors: Option, /// All the origin (base) positions for each arrow in the batch. /// /// If no origins are set, (0, 0) is used as the origin for each arrow. - pub origins: Option>, + pub origins: Option, /// Optional radii for the arrows. /// /// The shaft is rendered as a line with `radius = 0.5 * radius`. /// The tip is rendered with `height = 2.0 * radius` and `radius = 1.0 * radius`. - pub radii: Option>, + pub radii: Option, /// Optional colors for the points. - pub colors: Option>, + pub colors: Option, /// Optional text labels for the arrows. /// /// 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, /// An optional floating point value that specifies the 2D drawing order. /// /// Objects with higher values are drawn on top of those with lower values. - pub draw_order: Option, + pub draw_order: Option, /// Optional class Ids for the points. /// /// The [`components::ClassId`][crate::components::ClassId] provides colors and labels if not specified explicitly. - pub class_ids: Option>, + pub class_ids: Option, } impl Arrows2D { @@ -271,97 +271,36 @@ impl ::re_types_core::Archetype for Arrows2D { 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 vectors = { - let array = arrays_by_descr - .get(&Self::descriptor_vectors()) - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.Arrows2D#vectors")?; - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Arrows2D#vectors")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Arrows2D#vectors")? - }; - let origins = if let Some(array) = arrays_by_descr.get(&Self::descriptor_origins()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Arrows2D#origins")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Arrows2D#origins")? - }) - } else { - None - }; - let radii = if let Some(array) = arrays_by_descr.get(&Self::descriptor_radii()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Arrows2D#radii")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Arrows2D#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.Arrows2D#colors")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Arrows2D#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.Arrows2D#labels")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Arrows2D#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.Arrows2D#show_labels")? - .into_iter() - .next() - .flatten() - } else { - None - }; - let draw_order = if let Some(array) = arrays_by_descr.get(&Self::descriptor_draw_order()) { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Arrows2D#draw_order")? - .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.Arrows2D#class_ids")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Arrows2D#class_ids")? - }) - } else { - None - }; + let vectors = arrays_by_descr + .get(&Self::descriptor_vectors()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_vectors())); + let origins = arrays_by_descr + .get(&Self::descriptor_origins()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_origins())); + 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 draw_order = arrays_by_descr + .get(&Self::descriptor_draw_order()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_draw_order()) + }); + let class_ids = arrays_by_descr + .get(&Self::descriptor_class_ids()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_class_ids()) + }); Ok(Self { vectors, origins, @@ -376,73 +315,19 @@ impl ::re_types_core::Archetype for Arrows2D { } impl ::re_types_core::AsComponents for Arrows2D { - 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.vectors as &dyn ComponentBatch)).map(|batch| { - ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_vectors()), - } - }), - (self - .origins - .as_ref() - .map(|comp_batch| (comp_batch as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_origins()), - }), - (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 - .draw_order - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_draw_order()), - }), - (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.vectors.clone(), + self.origins.clone(), + self.radii.clone(), + self.colors.clone(), + self.labels.clone(), + self.show_labels.clone(), + self.draw_order.clone(), + self.class_ids.clone(), ] .into_iter() .flatten() @@ -459,7 +344,7 @@ impl Arrows2D { vectors: impl IntoIterator>, ) -> Self { Self { - vectors: vectors.into_iter().map(Into::into).collect(), + vectors: try_serialize_field(Self::descriptor_vectors(), vectors), origins: None, radii: None, colors: None, @@ -470,6 +355,62 @@ impl Arrows2D { } } + /// Update only some specific fields of a `Arrows2D`. + #[inline] + pub fn update_fields() -> Self { + Self::default() + } + + /// Clear all the fields of a `Arrows2D`. + #[inline] + pub fn clear_fields() -> Self { + use ::re_types_core::Loggable as _; + Self { + vectors: Some(SerializedComponentBatch::new( + crate::components::Vector2D::arrow_empty(), + Self::descriptor_vectors(), + )), + origins: Some(SerializedComponentBatch::new( + crate::components::Position2D::arrow_empty(), + Self::descriptor_origins(), + )), + 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(), + )), + draw_order: Some(SerializedComponentBatch::new( + crate::components::DrawOrder::arrow_empty(), + Self::descriptor_draw_order(), + )), + class_ids: Some(SerializedComponentBatch::new( + crate::components::ClassId::arrow_empty(), + Self::descriptor_class_ids(), + )), + } + } + + /// All the vectors for each arrow in the batch. + #[inline] + pub fn with_vectors( + mut self, + vectors: impl IntoIterator>, + ) -> Self { + self.vectors = try_serialize_field(Self::descriptor_vectors(), vectors); + self + } + /// All the origin (base) positions for each arrow in the batch. /// /// If no origins are set, (0, 0) is used as the origin for each arrow. @@ -478,7 +419,7 @@ impl Arrows2D { mut self, origins: impl IntoIterator>, ) -> Self { - self.origins = Some(origins.into_iter().map(Into::into).collect()); + self.origins = try_serialize_field(Self::descriptor_origins(), origins); self } @@ -491,7 +432,7 @@ impl Arrows2D { 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 } @@ -501,7 +442,7 @@ impl Arrows2D { 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 } @@ -514,7 +455,7 @@ impl Arrows2D { 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 } @@ -524,7 +465,7 @@ impl Arrows2D { 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 } @@ -533,7 +474,7 @@ impl Arrows2D { /// Objects with higher values are drawn on top of those with lower values. #[inline] pub fn with_draw_order(mut self, draw_order: impl Into) -> Self { - self.draw_order = Some(draw_order.into()); + self.draw_order = try_serialize_field(Self::descriptor_draw_order(), [draw_order]); self } @@ -545,7 +486,7 @@ impl Arrows2D { 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 } } @@ -562,16 +503,4 @@ impl ::re_byte_size::SizeBytes for Arrows2D { + self.draw_order.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() - && >::is_pod() - && >>::is_pod() - } } diff --git a/crates/store/re_types/src/archetypes/arrows3d.rs b/crates/store/re_types/src/archetypes/arrows3d.rs index dd0027b11e8d..5ba80d6c4c50 100644 --- a/crates/store/re_types/src/archetypes/arrows3d.rs +++ b/crates/store/re_types/src/archetypes/arrows3d.rs @@ -61,38 +61,38 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; /// /// /// -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Default)] pub struct Arrows3D { /// All the vectors for each arrow in the batch. - pub vectors: Vec, + pub vectors: Option, /// All the origin (base) positions for each arrow in the batch. /// /// If no origins are set, (0, 0, 0) is used as the origin for each arrow. - pub origins: Option>, + pub origins: Option, /// Optional radii for the arrows. /// /// The shaft is rendered as a line with `radius = 0.5 * radius`. /// The tip is rendered with `height = 2.0 * radius` and `radius = 1.0 * radius`. - pub radii: Option>, + pub radii: Option, /// Optional colors for the points. - pub colors: Option>, + pub colors: Option, /// Optional text labels for the arrows. /// /// 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 class Ids for the points. /// /// The [`components::ClassId`][crate::components::ClassId] provides colors and labels if not specified explicitly. - pub class_ids: Option>, + pub class_ids: Option, } impl Arrows3D { @@ -267,88 +267,31 @@ impl ::re_types_core::Archetype for Arrows3D { 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 vectors = { - let array = arrays_by_descr - .get(&Self::descriptor_vectors()) - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.Arrows3D#vectors")?; - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Arrows3D#vectors")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Arrows3D#vectors")? - }; - let origins = if let Some(array) = arrays_by_descr.get(&Self::descriptor_origins()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Arrows3D#origins")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Arrows3D#origins")? - }) - } else { - None - }; - let radii = if let Some(array) = arrays_by_descr.get(&Self::descriptor_radii()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Arrows3D#radii")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Arrows3D#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.Arrows3D#colors")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Arrows3D#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.Arrows3D#labels")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Arrows3D#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.Arrows3D#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.Arrows3D#class_ids")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Arrows3D#class_ids")? - }) - } else { - None - }; + let vectors = arrays_by_descr + .get(&Self::descriptor_vectors()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_vectors())); + let origins = arrays_by_descr + .get(&Self::descriptor_origins()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_origins())); + 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 { vectors, origins, @@ -362,65 +305,18 @@ impl ::re_types_core::Archetype for Arrows3D { } impl ::re_types_core::AsComponents for Arrows3D { - 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.vectors as &dyn ComponentBatch)).map(|batch| { - ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_vectors()), - } - }), - (self - .origins - .as_ref() - .map(|comp_batch| (comp_batch as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_origins()), - }), - (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.vectors.clone(), + self.origins.clone(), + self.radii.clone(), + self.colors.clone(), + self.labels.clone(), + self.show_labels.clone(), + self.class_ids.clone(), ] .into_iter() .flatten() @@ -437,7 +333,7 @@ impl Arrows3D { vectors: impl IntoIterator>, ) -> Self { Self { - vectors: vectors.into_iter().map(Into::into).collect(), + vectors: try_serialize_field(Self::descriptor_vectors(), vectors), origins: None, radii: None, colors: None, @@ -447,6 +343,58 @@ impl Arrows3D { } } + /// Update only some specific fields of a `Arrows3D`. + #[inline] + pub fn update_fields() -> Self { + Self::default() + } + + /// Clear all the fields of a `Arrows3D`. + #[inline] + pub fn clear_fields() -> Self { + use ::re_types_core::Loggable as _; + Self { + vectors: Some(SerializedComponentBatch::new( + crate::components::Vector3D::arrow_empty(), + Self::descriptor_vectors(), + )), + origins: Some(SerializedComponentBatch::new( + crate::components::Position3D::arrow_empty(), + Self::descriptor_origins(), + )), + 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 vectors for each arrow in the batch. + #[inline] + pub fn with_vectors( + mut self, + vectors: impl IntoIterator>, + ) -> Self { + self.vectors = try_serialize_field(Self::descriptor_vectors(), vectors); + self + } + /// All the origin (base) positions for each arrow in the batch. /// /// If no origins are set, (0, 0, 0) is used as the origin for each arrow. @@ -455,7 +403,7 @@ impl Arrows3D { mut self, origins: impl IntoIterator>, ) -> Self { - self.origins = Some(origins.into_iter().map(Into::into).collect()); + self.origins = try_serialize_field(Self::descriptor_origins(), origins); self } @@ -468,7 +416,7 @@ impl Arrows3D { 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 } @@ -478,7 +426,7 @@ impl Arrows3D { 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 } @@ -491,7 +439,7 @@ impl Arrows3D { 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 } @@ -501,7 +449,7 @@ impl Arrows3D { 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 } @@ -513,7 +461,7 @@ impl Arrows3D { 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 } } @@ -529,15 +477,4 @@ impl ::re_byte_size::SizeBytes for Arrows3D { + 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() - && >>::is_pod() - } } diff --git a/crates/store/re_types/src/archetypes/bar_chart.rs b/crates/store/re_types/src/archetypes/bar_chart.rs index 29ed3f84cf21..5e8cf8a7da88 100644 --- a/crates/store/re_types/src/archetypes/bar_chart.rs +++ b/crates/store/re_types/src/archetypes/bar_chart.rs @@ -46,13 +46,13 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; /// /// /// -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Default)] pub struct BarChart { /// The values. Should always be a 1-dimensional tensor (i.e. a vector). - pub values: crate::components::TensorData, + pub values: Option, /// The color of the bar chart - pub color: Option, + pub color: Option, } impl BarChart { @@ -159,52 +159,24 @@ impl ::re_types_core::Archetype for BarChart { 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 values = { - let array = arrays_by_descr - .get(&Self::descriptor_values()) - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.BarChart#values")?; - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.BarChart#values")? - .into_iter() - .next() - .flatten() - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.BarChart#values")? - }; - let color = if let Some(array) = arrays_by_descr.get(&Self::descriptor_color()) { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.BarChart#color")? - .into_iter() - .next() - .flatten() - } else { - None - }; + let values = arrays_by_descr + .get(&Self::descriptor_values()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_values())); + let color = arrays_by_descr + .get(&Self::descriptor_color()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_color())); Ok(Self { values, color }) } } impl ::re_types_core::AsComponents for BarChart { - 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.values as &dyn ComponentBatch)).map(|batch| { - ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_values()), - } - }), - (self - .color - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_color()), - }), + Self::indicator().serialized(), + self.values.clone(), + self.color.clone(), ] .into_iter() .flatten() @@ -219,15 +191,44 @@ impl BarChart { #[inline] pub fn new(values: impl Into) -> Self { Self { - values: values.into(), + values: try_serialize_field(Self::descriptor_values(), [values]), color: None, } } + /// Update only some specific fields of a `BarChart`. + #[inline] + pub fn update_fields() -> Self { + Self::default() + } + + /// Clear all the fields of a `BarChart`. + #[inline] + pub fn clear_fields() -> Self { + use ::re_types_core::Loggable as _; + Self { + values: Some(SerializedComponentBatch::new( + crate::components::TensorData::arrow_empty(), + Self::descriptor_values(), + )), + color: Some(SerializedComponentBatch::new( + crate::components::Color::arrow_empty(), + Self::descriptor_color(), + )), + } + } + + /// The values. Should always be a 1-dimensional tensor (i.e. a vector). + #[inline] + pub fn with_values(mut self, values: impl Into) -> Self { + self.values = try_serialize_field(Self::descriptor_values(), [values]); + self + } + /// The color of the bar chart #[inline] pub fn with_color(mut self, color: impl Into) -> Self { - self.color = Some(color.into()); + self.color = try_serialize_field(Self::descriptor_color(), [color]); self } } @@ -237,9 +238,4 @@ impl ::re_byte_size::SizeBytes for BarChart { fn heap_size_bytes(&self) -> u64 { self.values.heap_size_bytes() + self.color.heap_size_bytes() } - - #[inline] - fn is_pod() -> bool { - ::is_pod() && >::is_pod() - } } diff --git a/crates/store/re_types/src/archetypes/capsules3d.rs b/crates/store/re_types/src/archetypes/capsules3d.rs index db56147fb9cf..aa569e508056 100644 --- a/crates/store/re_types/src/archetypes/capsules3d.rs +++ b/crates/store/re_types/src/archetypes/capsules3d.rs @@ -71,45 +71,45 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; /// /// /// -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Default)] pub struct Capsules3D { /// Lengths of the capsules, defined as the distance between the centers of the endcaps. - pub lengths: Vec, + pub lengths: Option, /// Radii of the capsules. - pub radii: Vec, + pub radii: Option, /// Optional translations of the capsules. /// /// If not specified, one end of each capsule will be at (0, 0, 0). /// Note that this uses a [`components::PoseTranslation3D`][crate::components::PoseTranslation3D] which is also used by [`archetypes::InstancePoses3D`][crate::archetypes::InstancePoses3D]. - pub translations: Option>, + pub translations: Option, /// Rotations via axis + angle. /// /// If no rotation is specified, the capsules align with the +Z axis of the local coordinate system. /// Note that this uses a [`components::PoseRotationAxisAngle`][crate::components::PoseRotationAxisAngle] which is also used by [`archetypes::InstancePoses3D`][crate::archetypes::InstancePoses3D]. - pub rotation_axis_angles: Option>, + pub rotation_axis_angles: Option, /// Rotations via quaternion. /// /// If no rotation is specified, the capsules align with the +Z axis of the local coordinate system. /// Note that this uses a [`components::PoseRotationQuat`][crate::components::PoseRotationQuat] which is also used by [`archetypes::InstancePoses3D`][crate::archetypes::InstancePoses3D]. - pub quaternions: Option>, + pub quaternions: Option, /// Optional colors for the capsules. - pub colors: Option>, + pub colors: Option, /// Optional text labels for the capsules, which will be located at their centers. - 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 class ID for the ellipsoids. /// /// The class ID provides colors and labels if not specified explicitly. - pub class_ids: Option>, + pub class_ids: Option, } impl Capsules3D { @@ -312,115 +312,46 @@ impl ::re_types_core::Archetype for Capsules3D { 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 lengths = { - let array = arrays_by_descr - .get(&Self::descriptor_lengths()) - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.Capsules3D#lengths")?; - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Capsules3D#lengths")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Capsules3D#lengths")? - }; - let radii = { - let array = arrays_by_descr - .get(&Self::descriptor_radii()) - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.Capsules3D#radii")?; - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Capsules3D#radii")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Capsules3D#radii")? - }; - let translations = - if let Some(array) = arrays_by_descr.get(&Self::descriptor_translations()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Capsules3D#translations")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Capsules3D#translations")? - }) - } else { - None - }; - let rotation_axis_angles = - if let Some(array) = arrays_by_descr.get(&Self::descriptor_rotation_axis_angles()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Capsules3D#rotation_axis_angles")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Capsules3D#rotation_axis_angles")? - }) - } else { - None - }; - let quaternions = if let Some(array) = arrays_by_descr.get(&Self::descriptor_quaternions()) - { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Capsules3D#quaternions")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Capsules3D#quaternions")? - }) - } else { - None - }; - let colors = if let Some(array) = arrays_by_descr.get(&Self::descriptor_colors()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Capsules3D#colors")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Capsules3D#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.Capsules3D#labels")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Capsules3D#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.Capsules3D#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.Capsules3D#class_ids")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Capsules3D#class_ids")? - }) - } else { - None - }; + let lengths = arrays_by_descr + .get(&Self::descriptor_lengths()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_lengths())); + let radii = arrays_by_descr + .get(&Self::descriptor_radii()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_radii())); + let translations = arrays_by_descr + .get(&Self::descriptor_translations()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_translations()) + }); + let rotation_axis_angles = arrays_by_descr + .get(&Self::descriptor_rotation_axis_angles()) + .map(|array| { + SerializedComponentBatch::new( + array.clone(), + Self::descriptor_rotation_axis_angles(), + ) + }); + let quaternions = arrays_by_descr + .get(&Self::descriptor_quaternions()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_quaternions()) + }); + 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 { lengths, radii, @@ -436,79 +367,20 @@ impl ::re_types_core::Archetype for Capsules3D { } impl ::re_types_core::AsComponents for Capsules3D { - 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.lengths as &dyn ComponentBatch)).map(|batch| { - ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_lengths()), - } - }), - (Some(&self.radii as &dyn ComponentBatch)).map(|batch| { - ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_radii()), - } - }), - (self - .translations - .as_ref() - .map(|comp_batch| (comp_batch as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_translations()), - }), - (self - .rotation_axis_angles - .as_ref() - .map(|comp_batch| (comp_batch as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_rotation_axis_angles()), - }), - (self - .quaternions - .as_ref() - .map(|comp_batch| (comp_batch as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_quaternions()), - }), - (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.lengths.clone(), + self.radii.clone(), + self.translations.clone(), + self.rotation_axis_angles.clone(), + self.quaternions.clone(), + self.colors.clone(), + self.labels.clone(), + self.show_labels.clone(), + self.class_ids.clone(), ] .into_iter() .flatten() @@ -526,8 +398,8 @@ impl Capsules3D { radii: impl IntoIterator>, ) -> Self { Self { - lengths: lengths.into_iter().map(Into::into).collect(), - radii: radii.into_iter().map(Into::into).collect(), + lengths: try_serialize_field(Self::descriptor_lengths(), lengths), + radii: try_serialize_field(Self::descriptor_radii(), radii), translations: None, rotation_axis_angles: None, quaternions: None, @@ -538,6 +410,76 @@ impl Capsules3D { } } + /// Update only some specific fields of a `Capsules3D`. + #[inline] + pub fn update_fields() -> Self { + Self::default() + } + + /// Clear all the fields of a `Capsules3D`. + #[inline] + pub fn clear_fields() -> Self { + use ::re_types_core::Loggable as _; + Self { + lengths: Some(SerializedComponentBatch::new( + crate::components::Length::arrow_empty(), + Self::descriptor_lengths(), + )), + radii: Some(SerializedComponentBatch::new( + crate::components::Radius::arrow_empty(), + Self::descriptor_radii(), + )), + translations: Some(SerializedComponentBatch::new( + crate::components::PoseTranslation3D::arrow_empty(), + Self::descriptor_translations(), + )), + rotation_axis_angles: Some(SerializedComponentBatch::new( + crate::components::PoseRotationAxisAngle::arrow_empty(), + Self::descriptor_rotation_axis_angles(), + )), + quaternions: Some(SerializedComponentBatch::new( + crate::components::PoseRotationQuat::arrow_empty(), + Self::descriptor_quaternions(), + )), + 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(), + )), + } + } + + /// Lengths of the capsules, defined as the distance between the centers of the endcaps. + #[inline] + pub fn with_lengths( + mut self, + lengths: impl IntoIterator>, + ) -> Self { + self.lengths = try_serialize_field(Self::descriptor_lengths(), lengths); + self + } + + /// Radii of the capsules. + #[inline] + pub fn with_radii( + mut self, + radii: impl IntoIterator>, + ) -> Self { + self.radii = try_serialize_field(Self::descriptor_radii(), radii); + self + } + /// Optional translations of the capsules. /// /// If not specified, one end of each capsule will be at (0, 0, 0). @@ -547,7 +489,7 @@ impl Capsules3D { mut self, translations: impl IntoIterator>, ) -> Self { - self.translations = Some(translations.into_iter().map(Into::into).collect()); + self.translations = try_serialize_field(Self::descriptor_translations(), translations); self } @@ -562,8 +504,10 @@ impl Capsules3D { Item = impl Into, >, ) -> Self { - self.rotation_axis_angles = - Some(rotation_axis_angles.into_iter().map(Into::into).collect()); + self.rotation_axis_angles = try_serialize_field( + Self::descriptor_rotation_axis_angles(), + rotation_axis_angles, + ); self } @@ -576,7 +520,7 @@ impl Capsules3D { mut self, quaternions: impl IntoIterator>, ) -> Self { - self.quaternions = Some(quaternions.into_iter().map(Into::into).collect()); + self.quaternions = try_serialize_field(Self::descriptor_quaternions(), quaternions); self } @@ -586,7 +530,7 @@ impl Capsules3D { 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 } @@ -596,7 +540,7 @@ impl Capsules3D { 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 } @@ -606,7 +550,7 @@ impl Capsules3D { 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 } @@ -618,7 +562,7 @@ impl Capsules3D { 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 } } @@ -636,17 +580,4 @@ impl ::re_byte_size::SizeBytes for Capsules3D { + 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() - && >>::is_pod() - && >::is_pod() - && >>::is_pod() - } } diff --git a/crates/store/re_types/src/archetypes/capsules3d_ext.rs b/crates/store/re_types/src/archetypes/capsules3d_ext.rs index f42af8ab9f52..889adb4344c6 100644 --- a/crates/store/re_types/src/archetypes/capsules3d_ext.rs +++ b/crates/store/re_types/src/archetypes/capsules3d_ext.rs @@ -65,6 +65,7 @@ impl Capsules3D { } #[cfg(test)] +#[cfg(feature = "glam")] mod tests { use super::*; use glam::vec3; diff --git a/crates/store/re_types/src/archetypes/depth_image.rs b/crates/store/re_types/src/archetypes/depth_image.rs index 9feba02636a2..3293d6babd1d 100644 --- a/crates/store/re_types/src/archetypes/depth_image.rs +++ b/crates/store/re_types/src/archetypes/depth_image.rs @@ -64,13 +64,13 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; /// /// /// -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Default)] pub struct DepthImage { /// The raw depth image data. - pub buffer: crate::components::ImageBuffer, + pub buffer: Option, /// The format of the image. - pub format: crate::components::ImageFormat, + pub format: Option, /// An optional floating point value that specifies how long a meter is in the native depth units. /// @@ -79,12 +79,12 @@ pub struct DepthImage { /// /// Note that the only effect on 2D views is the physical depth values shown when hovering the image. /// In 3D views on the other hand, this affects where the points of the point cloud are placed. - pub meter: Option, + pub meter: Option, /// Colormap to use for rendering the depth image. /// /// If not set, the depth image will be rendered using the Turbo colormap. - pub colormap: Option, + pub colormap: Option, /// The expected range of depth values. /// @@ -97,7 +97,7 @@ pub struct DepthImage { /// in the contents of the depth image. /// E.g. if all values are positive, some bigger than 1.0 and all smaller than 255.0, /// the Viewer will guess that the data likely came from an 8bit image, thus assuming a range of 0-255. - pub depth_range: Option, + pub depth_range: Option, /// Scale the radii of the points in the point cloud generated from this image. /// @@ -106,12 +106,12 @@ pub struct DepthImage { /// A fill ratio of 0.5 means that each point touches the edge of its neighbor if it has the same depth. /// /// TODO(#6744): This applies only to 3D views! - pub point_fill_ratio: Option, + pub point_fill_ratio: Option, /// An optional floating point value that specifies the 2D drawing order, used only if the depth image is shown as a 2D image. /// /// Objects with higher values are drawn on top of those with lower values. - pub draw_order: Option, + pub draw_order: Option, } impl DepthImage { @@ -286,79 +286,33 @@ impl ::re_types_core::Archetype for DepthImage { 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 buffer = { - let array = arrays_by_descr - .get(&Self::descriptor_buffer()) - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.DepthImage#buffer")?; - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.DepthImage#buffer")? - .into_iter() - .next() - .flatten() - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.DepthImage#buffer")? - }; - let format = { - let array = arrays_by_descr - .get(&Self::descriptor_format()) - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.DepthImage#format")?; - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.DepthImage#format")? - .into_iter() - .next() - .flatten() - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.DepthImage#format")? - }; - let meter = if let Some(array) = arrays_by_descr.get(&Self::descriptor_meter()) { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.DepthImage#meter")? - .into_iter() - .next() - .flatten() - } else { - None - }; - let colormap = if let Some(array) = arrays_by_descr.get(&Self::descriptor_colormap()) { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.DepthImage#colormap")? - .into_iter() - .next() - .flatten() - } else { - None - }; - let depth_range = if let Some(array) = arrays_by_descr.get(&Self::descriptor_depth_range()) - { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.DepthImage#depth_range")? - .into_iter() - .next() - .flatten() - } else { - None - }; - let point_fill_ratio = - if let Some(array) = arrays_by_descr.get(&Self::descriptor_point_fill_ratio()) { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.DepthImage#point_fill_ratio")? - .into_iter() - .next() - .flatten() - } else { - None - }; - let draw_order = if let Some(array) = arrays_by_descr.get(&Self::descriptor_draw_order()) { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.DepthImage#draw_order")? - .into_iter() - .next() - .flatten() - } else { - None - }; + let buffer = arrays_by_descr + .get(&Self::descriptor_buffer()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_buffer())); + let format = arrays_by_descr + .get(&Self::descriptor_format()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_format())); + let meter = arrays_by_descr + .get(&Self::descriptor_meter()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_meter())); + let colormap = arrays_by_descr + .get(&Self::descriptor_colormap()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_colormap())); + let depth_range = arrays_by_descr + .get(&Self::descriptor_depth_range()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_depth_range()) + }); + let point_fill_ratio = arrays_by_descr + .get(&Self::descriptor_point_fill_ratio()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_point_fill_ratio()) + }); + let draw_order = arrays_by_descr + .get(&Self::descriptor_draw_order()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_draw_order()) + }); Ok(Self { buffer, format, @@ -372,63 +326,18 @@ impl ::re_types_core::Archetype for DepthImage { } impl ::re_types_core::AsComponents for DepthImage { - 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.buffer as &dyn ComponentBatch)).map(|batch| { - ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_buffer()), - } - }), - (Some(&self.format as &dyn ComponentBatch)).map(|batch| { - ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_format()), - } - }), - (self - .meter - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_meter()), - }), - (self - .colormap - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_colormap()), - }), - (self - .depth_range - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_depth_range()), - }), - (self - .point_fill_ratio - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_point_fill_ratio()), - }), - (self - .draw_order - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_draw_order()), - }), + Self::indicator().serialized(), + self.buffer.clone(), + self.format.clone(), + self.meter.clone(), + self.colormap.clone(), + self.depth_range.clone(), + self.point_fill_ratio.clone(), + self.draw_order.clone(), ] .into_iter() .flatten() @@ -446,8 +355,8 @@ impl DepthImage { format: impl Into, ) -> Self { Self { - buffer: buffer.into(), - format: format.into(), + buffer: try_serialize_field(Self::descriptor_buffer(), [buffer]), + format: try_serialize_field(Self::descriptor_format(), [format]), meter: None, colormap: None, depth_range: None, @@ -456,6 +365,62 @@ impl DepthImage { } } + /// Update only some specific fields of a `DepthImage`. + #[inline] + pub fn update_fields() -> Self { + Self::default() + } + + /// Clear all the fields of a `DepthImage`. + #[inline] + pub fn clear_fields() -> Self { + use ::re_types_core::Loggable as _; + Self { + buffer: Some(SerializedComponentBatch::new( + crate::components::ImageBuffer::arrow_empty(), + Self::descriptor_buffer(), + )), + format: Some(SerializedComponentBatch::new( + crate::components::ImageFormat::arrow_empty(), + Self::descriptor_format(), + )), + meter: Some(SerializedComponentBatch::new( + crate::components::DepthMeter::arrow_empty(), + Self::descriptor_meter(), + )), + colormap: Some(SerializedComponentBatch::new( + crate::components::Colormap::arrow_empty(), + Self::descriptor_colormap(), + )), + depth_range: Some(SerializedComponentBatch::new( + crate::components::ValueRange::arrow_empty(), + Self::descriptor_depth_range(), + )), + point_fill_ratio: Some(SerializedComponentBatch::new( + crate::components::FillRatio::arrow_empty(), + Self::descriptor_point_fill_ratio(), + )), + draw_order: Some(SerializedComponentBatch::new( + crate::components::DrawOrder::arrow_empty(), + Self::descriptor_draw_order(), + )), + } + } + + /// The raw depth image data. + #[inline] + pub fn with_buffer(mut self, buffer: impl Into) -> Self { + self.buffer = try_serialize_field(Self::descriptor_buffer(), [buffer]); + self + } + + /// The format of the image. + #[inline] + pub fn with_format(mut self, format: impl Into) -> Self { + self.format = try_serialize_field(Self::descriptor_format(), [format]); + self + } + /// An optional floating point value that specifies how long a meter is in the native depth units. /// /// For instance: with uint16, perhaps meter=1000 which would mean you have millimeter precision @@ -465,7 +430,7 @@ impl DepthImage { /// In 3D views on the other hand, this affects where the points of the point cloud are placed. #[inline] pub fn with_meter(mut self, meter: impl Into) -> Self { - self.meter = Some(meter.into()); + self.meter = try_serialize_field(Self::descriptor_meter(), [meter]); self } @@ -474,7 +439,7 @@ impl DepthImage { /// If not set, the depth image will be rendered using the Turbo colormap. #[inline] pub fn with_colormap(mut self, colormap: impl Into) -> Self { - self.colormap = Some(colormap.into()); + self.colormap = try_serialize_field(Self::descriptor_colormap(), [colormap]); self } @@ -494,7 +459,7 @@ impl DepthImage { mut self, depth_range: impl Into, ) -> Self { - self.depth_range = Some(depth_range.into()); + self.depth_range = try_serialize_field(Self::descriptor_depth_range(), [depth_range]); self } @@ -510,7 +475,8 @@ impl DepthImage { mut self, point_fill_ratio: impl Into, ) -> Self { - self.point_fill_ratio = Some(point_fill_ratio.into()); + self.point_fill_ratio = + try_serialize_field(Self::descriptor_point_fill_ratio(), [point_fill_ratio]); self } @@ -519,7 +485,7 @@ impl DepthImage { /// Objects with higher values are drawn on top of those with lower values. #[inline] pub fn with_draw_order(mut self, draw_order: impl Into) -> Self { - self.draw_order = Some(draw_order.into()); + self.draw_order = try_serialize_field(Self::descriptor_draw_order(), [draw_order]); self } } @@ -535,15 +501,4 @@ impl ::re_byte_size::SizeBytes for DepthImage { + self.point_fill_ratio.heap_size_bytes() + self.draw_order.heap_size_bytes() } - - #[inline] - fn is_pod() -> bool { - ::is_pod() - && ::is_pod() - && >::is_pod() - && >::is_pod() - && >::is_pod() - && >::is_pod() - && >::is_pod() - } } diff --git a/crates/store/re_types/src/archetypes/depth_image_ext.rs b/crates/store/re_types/src/archetypes/depth_image_ext.rs index af72285a3edd..f6128ca7979f 100644 --- a/crates/store/re_types/src/archetypes/depth_image_ext.rs +++ b/crates/store/re_types/src/archetypes/depth_image_ext.rs @@ -34,15 +34,7 @@ impl DepthImage { let image_format = ImageFormat::depth([width as u32, height as u32], datatype); - Ok(Self { - buffer: blob.into(), - format: image_format, - draw_order: None, - meter: None, - colormap: None, - point_fill_ratio: None, - depth_range: None, - }) + Ok(Self::new(blob, image_format)) } /// Construct a depth image from a byte buffer given its resolution, and data type. @@ -62,15 +54,7 @@ impl DepthImage { ); } - Self { - buffer, - format: image_format, - meter: None, - colormap: None, - depth_range: None, - point_fill_ratio: None, - draw_order: None, - } + Self::new(buffer, image_format) } /// From an 16-bit grayscale image. diff --git a/crates/store/re_types/src/archetypes/ellipsoids3d.rs b/crates/store/re_types/src/archetypes/ellipsoids3d.rs index 06677f84f624..4bd00fda37be 100644 --- a/crates/store/re_types/src/archetypes/ellipsoids3d.rs +++ b/crates/store/re_types/src/archetypes/ellipsoids3d.rs @@ -79,50 +79,50 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; /// /// /// -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Default)] pub struct Ellipsoids3D { /// For each ellipsoid, half of its size on its three axes. /// /// If all components are equal, then it is a sphere with that radius. - pub half_sizes: Vec, + pub half_sizes: Option, /// Optional center positions of the ellipsoids. /// /// If not specified, the centers will be at (0, 0, 0). /// Note that this uses a [`components::PoseTranslation3D`][crate::components::PoseTranslation3D] which is also used by [`archetypes::InstancePoses3D`][crate::archetypes::InstancePoses3D]. - pub centers: Option>, + pub centers: Option, /// Rotations via axis + angle. /// /// If no rotation is specified, the axes of the ellipsoid align with the axes of the local coordinate system. /// Note that this uses a [`components::PoseRotationAxisAngle`][crate::components::PoseRotationAxisAngle] which is also used by [`archetypes::InstancePoses3D`][crate::archetypes::InstancePoses3D]. - pub rotation_axis_angles: Option>, + pub rotation_axis_angles: Option, /// Rotations via quaternion. /// /// If no rotation is specified, the axes of the ellipsoid align with the axes of the local coordinate system. /// Note that this uses a [`components::PoseRotationQuat`][crate::components::PoseRotationQuat] which is also used by [`archetypes::InstancePoses3D`][crate::archetypes::InstancePoses3D]. - pub quaternions: Option>, + pub quaternions: Option, /// Optional colors for the ellipsoids. - pub colors: Option>, + pub colors: Option, /// Optional radii for the lines used when the ellipsoid is rendered as a wireframe. - pub line_radii: Option>, + pub line_radii: Option, /// Optionally choose whether the ellipsoids are drawn with lines or solid. - pub fill_mode: Option, + pub fill_mode: Option, /// Optional text labels for the ellipsoids. - 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 class ID for the ellipsoids. /// /// The class ID provides colors and labels if not specified explicitly. - pub class_ids: Option>, + pub class_ids: Option, } impl Ellipsoids3D { @@ -333,123 +333,53 @@ impl ::re_types_core::Archetype for Ellipsoids3D { 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 half_sizes = { - let array = arrays_by_descr - .get(&Self::descriptor_half_sizes()) - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.Ellipsoids3D#half_sizes")?; - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Ellipsoids3D#half_sizes")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Ellipsoids3D#half_sizes")? - }; - let centers = if let Some(array) = arrays_by_descr.get(&Self::descriptor_centers()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Ellipsoids3D#centers")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Ellipsoids3D#centers")? - }) - } else { - None - }; - let rotation_axis_angles = - if let Some(array) = arrays_by_descr.get(&Self::descriptor_rotation_axis_angles()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Ellipsoids3D#rotation_axis_angles")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Ellipsoids3D#rotation_axis_angles")? - }) - } else { - None - }; - let quaternions = if let Some(array) = arrays_by_descr.get(&Self::descriptor_quaternions()) - { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Ellipsoids3D#quaternions")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Ellipsoids3D#quaternions")? - }) - } else { - None - }; - let colors = if let Some(array) = arrays_by_descr.get(&Self::descriptor_colors()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Ellipsoids3D#colors")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Ellipsoids3D#colors")? - }) - } else { - None - }; - let line_radii = if let Some(array) = arrays_by_descr.get(&Self::descriptor_line_radii()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Ellipsoids3D#line_radii")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Ellipsoids3D#line_radii")? - }) - } else { - None - }; - let fill_mode = if let Some(array) = arrays_by_descr.get(&Self::descriptor_fill_mode()) { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Ellipsoids3D#fill_mode")? - .into_iter() - .next() - .flatten() - } else { - None - }; - let labels = if let Some(array) = arrays_by_descr.get(&Self::descriptor_labels()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Ellipsoids3D#labels")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Ellipsoids3D#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.Ellipsoids3D#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.Ellipsoids3D#class_ids")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Ellipsoids3D#class_ids")? - }) - } else { - None - }; + let half_sizes = arrays_by_descr + .get(&Self::descriptor_half_sizes()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_half_sizes()) + }); + let centers = arrays_by_descr + .get(&Self::descriptor_centers()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_centers())); + let rotation_axis_angles = arrays_by_descr + .get(&Self::descriptor_rotation_axis_angles()) + .map(|array| { + SerializedComponentBatch::new( + array.clone(), + Self::descriptor_rotation_axis_angles(), + ) + }); + let quaternions = arrays_by_descr + .get(&Self::descriptor_quaternions()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_quaternions()) + }); + let colors = arrays_by_descr + .get(&Self::descriptor_colors()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_colors())); + let line_radii = arrays_by_descr + .get(&Self::descriptor_line_radii()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_line_radii()) + }); + let fill_mode = arrays_by_descr + .get(&Self::descriptor_fill_mode()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_fill_mode()) + }); + 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 { half_sizes, centers, @@ -466,89 +396,21 @@ impl ::re_types_core::Archetype for Ellipsoids3D { } impl ::re_types_core::AsComponents for Ellipsoids3D { - 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.half_sizes as &dyn ComponentBatch)).map(|batch| { - ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_half_sizes()), - } - }), - (self - .centers - .as_ref() - .map(|comp_batch| (comp_batch as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_centers()), - }), - (self - .rotation_axis_angles - .as_ref() - .map(|comp_batch| (comp_batch as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_rotation_axis_angles()), - }), - (self - .quaternions - .as_ref() - .map(|comp_batch| (comp_batch as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_quaternions()), - }), - (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 - .line_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_line_radii()), - }), - (self - .fill_mode - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_fill_mode()), - }), - (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.half_sizes.clone(), + self.centers.clone(), + self.rotation_axis_angles.clone(), + self.quaternions.clone(), + self.colors.clone(), + self.line_radii.clone(), + self.fill_mode.clone(), + self.labels.clone(), + self.show_labels.clone(), + self.class_ids.clone(), ] .into_iter() .flatten() @@ -565,7 +427,7 @@ impl Ellipsoids3D { half_sizes: impl IntoIterator>, ) -> Self { Self { - half_sizes: half_sizes.into_iter().map(Into::into).collect(), + half_sizes: try_serialize_field(Self::descriptor_half_sizes(), half_sizes), centers: None, rotation_axis_angles: None, quaternions: None, @@ -578,6 +440,72 @@ impl Ellipsoids3D { } } + /// Update only some specific fields of a `Ellipsoids3D`. + #[inline] + pub fn update_fields() -> Self { + Self::default() + } + + /// Clear all the fields of a `Ellipsoids3D`. + #[inline] + pub fn clear_fields() -> Self { + use ::re_types_core::Loggable as _; + Self { + half_sizes: Some(SerializedComponentBatch::new( + crate::components::HalfSize3D::arrow_empty(), + Self::descriptor_half_sizes(), + )), + centers: Some(SerializedComponentBatch::new( + crate::components::PoseTranslation3D::arrow_empty(), + Self::descriptor_centers(), + )), + rotation_axis_angles: Some(SerializedComponentBatch::new( + crate::components::PoseRotationAxisAngle::arrow_empty(), + Self::descriptor_rotation_axis_angles(), + )), + quaternions: Some(SerializedComponentBatch::new( + crate::components::PoseRotationQuat::arrow_empty(), + Self::descriptor_quaternions(), + )), + colors: Some(SerializedComponentBatch::new( + crate::components::Color::arrow_empty(), + Self::descriptor_colors(), + )), + line_radii: Some(SerializedComponentBatch::new( + crate::components::Radius::arrow_empty(), + Self::descriptor_line_radii(), + )), + fill_mode: Some(SerializedComponentBatch::new( + crate::components::FillMode::arrow_empty(), + Self::descriptor_fill_mode(), + )), + 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(), + )), + } + } + + /// For each ellipsoid, half of its size on its three axes. + /// + /// If all components are equal, then it is a sphere with that radius. + #[inline] + pub fn with_half_sizes( + mut self, + half_sizes: impl IntoIterator>, + ) -> Self { + self.half_sizes = try_serialize_field(Self::descriptor_half_sizes(), half_sizes); + self + } + /// Optional center positions of the ellipsoids. /// /// If not specified, the centers will be at (0, 0, 0). @@ -587,7 +515,7 @@ impl Ellipsoids3D { mut self, centers: impl IntoIterator>, ) -> Self { - self.centers = Some(centers.into_iter().map(Into::into).collect()); + self.centers = try_serialize_field(Self::descriptor_centers(), centers); self } @@ -602,8 +530,10 @@ impl Ellipsoids3D { Item = impl Into, >, ) -> Self { - self.rotation_axis_angles = - Some(rotation_axis_angles.into_iter().map(Into::into).collect()); + self.rotation_axis_angles = try_serialize_field( + Self::descriptor_rotation_axis_angles(), + rotation_axis_angles, + ); self } @@ -616,7 +546,7 @@ impl Ellipsoids3D { mut self, quaternions: impl IntoIterator>, ) -> Self { - self.quaternions = Some(quaternions.into_iter().map(Into::into).collect()); + self.quaternions = try_serialize_field(Self::descriptor_quaternions(), quaternions); self } @@ -626,7 +556,7 @@ impl Ellipsoids3D { 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 } @@ -636,14 +566,14 @@ impl Ellipsoids3D { mut self, line_radii: impl IntoIterator>, ) -> Self { - self.line_radii = Some(line_radii.into_iter().map(Into::into).collect()); + self.line_radii = try_serialize_field(Self::descriptor_line_radii(), line_radii); self } /// Optionally choose whether the ellipsoids are drawn with lines or solid. #[inline] pub fn with_fill_mode(mut self, fill_mode: impl Into) -> Self { - self.fill_mode = Some(fill_mode.into()); + self.fill_mode = try_serialize_field(Self::descriptor_fill_mode(), [fill_mode]); self } @@ -653,7 +583,7 @@ impl Ellipsoids3D { 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 } @@ -663,7 +593,7 @@ impl Ellipsoids3D { 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 } @@ -675,7 +605,7 @@ impl Ellipsoids3D { 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 } } @@ -694,18 +624,4 @@ impl ::re_byte_size::SizeBytes for Ellipsoids3D { + 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() - && >::is_pod() - && >>::is_pod() - && >::is_pod() - && >>::is_pod() - } } diff --git a/crates/store/re_types/src/archetypes/encoded_image.rs b/crates/store/re_types/src/archetypes/encoded_image.rs index 8dfd575a277f..8c06b552f1ce 100644 --- a/crates/store/re_types/src/archetypes/encoded_image.rs +++ b/crates/store/re_types/src/archetypes/encoded_image.rs @@ -40,10 +40,10 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; /// Ok(()) /// } /// ``` -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Default)] pub struct EncodedImage { /// The encoded content of some image file, e.g. a PNG or JPEG. - pub blob: crate::components::Blob, + pub blob: Option, /// The Media Type of the asset. /// @@ -53,17 +53,17 @@ pub struct EncodedImage { /// /// If omitted, the viewer will try to guess from the data blob. /// If it cannot guess, it won't be able to render the asset. - pub media_type: Option, + pub media_type: Option, /// Opacity of the image, useful for layering several images. /// /// Defaults to 1.0 (fully opaque). - pub opacity: Option, + pub opacity: Option, /// An optional floating point value that specifies the 2D drawing order. /// /// Objects with higher values are drawn on top of those with lower values. - pub draw_order: Option, + pub draw_order: Option, } impl EncodedImage { @@ -202,46 +202,22 @@ impl ::re_types_core::Archetype for EncodedImage { 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 blob = { - let array = arrays_by_descr - .get(&Self::descriptor_blob()) - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.EncodedImage#blob")?; - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.EncodedImage#blob")? - .into_iter() - .next() - .flatten() - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.EncodedImage#blob")? - }; - let media_type = if let Some(array) = arrays_by_descr.get(&Self::descriptor_media_type()) { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.EncodedImage#media_type")? - .into_iter() - .next() - .flatten() - } else { - None - }; - let opacity = if let Some(array) = arrays_by_descr.get(&Self::descriptor_opacity()) { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.EncodedImage#opacity")? - .into_iter() - .next() - .flatten() - } else { - None - }; - let draw_order = if let Some(array) = arrays_by_descr.get(&Self::descriptor_draw_order()) { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.EncodedImage#draw_order")? - .into_iter() - .next() - .flatten() - } else { - None - }; + let blob = arrays_by_descr + .get(&Self::descriptor_blob()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_blob())); + let media_type = arrays_by_descr + .get(&Self::descriptor_media_type()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_media_type()) + }); + let opacity = arrays_by_descr + .get(&Self::descriptor_opacity()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_opacity())); + let draw_order = arrays_by_descr + .get(&Self::descriptor_draw_order()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_draw_order()) + }); Ok(Self { blob, media_type, @@ -252,41 +228,15 @@ impl ::re_types_core::Archetype for EncodedImage { } impl ::re_types_core::AsComponents for EncodedImage { - 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.blob as &dyn ComponentBatch)).map(|batch| { - ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_blob()), - } - }), - (self - .media_type - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_media_type()), - }), - (self - .opacity - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_opacity()), - }), - (self - .draw_order - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_draw_order()), - }), + Self::indicator().serialized(), + self.blob.clone(), + self.media_type.clone(), + self.opacity.clone(), + self.draw_order.clone(), ] .into_iter() .flatten() @@ -301,13 +251,50 @@ impl EncodedImage { #[inline] pub fn new(blob: impl Into) -> Self { Self { - blob: blob.into(), + blob: try_serialize_field(Self::descriptor_blob(), [blob]), media_type: None, opacity: None, draw_order: None, } } + /// Update only some specific fields of a `EncodedImage`. + #[inline] + pub fn update_fields() -> Self { + Self::default() + } + + /// Clear all the fields of a `EncodedImage`. + #[inline] + pub fn clear_fields() -> Self { + use ::re_types_core::Loggable as _; + Self { + blob: Some(SerializedComponentBatch::new( + crate::components::Blob::arrow_empty(), + Self::descriptor_blob(), + )), + media_type: Some(SerializedComponentBatch::new( + crate::components::MediaType::arrow_empty(), + Self::descriptor_media_type(), + )), + opacity: Some(SerializedComponentBatch::new( + crate::components::Opacity::arrow_empty(), + Self::descriptor_opacity(), + )), + draw_order: Some(SerializedComponentBatch::new( + crate::components::DrawOrder::arrow_empty(), + Self::descriptor_draw_order(), + )), + } + } + + /// The encoded content of some image file, e.g. a PNG or JPEG. + #[inline] + pub fn with_blob(mut self, blob: impl Into) -> Self { + self.blob = try_serialize_field(Self::descriptor_blob(), [blob]); + self + } + /// The Media Type of the asset. /// /// Supported values: @@ -318,7 +305,7 @@ impl EncodedImage { /// If it cannot guess, it won't be able to render the asset. #[inline] pub fn with_media_type(mut self, media_type: impl Into) -> Self { - self.media_type = Some(media_type.into()); + self.media_type = try_serialize_field(Self::descriptor_media_type(), [media_type]); self } @@ -327,7 +314,7 @@ impl EncodedImage { /// Defaults to 1.0 (fully opaque). #[inline] pub fn with_opacity(mut self, opacity: impl Into) -> Self { - self.opacity = Some(opacity.into()); + self.opacity = try_serialize_field(Self::descriptor_opacity(), [opacity]); self } @@ -336,7 +323,7 @@ impl EncodedImage { /// Objects with higher values are drawn on top of those with lower values. #[inline] pub fn with_draw_order(mut self, draw_order: impl Into) -> Self { - self.draw_order = Some(draw_order.into()); + self.draw_order = try_serialize_field(Self::descriptor_draw_order(), [draw_order]); self } } @@ -349,12 +336,4 @@ impl ::re_byte_size::SizeBytes for EncodedImage { + self.opacity.heap_size_bytes() + self.draw_order.heap_size_bytes() } - - #[inline] - fn is_pod() -> bool { - ::is_pod() - && >::is_pod() - && >::is_pod() - && >::is_pod() - } } diff --git a/crates/store/re_types/src/archetypes/encoded_image_ext.rs b/crates/store/re_types/src/archetypes/encoded_image_ext.rs index 09b37ad36ced..409c4411e189 100644 --- a/crates/store/re_types/src/archetypes/encoded_image_ext.rs +++ b/crates/store/re_types/src/archetypes/encoded_image_ext.rs @@ -1,5 +1,3 @@ -use crate::components::Blob; - use super::EncodedImage; impl EncodedImage { @@ -20,14 +18,16 @@ impl EncodedImage { /// /// [`Self::media_type`] will be guessed from the bytes. pub fn from_file_contents(bytes: Vec) -> Self { - #[allow(clippy::unnecessary_struct_initialization)] - Self { - #[cfg(feature = "image")] - media_type: image::guess_format(&bytes) + #[cfg(feature = "image")] + { + if let Some(media_type) = image::guess_format(&bytes) .ok() - .map(|format| crate::components::MediaType::from(format.to_mime_type())), - - ..Self::new(Blob::from(bytes)) + .map(|format| crate::components::MediaType::from(format.to_mime_type())) + { + return Self::new(bytes).with_media_type(media_type); + } } + + Self::new(bytes) } } diff --git a/crates/store/re_types/src/archetypes/geo_line_strings.rs b/crates/store/re_types/src/archetypes/geo_line_strings.rs index 58109147e0bc..a7159b1232ca 100644 --- a/crates/store/re_types/src/archetypes/geo_line_strings.rs +++ b/crates/store/re_types/src/archetypes/geo_line_strings.rs @@ -54,19 +54,19 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; /// /// /// -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Default)] pub struct GeoLineStrings { /// The line strings, expressed in [EPSG:4326](https://epsg.io/4326) coordinates (North/East-positive degrees). - pub line_strings: Vec, + pub line_strings: Option, /// Optional radii for the line strings. /// /// *Note*: scene units radiii are interpreted as meters. Currently, the display scale only considers the latitude of /// the first vertex of each line string (see [this issue](https://github.com/rerun-io/rerun/issues/8013)). - pub radii: Option>, + pub radii: Option, /// Optional colors for the line strings. - pub colors: Option>, + pub colors: Option, } impl GeoLineStrings { @@ -190,42 +190,17 @@ impl ::re_types_core::Archetype for GeoLineStrings { 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 line_strings = { - let array = arrays_by_descr - .get(&Self::descriptor_line_strings()) - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.GeoLineStrings#line_strings")?; - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.GeoLineStrings#line_strings")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.GeoLineStrings#line_strings")? - }; - let radii = if let Some(array) = arrays_by_descr.get(&Self::descriptor_radii()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.GeoLineStrings#radii")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.GeoLineStrings#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.GeoLineStrings#colors")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.GeoLineStrings#colors")? - }) - } else { - None - }; + let line_strings = arrays_by_descr + .get(&Self::descriptor_line_strings()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_line_strings()) + }); + 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())); Ok(Self { line_strings, radii, @@ -235,33 +210,14 @@ impl ::re_types_core::Archetype for GeoLineStrings { } impl ::re_types_core::AsComponents for GeoLineStrings { - 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.line_strings as &dyn ComponentBatch)).map(|batch| { - ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_line_strings()), - } - }), - (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::indicator().serialized(), + self.line_strings.clone(), + self.radii.clone(), + self.colors.clone(), ] .into_iter() .flatten() @@ -278,12 +234,48 @@ impl GeoLineStrings { line_strings: impl IntoIterator>, ) -> Self { Self { - line_strings: line_strings.into_iter().map(Into::into).collect(), + line_strings: try_serialize_field(Self::descriptor_line_strings(), line_strings), radii: None, colors: None, } } + /// Update only some specific fields of a `GeoLineStrings`. + #[inline] + pub fn update_fields() -> Self { + Self::default() + } + + /// Clear all the fields of a `GeoLineStrings`. + #[inline] + pub fn clear_fields() -> Self { + use ::re_types_core::Loggable as _; + Self { + line_strings: Some(SerializedComponentBatch::new( + crate::components::GeoLineString::arrow_empty(), + Self::descriptor_line_strings(), + )), + radii: Some(SerializedComponentBatch::new( + crate::components::Radius::arrow_empty(), + Self::descriptor_radii(), + )), + colors: Some(SerializedComponentBatch::new( + crate::components::Color::arrow_empty(), + Self::descriptor_colors(), + )), + } + } + + /// The line strings, expressed in [EPSG:4326](https://epsg.io/4326) coordinates (North/East-positive degrees). + #[inline] + pub fn with_line_strings( + mut self, + line_strings: impl IntoIterator>, + ) -> Self { + self.line_strings = try_serialize_field(Self::descriptor_line_strings(), line_strings); + self + } + /// Optional radii for the line strings. /// /// *Note*: scene units radiii are interpreted as meters. Currently, the display scale only considers the latitude of @@ -293,7 +285,7 @@ impl GeoLineStrings { 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 } @@ -303,7 +295,7 @@ impl GeoLineStrings { 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 } } @@ -315,11 +307,4 @@ impl ::re_byte_size::SizeBytes for GeoLineStrings { + self.radii.heap_size_bytes() + self.colors.heap_size_bytes() } - - #[inline] - fn is_pod() -> bool { - >::is_pod() - && >>::is_pod() - && >>::is_pod() - } } diff --git a/crates/store/re_types/src/archetypes/geo_points.rs b/crates/store/re_types/src/archetypes/geo_points.rs index 44dfd2581e17..9f6a0f585749 100644 --- a/crates/store/re_types/src/archetypes/geo_points.rs +++ b/crates/store/re_types/src/archetypes/geo_points.rs @@ -46,23 +46,23 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; /// /// /// -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Default)] pub struct GeoPoints { /// The [EPSG:4326](https://epsg.io/4326) coordinates for the points (North/East-positive degrees). - pub positions: Vec, + pub positions: Option, /// Optional radii for the points, effectively turning them into circles. /// /// *Note*: scene units radiii are interpreted as meters. - pub radii: Option>, + pub radii: Option, /// Optional colors for the points. - pub colors: Option>, + pub colors: Option, /// Optional class Ids for the points. /// /// The [`components::ClassId`][crate::components::ClassId] provides colors if not specified explicitly. - pub class_ids: Option>, + pub class_ids: Option, } impl GeoPoints { @@ -197,54 +197,22 @@ impl ::re_types_core::Archetype for GeoPoints { 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 positions = { - let array = arrays_by_descr - .get(&Self::descriptor_positions()) - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.GeoPoints#positions")?; - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.GeoPoints#positions")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.GeoPoints#positions")? - }; - let radii = if let Some(array) = arrays_by_descr.get(&Self::descriptor_radii()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.GeoPoints#radii")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.GeoPoints#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.GeoPoints#colors")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.GeoPoints#colors")? - }) - } 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.GeoPoints#class_ids")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.GeoPoints#class_ids")? - }) - } else { - None - }; + let positions = arrays_by_descr + .get(&Self::descriptor_positions()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_positions()) + }); + 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 class_ids = arrays_by_descr + .get(&Self::descriptor_class_ids()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_class_ids()) + }); Ok(Self { positions, radii, @@ -255,41 +223,15 @@ impl ::re_types_core::Archetype for GeoPoints { } impl ::re_types_core::AsComponents for GeoPoints { - 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.positions as &dyn ComponentBatch)).map(|batch| { - ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_positions()), - } - }), - (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 - .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.positions.clone(), + self.radii.clone(), + self.colors.clone(), + self.class_ids.clone(), ] .into_iter() .flatten() @@ -306,13 +248,53 @@ impl GeoPoints { positions: impl IntoIterator>, ) -> Self { Self { - positions: positions.into_iter().map(Into::into).collect(), + positions: try_serialize_field(Self::descriptor_positions(), positions), radii: None, colors: None, class_ids: None, } } + /// Update only some specific fields of a `GeoPoints`. + #[inline] + pub fn update_fields() -> Self { + Self::default() + } + + /// Clear all the fields of a `GeoPoints`. + #[inline] + pub fn clear_fields() -> Self { + use ::re_types_core::Loggable as _; + Self { + positions: Some(SerializedComponentBatch::new( + crate::components::LatLon::arrow_empty(), + Self::descriptor_positions(), + )), + radii: Some(SerializedComponentBatch::new( + crate::components::Radius::arrow_empty(), + Self::descriptor_radii(), + )), + colors: Some(SerializedComponentBatch::new( + crate::components::Color::arrow_empty(), + Self::descriptor_colors(), + )), + class_ids: Some(SerializedComponentBatch::new( + crate::components::ClassId::arrow_empty(), + Self::descriptor_class_ids(), + )), + } + } + + /// The [EPSG:4326](https://epsg.io/4326) coordinates for the points (North/East-positive degrees). + #[inline] + pub fn with_positions( + mut self, + positions: impl IntoIterator>, + ) -> Self { + self.positions = try_serialize_field(Self::descriptor_positions(), positions); + self + } + /// Optional radii for the points, effectively turning them into circles. /// /// *Note*: scene units radiii are interpreted as meters. @@ -321,7 +303,7 @@ impl GeoPoints { 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 } @@ -331,7 +313,7 @@ impl GeoPoints { 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 } @@ -343,7 +325,7 @@ impl GeoPoints { 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 } } @@ -356,12 +338,4 @@ impl ::re_byte_size::SizeBytes for GeoPoints { + self.colors.heap_size_bytes() + self.class_ids.heap_size_bytes() } - - #[inline] - fn is_pod() -> bool { - >::is_pod() - && >>::is_pod() - && >>::is_pod() - && >>::is_pod() - } } diff --git a/crates/store/re_types/src/archetypes/graph_edges.rs b/crates/store/re_types/src/archetypes/graph_edges.rs index a3b74d6e0c45..7ebf59ec2f30 100644 --- a/crates/store/re_types/src/archetypes/graph_edges.rs +++ b/crates/store/re_types/src/archetypes/graph_edges.rs @@ -51,15 +51,15 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; /// /// /// -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Default)] pub struct GraphEdges { /// A list of node tuples. - pub edges: Vec, + pub edges: Option, /// Specifies if the graph is directed or undirected. /// /// If no [`components::GraphType`][crate::components::GraphType] is provided, the graph is assumed to be undirected. - pub graph_type: Option, + pub graph_type: Option, } impl GraphEdges { @@ -171,51 +171,26 @@ impl ::re_types_core::Archetype for GraphEdges { 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 edges = { - let array = arrays_by_descr - .get(&Self::descriptor_edges()) - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.GraphEdges#edges")?; - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.GraphEdges#edges")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.GraphEdges#edges")? - }; - let graph_type = if let Some(array) = arrays_by_descr.get(&Self::descriptor_graph_type()) { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.GraphEdges#graph_type")? - .into_iter() - .next() - .flatten() - } else { - None - }; + let edges = arrays_by_descr + .get(&Self::descriptor_edges()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_edges())); + let graph_type = arrays_by_descr + .get(&Self::descriptor_graph_type()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_graph_type()) + }); Ok(Self { edges, graph_type }) } } impl ::re_types_core::AsComponents for GraphEdges { - 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.edges as &dyn ComponentBatch)).map(|batch| { - ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_edges()), - } - }), - (self - .graph_type - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_graph_type()), - }), + Self::indicator().serialized(), + self.edges.clone(), + self.graph_type.clone(), ] .into_iter() .flatten() @@ -230,17 +205,49 @@ impl GraphEdges { #[inline] pub fn new(edges: impl IntoIterator>) -> Self { Self { - edges: edges.into_iter().map(Into::into).collect(), + edges: try_serialize_field(Self::descriptor_edges(), edges), graph_type: None, } } + /// Update only some specific fields of a `GraphEdges`. + #[inline] + pub fn update_fields() -> Self { + Self::default() + } + + /// Clear all the fields of a `GraphEdges`. + #[inline] + pub fn clear_fields() -> Self { + use ::re_types_core::Loggable as _; + Self { + edges: Some(SerializedComponentBatch::new( + crate::components::GraphEdge::arrow_empty(), + Self::descriptor_edges(), + )), + graph_type: Some(SerializedComponentBatch::new( + crate::components::GraphType::arrow_empty(), + Self::descriptor_graph_type(), + )), + } + } + + /// A list of node tuples. + #[inline] + pub fn with_edges( + mut self, + edges: impl IntoIterator>, + ) -> Self { + self.edges = try_serialize_field(Self::descriptor_edges(), edges); + self + } + /// Specifies if the graph is directed or undirected. /// /// If no [`components::GraphType`][crate::components::GraphType] is provided, the graph is assumed to be undirected. #[inline] pub fn with_graph_type(mut self, graph_type: impl Into) -> Self { - self.graph_type = Some(graph_type.into()); + self.graph_type = try_serialize_field(Self::descriptor_graph_type(), [graph_type]); self } } @@ -250,10 +257,4 @@ impl ::re_byte_size::SizeBytes for GraphEdges { fn heap_size_bytes(&self) -> u64 { self.edges.heap_size_bytes() + self.graph_type.heap_size_bytes() } - - #[inline] - fn is_pod() -> bool { - >::is_pod() - && >::is_pod() - } } diff --git a/crates/store/re_types/src/archetypes/graph_edges_ext.rs b/crates/store/re_types/src/archetypes/graph_edges_ext.rs index 9e97e0797882..f77ef05d3ada 100644 --- a/crates/store/re_types/src/archetypes/graph_edges_ext.rs +++ b/crates/store/re_types/src/archetypes/graph_edges_ext.rs @@ -3,15 +3,13 @@ use super::GraphEdges; impl GraphEdges { /// Creates a graph with undirected edges. #[inline(always)] - pub fn with_undirected_edges(mut self) -> Self { - self.graph_type = Some(crate::components::GraphType::Undirected); - self + pub fn with_undirected_edges(self) -> Self { + self.with_graph_type(crate::components::GraphType::Undirected) } /// Creates a graph with directed edges. #[inline(always)] - pub fn with_directed_edges(mut self) -> Self { - self.graph_type = Some(crate::components::GraphType::Directed); - self + pub fn with_directed_edges(self) -> Self { + self.with_graph_type(crate::components::GraphType::Directed) } } diff --git a/crates/store/re_types/src/archetypes/graph_nodes.rs b/crates/store/re_types/src/archetypes/graph_nodes.rs index 615538403848..59a9b48ed87e 100644 --- a/crates/store/re_types/src/archetypes/graph_nodes.rs +++ b/crates/store/re_types/src/archetypes/graph_nodes.rs @@ -49,25 +49,25 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; /// /// /// -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Default)] pub struct GraphNodes { /// A list of node IDs. - pub node_ids: Vec, + pub node_ids: Option, /// Optional center positions of the nodes. - pub positions: Option>, + pub positions: Option, /// Optional colors for the boxes. - pub colors: Option>, + pub colors: Option, /// Optional text labels for the node. - 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 radii for nodes. - pub radii: Option>, + pub radii: Option, } impl GraphNodes { @@ -226,76 +226,28 @@ impl ::re_types_core::Archetype for GraphNodes { 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 node_ids = { - let array = arrays_by_descr - .get(&Self::descriptor_node_ids()) - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.GraphNodes#node_ids")?; - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.GraphNodes#node_ids")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.GraphNodes#node_ids")? - }; - let positions = if let Some(array) = arrays_by_descr.get(&Self::descriptor_positions()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.GraphNodes#positions")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.GraphNodes#positions")? - }) - } else { - None - }; - let colors = if let Some(array) = arrays_by_descr.get(&Self::descriptor_colors()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.GraphNodes#colors")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.GraphNodes#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.GraphNodes#labels")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.GraphNodes#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.GraphNodes#show_labels")? - .into_iter() - .next() - .flatten() - } else { - None - }; - let radii = if let Some(array) = arrays_by_descr.get(&Self::descriptor_radii()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.GraphNodes#radii")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.GraphNodes#radii")? - }) - } else { - None - }; + let node_ids = arrays_by_descr + .get(&Self::descriptor_node_ids()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_node_ids())); + let positions = arrays_by_descr + .get(&Self::descriptor_positions()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_positions()) + }); + 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 radii = arrays_by_descr + .get(&Self::descriptor_radii()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_radii())); Ok(Self { node_ids, positions, @@ -308,57 +260,17 @@ impl ::re_types_core::Archetype for GraphNodes { } impl ::re_types_core::AsComponents for GraphNodes { - 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.node_ids as &dyn ComponentBatch)).map(|batch| { - ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_node_ids()), - } - }), - (self - .positions - .as_ref() - .map(|comp_batch| (comp_batch as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_positions()), - }), - (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 - .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::indicator().serialized(), + self.node_ids.clone(), + self.positions.clone(), + self.colors.clone(), + self.labels.clone(), + self.show_labels.clone(), + self.radii.clone(), ] .into_iter() .flatten() @@ -375,7 +287,7 @@ impl GraphNodes { node_ids: impl IntoIterator>, ) -> Self { Self { - node_ids: node_ids.into_iter().map(Into::into).collect(), + node_ids: try_serialize_field(Self::descriptor_node_ids(), node_ids), positions: None, colors: None, labels: None, @@ -384,13 +296,61 @@ impl GraphNodes { } } + /// Update only some specific fields of a `GraphNodes`. + #[inline] + pub fn update_fields() -> Self { + Self::default() + } + + /// Clear all the fields of a `GraphNodes`. + #[inline] + pub fn clear_fields() -> Self { + use ::re_types_core::Loggable as _; + Self { + node_ids: Some(SerializedComponentBatch::new( + crate::components::GraphNode::arrow_empty(), + Self::descriptor_node_ids(), + )), + positions: Some(SerializedComponentBatch::new( + crate::components::Position2D::arrow_empty(), + Self::descriptor_positions(), + )), + 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(), + )), + radii: Some(SerializedComponentBatch::new( + crate::components::Radius::arrow_empty(), + Self::descriptor_radii(), + )), + } + } + + /// A list of node IDs. + #[inline] + pub fn with_node_ids( + mut self, + node_ids: impl IntoIterator>, + ) -> Self { + self.node_ids = try_serialize_field(Self::descriptor_node_ids(), node_ids); + self + } + /// Optional center positions of the nodes. #[inline] pub fn with_positions( mut self, positions: impl IntoIterator>, ) -> Self { - self.positions = Some(positions.into_iter().map(Into::into).collect()); + self.positions = try_serialize_field(Self::descriptor_positions(), positions); self } @@ -400,7 +360,7 @@ impl GraphNodes { 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 } @@ -410,7 +370,7 @@ impl GraphNodes { 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 } @@ -420,7 +380,7 @@ impl GraphNodes { 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 } @@ -430,7 +390,7 @@ impl GraphNodes { 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 } } @@ -445,14 +405,4 @@ impl ::re_byte_size::SizeBytes for GraphNodes { + self.show_labels.heap_size_bytes() + self.radii.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/src/archetypes/instance_poses3d.rs b/crates/store/re_types/src/archetypes/instance_poses3d.rs index daf9df5a9dc9..a019a9c1cc1b 100644 --- a/crates/store/re_types/src/archetypes/instance_poses3d.rs +++ b/crates/store/re_types/src/archetypes/instance_poses3d.rs @@ -90,22 +90,22 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; /// /// /// -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Default)] pub struct InstancePoses3D { /// Translation vectors. - pub translations: Option>, + pub translations: Option, /// Rotations via axis + angle. - pub rotation_axis_angles: Option>, + pub rotation_axis_angles: Option, /// Rotations via quaternion. - pub quaternions: Option>, + pub quaternions: Option, /// Scaling factors. - pub scales: Option>, + pub scales: Option, /// 3x3 transformation matrices. - pub mat3x3: Option>, + pub mat3x3: Option, } impl InstancePoses3D { @@ -253,69 +253,30 @@ impl ::re_types_core::Archetype for InstancePoses3D { 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 translations = - if let Some(array) = arrays_by_descr.get(&Self::descriptor_translations()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.InstancePoses3D#translations")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.InstancePoses3D#translations")? - }) - } else { - None - }; - let rotation_axis_angles = - if let Some(array) = arrays_by_descr.get(&Self::descriptor_rotation_axis_angles()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.InstancePoses3D#rotation_axis_angles")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.InstancePoses3D#rotation_axis_angles")? - }) - } else { - None - }; - let quaternions = if let Some(array) = arrays_by_descr.get(&Self::descriptor_quaternions()) - { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.InstancePoses3D#quaternions")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.InstancePoses3D#quaternions")? - }) - } else { - None - }; - let scales = if let Some(array) = arrays_by_descr.get(&Self::descriptor_scales()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.InstancePoses3D#scales")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.InstancePoses3D#scales")? - }) - } else { - None - }; - let mat3x3 = if let Some(array) = arrays_by_descr.get(&Self::descriptor_mat3x3()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.InstancePoses3D#mat3x3")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.InstancePoses3D#mat3x3")? - }) - } else { - None - }; + let translations = arrays_by_descr + .get(&Self::descriptor_translations()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_translations()) + }); + let rotation_axis_angles = arrays_by_descr + .get(&Self::descriptor_rotation_axis_angles()) + .map(|array| { + SerializedComponentBatch::new( + array.clone(), + Self::descriptor_rotation_axis_angles(), + ) + }); + let quaternions = arrays_by_descr + .get(&Self::descriptor_quaternions()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_quaternions()) + }); + let scales = arrays_by_descr + .get(&Self::descriptor_scales()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_scales())); + let mat3x3 = arrays_by_descr + .get(&Self::descriptor_mat3x3()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_mat3x3())); Ok(Self { translations, rotation_axis_angles, @@ -327,51 +288,16 @@ impl ::re_types_core::Archetype for InstancePoses3D { } impl ::re_types_core::AsComponents for InstancePoses3D { - 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()), - (self - .translations - .as_ref() - .map(|comp_batch| (comp_batch as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_translations()), - }), - (self - .rotation_axis_angles - .as_ref() - .map(|comp_batch| (comp_batch as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_rotation_axis_angles()), - }), - (self - .quaternions - .as_ref() - .map(|comp_batch| (comp_batch as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_quaternions()), - }), - (self - .scales - .as_ref() - .map(|comp_batch| (comp_batch as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_scales()), - }), - (self - .mat3x3 - .as_ref() - .map(|comp_batch| (comp_batch as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_mat3x3()), - }), + Self::indicator().serialized(), + self.translations.clone(), + self.rotation_axis_angles.clone(), + self.quaternions.clone(), + self.scales.clone(), + self.mat3x3.clone(), ] .into_iter() .flatten() @@ -394,13 +320,47 @@ impl InstancePoses3D { } } + /// Update only some specific fields of a `InstancePoses3D`. + #[inline] + pub fn update_fields() -> Self { + Self::default() + } + + /// Clear all the fields of a `InstancePoses3D`. + #[inline] + pub fn clear_fields() -> Self { + use ::re_types_core::Loggable as _; + Self { + translations: Some(SerializedComponentBatch::new( + crate::components::PoseTranslation3D::arrow_empty(), + Self::descriptor_translations(), + )), + rotation_axis_angles: Some(SerializedComponentBatch::new( + crate::components::PoseRotationAxisAngle::arrow_empty(), + Self::descriptor_rotation_axis_angles(), + )), + quaternions: Some(SerializedComponentBatch::new( + crate::components::PoseRotationQuat::arrow_empty(), + Self::descriptor_quaternions(), + )), + scales: Some(SerializedComponentBatch::new( + crate::components::PoseScale3D::arrow_empty(), + Self::descriptor_scales(), + )), + mat3x3: Some(SerializedComponentBatch::new( + crate::components::PoseTransformMat3x3::arrow_empty(), + Self::descriptor_mat3x3(), + )), + } + } + /// Translation vectors. #[inline] pub fn with_translations( mut self, translations: impl IntoIterator>, ) -> Self { - self.translations = Some(translations.into_iter().map(Into::into).collect()); + self.translations = try_serialize_field(Self::descriptor_translations(), translations); self } @@ -412,8 +372,10 @@ impl InstancePoses3D { Item = impl Into, >, ) -> Self { - self.rotation_axis_angles = - Some(rotation_axis_angles.into_iter().map(Into::into).collect()); + self.rotation_axis_angles = try_serialize_field( + Self::descriptor_rotation_axis_angles(), + rotation_axis_angles, + ); self } @@ -423,7 +385,7 @@ impl InstancePoses3D { mut self, quaternions: impl IntoIterator>, ) -> Self { - self.quaternions = Some(quaternions.into_iter().map(Into::into).collect()); + self.quaternions = try_serialize_field(Self::descriptor_quaternions(), quaternions); self } @@ -433,7 +395,7 @@ impl InstancePoses3D { mut self, scales: impl IntoIterator>, ) -> Self { - self.scales = Some(scales.into_iter().map(Into::into).collect()); + self.scales = try_serialize_field(Self::descriptor_scales(), scales); self } @@ -443,7 +405,7 @@ impl InstancePoses3D { mut self, mat3x3: impl IntoIterator>, ) -> Self { - self.mat3x3 = Some(mat3x3.into_iter().map(Into::into).collect()); + self.mat3x3 = try_serialize_field(Self::descriptor_mat3x3(), mat3x3); self } } @@ -457,13 +419,4 @@ impl ::re_byte_size::SizeBytes for InstancePoses3D { + self.scales.heap_size_bytes() + self.mat3x3.heap_size_bytes() } - - #[inline] - fn is_pod() -> bool { - >>::is_pod() - && >>::is_pod() - && >>::is_pod() - && >>::is_pod() - && >>::is_pod() - } } diff --git a/crates/store/re_types/src/archetypes/points2d.rs b/crates/store/re_types/src/archetypes/points2d.rs index ff673182bf6a..54a4cf25b289 100644 --- a/crates/store/re_types/src/archetypes/points2d.rs +++ b/crates/store/re_types/src/archetypes/points2d.rs @@ -96,35 +96,35 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; /// /// /// -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Default)] pub struct Points2D { /// All the 2D positions at which the point cloud shows points. - pub positions: Vec, + pub positions: Option, /// Optional radii for the points, effectively turning them into circles. - pub radii: Option>, + pub radii: Option, /// Optional colors for the points. - pub colors: Option>, + pub colors: Option, /// Optional text labels for the points. /// /// 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, /// An optional floating point value that specifies the 2D drawing order. /// /// Objects with higher values are drawn on top of those with lower values. - pub draw_order: Option, + pub draw_order: Option, /// Optional class Ids for the points. /// /// The [`components::ClassId`][crate::components::ClassId] provides colors and labels if not specified explicitly. - pub class_ids: Option>, + pub class_ids: Option, /// Optional keypoint IDs for the points, identifying them within a class. /// @@ -134,7 +134,7 @@ pub struct Points2D { /// with `class_id`). /// E.g. the classification might be 'Person' and the keypoints refer to joints on a /// detected skeleton. - pub keypoint_ids: Option>, + pub keypoint_ids: Option, } impl Points2D { @@ -321,98 +321,40 @@ impl ::re_types_core::Archetype for Points2D { 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 positions = { - let array = arrays_by_descr - .get(&Self::descriptor_positions()) - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.Points2D#positions")?; - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Points2D#positions")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Points2D#positions")? - }; - let radii = if let Some(array) = arrays_by_descr.get(&Self::descriptor_radii()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Points2D#radii")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Points2D#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.Points2D#colors")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Points2D#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.Points2D#labels")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Points2D#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.Points2D#show_labels")? - .into_iter() - .next() - .flatten() - } else { - None - }; - let draw_order = if let Some(array) = arrays_by_descr.get(&Self::descriptor_draw_order()) { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Points2D#draw_order")? - .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.Points2D#class_ids")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Points2D#class_ids")? - }) - } else { - None - }; - let keypoint_ids = - if let Some(array) = arrays_by_descr.get(&Self::descriptor_keypoint_ids()) { - Some({ - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Points2D#keypoint_ids")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.archetypes.Points2D#keypoint_ids")? - }) - } else { - None - }; + let positions = arrays_by_descr + .get(&Self::descriptor_positions()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_positions()) + }); + 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 draw_order = arrays_by_descr + .get(&Self::descriptor_draw_order()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_draw_order()) + }); + let class_ids = arrays_by_descr + .get(&Self::descriptor_class_ids()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_class_ids()) + }); + let keypoint_ids = arrays_by_descr + .get(&Self::descriptor_keypoint_ids()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_keypoint_ids()) + }); Ok(Self { positions, radii, @@ -427,73 +369,19 @@ impl ::re_types_core::Archetype for Points2D { } impl ::re_types_core::AsComponents for Points2D { - 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.positions as &dyn ComponentBatch)).map(|batch| { - ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_positions()), - } - }), - (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 - .draw_order - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_draw_order()), - }), - (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 - .keypoint_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_keypoint_ids()), - }), + Self::indicator().serialized(), + self.positions.clone(), + self.radii.clone(), + self.colors.clone(), + self.labels.clone(), + self.show_labels.clone(), + self.draw_order.clone(), + self.class_ids.clone(), + self.keypoint_ids.clone(), ] .into_iter() .flatten() @@ -510,7 +398,7 @@ impl Points2D { positions: impl IntoIterator>, ) -> Self { Self { - positions: positions.into_iter().map(Into::into).collect(), + positions: try_serialize_field(Self::descriptor_positions(), positions), radii: None, colors: None, labels: None, @@ -521,13 +409,69 @@ impl Points2D { } } + /// Update only some specific fields of a `Points2D`. + #[inline] + pub fn update_fields() -> Self { + Self::default() + } + + /// Clear all the fields of a `Points2D`. + #[inline] + pub fn clear_fields() -> Self { + use ::re_types_core::Loggable as _; + Self { + positions: Some(SerializedComponentBatch::new( + crate::components::Position2D::arrow_empty(), + Self::descriptor_positions(), + )), + 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(), + )), + draw_order: Some(SerializedComponentBatch::new( + crate::components::DrawOrder::arrow_empty(), + Self::descriptor_draw_order(), + )), + class_ids: Some(SerializedComponentBatch::new( + crate::components::ClassId::arrow_empty(), + Self::descriptor_class_ids(), + )), + keypoint_ids: Some(SerializedComponentBatch::new( + crate::components::KeypointId::arrow_empty(), + Self::descriptor_keypoint_ids(), + )), + } + } + + /// All the 2D positions at which the point cloud shows points. + #[inline] + pub fn with_positions( + mut self, + positions: impl IntoIterator>, + ) -> Self { + self.positions = try_serialize_field(Self::descriptor_positions(), positions); + self + } + /// Optional radii for the points, effectively turning them into circles. #[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 } @@ -537,7 +481,7 @@ impl Points2D { 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 } @@ -550,7 +494,7 @@ impl Points2D { 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 } @@ -560,7 +504,7 @@ impl Points2D { 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 } @@ -569,7 +513,7 @@ impl Points2D { /// Objects with higher values are drawn on top of those with lower values. #[inline] pub fn with_draw_order(mut self, draw_order: impl Into) -> Self { - self.draw_order = Some(draw_order.into()); + self.draw_order = try_serialize_field(Self::descriptor_draw_order(), [draw_order]); self } @@ -581,7 +525,7 @@ impl Points2D { 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 } @@ -598,7 +542,7 @@ impl Points2D { mut self, keypoint_ids: impl IntoIterator>, ) -> Self { - self.keypoint_ids = Some(keypoint_ids.into_iter().map(Into::into).collect()); + self.keypoint_ids = try_serialize_field(Self::descriptor_keypoint_ids(), keypoint_ids); self } } @@ -615,16 +559,4 @@ impl ::re_byte_size::SizeBytes for Points2D { + self.class_ids.heap_size_bytes() + self.keypoint_ids.heap_size_bytes() } - - #[inline] - fn is_pod() -> bool { - >::is_pod() - && >>::is_pod() - && >>::is_pod() - && >>::is_pod() - && >::is_pod() - && >::is_pod() - && >>::is_pod() - && >>::is_pod() - } } diff --git a/crates/store/re_types/src/archetypes/scalar.rs b/crates/store/re_types/src/archetypes/scalar.rs index 686aa4a106ce..9653c4d40a90 100644 --- a/crates/store/re_types/src/archetypes/scalar.rs +++ b/crates/store/re_types/src/archetypes/scalar.rs @@ -53,10 +53,10 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; /// /// /// -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Default)] pub struct Scalar { /// The scalar value to log. - pub scalar: crate::components::Scalar, + pub scalar: Option, } impl Scalar { @@ -147,39 +147,21 @@ impl ::re_types_core::Archetype for Scalar { 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 scalar = { - let array = arrays_by_descr - .get(&Self::descriptor_scalar()) - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.Scalar#scalar")?; - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Scalar#scalar")? - .into_iter() - .next() - .flatten() - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.Scalar#scalar")? - }; + let scalar = arrays_by_descr + .get(&Self::descriptor_scalar()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_scalar())); Ok(Self { scalar }) } } impl ::re_types_core::AsComponents for Scalar { - 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.scalar as &dyn ComponentBatch)).map(|batch| { - ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_scalar()), - } - }), - ] - .into_iter() - .flatten() - .collect() + [Self::indicator().serialized(), self.scalar.clone()] + .into_iter() + .flatten() + .collect() } } @@ -190,9 +172,34 @@ impl Scalar { #[inline] pub fn new(scalar: impl Into) -> Self { Self { - scalar: scalar.into(), + scalar: try_serialize_field(Self::descriptor_scalar(), [scalar]), } } + + /// Update only some specific fields of a `Scalar`. + #[inline] + pub fn update_fields() -> Self { + Self::default() + } + + /// Clear all the fields of a `Scalar`. + #[inline] + pub fn clear_fields() -> Self { + use ::re_types_core::Loggable as _; + Self { + scalar: Some(SerializedComponentBatch::new( + crate::components::Scalar::arrow_empty(), + Self::descriptor_scalar(), + )), + } + } + + /// The scalar value to log. + #[inline] + pub fn with_scalar(mut self, scalar: impl Into) -> Self { + self.scalar = try_serialize_field(Self::descriptor_scalar(), [scalar]); + self + } } impl ::re_byte_size::SizeBytes for Scalar { @@ -200,9 +207,4 @@ impl ::re_byte_size::SizeBytes for Scalar { fn heap_size_bytes(&self) -> u64 { self.scalar.heap_size_bytes() } - - #[inline] - fn is_pod() -> bool { - ::is_pod() - } } diff --git a/crates/store/re_types/src/archetypes/segmentation_image.rs b/crates/store/re_types/src/archetypes/segmentation_image.rs index 45e298b84e07..d447dccf0084 100644 --- a/crates/store/re_types/src/archetypes/segmentation_image.rs +++ b/crates/store/re_types/src/archetypes/segmentation_image.rs @@ -64,23 +64,23 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; /// /// /// -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Default)] pub struct SegmentationImage { /// The raw image data. - pub buffer: crate::components::ImageBuffer, + pub buffer: Option, /// The format of the image. - pub format: crate::components::ImageFormat, + pub format: Option, /// Opacity of the image, useful for layering the segmentation image on top of another image. /// /// Defaults to 0.5 if there's any other images in the scene, otherwise 1.0. - pub opacity: Option, + pub opacity: Option, /// An optional floating point value that specifies the 2D drawing order. /// /// Objects with higher values are drawn on top of those with lower values. - pub draw_order: Option, + pub draw_order: Option, } impl SegmentationImage { @@ -219,50 +219,20 @@ impl ::re_types_core::Archetype for SegmentationImage { 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 buffer = { - let array = arrays_by_descr - .get(&Self::descriptor_buffer()) - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.SegmentationImage#buffer")?; - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.SegmentationImage#buffer")? - .into_iter() - .next() - .flatten() - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.SegmentationImage#buffer")? - }; - let format = { - let array = arrays_by_descr - .get(&Self::descriptor_format()) - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.SegmentationImage#format")?; - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.SegmentationImage#format")? - .into_iter() - .next() - .flatten() - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.SegmentationImage#format")? - }; - let opacity = if let Some(array) = arrays_by_descr.get(&Self::descriptor_opacity()) { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.SegmentationImage#opacity")? - .into_iter() - .next() - .flatten() - } else { - None - }; - let draw_order = if let Some(array) = arrays_by_descr.get(&Self::descriptor_draw_order()) { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.SegmentationImage#draw_order")? - .into_iter() - .next() - .flatten() - } else { - None - }; + let buffer = arrays_by_descr + .get(&Self::descriptor_buffer()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_buffer())); + let format = arrays_by_descr + .get(&Self::descriptor_format()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_format())); + let opacity = arrays_by_descr + .get(&Self::descriptor_opacity()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_opacity())); + let draw_order = arrays_by_descr + .get(&Self::descriptor_draw_order()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_draw_order()) + }); Ok(Self { buffer, format, @@ -273,39 +243,15 @@ impl ::re_types_core::Archetype for SegmentationImage { } impl ::re_types_core::AsComponents for SegmentationImage { - 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.buffer as &dyn ComponentBatch)).map(|batch| { - ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_buffer()), - } - }), - (Some(&self.format as &dyn ComponentBatch)).map(|batch| { - ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_format()), - } - }), - (self - .opacity - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_opacity()), - }), - (self - .draw_order - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_draw_order()), - }), + Self::indicator().serialized(), + self.buffer.clone(), + self.format.clone(), + self.opacity.clone(), + self.draw_order.clone(), ] .into_iter() .flatten() @@ -323,19 +269,63 @@ impl SegmentationImage { format: impl Into, ) -> Self { Self { - buffer: buffer.into(), - format: format.into(), + buffer: try_serialize_field(Self::descriptor_buffer(), [buffer]), + format: try_serialize_field(Self::descriptor_format(), [format]), opacity: None, draw_order: None, } } + /// Update only some specific fields of a `SegmentationImage`. + #[inline] + pub fn update_fields() -> Self { + Self::default() + } + + /// Clear all the fields of a `SegmentationImage`. + #[inline] + pub fn clear_fields() -> Self { + use ::re_types_core::Loggable as _; + Self { + buffer: Some(SerializedComponentBatch::new( + crate::components::ImageBuffer::arrow_empty(), + Self::descriptor_buffer(), + )), + format: Some(SerializedComponentBatch::new( + crate::components::ImageFormat::arrow_empty(), + Self::descriptor_format(), + )), + opacity: Some(SerializedComponentBatch::new( + crate::components::Opacity::arrow_empty(), + Self::descriptor_opacity(), + )), + draw_order: Some(SerializedComponentBatch::new( + crate::components::DrawOrder::arrow_empty(), + Self::descriptor_draw_order(), + )), + } + } + + /// The raw image data. + #[inline] + pub fn with_buffer(mut self, buffer: impl Into) -> Self { + self.buffer = try_serialize_field(Self::descriptor_buffer(), [buffer]); + self + } + + /// The format of the image. + #[inline] + pub fn with_format(mut self, format: impl Into) -> Self { + self.format = try_serialize_field(Self::descriptor_format(), [format]); + self + } + /// Opacity of the image, useful for layering the segmentation image on top of another image. /// /// Defaults to 0.5 if there's any other images in the scene, otherwise 1.0. #[inline] pub fn with_opacity(mut self, opacity: impl Into) -> Self { - self.opacity = Some(opacity.into()); + self.opacity = try_serialize_field(Self::descriptor_opacity(), [opacity]); self } @@ -344,7 +334,7 @@ impl SegmentationImage { /// Objects with higher values are drawn on top of those with lower values. #[inline] pub fn with_draw_order(mut self, draw_order: impl Into) -> Self { - self.draw_order = Some(draw_order.into()); + self.draw_order = try_serialize_field(Self::descriptor_draw_order(), [draw_order]); self } } @@ -357,12 +347,4 @@ impl ::re_byte_size::SizeBytes for SegmentationImage { + self.opacity.heap_size_bytes() + self.draw_order.heap_size_bytes() } - - #[inline] - fn is_pod() -> bool { - ::is_pod() - && ::is_pod() - && >::is_pod() - && >::is_pod() - } } diff --git a/crates/store/re_types/src/archetypes/segmentation_image_ext.rs b/crates/store/re_types/src/archetypes/segmentation_image_ext.rs index a90856eb24d3..5a071c28335b 100644 --- a/crates/store/re_types/src/archetypes/segmentation_image_ext.rs +++ b/crates/store/re_types/src/archetypes/segmentation_image_ext.rs @@ -33,11 +33,6 @@ impl SegmentationImage { let image_format = ImageFormat::segmentation([width as _, height as _], datatype); - Ok(Self { - buffer: blob.into(), - format: image_format.into(), - draw_order: None, - opacity: None, - }) + Ok(Self::new(blob, image_format)) } } diff --git a/crates/store/re_types/src/archetypes/series_line.rs b/crates/store/re_types/src/archetypes/series_line.rs index d1c7ffda63b5..539b65bc09a2 100644 --- a/crates/store/re_types/src/archetypes/series_line.rs +++ b/crates/store/re_types/src/archetypes/series_line.rs @@ -69,25 +69,25 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; /// /// /// -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct SeriesLine { /// Color for the corresponding series. - pub color: Option, + pub color: Option, /// Stroke width for the corresponding series. - pub width: Option, + pub width: Option, /// Display name of the series. /// /// Used in the legend. - pub name: Option, + pub name: Option, /// Configures the zoom-dependent scalar aggregation. /// /// This is done only if steps on the X axis go below a single pixel, /// i.e. a single pixel covers more than one tick worth of data. It can greatly improve performance /// (and readability) in such situations as it prevents overdraw. - pub aggregation_policy: Option, + pub aggregation_policy: Option, } impl SeriesLine { @@ -223,43 +223,20 @@ impl ::re_types_core::Archetype for SeriesLine { 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 color = if let Some(array) = arrays_by_descr.get(&Self::descriptor_color()) { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.SeriesLine#color")? - .into_iter() - .next() - .flatten() - } else { - None - }; - let width = if let Some(array) = arrays_by_descr.get(&Self::descriptor_width()) { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.SeriesLine#width")? - .into_iter() - .next() - .flatten() - } else { - None - }; - let name = if let Some(array) = arrays_by_descr.get(&Self::descriptor_name()) { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.SeriesLine#name")? - .into_iter() - .next() - .flatten() - } else { - None - }; - let aggregation_policy = - if let Some(array) = arrays_by_descr.get(&Self::descriptor_aggregation_policy()) { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.SeriesLine#aggregation_policy")? - .into_iter() - .next() - .flatten() - } else { - None - }; + let color = arrays_by_descr + .get(&Self::descriptor_color()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_color())); + let width = arrays_by_descr + .get(&Self::descriptor_width()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_width())); + let name = arrays_by_descr + .get(&Self::descriptor_name()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_name())); + let aggregation_policy = arrays_by_descr + .get(&Self::descriptor_aggregation_policy()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_aggregation_policy()) + }); Ok(Self { color, width, @@ -270,41 +247,15 @@ impl ::re_types_core::Archetype for SeriesLine { } impl ::re_types_core::AsComponents for SeriesLine { - 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()), - (self - .color - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_color()), - }), - (self - .width - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_width()), - }), - (self.name.as_ref().map(|comp| (comp as &dyn ComponentBatch))).map(|batch| { - ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_name()), - } - }), - (self - .aggregation_policy - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_aggregation_policy()), - }), + Self::indicator().serialized(), + self.color.clone(), + self.width.clone(), + self.name.clone(), + self.aggregation_policy.clone(), ] .into_iter() .flatten() @@ -326,17 +277,47 @@ impl SeriesLine { } } + /// Update only some specific fields of a `SeriesLine`. + #[inline] + pub fn update_fields() -> Self { + Self::default() + } + + /// Clear all the fields of a `SeriesLine`. + #[inline] + pub fn clear_fields() -> Self { + use ::re_types_core::Loggable as _; + Self { + color: Some(SerializedComponentBatch::new( + crate::components::Color::arrow_empty(), + Self::descriptor_color(), + )), + width: Some(SerializedComponentBatch::new( + crate::components::StrokeWidth::arrow_empty(), + Self::descriptor_width(), + )), + name: Some(SerializedComponentBatch::new( + crate::components::Name::arrow_empty(), + Self::descriptor_name(), + )), + aggregation_policy: Some(SerializedComponentBatch::new( + crate::components::AggregationPolicy::arrow_empty(), + Self::descriptor_aggregation_policy(), + )), + } + } + /// Color for the corresponding series. #[inline] pub fn with_color(mut self, color: impl Into) -> Self { - self.color = Some(color.into()); + self.color = try_serialize_field(Self::descriptor_color(), [color]); self } /// Stroke width for the corresponding series. #[inline] pub fn with_width(mut self, width: impl Into) -> Self { - self.width = Some(width.into()); + self.width = try_serialize_field(Self::descriptor_width(), [width]); self } @@ -345,7 +326,7 @@ impl SeriesLine { /// Used in the legend. #[inline] pub fn with_name(mut self, name: impl Into) -> Self { - self.name = Some(name.into()); + self.name = try_serialize_field(Self::descriptor_name(), [name]); self } @@ -359,7 +340,8 @@ impl SeriesLine { mut self, aggregation_policy: impl Into, ) -> Self { - self.aggregation_policy = Some(aggregation_policy.into()); + self.aggregation_policy = + try_serialize_field(Self::descriptor_aggregation_policy(), [aggregation_policy]); self } } @@ -372,12 +354,4 @@ impl ::re_byte_size::SizeBytes for SeriesLine { + self.name.heap_size_bytes() + self.aggregation_policy.heap_size_bytes() } - - #[inline] - fn is_pod() -> bool { - >::is_pod() - && >::is_pod() - && >::is_pod() - && >::is_pod() - } } diff --git a/crates/store/re_types/src/archetypes/series_point.rs b/crates/store/re_types/src/archetypes/series_point.rs index 67dd7ff002e5..bc839b5c5c28 100644 --- a/crates/store/re_types/src/archetypes/series_point.rs +++ b/crates/store/re_types/src/archetypes/series_point.rs @@ -71,21 +71,21 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; /// /// /// -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct SeriesPoint { /// Color for the corresponding series. - pub color: Option, + pub color: Option, /// What shape to use to represent the point - pub marker: Option, + pub marker: Option, /// Display name of the series. /// /// Used in the legend. - pub name: Option, + pub name: Option, /// Size of the marker. - pub marker_size: Option, + pub marker_size: Option, } impl SeriesPoint { @@ -221,43 +221,20 @@ impl ::re_types_core::Archetype for SeriesPoint { 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 color = if let Some(array) = arrays_by_descr.get(&Self::descriptor_color()) { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.SeriesPoint#color")? - .into_iter() - .next() - .flatten() - } else { - None - }; - let marker = if let Some(array) = arrays_by_descr.get(&Self::descriptor_marker()) { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.SeriesPoint#marker")? - .into_iter() - .next() - .flatten() - } else { - None - }; - let name = if let Some(array) = arrays_by_descr.get(&Self::descriptor_name()) { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.SeriesPoint#name")? - .into_iter() - .next() - .flatten() - } else { - None - }; - let marker_size = if let Some(array) = arrays_by_descr.get(&Self::descriptor_marker_size()) - { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.SeriesPoint#marker_size")? - .into_iter() - .next() - .flatten() - } else { - None - }; + let color = arrays_by_descr + .get(&Self::descriptor_color()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_color())); + let marker = arrays_by_descr + .get(&Self::descriptor_marker()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_marker())); + let name = arrays_by_descr + .get(&Self::descriptor_name()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_name())); + let marker_size = arrays_by_descr + .get(&Self::descriptor_marker_size()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_marker_size()) + }); Ok(Self { color, marker, @@ -268,41 +245,15 @@ impl ::re_types_core::Archetype for SeriesPoint { } impl ::re_types_core::AsComponents for SeriesPoint { - 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()), - (self - .color - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_color()), - }), - (self - .marker - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_marker()), - }), - (self.name.as_ref().map(|comp| (comp as &dyn ComponentBatch))).map(|batch| { - ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_name()), - } - }), - (self - .marker_size - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_marker_size()), - }), + Self::indicator().serialized(), + self.color.clone(), + self.marker.clone(), + self.name.clone(), + self.marker_size.clone(), ] .into_iter() .flatten() @@ -324,17 +275,47 @@ impl SeriesPoint { } } + /// Update only some specific fields of a `SeriesPoint`. + #[inline] + pub fn update_fields() -> Self { + Self::default() + } + + /// Clear all the fields of a `SeriesPoint`. + #[inline] + pub fn clear_fields() -> Self { + use ::re_types_core::Loggable as _; + Self { + color: Some(SerializedComponentBatch::new( + crate::components::Color::arrow_empty(), + Self::descriptor_color(), + )), + marker: Some(SerializedComponentBatch::new( + crate::components::MarkerShape::arrow_empty(), + Self::descriptor_marker(), + )), + name: Some(SerializedComponentBatch::new( + crate::components::Name::arrow_empty(), + Self::descriptor_name(), + )), + marker_size: Some(SerializedComponentBatch::new( + crate::components::MarkerSize::arrow_empty(), + Self::descriptor_marker_size(), + )), + } + } + /// Color for the corresponding series. #[inline] pub fn with_color(mut self, color: impl Into) -> Self { - self.color = Some(color.into()); + self.color = try_serialize_field(Self::descriptor_color(), [color]); self } /// What shape to use to represent the point #[inline] pub fn with_marker(mut self, marker: impl Into) -> Self { - self.marker = Some(marker.into()); + self.marker = try_serialize_field(Self::descriptor_marker(), [marker]); self } @@ -343,7 +324,7 @@ impl SeriesPoint { /// Used in the legend. #[inline] pub fn with_name(mut self, name: impl Into) -> Self { - self.name = Some(name.into()); + self.name = try_serialize_field(Self::descriptor_name(), [name]); self } @@ -353,7 +334,7 @@ impl SeriesPoint { mut self, marker_size: impl Into, ) -> Self { - self.marker_size = Some(marker_size.into()); + self.marker_size = try_serialize_field(Self::descriptor_marker_size(), [marker_size]); self } } @@ -366,12 +347,4 @@ impl ::re_byte_size::SizeBytes for SeriesPoint { + self.name.heap_size_bytes() + self.marker_size.heap_size_bytes() } - - #[inline] - fn is_pod() -> bool { - >::is_pod() - && >::is_pod() - && >::is_pod() - && >::is_pod() - } } diff --git a/crates/store/re_types/src/archetypes/text_document.rs b/crates/store/re_types/src/archetypes/text_document.rs index e990e14407c3..e06b1347e6e5 100644 --- a/crates/store/re_types/src/archetypes/text_document.rs +++ b/crates/store/re_types/src/archetypes/text_document.rs @@ -87,10 +87,10 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; /// /// /// -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Default)] pub struct TextDocument { /// Contents of the text document. - pub text: crate::components::Text, + pub text: Option, /// The Media Type of the text. /// @@ -99,7 +99,7 @@ pub struct TextDocument { /// * `text/markdown` /// /// If omitted, `text/plain` is assumed. - pub media_type: Option, + pub media_type: Option, } impl TextDocument { @@ -206,52 +206,26 @@ impl ::re_types_core::Archetype for TextDocument { 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 text = { - let array = arrays_by_descr - .get(&Self::descriptor_text()) - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.TextDocument#text")?; - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.TextDocument#text")? - .into_iter() - .next() - .flatten() - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.TextDocument#text")? - }; - let media_type = if let Some(array) = arrays_by_descr.get(&Self::descriptor_media_type()) { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.TextDocument#media_type")? - .into_iter() - .next() - .flatten() - } else { - None - }; + let text = arrays_by_descr + .get(&Self::descriptor_text()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_text())); + let media_type = arrays_by_descr + .get(&Self::descriptor_media_type()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_media_type()) + }); Ok(Self { text, media_type }) } } impl ::re_types_core::AsComponents for TextDocument { - 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.text as &dyn ComponentBatch)).map(|batch| { - ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_text()), - } - }), - (self - .media_type - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_media_type()), - }), + Self::indicator().serialized(), + self.text.clone(), + self.media_type.clone(), ] .into_iter() .flatten() @@ -266,11 +240,40 @@ impl TextDocument { #[inline] pub fn new(text: impl Into) -> Self { Self { - text: text.into(), + text: try_serialize_field(Self::descriptor_text(), [text]), media_type: None, } } + /// Update only some specific fields of a `TextDocument`. + #[inline] + pub fn update_fields() -> Self { + Self::default() + } + + /// Clear all the fields of a `TextDocument`. + #[inline] + pub fn clear_fields() -> Self { + use ::re_types_core::Loggable as _; + Self { + text: Some(SerializedComponentBatch::new( + crate::components::Text::arrow_empty(), + Self::descriptor_text(), + )), + media_type: Some(SerializedComponentBatch::new( + crate::components::MediaType::arrow_empty(), + Self::descriptor_media_type(), + )), + } + } + + /// Contents of the text document. + #[inline] + pub fn with_text(mut self, text: impl Into) -> Self { + self.text = try_serialize_field(Self::descriptor_text(), [text]); + self + } + /// The Media Type of the text. /// /// For instance: @@ -280,7 +283,7 @@ impl TextDocument { /// If omitted, `text/plain` is assumed. #[inline] pub fn with_media_type(mut self, media_type: impl Into) -> Self { - self.media_type = Some(media_type.into()); + self.media_type = try_serialize_field(Self::descriptor_media_type(), [media_type]); self } } @@ -290,9 +293,4 @@ impl ::re_byte_size::SizeBytes for TextDocument { fn heap_size_bytes(&self) -> u64 { self.text.heap_size_bytes() + self.media_type.heap_size_bytes() } - - #[inline] - fn is_pod() -> bool { - ::is_pod() && >::is_pod() - } } diff --git a/crates/store/re_types/src/archetypes/text_document_ext.rs b/crates/store/re_types/src/archetypes/text_document_ext.rs index 891921bb9435..80bad89c7eaa 100644 --- a/crates/store/re_types/src/archetypes/text_document_ext.rs +++ b/crates/store/re_types/src/archetypes/text_document_ext.rs @@ -25,11 +25,13 @@ impl TextDocument { contents: Vec, media_type: Option>, ) -> anyhow::Result { - let media_type = media_type.map(Into::into); - let media_type = MediaType::or_guess_from_data(media_type, &contents); - Ok(Self { - text: String::from_utf8(contents)?.into(), - media_type, + let media_type = MediaType::or_guess_from_data(media_type.map(Into::into), &contents); + let result = Self::new(String::from_utf8(contents)?); + + Ok(if let Some(media_type) = media_type { + result.with_media_type(media_type) + } else { + result }) } diff --git a/crates/store/re_types/src/archetypes/text_log.rs b/crates/store/re_types/src/archetypes/text_log.rs index e417bb959b7c..1504cad37f84 100644 --- a/crates/store/re_types/src/archetypes/text_log.rs +++ b/crates/store/re_types/src/archetypes/text_log.rs @@ -58,18 +58,18 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; /// /// /// -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Default)] pub struct TextLog { /// The body of the message. - pub text: crate::components::Text, + pub text: Option, /// The verbosity level of the message. /// /// This can be used to filter the log messages in the Rerun Viewer. - pub level: Option, + pub level: Option, /// Optional color to use for the log line in the Rerun Viewer. - pub color: Option, + pub color: Option, } impl TextLog { @@ -187,69 +187,28 @@ impl ::re_types_core::Archetype for TextLog { 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 text = { - let array = arrays_by_descr - .get(&Self::descriptor_text()) - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.TextLog#text")?; - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.TextLog#text")? - .into_iter() - .next() - .flatten() - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.TextLog#text")? - }; - let level = if let Some(array) = arrays_by_descr.get(&Self::descriptor_level()) { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.TextLog#level")? - .into_iter() - .next() - .flatten() - } else { - None - }; - let color = if let Some(array) = arrays_by_descr.get(&Self::descriptor_color()) { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.TextLog#color")? - .into_iter() - .next() - .flatten() - } else { - None - }; + let text = arrays_by_descr + .get(&Self::descriptor_text()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_text())); + let level = arrays_by_descr + .get(&Self::descriptor_level()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_level())); + let color = arrays_by_descr + .get(&Self::descriptor_color()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_color())); Ok(Self { text, level, color }) } } impl ::re_types_core::AsComponents for TextLog { - 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.text as &dyn ComponentBatch)).map(|batch| { - ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_text()), - } - }), - (self - .level - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_level()), - }), - (self - .color - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_color()), - }), + Self::indicator().serialized(), + self.text.clone(), + self.level.clone(), + self.color.clone(), ] .into_iter() .flatten() @@ -264,25 +223,58 @@ impl TextLog { #[inline] pub fn new(text: impl Into) -> Self { Self { - text: text.into(), + text: try_serialize_field(Self::descriptor_text(), [text]), level: None, color: None, } } + /// Update only some specific fields of a `TextLog`. + #[inline] + pub fn update_fields() -> Self { + Self::default() + } + + /// Clear all the fields of a `TextLog`. + #[inline] + pub fn clear_fields() -> Self { + use ::re_types_core::Loggable as _; + Self { + text: Some(SerializedComponentBatch::new( + crate::components::Text::arrow_empty(), + Self::descriptor_text(), + )), + level: Some(SerializedComponentBatch::new( + crate::components::TextLogLevel::arrow_empty(), + Self::descriptor_level(), + )), + color: Some(SerializedComponentBatch::new( + crate::components::Color::arrow_empty(), + Self::descriptor_color(), + )), + } + } + + /// The body of the message. + #[inline] + pub fn with_text(mut self, text: impl Into) -> Self { + self.text = try_serialize_field(Self::descriptor_text(), [text]); + self + } + /// The verbosity level of the message. /// /// This can be used to filter the log messages in the Rerun Viewer. #[inline] pub fn with_level(mut self, level: impl Into) -> Self { - self.level = Some(level.into()); + self.level = try_serialize_field(Self::descriptor_level(), [level]); self } /// Optional color to use for the log line in the Rerun Viewer. #[inline] pub fn with_color(mut self, color: impl Into) -> Self { - self.color = Some(color.into()); + self.color = try_serialize_field(Self::descriptor_color(), [color]); self } } @@ -292,11 +284,4 @@ impl ::re_byte_size::SizeBytes for TextLog { fn heap_size_bytes(&self) -> u64 { self.text.heap_size_bytes() + self.level.heap_size_bytes() + self.color.heap_size_bytes() } - - #[inline] - fn is_pod() -> bool { - ::is_pod() - && >::is_pod() - && >::is_pod() - } } diff --git a/crates/store/re_types/src/archetypes/video_frame_reference.rs b/crates/store/re_types/src/archetypes/video_frame_reference.rs index 45092d428a7e..c84541a5f45c 100644 --- a/crates/store/re_types/src/archetypes/video_frame_reference.rs +++ b/crates/store/re_types/src/archetypes/video_frame_reference.rs @@ -122,7 +122,7 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; /// /// /// -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct VideoFrameReference { /// References the closest video frame to this timestamp. /// @@ -132,7 +132,7 @@ pub struct VideoFrameReference { /// Timestamps are relative to the start of the video, i.e. a timestamp of 0 always corresponds to the first frame. /// This is oftentimes equivalent to presentation timestamps (known as PTS), but in the presence of B-frames /// (bidirectionally predicted frames) there may be an offset on the first presentation timestamp in the video. - pub timestamp: crate::components::VideoTimestamp, + pub timestamp: Option, /// Optional reference to an entity with a [`archetypes::AssetVideo`][crate::archetypes::AssetVideo]. /// @@ -143,7 +143,7 @@ pub struct VideoFrameReference { /// For a series of video frame references, it is recommended to specify this path only once /// at the beginning of the series and then rely on latest-at query semantics to /// keep the video reference active. - pub video_reference: Option, + pub video_reference: Option, } impl VideoFrameReference { @@ -251,29 +251,16 @@ impl ::re_types_core::Archetype for VideoFrameReference { 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 timestamp = { - let array = arrays_by_descr - .get(&Self::descriptor_timestamp()) - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.VideoFrameReference#timestamp")?; - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.VideoFrameReference#timestamp")? - .into_iter() - .next() - .flatten() - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.VideoFrameReference#timestamp")? - }; - let video_reference = - if let Some(array) = arrays_by_descr.get(&Self::descriptor_video_reference()) { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.VideoFrameReference#video_reference")? - .into_iter() - .next() - .flatten() - } else { - None - }; + let timestamp = arrays_by_descr + .get(&Self::descriptor_timestamp()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_timestamp()) + }); + let video_reference = arrays_by_descr + .get(&Self::descriptor_video_reference()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_video_reference()) + }); Ok(Self { timestamp, video_reference, @@ -282,25 +269,13 @@ impl ::re_types_core::Archetype for VideoFrameReference { } impl ::re_types_core::AsComponents for VideoFrameReference { - 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.timestamp as &dyn ComponentBatch)).map(|batch| { - ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_timestamp()), - } - }), - (self - .video_reference - .as_ref() - .map(|comp| (comp as &dyn ComponentBatch))) - .map(|batch| ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_video_reference()), - }), + Self::indicator().serialized(), + self.timestamp.clone(), + self.video_reference.clone(), ] .into_iter() .flatten() @@ -315,11 +290,50 @@ impl VideoFrameReference { #[inline] pub fn new(timestamp: impl Into) -> Self { Self { - timestamp: timestamp.into(), + timestamp: try_serialize_field(Self::descriptor_timestamp(), [timestamp]), video_reference: None, } } + /// Update only some specific fields of a `VideoFrameReference`. + #[inline] + pub fn update_fields() -> Self { + Self::default() + } + + /// Clear all the fields of a `VideoFrameReference`. + #[inline] + pub fn clear_fields() -> Self { + use ::re_types_core::Loggable as _; + Self { + timestamp: Some(SerializedComponentBatch::new( + crate::components::VideoTimestamp::arrow_empty(), + Self::descriptor_timestamp(), + )), + video_reference: Some(SerializedComponentBatch::new( + crate::components::EntityPath::arrow_empty(), + Self::descriptor_video_reference(), + )), + } + } + + /// References the closest video frame to this timestamp. + /// + /// Note that this uses the closest video frame instead of the latest at this timestamp + /// in order to be more forgiving of rounding errors for inprecise timestamp types. + /// + /// Timestamps are relative to the start of the video, i.e. a timestamp of 0 always corresponds to the first frame. + /// This is oftentimes equivalent to presentation timestamps (known as PTS), but in the presence of B-frames + /// (bidirectionally predicted frames) there may be an offset on the first presentation timestamp in the video. + #[inline] + pub fn with_timestamp( + mut self, + timestamp: impl Into, + ) -> Self { + self.timestamp = try_serialize_field(Self::descriptor_timestamp(), [timestamp]); + self + } + /// Optional reference to an entity with a [`archetypes::AssetVideo`][crate::archetypes::AssetVideo]. /// /// If none is specified, the video is assumed to be at the same entity. @@ -334,7 +348,8 @@ impl VideoFrameReference { mut self, video_reference: impl Into, ) -> Self { - self.video_reference = Some(video_reference.into()); + self.video_reference = + try_serialize_field(Self::descriptor_video_reference(), [video_reference]); self } } @@ -344,10 +359,4 @@ impl ::re_byte_size::SizeBytes for VideoFrameReference { fn heap_size_bytes(&self) -> u64 { self.timestamp.heap_size_bytes() + self.video_reference.heap_size_bytes() } - - #[inline] - fn is_pod() -> bool { - ::is_pod() - && >::is_pod() - } } diff --git a/crates/store/re_types/tests/types/arrows3d.rs b/crates/store/re_types/tests/types/arrows3d.rs index 5e838c40da6c..b8517a64f73d 100644 --- a/crates/store/re_types/tests/types/arrows3d.rs +++ b/crates/store/re_types/tests/types/arrows3d.rs @@ -1,8 +1,8 @@ use re_types::{ archetypes::Arrows3D, - components::{ClassId, Color, Position3D, Radius, Vector3D}, + components::{ClassId, Color, Position3D, Radius, ShowLabels, Text, Vector3D}, datatypes::Vec3D, - Archetype as _, AsComponents as _, + Archetype as _, AsComponents as _, ComponentBatch, }; #[test] @@ -11,28 +11,42 @@ fn roundtrip() { vectors: vec![ Vector3D(Vec3D([1.0, 2.0, 3.0])), Vector3D(Vec3D([10.0, 20.0, 30.0])), - ], - origins: Some(vec![ + ] + .serialized() + .map(|batch| batch.with_descriptor_override(Arrows3D::descriptor_vectors())), + origins: vec![ Position3D(Vec3D([4.0, 5.0, 6.0])), // Position3D(Vec3D([40.0, 50.0, 60.0])), // - ]), - radii: Some(vec![ + ] + .serialized() + .map(|batch| batch.with_descriptor_override(Arrows3D::descriptor_origins())), + radii: vec![ Radius::from(1.0), // Radius::from(10.0), - ]), - colors: Some(vec![ + ] + .serialized() + .map(|batch| batch.with_descriptor_override(Arrows3D::descriptor_radii())), + colors: 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![ + ] + .serialized() + .map(|batch| batch.with_descriptor_override(Arrows3D::descriptor_colors())), + labels: vec![ + Text::from("hello"), // + Text::from("friend"), // + ] + .serialized() + .map(|batch| batch.with_descriptor_override(Arrows3D::descriptor_labels())), + class_ids: vec![ ClassId::from(126), // ClassId::from(127), // - ]), - show_labels: Some(true.into()), + ] + .serialized() + .map(|batch| batch.with_descriptor_override(Arrows3D::descriptor_class_ids())), + show_labels: ShowLabels(true.into()) + .serialized() + .map(|batch| batch.with_descriptor_override(Arrows3D::descriptor_show_labels())), }; let arch = Arrows3D::from_vectors([[1.0, 2.0, 3.0], [10.0, 20.0, 30.0]]) diff --git a/crates/store/re_types/tests/types/clear.rs b/crates/store/re_types/tests/types/clear.rs index a9a6d2084441..02eac2769d11 100644 --- a/crates/store/re_types/tests/types/clear.rs +++ b/crates/store/re_types/tests/types/clear.rs @@ -1,13 +1,17 @@ -use re_types::{archetypes::Clear, Archetype as _, AsComponents as _}; +use re_types::{archetypes::Clear, Archetype as _, AsComponents as _, ComponentBatch as _}; #[test] fn roundtrip() { let all_expected = [ Clear { - is_recursive: true.into(), - }, // + is_recursive: re_types::components::ClearIsRecursive(true.into()) + .serialized() + .map(|batch| batch.with_descriptor_override(Clear::descriptor_is_recursive())), + }, Clear { - is_recursive: false.into(), + is_recursive: re_types::components::ClearIsRecursive(false.into()) + .serialized() + .map(|batch| batch.with_descriptor_override(Clear::descriptor_is_recursive())), }, ]; diff --git a/crates/store/re_types/tests/types/depth_image.rs b/crates/store/re_types/tests/types/depth_image.rs index a7a992518d1e..869aa5afe5c3 100644 --- a/crates/store/re_types/tests/types/depth_image.rs +++ b/crates/store/re_types/tests/types/depth_image.rs @@ -1,24 +1,30 @@ use re_types::{ archetypes::DepthImage, - components::DepthMeter, - datatypes::{ChannelDatatype, ImageFormat}, - Archetype as _, AsComponents as _, + components::{DepthMeter, ImageBuffer, ImageFormat}, + datatypes::{self, ChannelDatatype}, + Archetype as _, AsComponents as _, ComponentBatch as _, }; #[test] fn depth_image_roundtrip() { - let format_expected = ImageFormat { + let format_expected = ImageFormat(datatypes::ImageFormat { width: 3, height: 2, pixel_format: None, channel_datatype: Some(ChannelDatatype::U8), color_model: None, - }; + }); let all_expected = [DepthImage { - buffer: vec![1, 2, 3, 4, 5, 6].into(), - format: format_expected.into(), - meter: Some(DepthMeter::from(1000.0)), + buffer: ImageBuffer::from(vec![1, 2, 3, 4, 5, 6]) + .serialized() + .map(|batch| batch.with_descriptor_override(DepthImage::descriptor_buffer())), + format: format_expected + .serialized() + .map(|batch| batch.with_descriptor_override(DepthImage::descriptor_format())), + meter: DepthMeter::from(1000.0) + .serialized() + .map(|batch| batch.with_descriptor_override(DepthImage::descriptor_meter())), draw_order: None, colormap: None, point_fill_ratio: None, diff --git a/crates/store/re_types/tests/types/points2d.rs b/crates/store/re_types/tests/types/points2d.rs index 4bce901cd764..4bc07b7815f1 100644 --- a/crates/store/re_types/tests/types/points2d.rs +++ b/crates/store/re_types/tests/types/points2d.rs @@ -1,4 +1,8 @@ -use re_types::{archetypes::Points2D, components, Archetype as _, AsComponents as _}; +use re_types::{ + archetypes::Points2D, + components::{self, ShowLabels}, + Archetype as _, AsComponents as _, ComponentBatch as _, +}; #[test] fn roundtrip() { @@ -6,29 +10,45 @@ fn roundtrip() { positions: vec![ components::Position2D::new(1.0, 2.0), // components::Position2D::new(3.0, 4.0), - ], - radii: Some(vec![ + ] + .serialized() + .map(|batch| batch.with_descriptor_override(Points2D::descriptor_positions())), + radii: vec![ components::Radius::from(42.0), // components::Radius::from(43.0), - ]), - colors: Some(vec![ + ] + .serialized() + .map(|batch| batch.with_descriptor_override(Points2D::descriptor_radii())), + colors: vec![ components::Color::from_unmultiplied_rgba(0xAA, 0x00, 0x00, 0xCC), // components::Color::from_unmultiplied_rgba(0x00, 0xBB, 0x00, 0xDD), - ]), - labels: Some(vec![ - "hello".into(), // - "friend".into(), // - ]), - draw_order: Some(components::DrawOrder(300.0.into())), - class_ids: Some(vec![ + ] + .serialized() + .map(|batch| batch.with_descriptor_override(Points2D::descriptor_colors())), + labels: vec![ + components::Text::from("hello"), // + components::Text::from("friend"), // + ] + .serialized() + .map(|batch| batch.with_descriptor_override(Points2D::descriptor_labels())), + draw_order: components::DrawOrder::from(300.0) + .serialized() + .map(|batch| batch.with_descriptor_override(Points2D::descriptor_draw_order())), + class_ids: vec![ components::ClassId::from(126), // components::ClassId::from(127), // - ]), - keypoint_ids: Some(vec![ + ] + .serialized() + .map(|batch| batch.with_descriptor_override(Points2D::descriptor_class_ids())), + keypoint_ids: vec![ components::KeypointId::from(2), // components::KeypointId::from(3), // - ]), - show_labels: Some(false.into()), + ] + .serialized() + .map(|batch| batch.with_descriptor_override(Points2D::descriptor_keypoint_ids())), + show_labels: ShowLabels::from(false) + .serialized() + .map(|batch| batch.with_descriptor_override(Points2D::descriptor_show_labels())), }; let arch = Points2D::new([(1.0, 2.0), (3.0, 4.0)]) diff --git a/crates/store/re_types/tests/types/segmentation_image.rs b/crates/store/re_types/tests/types/segmentation_image.rs index d99151f01447..83124d604372 100644 --- a/crates/store/re_types/tests/types/segmentation_image.rs +++ b/crates/store/re_types/tests/types/segmentation_image.rs @@ -1,22 +1,27 @@ use re_types::{ archetypes::SegmentationImage, - datatypes::{ChannelDatatype, ImageFormat}, - Archetype as _, AsComponents as _, + components::{ImageBuffer, ImageFormat}, + datatypes::{self, ChannelDatatype}, + Archetype as _, AsComponents as _, ComponentBatch as _, }; #[test] fn segmentation_image_roundtrip() { - let format_expected = ImageFormat { + let format_expected = ImageFormat(datatypes::ImageFormat { width: 3, height: 2, pixel_format: None, channel_datatype: Some(ChannelDatatype::U8), color_model: None, - }; + }); let all_expected = [SegmentationImage { - buffer: vec![1, 2, 3, 4, 5, 6].into(), - format: format_expected.into(), + buffer: ImageBuffer::from(vec![1, 2, 3, 4, 5, 6]) + .serialized() + .map(|batch| batch.with_descriptor_override(SegmentationImage::descriptor_buffer())), + format: format_expected + .serialized() + .map(|batch| batch.with_descriptor_override(SegmentationImage::descriptor_format())), draw_order: None, opacity: None, }]; diff --git a/crates/store/re_types/tests/types/text_document.rs b/crates/store/re_types/tests/types/text_document.rs index 3c3c44a052dc..279396ca3009 100644 --- a/crates/store/re_types/tests/types/text_document.rs +++ b/crates/store/re_types/tests/types/text_document.rs @@ -1,12 +1,19 @@ use re_types::{ archetypes::TextDocument, components::MediaType, Archetype as _, AsComponents as _, + ComponentBatch as _, }; #[test] fn roundtrip() { + use re_types::components::Text; + let expected = TextDocument { - text: "This is the contents of the text document.".into(), - media_type: Some(MediaType::markdown()), + text: Text::from("This is the contents of the text document.") + .serialized() + .map(|batch| batch.with_descriptor_override(TextDocument::descriptor_text())), + media_type: MediaType::markdown() + .serialized() + .map(|batch| batch.with_descriptor_override(TextDocument::descriptor_media_type())), }; let arch = TextDocument::new("This is the contents of the text document.") diff --git a/crates/store/re_types_core/src/archetypes/clear.rs b/crates/store/re_types_core/src/archetypes/clear.rs index f380e13e1295..2c0223e8506a 100644 --- a/crates/store/re_types_core/src/archetypes/clear.rs +++ b/crates/store/re_types_core/src/archetypes/clear.rs @@ -73,9 +73,9 @@ use crate::{DeserializationError, DeserializationResult}; /// /// /// -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Default)] pub struct Clear { - pub is_recursive: crate::components::ClearIsRecursive, + pub is_recursive: Option, } impl Clear { @@ -171,39 +171,23 @@ impl crate::Archetype for Clear { re_tracing::profile_function!(); use crate::{Loggable as _, ResultExt as _}; let arrays_by_descr: ::nohash_hasher::IntMap<_, _> = arrow_data.into_iter().collect(); - let is_recursive = { - let array = arrays_by_descr - .get(&Self::descriptor_is_recursive()) - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.Clear#is_recursive")?; - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Clear#is_recursive")? - .into_iter() - .next() - .flatten() - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.Clear#is_recursive")? - }; + let is_recursive = arrays_by_descr + .get(&Self::descriptor_is_recursive()) + .map(|array| { + SerializedComponentBatch::new(array.clone(), Self::descriptor_is_recursive()) + }); Ok(Self { is_recursive }) } } impl crate::AsComponents for Clear { - fn as_component_batches(&self) -> Vec> { - re_tracing::profile_function!(); + #[inline] + fn as_serialized_batches(&self) -> Vec { use crate::Archetype as _; - [ - Some(Self::indicator()), - (Some(&self.is_recursive as &dyn ComponentBatch)).map(|batch| { - crate::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_is_recursive()), - } - }), - ] - .into_iter() - .flatten() - .collect() + [Self::indicator().serialized(), self.is_recursive.clone()] + .into_iter() + .flatten() + .collect() } } @@ -214,9 +198,36 @@ impl Clear { #[inline] pub fn new(is_recursive: impl Into) -> Self { Self { - is_recursive: is_recursive.into(), + is_recursive: try_serialize_field(Self::descriptor_is_recursive(), [is_recursive]), + } + } + + /// Update only some specific fields of a `Clear`. + #[inline] + pub fn update_fields() -> Self { + Self::default() + } + + /// Clear all the fields of a `Clear`. + #[inline] + pub fn clear_fields() -> Self { + use crate::Loggable as _; + Self { + is_recursive: Some(SerializedComponentBatch::new( + crate::components::ClearIsRecursive::arrow_empty(), + Self::descriptor_is_recursive(), + )), } } + + #[inline] + pub fn with_is_recursive( + mut self, + is_recursive: impl Into, + ) -> Self { + self.is_recursive = try_serialize_field(Self::descriptor_is_recursive(), [is_recursive]); + self + } } impl ::re_byte_size::SizeBytes for Clear { @@ -224,9 +235,4 @@ impl ::re_byte_size::SizeBytes for Clear { fn heap_size_bytes(&self) -> u64 { self.is_recursive.heap_size_bytes() } - - #[inline] - fn is_pod() -> bool { - ::is_pod() - } } diff --git a/crates/store/re_types_core/src/lib.rs b/crates/store/re_types_core/src/lib.rs index d8e4e38d104d..620fd06eb3a1 100644 --- a/crates/store/re_types_core/src/lib.rs +++ b/crates/store/re_types_core/src/lib.rs @@ -98,8 +98,7 @@ pub mod external { /// Useful macro for statically asserting that a `struct` contains some specific fields. /// -/// In particular, this is useful to statcially check that an archetype -/// has a specific component. +/// For asserting that an archetype has a specific component use `re_log_types::debug_assert_archetype_has_components` /// /// ``` /// # #[macro_use] extern crate re_types_core; diff --git a/crates/viewer/re_data_ui/src/instance_path.rs b/crates/viewer/re_data_ui/src/instance_path.rs index 2184700e4c1b..dc52f05b96c0 100644 --- a/crates/viewer/re_data_ui/src/instance_path.rs +++ b/crates/viewer/re_data_ui/src/instance_path.rs @@ -3,7 +3,7 @@ use nohash_hasher::IntMap; use re_chunk_store::UnitChunkShared; use re_entity_db::InstancePath; -use re_log_types::ComponentPath; +use re_log_types::{debug_assert_archetype_has_components, ComponentPath}; use re_types::{ archetypes, components, datatypes::{ChannelDatatype, ColorModel}, @@ -278,12 +278,12 @@ fn preview_if_image_ui( buffer: components::ImageBuffer, format: components::ImageFormat ); - static_assert_struct_has_fields!( + debug_assert_archetype_has_components!( archetypes::DepthImage, buffer: components::ImageBuffer, format: components::ImageFormat ); - static_assert_struct_has_fields!( + debug_assert_archetype_has_components!( archetypes::SegmentationImage, buffer: components::ImageBuffer, format: components::ImageFormat diff --git a/crates/viewer/re_view_spatial/src/lib.rs b/crates/viewer/re_view_spatial/src/lib.rs index 1ce80145f306..cd0733894119 100644 --- a/crates/viewer/re_view_spatial/src/lib.rs +++ b/crates/viewer/re_view_spatial/src/lib.rs @@ -40,6 +40,7 @@ pub(crate) use pickable_textured_rect::{PickableRectSourceData, PickableTextured use re_view::DataResultQuery as _; use re_viewer_context::{ImageDecodeCache, ViewContext, ViewerContext}; +use re_log_types::debug_assert_archetype_has_components; use re_renderer::RenderContext; use re_types::{ archetypes, @@ -64,7 +65,7 @@ fn resolution_of_image_at( ) -> Option { // First check assumptions: static_assert_struct_has_fields!(archetypes::Image, format: components::ImageFormat); - static_assert_struct_has_fields!(archetypes::EncodedImage, blob: components::Blob); + debug_assert_archetype_has_components!(archetypes::EncodedImage, blob: components::Blob); let db = ctx.recording();