Skip to content

Commit

Permalink
Nicer transform archetype interface in python (#3560)
Browse files Browse the repository at this point in the history
### What

* Fixes #3528
* plus as discussed `TranslationRotationScale3D` and
`TranslationAndMat3x3` datatypes no longer implement the as_components
interface
* Need to patch up things in #3545

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/3560) (if
applicable)

- [PR Build Summary](https://build.rerun.io/pr/3560)
- [Docs
preview](https://rerun.io/preview/e0b9e97ed111ec63df54519176dac499fe46163d/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/e0b9e97ed111ec63df54519176dac499fe46163d/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://ref.rerun.io/dev/bench/)
- [Wasm size tracking](https://ref.rerun.io/dev/sizes/)
  • Loading branch information
Wumpf authored Oct 2, 2023
1 parent fa0aa93 commit 69a1549
Show file tree
Hide file tree
Showing 30 changed files with 241 additions and 151 deletions.
4 changes: 2 additions & 2 deletions crates/re_data_ui/src/transform3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl DataUi for TranslationAndMat3x3 {
) {
let TranslationAndMat3x3 {
translation,
matrix,
mat3x3,
from_parent: _,
} = self;

Expand All @@ -167,7 +167,7 @@ impl DataUi for TranslationAndMat3x3 {
ui.end_row();
}

if let Some(matrix) = matrix {
if let Some(matrix) = mat3x3 {
ui.label("matrix");
matrix.data_ui(ctx, ui, verbosity, query);
ui.end_row();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ table TranslationAndMat3x3 (
//
// NOTE: Nullable rather than defaulting to an identity-like value because we want to be able
// to differentiate between no value vs. default value in the backend.
matrix: Mat3x3 (nullable, order: 200);
mat3x3: Mat3x3 (nullable, order: 200);

// TODO(#2641): make this field non-nullable when default values are supported
/// If true, the transform maps from the parent space to the space where the transform was logged.
Expand Down
6 changes: 2 additions & 4 deletions crates/re_types/src/archetypes/transform3d.rs

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

4 changes: 2 additions & 2 deletions crates/re_types/src/datatypes/transform3d_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ impl From<Transform3D> for glam::Affine3A {
match value {
Transform3D::TranslationAndMat3x3(TranslationAndMat3x3 {
translation,
matrix,
mat3x3,
from_parent: _,
}) => glam::Affine3A::from_mat3_translation(
matrix.unwrap_or(super::Mat3x3::IDENTITY).into(),
mat3x3.unwrap_or(super::Mat3x3::IDENTITY).into(),
translation.map_or(glam::Vec3::ZERO, |v| v.into()),
),

Expand Down
44 changes: 22 additions & 22 deletions crates/re_types/src/datatypes/translation_and_mat3x3.rs

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

12 changes: 6 additions & 6 deletions crates/re_types/src/datatypes/translation_and_mat3x3_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ impl Default for TranslationAndMat3x3 {
impl TranslationAndMat3x3 {
pub const IDENTITY: Self = Self {
translation: None,
matrix: None,
mat3x3: None,
from_parent: false,
};

/// Create a new `TranslationAndMat3`.
#[inline]
pub fn new<T: Into<Vec3D>, M: Into<Mat3x3>>(translation: T, matrix: M) -> Self {
pub fn new<T: Into<Vec3D>, M: Into<Mat3x3>>(translation: T, mat3x3: M) -> Self {
Self {
translation: Some(translation.into()),
matrix: Some(matrix.into()),
mat3x3: Some(mat3x3.into()),
from_parent: false,
}
}
Expand All @@ -29,16 +29,16 @@ impl TranslationAndMat3x3 {
pub fn translation<T: Into<Vec3D>>(translation: T) -> Self {
Self {
translation: Some(translation.into()),
matrix: None,
mat3x3: None,
from_parent: false,
}
}

#[inline]
pub fn rotation<M: Into<Mat3x3>>(matrix: M) -> Self {
pub fn rotation<M: Into<Mat3x3>>(mat3x3: M) -> Self {
Self {
translation: None,
matrix: Some(matrix.into()),
mat3x3: Some(mat3x3.into()),
from_parent: false,
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/re_types/tests/transform3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn roundtrip() {
transform: components::Transform3D(datatypes::Transform3D::TranslationAndMat3x3(
TranslationAndMat3x3 {
translation: None,
matrix: None,
mat3x3: None,
from_parent: false,
},
)),
Expand All @@ -72,7 +72,7 @@ fn roundtrip() {
transform: components::Transform3D(datatypes::Transform3D::TranslationAndMat3x3(
TranslationAndMat3x3 {
translation: Some(Vec3D([1.0, 2.0, 3.0])),
matrix: None,
mat3x3: None,
from_parent: true,
},
)),
Expand All @@ -81,7 +81,7 @@ fn roundtrip() {
transform: components::Transform3D(datatypes::Transform3D::TranslationAndMat3x3(
TranslationAndMat3x3 {
translation: None,
matrix: Some(Mat3x3([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0])),
mat3x3: Some(Mat3x3([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0])),
from_parent: true,
},
)),
Expand Down
4 changes: 2 additions & 2 deletions docs/code-examples/transform3d_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

rr.log("base", rr.Arrows3D(origins=[0, 0, 0], vectors=[0, 1, 0]))

rr.log("base/translated", rr.TranslationAndMat3x3(translation=[1, 0, 0]))
rr.log("base/translated", rr.Transform3D(translation=[1, 0, 0]))
rr.log("base/translated", rr.Arrows3D(origins=[0, 0, 0], vectors=[0, 1, 0]))

rr.log(
"base/rotated_scaled",
rr.TranslationRotationScale3D(
rr.Transform3D(
rotation=RotationAxisAngle(axis=[0, 0, 1], angle=Angle(rad=pi / 4)),
scale=2,
),
Expand Down
6 changes: 2 additions & 4 deletions docs/code-examples/transform3d_simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
use rerun::{
archetypes::{Arrows3D, Transform3D},
datatypes::{
Angle, RotationAxisAngle, Scale3D, TranslationAndMat3x3, TranslationRotationScale3D,
},
datatypes::{Angle, RotationAxisAngle, Scale3D, TranslationRotationScale3D},
RecordingStreamBuilder,
};
use std::f32::consts::PI;
Expand All @@ -19,7 +17,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

rec.log(
"base/translated",
&Transform3D::new(TranslationAndMat3x3::translation([1.0, 0.0, 0.0])),
&Transform3D::new(TranslationRotationScale3D::translation([1.0, 0.0, 0.0])),
)?;

rec.log(
Expand Down
2 changes: 1 addition & 1 deletion examples/python/live_depth_sensor/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def run_realsense(num_frames: int | None) -> None:
rr.log_transform3d(
"realsense/rgb",
transform=rr.TranslationAndMat3(
translation=rgb_from_depth.translation, matrix=np.reshape(rgb_from_depth.rotation, (3, 3))
translation=rgb_from_depth.translation, mat3x3=np.reshape(rgb_from_depth.rotation, (3, 3))
),
from_parent=True,
timeless=True,
Expand Down
2 changes: 1 addition & 1 deletion examples/python/open_photogrammetry_format/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def log_calibrated_cameras(self) -> None:
)
)

rr.log_transform3d(entity, rr.TranslationAndMat3(translation=calib_camera.position, matrix=rot))
rr.log_transform3d(entity, rr.TranslationAndMat3(translation=calib_camera.position, mat3x3=rot))

assert calib_sensor.internals.type == "perspective"

Expand Down
5 changes: 3 additions & 2 deletions examples/python/raw_mesh/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ def log_scene(scene: trimesh.Scene, node: str, path: str | None = None) -> None:
world_from_mesh = node_data[0]
rr.log(
path,
rr.datatypes.TranslationAndMat3x3(
trimesh.transformations.translation_from_matrix(world_from_mesh), world_from_mesh[0:3, 0:3]
rr.Transform3D(
mat3x3=trimesh.transformations.translation_from_matrix(world_from_mesh),
translation=world_from_mesh[0:3, 0:3],
),
)

Expand Down
2 changes: 1 addition & 1 deletion examples/python/ros_node/rerun_urdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def log_scene(scene: trimesh.Scene, node: str, path: str | None = None, timeless
rr.Translation3D(
rr.TranslationAndMat3(
translation=trimesh.transformations.translation_from_matrix(world_from_mesh),
matrix=world_from_mesh[0:3, 0:3],
mat3x3=world_from_mesh[0:3, 0:3],
)
),
timeless=timeless,
Expand Down
2 changes: 1 addition & 1 deletion rerun_cpp/src/rerun/archetypes/transform3d.hpp

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

2 changes: 1 addition & 1 deletion rerun_cpp/src/rerun/archetypes/transform3d_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace rerun {
/// where the transform was logged. Otherwise, the transform maps from the space to its
/// parent.
Transform3D(const datatypes::Vec3D& translation, bool from_parent = false)
: Transform3D(datatypes::TranslationAndMat3x3(translation, from_parent)) {}
: Transform3D(datatypes::TranslationRotationScale3D(translation, from_parent)) {}

/// From 3x3 matrix only.
///
Expand Down
6 changes: 3 additions & 3 deletions rerun_cpp/src/rerun/datatypes/translation_and_mat3x3.cpp

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

Loading

0 comments on commit 69a1549

Please sign in to comment.