Skip to content

Commit

Permalink
Do all the awful things until it works
Browse files Browse the repository at this point in the history
  • Loading branch information
jleibs committed Jun 5, 2024
1 parent eabcb61 commit c1578dc
Show file tree
Hide file tree
Showing 14 changed files with 195 additions and 86 deletions.
2 changes: 2 additions & 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 Expand Up @@ -4891,6 +4892,7 @@ dependencies = [
"re_log_types",
"re_renderer",
"re_tracing",
"re_types",
"re_types_core",
"re_ui",
"re_viewer_context",
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
103 changes: 85 additions & 18 deletions crates/re_selection_panel/src/selection_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ use re_entity_db::{
ColorMapper, Colormap, EditableAutoValue, EntityPath, EntityProperties, InstancePath,
};
use re_log_types::EntityPathFilter;
use re_space_view::latest_at_with_overrides;
use re_space_view_time_series::TimeSeriesSpaceView;
use re_types::{
components::{PinholeProjection, Transform3D},
archetypes::Pinhole,
components::{ImagePlaneDistance, PinholeProjection, Transform3D},
tensor_data::TensorDataMeaning,
Archetype, Loggable,
};
use re_ui::{icons, list_item, ReUi, SyntaxHighlighting 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, ViewStates, ViewerContext,
};
use re_viewport_blueprint::{ui::show_add_space_view_or_container_modal, ViewportBlueprint};

Expand Down Expand Up @@ -231,7 +234,14 @@ impl SelectionPanel {
}

Item::DataResult(space_view_id, instance_path) => {
blueprint_ui_for_data_result(ctx, blueprint, ui, *space_view_id, instance_path);
blueprint_ui_for_data_result(
ctx,
blueprint,
ui,
*space_view_id,
view_states,
instance_path,
);
}
}
}
Expand Down Expand Up @@ -1175,6 +1185,7 @@ fn blueprint_ui_for_data_result(
blueprint: &ViewportBlueprint,
ui: &mut Ui,
space_view_id: SpaceViewId,
view_states: &mut ViewStates,
instance_path: &InstancePath,
) {
if let Some(space_view) = blueprint.space_view(&space_view_id) {
Expand All @@ -1194,8 +1205,11 @@ fn blueprint_ui_for_data_result(
entity_props_ui(
ctx,
ui,
blueprint,
space_view_id,
view_states,
ctx.lookup_query_result(space_view_id),
entity_path,
&data_result,
&mut accumulated_legacy_props,
);
if accumulated_legacy_props != accumulated_legacy_props_before {
Expand All @@ -1210,17 +1224,19 @@ fn blueprint_ui_for_data_result(
fn entity_props_ui(
ctx: &ViewerContext<'_>,
ui: &mut egui::Ui,
blueprint: &ViewportBlueprint,
space_view_id: SpaceViewId,
view_states: &mut ViewStates,
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 entity_path = &data_result.entity_path;

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

{
let visible_before = data_result.is_visible(ctx);
Expand Down Expand Up @@ -1258,7 +1274,7 @@ fn entity_props_ui(
.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);
pinhole_props_ui(ctx, ui, blueprint, space_view_id, view_states, data_result);
depth_props_ui(ctx, ui, entity_path, entity_props);
transform3d_visualization_ui(ctx, ui, entity_path, entity_props);
});
Expand Down Expand Up @@ -1298,27 +1314,78 @@ fn colormap_props_ui(
fn pinhole_props_ui(
ctx: &ViewerContext<'_>,
ui: &mut egui::Ui,
entity_path: &EntityPath,
entity_props: &mut EntityProperties,
blueprint: &ViewportBlueprint,
view_id: SpaceViewId,
view_states: &mut ViewStates,
data_result: &DataResult,
) {
let (query, store) = guess_query_and_db_for_selected_entity(ctx, entity_path);
let (query, store) = guess_query_and_db_for_selected_entity(ctx, &data_result.entity_path);

let resolver = ctx.recording().resolver();

let Some(class) = blueprint
.space_view(&view_id)
.map(|sv| sv.class(ctx.space_view_class_registry))
else {
return;
};

let view_state = view_states
.get_mut(ctx.space_view_class_registry, view_id, "3D".into())
.view_state
.as_ref();

let results = latest_at_with_overrides(
ctx,
None,
&query,
&data_result,
[ImagePlaneDistance::name()],
);

let mut image_plane_value = results
.get_or_empty(ImagePlaneDistance::name())
.to_dense::<ImagePlaneDistance>(resolver)
.flatten()
.ok()
.and_then(|r| r.first().copied())
.or_else(|| {
class
.untyped_fallback_raw(
ctx,
Some(Pinhole::name()),
view_state,
data_result,
ImagePlaneDistance::name(),
)
.and_then(|r| {
ImagePlaneDistance::from_arrow(r.as_ref())
.ok()
.and_then(|r| r.first().copied())
})
})
.unwrap_or_default()
.0
.0;

if store
.latest_at_component::<PinholeProjection>(entity_path, &query)
.latest_at_component::<PinholeProjection>(&data_result.entity_path, &query)
.is_some()
{
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 mut new_image_plane: ImagePlaneDistance = image_plane_value.into();

data_result.save_individual_override(ctx, &new_image_plane);
}
ui.end_row();
}
Expand Down
2 changes: 2 additions & 0 deletions crates/re_space_view_bar_chart/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,5 @@ fn to_egui_plot_corner(value: LegendCorner) -> egui_plot::Corner {
LegendCorner::RightBottom => egui_plot::Corner::RightBottom,
}
}

re_viewer_context::impl_component_fallback_provider!(BarChartSpaceView => []);
1 change: 1 addition & 0 deletions crates/re_space_view_dataframe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ re_log_types.workspace = true
re_renderer.workspace = true
re_tracing.workspace = true
re_types_core.workspace = true
re_types.workspace = true
re_ui.workspace = true
re_viewer_context.workspace = true

Expand Down
2 changes: 2 additions & 0 deletions crates/re_space_view_dataframe/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,5 @@ fn sorted_instance_paths_for<'a>(
.into_iter()
.map(|instance| InstancePath::instance(entity_path.clone(), instance))
}

re_viewer_context::impl_component_fallback_provider!(DataframeSpaceView => []);
102 changes: 42 additions & 60 deletions crates/re_space_view_spatial/src/contexts/transform_context.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use nohash_hasher::IntMap;

use re_data_store::LatestAtQuery;
use re_entity_db::{EntityDb, EntityPath, EntityPropertyMap, EntityTree};
use re_entity_db::{EntityDb, EntityPath, EntityTree};
use re_space_view::latest_at_with_overrides;
use re_types::{
archetypes::Pinhole,
Expand All @@ -15,7 +15,7 @@ use re_viewer_context::{
ViewContextSystem,
};

use crate::visualizers::{image_view_coordinates, CamerasVisualizer};
use crate::visualizers::image_view_coordinates;

#[derive(Clone)]
struct TransformInfo {
Expand Down Expand Up @@ -101,21 +101,6 @@ impl ViewContextSystem for TransformContext {

let entity_tree = ctx.recording().tree();

// TODO(jleibs): The need to do this hints at a problem with how we think about
// the interaction between properties and "context-systems".
// Build an entity_property_map for just the CamerasParts, where we would expect to find
// the image_depth_plane_distance property.
let entity_prop_map: EntityPropertyMap = query
.per_visualizer_data_results
.get(&CamerasVisualizer::identifier())
.map(|results| {
results
.iter()
.map(|r| (r.entity_path.clone(), r.accumulated_properties().clone()))
.collect()
})
.unwrap_or_default();

self.space_origin = query.space_origin.clone();

// Find the entity path tree for the root.
Expand All @@ -136,7 +121,6 @@ impl ViewContextSystem for TransformContext {
current_tree,
ctx.recording(),
&time_query,
&entity_prop_map,
glam::Affine3A::IDENTITY,
&None, // Ignore potential pinhole camera at the root of the space view, since it regarded as being "above" this root.
);
Expand Down Expand Up @@ -185,7 +169,6 @@ impl ViewContextSystem for TransformContext {
parent_tree,
ctx.recording(),
&time_query,
&entity_prop_map,
reference_from_ancestor,
&encountered_pinhole,
);
Expand All @@ -209,7 +192,6 @@ impl TransformContext {
subtree: &EntityTree,
entity_db: &EntityDb,
query: &LatestAtQuery,
entity_properties: &EntityPropertyMap,
reference_from_entity: glam::Affine3A,
encountered_pinhole: &Option<EntityPath>,
) {
Expand All @@ -227,49 +209,50 @@ impl TransformContext {

for child_tree in subtree.children.values() {
let mut encountered_pinhole = encountered_pinhole.clone();

let lookup_image_plane = |p: &_| {
let resolver = ctx.recording().resolver();

let query_result = ctx.lookup_query_result(view_query.space_view_id);

query_result
.tree
.lookup_result_by_path(p)
.cloned()
.and_then(|data_result| {
let results = latest_at_with_overrides(
ctx,
None,
query,
&data_result,
[ImagePlaneDistance::name()],
);

results
.get_or_empty(ImagePlaneDistance::name())
.to_dense::<ImagePlaneDistance>(resolver)
.flatten()
.ok()
.and_then(|r| r.first().copied())
.or_else(|| {
data_result.typed_fallback_for(
ctx,
self,
Some(Pinhole::name()),
view_state,
)
})
})
.unwrap_or_default()
.0
.0
};

let reference_from_child = match transform_at(
child_tree,
entity_db,
query,
|p| {
// TODO(jleibs): Make this way less painful
let resolver = ctx.recording().resolver();

let query_result = ctx.lookup_query_result(view_query.space_view_id);

query_result
.tree
.lookup_result_by_path(p)
.cloned()
.map(|data_result| {
let results = latest_at_with_overrides(
ctx,
None,
query,
&data_result,
[ImagePlaneDistance::name()],
);

let image_plane_distance = results
.get_or_empty(ImagePlaneDistance::name())
.to_dense::<ImagePlaneDistance>(resolver)
.flatten()
.ok()
.and_then(|r| r.first().copied())
.unwrap_or_else(|| {
data_result
.typed_fallback_for(
ctx,
self,
Some(Pinhole::name()),
view_state,
)
.unwrap_or_default()
});
});

0.0
},
lookup_image_plane,
&mut encountered_pinhole,
) {
Err(unreachable_reason) => {
Expand All @@ -287,7 +270,6 @@ impl TransformContext {
child_tree,
entity_db,
query,
entity_properties,
reference_from_child,
&encountered_pinhole,
);
Expand Down
2 changes: 2 additions & 0 deletions crates/re_space_view_tensor/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,3 +756,5 @@ fn selectors_ui(ui: &mut egui::Ui, state: &mut ViewTensorState, tensor: &TensorD
}
}
}

re_viewer_context::impl_component_fallback_provider!(TensorSpaceView => []);
2 changes: 2 additions & 0 deletions crates/re_space_view_text_document/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,5 @@ impl SpaceViewClass for TextDocumentSpaceView {
Ok(())
}
}

re_viewer_context::impl_component_fallback_provider!(TextDocumentSpaceView => []);
Loading

0 comments on commit c1578dc

Please sign in to comment.