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

Allow any pan/zoom in 2D spatial views #6089

Merged
merged 20 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
5 changes: 5 additions & 0 deletions crates/re_renderer/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@ pub fn ndc_from_pixel(pixel_coord: glam::Vec2, screen_extent: glam::UVec2) -> gl

/// Defines a transformation from a rectangular region of interest into a rectangular target region.
///
/// This is "pan and scan".
///
/// Transforms the range of `region_of_interest` to the range of `region`.
#[derive(Clone, Debug)]
pub struct RectTransform {
/// The region of the scene that should be visible.
pub region_of_interest: RectF32,

/// The full scene.
pub region: RectF32,
}

Expand Down
18 changes: 17 additions & 1 deletion crates/re_space_view_spatial/src/space_view_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use ahash::HashSet;
use nohash_hasher::{IntMap, IntSet};

use re_entity_db::{EntityDb, EntityProperties, EntityTree};
use re_format::format_f32;
use re_log_types::EntityPath;
use re_types::{
archetypes::{DepthImage, Image},
Expand Down Expand Up @@ -248,7 +249,22 @@ impl SpaceViewClass for SpatialSpaceView2D {
.show(ui, |ui| {
state.default_size_ui(ctx, ui);
state.bounding_box_ui(ctx, ui, SpatialSpaceViewKind::TwoD);
ui.end_row();

if let Some(bounds) = state.state_2d.bounds {
ctx.re_ui
.grid_left_hand_label(ui, "Bounds")
.on_hover_text("The currently visible area.");
emilk marked this conversation as resolved.
Show resolved Hide resolved
ui.vertical(|ui| {
ui.style_mut().wrap = Some(false);
let (min, max) = (bounds.min, bounds.max);
ui.label(format!("x [{} - {}]", format_f32(min.x), format_f32(max.x),));
ui.label(format!("y [{} - {}]", format_f32(min.y), format_f32(max.y),));
if ui.button("Reset bounds").clicked() {
state.state_2d.bounds = None;
}
});
ui.end_row();
}
});
Ok(())
}
Expand Down
11 changes: 6 additions & 5 deletions crates/re_space_view_spatial/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ impl SpatialSpaceViewState {
ui.label(format!("z [{} - {}]", format_f32(min.z), format_f32(max.z),));
}
});
ui.end_row();
}

pub fn default_size_ui(&mut self, ctx: &ViewerContext<'_>, ui: &mut egui::Ui) {
Expand Down Expand Up @@ -247,15 +248,15 @@ fn size_ui(

pub fn create_labels(
mut labels: Vec<UiLabel>,
ui_from_canvas: egui::emath::RectTransform,
ui_from_scene: egui::emath::RectTransform,
eye3d: &Eye,
parent_ui: &egui::Ui,
highlights: &SpaceViewHighlights,
spatial_kind: SpatialSpaceViewKind,
) -> (Vec<egui::Shape>, Vec<PickableUiRect>) {
re_tracing::profile_function!();

let ui_from_world_3d = eye3d.ui_from_world(*ui_from_canvas.to());
let ui_from_world_3d = eye3d.ui_from_world(*ui_from_scene.to());

// Closest last (painters algorithm)
labels.sort_by_key(|label| {
Expand All @@ -276,7 +277,7 @@ pub fn create_labels(
if spatial_kind == SpatialSpaceViewKind::ThreeD {
continue;
}
let rect_in_ui = ui_from_canvas.transform_rect(rect);
let rect_in_ui = ui_from_scene.transform_rect(rect);
(
// Place the text centered below the rect
(rect_in_ui.width() - 4.0).at_least(60.0),
Expand All @@ -288,7 +289,7 @@ pub fn create_labels(
if spatial_kind == SpatialSpaceViewKind::ThreeD {
continue;
}
let pos_in_ui = ui_from_canvas.transform_pos(pos);
let pos_in_ui = ui_from_scene.transform_pos(pos);
(f32::INFINITY, pos_in_ui + egui::vec2(0.0, 3.0))
}
UiLabelTarget::Position3D(pos) => {
Expand Down Expand Up @@ -352,7 +353,7 @@ pub fn create_labels(
));

ui_rects.push(PickableUiRect {
rect: ui_from_canvas.inverse().transform_rect(bg_rect),
rect: ui_from_scene.inverse().transform_rect(bg_rect),
instance_hash: label.labeled_instance,
});
}
Expand Down
Loading
Loading