Skip to content

Commit

Permalink
add new transform3d partial updates snippet for all languages
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Jan 14, 2025
1 parent dd04366 commit 81f06c8
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/snippets/INDEX.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 64 additions & 0 deletions docs/snippets/all/archetypes/transform3d_partial_updates.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Log different transforms with visualized coordinates axes.

#include <cmath>
#include <rerun.hpp>

float truncated_radians(float deg) {
return static_cast<float>(static_cast<int>(deg * M_PI / 180.0f * 1000.0f)) / 1000.0f;
}

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

auto step = 0;

rec.set_time_sequence("step", step);
rec.log(
"box",
rerun::Boxes3D::from_half_sizes({{4.f, 2.f, 1.0f}}).with_fill_mode(rerun::FillMode::Solid),
rerun::Transform3D().with_axis_length(10.0)
);

for (int deg = 0; deg <= 45; deg++) {
step++;
rec.set_time_sequence("step", step);

auto rad = truncated_radians(deg * 4);
// TODO(cmc): update_fields
rec.log(
"box",
rerun::Transform3D().with_rotation_axis_angle(
rerun::RotationAxisAngle({0.0f, 1.0f, 0.0f}, rerun::Angle::radians(rad))
)
);
}

for (int t = 0; t <= 45; t++) {
step++;
rec.set_time_sequence("step", step);
rec.log(
"box",
rerun::Transform3D().with_translation({0.0f, 0.0f, static_cast<float>(t) / 10.0f})
);
}

for (int deg = 0; deg <= 45; deg++) {
step++;
rec.set_time_sequence("step", step);

auto rad = truncated_radians((deg + 45) * 4);
// TODO(cmc): update_fields
rec.log(
"box",
rerun::Transform3D().with_rotation_axis_angle(
rerun::RotationAxisAngle({0.0f, 1.0f, 0.0f}, rerun::Angle::radians(rad))
)
);
}

step++;
rec.set_time_sequence("step", step);
// TODO(cmc): clear_fields
rec.log("box", rerun::Transform3D().with_axis_length(15.0));
}
66 changes: 66 additions & 0 deletions docs/snippets/all/archetypes/transform3d_partial_updates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""Log different transforms with visualized coordinates axes."""

import math

import rerun as rr


def truncated_radians(deg: float) -> float:
return float(int(math.radians(deg) * 1000.0)) / 1000.0


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

step = 0
rr.set_time_sequence("step", step)

rr.log(
"box",
rr.Boxes3D(half_sizes=[4.0, 2.0, 1.0], fill_mode=rr.components.FillMode.Solid),
rr.Transform3D(axis_length=10),
)

for deg in range(46):
step += 1
rr.set_time_sequence("step", step)

rad = truncated_radians(deg * 4)
# TODO(cmc): update_fields
rr.log(
"box",
rr.Transform3D(
# TODO(cmc): we should have access to all the fields of the extended constructor too.
rotation_axis_angle=rr.RotationAxisAngle(axis=[0.0, 1.0, 0.0], radians=rad),
),
)

for t in range(51):
step += 1
rr.set_time_sequence("step", step)
# TODO(cmc): update_fields
rr.log(
"box",
rr.Transform3D(translation=[0, 0, t / 10.0]),
)

for deg in range(46):
step += 1
rr.set_time_sequence("step", step)

rad = truncated_radians((deg + 45) * 4)
# TODO(cmc): update_fields
rr.log(
"box",
rr.Transform3D(
# TODO(cmc): we should have access to all the fields of the extended constructor too.
rotation_axis_angle=rr.RotationAxisAngle(axis=[0.0, 1.0, 0.0], radians=rad),
),
)

step += 1
rr.set_time_sequence("step", step)
# TODO(cmc): update_fields(clear=True)
rr.log(
"box",
rr.Transform3D(axis_length=15),
)
67 changes: 67 additions & 0 deletions docs/snippets/all/archetypes/transform3d_partial_updates.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//! Log different transforms with visualized coordinates axes.
fn main() -> Result<(), Box<dyn std::error::Error>> {
let rec = rerun::RecordingStreamBuilder::new("rerun_example_transform3d_axes").spawn()?;

let mut step = 0;

rec.set_time_sequence("step", step);
rec.log(
"box",
&[
&rerun::Boxes3D::from_half_sizes([(4.0, 2.0, 1.0)])
.with_fill_mode(rerun::FillMode::Solid) as &dyn rerun::AsComponents,
&rerun::Transform3D::default().with_axis_length(10.0),
],
)?;

for deg in 0..=45 {
step += 1;
rec.set_time_sequence("step", step);

let rad = truncated_radians((deg * 4) as f32);
rec.log(
"box",
&rerun::Transform3D::update_fields().with_rotation(rerun::RotationAxisAngle::new(
[0.0, 1.0, 0.0],
rerun::Angle::from_radians(rad),
)),
)?;
}

for t in 0..=50 {
step += 1;
rec.set_time_sequence("step", step);
rec.log(
"box",
&rerun::Transform3D::update_fields().with_translation([0.0, 0.0, t as f32 / 10.0]),
)?;
}

for deg in 0..=45 {
step += 1;
rec.set_time_sequence("step", step);

let rad = truncated_radians(((deg + 45) * 4) as f32);
rec.log(
"box",
&rerun::Transform3D::update_fields().with_rotation(rerun::RotationAxisAngle::new(
[0.0, 1.0, 0.0],
rerun::Angle::from_radians(rad),
)),
)?;
}

step += 1;
rec.set_time_sequence("step", step);
rec.log(
"box",
&rerun::Transform3D::clear_fields().with_axis_length(15.0),
)?;

Ok(())
}

fn truncated_radians(deg: f32) -> f32 {
((deg.to_radians() * 1000.0) as i32) as f32 / 1000.0
}
4 changes: 4 additions & 0 deletions docs/snippets/snippets.toml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ quick_start = [ # These examples don't have exactly the same implementation.
"archetypes/transform3d_hierarchy" = [ # Uses a lot of trigonometry which is surprisingly easy to get the same on Rust & C++, but not on Python/Numpy
"py",
]
"archetypes/transform3d_partial_updates" = [
"cpp", # TODO(cmc): remove once C++ partial updates APIs have shipped
"py", # TODO(cmc): remove once Python partial updates APIs have shipped
]
"archetypes/instance_poses3d_combined" = [ # TODO(#3235): Slight floating point differences in point grid.
"cpp",
"py",
Expand Down
3 changes: 3 additions & 0 deletions lychee.toml
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,7 @@ exclude = [
'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',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/transform3d_partial_updates.py',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/transform3d_partial_updates.cpp',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/transform3d_partial_updates.rs',
]

0 comments on commit 81f06c8

Please sign in to comment.