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

Improved 3D transform ingestion & affine transform support #2102

Merged
merged 65 commits into from May 24, 2023

Conversation

Wumpf
Copy link
Member

@Wumpf Wumpf commented May 12, 2023

Transform 3D type now captures a variety of properties as-is:

  • 🆕 direction child/parent vs parent/child
  • rotation:
    • 🆕 axis angle
      • 🆕 preserves radian/degree
    • quaternion
  • 🆕 scale
    • uniform
    • per-axis
  • translation
  • 🆕 scale/skew/rotation as matrix3x3

The viewer UI reflects this:
https://github.com/rerun-io/rerun/assets/1220815/412be346-b7b7-4c90-8b33-9089aadb7b13

Some transforms in action that we didn't expose so far:
https://github.com/rerun-io/rerun/assets/1220815/f27d6e3f-024b-4989-bea8-4ce95be3f8b0

Component split-up

  • Pinhole
  • Transform3D
    • Assumed to be affine. Not named such for ergonomic reasons

      pub struct Transform3D {
          pub transform: Transform3DRepr,
      		pub from_parent: bool,
      }
      
      pub enum Transform3DRepr {
          TranslationAndMat3(TranslationAndMat3),
          TranslationRotationScale(TranslationRotationScale3D),
          // TODO(andreas): Raw 4x4 matrix.
      }
  • DisconnectedSpace

Python API changes

  • log_rigid3 deprecated

  • log_unknown deprecated

  • log_pinhole unchanged

  • log_disconnected_space

  • log_transform3d Example:

    rr.log_transform3d(
      "transform_test/child_from_parent_mat3",
      rr.TranslationAndMat3((123, 456, 789), np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])),
      from_parent=True,
    )
    rr.log_transform3d("transform_test/parent_from_child_mat3",
    	rr.TranslationAndMat3((123, 456, 789))
    )
    rr.log_transform3d("transform_test/empty_translation_mat3",
    	rr.TranslationAndMat3()
    )
    rr.log_transform3d("transform_test/translation_only",
    	rr.TranslationRotationScale3D((1, 2, 3))
    )
    rr.log_transform3d("transform_test/quaternion_only",
    	rr.TranslationRotationScale3D(rotation=rr.Quaternion(xyzw=(0, 0, 0, 1))
    )
    rr.log_transform3d(
      "transform_test/axis_angle_degrees_only",
      rr.RotationAxisAngle((0, 1, 0), degrees=10),
    )
    # TODO: rr.Translation3D, also on native - enum Translation3D { None, Vec3(Vec3) }|
    # TODO: rr.Scale3D
    rr.log_transform3d(
      "transform_test/axis_angle_radians_only",
      rr.RotationAxisAngle((0, 0, 1), radians=1),
    )
    rr.log_transform3d(
      "transform_test/scale_uniform_only",
      rr.TranslationRotationScale3D(scale=rr.Scale3D(2)),
    )
    rr.log_transform3d(
      "transform_test/scale_vector",
      rr.TranslationRotationScale3D(scale=(1, 2, 3)),
    )

Future Work

  • Document & test Transform3D and Pinhole on the same entity (generally working now!)
  • Python utility rr.transform(rotation=, translation=, matrix=)
  • Support Matrix4 on transform3d
    • warning if not affine? etc.
  • Support euler angles?
  • Support None to specify unknown Pinhole/Transform3d
  • Support other Quaternion representations (open question whether this time we swizzle before ingesting, or add another enum. low stakes decision)
  • Direct support for scipi datatypes!
  • Allow to pass in interfaces - anything that implements some interface (that e.g. specifies translation) can be passed in to rr.log_transform3d

Fixes #1956

Checklist

PR Build Summary: https://build.rerun.io/pr/2102

@Wumpf Wumpf added 🐍 Python API Python logging API 🦀 Rust API Rust logging API labels May 12, 2023
@Wumpf Wumpf marked this pull request as ready for review May 17, 2023 17:59
@Wumpf
Copy link
Member Author

Wumpf commented May 17, 2023

Read for review now!

Can't repro python linting errors locally, must be version dependent. Those lints don't make sense to me though - sounds like mypi has a built-in quaternion type..? Any advice very welcome
https://github.com/rerun-io/rerun/actions/runs/5006419878/jobs/8971679858?pr=2102

@Wumpf Wumpf removed the do-not-merge Do not merge this PR label May 22, 2023
@emilk
Copy link
Member

emilk commented May 23, 2023

We also need to update https://www.rerun.io/docs/concepts/spaces-and-transforms

crates/re_log_types/src/component_types/transform3d.rs Outdated Show resolved Hide resolved
crates/re_data_ui/src/transform3d.rs Outdated Show resolved Hide resolved
crates/re_data_ui/src/transform3d.rs Outdated Show resolved Hide resolved
crates/re_log_types/src/component_types/transform3d.rs Outdated Show resolved Hide resolved
examples/rust/raw_mesh/src/main.rs Outdated Show resolved Hide resolved
else:
angle = pa.array([rotation.radians], type=pa.float32())
angle_variant = "Radians"
angle = build_dense_union(axis_angle_type["angle"].type, angle_variant, angle)
Copy link
Member

Choose a reason for hiding this comment

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

😭 oof -- the need to jump through these hoops is so painful

rerun_py/rerun_sdk/rerun/log/transform.py Outdated Show resolved Hide resolved
rerun_py/src/python_bridge.rs Show resolved Hide resolved
Comment on lines 43 to 45
rr.Translation3D(
trimesh.transformations.translation_from_matrix(world_from_mesh, world_from_mesh[0:3, 0:3])
),
Copy link
Member

Choose a reason for hiding this comment

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

something is wrong here...

Suggested change
rr.Translation3D(
trimesh.transformations.translation_from_matrix(world_from_mesh, world_from_mesh[0:3, 0:3])
),
rr.TranslationAndMat3(
rr.Translation3D(
trimesh.transformations.translation_from_matrix(world_from_mesh)
),
world_from_mesh[0:3, 0:3])
),

