-
Notifications
You must be signed in to change notification settings - Fork 373
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
SDK batching/revamp 2.1: clock
example for Rust
#2000
Merged
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
68d8b0c
version crossbeam at the workspace level
teh-cmc cb74038
more DataRow size helpers
teh-cmc a0d9d39
DataTableBatcher
teh-cmc f46ac72
lints
teh-cmc 5440f76
lints
teh-cmc c1088c5
self review
teh-cmc cbf17be
don't expose shutdown to make errors impossible
teh-cmc e7b42bf
doc
teh-cmc 573de98
backport
teh-cmc 67dc616
backport
teh-cmc 14130c5
introduce RecordingStream
teh-cmc 71a31bd
clean up old stuff from the before time
teh-cmc 649bbe8
self-review
teh-cmc 2b74c3b
ordered data columns in data tables
teh-cmc 34be0a7
tests
teh-cmc 72685fa
even more tests
teh-cmc 067168f
rogue todo
teh-cmc b8e0065
batching is now a reality
teh-cmc 0e69707
some extra peace of mind
teh-cmc 232bf8d
added Rust clock example
teh-cmc a7f84c8
revert
teh-cmc ead5883
Merge branch 'main' into cmc/sdk_revamp/1_batcher
teh-cmc 3f0ec73
Merge branch 'cmc/sdk_revamp/1_batcher' into cmc/sdk_revamp/2_rust_re…
teh-cmc 4bb95ea
Merge branch 'cmc/sdk_revamp/2_rust_revamp' into cmc/sdk_revamp/21_clock
teh-cmc 6e348db
lock shenanigans
teh-cmc 80557c3
Merge branch 'cmc/sdk_revamp/2_rust_revamp' into cmc/sdk_revamp/21_clock
teh-cmc 5e71844
lock shenanigans
teh-cmc a31285b
Merge branch 'main' into cmc/sdk_revamp/1_batcher
teh-cmc ecb7ce5
Merge branch 'cmc/sdk_revamp/1_batcher' into cmc/sdk_revamp/2_rust_re…
teh-cmc f64a4dc
Merge branch 'cmc/sdk_revamp/2_rust_revamp' into cmc/sdk_revamp/21_clock
teh-cmc 8580773
Merge remote-tracking branch 'origin/main' into cmc/sdk_revamp/2_rust…
teh-cmc 4af3342
merge shenanigans
teh-cmc d1e5c19
address PR comments
teh-cmc 180cdf1
Merge branch 'cmc/sdk_revamp/2_rust_revamp' into cmc/sdk_revamp/21_clock
teh-cmc dbab901
fix python example
teh-cmc cb4fd66
lock shenanigans
teh-cmc ce676d1
Merge remote-tracking branch 'origin/main' into cmc/sdk_revamp/21_clock
teh-cmc c2e39a2
self-review
teh-cmc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,14 @@ | ||
[package] | ||
name = "clock" | ||
version.workspace = true | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
license.workspace = true | ||
publish = false | ||
|
||
[dependencies] | ||
rerun = { path = "../../../crates/rerun", features = ["web_viewer"] } | ||
|
||
anyhow = "1.0" | ||
clap = { version = "4.0", features = ["derive"] } | ||
glam = "0.22" |
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,117 @@ | ||
//! Builds an analog clock using Rerun's `Arrow3D` primitive. | ||
//! | ||
//! This is a great benchmark for many small events. | ||
//! | ||
//! Usage: | ||
//! ``` | ||
//! cargo run -p clock -- --help | ||
//! ``` | ||
|
||
use std::f32::consts::TAU; | ||
|
||
use rerun::components::{Arrow3D, Box3D, ColorRGBA, Radius, Vec3D, ViewCoordinates}; | ||
use rerun::coordinates::SignedAxis3; | ||
use rerun::time::{Time, TimePoint, TimeType, Timeline}; | ||
use rerun::{external::re_log, MsgSender, RecordingStream}; | ||
|
||
#[derive(Debug, clap::Parser)] | ||
#[clap(author, version, about)] | ||
struct Args { | ||
#[command(flatten)] | ||
rerun: rerun::clap::RerunArgs, | ||
|
||
#[clap(long, default_value = "10000")] | ||
steps: usize, | ||
} | ||
|
||
fn run(rec_stream: &RecordingStream, args: &Args) -> anyhow::Result<()> { | ||
const LENGTH_S: f32 = 20.0; | ||
const LENGTH_M: f32 = 10.0; | ||
const LENGTH_H: f32 = 4.0; | ||
const WIDTH_S: f32 = 0.25; | ||
const WIDTH_M: f32 = 0.4; | ||
const WIDTH_H: f32 = 0.6; | ||
|
||
let view_coords = ViewCoordinates::from_up_and_handedness( | ||
SignedAxis3::POSITIVE_Y, | ||
rerun::coordinates::Handedness::Right, | ||
); | ||
MsgSender::new("world") | ||
.with_timeless(true) | ||
.with_component(&[view_coords])? | ||
.send(rec_stream)?; | ||
|
||
MsgSender::new("world/frame") | ||
.with_timeless(true) | ||
.with_component(&[Box3D::new(LENGTH_S, LENGTH_S, 1.0)])? | ||
.send(rec_stream)?; | ||
|
||
fn sim_time(at: f64) -> TimePoint { | ||
let timeline_sim_time = Timeline::new("sim_time", TimeType::Time); | ||
let time = Time::from_seconds_since_epoch(at); | ||
[(timeline_sim_time, time.into())].into() | ||
} | ||
|
||
fn pos(angle: f32, length: f32) -> Vec3D { | ||
Vec3D::new(length * angle.sin(), length * angle.cos(), 0.0) | ||
} | ||
|
||
fn color(angle: f32, blue: u8) -> ColorRGBA { | ||
let c = (angle * 255.0) as u8; | ||
ColorRGBA::from_unmultiplied_rgba(255 - c, c, blue, u8::max(128, blue)) | ||
} | ||
|
||
fn log_hand( | ||
rec_stream: &RecordingStream, | ||
name: &str, | ||
step: usize, | ||
angle: f32, | ||
length: f32, | ||
width: f32, | ||
blue: u8, | ||
) -> anyhow::Result<()> { | ||
let point = pos(angle * TAU, length); | ||
let color = color(angle, blue); | ||
MsgSender::new(format!("world/{name}_pt")) | ||
.with_timepoint(sim_time(step as _)) | ||
.with_component(&[point])? | ||
.with_component(&[color])? | ||
.send(rec_stream)?; | ||
MsgSender::new(format!("world/{name}_hand")) | ||
.with_timepoint(sim_time(step as _)) | ||
.with_component(&[Arrow3D { | ||
origin: glam::Vec3::ZERO.into(), | ||
vector: point, | ||
}])? | ||
.with_component(&[color])? | ||
.with_component(&[Radius(width * 0.5)])? | ||
.send(rec_stream)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
for step in 0..args.steps { | ||
#[rustfmt::skip] | ||
log_hand(rec_stream, "seconds", step, (step % 60) as f32 / 60.0, LENGTH_S, WIDTH_S, 0)?; | ||
#[rustfmt::skip] | ||
log_hand(rec_stream, "minutes", step, (step % 3600) as f32 / 3600.0, LENGTH_M, WIDTH_M, 128)?; | ||
#[rustfmt::skip] | ||
log_hand(rec_stream, "hours", step, (step % 43200) as f32 / 43200.0, LENGTH_H, WIDTH_H, 255)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn main() -> anyhow::Result<()> { | ||
re_log::setup_native_logging(); | ||
|
||
use clap::Parser as _; | ||
let args = Args::parse(); | ||
|
||
let default_enabled = true; | ||
args.rerun | ||
.clone() | ||
.run("clock", default_enabled, move |rec_stream| { | ||
run(&rec_stream, &args).unwrap(); | ||
}) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[rustfmt::skip]
doesn't work on a block?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not on expressions, it's been nightly-only since the dawn of time... 😒