Skip to content

Commit

Permalink
implement legacy and next-gen partial updates snippets for all, ready…
Browse files Browse the repository at this point in the history
… or not
  • Loading branch information
teh-cmc committed Jan 10, 2025
1 parent 81c9291 commit 392d78c
Show file tree
Hide file tree
Showing 12 changed files with 290 additions and 19 deletions.
10 changes: 10 additions & 0 deletions docs/snippets/INDEX.md

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletions docs/snippets/all/archetypes/points3d_partial_updates.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//! Demonstrates usage of the new partial updates APIs.

#include <rerun.hpp>

#include <algorithm>
#include <vector>

int main() {
const auto rec = rerun::RecordingStream("rerun_example_points3d_partial_updates");
rec.spawn().exit_on_failure();

std::vector<rerun::Position3D> positions;
for (int i = 0; i < 10; ++i) {
positions.emplace_back(static_cast<float>(i), 0.0f, 0.0f);
}

rec.set_time_sequence("frame", 0);
rec.log("points", rerun::Points3D(positions));

for (int i = 0; i < 10; ++i) {
std::vector<rerun::Color> colors;
for (int n = 0; n < 10; ++n) {
if (n < i) {
colors.emplace_back(rerun::Color(20, 200, 20));
} else {
colors.emplace_back(rerun::Color(200, 20, 20));
}
}

std::vector<rerun::Radius> radii;
for (int n = 0; n < 10; ++n) {
if (n < i) {
radii.emplace_back(rerun::Radius(0.6f));
} else {
radii.emplace_back(rerun::Radius(0.2f));
}
}

rec.set_time_sequence("frame", i);
rec.log("points", colors, radii);
// TODO(cmc): implement new APIs and use them!
// rec.log("points", rerun::Points3D::update_fields().with_radii(radii).with_colors(colors));
}

// TODO(cmc): remove this!
// We cannot replicate the clear_fields() logic!
rec.set_time_sequence("frame", 20);
rec.log("points", rerun::Clear::FLAT);

std::vector<rerun::Radius> radii;
radii.emplace_back(rerun::Radius(0.3));

rec.set_time_sequence("frame", 20);
rec.log("points", positions, radii);

// TODO(cmc): implement new APIs and use them!
// rec.log("points", rerun::Points3D::clear_fields().with_radii(radii).with_colors(colors));
}
30 changes: 30 additions & 0 deletions docs/snippets/all/archetypes/points3d_partial_updates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Demonstrates usage of the new partial updates APIs."""

import rerun as rr

rr.init("rerun_example_points3d_partial_updates", spawn=True)

positions = [[i, 0, 0] for i in range(0, 10)]

rr.set_time_sequence("frame", 0)
rr.log("points", rr.Points3D(positions))

for i in range(0, 10):
colors = [[20, 200, 20] if n < i else [200, 20, 20] for n in range(0, 10)]
radii = [0.6 if n < i else 0.2 for n in range(0, 10)]

rr.set_time_sequence("frame", i)
rr.log("points", [rr.components.ColorBatch(colors), rr.components.RadiusBatch(radii)])
# TODO(cmc): implement new APIs and use them!
# rr.log("points", rr.Points3D.update_fields(radii=radii, colors=colors))

# TODO(cmc): remove this!
# We cannot replicate the clear_fields() logic!
rr.set_time_sequence("frame", 20)
rr.log("points", rr.Clear(recursive=False))

rr.set_time_sequence("frame", 20)
rr.log("points", [rr.components.Position3DBatch(positions), rr.components.RadiusBatch(0.3)])

# TODO(cmc): implement new APIs and use them!
# rr.log("points", rr.Points3D.clear_fields().update_fields(positions=positions, radii=0.3))
40 changes: 40 additions & 0 deletions docs/snippets/all/archetypes/points3d_partial_updates.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//! Demonstrates usage of the new partial updates APIs.
fn main() -> Result<(), Box<dyn std::error::Error>> {
let rec =
rerun::RecordingStreamBuilder::new("rerun_example_points3d_partial_updates").spawn()?;

let positions = (0..10).map(|i| (i as f32, 0.0, 0.0)).collect::<Vec<_>>();

rec.set_time_sequence("frame", 0);
rec.log("points", &rerun::Points3D::new(&positions))?;

for i in 0..10 {
let colors = (0..10).map(|n| {
if n < i {
rerun::Color::from_rgb(20, 200, 20)
} else {
rerun::Color::from_rgb(200, 20, 20)
}
});
let radii = (0..10).map(|n| if n < i { 0.6 } else { 0.2 });

rec.set_time_sequence("frame", i);
rec.log(
"points",
&rerun::Points3D::update_fields()
.with_radii(radii)
.with_colors(colors),
)?;
}

rec.set_time_sequence("frame", 20);
rec.log(
"points",
&rerun::Points3D::clear_fields()
.with_positions(positions)
.with_radii([0.3]),
)?;

Ok(())
}
52 changes: 52 additions & 0 deletions docs/snippets/all/archetypes/points3d_partial_updates_legacy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Demonstrates usage of the legacy partial updates APIs.

#include <rerun.hpp>

#include <algorithm>
#include <vector>

int main() {
const auto rec = rerun::RecordingStream("rerun_example_points3d_partial_updates_legacy");
rec.spawn().exit_on_failure();

std::vector<rerun::Position3D> positions;
for (int i = 0; i < 10; ++i) {
positions.emplace_back(static_cast<float>(i), 0.0f, 0.0f);
}

rec.set_time_sequence("frame", 0);
rec.log("points", rerun::Points3D(positions));

for (int i = 0; i < 10; ++i) {
std::vector<rerun::Color> colors;
for (int n = 0; n < 10; ++n) {
if (n < i) {
colors.emplace_back(rerun::Color(20, 200, 20));
} else {
colors.emplace_back(rerun::Color(200, 20, 20));
}
}

std::vector<rerun::Radius> radii;
for (int n = 0; n < 10; ++n) {
if (n < i) {
radii.emplace_back(rerun::Radius(0.6f));
} else {
radii.emplace_back(rerun::Radius(0.2f));
}
}

rec.set_time_sequence("frame", i);
rec.log("points", colors, radii);
}

// We cannot replicate the clear_fields() logic!
rec.set_time_sequence("frame", 20);
rec.log("points", rerun::Clear::FLAT);

std::vector<rerun::Radius> radii;
radii.emplace_back(rerun::Radius(0.3));

rec.set_time_sequence("frame", 20);
rec.log("points", positions, radii);
}
24 changes: 24 additions & 0 deletions docs/snippets/all/archetypes/points3d_partial_updates_legacy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Demonstrates usage of the new partial updates APIs."""

