Skip to content
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

Add new Transform3D partial updates snippet for all languages #8690

Merged
merged 4 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

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

#include <rerun.hpp>

float truncated_radians(int deg) {
auto degf = static_cast<float>(deg);
const auto pi = 3.14159265358979323846;
return static_cast<float>(static_cast<int>(degf * pi / 180.0f * 1000.0f)) / 1000.0f;
}

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

// Set up a 3D box.
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)
);

// Update only the rotation of the box.
for (int deg = 0; deg <= 45; deg++) {
auto rad = truncated_radians(deg * 4);
// TODO(#8583): update_fields
rec.log(
"box",
rerun::Transform3D().with_rotation_axis_angle(
rerun::RotationAxisAngle({0.0f, 1.0f, 0.0f}, rerun::Angle::radians(rad))
)
);
}

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

// Update only the rotation of the box.
for (int deg = 0; deg <= 45; deg++) {
auto rad = truncated_radians((deg + 45) * 4);
// TODO(#8583): update_fields
rec.log(
"box",
rerun::Transform3D().with_rotation_axis_angle(
rerun::RotationAxisAngle({0.0f, 1.0f, 0.0f}, rerun::Angle::radians(rad))
)
);
}

// Clear all of the box's attributes, and reset its axis length.
// TODO(#8583): clear_fields
rec.log("box", rerun::Transform3D().with_axis_length(15.0));
}
53 changes: 53 additions & 0 deletions docs/snippets/all/archetypes/transform3d_partial_updates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""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_partial_updates", spawn=True)

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):
rad = truncated_radians(deg * 4)
# TODO(#8582): 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):
# TODO(#8582): update_fields
rr.log(
"box",
rr.Transform3D(translation=[0, 0, t / 10.0]),
)

for deg in range(46):
rad = truncated_radians((deg + 45) * 4)
# TODO(#8582): 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),
),
)

# TODO(#8582): update_fields(clear=True)
rr.log(
"box",
rr.Transform3D(axis_length=15),
)
60 changes: 60 additions & 0 deletions docs/snippets/all/archetypes/transform3d_partial_updates.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//! Log different transforms with visualized coordinates axes.

fn main() -> Result<(), Box<dyn std::error::Error>> {
let rec =
rerun::RecordingStreamBuilder::new("rerun_example_transform3d_partial_updates").spawn()?;

// Set up a 3D box.
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),
],
)?;

// Update only the rotation of the box.
for deg in 0..=45 {
teh-cmc marked this conversation as resolved.
Show resolved Hide resolved
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),
)),
)?;
}

// Update only the position of the box.
for t in 0..=50 {
teh-cmc marked this conversation as resolved.
Show resolved Hide resolved
rec.log(
"box",
&rerun::Transform3D::update_fields().with_translation([0.0, 0.0, t as f32 / 10.0]),
)?;
}

// Update only the rotation of the box.
for deg in 0..=45 {
teh-cmc marked this conversation as resolved.
Show resolved Hide resolved
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),
)),
)?;
}

// Clear all of the box's attributes, and reset its axis length.
rec.log(
"box",
&rerun::Transform3D::clear_fields().with_axis_length(15.0),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argueblt we should just demonste one thing here (clear_fields) and skip the with_axis_length

Copy link
Member Author

@teh-cmc teh-cmc Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

purposefully showing both: people need to know they don't need to (and shouldn't) log multiple rows in order to clear all data and reset one or more specific fields (and similarly, we need to make sure in the roundtrips that this indeed results in a single row for all languages).

)?;

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(#8583): remove once C++ partial updates APIs have shipped
"py", # TODO(#8582): 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',
]
Loading