re_view/
annotation_scene_context.rs

1use std::sync::Arc;
2
3use re_viewer_context::{
4    AnnotationMap, IdentifiedViewSystem, ViewContextSystem, ViewContextSystemStaticExecResult,
5    ViewSystemIdentifier,
6};
7
8#[derive(Default)]
9pub struct AnnotationSceneContext(pub Arc<AnnotationMap>);
10
11impl IdentifiedViewSystem for AnnotationSceneContext {
12    fn identifier() -> ViewSystemIdentifier {
13        "AnnotationSceneContext".into()
14    }
15}
16
17impl ViewContextSystem for AnnotationSceneContext {
18    fn execute_static(
19        ctx: &re_viewer_context::ViewerContext<'_>,
20    ) -> ViewContextSystemStaticExecResult {
21        // Use static execution to load the annotation map for all entities.
22        // Alternatively, we could do this only for visible ones per View but this is actually a lot more expensive to do
23        // given that there's typically just one annotation map per recording anyways!
24        let mut annotation_map = AnnotationMap::default();
25        annotation_map.load(ctx, &ctx.current_query());
26
27        Box::new(Self(Arc::new(annotation_map)))
28    }
29
30    fn execute(
31        &mut self,
32        _ctx: &re_viewer_context::ViewContext<'_>,
33        _query: &re_viewer_context::ViewQuery<'_>,
34        static_execution_result: &ViewContextSystemStaticExecResult,
35    ) {
36        // Take over the static result to make it available.
37        self.0 = static_execution_result
38            .downcast_ref::<Self>()
39            .expect("Unexpected static execution result type")
40            .0
41            .clone();
42    }
43
44    fn as_any(&self) -> &dyn std::any::Any {
45        self
46    }
47}