Skip to content

Commit

Permalink
Introduce ImagePlaneDistance Component (#6505)
Browse files Browse the repository at this point in the history
### What
- Resolves: #6084

This introduces a new `ViewContext` that holds onto the state so that we
don't need to continuously pass it around everywhere. Additionally,
introduces some new helpers to make querying with overrides and
fallbacks easier.

We are accumulating more information in the HybridDataResults so that we
can now find a fallback provider and resolve fallbacks.

Specifically this makes it possible to now use the DataResult to
directly produce a HybridLatestAtResults, which in turn allows you to
make calls like `get_mono_with_fallback()`.

For better or for worse, this will eat all manner of promise/deser
errors along the way and just get you a data value you can use.
```
    let results = data_result.latest_at_with_overrides::<re_types::archetypes::Pinhole>(ctx, query);

    let image_plane_distance = Some(results.get_mono_with_fallback());
``` 

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using examples from latest `main` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/6505?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/6505?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!

- [PR Build Summary](https://build.rerun.io/pr/6505)
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)

To run all checks from `main`, comment on the PR with `@rerun-bot
full-check`.
  • Loading branch information
jleibs authored Jun 6, 2024
1 parent 9b9ccab commit 0346905
Show file tree
Hide file tree
Showing 72 changed files with 1,234 additions and 478 deletions.
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,
};

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

0 comments on commit 0346905

Please sign in to comment.