From 4aa46087cd8df3397f915e68d1f6f0e6a5a82ae6 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Thu, 30 Jan 2025 11:49:52 +0100 Subject: [PATCH 1/4] Python `ComponentBatchMixin` has now `described` utility --- docs/snippets/all/descriptors/descr_builtin_component.py | 6 +++++- rerun_py/rerun_sdk/rerun/_baseclasses.py | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/snippets/all/descriptors/descr_builtin_component.py b/docs/snippets/all/descriptors/descr_builtin_component.py index 7b206526066e..c811d7e11e47 100644 --- a/docs/snippets/all/descriptors/descr_builtin_component.py +++ b/docs/snippets/all/descriptors/descr_builtin_component.py @@ -7,6 +7,10 @@ rr.init("rerun_example_descriptors_builtin_component") rr.spawn() -rr.log("data", [rr.components.Position3DBatch([1, 2, 3])], static=True) +rr.log( + "data", + [rr.components.Position3DBatch([1, 2, 3]).described()], + static=True, +) # The tags are indirectly checked by the Rust version (have a look over there for more info). diff --git a/rerun_py/rerun_sdk/rerun/_baseclasses.py b/rerun_py/rerun_sdk/rerun/_baseclasses.py index de07020e7395..891b3f75bd40 100644 --- a/rerun_py/rerun_sdk/rerun/_baseclasses.py +++ b/rerun_py/rerun_sdk/rerun/_baseclasses.py @@ -491,6 +491,12 @@ def component_descriptor(self) -> ComponentDescriptor: """ return self._COMPONENT_DESCRIPTOR # type: ignore[attr-defined, no-any-return] + def described(self, descriptor: ComponentDescriptor | None = None) -> DescribedComponentBatch: + """Wraps the current `ComponentBatchLike` in a `DescribedComponentBatch` with the given descriptor or, if None, the component's descriptor.""" + if descriptor is None: + descriptor = self.component_descriptor() + return DescribedComponentBatch(self, descriptor) + def with_descriptor(self, descriptor: ComponentDescriptor) -> DescribedComponentBatch: """Wraps the current `ComponentBatchLike` in a `DescribedComponentBatch` with the given descriptor.""" return DescribedComponentBatch(self, descriptor) From 9a877d411fab4563b569305ade88b48c8daa83fe Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Thu, 30 Jan 2025 11:54:26 +0100 Subject: [PATCH 2/4] C++ component batch & component column have now default arguments for descriptors --- .../descriptors/descr_builtin_component.cpp | 5 +-- rerun_cpp/src/rerun/component_batch.hpp | 12 ++++--- rerun_cpp/src/rerun/component_column.hpp | 5 +-- rerun_cpp/tests/recording_stream.cpp | 33 ++++++++----------- 4 files changed, 25 insertions(+), 30 deletions(-) diff --git a/docs/snippets/all/descriptors/descr_builtin_component.cpp b/docs/snippets/all/descriptors/descr_builtin_component.cpp index 425f7883bc31..22b3feb15c04 100644 --- a/docs/snippets/all/descriptors/descr_builtin_component.cpp +++ b/docs/snippets/all/descriptors/descr_builtin_component.cpp @@ -6,10 +6,7 @@ int main() { rec.log_static( "data", - rerun::ComponentBatch::from_loggable( - {1.0f, 2.0f, 3.0f}, - rerun::Loggable::Descriptor - ) + rerun::ComponentBatch::from_loggable(rerun::Position3D(1.0f, 2.0f, 3.0f)) ); // The tags are indirectly checked by the Rust version (have a look over there for more info). diff --git a/rerun_cpp/src/rerun/component_batch.hpp b/rerun_cpp/src/rerun/component_batch.hpp index 3856fe8dc741..37eef13f1f60 100644 --- a/rerun_cpp/src/rerun/component_batch.hpp +++ b/rerun_cpp/src/rerun/component_batch.hpp @@ -40,7 +40,9 @@ namespace rerun { /// Automatically registers the component type the first time this type is encountered. template static Result from_loggable( - const rerun::Collection& components, const ComponentDescriptor& descriptor + const rerun::Collection& components, + const ComponentDescriptor& descriptor = rerun::Loggable::Descriptor + ) { static_assert( rerun::is_loggable, @@ -86,7 +88,8 @@ namespace rerun { /// Automatically registers the component type the first time this type is encountered. template static Result from_loggable( - const T& component, const ComponentDescriptor& descriptor + const T& component, + const ComponentDescriptor& descriptor = rerun::Loggable::Descriptor ) { // Collection adapter will automatically borrow for single elements, but let's do this explicitly, avoiding the extra hoop. const auto collection = Collection::borrow(&component, 1); @@ -100,7 +103,8 @@ namespace rerun { /// Automatically registers the component type the first time this type is encountered. template static Result from_loggable( - const std::optional& component, const ComponentDescriptor& descriptor + const std::optional& component, + const ComponentDescriptor& descriptor = rerun::Loggable::Descriptor ) { if (component.has_value()) { return from_loggable(component.value(), descriptor); @@ -117,7 +121,7 @@ namespace rerun { template static Result from_loggable( const std::optional>& components, - const ComponentDescriptor& descriptor + const ComponentDescriptor& descriptor = rerun::Loggable::Descriptor ) { if (components.has_value()) { return from_loggable(components.value(), descriptor); diff --git a/rerun_cpp/src/rerun/component_column.hpp b/rerun_cpp/src/rerun/component_column.hpp index 4ddb2a6d70d1..307c66f3adfb 100644 --- a/rerun_cpp/src/rerun/component_column.hpp +++ b/rerun_cpp/src/rerun/component_column.hpp @@ -37,7 +37,7 @@ namespace rerun { template static Result from_loggable_with_lengths( const Collection& components, const Collection& lengths, - const ComponentDescriptor& descriptor + const ComponentDescriptor& descriptor = rerun::Loggable::Descriptor ) { auto component_batch_result = ComponentBatch::from_loggable(components, descriptor); if (component_batch_result.is_err()) { @@ -57,7 +57,8 @@ namespace rerun { /// \param descriptor Descriptor of the component type for this column. template static Result from_loggable( - const Collection& components, const ComponentDescriptor& descriptor + const Collection& components, + const ComponentDescriptor& descriptor = rerun::Loggable::Descriptor ) { return ComponentColumn::from_loggable_with_lengths( components, diff --git a/rerun_cpp/tests/recording_stream.cpp b/rerun_cpp/tests/recording_stream.cpp index 0cda74b2227f..a00000442b1d 100644 --- a/rerun_cpp/tests/recording_stream.cpp +++ b/rerun_cpp/tests/recording_stream.cpp @@ -148,15 +148,12 @@ SCENARIO("RecordingStream can be used for logging archetypes and components", TE GIVEN("component batches") { auto batch0 = rerun::ComponentBatch::from_loggable( - {{1.0, 2.0}, {4.0, 5.0}}, - rerun::Loggable::Descriptor - ) - .value_or_throw(); - auto batch1 = rerun::ComponentBatch::from_loggable( - {rerun::Color(0xFF0000FF)}, - rerun::Loggable::Descriptor - ) - .value_or_throw(); + {{1.0, 2.0}, {4.0, 5.0}} + ).value_or_throw(); + auto batch1 = + rerun::ComponentBatch::from_loggable({rerun::Color(0xFF0000FF) + }) + .value_or_throw(); THEN("single component batch can be logged") { stream.log("log_archetype-splat", batch0); stream.log_static("log_archetype-splat", batch0); @@ -173,13 +170,11 @@ SCENARIO("RecordingStream can be used for logging archetypes and components", TE } GIVEN("component batches wrapped in `rerun::Result`") { auto batch0 = rerun::ComponentBatch::from_loggable( - {{1.0, 2.0}, {4.0, 5.0}}, - rerun::Loggable::Descriptor - ); - auto batch1 = rerun::ComponentBatch::from_loggable( - {rerun::Color(0xFF0000FF)}, - rerun::Loggable::Descriptor + {{1.0, 2.0}, {4.0, 5.0}} ); + auto batch1 = + rerun::ComponentBatch::from_loggable({rerun::Color(0xFF0000FF) + }); THEN("single component batch can be logged") { stream.log("log_archetype-splat", batch0); stream.log_static("log_archetype-splat", batch0); @@ -191,7 +186,8 @@ SCENARIO("RecordingStream can be used for logging archetypes and components", TE THEN("collection of component batch results can be logged") { rerun::Collection> batches = { batch0, - batch1}; + batch1 + }; stream.log("log_archetype-splat", batches); stream.log_static("log_archetype-splat", batches); } @@ -408,10 +404,7 @@ SCENARIO("Recording stream handles serialization failure during logging graceful expected_error.code = GENERATE(rerun::ErrorCode::Unknown, rerun::ErrorCode::ArrowStatusCode_TypeError); - auto batch_result = rerun::ComponentBatch::from_loggable( - component, - rerun::Loggable::Descriptor - ); + auto batch_result = rerun::ComponentBatch::from_loggable(component); THEN("calling log with that batch logs the serialization error") { check_logged_error([&] { stream.log(path, batch_result); }, expected_error.code); From 75ac59452bb251304c8bd94069be1aa502c2079d Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Thu, 30 Jan 2025 11:54:41 +0100 Subject: [PATCH 3/4] sample cosmetics --- docs/snippets/all/descriptors/descr_builtin_component.rs | 5 ++--- docs/snippets/all/descriptors/descr_custom_archetype.cpp | 8 ++++---- docs/snippets/all/descriptors/descr_custom_archetype.rs | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/docs/snippets/all/descriptors/descr_builtin_component.rs b/docs/snippets/all/descriptors/descr_builtin_component.rs index dfb391127036..8b6a3bb0dc21 100644 --- a/docs/snippets/all/descriptors/descr_builtin_component.rs +++ b/docs/snippets/all/descriptors/descr_builtin_component.rs @@ -2,10 +2,9 @@ use rerun::{ChunkStore, ChunkStoreConfig, Component as _, ComponentDescriptor, V fn example(rec: &rerun::RecordingStream) -> Result<(), Box> { use rerun::ComponentBatch as _; - rec.log_serialized_batches( + rec.log_static( "data", - true, - [rerun::components::Position3D::new(1.0, 2.0, 3.0).try_serialized()?], + &[rerun::components::Position3D::new(1.0, 2.0, 3.0).try_serialized()?], )?; Ok(()) diff --git a/docs/snippets/all/descriptors/descr_custom_archetype.cpp b/docs/snippets/all/descriptors/descr_custom_archetype.cpp index a9043b1da4ec..c60fd6183bf9 100644 --- a/docs/snippets/all/descriptors/descr_custom_archetype.cpp +++ b/docs/snippets/all/descriptors/descr_custom_archetype.cpp @@ -59,10 +59,10 @@ int main() { const auto rec = rerun::RecordingStream("rerun_example_descriptors_custom_archetype"); rec.spawn().exit_on_failure(); - CustomPosition3D positions[1] = {{rerun::components::Position3D{1.0f, 2.0f, 3.0f}}}; - rerun::Color colors[1] = {rerun::Color(0xFF00FFFF)}; - - rec.log_static("data", CustomPoints3D{positions, colors}); + rec.log_static( + "data", + CustomPoints3D{CustomPosition3D{{1.0f, 2.0f, 3.0f}}, rerun::Color(0xFF00FFFF)} + ); // The tags are indirectly checked by the Rust version (have a look over there for more info). } diff --git a/docs/snippets/all/descriptors/descr_custom_archetype.rs b/docs/snippets/all/descriptors/descr_custom_archetype.rs index a4ecd1790b70..54a8fb11860b 100644 --- a/docs/snippets/all/descriptors/descr_custom_archetype.rs +++ b/docs/snippets/all/descriptors/descr_custom_archetype.rs @@ -47,7 +47,7 @@ fn example(rec: &rerun::RecordingStream) -> Result<(), Box Date: Thu, 30 Jan 2025 11:59:19 +0100 Subject: [PATCH 4/4] pixi run format --- rerun_cpp/tests/recording_stream.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/rerun_cpp/tests/recording_stream.cpp b/rerun_cpp/tests/recording_stream.cpp index a00000442b1d..b8497e1583be 100644 --- a/rerun_cpp/tests/recording_stream.cpp +++ b/rerun_cpp/tests/recording_stream.cpp @@ -150,10 +150,10 @@ SCENARIO("RecordingStream can be used for logging archetypes and components", TE auto batch0 = rerun::ComponentBatch::from_loggable( {{1.0, 2.0}, {4.0, 5.0}} ).value_or_throw(); - auto batch1 = - rerun::ComponentBatch::from_loggable({rerun::Color(0xFF0000FF) - }) - .value_or_throw(); + auto batch1 = rerun::ComponentBatch::from_loggable( + {rerun::Color(0xFF0000FF)} + ) + .value_or_throw(); THEN("single component batch can be logged") { stream.log("log_archetype-splat", batch0); stream.log_static("log_archetype-splat", batch0); @@ -172,9 +172,9 @@ SCENARIO("RecordingStream can be used for logging archetypes and components", TE auto batch0 = rerun::ComponentBatch::from_loggable( {{1.0, 2.0}, {4.0, 5.0}} ); - auto batch1 = - rerun::ComponentBatch::from_loggable({rerun::Color(0xFF0000FF) - }); + auto batch1 = rerun::ComponentBatch::from_loggable( + {rerun::Color(0xFF0000FF)} + ); THEN("single component batch can be logged") { stream.log("log_archetype-splat", batch0); stream.log_static("log_archetype-splat", batch0); @@ -186,8 +186,7 @@ SCENARIO("RecordingStream can be used for logging archetypes and components", TE THEN("collection of component batch results can be logged") { rerun::Collection> batches = { batch0, - batch1 - }; + batch1}; stream.log("log_archetype-splat", batches); stream.log_static("log_archetype-splat", batches); }