From 1e2975ee0c96b4df779568060da1e0f050814a9d Mon Sep 17 00:00:00 2001 From: Clement Rey Date: Sun, 11 Jun 2023 21:24:03 +0200 Subject: [PATCH] wip --- Cargo.lock | 16 ++ crates/re_types/Cargo.toml | 61 +++++++ crates/re_types/README.md | 12 ++ crates/re_types/build.rs | 104 +++++++++++ .../re_types/definitions/arrow/attributes.fbs | 12 ++ .../re_types/definitions/fbs/attributes.fbs | 16 ++ .../re_types/definitions/fbs/reflection.fbs | 157 +++++++++++++++++ crates/re_types/definitions/fbs/scalars.fbs | 10 ++ .../definitions/python/attributes.fbs | 16 ++ .../re_types/definitions/rerun/archetypes.fbs | 3 + .../definitions/rerun/archetypes/points2d.fbs | 62 +++++++ .../re_types/definitions/rerun/attributes.fbs | 19 ++ .../re_types/definitions/rerun/components.fbs | 8 + .../definitions/rerun/components/class_id.fbs | 23 +++ .../definitions/rerun/components/color.fbs | 23 +++ .../rerun/components/draw_order.fbs | 29 ++++ .../rerun/components/instance_key.fbs | 22 +++ .../rerun/components/keypoint_id.fbs | 30 ++++ .../definitions/rerun/components/label.fbs | 22 +++ .../definitions/rerun/components/point2d.fbs | 25 +++ .../definitions/rerun/components/radius.fbs | 22 +++ .../re_types/definitions/rerun/datatypes.fbs | 3 + .../definitions/rerun/datatypes/vec2d.fbs | 17 ++ .../re_types/definitions/rust/attributes.fbs | 15 ++ crates/re_types/source_hash.txt | 4 + crates/re_types/src/archetypes/mod.rs | 5 + crates/re_types/src/archetypes/points2d.rs | 162 ++++++++++++++++++ crates/re_types/src/components/class_id.rs | 19 ++ crates/re_types/src/components/color.rs | 20 +++ crates/re_types/src/components/color_ext.rs | 43 +++++ crates/re_types/src/components/draw_order.rs | 24 +++ .../re_types/src/components/draw_order_ext.rs | 60 +++++++ .../re_types/src/components/instance_key.rs | 17 ++ .../src/components/instance_key_ext.rs | 22 +++ crates/re_types/src/components/keypoint_id.rs | 21 +++ crates/re_types/src/components/label.rs | 18 ++ crates/re_types/src/components/label_ext.rs | 51 ++++++ crates/re_types/src/components/mod.rs | 25 +++ crates/re_types/src/components/point2d.rs | 25 +++ crates/re_types/src/components/point2d_ext.rs | 64 +++++++ crates/re_types/src/components/radius.rs | 17 ++ crates/re_types/src/components/radius_ext.rs | 24 +++ crates/re_types/src/datatypes/mod.rs | 6 + crates/re_types/src/datatypes/vec2d.rs | 25 +++ crates/re_types/src/datatypes/vec2d_ext.rs | 73 ++++++++ crates/re_types/src/lib.rs | 104 +++++++++++ crates/re_types/tests/points2d.rs | 108 ++++++++++++ rerun_py/rerun2/__init__.py | 3 + rerun_py/rerun2/archetypes/__init__.py | 8 + rerun_py/rerun2/archetypes/points2d.py | 112 ++++++++++++ rerun_py/rerun2/components/__init__.py | 33 ++++ rerun_py/rerun2/components/class_id.py | 70 ++++++++ rerun_py/rerun2/components/class_id_ext.py | 19 ++ rerun_py/rerun2/components/color.py | 78 +++++++++ rerun_py/rerun2/components/color_ext.py | 33 ++++ rerun_py/rerun2/components/draw_order.py | 76 ++++++++ rerun_py/rerun2/components/draw_order_ext.py | 19 ++ rerun_py/rerun2/components/instance_key.py | 68 ++++++++ .../rerun2/components/instance_key_ext.py | 19 ++ rerun_py/rerun2/components/keypoint_id.py | 77 +++++++++ rerun_py/rerun2/components/keypoint_id_ext.py | 19 ++ rerun_py/rerun2/components/label.py | 69 ++++++++ rerun_py/rerun2/components/label_ext.py | 18 ++ rerun_py/rerun2/components/point2d.py | 70 ++++++++ rerun_py/rerun2/components/point2d_ext.py | 19 ++ rerun_py/rerun2/components/radius.py | 68 ++++++++ rerun_py/rerun2/components/radius_ext.py | 19 ++ rerun_py/rerun2/datatypes/__init__.py | 8 + rerun_py/rerun2/datatypes/vec2d.py | 70 ++++++++ rerun_py/rerun2/datatypes/vec2d_ext.py | 19 ++ rerun_py/rerun_sdk/rerun/color_conversion.py | 24 ++- rerun_py/tests/unit/test_point2d.py | 115 +++++++++++++ 72 files changed, 2796 insertions(+), 1 deletion(-) create mode 100644 crates/re_types/Cargo.toml create mode 100644 crates/re_types/README.md create mode 100644 crates/re_types/build.rs create mode 100644 crates/re_types/definitions/arrow/attributes.fbs create mode 100644 crates/re_types/definitions/fbs/attributes.fbs create mode 100644 crates/re_types/definitions/fbs/reflection.fbs create mode 100644 crates/re_types/definitions/fbs/scalars.fbs create mode 100644 crates/re_types/definitions/python/attributes.fbs create mode 100644 crates/re_types/definitions/rerun/archetypes.fbs create mode 100644 crates/re_types/definitions/rerun/archetypes/points2d.fbs create mode 100644 crates/re_types/definitions/rerun/attributes.fbs create mode 100644 crates/re_types/definitions/rerun/components.fbs create mode 100644 crates/re_types/definitions/rerun/components/class_id.fbs create mode 100644 crates/re_types/definitions/rerun/components/color.fbs create mode 100644 crates/re_types/definitions/rerun/components/draw_order.fbs create mode 100644 crates/re_types/definitions/rerun/components/instance_key.fbs create mode 100644 crates/re_types/definitions/rerun/components/keypoint_id.fbs create mode 100644 crates/re_types/definitions/rerun/components/label.fbs create mode 100644 crates/re_types/definitions/rerun/components/point2d.fbs create mode 100644 crates/re_types/definitions/rerun/components/radius.fbs create mode 100644 crates/re_types/definitions/rerun/datatypes.fbs create mode 100644 crates/re_types/definitions/rerun/datatypes/vec2d.fbs create mode 100644 crates/re_types/definitions/rust/attributes.fbs create mode 100644 crates/re_types/source_hash.txt create mode 100644 crates/re_types/src/archetypes/mod.rs create mode 100644 crates/re_types/src/archetypes/points2d.rs create mode 100644 crates/re_types/src/components/class_id.rs create mode 100644 crates/re_types/src/components/color.rs create mode 100644 crates/re_types/src/components/color_ext.rs create mode 100644 crates/re_types/src/components/draw_order.rs create mode 100644 crates/re_types/src/components/draw_order_ext.rs create mode 100644 crates/re_types/src/components/instance_key.rs create mode 100644 crates/re_types/src/components/instance_key_ext.rs create mode 100644 crates/re_types/src/components/keypoint_id.rs create mode 100644 crates/re_types/src/components/label.rs create mode 100644 crates/re_types/src/components/label_ext.rs create mode 100644 crates/re_types/src/components/mod.rs create mode 100644 crates/re_types/src/components/point2d.rs create mode 100644 crates/re_types/src/components/point2d_ext.rs create mode 100644 crates/re_types/src/components/radius.rs create mode 100644 crates/re_types/src/components/radius_ext.rs create mode 100644 crates/re_types/src/datatypes/mod.rs create mode 100644 crates/re_types/src/datatypes/vec2d.rs create mode 100644 crates/re_types/src/datatypes/vec2d_ext.rs create mode 100644 crates/re_types/src/lib.rs create mode 100644 crates/re_types/tests/points2d.rs create mode 100644 rerun_py/rerun2/__init__.py create mode 100644 rerun_py/rerun2/archetypes/__init__.py create mode 100644 rerun_py/rerun2/archetypes/points2d.py create mode 100644 rerun_py/rerun2/components/__init__.py create mode 100644 rerun_py/rerun2/components/class_id.py create mode 100644 rerun_py/rerun2/components/class_id_ext.py create mode 100644 rerun_py/rerun2/components/color.py create mode 100644 rerun_py/rerun2/components/color_ext.py create mode 100644 rerun_py/rerun2/components/draw_order.py create mode 100644 rerun_py/rerun2/components/draw_order_ext.py create mode 100644 rerun_py/rerun2/components/instance_key.py create mode 100644 rerun_py/rerun2/components/instance_key_ext.py create mode 100644 rerun_py/rerun2/components/keypoint_id.py create mode 100644 rerun_py/rerun2/components/keypoint_id_ext.py create mode 100644 rerun_py/rerun2/components/label.py create mode 100644 rerun_py/rerun2/components/label_ext.py create mode 100644 rerun_py/rerun2/components/point2d.py create mode 100644 rerun_py/rerun2/components/point2d_ext.py create mode 100644 rerun_py/rerun2/components/radius.py create mode 100644 rerun_py/rerun2/components/radius_ext.py create mode 100644 rerun_py/rerun2/datatypes/__init__.py create mode 100644 rerun_py/rerun2/datatypes/vec2d.py create mode 100644 rerun_py/rerun2/datatypes/vec2d_ext.py create mode 100644 rerun_py/tests/unit/test_point2d.py diff --git a/Cargo.lock b/Cargo.lock index 1a250e41f9d8f..3088e82213e48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4495,6 +4495,22 @@ dependencies = [ "web-time", ] +[[package]] +name = "re_types" +version = "0.7.0-alpha.0" +dependencies = [ + "arrow2", + "bytemuck", + "document-features", + "ecolor", + "glam", + "itertools", + "macaw", + "re_build_tools", + "re_types_builder", + "xshell", +] + [[package]] name = "re_types_builder" version = "0.7.0-alpha.0" diff --git a/crates/re_types/Cargo.toml b/crates/re_types/Cargo.toml new file mode 100644 index 0000000000000..e3b1b9dc1b2a1 --- /dev/null +++ b/crates/re_types/Cargo.toml @@ -0,0 +1,61 @@ +[package] +name = "re_types" +authors.workspace = true +description = "The standard Rerun data types, component types, and archetypes." +edition.workspace = true +homepage.workspace = true +include.workspace = true +license.workspace = true +publish = true +readme = "README.md" +repository.workspace = true +rust-version.workspace = true +version.workspace = true + + +[package.metadata.docs.rs] +all-features = true + + +[features] +default = [] + +## Enable color conversions. +ecolor = ["dep:ecolor"] + +## Add support for some math operations using [`glam`](https://crates.io/crates/glam/). +glam = ["dep:glam", "dep:macaw"] + + +[dependencies] + +# External +arrow2 = { workspace = true, features = [ + "io_ipc", + "io_print", + "compute_concatenate", +] } +bytemuck = { version = "1.11", features = ["derive", "extern_crate_alloc"] } +document-features = "0.2" + +# External (optional) +ecolor = { workspace = true, optional = true } +glam = { workspace = true, optional = true } +macaw = { workspace = true, optional = true } + + +[dev-dependencies] + +# External +glam.workspace = true +itertools.workspace = true + + +[build-dependencies] + +# Rerun +re_build_tools.workspace = true +re_types_builder.workspace = true + +# External +xshell = "0.2" diff --git a/crates/re_types/README.md b/crates/re_types/README.md new file mode 100644 index 0000000000000..62c1ebddf06aa --- /dev/null +++ b/crates/re_types/README.md @@ -0,0 +1,12 @@ +# re_types + +Part of the [`rerun`](https://github.com/rerun-io/rerun) family of crates. + +[![Latest version](https://img.shields.io/crates/v/re_types.svg)](https://crates.io/crates/re_types) +[![Documentation](https://docs.rs/re_types/badge.svg)](https://docs.rs/re_types) +![MIT](https://img.shields.io/badge/license-MIT-blue.svg) +![Apache](https://img.shields.io/badge/license-Apache-blue.svg) + +The standard Rerun data types, component types, and archetypes. + +This crate includes both the language-agnostic definitions (flatbuffers IDL) as well as the generated code. diff --git a/crates/re_types/build.rs b/crates/re_types/build.rs new file mode 100644 index 0000000000000..34b976a07ea26 --- /dev/null +++ b/crates/re_types/build.rs @@ -0,0 +1,104 @@ +//! Generates Rust & Python code from flatbuffers definitions. + +use xshell::{cmd, Shell}; + +use re_build_tools::{ + compute_crate_hash, compute_dir_hash, compute_strings_hash, is_tracked_env_var_set, iter_dir, + read_versioning_hash, rerun_if_changed, rerun_if_changed_or_doesnt_exist, + write_versioning_hash, +}; + +// NOTE: Don't need to add extra context to xshell invocations, it does so on its own. + +// --- + +const SOURCE_HASH_PATH: &str = "./source_hash.txt"; +const DEFINITIONS_DIR_PATH: &str = "./definitions"; +const RUST_OUTPUT_DIR_PATH: &str = "."; +const PYTHON_OUTPUT_DIR_PATH: &str = "../../rerun_py/rerun2"; + +fn main() { + if std::env::var("CI").is_ok() { + // Don't run on CI! + // + // The code we're generating here is actual source code that gets committed into the + // repository. + return; + } + + if !is_tracked_env_var_set("IS_IN_RERUN_WORKSPACE") { + // Only run if we are in the rerun workspace, not on users machines. + return; + } + if is_tracked_env_var_set("RERUN_IS_PUBLISHING") { + // We don't need to rebuild - we should have done so beforehand! + // See `RELEASES.md` + return; + } + + rerun_if_changed_or_doesnt_exist(SOURCE_HASH_PATH); + for path in iter_dir(DEFINITIONS_DIR_PATH, Some(&[".fbs"])) { + rerun_if_changed(&path); + } + + // NOTE: We need to hash both the flatbuffers definitions as well as the source code of the + // code generator itself! + let re_types_builder_hash = compute_crate_hash("re_types_builder"); + let cur_hash = read_versioning_hash(SOURCE_HASH_PATH); + let new_hash = compute_dir_hash(DEFINITIONS_DIR_PATH, Some(&[".fbs"])); + let new_hash_final = compute_strings_hash(&[&re_types_builder_hash, &new_hash]); + + // Leave these be please, very useful when debugging. + eprintln!("re_types_builder_hash: {re_types_builder_hash:?}"); + eprintln!("cur_hash: {cur_hash:?}"); + eprintln!("new_hash: {new_hash:?}"); + eprintln!("new_hash_final: {new_hash_final:?}"); + + if let Some(cur_hash) = cur_hash { + if cur_hash == new_hash_final { + // Neither the source of the code generator nor the IDL definitions have changed, no need + // to do anything at this point. + return; + } + } + + let sh = Shell::new().unwrap(); + + re_types_builder::generate_rust_code( + DEFINITIONS_DIR_PATH, + RUST_OUTPUT_DIR_PATH, + "./definitions/rerun/archetypes.fbs", + ); + + // NOTE: We're purposefully ignoring the error here. + // + // In the very unlikely chance that the user doesn't have `cargo` in their $PATH, there's + // still no good reason to fail the build. + // + // The CI will catch the unformatted files at PR time and complain appropriately anyhow. + cmd!(sh, "cargo fmt").run().ok(); + + re_types_builder::generate_python_code( + DEFINITIONS_DIR_PATH, + PYTHON_OUTPUT_DIR_PATH, + "./definitions/rerun/archetypes.fbs", + ); + + // NOTE: We're purposefully ignoring the error here. + // + // If the user doesn't have `black` in their $PATH, there's still no good reason to fail + // the build. + // + // The CI will catch the unformatted files at PR time and complain appropriately anyhow. + cmd!(sh, "black {PYTHON_OUTPUT_DIR_PATH}").run().ok(); + + // NOTE: We're purposefully ignoring the error here. + // + // If the user doesn't have `ruff` in their $PATH, there's still no good reason to fail + // the build. + // + // The CI will catch the unformatted files at PR time and complain appropriately anyhow. + cmd!(sh, "ruff --fix {PYTHON_OUTPUT_DIR_PATH}").run().ok(); + + write_versioning_hash(SOURCE_HASH_PATH, new_hash_final); +} diff --git a/crates/re_types/definitions/arrow/attributes.fbs b/crates/re_types/definitions/arrow/attributes.fbs new file mode 100644 index 0000000000000..54374cc076430 --- /dev/null +++ b/crates/re_types/definitions/arrow/attributes.fbs @@ -0,0 +1,12 @@ +namespace arrow; + +/// Marks a union as sparse from Arrow's standpoint, affecting its Arrow datatype. +/// +/// Only applies to unions. +attribute "arrow.attr.sparse_union"; + +/// Marks a single-field object as transparent from Arrow's standpoint, affecting its Arrow +/// datatype. +/// +/// This is generally most useful for getting rid of extraneous `struct` layers. +attribute "arrow.attr.transparent"; diff --git a/crates/re_types/definitions/fbs/attributes.fbs b/crates/re_types/definitions/fbs/attributes.fbs new file mode 100644 index 0000000000000..9487163b54fb8 --- /dev/null +++ b/crates/re_types/definitions/fbs/attributes.fbs @@ -0,0 +1,16 @@ +namespace fbs.attributes; + +/// Mandatory attribute that applies to all kinds of objects: structs, enums, unions and even the +/// fields within. +/// +/// This defines a stable order between objects of the same kind, e.g. the order in which fields of a +/// struct should be laid out when generating code. +/// This is always required since flatbuffers works entirely with unordered maps internally, which +/// would results in flaky code generation. +/// +/// In unions, this effectively defines the arrow type of each variant, since that depends on the +/// fields's order! +/// +/// NOTE: We do not use flatbuffers' builtin `id` attribute as it only works on `table`s, whereas we +/// need a stable order for all kinds of things. +attribute "order"; diff --git a/crates/re_types/definitions/fbs/reflection.fbs b/crates/re_types/definitions/fbs/reflection.fbs new file mode 100644 index 0000000000000..513311f1b9c3b --- /dev/null +++ b/crates/re_types/definitions/fbs/reflection.fbs @@ -0,0 +1,157 @@ +// This schema defines objects that represent a parsed schema, like +// the binary version of a .fbs file. +// This could be used to operate on unknown FlatBuffers at runtime. +// It can even ... represent itself (!) + +namespace reflection; + +// These must correspond to the enum in idl.h. +enum BaseType : byte { + None, + UType, + Bool, + Byte, + UByte, + Short, + UShort, + Int, + UInt, + Long, + ULong, + Float, + Double, + String, + Vector, + Obj, // Used for tables & structs. + Union, + Array, + Vector64, + + // Add any new type above this value. + MaxBaseType +} + +table Type { + base_type:BaseType; + element:BaseType = None; // Only if base_type == Vector + // or base_type == Array. + index:int = -1; // If base_type == Object, index into "objects" below. + // If base_type == Union, UnionType, or integral derived + // from an enum, index into "enums" below. + // If base_type == Vector && element == Union or UnionType. + fixed_length:uint16 = 0; // Only if base_type == Array. + /// The size (octets) of the `base_type` field. + base_size:uint = 4; // 4 Is a common size due to offsets being that size. + /// The size (octets) of the `element` field, if present. + element_size:uint = 0; +} + +table KeyValue { + key:string (required, key); + value:string; +} + +table EnumVal { + name:string (required); + value:long (key); + object:Object (deprecated); + union_type:Type; + documentation:[string]; + attributes:[KeyValue]; +} + +table Enum { + name:string (required, key); + values:[EnumVal] (required); // In order of their values. + is_union:bool = false; + underlying_type:Type (required); + attributes:[KeyValue]; + documentation:[string]; + /// File that this Enum is declared in. + declaration_file: string; +} + +table Field { + name:string (required, key); + type:Type (required); + id:ushort; + offset:ushort; // Offset into the vtable for tables, or into the struct. + default_integer:long = 0; + default_real:double = 0.0; + deprecated:bool = false; + required:bool = false; + key:bool = false; + attributes:[KeyValue]; + documentation:[string]; + optional:bool = false; + /// Number of padding octets to always add after this field. Structs only. + padding:uint16 = 0; + /// If the field uses 64-bit offsets. + offset64:bool = false; +} + +table Object { // Used for both tables and structs. + name:string (required, key); + fields:[Field] (required); // Sorted. + is_struct:bool = false; + minalign:int; + bytesize:int; // For structs. + attributes:[KeyValue]; + documentation:[string]; + /// File that this Object is declared in. + declaration_file: string; +} + +table RPCCall { + name:string (required, key); + request:Object (required); // must be a table (not a struct) + response:Object (required); // must be a table (not a struct) + attributes:[KeyValue]; + documentation:[string]; +} + +table Service { + name:string (required, key); + calls:[RPCCall]; + attributes:[KeyValue]; + documentation:[string]; + /// File that this Service is declared in. + declaration_file: string; +} + +/// New schema language features that are not supported by old code generators. +enum AdvancedFeatures : ulong (bit_flags) { + AdvancedArrayFeatures, + AdvancedUnionFeatures, + OptionalScalars, + DefaultVectorsAndStrings, +} + +/// File specific information. +/// Symbols declared within a file may be recovered by iterating over all +/// symbols and examining the `declaration_file` field. +table SchemaFile { + /// Filename, relative to project root. + filename:string (required, key); + /// Names of included files, relative to project root. + included_filenames:[string]; +} + +table Schema { + objects:[Object] (required); // Sorted. + enums:[Enum] (required); // Sorted. + file_ident:string; + file_ext:string; + root_table:Object; + services:[Service]; // Sorted. + advanced_features:AdvancedFeatures; + /// All the files used in this compilation. Files are relative to where + /// flatc was invoked. + fbs_files:[SchemaFile]; // Sorted. +} + +root_type Schema; + +file_identifier "BFBS"; +file_extension "bfbs"; + diff --git a/crates/re_types/definitions/fbs/scalars.fbs b/crates/re_types/definitions/fbs/scalars.fbs new file mode 100644 index 0000000000000..bb6fcd75063b2 --- /dev/null +++ b/crates/re_types/definitions/fbs/scalars.fbs @@ -0,0 +1,10 @@ +/// Unions cannot directly refer to scalar types, they need to be wrapped in a struct or table +/// first. +/// This package provides pre-wrapped scalars that will be automatically flattened down to their +/// inner type by our parsers. +namespace fbs.scalars; + +/// Flattens down to a 32-bit float. +struct Float32 { + v: float; +} diff --git a/crates/re_types/definitions/python/attributes.fbs b/crates/re_types/definitions/python/attributes.fbs new file mode 100644 index 0000000000000..99b357f72abf3 --- /dev/null +++ b/crates/re_types/definitions/python/attributes.fbs @@ -0,0 +1,16 @@ +namespace python.attributes; + +/// Marks a field as transparent, meaning its type will be replaced by the underlying type. +/// +/// Only applies to field whose types have a single-field. +attribute "python.attr.transparent"; + +/// Defines the type aliases for a component, e.g. the types that make up `ComponentLike`. +/// +/// Only applies to structs/unions that are components. +attribute "python.attr.aliases"; + +/// Defines the array type aliases for a component, e.g. the types that make up `ComponentArrayLike`. +/// +/// Only applies to structs/unions that are components. +attribute "python.attr.array_aliases"; diff --git a/crates/re_types/definitions/rerun/archetypes.fbs b/crates/re_types/definitions/rerun/archetypes.fbs new file mode 100644 index 0000000000000..3b8c926f33a2f --- /dev/null +++ b/crates/re_types/definitions/rerun/archetypes.fbs @@ -0,0 +1,3 @@ +include "./archetypes/points2d.fbs"; + +namespace rerun.archetypes; diff --git a/crates/re_types/definitions/rerun/archetypes/points2d.fbs b/crates/re_types/definitions/rerun/archetypes/points2d.fbs new file mode 100644 index 0000000000000..10d5c3361ca52 --- /dev/null +++ b/crates/re_types/definitions/rerun/archetypes/points2d.fbs @@ -0,0 +1,62 @@ +include "fbs/attributes.fbs"; + +include "rerun/datatypes.fbs"; +include "rerun/components.fbs"; + +namespace rerun.archetypes; + +// --- + +// TODO(cmc): archetype IDL definitions must always be tables +// TODO(cmc): archetype IDL definitions must refer to objects of kind component + +/// A 2D point cloud with positions and optional colors, radii, labels, etc. +table Points2D ( + "rust.attr.derive": "Debug, Clone, PartialEq", + order: 100 +) { + // --- Required --- + + /// All the actual 2D points that make up the point cloud. + points: [rerun.components.Point2D] ("rerun.attr.component_required", required, order: 1000); + + // --- Recommended --- + + /// Optional radii for the points, effectively turning them into circles. + radii: [rerun.components.Radius] ("rerun.attr.component_recommended", order: 2000); + + /// Optional colors for the points. + /// + /// \python The colors are interpreted as RGB or RGBA in sRGB gamma-space, + /// \python As either 0-1 floats or 0-255 integers, with separate alpha. + colors: [rerun.components.Color] ("rerun.attr.component_recommended", order: 2100); + + // --- Optional --- + + /// Optional text labels for the points. + labels: [rerun.components.Label] ("rerun.attr.component_optional", order: 3000); + + /// 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. + draw_order: rerun.components.DrawOrder ("rerun.attr.component_optional", order: 3100); + + /// Optional class Ids for the points. + /// + /// The class ID provides colors and labels if not specified explicitly. + class_ids: [rerun.components.ClassId] ("rerun.attr.component_optional", order: 3200); + + /// 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. + keypoint_ids: [rerun.components.KeypointId] ("rerun.attr.component_optional", order: 3300); + + /// Unique identifiers for each individual point in the batch. + instance_keys: [rerun.components.InstanceKey] ("rerun.attr.component_optional", order: 3400); +} diff --git a/crates/re_types/definitions/rerun/attributes.fbs b/crates/re_types/definitions/rerun/attributes.fbs new file mode 100644 index 0000000000000..3cc2c2519f91e --- /dev/null +++ b/crates/re_types/definitions/rerun/attributes.fbs @@ -0,0 +1,19 @@ +namespace rerun.attributes; + +/// Marks a component as required, which is likely to impact the generated code in +/// backend-specific ways. +/// +/// Only applies to the fields of an archetype. +attribute "rerun.attr.component_required"; + +/// Marks a component as recommended, which is likely to impact the generated code in +/// backend-specific ways. +/// +/// Only applies to the fields of an archetype. +attribute "rerun.attr.component_recommended"; + +/// Marks a component as optional, which is likely to impact the generated code in +/// ways. +/// +/// Only applies to the fields of an archetype. +attribute "rerun.attr.component_optional"; diff --git a/crates/re_types/definitions/rerun/components.fbs b/crates/re_types/definitions/rerun/components.fbs new file mode 100644 index 0000000000000..bc1b16ff6953d --- /dev/null +++ b/crates/re_types/definitions/rerun/components.fbs @@ -0,0 +1,8 @@ +include "./components/class_id.fbs"; +include "./components/color.fbs"; +include "./components/draw_order.fbs"; +include "./components/instance_key.fbs"; +include "./components/keypoint_id.fbs"; +include "./components/label.fbs"; +include "./components/point2d.fbs"; +include "./components/radius.fbs"; diff --git a/crates/re_types/definitions/rerun/components/class_id.fbs b/crates/re_types/definitions/rerun/components/class_id.fbs new file mode 100644 index 0000000000000..12b96f224a5ac --- /dev/null +++ b/crates/re_types/definitions/rerun/components/class_id.fbs @@ -0,0 +1,23 @@ +include "arrow/attributes.fbs"; +include "python/attributes.fbs"; +include "rust/attributes.fbs"; + +include "rerun/attributes.fbs"; + +namespace rerun.components; + +// --- + +/// A 16-bit ID representing a type of semantic class. +/// +/// \rs Used to look up a `crate::components::ClassDescription` within the `crate::components::AnnotationContext`. +struct ClassId ( + "arrow.attr.transparent", + "python.attr.aliases": "float", + "python.attr.array_aliases": "npt.NDArray[np.uint8], npt.NDArray[np.uint16], npt.NDArray[np.uint32]", + "rust.attr.derive": "Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash", + "rust.attr.tuple_struct", + order: 100 +) { + id: ushort; +} diff --git a/crates/re_types/definitions/rerun/components/color.fbs b/crates/re_types/definitions/rerun/components/color.fbs new file mode 100644 index 0000000000000..483515843f67c --- /dev/null +++ b/crates/re_types/definitions/rerun/components/color.fbs @@ -0,0 +1,23 @@ +include "arrow/attributes.fbs"; +include "python/attributes.fbs"; +include "rust/attributes.fbs"; + +include "rerun/attributes.fbs"; +include "rerun/datatypes.fbs"; + +namespace rerun.components; + +// --- + +/// An RGBA color tuple with unmultiplied/separate alpha, in sRGB gamma space with linear alpha. +struct Color ( + "arrow.attr.transparent", + "python.attr.aliases": "Sequence[int], Sequence[float], npt.NDArray[np.uint8], npt.NDArray[np.float32], npt.NDArray[np.float64]", + "python.attr.array_aliases": "Sequence[int], Sequence[float], npt.NDArray[np.uint8], npt.NDArray[np.float32], npt.NDArray[np.float64]", + "rust.attr.derive": "Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, bytemuck::Pod, bytemuck::Zeroable", + "rust.attr.repr": "transparent", + "rust.attr.tuple_struct", + order: 100 +) { + rgba: uint; +} diff --git a/crates/re_types/definitions/rerun/components/draw_order.fbs b/crates/re_types/definitions/rerun/components/draw_order.fbs new file mode 100644 index 0000000000000..ada594b8cf51f --- /dev/null +++ b/crates/re_types/definitions/rerun/components/draw_order.fbs @@ -0,0 +1,29 @@ +include "arrow/attributes.fbs"; +include "python/attributes.fbs"; +include "rust/attributes.fbs"; + +include "rerun/datatypes.fbs"; +include "rerun/attributes.fbs"; + +namespace rerun.components; + +// --- + +/// 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. +struct DrawOrder ( + "arrow.attr.transparent", + "python.attr.aliases": "float", + "python.attr.array_aliases": "npt.NDArray[np.float32]", + "rust.attr.derive": "Debug, Clone, Copy", + "rust.attr.repr": "transparent", + "rust.attr.tuple_struct", + order: 100 +) { + value: float; +} diff --git a/crates/re_types/definitions/rerun/components/instance_key.fbs b/crates/re_types/definitions/rerun/components/instance_key.fbs new file mode 100644 index 0000000000000..77002e48467f3 --- /dev/null +++ b/crates/re_types/definitions/rerun/components/instance_key.fbs @@ -0,0 +1,22 @@ +include "arrow/attributes.fbs"; +include "python/attributes.fbs"; +include "rust/attributes.fbs"; + +include "rerun/datatypes.fbs"; +include "rerun/attributes.fbs"; + +namespace rerun.components; + +// --- + +/// A unique numeric identifier for each individual instance within a batch. +struct InstanceKey ( + "arrow.attr.transparent", + "python.attr.aliases": "int", + "python.attr.array_aliases": "npt.NDArray[np.uint64]", + "rust.attr.tuple_struct", + "rust.attr.derive": "Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord", + order: 100 +) { + value: uint64; +} diff --git a/crates/re_types/definitions/rerun/components/keypoint_id.fbs b/crates/re_types/definitions/rerun/components/keypoint_id.fbs new file mode 100644 index 0000000000000..a0f5f0ce483c4 --- /dev/null +++ b/crates/re_types/definitions/rerun/components/keypoint_id.fbs @@ -0,0 +1,30 @@ +include "arrow/attributes.fbs"; +include "python/attributes.fbs"; +include "rust/attributes.fbs"; + +include "rerun/attributes.fbs"; + +namespace rerun.components; + +// --- + +/// A 16-bit ID representing a type of semantic keypoint within a class. +/// +/// \py `KeypointId`s are only meaningful within the context of a [`rerun.components.ClassDescription`][]. +/// \py +/// \py Used to look up an [`rerun.components.AnnotationInfo`][] for a Keypoint within the +/// \py [`rerun.components.AnnotationContext`]. +/// +/// \rs `KeypointId`s are only meaningful within the context of a `crate::components::ClassDescription`. +/// \rs +/// \rs Used to look up an `crate::components::AnnotationInfo` for a Keypoint within the `crate::components::AnnotationContext`. +struct KeypointId ( + "arrow.attr.transparent", + "python.attr.aliases": "float", + "python.attr.array_aliases": "npt.NDArray[np.uint8], npt.NDArray[np.uint16], npt.NDArray[np.uint32]", + "rust.attr.derive": "Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash", + "rust.attr.tuple_struct", + order: 200 +) { + id: ushort; +} diff --git a/crates/re_types/definitions/rerun/components/label.fbs b/crates/re_types/definitions/rerun/components/label.fbs new file mode 100644 index 0000000000000..ad70138af361a --- /dev/null +++ b/crates/re_types/definitions/rerun/components/label.fbs @@ -0,0 +1,22 @@ +include "arrow/attributes.fbs"; +include "python/attributes.fbs"; +include "rust/attributes.fbs"; + +include "rerun/datatypes.fbs"; +include "rerun/attributes.fbs"; + +namespace rerun.components; + +// --- + +/// A String label component. +table Label ( + "arrow.attr.transparent", + "python.attr.aliases": "str", + "rust.attr.derive": "Debug, Clone, PartialEq, Eq, PartialOrd, Ord", + "rust.attr.repr": "transparent", + "rust.attr.tuple_struct", + order: 100 +) { + value: string (required, order: 100); +} diff --git a/crates/re_types/definitions/rerun/components/point2d.fbs b/crates/re_types/definitions/rerun/components/point2d.fbs new file mode 100644 index 0000000000000..a75496bd00cd7 --- /dev/null +++ b/crates/re_types/definitions/rerun/components/point2d.fbs @@ -0,0 +1,25 @@ +include "arrow/attributes.fbs"; +include "python/attributes.fbs"; +include "rust/attributes.fbs"; + +include "rerun/datatypes.fbs"; +include "rerun/attributes.fbs"; + +namespace rerun.components; + +// --- + +/// A point in 2D space. +struct Point2D ( + "arrow.attr.transparent", + "python.attr.aliases": "npt.NDArray[np.float32], Sequence[float], Tuple[float, float]", + "python.attr.array_aliases": "npt.NDArray[np.float32], Sequence[float]", + "rust.attr.tuple_struct", + "rust.attr.derive": "Debug, Default, Clone, Copy, PartialEq, PartialOrd", + order: 100 +) { + position: rerun.datatypes.Vec2D ( + "python.attr.transparent", + order: 100 + ); +} diff --git a/crates/re_types/definitions/rerun/components/radius.fbs b/crates/re_types/definitions/rerun/components/radius.fbs new file mode 100644 index 0000000000000..cfa68c185885d --- /dev/null +++ b/crates/re_types/definitions/rerun/components/radius.fbs @@ -0,0 +1,22 @@ +include "arrow/attributes.fbs"; +include "python/attributes.fbs"; +include "rust/attributes.fbs"; + +include "rerun/datatypes.fbs"; +include "rerun/attributes.fbs"; + +namespace rerun.components; + +// --- + +/// A Radius component. +struct Radius ( + "arrow.attr.transparent", + "python.attr.aliases": "float", + "python.attr.array_aliases": "npt.NDArray[np.float32]", + "rust.attr.tuple_struct", + "rust.attr.derive": "Debug, Clone, Copy, PartialEq, PartialOrd", + order: 100 +) { + value: float; +} diff --git a/crates/re_types/definitions/rerun/datatypes.fbs b/crates/re_types/definitions/rerun/datatypes.fbs new file mode 100644 index 0000000000000..3048df042e85e --- /dev/null +++ b/crates/re_types/definitions/rerun/datatypes.fbs @@ -0,0 +1,3 @@ +include "./datatypes/vec2d.fbs"; + +namespace rerun.datatypes; diff --git a/crates/re_types/definitions/rerun/datatypes/vec2d.fbs b/crates/re_types/definitions/rerun/datatypes/vec2d.fbs new file mode 100644 index 0000000000000..db6f976820e70 --- /dev/null +++ b/crates/re_types/definitions/rerun/datatypes/vec2d.fbs @@ -0,0 +1,17 @@ +include "arrow/attributes.fbs"; +include "fbs/attributes.fbs"; +include "rust/attributes.fbs"; + +namespace rerun.datatypes; + +// --- + +/// A vector in 2D space. +struct Vec2D ( + "arrow.attr.transparent", + "rust.attr.derive": "Debug, Default, Clone, Copy, PartialEq, PartialOrd", + "rust.attr.tuple_struct", + order: 100 +) { + xy: [float: 2]; +} diff --git a/crates/re_types/definitions/rust/attributes.fbs b/crates/re_types/definitions/rust/attributes.fbs new file mode 100644 index 0000000000000..58a8fac6b0706 --- /dev/null +++ b/crates/re_types/definitions/rust/attributes.fbs @@ -0,0 +1,15 @@ +namespace rust.attributes; + +/// Apply to a struct or table object to generate a tuple struct. +/// +/// The type definition of the target object must have exactly a single field. +attribute "rust.attr.tuple_struct"; + +/// Apply to any object to generate a #derive clause. +/// +/// The value of the attribute will be trimmed out but otherwise left as-is. +/// E.g. "rust.attr.derive": "Debug, Clone, Copy"`. +attribute "rust.attr.derive"; + +/// Apply to any object to generate a #repr clause with the specified value. +attribute "rust.attr.repr"; diff --git a/crates/re_types/source_hash.txt b/crates/re_types/source_hash.txt new file mode 100644 index 0000000000000..a9df68e60ef72 --- /dev/null +++ b/crates/re_types/source_hash.txt @@ -0,0 +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. +138919a69acfa38f9606b32e9113deb9d16c987262b9450d56b261115827a14f \ No newline at end of file diff --git a/crates/re_types/src/archetypes/mod.rs b/crates/re_types/src/archetypes/mod.rs new file mode 100644 index 0000000000000..d1e7d85ddc779 --- /dev/null +++ b/crates/re_types/src/archetypes/mod.rs @@ -0,0 +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 0000000000000..c08c438dcdf41 --- /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: [::std::borrow::Cow<'static, str>; 1] = + [::std::borrow::Cow::Borrowed("rerun.components.Point2D")]; + + pub const RECOMMENDED_COMPONENTS: [::std::borrow::Cow<'static, str>; 2] = [ + ::std::borrow::Cow::Borrowed("rerun.components.Radius"), + ::std::borrow::Cow::Borrowed("rerun.components.Color"), + ]; + + pub const OPTIONAL_COMPONENTS: [::std::borrow::Cow<'static, str>; 5] = [ + ::std::borrow::Cow::Borrowed("rerun.components.Label"), + ::std::borrow::Cow::Borrowed("rerun.components.DrawOrder"), + ::std::borrow::Cow::Borrowed("rerun.components.ClassId"), + ::std::borrow::Cow::Borrowed("rerun.components.KeypointId"), + ::std::borrow::Cow::Borrowed("rerun.components.InstanceKey"), + ]; + + pub const ALL_COMPONENTS: [::std::borrow::Cow<'static, str>; 8] = [ + ::std::borrow::Cow::Borrowed("rerun.components.Point2D"), + ::std::borrow::Cow::Borrowed("rerun.components.Radius"), + ::std::borrow::Cow::Borrowed("rerun.components.Color"), + ::std::borrow::Cow::Borrowed("rerun.components.Label"), + ::std::borrow::Cow::Borrowed("rerun.components.DrawOrder"), + ::std::borrow::Cow::Borrowed("rerun.components.ClassId"), + ::std::borrow::Cow::Borrowed("rerun.components.KeypointId"), + ::std::borrow::Cow::Borrowed("rerun.components.InstanceKey"), + ]; +} + +impl crate::Archetype for Points2D { + fn name() -> ::std::borrow::Cow<'static, str> { + ::std::borrow::Cow::Borrowed("rerun.archetypes.Points2D") + } + + fn required_components() -> Vec<::std::borrow::Cow<'static, str>> { + Self::REQUIRED_COMPONENTS.to_vec() + } + + fn recommended_components() -> Vec<::std::borrow::Cow<'static, str>> { + Self::RECOMMENDED_COMPONENTS.to_vec() + } + + fn optional_components() -> Vec<::std::borrow::Cow<'static, str>> { + 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 0000000000000..9d11e8dbb7886 --- /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() -> ::std::borrow::Cow<'static, str> { + ::std::borrow::Cow::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 0000000000000..97731490070f8 --- /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() -> ::std::borrow::Cow<'static, str> { + ::std::borrow::Cow::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/color_ext.rs b/crates/re_types/src/components/color_ext.rs new file mode 100644 index 0000000000000..093b72480ad1f --- /dev/null +++ b/crates/re_types/src/components/color_ext.rs @@ -0,0 +1,43 @@ +use super::Color; + +impl Color { + #[inline] + pub fn from_rgb(r: u8, g: u8, b: u8) -> Self { + Self::from([r, g, b, 255]) + } + + #[inline] + pub fn from_unmultiplied_rgba(r: u8, g: u8, b: u8, a: u8) -> Self { + Self::from([r, g, b, a]) + } + + #[inline] + pub fn to_array(&self) -> [u8; 4] { + [ + (self.0 >> 24) as u8, + (self.0 >> 16) as u8, + (self.0 >> 8) as u8, + self.0 as u8, + ] + } +} + +impl From<[u8; 4]> for Color { + #[inline] + fn from(bytes: [u8; 4]) -> Self { + Self( + (bytes[0] as u32) << 24 + | (bytes[1] as u32) << 16 + | (bytes[2] as u32) << 8 + | (bytes[3] as u32), + ) + } +} + +#[cfg(feature = "ecolor")] +impl From for ecolor::Color32 { + fn from(color: Color) -> Self { + let [r, g, b, a] = color.to_array(); + Self::from_rgba_premultiplied(r, g, b, a) + } +} 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 0000000000000..3161f98238492 --- /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)] +#[repr(transparent)] +pub struct DrawOrder(pub f32); + +impl crate::Component for DrawOrder { + fn name() -> ::std::borrow::Cow<'static, str> { + ::std::borrow::Cow::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/draw_order_ext.rs b/crates/re_types/src/components/draw_order_ext.rs new file mode 100644 index 0000000000000..f99f10213c56a --- /dev/null +++ b/crates/re_types/src/components/draw_order_ext.rs @@ -0,0 +1,60 @@ +use super::DrawOrder; + +// TODO(cmc): come up with some DSL in our flatbuffers definitions so that we can declare these +// constants directly in there. +impl DrawOrder { + /// Draw order used for images if no draw order was specified. + pub const DEFAULT_IMAGE: DrawOrder = DrawOrder(-10.0); + + /// Draw order used for 2D boxes if no draw order was specified. + pub const DEFAULT_BOX2D: DrawOrder = DrawOrder(10.0); + + /// Draw order used for 2D lines if no draw order was specified. + pub const DEFAULT_LINES2D: DrawOrder = DrawOrder(20.0); + + /// Draw order used for 2D points if no draw order was specified. + pub const DEFAULT_POINTS2D: DrawOrder = DrawOrder(30.0); +} + +impl std::cmp::PartialEq for DrawOrder { + #[inline] + fn eq(&self, other: &Self) -> bool { + self.0.is_nan() && other.0.is_nan() || self.0 == other.0 + } +} + +impl std::cmp::Eq for DrawOrder {} + +impl std::cmp::PartialOrd for DrawOrder { + #[inline] + fn partial_cmp(&self, other: &Self) -> Option { + if other == self { + Some(std::cmp::Ordering::Equal) + } else if other.0.is_nan() || self.0 < other.0 { + Some(std::cmp::Ordering::Less) + } else { + Some(std::cmp::Ordering::Greater) + } + } +} + +impl std::cmp::Ord for DrawOrder { + #[inline] + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.partial_cmp(other).unwrap() + } +} + +impl From for DrawOrder { + #[inline] + fn from(value: f32) -> Self { + Self(value) + } +} + +impl From for f32 { + #[inline] + fn from(value: DrawOrder) -> Self { + value.0 + } +} 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 0000000000000..1dd0061609be2 --- /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() -> ::std::borrow::Cow<'static, str> { + ::std::borrow::Cow::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/instance_key_ext.rs b/crates/re_types/src/components/instance_key_ext.rs new file mode 100644 index 0000000000000..c7a40974ebecc --- /dev/null +++ b/crates/re_types/src/components/instance_key_ext.rs @@ -0,0 +1,22 @@ +use super::InstanceKey; + +// TODO(cmc): come up with some DSL in our flatbuffers definitions so that we can declare these +// constants directly in there. +impl InstanceKey { + /// Draw order used for images if no draw order was specified. + pub const SPLAT: Self = Self(u64::MAX); +} + +impl From for InstanceKey { + #[inline] + fn from(value: u64) -> Self { + Self(value) + } +} + +impl From for u64 { + #[inline] + fn from(value: InstanceKey) -> Self { + value.0 + } +} 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 0000000000000..878aec47f1db2 --- /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() -> ::std::borrow::Cow<'static, str> { + ::std::borrow::Cow::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 0000000000000..9da8ce4941ab6 --- /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() -> ::std::borrow::Cow<'static, str> { + ::std::borrow::Cow::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/label_ext.rs b/crates/re_types/src/components/label_ext.rs new file mode 100644 index 0000000000000..679284f2b05da --- /dev/null +++ b/crates/re_types/src/components/label_ext.rs @@ -0,0 +1,51 @@ +use super::Label; + +impl Label { + #[inline] + pub fn as_str(&self) -> &str { + self.0.as_str() + } +} + +impl From for Label { + #[inline] + fn from(value: String) -> Self { + Self(value) + } +} + +impl From<&str> for Label { + #[inline] + fn from(value: &str) -> Self { + Self(value.to_owned()) + } +} + +impl From