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

Option to show scene bounding box #1770

Merged
merged 5 commits into from
Apr 4, 2023
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
31 changes: 31 additions & 0 deletions crates/re_renderer/src/renderer/depth_cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,37 @@ pub struct DepthCloud {
pub outline_mask_id: OutlineMaskPreference,
}

impl DepthCloud {
/// World-space bounding-box.
pub fn bbox(&self) -> macaw::BoundingBox {
let max_depth = self.max_depth_in_world;
let w = self.depth_dimensions.x as f32;
let h = self.depth_dimensions.y as f32;
let corners = [
glam::Vec3::ZERO, // camera origin
glam::Vec3::new(0.0, 0.0, max_depth),
glam::Vec3::new(0.0, h, max_depth),
glam::Vec3::new(w, 0.0, max_depth),
glam::Vec3::new(w, h, max_depth),
];

let intrinsics = self.depth_camera_intrinsics;
let focal_length = glam::vec2(intrinsics.col(0).x, intrinsics.col(1).y);
let offset = intrinsics.col(2).truncate();

let mut bbox = macaw::BoundingBox::nothing();

for corner in corners {
let depth = corner.z;
let pos_in_obj = ((corner.truncate() - offset) * depth / focal_length).extend(depth);
let pos_in_world = self.world_from_obj.project_point3(pos_in_obj);
bbox.extend(pos_in_world);
}

bbox
}
}

pub struct DepthClouds {
pub clouds: Vec<DepthCloud>,
pub radius_boost_in_ui_points_for_outlines: f32,
Expand Down
6 changes: 4 additions & 2 deletions crates/re_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,13 @@ impl ReUi {
.inner
}

/// Grid to be used in selection view.
/// Two-column grid to be used in selection view.
#[allow(clippy::unused_self)]
pub fn selection_grid(&self, ui: &mut egui::Ui, id: &str) -> egui::Grid {
// Spread rows a bit to make it easier to see the groupings
egui::Grid::new(id).spacing(ui.style().spacing.item_spacing + egui::vec2(0.0, 8.0))
egui::Grid::new(id)
.num_columns(2)
.spacing(ui.style().spacing.item_spacing + egui::vec2(0.0, 8.0))
}

/// Draws a shadow into the given rect with the shadow direction given from dark to light
Expand Down
6 changes: 5 additions & 1 deletion crates/re_viewer/src/ui/view_spatial/scene/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl SceneSpatialPrimitives {
line_strips,
points,
meshes,
depth_clouds: _, // no bbox for depth clouds
depth_clouds,
any_outlines: _,
} = self;

Expand Down Expand Up @@ -133,6 +133,10 @@ impl SceneSpatialPrimitives {
*bounding_box =
bounding_box.union(mesh.mesh.bbox().transform_affine3(&mesh.world_from_mesh));
}

for cloud in &depth_clouds.clouds {
*bounding_box = bounding_box.union(cloud.bbox());
}
}

pub fn mesh_instances(&self) -> Vec<MeshInstance> {
Expand Down
2 changes: 2 additions & 0 deletions crates/re_viewer/src/ui/view_spatial/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,15 @@ impl ViewSpatialState {
});
});
ui.checkbox(&mut self.state_3d.show_axes, "Show origin axes").on_hover_text("Show X-Y-Z axes");
ui.checkbox(&mut self.state_3d.show_bbox, "Show bounding box").on_hover_text("Show the current scene bounding box");
});
ui.end_row();
}

ctx.re_ui.grid_left_hand_label(ui, "Bounding box")
.on_hover_text("The bounding box encompassing all Entities in the view right now.");
ui.vertical(|ui| {
ui.style_mut().wrap = Some(false);
let BoundingBox { min, max } = self.scene_bbox;
ui.label(format!(
"x [{} - {}]",
Expand Down
22 changes: 22 additions & 0 deletions crates/re_viewer/src/ui/view_spatial/ui_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub struct View3DState {
// options:
pub spin: bool,
pub show_axes: bool,
pub show_bbox: bool,

#[serde(skip)]
last_eye_interact_time: f64,
Expand All @@ -77,6 +78,7 @@ impl Default for View3DState {
hovered_point: Default::default(),
spin: false,
show_axes: false,
show_bbox: false,
last_eye_interact_time: f64::NEG_INFINITY,
space_specs: Default::default(),
space_camera: Default::default(),
Expand Down Expand Up @@ -549,6 +551,26 @@ pub fn view_3d(
);
}

if state.state_3d.show_bbox {
let bbox = scene.primitives.bounding_box();
if bbox.is_something() && bbox.is_finite() {
let scale = bbox.size();
let translation = bbox.center();
let bbox_from_unit_cube = glam::Affine3A::from_scale_rotation_translation(
scale,
Default::default(),
translation,
);
scene
.primitives
.line_strips
.batch("scene_bbox")
.add_box_outline(bbox_from_unit_cube)
.radius(Size::AUTO)
.color(egui::Color32::WHITE);
}
}

{
let orbit_center_alpha = egui::remap_clamp(
ui.input(|i| i.time) - state.state_3d.last_eye_interact_time,
Expand Down
63 changes: 30 additions & 33 deletions crates/re_viewer/src/ui/view_text/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,43 +37,40 @@ impl ViewTextState {
row_log_levels,
} = &mut self.filters;

re_ui
.selection_grid(ui, "log_config")
.num_columns(2)
.show(ui, |ui| {
re_ui.grid_left_hand_label(ui, "Columns");
ui.vertical(|ui| {
for (timeline, visible) in col_timelines {
ui.checkbox(visible, timeline.name().to_string());
}
ui.checkbox(col_entity_path, "Entity path");
ui.checkbox(col_log_level, "Log level");
});
ui.end_row();
re_ui.selection_grid(ui, "log_config").show(ui, |ui| {
re_ui.grid_left_hand_label(ui, "Columns");
ui.vertical(|ui| {
for (timeline, visible) in col_timelines {
ui.checkbox(visible, timeline.name().to_string());
}
ui.checkbox(col_entity_path, "Entity path");
ui.checkbox(col_log_level, "Log level");
});
ui.end_row();

re_ui.grid_left_hand_label(ui, "Entity Filter");
ui.vertical(|ui| {
for (entity_path, visible) in row_entity_paths {
ui.checkbox(visible, &entity_path.to_string());
}
});
ui.end_row();
re_ui.grid_left_hand_label(ui, "Entity Filter");
ui.vertical(|ui| {
for (entity_path, visible) in row_entity_paths {
ui.checkbox(visible, &entity_path.to_string());
}
});
ui.end_row();

re_ui.grid_left_hand_label(ui, "Level Filter");
ui.vertical(|ui| {
for (log_level, visible) in row_log_levels {
ui.checkbox(visible, level_to_rich_text(ui, log_level));
}
});
ui.end_row();
re_ui.grid_left_hand_label(ui, "Level Filter");
ui.vertical(|ui| {
for (log_level, visible) in row_log_levels {
ui.checkbox(visible, level_to_rich_text(ui, log_level));
}
});
ui.end_row();

re_ui.grid_left_hand_label(ui, "Text style");
ui.vertical(|ui| {
ui.radio_value(&mut self.monospace, false, "Proportional");
ui.radio_value(&mut self.monospace, true, "Monospace");
});
ui.end_row();
re_ui.grid_left_hand_label(ui, "Text style");
ui.vertical(|ui| {
ui.radio_value(&mut self.monospace, false, "Proportional");
ui.radio_value(&mut self.monospace, true, "Monospace");
});
ui.end_row();
});
}
}

Expand Down