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

Tighter UI for Pinhole and when hovering images #3579

Merged
merged 6 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 11 additions & 0 deletions crates/re_data_ui/src/pinhole.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ impl DataUi for PinholeProjection {
verbosity: UiVerbosity,
query: &re_arrow_store::LatestAtQuery,
) {
if verbosity == UiVerbosity::Small {
// See if this is a trivial pinhole, and can be displayed as such:
let fl = self.focal_length_in_pixels();
let pp = self.principal_point();
if *self == Self::from_focal_length_and_principal_point(fl, pp) {
ui.label(format!("Focal length: {fl}\nPrincipal point: {pp}"))
.on_hover_ui(|ui| self.data_ui(ctx, ui, UiVerbosity::Reduced, query));
Comment on lines +25 to +26
Copy link
Member

Choose a reason for hiding this comment

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

focal length is most of the time same on X and Y. I think the ui should tighten this further in that case

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point!

image

return;
}
}

self.0.data_ui(ctx, ui, verbosity, query);
}
}
Expand Down
23 changes: 23 additions & 0 deletions crates/re_types/src/components/pinhole_projection_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ use crate::datatypes::Vec2D;
use super::PinholeProjection;

impl PinholeProjection {
#[inline]
pub fn from_focal_length_and_principal_point(
focal_length: impl Into<Vec2D>,
principal_point: impl Into<Vec2D>,
) -> Self {
let fl = focal_length.into();
let pp = principal_point.into();
Self::from([
[fl.x(), 0.0, 0.0],
[0.0, fl.y(), 0.0],
[pp.x(), pp.y(), 1.0],
])
}

/// X & Y focal length in pixels.
///
/// [see definition of intrinsic matrix](https://en.wikipedia.org/wiki/Camera_resectioning#Intrinsic_parameters)
Expand Down Expand Up @@ -43,3 +57,12 @@ impl PinholeProjection {
.extend(pixel.z)
}
}

#[test]
fn test_pinhole() {
let fl = Vec2D::from([600.0, 600.0]);
let pp = glam::Vec2::from([300.0, 240.0]);
let pinhole = PinholeProjection::from_focal_length_and_principal_point(fl, pp);
assert_eq!(pinhole.focal_length_in_pixels(), fl);
assert_eq!(pinhole.principal_point(), pp);
}
Loading