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/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/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 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..b8497e1583be 100644 --- a/rerun_cpp/tests/recording_stream.cpp +++ b/rerun_cpp/tests/recording_stream.cpp @@ -148,13 +148,10 @@ 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(); + {{1.0, 2.0}, {4.0, 5.0}} + ).value_or_throw(); auto batch1 = rerun::ComponentBatch::from_loggable( - {rerun::Color(0xFF0000FF)}, - rerun::Loggable::Descriptor + {rerun::Color(0xFF0000FF)} ) .value_or_throw(); THEN("single component batch can be logged") { @@ -173,12 +170,10 @@ 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 + {{1.0, 2.0}, {4.0, 5.0}} ); auto batch1 = rerun::ComponentBatch::from_loggable( - {rerun::Color(0xFF0000FF)}, - rerun::Loggable::Descriptor + {rerun::Color(0xFF0000FF)} ); THEN("single component batch can be logged") { stream.log("log_archetype-splat", batch0); @@ -408,10 +403,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); 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)