-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement legacy and next-gen partial updates snippets for all, ready…
… or not
- Loading branch information
Showing
12 changed files
with
290 additions
and
19 deletions.
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,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)); | ||
} |
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,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)) |
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)).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
52
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,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
24
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,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
49
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,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(()) | ||
} |
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
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
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
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
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