use re_viewer_context::{
ApplicableEntities, IdentifiedViewSystem, RecommendedView, ViewClass, ViewSpawnHeuristics,
ViewerContext, VisualizerSystem,
};
pub fn suggest_view_for_each_entity<TVisualizer>(
ctx: &ViewerContext<'_>,
view: &impl ViewClass,
) -> ViewSpawnHeuristics
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_views = applicable_entities
.intersection(indicator_matching_entities)
.filter_map(|entity| {
let context = 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(RecommendedView::new_single_entity(entity.clone()))
}
});
re_viewer_context::ViewSpawnHeuristics::new(recommended_views)
}