@Wumpf Wumpf merged commit 60d525e into main May 24, 2023
17 checks passed
@Wumpf Wumpf deleted the andreas/transform3d branch May 24, 2023 16:22
emilk pushed a commit that referenced this pull request Jun 15, 2023
* Transform is now Transform3D and has an affine transform with various options

* todo notes on sparse enums in transform3d

* from instead of into glam impls

* add more utilities, port rust examples

* better ui display for transform3d

* transform3d now also captures direction parent/child child/parent

* Fix images with same render order not layering transparently

* nicer draw order sample

* every draw order given out is individual again to avoid z fighting

* affine3 python interface wip

* unified affine transform logging from python

* hide zero translations

* fix up log_rigid3 and deprecate it

* example for log_affine3

* Rename RotationAxisAngle

* py-lint fixes

* re-enable data_table_sizes_basics test

* more docs and doc tests for transform3d

* implement pinhole via transform3d.py

* spelling

* better affine transform error messages on python, fix tensor logging again

* linting, small improvements

* update all uses of log_rigid3 in python examples

* fix old python incompatibility issues

* split up transform enum into three different components
rust only so far

* wire up python sdk again to new components

* fix pinhole camera not being categorized as spatial

* enable custom pinhole ui

* Rename to TranslationAndMat3

* fixup some tests in re_log_types

* mono component documentation

* fixup test_clean_for_polars_modify

* change python api to log_transform3d

* explicit quaternion type for python

* Translation3D is now its own enum to allow explicit non-logged translation

* fix quaternion logging in examples

* slightly better error messages on wrong type in python transform api

* Rust fmt

* rust test fix

* Avoid using attr.dataclass

* comment and cosmetic fixes, fixes for ros demo

* translation/rotation/scale are now options

* rename creation methods in rust api fro Transform3D

* fixup SpaceInfoConnection to be more versatile

* Rigid3D helper class on python

* a bit nicer rust api, less word duplication

* Quaternion is no longer a dataclass  in order to enforce spelling out the ordering

* fix documentation of datalayout for matrix on python transform api

* test/lint fixes

* doc fix

* fixup ros demo

---------

Co-authored-by: Jeremy Leibs <jeremy@rerun.io>
This was referenced Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐍 Python API Python logging API 📺 re_viewer affects re_viewer itself 🦀 Rust API Rust logging API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support affine transformations (allow scaling!)
3 participants