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

Never direct users towards using RecordingStream::log_component_batches #8149

Merged
merged 2 commits into from
Nov 15, 2024
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
34 changes: 34 additions & 0 deletions crates/store/re_types_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,40 @@ impl<C: Component> AsComponents for C {
}
}

impl AsComponents for dyn ComponentBatch {
#[inline]
fn as_component_batches(&self) -> Vec<MaybeOwnedComponentBatch<'_>> {
vec![MaybeOwnedComponentBatch::Ref(self)]
}
}

impl<const N: usize> AsComponents for [&dyn ComponentBatch; N] {
#[inline]
fn as_component_batches(&self) -> Vec<MaybeOwnedComponentBatch<'_>> {
self.iter()
.map(|batch| MaybeOwnedComponentBatch::Ref(*batch))
.collect()
}
}

impl AsComponents for &[&dyn ComponentBatch] {
#[inline]
fn as_component_batches(&self) -> Vec<MaybeOwnedComponentBatch<'_>> {
self.iter()
.map(|batch| MaybeOwnedComponentBatch::Ref(*batch))
.collect()
}
}

impl AsComponents for Vec<&dyn ComponentBatch> {
#[inline]
fn as_component_batches(&self) -> Vec<MaybeOwnedComponentBatch<'_>> {
self.iter()
.map(|batch| MaybeOwnedComponentBatch::Ref(*batch))
.collect()
}
}

// ---

mod archetype;
Expand Down
6 changes: 1 addition & 5 deletions docs/snippets/all/archetypes/image_send_columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

// Log the ImageFormat and indicator once, as static.
let format = rerun::components::ImageFormat::rgb8([width as _, height as _]);
rec.log_component_batches(
"images",
true,
[&format as _, &rerun::Image::indicator() as _],
)?;
rec.log_static("images", &[&format as _, &rerun::Image::indicator() as _])?;

// Split up the image data into several components referencing the underlying data.
let image_size_in_bytes = width * height * 3;
Expand Down
5 changes: 2 additions & 3 deletions docs/snippets/all/archetypes/manual_indicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

// Specify both a Mesh3D and a Points3D indicator component so that the data is shown as both a
// 3D mesh _and_ a point cloud by default.
rec.log_component_batches(
rec.log(
"points_and_mesh",
false,
[
&[
rerun::Points3D::indicator().as_ref() as &dyn rerun::ComponentBatch,
rerun::Mesh3D::indicator().as_ref(),
&[[0.0, 0.0, 0.0], [10.0, 0.0, 0.0], [0.0, 10.0, 0.0]].map(rerun::Position3D::from),
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/all/archetypes/mesh3d_partial_updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
(glam::Vec3::from(vertex_positions[1]) * factor).into(),
(glam::Vec3::from(vertex_positions[2]) * factor).into(),
];
rec.log_component_batches("triangle", false, [&vertex_positions as _])?;
rec.log("triangle", &[&vertex_positions as _])?;
}

Ok(())
Expand Down
10 changes: 4 additions & 6 deletions docs/snippets/all/concepts/different_data_per_timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Log a red color on one timeline.
rec.reset_time(); // Clears all set timeline info.
rec.set_time_seconds("red timeline", 1.0);
rec.log_component_batches(
rec.log(
"points",
false,
[&rerun::components::Color::from_u32(0xFF0000FF) as &dyn rerun::ComponentBatch],
&[&rerun::components::Color::from_u32(0xFF0000FF) as &dyn rerun::ComponentBatch],
)?;

// And a blue color on the other.
rec.reset_time(); // Clears all set timeline info.
rec.set_time_sequence("blue timeline", 1);
rec.log_component_batches(
rec.log(
"points",
false,
[&rerun::components::Color::from_u32(0x0000FFFF) as &dyn rerun::ComponentBatch],
&[&rerun::components::Color::from_u32(0x0000FFFF) as &dyn rerun::ComponentBatch],
)?;

// TODO(#5521): log VisualBounds2D
Expand Down
14 changes: 3 additions & 11 deletions examples/rust/incremental_logging/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ let radii = [rerun::Radius(0.1); 10];

// Only log colors and radii once.
rec.set_time_sequence("frame_nr", 0);
rec.log_component_batches("points", false /* static */, [&colors as &dyn rerun::ComponentBatch, &radii])?;
rec.log("points", &[&colors as &dyn rerun::ComponentBatch, &radii])?;

let mut rng = rand::thread_rng();
let dist = Uniform::new(-5., 5.);
Expand All @@ -63,17 +63,9 @@ fn run(rec: &rerun::RecordingStream) -> anyhow::Result<()> {

// Only log colors and radii once.
rec.set_time_sequence("frame_nr", 0);
rec.log_component_batches(
"points",
false, /* static */
[&colors as &dyn rerun::ComponentBatch, &radii],
)?;
rec.log("points", &[&colors as &dyn rerun::ComponentBatch, &radii])?;
// Logging statically would also work.
// rec.log_component_batches(
// "points",
// true, /* static */
// [&colors as &dyn rerun::ComponentBatch, &radii],
// )?;
// rec.log_static("points", &[&colors as &dyn rerun::ComponentBatch, &radii])?;

let mut rng = rand::thread_rng();
let dist = Uniform::new(-5., 5.);
Expand Down
Loading