diff --git a/crates/re_types/definitions/rerun/archetypes.fbs b/crates/re_types/definitions/rerun/archetypes.fbs index e8f07787a567..3b8c926f33a2 100644 --- a/crates/re_types/definitions/rerun/archetypes.fbs +++ b/crates/re_types/definitions/rerun/archetypes.fbs @@ -1 +1,3 @@ +include "./archetypes/points2d.fbs"; + namespace rerun.archetypes; diff --git a/crates/re_types/source_hash.txt b/crates/re_types/source_hash.txt index d77d8829d788..c42e78830657 100644 --- a/crates/re_types/source_hash.txt +++ b/crates/re_types/source_hash.txt @@ -1,4 +1,4 @@ # This is a sha256 hash for all direct and indirect dependencies of this crate's build script. # It can be safely removed at anytime to force the build script to run again. # Check out build.rs to see how it's computed. -95c13226f31d47e4639e155fc80ee6830579c50e38ee1d997b4bda4d23ba03b6 +2d611d0d686a6314da94b1797472e7690413465d16a611aae3560a847668d53d \ No newline at end of file diff --git a/crates/re_types/src/archetypes/mod.rs b/crates/re_types/src/archetypes/mod.rs index cf43c16c6a0e..d1e7d85ddc77 100644 --- a/crates/re_types/src/archetypes/mod.rs +++ b/crates/re_types/src/archetypes/mod.rs @@ -1 +1,5 @@ // NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +mod points2d; + +pub use self::points2d::Points2D; diff --git a/crates/re_types/src/archetypes/points2d.rs b/crates/re_types/src/archetypes/points2d.rs new file mode 100644 index 000000000000..b40f91afb512 --- /dev/null +++ b/crates/re_types/src/archetypes/points2d.rs @@ -0,0 +1,162 @@ +// NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +/// A 2D point cloud with positions and optional colors, radii, labels, etc. +#[derive(Debug, Clone, PartialEq)] +pub struct Points2D { + /// All the actual 2D points that make up the point cloud. + pub points: Vec, + + /// Optional radii for the points, effectively turning them into circles. + pub radii: Option>, + + /// Optional colors for the points. + pub colors: Option>, + + /// Optional text labels for the points. + pub 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. + /// + /// The default for 2D points is 30.0. + pub draw_order: Option, + + /// Optional class Ids for the points. + /// + /// The class ID provides colors and labels if not specified explicitly. + pub class_ids: Option>, + + /// Optional keypoint IDs for the points, identifying them within a class. + /// + /// If keypoint IDs are passed in but no class IDs were specified, the class ID will + /// default to 0. + /// This is useful to identify points within a single classification (which is identified + /// with `class_id`). + /// E.g. the classification might be 'Person' and the keypoints refer to joints on a + /// detected skeleton. + pub keypoint_ids: Option>, + + /// Unique identifiers for each individual point in the batch. + pub instance_keys: Option>, +} + +impl Points2D { + pub const REQUIRED_COMPONENTS: [crate::ComponentName; 1] = + [crate::ComponentName::Borrowed("rerun.components.Point2D")]; + + pub const RECOMMENDED_COMPONENTS: [crate::ComponentName; 2] = [ + crate::ComponentName::Borrowed("rerun.components.Radius"), + crate::ComponentName::Borrowed("rerun.components.Color"), + ]; + + pub const OPTIONAL_COMPONENTS: [crate::ComponentName; 5] = [ + crate::ComponentName::Borrowed("rerun.components.Label"), + crate::ComponentName::Borrowed("rerun.components.DrawOrder"), + crate::ComponentName::Borrowed("rerun.components.ClassId"), + crate::ComponentName::Borrowed("rerun.components.KeypointId"), + crate::ComponentName::Borrowed("rerun.components.InstanceKey"), + ]; + + pub const ALL_COMPONENTS: [crate::ComponentName; 8] = [ + crate::ComponentName::Borrowed("rerun.components.Point2D"), + crate::ComponentName::Borrowed("rerun.components.Radius"), + crate::ComponentName::Borrowed("rerun.components.Color"), + crate::ComponentName::Borrowed("rerun.components.Label"), + crate::ComponentName::Borrowed("rerun.components.DrawOrder"), + crate::ComponentName::Borrowed("rerun.components.ClassId"), + crate::ComponentName::Borrowed("rerun.components.KeypointId"), + crate::ComponentName::Borrowed("rerun.components.InstanceKey"), + ]; +} + +impl crate::Archetype for Points2D { + fn name() -> crate::ArchetypeName { + crate::ArchetypeName::Borrowed("rerun.archetypes.Points2D") + } + + fn required_components() -> Vec { + Self::REQUIRED_COMPONENTS.to_vec() + } + + fn recommended_components() -> Vec { + Self::RECOMMENDED_COMPONENTS.to_vec() + } + + fn optional_components() -> Vec { + Self::OPTIONAL_COMPONENTS.to_vec() + } + + #[allow(clippy::unimplemented)] + fn to_arrow_datatypes() -> Vec { + // TODO(#2368): dump the arrow registry into the generated code + unimplemented!("query the registry for all fqnames"); // NOLINT + } +} + +impl Points2D { + pub fn new(points: impl IntoIterator>) -> Self { + Self { + points: points.into_iter().map(Into::into).collect(), + radii: None, + colors: None, + labels: None, + draw_order: None, + class_ids: None, + keypoint_ids: None, + instance_keys: None, + } + } + + pub fn with_radii( + mut self, + radii: impl IntoIterator>, + ) -> Self { + self.radii = Some(radii.into_iter().map(Into::into).collect()); + self + } + + pub fn with_colors( + mut self, + colors: impl IntoIterator>, + ) -> Self { + self.colors = Some(colors.into_iter().map(Into::into).collect()); + self + } + + pub fn with_labels( + mut self, + labels: impl IntoIterator>, + ) -> Self { + self.labels = Some(labels.into_iter().map(Into::into).collect()); + self + } + + pub fn with_draw_order(mut self, draw_order: impl Into) -> Self { + self.draw_order = Some(draw_order.into()); + self + } + + pub fn with_class_ids( + mut self, + class_ids: impl IntoIterator>, + ) -> Self { + self.class_ids = Some(class_ids.into_iter().map(Into::into).collect()); + self + } + + pub fn with_keypoint_ids( + mut self, + keypoint_ids: impl IntoIterator>, + ) -> Self { + self.keypoint_ids = Some(keypoint_ids.into_iter().map(Into::into).collect()); + self + } + + pub fn with_instance_keys( + mut self, + instance_keys: impl IntoIterator>, + ) -> Self { + self.instance_keys = Some(instance_keys.into_iter().map(Into::into).collect()); + self + } +} diff --git a/crates/re_types/src/components/class_id.rs b/crates/re_types/src/components/class_id.rs new file mode 100644 index 000000000000..21d987ceba8d --- /dev/null +++ b/crates/re_types/src/components/class_id.rs @@ -0,0 +1,19 @@ +// NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +/// A 16-bit ID representing a type of semantic class. +/// +/// Used to look up a `crate::components::ClassDescription` within the `crate::components::AnnotationContext`. +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct ClassId(pub u16); + +impl crate::Component for ClassId { + fn name() -> crate::ComponentName { + crate::ComponentName::Borrowed("rerun.components.ClassId") + } + + #[allow(clippy::wildcard_imports)] + fn to_arrow_datatype() -> arrow2::datatypes::DataType { + use ::arrow2::datatypes::*; + DataType::UInt16 + } +} diff --git a/crates/re_types/src/components/color.rs b/crates/re_types/src/components/color.rs new file mode 100644 index 000000000000..12f2bf0dec65 --- /dev/null +++ b/crates/re_types/src/components/color.rs @@ -0,0 +1,20 @@ +// NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +/// An RGBA color tuple with unmultiplied/separate alpha, in sRGB gamma space with linear alpha. +#[derive( + Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, bytemuck::Pod, bytemuck::Zeroable, +)] +#[repr(transparent)] +pub struct Color(pub u32); + +impl crate::Component for Color { + fn name() -> crate::ComponentName { + crate::ComponentName::Borrowed("rerun.components.Color") + } + + #[allow(clippy::wildcard_imports)] + fn to_arrow_datatype() -> arrow2::datatypes::DataType { + use ::arrow2::datatypes::*; + DataType::UInt32 + } +} diff --git a/crates/re_types/src/components/draw_order.rs b/crates/re_types/src/components/draw_order.rs new file mode 100644 index 000000000000..3ccf929240b7 --- /dev/null +++ b/crates/re_types/src/components/draw_order.rs @@ -0,0 +1,24 @@ +// NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +/// Draw order used for the display order of 2D elements. +/// +/// Higher values are drawn on top of lower values. +/// An entity can have only a single draw order component. +/// Within an entity draw order is governed by the order of the components. +/// +/// Draw order for entities with the same draw order is generally undefined. +#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)] +#[repr(transparent)] +pub struct DrawOrder(pub f32); + +impl crate::Component for DrawOrder { + fn name() -> crate::ComponentName { + crate::ComponentName::Borrowed("rerun.components.DrawOrder") + } + + #[allow(clippy::wildcard_imports)] + fn to_arrow_datatype() -> arrow2::datatypes::DataType { + use ::arrow2::datatypes::*; + DataType::Float32 + } +} diff --git a/crates/re_types/src/components/instance_key.rs b/crates/re_types/src/components/instance_key.rs new file mode 100644 index 000000000000..3b46e8719144 --- /dev/null +++ b/crates/re_types/src/components/instance_key.rs @@ -0,0 +1,17 @@ +// NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +/// A unique numeric identifier for each individual instance within a batch. +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +pub struct InstanceKey(pub u64); + +impl crate::Component for InstanceKey { + fn name() -> crate::ComponentName { + crate::ComponentName::Borrowed("rerun.components.InstanceKey") + } + + #[allow(clippy::wildcard_imports)] + fn to_arrow_datatype() -> arrow2::datatypes::DataType { + use ::arrow2::datatypes::*; + DataType::UInt64 + } +} diff --git a/crates/re_types/src/components/keypoint_id.rs b/crates/re_types/src/components/keypoint_id.rs new file mode 100644 index 000000000000..531fcb117191 --- /dev/null +++ b/crates/re_types/src/components/keypoint_id.rs @@ -0,0 +1,21 @@ +// NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +/// A 16-bit ID representing a type of semantic keypoint within a class. +/// +/// `KeypointId`s are only meaningful within the context of a `crate::components::ClassDescription`. +/// +/// Used to look up an `crate::components::AnnotationInfo` for a Keypoint within the `crate::components::AnnotationContext`. +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct KeypointId(pub u16); + +impl crate::Component for KeypointId { + fn name() -> crate::ComponentName { + crate::ComponentName::Borrowed("rerun.components.KeypointId") + } + + #[allow(clippy::wildcard_imports)] + fn to_arrow_datatype() -> arrow2::datatypes::DataType { + use ::arrow2::datatypes::*; + DataType::UInt16 + } +} diff --git a/crates/re_types/src/components/label.rs b/crates/re_types/src/components/label.rs new file mode 100644 index 000000000000..5a5472391f64 --- /dev/null +++ b/crates/re_types/src/components/label.rs @@ -0,0 +1,18 @@ +// NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +/// A String label component. +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[repr(transparent)] +pub struct Label(pub String); + +impl crate::Component for Label { + fn name() -> crate::ComponentName { + crate::ComponentName::Borrowed("rerun.components.Label") + } + + #[allow(clippy::wildcard_imports)] + fn to_arrow_datatype() -> arrow2::datatypes::DataType { + use ::arrow2::datatypes::*; + DataType::Utf8 + } +} diff --git a/crates/re_types/src/components/mod.rs b/crates/re_types/src/components/mod.rs index cf43c16c6a0e..8fe7f6428266 100644 --- a/crates/re_types/src/components/mod.rs +++ b/crates/re_types/src/components/mod.rs @@ -1 +1,19 @@ // NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +mod class_id; +mod color; +mod draw_order; +mod instance_key; +mod keypoint_id; +mod label; +mod point2d; +mod radius; + +pub use self::class_id::ClassId; +pub use self::color::Color; +pub use self::draw_order::DrawOrder; +pub use self::instance_key::InstanceKey; +pub use self::keypoint_id::KeypointId; +pub use self::label::Label; +pub use self::point2d::Point2D; +pub use self::radius::Radius; diff --git a/crates/re_types/src/components/point2d.rs b/crates/re_types/src/components/point2d.rs new file mode 100644 index 000000000000..2f9dc0855cb3 --- /dev/null +++ b/crates/re_types/src/components/point2d.rs @@ -0,0 +1,25 @@ +// NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +/// A point in 2D space. +#[derive(Debug, Default, Clone, Copy, PartialEq, PartialOrd)] +pub struct Point2D(pub crate::datatypes::Vec2D); + +impl crate::Component for Point2D { + fn name() -> crate::ComponentName { + crate::ComponentName::Borrowed("rerun.components.Point2D") + } + + #[allow(clippy::wildcard_imports)] + fn to_arrow_datatype() -> arrow2::datatypes::DataType { + use ::arrow2::datatypes::*; + DataType::FixedSizeList( + Box::new(Field { + name: "item".to_owned(), + data_type: DataType::Float32, + is_nullable: false, + metadata: [].into(), + }), + 2, + ) + } +} diff --git a/crates/re_types/src/components/radius.rs b/crates/re_types/src/components/radius.rs new file mode 100644 index 000000000000..34a57bfbe31b --- /dev/null +++ b/crates/re_types/src/components/radius.rs @@ -0,0 +1,17 @@ +// NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +/// A Radius component. +#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)] +pub struct Radius(pub f32); + +impl crate::Component for Radius { + fn name() -> crate::ComponentName { + crate::ComponentName::Borrowed("rerun.components.Radius") + } + + #[allow(clippy::wildcard_imports)] + fn to_arrow_datatype() -> arrow2::datatypes::DataType { + use ::arrow2::datatypes::*; + DataType::Float32 + } +} diff --git a/crates/re_types/src/datatypes/mod.rs b/crates/re_types/src/datatypes/mod.rs index cf43c16c6a0e..894c386d7e99 100644 --- a/crates/re_types/src/datatypes/mod.rs +++ b/crates/re_types/src/datatypes/mod.rs @@ -1 +1,5 @@ // NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +mod vec2d; + +pub use self::vec2d::Vec2D; diff --git a/crates/re_types/src/datatypes/vec2d.rs b/crates/re_types/src/datatypes/vec2d.rs new file mode 100644 index 000000000000..ff1645c08ee1 --- /dev/null +++ b/crates/re_types/src/datatypes/vec2d.rs @@ -0,0 +1,25 @@ +// NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +/// A vector in 2D space. +#[derive(Debug, Default, Clone, Copy, PartialEq, PartialOrd)] +pub struct Vec2D(pub [f32; 2]); + +impl crate::Datatype for Vec2D { + fn name() -> crate::DatatypeName { + crate::DatatypeName::Borrowed("rerun.datatypes.Vec2D") + } + + #[allow(clippy::wildcard_imports)] + fn to_arrow_datatype() -> arrow2::datatypes::DataType { + use ::arrow2::datatypes::*; + DataType::FixedSizeList( + Box::new(Field { + name: "item".to_owned(), + data_type: DataType::Float32, + is_nullable: false, + metadata: [].into(), + }), + 2, + ) + } +} diff --git a/crates/re_types/src/lib.rs b/crates/re_types/src/lib.rs index e6ddbfc3f92f..f64449073cbe 100644 --- a/crates/re_types/src/lib.rs +++ b/crates/re_types/src/lib.rs @@ -71,31 +71,39 @@ //! auto-generated class. //! The simplest way to get started is to look at any of the existing examples. -use std::borrow::Cow; +// --- + +pub type DatatypeName = ::std::borrow::Cow<'static, str>; /// A [`Datatype`] describes plain old data. pub trait Datatype { - fn name() -> Cow<'static, str>; + fn name() -> DatatypeName; fn to_arrow_datatype() -> arrow2::datatypes::DataType; } +pub type ComponentName = ::std::borrow::Cow<'static, str>; + pub trait Component { - fn name() -> Cow<'static, str>; + fn name() -> ComponentName; fn to_arrow_datatype() -> arrow2::datatypes::DataType; } +pub type ArchetypeName = ::std::borrow::Cow<'static, str>; + pub trait Archetype { - fn name() -> Cow<'static, str>; + fn name() -> ArchetypeName; - fn required_components() -> Vec>; - fn recommended_components() -> Vec>; - fn optional_components() -> Vec>; + fn required_components() -> Vec; + fn recommended_components() -> Vec; + fn optional_components() -> Vec; fn to_arrow_datatypes() -> Vec; } +// --- + /// Number of decimals shown for all vector display methods. pub const DISPLAY_PRECISION: usize = 3; diff --git a/crates/re_types_builder/src/codegen/rust.rs b/crates/re_types_builder/src/codegen/rust.rs index 9e78c7a984ec..905dbb63f6d8 100644 --- a/crates/re_types_builder/src/codegen/rust.rs +++ b/crates/re_types_builder/src/codegen/rust.rs @@ -426,8 +426,8 @@ fn quote_trait_impls_from_obj(arrow_registry: &ArrowRegistry, obj: &Object) -> S format!( r#" impl crate::Datatype for {name} {{ - fn name() -> ::std::borrow::Cow<'static, str> {{ - ::std::borrow::Cow::Borrowed({fqname:?}) + fn name() -> crate::DatatypeName {{ + crate::DatatypeName::Borrowed({fqname:?}) }} #[allow(clippy::wildcard_imports)] @@ -444,8 +444,8 @@ fn quote_trait_impls_from_obj(arrow_registry: &ArrowRegistry, obj: &Object) -> S format!( r#" impl crate::Component for {name} {{ - fn name() -> ::std::borrow::Cow<'static, str> {{ - ::std::borrow::Cow::Borrowed({fqname:?}) + fn name() -> crate::ComponentName {{ + crate::ComponentName::Borrowed({fqname:?}) }} #[allow(clippy::wildcard_imports)] @@ -464,7 +464,7 @@ fn quote_trait_impls_from_obj(arrow_registry: &ArrowRegistry, obj: &Object) -> S let num_components = components.len(); let components = components .into_iter() - .map(|fqname| format!("::std::borrow::Cow::Borrowed({fqname:?})")) + .map(|fqname| format!("crate::ComponentName::Borrowed({fqname:?})")) .collect::>() .join(", "); @@ -484,29 +484,29 @@ fn quote_trait_impls_from_obj(arrow_registry: &ArrowRegistry, obj: &Object) -> S format!( r#" impl {name} {{ - pub const REQUIRED_COMPONENTS: [::std::borrow::Cow<'static, str>; {num_required}] = [{required}]; + pub const REQUIRED_COMPONENTS: [crate::ComponentName; {num_required}] = [{required}]; - pub const RECOMMENDED_COMPONENTS: [::std::borrow::Cow<'static, str>; {num_recommended}] = [{recommended}]; + pub const RECOMMENDED_COMPONENTS: [crate::ComponentName; {num_recommended}] = [{recommended}]; - pub const OPTIONAL_COMPONENTS: [::std::borrow::Cow<'static, str>; {num_optional}] = [{optional}]; + pub const OPTIONAL_COMPONENTS: [crate::ComponentName; {num_optional}] = [{optional}]; - pub const ALL_COMPONENTS: [::std::borrow::Cow<'static, str>; {num_all}] = [{all}]; + pub const ALL_COMPONENTS: [crate::ComponentName; {num_all}] = [{all}]; }} impl crate::Archetype for {name} {{ - fn name() -> ::std::borrow::Cow<'static, str> {{ - ::std::borrow::Cow::Borrowed({fqname:?}) + fn name() -> crate::ArchetypeName {{ + crate::ArchetypeName::Borrowed({fqname:?}) }} - fn required_components() -> Vec<::std::borrow::Cow<'static, str>> {{ + fn required_components() -> Vec {{ Self::REQUIRED_COMPONENTS.to_vec() }} - fn recommended_components() -> Vec<::std::borrow::Cow<'static, str>> {{ + fn recommended_components() -> Vec {{ Self::RECOMMENDED_COMPONENTS.to_vec() }} - fn optional_components() -> Vec<::std::borrow::Cow<'static, str>> {{ + fn optional_components() -> Vec {{ Self::OPTIONAL_COMPONENTS.to_vec() }}