import rerun as rr

rr.init("rerun_example_points3d_partial_updates_legacy", spawn=True)

positions = [[i, 0, 0] for i in range(0, 10)]

rr.set_time_sequence("frame", 0)
rr.log("points", rr.Points3D(positions))

for i in range(0, 10):
colors = [[20, 200, 20] if n < i else [200, 20, 20] for n in range(0, 10)]
radii = [0.6 if n < i else 0.2 for n in range(0, 10)]

rr.set_time_sequence("frame", i)
rr.log("points", [rr.components.ColorBatch(colors), rr.components.RadiusBatch(radii)])

# We cannot replicate the clear_fields() logic!
rr.set_time_sequence("frame", 20)
rr.log("points", rr.Clear(recursive=False))

rr.set_time_sequence("frame", 20)
rr.log("points", [rr.components.Position3DBatch(positions), rr.components.RadiusBatch(0.3)])
49 changes: 49 additions & 0 deletions docs/snippets/all/archetypes/points3d_partial_updates_legacy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//! Demonstrates usage of the legacy partial updates APIs.
fn main() -> Result<(), Box<dyn std::error::Error>> {
let rec = rerun::RecordingStreamBuilder::new("rerun_example_points3d_partial_updates_legacy")
.spawn()?;

let positions = (0..10).map(|i| (i as f32, 0.0, 0.0)).collect::<Vec<_>>();

rec.set_time_sequence("frame", 0);
rec.log("points", &rerun::Points3D::new(positions.clone()))?;

for i in 0..10 {
let colors: Vec<rerun::components::Color> = (0..10)
.map(|n| {
if n < i {
rerun::Color::from_rgb(20, 200, 20)
} else {
rerun::Color::from_rgb(200, 20, 20)
}
})
.collect();
let radii: Vec<rerun::components::Radius> = (0..10)
.map(|n| if n < i { 0.6 } else { 0.2 })
.map(Into::into)
.collect();

rec.set_time_sequence("frame", i);
rec.log("points", &[&colors as &dyn rerun::ComponentBatch, &radii])?;
}

// We cannot replicate the clear_fields() logic!
rec.set_time_sequence("frame", 20);
rec.log("points", &rerun::Clear::flat())?;

rec.set_time_sequence("frame", 20);
let positions: Vec<rerun::components::Position3D> = (0..10)
.map(|i| (i as f32, 0.0, 0.0))
.map(Into::into)
.collect();
rec.log(
"points",
&[
&positions as &dyn rerun::ComponentBatch,
&rerun::components::Radius(0.3.into()),
],
)?;

Ok(())
}
4 changes: 2 additions & 2 deletions docs/snippets/all/descriptors/descr_builtin_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ 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_component_batches_v2(
rec.log_serialized_batches(
"data",
true,
[rerun::components::Position3D::new(1.0, 2.0, 3.0).serialized()],
[rerun::components::Position3D::new(1.0, 2.0, 3.0).try_serialized()?],
)?;

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions docs/snippets/all/descriptors/descr_custom_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use rerun::{ChunkStore, ChunkStoreConfig, ComponentBatch, ComponentDescriptor, V

fn example(rec: &rerun::RecordingStream) -> Result<(), Box<dyn std::error::Error>> {
let positions = rerun::components::Position3D::new(1.0, 2.0, 3.0)
.serialized()
.try_serialized()?
.with_descriptor_override(ComponentDescriptor {
archetype_name: Some("user.CustomArchetype".into()),
archetype_field_name: Some("custom_positions".into()),
component_name: "user.CustomPosition3D".into(),
});
rec.log_component_batches_v2("data", true, [positions])?;
rec.log_serialized_batches("data", true, [positions])?;

Ok(())
}
Expand Down
24 changes: 10 additions & 14 deletions docs/snippets/all/tutorials/custom_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,22 @@ struct CustomPoints3D {
}

impl rerun::AsComponents for CustomPoints3D {
fn as_component_batches_v2(&self) -> Vec<SerializedComponentBatch> {
fn as_serialized_batches(&self) -> Vec<SerializedComponentBatch> {
let indicator = rerun::NamedIndicatorComponent("user.CustomPoints3DIndicator".into());
self.points3d
.as_component_batches_v2()
.as_serialized_batches()
.into_iter()
.chain(
[
Some(indicator.serialized()),
self.confidences.as_ref().map(|batch| {
batch
.serialized()
indicator.serialized(),
self.confidences
.as_ref()
.and_then(|batch| batch.serialized())
.map(|batch|
// Optionally override the descriptor with extra information.
.with_descriptor_override(
batch
.descriptor()
.into_owned()
.or_with_archetype_name(|| "user.CustomPoints3D".into())
.or_with_archetype_field_name(|| "confidences".into()),
)
}),
batch
.or_with_archetype_name(|| "user.CustomPoints3D".into())
.or_with_archetype_field_name(|| "confidences".into())),
]
.into_iter()
.flatten(),
Expand Down
4 changes: 4 additions & 0 deletions docs/snippets/snippets.toml
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ quick_start = [ # These examples don't have exactly the same implementation.
"py",
"rust",
]
"archetypes/points3d_partial_updates" = [ # TODO(cmc): not supported yet
"py",
"cpp",
]
"archetypes/points3d_random" = [ # TODO(#3206): examples use different RNGs
"cpp",
"py",
Expand Down
10 changes: 9 additions & 1 deletion lychee.toml
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,13 @@ exclude = [
'https://openaccess.thecvf.com/content/CVPR2023/html/Du_Learning_To_Render_Novel_Views_From_Wide-Baseline_Stereo_Pairs_CVPR_2023_paper.html',
'https://anaconda.org/conda-forge/arrow-cpp',

#'^file:///', # Ignore local file links. They need to be tested, but it's useful for external links we have to ping.
# '^file:///', # Ignore local file links. They need to be tested, but it's useful for external links we have to ping.

# Snippets that haven't been released yet.
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates.py',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates_legacy.py',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates.cpp',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates_legacy.cpp',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates.rs',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates_legacy.rs',
]

0 comments on commit 392d78c

Please sign in to comment.