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

Introduce ImagePlaneDistance Component #6505

Merged
merged 20 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4820,6 +4820,7 @@ dependencies = [
"re_log",
"re_log_types",
"re_renderer",
"re_space_view",
"re_space_view_spatial",
"re_space_view_time_series",
"re_tracing",
Expand Down
18 changes: 0 additions & 18 deletions crates/re_entity_db/src/entity_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,6 @@ pub struct EntityProperties {
/// What kind of color mapping should be applied (none, map, texture, transfer..)?
pub color_mapper: EditableAutoValue<ColorMapper>, // TODO(andreas): should become a component and be part of the DepthImage and regular Images (with limitation to mono channel image).

/// Distance of the projection plane (frustum far plane).
///
/// Only applies to pinhole cameras when in a spatial view, using 3D navigation.
pub pinhole_image_plane_distance: EditableAutoValue<f32>, // TODO(#6084): should be a regular component on the Pinhole archetype.

/// Should the depth texture be backprojected into a point cloud?
///
/// Only applies to tensors with meaning=depth that are affected by a pinhole transform.
Expand Down Expand Up @@ -149,7 +144,6 @@ impl Default for EntityProperties {
Self {
interactive: true,
color_mapper: EditableAutoValue::default(),
pinhole_image_plane_distance: EditableAutoValue::Auto(1.0),
backproject_depth: EditableAutoValue::Auto(true),
depth_from_world_scale: EditableAutoValue::Auto(1.0),
backproject_radius_scale: EditableAutoValue::Auto(1.0),
Expand All @@ -171,11 +165,6 @@ impl EntityProperties {

color_mapper: self.color_mapper.or(&child.color_mapper).clone(),

pinhole_image_plane_distance: self
.pinhole_image_plane_distance
.or(&child.pinhole_image_plane_distance)
.clone(),

backproject_depth: self.backproject_depth.or(&child.backproject_depth).clone(),
depth_from_world_scale: self
.depth_from_world_scale
Expand Down Expand Up @@ -214,11 +203,6 @@ impl EntityProperties {

color_mapper: other.color_mapper.or(&self.color_mapper).clone(),

pinhole_image_plane_distance: other
.pinhole_image_plane_distance
.or(&self.pinhole_image_plane_distance)
.clone(),

backproject_depth: other.backproject_depth.or(&self.backproject_depth).clone(),
depth_from_world_scale: other
.depth_from_world_scale
Expand Down Expand Up @@ -249,7 +233,6 @@ impl EntityProperties {
let Self {
interactive,
color_mapper,
pinhole_image_plane_distance,
backproject_depth,
depth_from_world_scale,
backproject_radius_scale,
Expand All @@ -262,7 +245,6 @@ impl EntityProperties {

interactive != &other.interactive
|| color_mapper.has_edits(&other.color_mapper)
|| pinhole_image_plane_distance.has_edits(&other.pinhole_image_plane_distance)
|| backproject_depth.has_edits(&other.backproject_depth)
|| depth_from_world_scale.has_edits(&other.depth_from_world_scale)
|| backproject_radius_scale.has_edits(&other.backproject_radius_scale)
Expand Down
2 changes: 1 addition & 1 deletion crates/re_query/src/promise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Promise {
// ---

/// Resolves and keeps track of [`Promise`]s.
#[derive(Default)]
#[derive(Debug, Default)]
pub struct PromiseResolver {}

impl PromiseResolver {
Expand Down
1 change: 1 addition & 0 deletions crates/re_selection_panel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ re_entity_db = { workspace = true, features = ["serde"] }
re_log.workspace = true
re_log_types.workspace = true
re_renderer.workspace = true
re_space_view.workspace = true
re_space_view_time_series.workspace = true
re_space_view_spatial.workspace = true
re_tracing.workspace = true
Expand Down
139 changes: 86 additions & 53 deletions crates/re_selection_panel/src/selection_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@ use re_entity_db::{
ColorMapper, Colormap, EditableAutoValue, EntityPath, EntityProperties, InstancePath,
};
use re_log_types::EntityPathFilter;
use re_space_view::DataResultQuery as _;
use re_space_view_time_series::TimeSeriesSpaceView;
use re_types::{
components::{PinholeProjection, Transform3D},
archetypes::Pinhole,
components::{ImagePlaneDistance, PinholeProjection, Transform3D},
tensor_data::TensorDataMeaning,
};
use re_ui::{icons, list_item, ContextExt as _, DesignTokens, SyntaxHighlighting as _, UiExt as _};
use re_viewer_context::{
contents_name_style, gpu_bridge::colormap_dropdown_button_ui, icon_for_container_kind,
ContainerId, Contents, DataQueryResult, HoverHighlight, Item, SpaceViewClass, SpaceViewId,
UiLayout, ViewStates, ViewerContext,
ContainerId, Contents, DataQueryResult, DataResult, HoverHighlight, Item, SpaceViewClass,
SpaceViewId, UiLayout, ViewContext, ViewStates, ViewerContext,
};
use re_viewport_blueprint::{
ui::show_add_space_view_or_container_modal, SpaceViewBlueprint, ViewportBlueprint,
};
use re_viewport_blueprint::{ui::show_add_space_view_or_container_modal, ViewportBlueprint};

use crate::override_ui::{override_ui, override_visualizer_ui};
use crate::space_view_entity_picker::SpaceViewEntityPicker;
Expand Down Expand Up @@ -221,7 +225,34 @@ impl SelectionPanel {
}

Item::DataResult(space_view_id, instance_path) => {
blueprint_ui_for_data_result(ctx, blueprint, ui, *space_view_id, instance_path);
let Some(space_view) = blueprint.space_view(space_view_id) else {
return;
};

let visualizer_collection = ctx
.space_view_class_registry
.new_visualizer_collection(space_view.class_identifier());

let Some(view_state) = view_states
.get(*space_view_id)
.map(|states| states.view_state.as_ref())
else {
return;
};

let view_ctx = ViewContext {
viewer_ctx: ctx,
view_state,
visualizer_collection: &visualizer_collection,
};
Comment on lines +232 to +247
Copy link
Member

Choose a reason for hiding this comment

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

A helper would be nice.

Suggested change
let visualizer_collection = ctx
.space_view_class_registry
.new_visualizer_collection(space_view.class_identifier());
let Some(view_state) = view_states
.get(*space_view_id)
.map(|states| states.view_state.as_ref())
else {
return;
};
let view_ctx = ViewContext {
viewer_ctx: ctx,
view_state,
visualizer_collection: &visualizer_collection,
};
if let Some(view_ctx) = ctx.as_view_context() else {
return;
};

edit: I saw elsewhere that you are constructing it slightly differently, so this may not make much sense

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm going to come back and do this one on top of the next PR in this stack once I know the different variants of how it needs to get built.

Copy link
Member

Choose a reason for hiding this comment

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

makes sense 👍🏻


blueprint_ui_for_data_result(
&view_ctx,
space_view,
ui,
*space_view_id,
instance_path,
);
}
}
}
Expand Down Expand Up @@ -1131,58 +1162,56 @@ fn has_blueprint_section(item: &Item) -> bool {
}

fn blueprint_ui_for_data_result(
ctx: &ViewerContext<'_>,
blueprint: &ViewportBlueprint,
ctx: &ViewContext<'_>,
space_view: &SpaceViewBlueprint,
ui: &mut Ui,
space_view_id: SpaceViewId,
instance_path: &InstancePath,
) {
if let Some(space_view) = blueprint.space_view(&space_view_id) {
if instance_path.instance.is_all() {
// the whole entity
let entity_path = &instance_path.entity_path;

let query_result = ctx.lookup_query_result(space_view.id);
if let Some(data_result) = query_result
.tree
.lookup_result_by_path(entity_path)
.cloned()
{
let mut accumulated_legacy_props = data_result.accumulated_properties().clone();
let accumulated_legacy_props_before = accumulated_legacy_props.clone();
if instance_path.instance.is_all() {
// the whole entity
let entity_path = &instance_path.entity_path;

let query_result = ctx.lookup_query_result(space_view.id);
if let Some(data_result) = query_result
.tree
.lookup_result_by_path(entity_path)
.cloned()
{
let mut accumulated_legacy_props = data_result.accumulated_properties().clone();
let accumulated_legacy_props_before = accumulated_legacy_props.clone();

entity_props_ui(
ctx,
ui,
ctx.lookup_query_result(space_view_id),
entity_path,
&mut accumulated_legacy_props,
entity_props_ui(
ctx,
ui,
ctx.lookup_query_result(space_view_id),
&data_result,
&mut accumulated_legacy_props,
);
if accumulated_legacy_props != accumulated_legacy_props_before {
data_result.save_individual_override_properties(
ctx.viewer_ctx,
Some(accumulated_legacy_props),
);
if accumulated_legacy_props != accumulated_legacy_props_before {
data_result
.save_individual_override_properties(ctx, Some(accumulated_legacy_props));
}
}
}
}
}

fn entity_props_ui(
ctx: &ViewerContext<'_>,
ctx: &ViewContext<'_>,
ui: &mut egui::Ui,
query_result: &DataQueryResult,
entity_path: &EntityPath,
data_result: &DataResult,
entity_props: &mut EntityProperties,
) {
use re_types::blueprint::components::Visible;
use re_types::Loggable as _;

let Some(data_result) = query_result.tree.lookup_result_by_path(entity_path) else {
return;
};
let entity_path = &data_result.entity_path;

{
let visible_before = data_result.is_visible(ctx);
let visible_before = data_result.is_visible(ctx.viewer_ctx);
let mut visible = visible_before;

let override_source =
Expand All @@ -1199,7 +1228,7 @@ fn entity_props_ui(

if visible_before != visible {
data_result.save_recursive_override_or_clear_if_redundant(
ctx,
ctx.viewer_ctx,
&query_result.tree,
&Visible(visible),
);
Expand All @@ -1209,16 +1238,16 @@ fn entity_props_ui(
ui.re_checkbox(&mut entity_props.interactive, "Interactive")
.on_hover_text("If disabled, the entity will not react to any mouse interaction");

query_range_ui_data_result(ctx, ui, data_result);
query_range_ui_data_result(ctx.viewer_ctx, ui, data_result);

egui::Grid::new("entity_properties")
.num_columns(2)
.show(ui, |ui| {
// TODO(wumpf): It would be nice to only show pinhole & depth properties in the context of a 3D view.
// if *view_state.state_spatial.nav_mode.get() == SpatialNavigationMode::ThreeD {
pinhole_props_ui(ctx, ui, entity_path, entity_props);
depth_props_ui(ctx, ui, entity_path, entity_props);
transform3d_visualization_ui(ctx, ui, entity_path, entity_props);
pinhole_props_ui(ctx, ui, data_result);
depth_props_ui(ctx.viewer_ctx, ui, entity_path, entity_props);
transform3d_visualization_ui(ctx.viewer_ctx, ui, entity_path, entity_props);
});
}

Expand Down Expand Up @@ -1252,30 +1281,34 @@ fn colormap_props_ui(
ui.end_row();
}

fn pinhole_props_ui(
ctx: &ViewerContext<'_>,
ui: &mut egui::Ui,
entity_path: &EntityPath,
entity_props: &mut EntityProperties,
) {
let (query, store) = guess_query_and_db_for_selected_entity(ctx, entity_path);
fn pinhole_props_ui(ctx: &ViewContext<'_>, ui: &mut egui::Ui, data_result: &DataResult) {
let (query, store) =
guess_query_and_db_for_selected_entity(ctx.viewer_ctx, &data_result.entity_path);

if store
.latest_at_component::<PinholeProjection>(entity_path, &query)
.latest_at_component::<PinholeProjection>(&data_result.entity_path, &query)
.is_some()
{
let results = data_result.latest_at_with_overrides::<Pinhole>(ctx, &query);

let mut image_plane_value: f32 = results
.get_mono_with_fallback::<ImagePlaneDistance>()
.into();

ui.label("Image plane distance");
let mut distance = *entity_props.pinhole_image_plane_distance;
let speed = (distance * 0.05).at_least(0.01);
let speed = (image_plane_value * 0.05).at_least(0.01);
if ui
.add(
egui::DragValue::new(&mut distance)
egui::DragValue::new(&mut image_plane_value)
.clamp_range(0.0..=1.0e8)
.speed(speed),
)
.on_hover_text("Controls how far away the image plane is")
.changed()
{
entity_props.pinhole_image_plane_distance = EditableAutoValue::UserEdited(distance);
let new_image_plane: ImagePlaneDistance = image_plane_value.into();

data_result.save_individual_override(ctx.viewer_ctx, &new_image_plane);
}
ui.end_row();
}
Expand Down
4 changes: 2 additions & 2 deletions crates/re_space_view/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ mod screenshot;
mod view_property_ui;

pub use heuristics::suggest_space_view_for_each_entity;
pub use query::{latest_at_with_overrides, range_with_overrides, HybridResults};
pub use results_ext::RangeResultsExt;
pub use query::{latest_at_with_overrides, range_with_overrides, DataResultQuery};
pub use results_ext::{HybridResults, RangeResultsExt};
pub use screenshot::ScreenshotMode;
pub use view_property_ui::view_property_ui;

Expand Down
Loading
Loading