use re_viewer_context::{
ApplicableEntities, IdentifiedViewSystem, RecommendedSpaceView, SpaceViewClass,
SpaceViewSpawnHeuristics, ViewerContext, VisualizerSystem,
};
pub fn suggest_space_view_for_each_entity<TVisualizer>(
ctx: &ViewerContext<'_>,
space_view: &impl SpaceViewClass,
) -> SpaceViewSpawnHeuristics
where
TVisualizer: VisualizerSystem + IdentifiedViewSystem + Default,
{
re_tracing::profile_function!();
let Some(indicator_matching_entities) = ctx
.indicated_entities_per_visualizer
.get(&TVisualizer::identifier())
else {
return Default::default();
};
let Some(applicable_entities) = ctx
.applicable_entities_per_visualizer
.get(&TVisualizer::identifier())
else {
return Default::default();
};
let visualizer = TVisualizer::default();
let recommended_space_views = applicable_entities
.intersection(indicator_matching_entities)
.filter_map(|entity| {
let context = space_view.visualizable_filter_context(entity, ctx.recording());
if visualizer
.filter_visualizable_entities(
ApplicableEntities(std::iter::once(entity.clone()).collect()),
context.as_ref(),
)
.is_empty()
{
None
} else {
Some(RecommendedSpaceView::new_single_entity(entity.clone()))
}
});
re_viewer_context::SpaceViewSpawnHeuristics::new(recommended_space_views)
}