From ee949214b294b610925d8b5b7b97d97719530a68 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Mon, 4 Mar 2024 17:31:48 +0100 Subject: [PATCH 1/9] space view class is now a regular utf8 string. Started tests for space view blueprint --- .../blueprint/components/space_view_class.fbs | 11 ++-- .../blueprint/components/space_view_class.rs | 58 +++++++++++++------ .../blueprint/components/space_view_class.cpp | 26 ++++----- .../blueprint/components/space_view_class.hpp | 15 ++++- .../archetypes/space_view_blueprint.py | 2 +- .../rerun/blueprint/components/__init__.py | 10 +--- .../blueprint/components/space_view_class.py | 49 +++------------- .../tests/unit/test_space_view_blueprint.py | 38 ++++++++++++ 8 files changed, 120 insertions(+), 89 deletions(-) create mode 100644 rerun_py/tests/unit/test_space_view_blueprint.py diff --git a/crates/re_types/definitions/rerun/blueprint/components/space_view_class.fbs b/crates/re_types/definitions/rerun/blueprint/components/space_view_class.fbs index 7af5f0b3e2e7..3473172b4509 100644 --- a/crates/re_types/definitions/rerun/blueprint/components/space_view_class.fbs +++ b/crates/re_types/definitions/rerun/blueprint/components/space_view_class.fbs @@ -11,9 +11,12 @@ namespace rerun.blueprint.components; /// The class of a `SpaceView`. table SpaceViewClass ( - "attr.rerun.scope": "blueprint", - "attr.rust.derive": "Default, PartialEq, Eq, PartialOrd, Ord", - "attr.rust.repr": "transparent" + "attr.arrow.transparent", + "attr.rerun.scope": "blueprint", + "attr.python.aliases": "str", + "attr.python.array_aliases": "str, Sequence[str]", + "attr.rust.derive": "PartialEq, Eq, PartialOrd, Ord", + "attr.rust.repr": "transparent" ) { - value: string (order: 100); + value: rerun.datatypes.Utf8 (order: 100); } diff --git a/crates/re_types/src/blueprint/components/space_view_class.rs b/crates/re_types/src/blueprint/components/space_view_class.rs index c2d2a38975b4..2060d254b5f8 100644 --- a/crates/re_types/src/blueprint/components/space_view_class.rs +++ b/crates/re_types/src/blueprint/components/space_view_class.rs @@ -22,9 +22,9 @@ use ::re_types_core::{ComponentBatch, MaybeOwnedComponentBatch}; use ::re_types_core::{DeserializationError, DeserializationResult}; /// **Component**: The class of a `SpaceView`. -#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] #[repr(transparent)] -pub struct SpaceViewClass(pub ::re_types_core::ArrowString); +pub struct SpaceViewClass(pub crate::datatypes::Utf8); impl ::re_types_core::SizeBytes for SpaceViewClass { #[inline] @@ -34,21 +34,29 @@ impl ::re_types_core::SizeBytes for SpaceViewClass { #[inline] fn is_pod() -> bool { - <::re_types_core::ArrowString>::is_pod() + ::is_pod() } } -impl From<::re_types_core::ArrowString> for SpaceViewClass { +impl> From for SpaceViewClass { + fn from(v: T) -> Self { + Self(v.into()) + } +} + +impl std::borrow::Borrow for SpaceViewClass { #[inline] - fn from(value: ::re_types_core::ArrowString) -> Self { - Self(value) + fn borrow(&self) -> &crate::datatypes::Utf8 { + &self.0 } } -impl From for ::re_types_core::ArrowString { +impl std::ops::Deref for SpaceViewClass { + type Target = crate::datatypes::Utf8; + #[inline] - fn from(value: SpaceViewClass) -> Self { - value.0 + fn deref(&self) -> &crate::datatypes::Utf8 { + &self.0 } } @@ -95,15 +103,25 @@ impl ::re_types_core::Loggable for SpaceViewClass { any_nones.then(|| somes.into()) }; { - let inner_data: arrow2::buffer::Buffer = - data0.iter().flatten().flat_map(|s| s.0.clone()).collect(); - let offsets = arrow2::offset::Offsets::::try_from_lengths( - data0 - .iter() - .map(|opt| opt.as_ref().map(|datum| datum.0.len()).unwrap_or_default()), - ) - .unwrap() - .into(); + let inner_data: arrow2::buffer::Buffer = data0 + .iter() + .flatten() + .flat_map(|datum| { + let crate::datatypes::Utf8(data0) = datum; + data0.0.clone() + }) + .collect(); + let offsets = + arrow2::offset::Offsets::::try_from_lengths(data0.iter().map(|opt| { + opt.as_ref() + .map(|datum| { + let crate::datatypes::Utf8(data0) = datum; + data0.0.len() + }) + .unwrap_or_default() + })) + .unwrap() + .into(); #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)] unsafe { @@ -162,7 +180,9 @@ impl ::re_types_core::Loggable for SpaceViewClass { .transpose() }) .map(|res_or_opt| { - res_or_opt.map(|res_or_opt| res_or_opt.map(|v| ::re_types_core::ArrowString(v))) + res_or_opt.map(|res_or_opt| { + res_or_opt.map(|v| crate::datatypes::Utf8(::re_types_core::ArrowString(v))) + }) }) .collect::>>>() .with_context("rerun.blueprint.components.SpaceViewClass#value")? diff --git a/rerun_cpp/src/rerun/blueprint/components/space_view_class.cpp b/rerun_cpp/src/rerun/blueprint/components/space_view_class.cpp index cd3d52b329f7..2badc811cb5c 100644 --- a/rerun_cpp/src/rerun/blueprint/components/space_view_class.cpp +++ b/rerun_cpp/src/rerun/blueprint/components/space_view_class.cpp @@ -3,6 +3,8 @@ #include "space_view_class.hpp" +#include "../../datatypes/utf8.hpp" + #include #include @@ -11,7 +13,7 @@ namespace rerun::blueprint::components {} namespace rerun { const std::shared_ptr& Loggable::arrow_datatype() { - static const auto datatype = arrow::utf8(); + static const auto datatype = Loggable::arrow_datatype(); return datatype; } @@ -19,20 +21,14 @@ namespace rerun { arrow::StringBuilder* builder, const blueprint::components::SpaceViewClass* elements, size_t num_elements ) { - if (builder == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - ARROW_RETURN_NOT_OK(builder->Append(elements[elem_idx].value)); - } + static_assert( + sizeof(rerun::datatypes::Utf8) == sizeof(blueprint::components::SpaceViewClass) + ); + RR_RETURN_NOT_OK(Loggable::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); return Error::ok(); } diff --git a/rerun_cpp/src/rerun/blueprint/components/space_view_class.hpp b/rerun_cpp/src/rerun/blueprint/components/space_view_class.hpp index cc706792626a..428aa26db77c 100644 --- a/rerun_cpp/src/rerun/blueprint/components/space_view_class.hpp +++ b/rerun_cpp/src/rerun/blueprint/components/space_view_class.hpp @@ -3,6 +3,7 @@ #pragma once +#include "../../datatypes/utf8.hpp" #include "../../result.hpp" #include @@ -19,17 +20,29 @@ namespace arrow { namespace rerun::blueprint::components { /// **Component**: The class of a `SpaceView`. struct SpaceViewClass { - std::string value; + rerun::datatypes::Utf8 value; public: SpaceViewClass() = default; + SpaceViewClass(rerun::datatypes::Utf8 value_) : value(std::move(value_)) {} + + SpaceViewClass& operator=(rerun::datatypes::Utf8 value_) { + value = std::move(value_); + return *this; + } + SpaceViewClass(std::string value_) : value(std::move(value_)) {} SpaceViewClass& operator=(std::string value_) { value = std::move(value_); return *this; } + + /// Cast to the underlying Utf8 datatype + operator rerun::datatypes::Utf8() const { + return value; + } }; } // namespace rerun::blueprint::components diff --git a/rerun_py/rerun_sdk/rerun/blueprint/archetypes/space_view_blueprint.py b/rerun_py/rerun_sdk/rerun/blueprint/archetypes/space_view_blueprint.py index 61eabd7d801d..266353cc83b9 100644 --- a/rerun_py/rerun_sdk/rerun/blueprint/archetypes/space_view_blueprint.py +++ b/rerun_py/rerun_sdk/rerun/blueprint/archetypes/space_view_blueprint.py @@ -23,7 +23,7 @@ class SpaceViewBlueprint(Archetype): def __init__( self: Any, - class_identifier: blueprint_components.SpaceViewClassLike, + class_identifier: datatypes.Utf8Like, *, display_name: datatypes.Utf8Like | None = None, space_origin: datatypes.EntityPathLike | None = None, diff --git a/rerun_py/rerun_sdk/rerun/blueprint/components/__init__.py b/rerun_py/rerun_sdk/rerun/blueprint/components/__init__.py index a0f0cc5e59c6..4fde4821b7fe 100644 --- a/rerun_py/rerun_sdk/rerun/blueprint/components/__init__.py +++ b/rerun_py/rerun_sdk/rerun/blueprint/components/__init__.py @@ -67,13 +67,7 @@ ) from .root_container import RootContainer, RootContainerBatch, RootContainerType from .row_shares import RowShares, RowSharesArrayLike, RowSharesBatch, RowSharesLike, RowSharesType -from .space_view_class import ( - SpaceViewClass, - SpaceViewClassArrayLike, - SpaceViewClassBatch, - SpaceViewClassLike, - SpaceViewClassType, -) +from .space_view_class import SpaceViewClass, SpaceViewClassBatch, SpaceViewClassType from .space_view_maximized import SpaceViewMaximized, SpaceViewMaximizedBatch, SpaceViewMaximizedType from .space_view_origin import SpaceViewOrigin, SpaceViewOriginBatch, SpaceViewOriginType from .visible import Visible, VisibleArrayLike, VisibleBatch, VisibleLike, VisibleType @@ -159,9 +153,7 @@ "RowSharesLike", "RowSharesType", "SpaceViewClass", - "SpaceViewClassArrayLike", "SpaceViewClassBatch", - "SpaceViewClassLike", "SpaceViewClassType", "SpaceViewMaximized", "SpaceViewMaximizedBatch", diff --git a/rerun_py/rerun_sdk/rerun/blueprint/components/space_view_class.py b/rerun_py/rerun_sdk/rerun/blueprint/components/space_view_class.py index 5f801787aaaf..b4566eb61718 100644 --- a/rerun_py/rerun_sdk/rerun/blueprint/components/space_view_class.py +++ b/rerun_py/rerun_sdk/rerun/blueprint/components/space_view_class.py @@ -5,55 +5,24 @@ from __future__ import annotations -from typing import Any, Sequence, Union +from ... import datatypes +from ..._baseclasses import ComponentBatchMixin -import pyarrow as pa -from attrs import define, field +__all__ = ["SpaceViewClass", "SpaceViewClassBatch", "SpaceViewClassType"] -from ..._baseclasses import BaseBatch, BaseExtensionType, ComponentBatchMixin -__all__ = [ - "SpaceViewClass", - "SpaceViewClassArrayLike", - "SpaceViewClassBatch", - "SpaceViewClassLike", - "SpaceViewClassType", -] - - -@define(init=False) -class SpaceViewClass: +class SpaceViewClass(datatypes.Utf8): """**Component**: The class of a `SpaceView`.""" - def __init__(self: Any, value: SpaceViewClassLike): - """Create a new instance of the SpaceViewClass component.""" - - # You can define your own __init__ function as a member of SpaceViewClassExt in space_view_class_ext.py - self.__attrs_init__(value=value) - - value: str = field(converter=str) + # You can define your own __init__ function as a member of SpaceViewClassExt in space_view_class_ext.py - def __str__(self) -> str: - return str(self.value) + # Note: there are no fields here because SpaceViewClass delegates to datatypes.Utf8 + pass -SpaceViewClassLike = SpaceViewClass -SpaceViewClassArrayLike = Union[ - SpaceViewClass, - Sequence[SpaceViewClassLike], -] - - -class SpaceViewClassType(BaseExtensionType): +class SpaceViewClassType(datatypes.Utf8Type): _TYPE_NAME: str = "rerun.blueprint.components.SpaceViewClass" - def __init__(self) -> None: - pa.ExtensionType.__init__(self, pa.utf8(), self._TYPE_NAME) - -class SpaceViewClassBatch(BaseBatch[SpaceViewClassArrayLike], ComponentBatchMixin): +class SpaceViewClassBatch(datatypes.Utf8Batch, ComponentBatchMixin): _ARROW_TYPE = SpaceViewClassType() - - @staticmethod - def _native_to_pa_array(data: SpaceViewClassArrayLike, data_type: pa.DataType) -> pa.Array: - raise NotImplementedError # You need to implement native_to_pa_array_override in space_view_class_ext.py diff --git a/rerun_py/tests/unit/test_space_view_blueprint.py b/rerun_py/tests/unit/test_space_view_blueprint.py new file mode 100644 index 000000000000..94632d1d6e0f --- /dev/null +++ b/rerun_py/tests/unit/test_space_view_blueprint.py @@ -0,0 +1,38 @@ +from __future__ import annotations + +import itertools + +from rerun.blueprint.archetypes.space_view_blueprint import SpaceViewBlueprint +from rerun.blueprint.components.space_view_class import SpaceViewClassBatch +from rerun.components.name import NameBatch + +from .common_arrays import none_empty_or_value + + +def test_space_view_blueprint() -> None: + class_identifier_arrays = ["3D", "TimeSeries"] + display_name_arrays = ["3D View", "Time Series View", None] + + all_arrays = itertools.zip_longest( + class_identifier_arrays, + display_name_arrays, + ) + + # for space_views, layout, root_container, maximized, auto_layout, auto_space_views in all_arrays: + for class_identifier, display_name in all_arrays: + class_identifier = class_identifier if class_identifier is not None else class_identifier_arrays[-1] + + print( + "rr.SpaceViewBlueprint(\n", + f" class_identifier={class_identifier!r}\n", + f" display_name={display_name!r}\n", + ")", + ) + arch = SpaceViewBlueprint( + class_identifier, + display_name=display_name, + ) + print(f"{arch}\n") + + assert arch.class_identifier == SpaceViewClassBatch(class_identifier) + assert arch.display_name == NameBatch._optional(none_empty_or_value(display_name, display_name)) From 8f32d9c9fa099cb1f2cc8ade95d3ccf9cf1b39ae Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Mon, 4 Mar 2024 17:49:08 +0100 Subject: [PATCH 2/9] space view origin serialization --- .../archetypes/space_view_blueprint.fbs | 2 +- .../blueprint/components/space_view_class.fbs | 1 - .../components/space_view_origin.fbs | 2 ++ .../rerun_sdk/rerun/datatypes/entity_path.py | 5 ++-- .../rerun/datatypes/entity_path_ext.py | 24 +++++++++++++++++++ .../rerun_sdk/rerun/datatypes/utf8_ext.py | 1 + .../tests/unit/test_space_view_blueprint.py | 23 +++++++++++++++++- 7 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 rerun_py/rerun_sdk/rerun/datatypes/entity_path_ext.py diff --git a/crates/re_types/definitions/rerun/blueprint/archetypes/space_view_blueprint.fbs b/crates/re_types/definitions/rerun/blueprint/archetypes/space_view_blueprint.fbs index 541f6064a4af..957ce0cfcb48 100644 --- a/crates/re_types/definitions/rerun/blueprint/archetypes/space_view_blueprint.fbs +++ b/crates/re_types/definitions/rerun/blueprint/archetypes/space_view_blueprint.fbs @@ -27,7 +27,7 @@ table SpaceViewBlueprint ( /// The transform at this path forms the reference point for all scene->world transforms in this space view. /// I.e. the position of this entity path in space forms the origin of the coordinate system in this space view. /// Furthermore, this is the primary indicator for heuristics on what entities we show in this space view. - space_origin: rerun.blueprint.components.SpaceViewOrigin ("attr.rerun.component_optional", nullable, order: 300); + space_origin: rerun.blueprint.components.SpaceViewOrigin ("attr.rerun.component_optional", nullable, order: 300); /// True if the user is has added entities themselves. False otherwise. entities_determined_by_user: rerun.blueprint.components.EntitiesDeterminedByUser ("attr.rerun.component_optional", nullable, order: 400); diff --git a/crates/re_types/definitions/rerun/blueprint/components/space_view_class.fbs b/crates/re_types/definitions/rerun/blueprint/components/space_view_class.fbs index 3473172b4509..d6baab29c6cd 100644 --- a/crates/re_types/definitions/rerun/blueprint/components/space_view_class.fbs +++ b/crates/re_types/definitions/rerun/blueprint/components/space_view_class.fbs @@ -14,7 +14,6 @@ table SpaceViewClass ( "attr.arrow.transparent", "attr.rerun.scope": "blueprint", "attr.python.aliases": "str", - "attr.python.array_aliases": "str, Sequence[str]", "attr.rust.derive": "PartialEq, Eq, PartialOrd, Ord", "attr.rust.repr": "transparent" ) { diff --git a/crates/re_types/definitions/rerun/blueprint/components/space_view_origin.fbs b/crates/re_types/definitions/rerun/blueprint/components/space_view_origin.fbs index 5b207f5831ea..8383cd462e5e 100644 --- a/crates/re_types/definitions/rerun/blueprint/components/space_view_origin.fbs +++ b/crates/re_types/definitions/rerun/blueprint/components/space_view_origin.fbs @@ -11,7 +11,9 @@ namespace rerun.blueprint.components; /// The origin of a `SpaceView`. table SpaceViewOrigin ( + "attr.arrow.transparent", "attr.rerun.scope": "blueprint", + "attr.python.aliases": "str", "attr.rust.derive": "PartialEq, Eq, PartialOrd, Ord", "attr.rust.repr": "transparent" ) { diff --git a/rerun_py/rerun_sdk/rerun/datatypes/entity_path.py b/rerun_py/rerun_sdk/rerun/datatypes/entity_path.py index 64b044d317eb..ec57e8f79002 100644 --- a/rerun_py/rerun_sdk/rerun/datatypes/entity_path.py +++ b/rerun_py/rerun_sdk/rerun/datatypes/entity_path.py @@ -11,12 +11,13 @@ from attrs import define, field from .._baseclasses import BaseBatch, BaseExtensionType +from .entity_path_ext import EntityPathExt __all__ = ["EntityPath", "EntityPathArrayLike", "EntityPathBatch", "EntityPathLike", "EntityPathType"] @define(init=False) -class EntityPath: +class EntityPath(EntityPathExt): """**Datatype**: A path to an entity in the `DataStore`.""" def __init__(self: Any, path: EntityPathLike): @@ -50,4 +51,4 @@ class EntityPathBatch(BaseBatch[EntityPathArrayLike]): @staticmethod def _native_to_pa_array(data: EntityPathArrayLike, data_type: pa.DataType) -> pa.Array: - raise NotImplementedError # You need to implement native_to_pa_array_override in entity_path_ext.py + return EntityPathExt.native_to_pa_array_override(data, data_type) diff --git a/rerun_py/rerun_sdk/rerun/datatypes/entity_path_ext.py b/rerun_py/rerun_sdk/rerun/datatypes/entity_path_ext.py new file mode 100644 index 000000000000..1d4e947e8104 --- /dev/null +++ b/rerun_py/rerun_sdk/rerun/datatypes/entity_path_ext.py @@ -0,0 +1,24 @@ +from __future__ import annotations +from __future__ import annotations + +from typing import TYPE_CHECKING, Sequence + +import pyarrow as pa + +if TYPE_CHECKING: + from . import EntityPathArrayLike + + +class EntityPathExt: + """Extension for [EntityPath][rerun.datatypes.EntityPath].""" + + @staticmethod + def native_to_pa_array_override(data: EntityPathArrayLike, data_type: pa.DataType) -> pa.Array: + if isinstance(data, str): + array = [data] + elif isinstance(data, Sequence): + array = [str(datum) for datum in data] + else: + array = [str(data)] + + return pa.array(array, type=data_type) diff --git a/rerun_py/rerun_sdk/rerun/datatypes/utf8_ext.py b/rerun_py/rerun_sdk/rerun/datatypes/utf8_ext.py index f0c243d1f182..230a40ca07a8 100644 --- a/rerun_py/rerun_sdk/rerun/datatypes/utf8_ext.py +++ b/rerun_py/rerun_sdk/rerun/datatypes/utf8_ext.py @@ -1,4 +1,5 @@ from __future__ import annotations +from __future__ import annotations from typing import TYPE_CHECKING, Sequence diff --git a/rerun_py/tests/unit/test_space_view_blueprint.py b/rerun_py/tests/unit/test_space_view_blueprint.py index 94632d1d6e0f..a3dfdc8c0e0f 100644 --- a/rerun_py/tests/unit/test_space_view_blueprint.py +++ b/rerun_py/tests/unit/test_space_view_blueprint.py @@ -3,7 +3,10 @@ import itertools from rerun.blueprint.archetypes.space_view_blueprint import SpaceViewBlueprint +from rerun.blueprint.components.entities_determined_by_user import EntitiesDeterminedByUserBatch from rerun.blueprint.components.space_view_class import SpaceViewClassBatch +from rerun.blueprint.components.space_view_origin import SpaceViewOriginBatch +from rerun.blueprint.components.visible import VisibleBatch from rerun.components.name import NameBatch from .common_arrays import none_empty_or_value @@ -12,27 +15,45 @@ def test_space_view_blueprint() -> None: class_identifier_arrays = ["3D", "TimeSeries"] display_name_arrays = ["3D View", "Time Series View", None] + space_origin_arrays = ["/", None, "/robot/arm"] + entities_determined_by_user_arrays = [True, False, None] + visible_arrays = [False, True, None] all_arrays = itertools.zip_longest( class_identifier_arrays, display_name_arrays, + space_origin_arrays, + entities_determined_by_user_arrays, + visible_arrays, ) # for space_views, layout, root_container, maximized, auto_layout, auto_space_views in all_arrays: - for class_identifier, display_name in all_arrays: + for class_identifier, display_name, space_origin, entities_determined_by_user, visible in all_arrays: class_identifier = class_identifier if class_identifier is not None else class_identifier_arrays[-1] print( "rr.SpaceViewBlueprint(\n", f" class_identifier={class_identifier!r}\n", f" display_name={display_name!r}\n", + f" space_origin={space_origin!r}\n", + f" entities_determined_by_user={entities_determined_by_user!r}\n", + f" visible={visible!r}\n", ")", ) arch = SpaceViewBlueprint( class_identifier, display_name=display_name, + space_origin=space_origin, + entities_determined_by_user=entities_determined_by_user, + visible=visible, ) print(f"{arch}\n") + # Equality checks on some of these are a bit silly, but at least they test out that the serialization code runs without problems. assert arch.class_identifier == SpaceViewClassBatch(class_identifier) assert arch.display_name == NameBatch._optional(none_empty_or_value(display_name, display_name)) + assert arch.space_origin == SpaceViewOriginBatch._optional(none_empty_or_value(space_origin, space_origin)) + assert arch.entities_determined_by_user == EntitiesDeterminedByUserBatch._optional( + none_empty_or_value(entities_determined_by_user, entities_determined_by_user) + ) + assert arch.visible == VisibleBatch._optional(none_empty_or_value(visible, visible)) From 6b5fca8b8399297a9f90527a75eeab7d7f79de4b Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Mon, 4 Mar 2024 17:58:53 +0100 Subject: [PATCH 3/9] EntitiesDeterminedByUser serialization --- .../components/entities_determined_by_user.fbs | 1 + .../components/entities_determined_by_user.py | 13 +++++++++---- .../entities_determined_by_user_ext.py | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 rerun_py/rerun_sdk/rerun/blueprint/components/entities_determined_by_user_ext.py diff --git a/crates/re_types/definitions/rerun/blueprint/components/entities_determined_by_user.fbs b/crates/re_types/definitions/rerun/blueprint/components/entities_determined_by_user.fbs index e33227bb78ac..860860e889ed 100644 --- a/crates/re_types/definitions/rerun/blueprint/components/entities_determined_by_user.fbs +++ b/crates/re_types/definitions/rerun/blueprint/components/entities_determined_by_user.fbs @@ -12,6 +12,7 @@ namespace rerun.blueprint.components; /// Whether the space view entities were manually edited. table EntitiesDeterminedByUser ( "attr.rerun.scope": "blueprint", + "attr.python.aliases": "bool", "attr.rust.derive": "Default, PartialEq, Eq, PartialOrd, Ord", "attr.rust.repr": "transparent" ) { diff --git a/rerun_py/rerun_sdk/rerun/blueprint/components/entities_determined_by_user.py b/rerun_py/rerun_sdk/rerun/blueprint/components/entities_determined_by_user.py index b1dd1836cdd3..7e4775420eaf 100644 --- a/rerun_py/rerun_sdk/rerun/blueprint/components/entities_determined_by_user.py +++ b/rerun_py/rerun_sdk/rerun/blueprint/components/entities_determined_by_user.py @@ -5,12 +5,13 @@ from __future__ import annotations -from typing import Any, Sequence, Union +from typing import TYPE_CHECKING, Any, Sequence, Union import pyarrow as pa from attrs import define, field from ..._baseclasses import BaseBatch, BaseExtensionType, ComponentBatchMixin +from .entities_determined_by_user_ext import EntitiesDeterminedByUserExt __all__ = [ "EntitiesDeterminedByUser", @@ -22,7 +23,7 @@ @define(init=False) -class EntitiesDeterminedByUser: +class EntitiesDeterminedByUser(EntitiesDeterminedByUserExt): """**Component**: Whether the space view entities were manually edited.""" def __init__(self: Any, value: EntitiesDeterminedByUserLike): @@ -37,7 +38,11 @@ def __bool__(self) -> bool: value: bool = field(converter=bool) -EntitiesDeterminedByUserLike = EntitiesDeterminedByUser +if TYPE_CHECKING: + EntitiesDeterminedByUserLike = Union[EntitiesDeterminedByUser, bool] +else: + EntitiesDeterminedByUserLike = Any + EntitiesDeterminedByUserArrayLike = Union[ EntitiesDeterminedByUser, Sequence[EntitiesDeterminedByUserLike], @@ -56,4 +61,4 @@ class EntitiesDeterminedByUserBatch(BaseBatch[EntitiesDeterminedByUserArrayLike] @staticmethod def _native_to_pa_array(data: EntitiesDeterminedByUserArrayLike, data_type: pa.DataType) -> pa.Array: - raise NotImplementedError # You need to implement native_to_pa_array_override in entities_determined_by_user_ext.py + return EntitiesDeterminedByUserExt.native_to_pa_array_override(data, data_type) diff --git a/rerun_py/rerun_sdk/rerun/blueprint/components/entities_determined_by_user_ext.py b/rerun_py/rerun_sdk/rerun/blueprint/components/entities_determined_by_user_ext.py new file mode 100644 index 000000000000..dcadd92a76d2 --- /dev/null +++ b/rerun_py/rerun_sdk/rerun/blueprint/components/entities_determined_by_user_ext.py @@ -0,0 +1,18 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +import numpy as np +import pyarrow as pa + +if TYPE_CHECKING: + from . import EntitiesDeterminedByUserArrayLike + + +class EntitiesDeterminedByUserExt: + """Extension for [EntitiesDeterminedByUser][rerun.components.EntitiesDeterminedByUser].""" + + @staticmethod + def native_to_pa_array_override(data: EntitiesDeterminedByUserArrayLike, data_type: pa.DataType) -> pa.Array: + array = np.asarray(data, dtype=np.bool_).flatten() + return pa.array(array, type=data_type) From 657c01a620bcb6110306cadc1d2119a3690534d8 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Mon, 4 Mar 2024 18:00:35 +0100 Subject: [PATCH 4/9] Visible serialization --- .../components/entities_determined_by_user.fbs | 4 +++- .../rerun/blueprint/components/visible.fbs | 1 + .../rerun/blueprint/components/visible.py | 13 +++++++++---- .../rerun/blueprint/components/visible_ext.py | 18 ++++++++++++++++++ 4 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 rerun_py/rerun_sdk/rerun/blueprint/components/visible_ext.py diff --git a/crates/re_types/definitions/rerun/blueprint/components/entities_determined_by_user.fbs b/crates/re_types/definitions/rerun/blueprint/components/entities_determined_by_user.fbs index 860860e889ed..239f48c0419b 100644 --- a/crates/re_types/definitions/rerun/blueprint/components/entities_determined_by_user.fbs +++ b/crates/re_types/definitions/rerun/blueprint/components/entities_determined_by_user.fbs @@ -11,10 +11,12 @@ namespace rerun.blueprint.components; /// Whether the space view entities were manually edited. table EntitiesDeterminedByUser ( + "attr.arrow.transparent", "attr.rerun.scope": "blueprint", "attr.python.aliases": "bool", "attr.rust.derive": "Default, PartialEq, Eq, PartialOrd, Ord", - "attr.rust.repr": "transparent" + "attr.rust.repr": "transparent", + "attr.rust.tuple_struct" ) { value: bool (order: 100); } diff --git a/crates/re_types/definitions/rerun/blueprint/components/visible.fbs b/crates/re_types/definitions/rerun/blueprint/components/visible.fbs index 02dd92ce8fb5..4572583b3137 100644 --- a/crates/re_types/definitions/rerun/blueprint/components/visible.fbs +++ b/crates/re_types/definitions/rerun/blueprint/components/visible.fbs @@ -13,6 +13,7 @@ namespace rerun.blueprint.components; struct Visible ( "attr.arrow.transparent", "attr.rerun.scope": "blueprint", + "attr.python.aliases": "bool", "attr.rust.derive": "Copy, PartialEq, Eq", "attr.rust.repr": "transparent", "attr.rust.tuple_struct" diff --git a/rerun_py/rerun_sdk/rerun/blueprint/components/visible.py b/rerun_py/rerun_sdk/rerun/blueprint/components/visible.py index 57269d665ff9..35b280ba3cf4 100644 --- a/rerun_py/rerun_sdk/rerun/blueprint/components/visible.py +++ b/rerun_py/rerun_sdk/rerun/blueprint/components/visible.py @@ -5,18 +5,19 @@ from __future__ import annotations -from typing import Any, Sequence, Union +from typing import TYPE_CHECKING, Any, Sequence, Union import pyarrow as pa from attrs import define, field from ..._baseclasses import BaseBatch, BaseExtensionType, ComponentBatchMixin +from .visible_ext import VisibleExt __all__ = ["Visible", "VisibleArrayLike", "VisibleBatch", "VisibleLike", "VisibleType"] @define(init=False) -class Visible: +class Visible(VisibleExt): """**Component**: Whether the container, space view, entity or instance is currently visible.""" def __init__(self: Any, visible: VisibleLike): @@ -31,7 +32,11 @@ def __bool__(self) -> bool: visible: bool = field(converter=bool) -VisibleLike = Visible +if TYPE_CHECKING: + VisibleLike = Union[Visible, bool] +else: + VisibleLike = Any + VisibleArrayLike = Union[ Visible, Sequence[VisibleLike], @@ -50,4 +55,4 @@ class VisibleBatch(BaseBatch[VisibleArrayLike], ComponentBatchMixin): @staticmethod def _native_to_pa_array(data: VisibleArrayLike, data_type: pa.DataType) -> pa.Array: - raise NotImplementedError # You need to implement native_to_pa_array_override in visible_ext.py + return VisibleExt.native_to_pa_array_override(data, data_type) diff --git a/rerun_py/rerun_sdk/rerun/blueprint/components/visible_ext.py b/rerun_py/rerun_sdk/rerun/blueprint/components/visible_ext.py new file mode 100644 index 000000000000..cc0a045cbda6 --- /dev/null +++ b/rerun_py/rerun_sdk/rerun/blueprint/components/visible_ext.py @@ -0,0 +1,18 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +import numpy as np +import pyarrow as pa + +if TYPE_CHECKING: + from . import VisibleArrayLike + + +class VisibleExt: + """Extension for [Visible][rerun.components.Visible].""" + + @staticmethod + def native_to_pa_array_override(data: VisibleArrayLike, data_type: pa.DataType) -> pa.Array: + array = np.asarray(data, dtype=np.bool_).flatten() + return pa.array(array, type=data_type) From 0c46b4c54830c12cad2e15f661f5610b91752e97 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Tue, 5 Mar 2024 11:32:37 +0100 Subject: [PATCH 5/9] make included query singular, rust fixups, round up space_view_blueprint test --- crates/re_data_ui/src/blueprint_data.rs | 19 +- .../re_data_ui/src/component_ui_registry.rs | 2 +- .../blueprint/components/query_expressions.rs | 2 +- crates/re_space_view/src/space_view.rs | 3 +- .../re_types/definitions/rerun/blueprint.fbs | 2 +- .../archetypes/space_view_blueprint.fbs | 9 +- .../blueprint/components/auto_space_views.fbs | 2 +- .../entities_determined_by_user.fbs | 2 +- ...ncluded_queries.fbs => included_query.fbs} | 6 +- .../components/query_expressions.fbs | 2 +- .../rerun/blueprint/components/visible.fbs | 14 +- .../archetypes/space_view_blueprint.rs | 35 +- .../src/blueprint/components/.gitattributes | 2 +- .../components/entities_determined_by_user.rs | 2 +- .../blueprint/components/included_queries.rs | 298 ------------------ .../blueprint/components/included_query.rs | 282 +++++++++++++++++ .../re_types/src/blueprint/components/mod.rs | 5 +- .../components/space_view_class_ext.rs | 16 - .../src/blueprint/components/visible.rs | 2 +- .../src/blueprint/validation_gen/mod.rs | 4 +- .../blueprint/components/auto_space_views.rs | 2 +- .../archetypes/space_view_blueprint.hpp | 15 +- rerun_cpp/src/rerun/blueprint/components.hpp | 2 +- .../rerun/blueprint/components/.gitattributes | 4 +- .../blueprint/components/included_queries.cpp | 77 ----- .../blueprint/components/included_query.cpp | 57 ++++ ...ncluded_queries.hpp => included_query.hpp} | 46 +-- .../components/query_expressions.hpp | 2 +- .../archetypes/space_view_blueprint.py | 14 +- .../rerun/blueprint/components/.gitattributes | 2 +- .../rerun/blueprint/components/__init__.py | 16 +- .../blueprint/components/included_queries.py | 72 ----- .../blueprint/components/included_query.py | 32 ++ .../blueprint/components/query_expressions.py | 2 +- .../tests/unit/test_space_view_blueprint.py | 40 ++- .../tests/unit/test_viewport_blueprint.py | 8 +- 36 files changed, 504 insertions(+), 596 deletions(-) rename crates/re_types/definitions/rerun/blueprint/components/{included_queries.fbs => included_query.fbs} (74%) delete mode 100644 crates/re_types/src/blueprint/components/included_queries.rs create mode 100644 crates/re_types/src/blueprint/components/included_query.rs delete mode 100644 crates/re_types/src/blueprint/components/space_view_class_ext.rs delete mode 100644 rerun_cpp/src/rerun/blueprint/components/included_queries.cpp create mode 100644 rerun_cpp/src/rerun/blueprint/components/included_query.cpp rename rerun_cpp/src/rerun/blueprint/components/{included_queries.hpp => included_query.hpp} (50%) delete mode 100644 rerun_py/rerun_sdk/rerun/blueprint/components/included_queries.py create mode 100644 rerun_py/rerun_sdk/rerun/blueprint/components/included_query.py diff --git a/crates/re_data_ui/src/blueprint_data.rs b/crates/re_data_ui/src/blueprint_data.rs index 5836c4ae47e1..1e313db60917 100644 --- a/crates/re_data_ui/src/blueprint_data.rs +++ b/crates/re_data_ui/src/blueprint_data.rs @@ -1,11 +1,11 @@ -use re_types::blueprint::components::IncludedQueries; +use re_types::blueprint::components::IncludedQuery; use re_viewer_context::{ BlueprintId, BlueprintIdRegistry, DataQueryId, UiVerbosity, ViewerContext, }; use crate::{item_ui::entity_path_button_to, DataUi}; -impl DataUi for IncludedQueries { +impl DataUi for IncludedQuery { #[allow(clippy::only_used_in_recursion)] fn data_ui( &self, @@ -15,18 +15,9 @@ impl DataUi for IncludedQueries { query: &re_data_store::LatestAtQuery, store: &re_data_store::DataStore, ) { - match verbosity { - UiVerbosity::Small => { - ui.label(format!("{} Queries", self.0.len())); - } - UiVerbosity::Full | UiVerbosity::LimitHeight | UiVerbosity::Reduced => { - for data_query in &self.0 { - let data_query: DataQueryId = (*data_query).into(); - data_query.data_ui(_ctx, ui, verbosity, query, store); - ui.end_row(); - } - } - } + let data_query: DataQueryId = self.0.into(); + data_query.data_ui(_ctx, ui, verbosity, query, store); + ui.end_row(); } } diff --git a/crates/re_data_ui/src/component_ui_registry.rs b/crates/re_data_ui/src/component_ui_registry.rs index cc39e4118b63..1d7f8947b2b5 100644 --- a/crates/re_data_ui/src/component_ui_registry.rs +++ b/crates/re_data_ui/src/component_ui_registry.rs @@ -29,7 +29,7 @@ pub fn create_component_ui_registry() -> ComponentUiRegistry { add_to_registry::(&mut registry); add_to_registry::(&mut registry); - add_to_registry::(&mut registry); + add_to_registry::(&mut registry); register_editors(&mut registry); diff --git a/crates/re_space_view/src/blueprint/components/query_expressions.rs b/crates/re_space_view/src/blueprint/components/query_expressions.rs index 595541132b5e..662e489ea9ec 100644 --- a/crates/re_space_view/src/blueprint/components/query_expressions.rs +++ b/crates/re_space_view/src/blueprint/components/query_expressions.rs @@ -39,7 +39,7 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; /// (`/world/**` matches both `/world` and `/world/car/driver`). /// Other uses of `*` are not (yet) supported. /// -/// `EntityPathFilter` sorts the rule by entity path, with recursive coming before non-recursive. +/// Internally, `EntityPathFilter` sorts the rule by entity path, with recursive coming before non-recursive. /// This means the last matching rule is also the most specific one. /// For instance: /// diff --git a/crates/re_space_view/src/space_view.rs b/crates/re_space_view/src/space_view.rs index 1dd73f4f2a1e..f6bab7fa3dff 100644 --- a/crates/re_space_view/src/space_view.rs +++ b/crates/re_space_view/src/space_view.rs @@ -175,9 +175,8 @@ impl SpaceViewBlueprint { let queries = contents .unwrap_or_default() - .0 .into_iter() - .map(DataQueryId::from) + .map(|included| DataQueryId::from(included.0)) .filter_map(|id| { DataQueryBlueprint::try_from_db(id, blueprint_db, query, class_identifier) }) diff --git a/crates/re_types/definitions/rerun/blueprint.fbs b/crates/re_types/definitions/rerun/blueprint.fbs index 9168e3548e6d..11e136db69c7 100644 --- a/crates/re_types/definitions/rerun/blueprint.fbs +++ b/crates/re_types/definitions/rerun/blueprint.fbs @@ -7,7 +7,7 @@ include "./blueprint/components/entities_determined_by_user.fbs"; include "./blueprint/components/entity_properties_component.fbs"; include "./blueprint/components/grid_columns.fbs"; include "./blueprint/components/included_contents.fbs"; -include "./blueprint/components/included_queries.fbs"; +include "./blueprint/components/included_query.fbs"; include "./blueprint/components/included_space_view.fbs"; include "./blueprint/components/panel_view.fbs"; include "./blueprint/components/query_expressions.fbs"; diff --git a/crates/re_types/definitions/rerun/blueprint/archetypes/space_view_blueprint.fbs b/crates/re_types/definitions/rerun/blueprint/archetypes/space_view_blueprint.fbs index 957ce0cfcb48..4d88bdc5c0b2 100644 --- a/crates/re_types/definitions/rerun/blueprint/archetypes/space_view_blueprint.fbs +++ b/crates/re_types/definitions/rerun/blueprint/archetypes/space_view_blueprint.fbs @@ -9,8 +9,7 @@ namespace rerun.blueprint.archetypes; /// The top-level description of the Viewport. table SpaceViewBlueprint ( - "attr.rerun.scope": "blueprint", - "attr.rust.derive": "Default" + "attr.rerun.scope": "blueprint" ) { // --- Required --- @@ -32,10 +31,10 @@ table SpaceViewBlueprint ( /// True if the user is has added entities themselves. False otherwise. entities_determined_by_user: rerun.blueprint.components.EntitiesDeterminedByUser ("attr.rerun.component_optional", nullable, order: 400); - /// `BlueprintId`s of the `DataQuery`s that make up this `SpaceView`. + /// Ids of the `DataQuery`s that make up this `SpaceView`. /// - /// It determines which entities are part of the spaceview. - contents: rerun.blueprint.components.IncludedQueries ("attr.rerun.component_optional", nullable, order: 500); + /// They determine which entities are part of the spaceview. + contents: [rerun.blueprint.components.IncludedQuery] ("attr.rerun.component_optional", nullable, order: 500); /// Whether this space view is visible. /// diff --git a/crates/re_types/definitions/rerun/blueprint/components/auto_space_views.fbs b/crates/re_types/definitions/rerun/blueprint/components/auto_space_views.fbs index e8b7bb4b3c7f..e50ce3284672 100644 --- a/crates/re_types/definitions/rerun/blueprint/components/auto_space_views.fbs +++ b/crates/re_types/definitions/rerun/blueprint/components/auto_space_views.fbs @@ -16,7 +16,7 @@ struct AutoSpaceViews ( "attr.arrow.transparent", "attr.rerun.scope": "blueprint", "attr.python.aliases": "bool", - "attr.rust.derive": "Copy, Default", + "attr.rust.derive": "Copy, Default, PartialEq, Eq, PartialOrd, Ord", "attr.rust.override_crate": "re_viewport", "attr.rust.repr": "transparent", "attr.rust.tuple_struct" diff --git a/crates/re_types/definitions/rerun/blueprint/components/entities_determined_by_user.fbs b/crates/re_types/definitions/rerun/blueprint/components/entities_determined_by_user.fbs index 239f48c0419b..0b54cdb618fa 100644 --- a/crates/re_types/definitions/rerun/blueprint/components/entities_determined_by_user.fbs +++ b/crates/re_types/definitions/rerun/blueprint/components/entities_determined_by_user.fbs @@ -14,7 +14,7 @@ table EntitiesDeterminedByUser ( "attr.arrow.transparent", "attr.rerun.scope": "blueprint", "attr.python.aliases": "bool", - "attr.rust.derive": "Default, PartialEq, Eq, PartialOrd, Ord", + "attr.rust.derive": "Copy, Default, PartialEq, Eq, PartialOrd, Ord", "attr.rust.repr": "transparent", "attr.rust.tuple_struct" ) { diff --git a/crates/re_types/definitions/rerun/blueprint/components/included_queries.fbs b/crates/re_types/definitions/rerun/blueprint/components/included_query.fbs similarity index 74% rename from crates/re_types/definitions/rerun/blueprint/components/included_queries.fbs rename to crates/re_types/definitions/rerun/blueprint/components/included_query.fbs index 7a717454bb0b..ef7b6e08bc8d 100644 --- a/crates/re_types/definitions/rerun/blueprint/components/included_queries.fbs +++ b/crates/re_types/definitions/rerun/blueprint/components/included_query.fbs @@ -10,13 +10,13 @@ namespace rerun.blueprint.components; // --- -/// All the queries belonging to a given `SpaceView`. +/// Each query id referes to a [`QueryExpressions`] component. /// /// Unstable. Used for the ongoing blueprint experimentations. -table IncludedQueries ( +table IncludedQuery ( "attr.rerun.scope": "blueprint", "attr.rust.derive": "Default", "attr.rust.repr": "transparent" ) { - query_ids: [rerun.datatypes.Uuid] (order: 100); + query_id: rerun.datatypes.Uuid (order: 100); } diff --git a/crates/re_types/definitions/rerun/blueprint/components/query_expressions.fbs b/crates/re_types/definitions/rerun/blueprint/components/query_expressions.fbs index eea81bcd6b59..dc0c96937650 100644 --- a/crates/re_types/definitions/rerun/blueprint/components/query_expressions.fbs +++ b/crates/re_types/definitions/rerun/blueprint/components/query_expressions.fbs @@ -26,7 +26,7 @@ namespace rerun.blueprint.components; /// (`/world/**` matches both `/world` and `/world/car/driver`). /// Other uses of `*` are not (yet) supported. /// -/// `EntityPathFilter` sorts the rule by entity path, with recursive coming before non-recursive. +/// Internally, `EntityPathFilter` sorts the rule by entity path, with recursive coming before non-recursive. /// This means the last matching rule is also the most specific one. /// For instance: /// diff --git a/crates/re_types/definitions/rerun/blueprint/components/visible.fbs b/crates/re_types/definitions/rerun/blueprint/components/visible.fbs index 4572583b3137..992d11f53f6b 100644 --- a/crates/re_types/definitions/rerun/blueprint/components/visible.fbs +++ b/crates/re_types/definitions/rerun/blueprint/components/visible.fbs @@ -11,12 +11,12 @@ namespace rerun.blueprint.components; /// Whether the container, space view, entity or instance is currently visible. struct Visible ( - "attr.arrow.transparent", - "attr.rerun.scope": "blueprint", - "attr.python.aliases": "bool", - "attr.rust.derive": "Copy, PartialEq, Eq", - "attr.rust.repr": "transparent", - "attr.rust.tuple_struct" + "attr.arrow.transparent", + "attr.rerun.scope": "blueprint", + "attr.python.aliases": "bool", + "attr.rust.derive": "Copy, Default, PartialEq, Eq, PartialOrd, Ord", + "attr.rust.repr": "transparent", + "attr.rust.tuple_struct" ) { - visible: bool (order: 100); + visible: bool (order: 100); } diff --git a/crates/re_types/src/blueprint/archetypes/space_view_blueprint.rs b/crates/re_types/src/blueprint/archetypes/space_view_blueprint.rs index f414a68ffb0e..cc23c836b43f 100644 --- a/crates/re_types/src/blueprint/archetypes/space_view_blueprint.rs +++ b/crates/re_types/src/blueprint/archetypes/space_view_blueprint.rs @@ -22,7 +22,7 @@ use ::re_types_core::{ComponentBatch, MaybeOwnedComponentBatch}; use ::re_types_core::{DeserializationError, DeserializationResult}; /// **Archetype**: The top-level description of the Viewport. -#[derive(Clone, Debug, Default)] +#[derive(Clone, Debug)] pub struct SpaceViewBlueprint { /// The class of the view. pub class_identifier: crate::blueprint::components::SpaceViewClass, @@ -40,10 +40,10 @@ pub struct SpaceViewBlueprint { /// True if the user is has added entities themselves. False otherwise. pub entities_determined_by_user: Option, - /// `BlueprintId`s of the `DataQuery`s that make up this `SpaceView`. + /// Ids of the `DataQuery`s that make up this `SpaceView`. /// - /// It determines which entities are part of the spaceview. - pub contents: Option, + /// They determine which entities are part of the spaceview. + pub contents: Option>, /// Whether this space view is visible. /// @@ -68,7 +68,7 @@ impl ::re_types_core::SizeBytes for SpaceViewBlueprint { && >::is_pod() && >::is_pod() && >::is_pod() - && >::is_pod() + && >>::is_pod() && >::is_pod() } } @@ -85,7 +85,7 @@ static OPTIONAL_COMPONENTS: once_cell::sync::Lazy<[ComponentName; 6usize]> = once_cell::sync::Lazy::new(|| { [ "rerun.blueprint.components.EntitiesDeterminedByUser".into(), - "rerun.blueprint.components.IncludedQueries".into(), + "rerun.blueprint.components.IncludedQuery".into(), "rerun.blueprint.components.SpaceViewOrigin".into(), "rerun.blueprint.components.Visible".into(), "rerun.components.InstanceKey".into(), @@ -99,7 +99,7 @@ static ALL_COMPONENTS: once_cell::sync::Lazy<[ComponentName; 8usize]> = "rerun.blueprint.components.SpaceViewClass".into(), "rerun.blueprint.components.SpaceViewBlueprintIndicator".into(), "rerun.blueprint.components.EntitiesDeterminedByUser".into(), - "rerun.blueprint.components.IncludedQueries".into(), + "rerun.blueprint.components.IncludedQuery".into(), "rerun.blueprint.components.SpaceViewOrigin".into(), "rerun.blueprint.components.Visible".into(), "rerun.components.InstanceKey".into(), @@ -205,12 +205,15 @@ impl ::re_types_core::Archetype for SpaceViewBlueprint { None }; let contents = - if let Some(array) = arrays_by_name.get("rerun.blueprint.components.IncludedQueries") { - ::from_arrow_opt(&**array) - .with_context("rerun.blueprint.archetypes.SpaceViewBlueprint#contents")? - .into_iter() - .next() - .flatten() + if let Some(array) = arrays_by_name.get("rerun.blueprint.components.IncludedQuery") { + Some({ + ::from_arrow_opt(&**array) + .with_context("rerun.blueprint.archetypes.SpaceViewBlueprint#contents")? + .into_iter() + .map(|v| v.ok_or_else(DeserializationError::missing_data)) + .collect::>>() + .with_context("rerun.blueprint.archetypes.SpaceViewBlueprint#contents")? + }) } else { None }; @@ -253,7 +256,7 @@ impl ::re_types_core::AsComponents for SpaceViewBlueprint { .map(|comp| (comp as &dyn ComponentBatch).into()), self.contents .as_ref() - .map(|comp| (comp as &dyn ComponentBatch).into()), + .map(|comp_batch| (comp_batch as &dyn ComponentBatch).into()), self.visible .as_ref() .map(|comp| (comp as &dyn ComponentBatch).into()), @@ -308,9 +311,9 @@ impl SpaceViewBlueprint { #[inline] pub fn with_contents( mut self, - contents: impl Into, + contents: impl IntoIterator>, ) -> Self { - self.contents = Some(contents.into()); + self.contents = Some(contents.into_iter().map(Into::into).collect()); self } diff --git a/crates/re_types/src/blueprint/components/.gitattributes b/crates/re_types/src/blueprint/components/.gitattributes index 58a10696238d..71a4ce4a3968 100644 --- a/crates/re_types/src/blueprint/components/.gitattributes +++ b/crates/re_types/src/blueprint/components/.gitattributes @@ -6,7 +6,7 @@ column_shares.rs linguist-generated=true corner2d.rs linguist-generated=true entities_determined_by_user.rs linguist-generated=true included_contents.rs linguist-generated=true -included_queries.rs linguist-generated=true +included_query.rs linguist-generated=true lock_range_during_zoom.rs linguist-generated=true mod.rs linguist-generated=true row_shares.rs linguist-generated=true diff --git a/crates/re_types/src/blueprint/components/entities_determined_by_user.rs b/crates/re_types/src/blueprint/components/entities_determined_by_user.rs index 5d27e1507967..8c8419bb0dd8 100644 --- a/crates/re_types/src/blueprint/components/entities_determined_by_user.rs +++ b/crates/re_types/src/blueprint/components/entities_determined_by_user.rs @@ -22,7 +22,7 @@ use ::re_types_core::{ComponentBatch, MaybeOwnedComponentBatch}; use ::re_types_core::{DeserializationError, DeserializationResult}; /// **Component**: Whether the space view entities were manually edited. -#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Debug, Copy, Default, PartialEq, Eq, PartialOrd, Ord)] #[repr(transparent)] pub struct EntitiesDeterminedByUser(pub bool); diff --git a/crates/re_types/src/blueprint/components/included_queries.rs b/crates/re_types/src/blueprint/components/included_queries.rs deleted file mode 100644 index 7896bd59494e..000000000000 --- a/crates/re_types/src/blueprint/components/included_queries.rs +++ /dev/null @@ -1,298 +0,0 @@ -// DO NOT EDIT! This file was auto-generated by crates/re_types_builder/src/codegen/rust/api.rs -// Based on "crates/re_types/definitions/rerun/blueprint/components/included_queries.fbs". - -#![allow(trivial_numeric_casts)] -#![allow(unused_imports)] -#![allow(unused_parens)] -#![allow(clippy::clone_on_copy)] -#![allow(clippy::iter_on_single_items)] -#![allow(clippy::map_flatten)] -#![allow(clippy::match_wildcard_for_single_variants)] -#![allow(clippy::needless_question_mark)] -#![allow(clippy::new_without_default)] -#![allow(clippy::redundant_closure)] -#![allow(clippy::too_many_arguments)] -#![allow(clippy::too_many_lines)] -#![allow(clippy::unnecessary_cast)] - -use ::re_types_core::external::arrow2; -use ::re_types_core::ComponentName; -use ::re_types_core::SerializationResult; -use ::re_types_core::{ComponentBatch, MaybeOwnedComponentBatch}; -use ::re_types_core::{DeserializationError, DeserializationResult}; - -/// **Component**: All the queries belonging to a given `SpaceView`. -/// -/// Unstable. Used for the ongoing blueprint experimentations. -#[derive(Clone, Debug, Default)] -#[repr(transparent)] -pub struct IncludedQueries(pub Vec); - -impl ::re_types_core::SizeBytes for IncludedQueries { - #[inline] - fn heap_size_bytes(&self) -> u64 { - self.0.heap_size_bytes() - } - - #[inline] - fn is_pod() -> bool { - >::is_pod() - } -} - -impl, T: IntoIterator> From for IncludedQueries { - fn from(v: T) -> Self { - Self(v.into_iter().map(|v| v.into()).collect()) - } -} - -::re_types_core::macros::impl_into_cow!(IncludedQueries); - -impl ::re_types_core::Loggable for IncludedQueries { - type Name = ::re_types_core::ComponentName; - - #[inline] - fn name() -> Self::Name { - "rerun.blueprint.components.IncludedQueries".into() - } - - #[allow(clippy::wildcard_imports)] - #[inline] - fn arrow_datatype() -> arrow2::datatypes::DataType { - use arrow2::datatypes::*; - DataType::List(std::sync::Arc::new(Field::new( - "item", - ::arrow_datatype(), - false, - ))) - } - - #[allow(clippy::wildcard_imports)] - fn to_arrow_opt<'a>( - data: impl IntoIterator>>>, - ) -> SerializationResult> - where - Self: Clone + 'a, - { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| { - let Self(data0) = datum.into_owned(); - data0 - }); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - use arrow2::{buffer::Buffer, offset::OffsetsBuffer}; - let data0_inner_data: Vec<_> = data0 - .iter() - .flatten() - .flatten() - .cloned() - .map(Some) - .collect(); - let data0_inner_bitmap: Option = None; - let offsets = arrow2::offset::Offsets::::try_from_lengths( - data0 - .iter() - .map(|opt| opt.as_ref().map(|datum| datum.len()).unwrap_or_default()), - ) - .unwrap() - .into(); - ListArray::new( - Self::arrow_datatype(), - offsets, - { - use arrow2::{buffer::Buffer, offset::OffsetsBuffer}; - let data0_inner_data_inner_data: Vec<_> = data0_inner_data - .iter() - .map(|datum| { - datum - .map(|datum| { - let crate::datatypes::Uuid { bytes } = datum; - bytes - }) - .unwrap_or_default() - }) - .flatten() - .map(Some) - .collect(); - let data0_inner_data_inner_bitmap: Option = - data0_inner_bitmap.as_ref().map(|bitmap| { - bitmap - .iter() - .map(|i| std::iter::repeat(i).take(16usize)) - .flatten() - .collect::>() - .into() - }); - FixedSizeListArray::new( - DataType::FixedSizeList( - std::sync::Arc::new(Field::new("item", DataType::UInt8, false)), - 16usize, - ), - PrimitiveArray::new( - DataType::UInt8, - data0_inner_data_inner_data - .into_iter() - .map(|v| v.unwrap_or_default()) - .collect(), - data0_inner_data_inner_bitmap, - ) - .boxed(), - data0_inner_bitmap, - ) - .boxed() - }, - data0_bitmap, - ) - .boxed() - } - }) - } - - #[allow(clippy::wildcard_imports)] - fn from_arrow_opt( - arrow_data: &dyn arrow2::array::Array, - ) -> DeserializationResult>> - where - Self: Sized, - { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, buffer::*, datatypes::*}; - Ok({ - let arrow_data = arrow_data - .as_any() - .downcast_ref::>() - .ok_or_else(|| { - let expected = Self::arrow_datatype(); - let actual = arrow_data.data_type().clone(); - DeserializationError::datatype_mismatch(expected, actual) - }) - .with_context("rerun.blueprint.components.IncludedQueries#query_ids")?; - if arrow_data.is_empty() { - Vec::new() - } else { - let arrow_data_inner = { - let arrow_data_inner = &**arrow_data.values(); - { - let arrow_data_inner = arrow_data_inner - .as_any() - .downcast_ref::() - .ok_or_else(|| { - let expected = DataType::FixedSizeList( - std::sync::Arc::new(Field::new("item", DataType::UInt8, false)), - 16usize, - ); - let actual = arrow_data_inner.data_type().clone(); - DeserializationError::datatype_mismatch(expected, actual) - }) - .with_context("rerun.blueprint.components.IncludedQueries#query_ids")?; - if arrow_data_inner.is_empty() { - Vec::new() - } else { - let offsets = (0..) - .step_by(16usize) - .zip((16usize..).step_by(16usize).take(arrow_data_inner.len())); - let arrow_data_inner_inner = { - let arrow_data_inner_inner = &**arrow_data_inner.values(); - arrow_data_inner_inner - .as_any() - .downcast_ref::() - .ok_or_else(|| { - let expected = DataType::UInt8; - let actual = arrow_data_inner_inner.data_type().clone(); - DeserializationError::datatype_mismatch(expected, actual) - }) - .with_context( - "rerun.blueprint.components.IncludedQueries#query_ids", - )? - .into_iter() - .map(|opt| opt.copied()) - .collect::>() - }; - arrow2::bitmap::utils::ZipValidity::new_with_validity( - offsets, - arrow_data_inner.validity(), - ) - .map(|elem| { - elem.map(|(start, end)| { - debug_assert!(end - start == 16usize); - if end as usize > arrow_data_inner_inner.len() { - return Err(DeserializationError::offset_slice_oob( - (start, end), - arrow_data_inner_inner.len(), - )); - } - - #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)] - let data = unsafe { - arrow_data_inner_inner - .get_unchecked(start as usize..end as usize) - }; - let data = data.iter().cloned().map(Option::unwrap_or_default); - let arr = array_init::from_iter(data).unwrap(); - Ok(arr) - }) - .transpose() - }) - .map(|res_or_opt| { - res_or_opt.map(|res_or_opt| { - res_or_opt.map(|bytes| crate::datatypes::Uuid { bytes }) - }) - }) - .collect::>>>()? - } - .into_iter() - } - .collect::>() - }; - let offsets = arrow_data.offsets(); - arrow2::bitmap::utils::ZipValidity::new_with_validity( - offsets.iter().zip(offsets.lengths()), - arrow_data.validity(), - ) - .map(|elem| { - elem.map(|(start, len)| { - let start = *start as usize; - let end = start + len; - if end as usize > arrow_data_inner.len() { - return Err(DeserializationError::offset_slice_oob( - (start, end), - arrow_data_inner.len(), - )); - } - - #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)] - let data = - unsafe { arrow_data_inner.get_unchecked(start as usize..end as usize) }; - let data = data - .iter() - .cloned() - .map(Option::unwrap_or_default) - .collect(); - Ok(data) - }) - .transpose() - }) - .collect::>>>()? - } - .into_iter() - } - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .map(|res| res.map(|v| Some(Self(v)))) - .collect::>>>() - .with_context("rerun.blueprint.components.IncludedQueries#query_ids") - .with_context("rerun.blueprint.components.IncludedQueries")?) - } -} diff --git a/crates/re_types/src/blueprint/components/included_query.rs b/crates/re_types/src/blueprint/components/included_query.rs new file mode 100644 index 000000000000..20207afc7ab2 --- /dev/null +++ b/crates/re_types/src/blueprint/components/included_query.rs @@ -0,0 +1,282 @@ +// DO NOT EDIT! This file was auto-generated by crates/re_types_builder/src/codegen/rust/api.rs +// Based on "crates/re_types/definitions/rerun/blueprint/components/included_query.fbs". + +#![allow(trivial_numeric_casts)] +#![allow(unused_imports)] +#![allow(unused_parens)] +#![allow(clippy::clone_on_copy)] +#![allow(clippy::iter_on_single_items)] +#![allow(clippy::map_flatten)] +#![allow(clippy::match_wildcard_for_single_variants)] +#![allow(clippy::needless_question_mark)] +#![allow(clippy::new_without_default)] +#![allow(clippy::redundant_closure)] +#![allow(clippy::too_many_arguments)] +#![allow(clippy::too_many_lines)] +#![allow(clippy::unnecessary_cast)] + +use ::re_types_core::external::arrow2; +use ::re_types_core::ComponentName; +use ::re_types_core::SerializationResult; +use ::re_types_core::{ComponentBatch, MaybeOwnedComponentBatch}; +use ::re_types_core::{DeserializationError, DeserializationResult}; + +/// **Component**: Each query id referes to a [`QueryExpressions`] component. +/// +/// Unstable. Used for the ongoing blueprint experimentations. +#[derive(Clone, Debug, Default)] +#[repr(transparent)] +pub struct IncludedQuery(pub crate::datatypes::Uuid); + +impl ::re_types_core::SizeBytes for IncludedQuery { + #[inline] + fn heap_size_bytes(&self) -> u64 { + self.0.heap_size_bytes() + } + + #[inline] + fn is_pod() -> bool { + ::is_pod() + } +} + +impl> From for IncludedQuery { + fn from(v: T) -> Self { + Self(v.into()) + } +} + +impl std::borrow::Borrow for IncludedQuery { + #[inline] + fn borrow(&self) -> &crate::datatypes::Uuid { + &self.0 + } +} + +impl std::ops::Deref for IncludedQuery { + type Target = crate::datatypes::Uuid; + + #[inline] + fn deref(&self) -> &crate::datatypes::Uuid { + &self.0 + } +} + +::re_types_core::macros::impl_into_cow!(IncludedQuery); + +impl ::re_types_core::Loggable for IncludedQuery { + type Name = ::re_types_core::ComponentName; + + #[inline] + fn name() -> Self::Name { + "rerun.blueprint.components.IncludedQuery".into() + } + + #[allow(clippy::wildcard_imports)] + #[inline] + fn arrow_datatype() -> arrow2::datatypes::DataType { + use arrow2::datatypes::*; + DataType::FixedSizeList( + std::sync::Arc::new(Field::new("item", DataType::UInt8, false)), + 16usize, + ) + } + + #[allow(clippy::wildcard_imports)] + fn to_arrow_opt<'a>( + data: impl IntoIterator>>>, + ) -> SerializationResult> + where + Self: Clone + 'a, + { + use ::re_types_core::{Loggable as _, ResultExt as _}; + use arrow2::{array::*, datatypes::*}; + Ok({ + let (somes, data0): (Vec<_>, Vec<_>) = data + .into_iter() + .map(|datum| { + let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); + let datum = datum.map(|datum| { + let Self(data0) = datum.into_owned(); + data0 + }); + (datum.is_some(), datum) + }) + .unzip(); + let data0_bitmap: Option = { + let any_nones = somes.iter().any(|some| !*some); + any_nones.then(|| somes.into()) + }; + { + use arrow2::{buffer::Buffer, offset::OffsetsBuffer}; + let data0_inner_data: Vec<_> = data0 + .iter() + .map(|datum| { + datum + .map(|datum| { + let crate::datatypes::Uuid { bytes } = datum; + bytes + }) + .unwrap_or_default() + }) + .flatten() + .map(Some) + .collect(); + let data0_inner_bitmap: Option = + data0_bitmap.as_ref().map(|bitmap| { + bitmap + .iter() + .map(|i| std::iter::repeat(i).take(16usize)) + .flatten() + .collect::>() + .into() + }); + FixedSizeListArray::new( + Self::arrow_datatype(), + PrimitiveArray::new( + DataType::UInt8, + data0_inner_data + .into_iter() + .map(|v| v.unwrap_or_default()) + .collect(), + data0_inner_bitmap, + ) + .boxed(), + data0_bitmap, + ) + .boxed() + } + }) + } + + #[allow(clippy::wildcard_imports)] + fn from_arrow_opt( + arrow_data: &dyn arrow2::array::Array, + ) -> DeserializationResult>> + where + Self: Sized, + { + use ::re_types_core::{Loggable as _, ResultExt as _}; + use arrow2::{array::*, buffer::*, datatypes::*}; + Ok({ + let arrow_data = arrow_data + .as_any() + .downcast_ref::() + .ok_or_else(|| { + let expected = Self::arrow_datatype(); + let actual = arrow_data.data_type().clone(); + DeserializationError::datatype_mismatch(expected, actual) + }) + .with_context("rerun.blueprint.components.IncludedQuery#query_id")?; + if arrow_data.is_empty() { + Vec::new() + } else { + let offsets = (0..) + .step_by(16usize) + .zip((16usize..).step_by(16usize).take(arrow_data.len())); + let arrow_data_inner = { + let arrow_data_inner = &**arrow_data.values(); + arrow_data_inner + .as_any() + .downcast_ref::() + .ok_or_else(|| { + let expected = DataType::UInt8; + let actual = arrow_data_inner.data_type().clone(); + DeserializationError::datatype_mismatch(expected, actual) + }) + .with_context("rerun.blueprint.components.IncludedQuery#query_id")? + .into_iter() + .map(|opt| opt.copied()) + .collect::>() + }; + arrow2::bitmap::utils::ZipValidity::new_with_validity( + offsets, + arrow_data.validity(), + ) + .map(|elem| { + elem.map(|(start, end)| { + debug_assert!(end - start == 16usize); + if end as usize > arrow_data_inner.len() { + return Err(DeserializationError::offset_slice_oob( + (start, end), + arrow_data_inner.len(), + )); + } + + #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)] + let data = + unsafe { arrow_data_inner.get_unchecked(start as usize..end as usize) }; + let data = data.iter().cloned().map(Option::unwrap_or_default); + let arr = array_init::from_iter(data).unwrap(); + Ok(arr) + }) + .transpose() + }) + .map(|res_or_opt| { + res_or_opt + .map(|res_or_opt| res_or_opt.map(|bytes| crate::datatypes::Uuid { bytes })) + }) + .collect::>>>()? + } + .into_iter() + } + .map(|v| v.ok_or_else(DeserializationError::missing_data)) + .map(|res| res.map(|v| Some(Self(v)))) + .collect::>>>() + .with_context("rerun.blueprint.components.IncludedQuery#query_id") + .with_context("rerun.blueprint.components.IncludedQuery")?) + } + + #[allow(clippy::wildcard_imports)] + #[inline] + fn from_arrow(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> + where + Self: Sized, + { + use ::re_types_core::{Loggable as _, ResultExt as _}; + use arrow2::{array::*, buffer::*, datatypes::*}; + if let Some(validity) = arrow_data.validity() { + if validity.unset_bits() != 0 { + return Err(DeserializationError::missing_data()); + } + } + Ok({ + let slice = { + let arrow_data = arrow_data + .as_any() + .downcast_ref::() + .ok_or_else(|| { + let expected = DataType::FixedSizeList( + std::sync::Arc::new(Field::new("item", DataType::UInt8, false)), + 16usize, + ); + let actual = arrow_data.data_type().clone(); + DeserializationError::datatype_mismatch(expected, actual) + }) + .with_context("rerun.blueprint.components.IncludedQuery#query_id")?; + let arrow_data_inner = &**arrow_data.values(); + bytemuck::cast_slice::<_, [_; 16usize]>( + arrow_data_inner + .as_any() + .downcast_ref::() + .ok_or_else(|| { + let expected = DataType::UInt8; + let actual = arrow_data_inner.data_type().clone(); + DeserializationError::datatype_mismatch(expected, actual) + }) + .with_context("rerun.blueprint.components.IncludedQuery#query_id")? + .values() + .as_slice(), + ) + }; + { + slice + .iter() + .copied() + .map(|bytes| crate::datatypes::Uuid { bytes }) + .map(|v| Self(v)) + .collect::>() + } + }) + } +} diff --git a/crates/re_types/src/blueprint/components/mod.rs b/crates/re_types/src/blueprint/components/mod.rs index 9ab4726d6e99..fe806d9a05d7 100644 --- a/crates/re_types/src/blueprint/components/mod.rs +++ b/crates/re_types/src/blueprint/components/mod.rs @@ -6,11 +6,10 @@ mod corner2d; mod corner2d_ext; mod entities_determined_by_user; mod included_contents; -mod included_queries; +mod included_query; mod lock_range_during_zoom; mod row_shares; mod space_view_class; -mod space_view_class_ext; mod space_view_origin; mod visible; @@ -19,7 +18,7 @@ pub use self::column_shares::ColumnShares; pub use self::corner2d::Corner2D; pub use self::entities_determined_by_user::EntitiesDeterminedByUser; pub use self::included_contents::IncludedContents; -pub use self::included_queries::IncludedQueries; +pub use self::included_query::IncludedQuery; pub use self::lock_range_during_zoom::LockRangeDuringZoom; pub use self::row_shares::RowShares; pub use self::space_view_class::SpaceViewClass; diff --git a/crates/re_types/src/blueprint/components/space_view_class_ext.rs b/crates/re_types/src/blueprint/components/space_view_class_ext.rs deleted file mode 100644 index 031b3aaf73e1..000000000000 --- a/crates/re_types/src/blueprint/components/space_view_class_ext.rs +++ /dev/null @@ -1,16 +0,0 @@ -use super::SpaceViewClass; - -// TODO(#4536): These should come for free -impl From<&str> for SpaceViewClass { - #[inline] - fn from(value: &str) -> Self { - Self(value.into()) - } -} - -impl From for SpaceViewClass { - #[inline] - fn from(value: String) -> Self { - Self(value.into()) - } -} diff --git a/crates/re_types/src/blueprint/components/visible.rs b/crates/re_types/src/blueprint/components/visible.rs index bfb5d405da15..7c671219a95e 100644 --- a/crates/re_types/src/blueprint/components/visible.rs +++ b/crates/re_types/src/blueprint/components/visible.rs @@ -22,7 +22,7 @@ use ::re_types_core::{ComponentBatch, MaybeOwnedComponentBatch}; use ::re_types_core::{DeserializationError, DeserializationResult}; /// **Component**: Whether the container, space view, entity or instance is currently visible. -#[derive(Clone, Debug, Copy, PartialEq, Eq)] +#[derive(Clone, Debug, Copy, Default, PartialEq, Eq, PartialOrd, Ord)] #[repr(transparent)] pub struct Visible(pub bool); diff --git a/crates/re_viewer/src/blueprint/validation_gen/mod.rs b/crates/re_viewer/src/blueprint/validation_gen/mod.rs index 093903cab02e..af239955c32c 100644 --- a/crates/re_viewer/src/blueprint/validation_gen/mod.rs +++ b/crates/re_viewer/src/blueprint/validation_gen/mod.rs @@ -9,7 +9,7 @@ pub use re_types::blueprint::components::ColumnShares; pub use re_types::blueprint::components::Corner2D; pub use re_types::blueprint::components::EntitiesDeterminedByUser; pub use re_types::blueprint::components::IncludedContents; -pub use re_types::blueprint::components::IncludedQueries; +pub use re_types::blueprint::components::IncludedQuery; pub use re_types::blueprint::components::LockRangeDuringZoom; pub use re_types::blueprint::components::RowShares; pub use re_types::blueprint::components::SpaceViewClass; @@ -37,7 +37,7 @@ pub fn is_valid_blueprint(blueprint: &EntityDb) -> bool { && validate_component::(blueprint) && validate_component::(blueprint) && validate_component::(blueprint) - && validate_component::(blueprint) + && validate_component::(blueprint) && validate_component::(blueprint) && validate_component::(blueprint) && validate_component::(blueprint) diff --git a/crates/re_viewport/src/blueprint/components/auto_space_views.rs b/crates/re_viewport/src/blueprint/components/auto_space_views.rs index f3fac40c6025..9b147d84ffe0 100644 --- a/crates/re_viewport/src/blueprint/components/auto_space_views.rs +++ b/crates/re_viewport/src/blueprint/components/auto_space_views.rs @@ -24,7 +24,7 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; /// **Component**: Whether or not space views should be created automatically. /// /// Unstable. Used for the ongoing blueprint experimentations. -#[derive(Clone, Debug, Copy, Default)] +#[derive(Clone, Debug, Copy, Default, PartialEq, Eq, PartialOrd, Ord)] #[repr(transparent)] pub struct AutoSpaceViews(pub bool); diff --git a/rerun_cpp/src/rerun/blueprint/archetypes/space_view_blueprint.hpp b/rerun_cpp/src/rerun/blueprint/archetypes/space_view_blueprint.hpp index 7f9ba7f2e26c..8d3fba57da7b 100644 --- a/rerun_cpp/src/rerun/blueprint/archetypes/space_view_blueprint.hpp +++ b/rerun_cpp/src/rerun/blueprint/archetypes/space_view_blueprint.hpp @@ -4,7 +4,7 @@ #pragma once #include "../../blueprint/components/entities_determined_by_user.hpp" -#include "../../blueprint/components/included_queries.hpp" +#include "../../blueprint/components/included_query.hpp" #include "../../blueprint/components/space_view_class.hpp" #include "../../blueprint/components/space_view_origin.hpp" #include "../../blueprint/components/visible.hpp" @@ -40,10 +40,10 @@ namespace rerun::blueprint::archetypes { std::optional entities_determined_by_user; - /// `BlueprintId`s of the `DataQuery`s that make up this `SpaceView`. + /// Ids of the `DataQuery`s that make up this `SpaceView`. /// - /// It determines which entities are part of the spaceview. - std::optional contents; + /// They determine which entities are part of the spaceview. + std::optional> contents; /// Whether this space view is visible. /// @@ -93,10 +93,11 @@ namespace rerun::blueprint::archetypes { RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } - /// `BlueprintId`s of the `DataQuery`s that make up this `SpaceView`. + /// Ids of the `DataQuery`s that make up this `SpaceView`. /// - /// It determines which entities are part of the spaceview. - SpaceViewBlueprint with_contents(rerun::blueprint::components::IncludedQueries _contents + /// They determine which entities are part of the spaceview. + SpaceViewBlueprint with_contents( + Collection _contents ) && { contents = std::move(_contents); // See: https://github.com/rerun-io/rerun/issues/4027 diff --git a/rerun_cpp/src/rerun/blueprint/components.hpp b/rerun_cpp/src/rerun/blueprint/components.hpp index eb115a04310e..a89ec6dd8048 100644 --- a/rerun_cpp/src/rerun/blueprint/components.hpp +++ b/rerun_cpp/src/rerun/blueprint/components.hpp @@ -12,7 +12,7 @@ #include "blueprint/components/entity_properties_component.hpp" #include "blueprint/components/grid_columns.hpp" #include "blueprint/components/included_contents.hpp" -#include "blueprint/components/included_queries.hpp" +#include "blueprint/components/included_query.hpp" #include "blueprint/components/included_space_view.hpp" #include "blueprint/components/lock_range_during_zoom.hpp" #include "blueprint/components/panel_view.hpp" diff --git a/rerun_cpp/src/rerun/blueprint/components/.gitattributes b/rerun_cpp/src/rerun/blueprint/components/.gitattributes index 40719979c7d4..888bf6b6faa1 100644 --- a/rerun_cpp/src/rerun/blueprint/components/.gitattributes +++ b/rerun_cpp/src/rerun/blueprint/components/.gitattributes @@ -21,8 +21,8 @@ grid_columns.cpp linguist-generated=true grid_columns.hpp linguist-generated=true included_contents.cpp linguist-generated=true included_contents.hpp linguist-generated=true -included_queries.cpp linguist-generated=true -included_queries.hpp linguist-generated=true +included_query.cpp linguist-generated=true +included_query.hpp linguist-generated=true included_space_view.cpp linguist-generated=true included_space_view.hpp linguist-generated=true lock_range_during_zoom.cpp linguist-generated=true diff --git a/rerun_cpp/src/rerun/blueprint/components/included_queries.cpp b/rerun_cpp/src/rerun/blueprint/components/included_queries.cpp deleted file mode 100644 index b2d712fd45d4..000000000000 --- a/rerun_cpp/src/rerun/blueprint/components/included_queries.cpp +++ /dev/null @@ -1,77 +0,0 @@ -// DO NOT EDIT! This file was auto-generated by crates/re_types_builder/src/codegen/cpp/mod.rs -// Based on "crates/re_types/definitions/rerun/blueprint/components/included_queries.fbs". - -#include "included_queries.hpp" - -#include "../../datatypes/uuid.hpp" - -#include -#include - -namespace rerun::blueprint::components {} - -namespace rerun { - const std::shared_ptr& - Loggable::arrow_datatype() { - static const auto datatype = arrow::list( - arrow::field("item", Loggable::arrow_datatype(), false) - ); - return datatype; - } - - rerun::Error Loggable::fill_arrow_array_builder( - arrow::ListBuilder* builder, const blueprint::components::IncludedQueries* elements, - size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - auto value_builder = static_cast(builder->value_builder()); - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); - - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - ARROW_RETURN_NOT_OK(builder->Append()); - if (element.query_ids.data()) { - RR_RETURN_NOT_OK(Loggable::fill_arrow_array_builder( - value_builder, - element.query_ids.data(), - element.query_ids.size() - )); - } - } - - return Error::ok(); - } - - Result> - Loggable::to_arrow( - const blueprint::components::IncludedQueries* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); - auto datatype = arrow_datatype(); - - ARROW_ASSIGN_OR_RAISE(auto builder, arrow::MakeBuilder(datatype, pool)) - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - Loggable::fill_arrow_array_builder( - static_cast(builder.get()), - instances, - num_instances - ) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); - return array; - } -} // namespace rerun diff --git a/rerun_cpp/src/rerun/blueprint/components/included_query.cpp b/rerun_cpp/src/rerun/blueprint/components/included_query.cpp new file mode 100644 index 000000000000..ed4b41507883 --- /dev/null +++ b/rerun_cpp/src/rerun/blueprint/components/included_query.cpp @@ -0,0 +1,57 @@ +// DO NOT EDIT! This file was auto-generated by crates/re_types_builder/src/codegen/cpp/mod.rs +// Based on "crates/re_types/definitions/rerun/blueprint/components/included_query.fbs". + +#include "included_query.hpp" + +#include "../../datatypes/uuid.hpp" + +#include +#include + +namespace rerun::blueprint::components {} + +namespace rerun { + const std::shared_ptr& + Loggable::arrow_datatype() { + static const auto datatype = Loggable::arrow_datatype(); + return datatype; + } + + rerun::Error Loggable::fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const blueprint::components::IncludedQuery* elements, + size_t num_elements + ) { + static_assert( + sizeof(rerun::datatypes::Uuid) == sizeof(blueprint::components::IncludedQuery) + ); + RR_RETURN_NOT_OK(Loggable::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); + + return Error::ok(); + } + + Result> Loggable::to_arrow( + const blueprint::components::IncludedQuery* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); + auto datatype = arrow_datatype(); + + ARROW_ASSIGN_OR_RAISE(auto builder, arrow::MakeBuilder(datatype, pool)) + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + Loggable::fill_arrow_array_builder( + static_cast(builder.get()), + instances, + num_instances + ) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + return array; + } +} // namespace rerun diff --git a/rerun_cpp/src/rerun/blueprint/components/included_queries.hpp b/rerun_cpp/src/rerun/blueprint/components/included_query.hpp similarity index 50% rename from rerun_cpp/src/rerun/blueprint/components/included_queries.hpp rename to rerun_cpp/src/rerun/blueprint/components/included_query.hpp index 29ffc8173156..24c4df29ce2a 100644 --- a/rerun_cpp/src/rerun/blueprint/components/included_queries.hpp +++ b/rerun_cpp/src/rerun/blueprint/components/included_query.hpp @@ -1,39 +1,49 @@ // DO NOT EDIT! This file was auto-generated by crates/re_types_builder/src/codegen/cpp/mod.rs -// Based on "crates/re_types/definitions/rerun/blueprint/components/included_queries.fbs". +// Based on "crates/re_types/definitions/rerun/blueprint/components/included_query.fbs". #pragma once -#include "../../collection.hpp" #include "../../datatypes/uuid.hpp" #include "../../result.hpp" +#include #include #include -#include namespace arrow { class Array; class DataType; - class ListBuilder; + class FixedSizeListBuilder; } // namespace arrow namespace rerun::blueprint::components { - /// **Component**: All the queries belonging to a given `SpaceView`. + /// **Component**: Each query id referes to a [`QueryExpressions`] component. /// /// Unstable. Used for the ongoing blueprint experimentations. - struct IncludedQueries { - rerun::Collection query_ids; + struct IncludedQuery { + rerun::datatypes::Uuid query_id; public: - IncludedQueries() = default; + IncludedQuery() = default; - IncludedQueries(rerun::Collection query_ids_) - : query_ids(std::move(query_ids_)) {} + IncludedQuery(rerun::datatypes::Uuid query_id_) : query_id(query_id_) {} - IncludedQueries& operator=(rerun::Collection query_ids_) { - query_ids = std::move(query_ids_); + IncludedQuery& operator=(rerun::datatypes::Uuid query_id_) { + query_id = query_id_; return *this; } + + IncludedQuery(std::array bytes_) : query_id(bytes_) {} + + IncludedQuery& operator=(std::array bytes_) { + query_id = bytes_; + return *this; + } + + /// Cast to the underlying Uuid datatype + operator rerun::datatypes::Uuid() const { + return query_id; + } }; } // namespace rerun::blueprint::components @@ -43,21 +53,21 @@ namespace rerun { /// \private template <> - struct Loggable { - static constexpr const char Name[] = "rerun.blueprint.components.IncludedQueries"; + struct Loggable { + static constexpr const char Name[] = "rerun.blueprint.components.IncludedQuery"; /// Returns the arrow data type this type corresponds to. static const std::shared_ptr& arrow_datatype(); /// Fills an arrow array builder with an array of this type. static rerun::Error fill_arrow_array_builder( - arrow::ListBuilder* builder, const blueprint::components::IncludedQueries* elements, - size_t num_elements + arrow::FixedSizeListBuilder* builder, + const blueprint::components::IncludedQuery* elements, size_t num_elements ); - /// Serializes an array of `rerun::blueprint:: components::IncludedQueries` into an arrow array. + /// Serializes an array of `rerun::blueprint:: components::IncludedQuery` into an arrow array. static Result> to_arrow( - const blueprint::components::IncludedQueries* instances, size_t num_instances + const blueprint::components::IncludedQuery* instances, size_t num_instances ); }; } // namespace rerun diff --git a/rerun_cpp/src/rerun/blueprint/components/query_expressions.hpp b/rerun_cpp/src/rerun/blueprint/components/query_expressions.hpp index 96d0e5b15d0c..56e7cb6cf2ad 100644 --- a/rerun_cpp/src/rerun/blueprint/components/query_expressions.hpp +++ b/rerun_cpp/src/rerun/blueprint/components/query_expressions.hpp @@ -35,7 +35,7 @@ namespace rerun::blueprint::components { /// (`/world/**` matches both `/world` and `/world/car/driver`). /// Other uses of `*` are not (yet) supported. /// - /// `EntityPathFilter` sorts the rule by entity path, with recursive coming before non-recursive. + /// Internally, `EntityPathFilter` sorts the rule by entity path, with recursive coming before non-recursive. /// This means the last matching rule is also the most specific one. /// For instance: /// diff --git a/rerun_py/rerun_sdk/rerun/blueprint/archetypes/space_view_blueprint.py b/rerun_py/rerun_sdk/rerun/blueprint/archetypes/space_view_blueprint.py index 266353cc83b9..bd9f2639e76f 100644 --- a/rerun_py/rerun_sdk/rerun/blueprint/archetypes/space_view_blueprint.py +++ b/rerun_py/rerun_sdk/rerun/blueprint/archetypes/space_view_blueprint.py @@ -28,7 +28,7 @@ def __init__( display_name: datatypes.Utf8Like | None = None, space_origin: datatypes.EntityPathLike | None = None, entities_determined_by_user: blueprint_components.EntitiesDeterminedByUserLike | None = None, - contents: blueprint_components.IncludedQueriesLike | None = None, + contents: datatypes.UuidArrayLike | None = None, visible: blueprint_components.VisibleLike | None = None, ): """ @@ -49,9 +49,9 @@ def __init__( entities_determined_by_user: True if the user is has added entities themselves. False otherwise. contents: - `BlueprintId`s of the `DataQuery`s that make up this `SpaceView`. + Ids of the `DataQuery`s that make up this `SpaceView`. - It determines which entities are part of the spaceview. + They determine which entities are part of the spaceview. visible: Whether this space view is visible. @@ -129,14 +129,14 @@ def _clear(cls) -> SpaceViewBlueprint: # # (Docstring intentionally commented out to hide this field from the docs) - contents: blueprint_components.IncludedQueriesBatch | None = field( + contents: blueprint_components.IncludedQueryBatch | None = field( metadata={"component": "optional"}, default=None, - converter=blueprint_components.IncludedQueriesBatch._optional, # type: ignore[misc] + converter=blueprint_components.IncludedQueryBatch._optional, # type: ignore[misc] ) - # `BlueprintId`s of the `DataQuery`s that make up this `SpaceView`. + # Ids of the `DataQuery`s that make up this `SpaceView`. # - # It determines which entities are part of the spaceview. + # They determine which entities are part of the spaceview. # # (Docstring intentionally commented out to hide this field from the docs) diff --git a/rerun_py/rerun_sdk/rerun/blueprint/components/.gitattributes b/rerun_py/rerun_sdk/rerun/blueprint/components/.gitattributes index 811e3c4fa2b3..59c6ef16ae1a 100644 --- a/rerun_py/rerun_sdk/rerun/blueprint/components/.gitattributes +++ b/rerun_py/rerun_sdk/rerun/blueprint/components/.gitattributes @@ -12,7 +12,7 @@ entities_determined_by_user.py linguist-generated=true entity_properties_component.py linguist-generated=true grid_columns.py linguist-generated=true included_contents.py linguist-generated=true -included_queries.py linguist-generated=true +included_query.py linguist-generated=true included_space_view.py linguist-generated=true lock_range_during_zoom.py linguist-generated=true panel_view.py linguist-generated=true diff --git a/rerun_py/rerun_sdk/rerun/blueprint/components/__init__.py b/rerun_py/rerun_sdk/rerun/blueprint/components/__init__.py index 4fde4821b7fe..6794927fc3d5 100644 --- a/rerun_py/rerun_sdk/rerun/blueprint/components/__init__.py +++ b/rerun_py/rerun_sdk/rerun/blueprint/components/__init__.py @@ -42,13 +42,7 @@ IncludedContentsLike, IncludedContentsType, ) -from .included_queries import ( - IncludedQueries, - IncludedQueriesArrayLike, - IncludedQueriesBatch, - IncludedQueriesLike, - IncludedQueriesType, -) +from .included_query import IncludedQuery, IncludedQueryBatch, IncludedQueryType from .included_space_view import IncludedSpaceView, IncludedSpaceViewBatch, IncludedSpaceViewType from .lock_range_during_zoom import ( LockRangeDuringZoom, @@ -121,11 +115,9 @@ "IncludedContentsBatch", "IncludedContentsLike", "IncludedContentsType", - "IncludedQueries", - "IncludedQueriesArrayLike", - "IncludedQueriesBatch", - "IncludedQueriesLike", - "IncludedQueriesType", + "IncludedQuery", + "IncludedQueryBatch", + "IncludedQueryType", "IncludedSpaceView", "IncludedSpaceViewBatch", "IncludedSpaceViewType", diff --git a/rerun_py/rerun_sdk/rerun/blueprint/components/included_queries.py b/rerun_py/rerun_sdk/rerun/blueprint/components/included_queries.py deleted file mode 100644 index 02282866b80c..000000000000 --- a/rerun_py/rerun_sdk/rerun/blueprint/components/included_queries.py +++ /dev/null @@ -1,72 +0,0 @@ -# DO NOT EDIT! This file was auto-generated by crates/re_types_builder/src/codegen/python/mod.rs -# Based on "crates/re_types/definitions/rerun/blueprint/components/included_queries.fbs". - -# You can extend this class by creating a "IncludedQueriesExt" class in "included_queries_ext.py". - -from __future__ import annotations - -from typing import Any, Sequence, Union - -import pyarrow as pa -from attrs import define, field - -from ... import datatypes -from ..._baseclasses import BaseBatch, BaseExtensionType, ComponentBatchMixin - -__all__ = [ - "IncludedQueries", - "IncludedQueriesArrayLike", - "IncludedQueriesBatch", - "IncludedQueriesLike", - "IncludedQueriesType", -] - - -@define(init=False) -class IncludedQueries: - """ - **Component**: All the queries belonging to a given `SpaceView`. - - Unstable. Used for the ongoing blueprint experimentations. - """ - - def __init__(self: Any, query_ids: IncludedQueriesLike): - """Create a new instance of the IncludedQueries component.""" - - # You can define your own __init__ function as a member of IncludedQueriesExt in included_queries_ext.py - self.__attrs_init__(query_ids=query_ids) - - query_ids: list[datatypes.Uuid] = field() - - -IncludedQueriesLike = IncludedQueries -IncludedQueriesArrayLike = Union[ - IncludedQueries, - Sequence[IncludedQueriesLike], -] - - -class IncludedQueriesType(BaseExtensionType): - _TYPE_NAME: str = "rerun.blueprint.components.IncludedQueries" - - def __init__(self) -> None: - pa.ExtensionType.__init__( - self, - pa.list_( - pa.field( - "item", - pa.list_(pa.field("item", pa.uint8(), nullable=False, metadata={}), 16), - nullable=False, - metadata={}, - ) - ), - self._TYPE_NAME, - ) - - -class IncludedQueriesBatch(BaseBatch[IncludedQueriesArrayLike], ComponentBatchMixin): - _ARROW_TYPE = IncludedQueriesType() - - @staticmethod - def _native_to_pa_array(data: IncludedQueriesArrayLike, data_type: pa.DataType) -> pa.Array: - raise NotImplementedError # You need to implement native_to_pa_array_override in included_queries_ext.py diff --git a/rerun_py/rerun_sdk/rerun/blueprint/components/included_query.py b/rerun_py/rerun_sdk/rerun/blueprint/components/included_query.py new file mode 100644 index 000000000000..48f93940e50d --- /dev/null +++ b/rerun_py/rerun_sdk/rerun/blueprint/components/included_query.py @@ -0,0 +1,32 @@ +# DO NOT EDIT! This file was auto-generated by crates/re_types_builder/src/codegen/python/mod.rs +# Based on "crates/re_types/definitions/rerun/blueprint/components/included_query.fbs". + +# You can extend this class by creating a "IncludedQueryExt" class in "included_query_ext.py". + +from __future__ import annotations + +from ... import datatypes +from ..._baseclasses import ComponentBatchMixin + +__all__ = ["IncludedQuery", "IncludedQueryBatch", "IncludedQueryType"] + + +class IncludedQuery(datatypes.Uuid): + """ + **Component**: Each query id referes to a [`QueryExpressions`] component. + + Unstable. Used for the ongoing blueprint experimentations. + """ + + # You can define your own __init__ function as a member of IncludedQueryExt in included_query_ext.py + + # Note: there are no fields here because IncludedQuery delegates to datatypes.Uuid + pass + + +class IncludedQueryType(datatypes.UuidType): + _TYPE_NAME: str = "rerun.blueprint.components.IncludedQuery" + + +class IncludedQueryBatch(datatypes.UuidBatch, ComponentBatchMixin): + _ARROW_TYPE = IncludedQueryType() diff --git a/rerun_py/rerun_sdk/rerun/blueprint/components/query_expressions.py b/rerun_py/rerun_sdk/rerun/blueprint/components/query_expressions.py index 25ed88fa5dc3..91e8c2a07f9d 100644 --- a/rerun_py/rerun_sdk/rerun/blueprint/components/query_expressions.py +++ b/rerun_py/rerun_sdk/rerun/blueprint/components/query_expressions.py @@ -42,7 +42,7 @@ class QueryExpressions: (`/world/**` matches both `/world` and `/world/car/driver`). Other uses of `*` are not (yet) supported. - `EntityPathFilter` sorts the rule by entity path, with recursive coming before non-recursive. + Internally, `EntityPathFilter` sorts the rule by entity path, with recursive coming before non-recursive. This means the last matching rule is also the most specific one. For instance: diff --git a/rerun_py/tests/unit/test_space_view_blueprint.py b/rerun_py/tests/unit/test_space_view_blueprint.py index a3dfdc8c0e0f..dce642a83e89 100644 --- a/rerun_py/tests/unit/test_space_view_blueprint.py +++ b/rerun_py/tests/unit/test_space_view_blueprint.py @@ -3,32 +3,35 @@ import itertools from rerun.blueprint.archetypes.space_view_blueprint import SpaceViewBlueprint -from rerun.blueprint.components.entities_determined_by_user import EntitiesDeterminedByUserBatch -from rerun.blueprint.components.space_view_class import SpaceViewClassBatch -from rerun.blueprint.components.space_view_origin import SpaceViewOriginBatch -from rerun.blueprint.components.visible import VisibleBatch -from rerun.components.name import NameBatch +from rerun.blueprint.components.entities_determined_by_user import EntitiesDeterminedByUserBatch, EntitiesDeterminedByUser +from rerun.blueprint.components.included_query import IncludedQueryBatch, IncludedQuery +from rerun.blueprint.components.space_view_class import SpaceViewClassBatch, SpaceViewClass +from rerun.blueprint.components.space_view_origin import SpaceViewOriginBatch, SpaceViewOrigin +from rerun.blueprint.components.visible import VisibleBatch, Visible +from rerun.components.name import NameBatch, Name -from .common_arrays import none_empty_or_value +from .common_arrays import none_empty_or_value, uuid_bytes0, uuid_bytes1 def test_space_view_blueprint() -> None: - class_identifier_arrays = ["3D", "TimeSeries"] - display_name_arrays = ["3D View", "Time Series View", None] - space_origin_arrays = ["/", None, "/robot/arm"] - entities_determined_by_user_arrays = [True, False, None] - visible_arrays = [False, True, None] + class_identifier_arrays = ["3D", SpaceViewClass("3D")] + display_name_arrays = ["3D View", Name("3D View"), None] + space_origin_arrays = ["/robot/arm", None, SpaceViewOrigin("/robot/arm")] + entities_determined_by_user_arrays = [False, EntitiesDeterminedByUser(False), None] + contents_arrays = [[uuid_bytes0, uuid_bytes1], [IncludedQuery(uuid_bytes0), IncludedQuery(uuid_bytes1)], None] + visible_arrays = [False, Visible(False), None] all_arrays = itertools.zip_longest( class_identifier_arrays, display_name_arrays, space_origin_arrays, entities_determined_by_user_arrays, + contents_arrays, visible_arrays, ) # for space_views, layout, root_container, maximized, auto_layout, auto_space_views in all_arrays: - for class_identifier, display_name, space_origin, entities_determined_by_user, visible in all_arrays: + for class_identifier, display_name, space_origin, entities_determined_by_user, contents, visible in all_arrays: class_identifier = class_identifier if class_identifier is not None else class_identifier_arrays[-1] print( @@ -37,6 +40,7 @@ def test_space_view_blueprint() -> None: f" display_name={display_name!r}\n", f" space_origin={space_origin!r}\n", f" entities_determined_by_user={entities_determined_by_user!r}\n", + f" contents={contents!r}\n", f" visible={visible!r}\n", ")", ) @@ -45,15 +49,17 @@ def test_space_view_blueprint() -> None: display_name=display_name, space_origin=space_origin, entities_determined_by_user=entities_determined_by_user, + contents=contents, visible=visible, ) print(f"{arch}\n") # Equality checks on some of these are a bit silly, but at least they test out that the serialization code runs without problems. - assert arch.class_identifier == SpaceViewClassBatch(class_identifier) - assert arch.display_name == NameBatch._optional(none_empty_or_value(display_name, display_name)) - assert arch.space_origin == SpaceViewOriginBatch._optional(none_empty_or_value(space_origin, space_origin)) + assert arch.class_identifier == SpaceViewClassBatch("3D") + assert arch.display_name == NameBatch._optional(none_empty_or_value(display_name, "3D View")) + assert arch.space_origin == SpaceViewOriginBatch._optional(none_empty_or_value(space_origin, "/robot/arm")) assert arch.entities_determined_by_user == EntitiesDeterminedByUserBatch._optional( - none_empty_or_value(entities_determined_by_user, entities_determined_by_user) + none_empty_or_value(arch.entities_determined_by_user, False) ) - assert arch.visible == VisibleBatch._optional(none_empty_or_value(visible, visible)) + assert arch.contents == IncludedQueryBatch._optional(none_empty_or_value(contents, [uuid_bytes0, uuid_bytes1])) + assert arch.visible == VisibleBatch._optional(none_empty_or_value(visible, False)) diff --git a/rerun_py/tests/unit/test_viewport_blueprint.py b/rerun_py/tests/unit/test_viewport_blueprint.py index a702271d6c71..6bda35b8f607 100644 --- a/rerun_py/tests/unit/test_viewport_blueprint.py +++ b/rerun_py/tests/unit/test_viewport_blueprint.py @@ -33,7 +33,7 @@ def test_viewport_blueprint() -> None: auto_space_views_arrays, ) - for space_views, root_container, maximized, auto_layout, auto_space_view in all_arrays: + for space_views, root_container, maximized, auto_layout, auto_space_views in all_arrays: space_views = space_views if space_views is not None else space_views_arrays[-1] print( @@ -42,7 +42,7 @@ def test_viewport_blueprint() -> None: f" root_container={root_container!r}\n", f" maximized={maximized!r}\n", f" auto_layout={auto_layout!r}\n", - f" auto_space_views={auto_space_view!r}\n", + f" auto_space_views={auto_space_views!r}\n", ")", ) arch = ViewportBlueprint( @@ -50,7 +50,7 @@ def test_viewport_blueprint() -> None: root_container=root_container, maximized=maximized, auto_layout=auto_layout, - auto_space_views=auto_space_view, + auto_space_views=auto_space_views, ) print(f"{arch}\n") @@ -58,4 +58,4 @@ def test_viewport_blueprint() -> None: assert arch.root_container == RootContainerBatch._optional(none_empty_or_value(root_container, uuid_bytes0)) assert arch.maximized == SpaceViewMaximizedBatch._optional(none_empty_or_value(maximized, uuid_bytes1)) assert arch.auto_layout == AutoLayoutBatch._optional(none_empty_or_value(auto_layout, True)) - assert arch.auto_space_views == AutoSpaceViewsBatch._optional(none_empty_or_value(auto_space_view, False)) + assert arch.auto_space_views == AutoSpaceViewsBatch._optional(none_empty_or_value(auto_space_views, False)) From b7b64ee5817263927d3e903f2eb48dc4e9668044 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Tue, 5 Mar 2024 15:35:15 +0100 Subject: [PATCH 6/9] python formatting --- .../rerun_sdk/rerun/datatypes/entity_path_ext.py | 1 - rerun_py/rerun_sdk/rerun/datatypes/utf8_ext.py | 1 - rerun_py/tests/unit/test_space_view_blueprint.py | 15 +++++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/rerun_py/rerun_sdk/rerun/datatypes/entity_path_ext.py b/rerun_py/rerun_sdk/rerun/datatypes/entity_path_ext.py index 1d4e947e8104..9d372555cec7 100644 --- a/rerun_py/rerun_sdk/rerun/datatypes/entity_path_ext.py +++ b/rerun_py/rerun_sdk/rerun/datatypes/entity_path_ext.py @@ -1,5 +1,4 @@ from __future__ import annotations -from __future__ import annotations from typing import TYPE_CHECKING, Sequence diff --git a/rerun_py/rerun_sdk/rerun/datatypes/utf8_ext.py b/rerun_py/rerun_sdk/rerun/datatypes/utf8_ext.py index 230a40ca07a8..f0c243d1f182 100644 --- a/rerun_py/rerun_sdk/rerun/datatypes/utf8_ext.py +++ b/rerun_py/rerun_sdk/rerun/datatypes/utf8_ext.py @@ -1,5 +1,4 @@ from __future__ import annotations -from __future__ import annotations from typing import TYPE_CHECKING, Sequence diff --git a/rerun_py/tests/unit/test_space_view_blueprint.py b/rerun_py/tests/unit/test_space_view_blueprint.py index dce642a83e89..98da5af621dc 100644 --- a/rerun_py/tests/unit/test_space_view_blueprint.py +++ b/rerun_py/tests/unit/test_space_view_blueprint.py @@ -3,12 +3,15 @@ import itertools from rerun.blueprint.archetypes.space_view_blueprint import SpaceViewBlueprint -from rerun.blueprint.components.entities_determined_by_user import EntitiesDeterminedByUserBatch, EntitiesDeterminedByUser -from rerun.blueprint.components.included_query import IncludedQueryBatch, IncludedQuery -from rerun.blueprint.components.space_view_class import SpaceViewClassBatch, SpaceViewClass -from rerun.blueprint.components.space_view_origin import SpaceViewOriginBatch, SpaceViewOrigin -from rerun.blueprint.components.visible import VisibleBatch, Visible -from rerun.components.name import NameBatch, Name +from rerun.blueprint.components.entities_determined_by_user import ( + EntitiesDeterminedByUser, + EntitiesDeterminedByUserBatch, +) +from rerun.blueprint.components.included_query import IncludedQuery, IncludedQueryBatch +from rerun.blueprint.components.space_view_class import SpaceViewClass, SpaceViewClassBatch +from rerun.blueprint.components.space_view_origin import SpaceViewOrigin, SpaceViewOriginBatch +from rerun.blueprint.components.visible import Visible, VisibleBatch +from rerun.components.name import Name, NameBatch from .common_arrays import none_empty_or_value, uuid_bytes0, uuid_bytes1 From 048a468cd3bbc3c54816ef4a694f9fbd9caf2cd6 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Tue, 5 Mar 2024 15:45:28 +0100 Subject: [PATCH 7/9] typo fix --- .../definitions/rerun/blueprint/components/included_query.fbs | 2 +- crates/re_types/src/blueprint/components/included_query.rs | 2 +- rerun_cpp/src/rerun/blueprint/components/included_query.hpp | 2 +- rerun_py/rerun_sdk/rerun/blueprint/components/included_query.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/re_types/definitions/rerun/blueprint/components/included_query.fbs b/crates/re_types/definitions/rerun/blueprint/components/included_query.fbs index ef7b6e08bc8d..f18c7519a3a1 100644 --- a/crates/re_types/definitions/rerun/blueprint/components/included_query.fbs +++ b/crates/re_types/definitions/rerun/blueprint/components/included_query.fbs @@ -10,7 +10,7 @@ namespace rerun.blueprint.components; // --- -/// Each query id referes to a [`QueryExpressions`] component. +/// Each query id refers to a [`QueryExpressions`] component. /// /// Unstable. Used for the ongoing blueprint experimentations. table IncludedQuery ( diff --git a/crates/re_types/src/blueprint/components/included_query.rs b/crates/re_types/src/blueprint/components/included_query.rs index 20207afc7ab2..6b9e2978c3e1 100644 --- a/crates/re_types/src/blueprint/components/included_query.rs +++ b/crates/re_types/src/blueprint/components/included_query.rs @@ -21,7 +21,7 @@ use ::re_types_core::SerializationResult; use ::re_types_core::{ComponentBatch, MaybeOwnedComponentBatch}; use ::re_types_core::{DeserializationError, DeserializationResult}; -/// **Component**: Each query id referes to a [`QueryExpressions`] component. +/// **Component**: Each query id refers to a [`QueryExpressions`] component. /// /// Unstable. Used for the ongoing blueprint experimentations. #[derive(Clone, Debug, Default)] diff --git a/rerun_cpp/src/rerun/blueprint/components/included_query.hpp b/rerun_cpp/src/rerun/blueprint/components/included_query.hpp index 24c4df29ce2a..cc7321b08f01 100644 --- a/rerun_cpp/src/rerun/blueprint/components/included_query.hpp +++ b/rerun_cpp/src/rerun/blueprint/components/included_query.hpp @@ -17,7 +17,7 @@ namespace arrow { } // namespace arrow namespace rerun::blueprint::components { - /// **Component**: Each query id referes to a [`QueryExpressions`] component. + /// **Component**: Each query id refers to a [`QueryExpressions`] component. /// /// Unstable. Used for the ongoing blueprint experimentations. struct IncludedQuery { diff --git a/rerun_py/rerun_sdk/rerun/blueprint/components/included_query.py b/rerun_py/rerun_sdk/rerun/blueprint/components/included_query.py index 48f93940e50d..e98aa956c0e8 100644 --- a/rerun_py/rerun_sdk/rerun/blueprint/components/included_query.py +++ b/rerun_py/rerun_sdk/rerun/blueprint/components/included_query.py @@ -13,7 +13,7 @@ class IncludedQuery(datatypes.Uuid): """ - **Component**: Each query id referes to a [`QueryExpressions`] component. + **Component**: Each query id refers to a [`QueryExpressions`] component. Unstable. Used for the ongoing blueprint experimentations. """ From 09b8f815e7519af3ba7601b22eea6bb6aecfa570 Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Tue, 5 Mar 2024 10:35:18 -0500 Subject: [PATCH 8/9] Add lints to fix casts --- rerun_py/tests/unit/test_space_view_blueprint.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/rerun_py/tests/unit/test_space_view_blueprint.py b/rerun_py/tests/unit/test_space_view_blueprint.py index 98da5af621dc..5513fb18040b 100644 --- a/rerun_py/tests/unit/test_space_view_blueprint.py +++ b/rerun_py/tests/unit/test_space_view_blueprint.py @@ -1,17 +1,22 @@ from __future__ import annotations import itertools +from typing import Optional, cast from rerun.blueprint.archetypes.space_view_blueprint import SpaceViewBlueprint from rerun.blueprint.components.entities_determined_by_user import ( EntitiesDeterminedByUser, EntitiesDeterminedByUserBatch, + EntitiesDeterminedByUserLike, ) from rerun.blueprint.components.included_query import IncludedQuery, IncludedQueryBatch from rerun.blueprint.components.space_view_class import SpaceViewClass, SpaceViewClassBatch from rerun.blueprint.components.space_view_origin import SpaceViewOrigin, SpaceViewOriginBatch -from rerun.blueprint.components.visible import Visible, VisibleBatch +from rerun.blueprint.components.visible import Visible, VisibleBatch, VisibleLike from rerun.components.name import Name, NameBatch +from rerun.datatypes.entity_path import EntityPathLike +from rerun.datatypes.utf8 import Utf8Like +from rerun.datatypes.uuid import UuidArrayLike from .common_arrays import none_empty_or_value, uuid_bytes0, uuid_bytes1 @@ -37,6 +42,14 @@ def test_space_view_blueprint() -> None: for class_identifier, display_name, space_origin, entities_determined_by_user, contents, visible in all_arrays: class_identifier = class_identifier if class_identifier is not None else class_identifier_arrays[-1] + # mypy can't track types properly through itertools zip so re-cast + class_identifier = cast(Utf8Like, class_identifier) + display_name = cast(Optional[Utf8Like], display_name) + space_origin = cast(Optional[EntityPathLike], space_origin) + entities_determined_by_user = cast(Optional[EntitiesDeterminedByUserLike], entities_determined_by_user) + contents = cast(Optional[UuidArrayLike], contents) + visible = cast(Optional[VisibleLike], visible) + print( "rr.SpaceViewBlueprint(\n", f" class_identifier={class_identifier!r}\n", From 4095985db6d11b3625e845b512983983c0bbea7a Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Tue, 5 Mar 2024 10:55:20 -0500 Subject: [PATCH 9/9] Lint --- .../definitions/rerun/blueprint/components/included_query.fbs | 2 +- crates/re_types/src/blueprint/components/included_query.rs | 2 +- rerun_cpp/src/rerun/blueprint/components/included_query.hpp | 2 +- rerun_py/rerun_sdk/rerun/blueprint/components/included_query.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/re_types/definitions/rerun/blueprint/components/included_query.fbs b/crates/re_types/definitions/rerun/blueprint/components/included_query.fbs index f18c7519a3a1..194479a4e830 100644 --- a/crates/re_types/definitions/rerun/blueprint/components/included_query.fbs +++ b/crates/re_types/definitions/rerun/blueprint/components/included_query.fbs @@ -10,7 +10,7 @@ namespace rerun.blueprint.components; // --- -/// Each query id refers to a [`QueryExpressions`] component. +/// Each query id refers to a `QueryExpression` component. /// /// Unstable. Used for the ongoing blueprint experimentations. table IncludedQuery ( diff --git a/crates/re_types/src/blueprint/components/included_query.rs b/crates/re_types/src/blueprint/components/included_query.rs index 6b9e2978c3e1..a5c982e3837b 100644 --- a/crates/re_types/src/blueprint/components/included_query.rs +++ b/crates/re_types/src/blueprint/components/included_query.rs @@ -21,7 +21,7 @@ use ::re_types_core::SerializationResult; use ::re_types_core::{ComponentBatch, MaybeOwnedComponentBatch}; use ::re_types_core::{DeserializationError, DeserializationResult}; -/// **Component**: Each query id refers to a [`QueryExpressions`] component. +/// **Component**: Each query id refers to a `QueryExpression` component. /// /// Unstable. Used for the ongoing blueprint experimentations. #[derive(Clone, Debug, Default)] diff --git a/rerun_cpp/src/rerun/blueprint/components/included_query.hpp b/rerun_cpp/src/rerun/blueprint/components/included_query.hpp index cc7321b08f01..9a2e4db52ab2 100644 --- a/rerun_cpp/src/rerun/blueprint/components/included_query.hpp +++ b/rerun_cpp/src/rerun/blueprint/components/included_query.hpp @@ -17,7 +17,7 @@ namespace arrow { } // namespace arrow namespace rerun::blueprint::components { - /// **Component**: Each query id refers to a [`QueryExpressions`] component. + /// **Component**: Each query id refers to a `QueryExpression` component. /// /// Unstable. Used for the ongoing blueprint experimentations. struct IncludedQuery { diff --git a/rerun_py/rerun_sdk/rerun/blueprint/components/included_query.py b/rerun_py/rerun_sdk/rerun/blueprint/components/included_query.py index e98aa956c0e8..3ee1d5f740dc 100644 --- a/rerun_py/rerun_sdk/rerun/blueprint/components/included_query.py +++ b/rerun_py/rerun_sdk/rerun/blueprint/components/included_query.py @@ -13,7 +13,7 @@ class IncludedQuery(datatypes.Uuid): """ - **Component**: Each query id refers to a [`QueryExpressions`] component. + **Component**: Each query id refers to a `QueryExpression` component. Unstable. Used for the ongoing blueprint experimentations. """