Skip to content

Commit ea63a88

Browse files
authored
Fix group selection/hover with data queries (#4643)
### What - Resolves: #4377 Restores the behavior of group hover/selection using the cached data query result. Also removes some deprecated TODOs. ### 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 newly built examples: [app.rerun.io](https://app.rerun.io/pr/4643/index.html) * Using examples from latest `main` build: [app.rerun.io](https://app.rerun.io/pr/4643/index.html?manifest_url=https://app.rerun.io/version/main/examples_manifest.json) * Using full set of examples from `nightly` build: [app.rerun.io](https://app.rerun.io/pr/4643/index.html?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 - [PR Build Summary](https://build.rerun.io/pr/4643) - [Docs preview](https://rerun.io/preview/cfc9311cc36a57c15ac46eede644d60e67b5d050/docs) <!--DOCS-PREVIEW--> - [Examples preview](https://rerun.io/preview/cfc9311cc36a57c15ac46eede644d60e67b5d050/examples) <!--EXAMPLES-PREVIEW--> - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
1 parent b0493de commit ea63a88

File tree

6 files changed

+49
-53
lines changed

6 files changed

+49
-53
lines changed

crates/re_viewer_context/src/query_context.rs

+11
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,17 @@ impl DataResultTree {
150150
}
151151
}
152152

153+
/// Depth-first traversal of a subtree, starting with the given group entity-path, calling `visitor` on each result.
154+
pub fn visit_group(
155+
&self,
156+
entity_path: &EntityPath,
157+
visitor: &mut impl FnMut(DataResultHandle),
158+
) {
159+
if let Some(subtree_handle) = self.data_results_by_path.get(&(entity_path.clone(), true)) {
160+
self.visit_recursive(*subtree_handle, visitor);
161+
}
162+
}
163+
153164
/// Look up a [`DataResult`] in the tree based on its handle.
154165
pub fn lookup_result(&self, handle: DataResultHandle) -> Option<&DataResult> {
155166
self.data_results.get(handle).map(|node| &node.data_result)

crates/re_viewport/src/space_view.rs

-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ impl SpaceViewBlueprint {
251251

252252
let query_result = ctx.lookup_query_result(self.query_id()).clone();
253253

254-
// TODO(#4377): Use PerSystemDataResults
255254
let mut per_system_entities = PerSystemEntities::default();
256255
{
257256
re_tracing::profile_scope!("per_system_data_results");

crates/re_viewport/src/space_view_heuristics.rs

-3
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ pub fn all_possible_space_views(
8080
let mut entity_path_filter = EntityPathFilter::default();
8181
entity_path_filter.add_subtree(candidate_space_path.clone());
8282

83-
// TODO(#4377): The need to run a query-per-candidate for all possible candidates
84-
// is way too expensive. This needs to be optimized significantly.
8583
let candidate_query =
8684
DataQueryBlueprint::new(class_identifier, entity_path_filter);
8785

@@ -217,7 +215,6 @@ pub fn default_created_space_views(
217215
// Main pass through all candidates.
218216
// We first check if a candidate is "interesting" and then split it up/modify it further if required.
219217
for (candidate, query_result) in candidates {
220-
// TODO(#4377): Can spawn heuristics consume the query_result directly?
221218
let mut per_system_entities = PerSystemEntities::default();
222219
{
223220
re_tracing::profile_scope!("per_system_data_results");

crates/re_viewport/src/space_view_highlights.rs

+36-42
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
use std::collections::BTreeMap;
2-
31
use egui::NumExt;
42
use nohash_hasher::IntMap;
53

64
use re_log_types::EntityPathHash;
75
use re_renderer::OutlineMaskPreference;
86
use re_viewer_context::{
9-
ApplicationSelectionState, HoverHighlight, Item, SelectionHighlight, SpaceViewEntityHighlight,
10-
SpaceViewHighlights, SpaceViewId, SpaceViewOutlineMasks,
7+
HoverHighlight, Item, SelectionHighlight, SpaceViewEntityHighlight, SpaceViewHighlights,
8+
SpaceViewId, SpaceViewOutlineMasks,
119
};
1210

13-
use crate::SpaceViewBlueprint;
14-
1511
pub fn highlights_for_space_view(
16-
selection_state: &ApplicationSelectionState,
12+
ctx: &re_viewer_context::ViewerContext<'_>,
1713
space_view_id: SpaceViewId,
18-
_space_views: &BTreeMap<SpaceViewId, SpaceViewBlueprint>,
1914
) -> SpaceViewHighlights {
2015
re_tracing::profile_function!();
2116

@@ -36,36 +31,36 @@ pub fn highlights_for_space_view(
3631
OutlineMaskPreference::some(hover_mask_index, 0)
3732
};
3833

39-
for current_selection in selection_state.current().iter_items() {
34+
for current_selection in ctx.selection_state().current().iter_items() {
4035
match current_selection {
4136
Item::ComponentPath(_) | Item::SpaceView(_) | Item::Container(_) => {}
4237

43-
Item::DataBlueprintGroup(_space_view_id, _query_id, _entity_path) => {
44-
// TODO(#4377): Fix DataBlueprintGroup
45-
/*
38+
Item::DataBlueprintGroup(group_space_view_id, query_id, group_entity_path) => {
39+
// Unlike for selected objects/data we are more picky for data blueprints with our hover highlights
40+
// since they are truly local to a space view.
4641
if *group_space_view_id == space_view_id {
47-
if let Some(space_view) = space_views.get(group_space_view_id) {
48-
// Everything in the same group should receive the same selection outline.
49-
// (Due to the way outline masks work in re_renderer, we can't leave the hover channel empty)
50-
let selection_mask = next_selection_mask();
51-
52-
space_view.contents.visit_group_entities_recursively(
53-
*group_handle,
54-
&mut |entity_path: &EntityPath| {
42+
// Everything in the same group should receive the same selection outline.
43+
// (Due to the way outline masks work in re_renderer, we can't leave the hover channel empty)
44+
let selection_mask = next_selection_mask();
45+
46+
let query_result = ctx.lookup_query_result(*query_id).clone();
47+
48+
query_result
49+
.tree
50+
.visit_group(group_entity_path, &mut |handle| {
51+
if let Some(result) = query_result.tree.lookup_result(handle) {
5552
highlighted_entity_paths
56-
.entry(entity_path.hash())
53+
.entry(result.entity_path.hash())
5754
.or_default()
5855
.overall
5956
.selection = SelectionHighlight::SiblingSelection;
6057
let outline_mask_ids =
61-
outlines_masks.entry(entity_path.hash()).or_default();
58+
outlines_masks.entry(result.entity_path.hash()).or_default();
6259
outline_mask_ids.overall =
6360
selection_mask.with_fallback_to(outline_mask_ids.overall);
64-
},
65-
);
66-
}
61+
}
62+
});
6763
}
68-
*/
6964
}
7065

7166
Item::InstancePath(selected_space_view_context, selected_instance) => {
@@ -113,35 +108,34 @@ pub fn highlights_for_space_view(
113108
};
114109
}
115110

116-
for current_hover in selection_state.hovered().iter_items() {
111+
for current_hover in ctx.selection_state().hovered().iter_items() {
117112
match current_hover {
118113
Item::ComponentPath(_) | Item::SpaceView(_) | Item::Container(_) => {}
119114

120-
Item::DataBlueprintGroup(_space_view_id, _query_id, _entity_path) => {
121-
// TODO(#4377): Fix DataBlueprintGroup
122-
/*
115+
Item::DataBlueprintGroup(group_space_view_id, query_id, group_entity_path) => {
123116
// Unlike for selected objects/data we are more picky for data blueprints with our hover highlights
124117
// since they are truly local to a space view.
125118
if *group_space_view_id == space_view_id {
126-
if let Some(space_view) = space_views.get(group_space_view_id) {
127-
// Everything in the same group should receive the same selection outline.
128-
let hover_mask = next_hover_mask();
119+
// Everything in the same group should receive the same hover outline.
120+
let hover_mask = next_hover_mask();
121+
122+
let query_result = ctx.lookup_query_result(*query_id).clone();
129123

130-
space_view.contents.visit_group_entities_recursively(
131-
*group_handle,
132-
&mut |entity_path: &EntityPath| {
124+
query_result
125+
.tree
126+
.visit_group(group_entity_path, &mut |handle| {
127+
if let Some(result) = query_result.tree.lookup_result(handle) {
133128
highlighted_entity_paths
134-
.entry(entity_path.hash())
129+
.entry(result.entity_path.hash())
135130
.or_default()
136131
.overall
137132
.hover = HoverHighlight::Hovered;
138-
let mask = outlines_masks.entry(entity_path.hash()).or_default();
133+
let mask =
134+
outlines_masks.entry(result.entity_path.hash()).or_default();
139135
mask.overall = hover_mask.with_fallback_to(mask.overall);
140-
},
141-
);
142-
}
136+
}
137+
});
143138
}
144-
*/
145139
}
146140

147141
Item::InstancePath(_, selected_instance) => {

crates/re_viewport/src/system_execution.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ pub fn execute_systems_for_space_views<'a>(
7373
.par_drain(..)
7474
.filter_map(|space_view_id| {
7575
let space_view_blueprint = space_views.get(&space_view_id)?;
76-
let highlights =
77-
highlights_for_space_view(ctx.selection_state(), space_view_id, space_views);
76+
let highlights = highlights_for_space_view(ctx, space_view_id);
7877
let output = space_view_blueprint.execute_systems(ctx, time_int, highlights);
7978
Some((space_view_id, output))
8079
})

crates/re_viewport/src/viewport.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -495,11 +495,7 @@ impl<'a, 'b> egui_tiles::Behavior<SpaceViewId> for TabViewer<'a, 'b> {
495495
if let Some(result) = self.executed_systems_per_space_view.remove(space_view_id) {
496496
result
497497
} else {
498-
let highlights = highlights_for_space_view(
499-
self.ctx.selection_state(),
500-
*space_view_id,
501-
self.space_views,
502-
);
498+
let highlights = highlights_for_space_view(self.ctx, *space_view_id);
503499
space_view_blueprint.execute_systems(self.ctx, latest_at, highlights)
504500
};
505501

0 commit comments

Comments
 (0)