-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add legacy and next-gen partial updates snippets for all languages (#…
…8649) This adds a partial update example for `Points3D`, in all languages, using both the legacy and new APIs (if they already exist). This acts as a before/after comparison, a piece of documentation and a way to make sure that the legacy and new APIs behave similarly. * DNM: requires #8648 * Part of #8583 * Part of #8581 * Part of #8582
- Loading branch information
Showing
8 changed files
with
304 additions
and
1 deletion.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
//! 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", rerun::Points3D::IndicatorComponent(), colors, radii); | ||
// TODO(cmc): implement new APIs and use them! | ||
// rec.log("points", rerun::Points3D::update_fields().with_radii(radii).with_colors(colors)); | ||
} | ||
|
||
std::vector<rerun::Radius> radii; | ||
radii.emplace_back(0.3f); | ||
|
||
rec.set_time_sequence("frame", 20); | ||
rec.log( | ||
"points", | ||
rerun::Points3D::IndicatorComponent(), | ||
positions, | ||
radii, | ||
std::vector<rerun::components::Color>(), | ||
std::vector<rerun::components::Text>(), | ||
std::vector<rerun::components::ShowLabels>(), | ||
std::vector<rerun::components::ClassId>(), | ||
std::vector<rerun::components::KeypointId>() | ||
); | ||
// TODO(cmc): implement new APIs and use them! | ||
// rec.log("points", rerun::Points3D::clear_fields().with_radii(radii).with_colors(colors)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""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.Points3D.indicator(), 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)) | ||
|
||
rr.set_time_sequence("frame", 20) | ||
rr.log( | ||
"points", | ||
[ | ||
rr.Points3D.indicator(), | ||
rr.components.Position3DBatch(positions), | ||
rr.components.RadiusBatch(0.3), | ||
rr.components.ColorBatch([]), | ||
rr.components.TextBatch([]), | ||
rr.components.ShowLabelsBatch([]), | ||
rr.components.ClassIdBatch([]), | ||
rr.components.KeypointIdBatch([]), | ||
], | ||
) | ||
# TODO(cmc): implement new APIs and use them! | ||
# rr.log("points", rr.Points3D.clear_fields().update_fields(positions=positions, radii=0.3)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
|
||
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(()) | ||
} |
58 changes: 58 additions & 0 deletions
58
docs/snippets/all/archetypes/points3d_partial_updates_legacy.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// 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); | ||
} | ||
|
||
std::vector<rerun::Radius> radii; | ||
radii.emplace_back(0.3f); | ||
|
||
rec.set_time_sequence("frame", 20); | ||
rec.log( | ||
"points", | ||
rerun::Points3D::IndicatorComponent(), | ||
positions, | ||
radii, | ||
std::vector<rerun::components::Color>(), | ||
std::vector<rerun::components::Text>(), | ||
std::vector<rerun::components::ShowLabels>(), | ||
std::vector<rerun::components::ClassId>(), | ||
std::vector<rerun::components::KeypointId>() | ||
); | ||
} |
32 changes: 32 additions & 0 deletions
32
docs/snippets/all/archetypes/points3d_partial_updates_legacy.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""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)]) | ||
|
||
rr.set_time_sequence("frame", 20) | ||
rr.log( | ||
"points", | ||
[ | ||
rr.Points3D.indicator(), | ||
rr.components.Position3DBatch(positions), | ||
rr.components.RadiusBatch(0.3), | ||
rr.components.ColorBatch([]), | ||
rr.components.TextBatch([]), | ||
rr.components.ShowLabelsBatch([]), | ||
rr.components.ClassIdBatch([]), | ||
rr.components.KeypointIdBatch([]), | ||
], | ||
) |
51 changes: 51 additions & 0 deletions
51
docs/snippets/all/archetypes/points3d_partial_updates_legacy.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//! 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)); | ||
|
||
rec.set_time_sequence("frame", 0); | ||
rec.log("points", &rerun::Points3D::new(positions))?; | ||
|
||
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])?; | ||
} | ||
|
||
use rerun::Archetype as _; | ||
let positions: Vec<rerun::components::Position3D> = | ||
(0..10).map(|i| (i as f32, 0.0, 0.0).into()).collect(); | ||
|
||
rec.set_time_sequence("frame", 20); | ||
rec.log( | ||
"points", | ||
&[ | ||
&rerun::Points3D::indicator() as &dyn rerun::ComponentBatch, | ||
&positions, | ||
&vec![rerun::components::Radius(0.3.into())], | ||
&Vec::<rerun::components::Color>::new(), | ||
&Vec::<rerun::components::Text>::new(), | ||
&Vec::<rerun::components::ShowLabels>::new(), | ||
&Vec::<rerun::components::ClassId>::new(), | ||
&Vec::<rerun::components::KeypointId>::new(), | ||
], | ||
)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters