Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polish manual tagged APIs #8869

Merged
merged 4 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions docs/snippets/all/descriptors/descr_builtin_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ int main() {

rec.log_static(
"data",
rerun::ComponentBatch::from_loggable<rerun::Position3D>(
{1.0f, 2.0f, 3.0f},
rerun::Loggable<rerun::Position3D>::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).
Expand Down
6 changes: 5 additions & 1 deletion docs/snippets/all/descriptors/descr_builtin_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
5 changes: 2 additions & 3 deletions docs/snippets/all/descriptors/descr_builtin_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ use rerun::{ChunkStore, ChunkStoreConfig, Component as _, ComponentDescriptor, V

fn example(rec: &rerun::RecordingStream) -> Result<(), Box<dyn std::error::Error>> {
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(())
Expand Down
8 changes: 4 additions & 4 deletions docs/snippets/all/descriptors/descr_custom_archetype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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).
}
2 changes: 1 addition & 1 deletion docs/snippets/all/descriptors/descr_custom_archetype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn example(rec: &rerun::RecordingStream) -> Result<(), Box<dyn std::error::Error
colors: Some(vec![colors]),
};

rec.log_static("data", &points as _)?;
rec.log_static("data", &points)?;

Ok(())
}
Expand Down
12 changes: 8 additions & 4 deletions rerun_cpp/src/rerun/component_batch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ namespace rerun {
/// Automatically registers the component type the first time this type is encountered.
template <typename T>
static Result<ComponentBatch> from_loggable(
const rerun::Collection<T>& components, const ComponentDescriptor& descriptor
const rerun::Collection<T>& components,
const ComponentDescriptor& descriptor = rerun::Loggable<T>::Descriptor

) {
static_assert(
rerun::is_loggable<T>,
Expand Down Expand Up @@ -86,7 +88,8 @@ namespace rerun {
/// Automatically registers the component type the first time this type is encountered.
template <typename T>
static Result<ComponentBatch> from_loggable(
const T& component, const ComponentDescriptor& descriptor
const T& component,
const ComponentDescriptor& descriptor = rerun::Loggable<T>::Descriptor
) {
// Collection adapter will automatically borrow for single elements, but let's do this explicitly, avoiding the extra hoop.
const auto collection = Collection<T>::borrow(&component, 1);
Expand All @@ -100,7 +103,8 @@ namespace rerun {
/// Automatically registers the component type the first time this type is encountered.
template <typename T>
static Result<ComponentBatch> from_loggable(
const std::optional<T>& component, const ComponentDescriptor& descriptor
const std::optional<T>& component,
const ComponentDescriptor& descriptor = rerun::Loggable<T>::Descriptor
) {
if (component.has_value()) {
return from_loggable(component.value(), descriptor);
Expand All @@ -117,7 +121,7 @@ namespace rerun {
template <typename T>
static Result<ComponentBatch> from_loggable(
const std::optional<rerun::Collection<T>>& components,
const ComponentDescriptor& descriptor
const ComponentDescriptor& descriptor = rerun::Loggable<T>::Descriptor
) {
if (components.has_value()) {
return from_loggable(components.value(), descriptor);
Expand Down
5 changes: 3 additions & 2 deletions rerun_cpp/src/rerun/component_column.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace rerun {
template <typename T>
static Result<ComponentColumn> from_loggable_with_lengths(
const Collection<T>& components, const Collection<uint32_t>& lengths,
const ComponentDescriptor& descriptor
const ComponentDescriptor& descriptor = rerun::Loggable<T>::Descriptor
) {
auto component_batch_result = ComponentBatch::from_loggable(components, descriptor);
if (component_batch_result.is_err()) {
Expand All @@ -57,7 +57,8 @@ namespace rerun {
/// \param descriptor Descriptor of the component type for this column.
template <typename T>
static Result<ComponentColumn> from_loggable(
const Collection<T>& components, const ComponentDescriptor& descriptor
const Collection<T>& components,
const ComponentDescriptor& descriptor = rerun::Loggable<T>::Descriptor
) {
return ComponentColumn::from_loggable_with_lengths(
components,
Expand Down
20 changes: 6 additions & 14 deletions rerun_cpp/tests/recording_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,10 @@ SCENARIO("RecordingStream can be used for logging archetypes and components", TE

GIVEN("component batches") {
auto batch0 = rerun::ComponentBatch::from_loggable<rerun::Position2D>(
{{1.0, 2.0}, {4.0, 5.0}},
rerun::Loggable<rerun::Position2D>::Descriptor
)
.value_or_throw();
{{1.0, 2.0}, {4.0, 5.0}}
).value_or_throw();
auto batch1 = rerun::ComponentBatch::from_loggable<rerun::Color>(
{rerun::Color(0xFF0000FF)},
rerun::Loggable<rerun::Color>::Descriptor
{rerun::Color(0xFF0000FF)}
)
.value_or_throw();
THEN("single component batch can be logged") {
Expand All @@ -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<rerun::Position2D>(
{{1.0, 2.0}, {4.0, 5.0}},
rerun::Loggable<rerun::Position2D>::Descriptor
{{1.0, 2.0}, {4.0, 5.0}}
);
auto batch1 = rerun::ComponentBatch::from_loggable<rerun::Color>(
{rerun::Color(0xFF0000FF)},
rerun::Loggable<rerun::Color>::Descriptor
{rerun::Color(0xFF0000FF)}
);
THEN("single component batch can be logged") {
stream.log("log_archetype-splat", batch0);
Expand Down Expand Up @@ -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<BadComponent>::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);
Expand Down
6 changes: 6 additions & 0 deletions rerun_py/rerun_sdk/rerun/_baseclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down