Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Space view scenes (parts) are now independent of space view type #2522

Closed
wants to merge 8 commits into from
19 changes: 11 additions & 8 deletions crates/re_data_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use itertools::Itertools;
use re_log_types::{DataCell, EntityPath, PathOp, TimePoint};
use re_viewer_context::{UiVerbosity, ViewerContext};
use re_viewer_context::{SpaceViewHighlights, UiVerbosity, ViewerContext};

mod annotation_context;
mod component;
Expand Down Expand Up @@ -158,13 +158,16 @@ pub fn annotations(
let mut annotation_map = re_viewer_context::AnnotationMap::default();
let entity_paths: nohash_hasher::IntSet<_> = std::iter::once(entity_path.clone()).collect();
let entity_props_map = re_data_store::EntityPropertyMap::default();
let scene_query = re_viewer_context::SceneQuery::new(
entity_path,
&entity_paths,
query.timeline,
query.at,
&entity_props_map,
);
let highlights = SpaceViewHighlights::default();
let scene_query = re_viewer_context::SceneQuery {
space_origin: entity_path,
entity_paths: &entity_paths,
timeline: query.timeline,
latest_at: query.at,
entity_props_map: &entity_props_map,
highlights: &highlights,
};

annotation_map.load(ctx, &scene_query);
annotation_map.find(entity_path)
}
23 changes: 16 additions & 7 deletions crates/re_space_view_bar_chart/src/scene_part.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,29 @@ use re_components::Tensor;
use re_data_store::EntityPath;
use re_log_types::Component as _;
use re_viewer_context::{
ArchetypeDefinition, ScenePart, SceneQuery, SpaceViewClass, SpaceViewHighlights, ViewerContext,
ArchetypeDefinition, ScenePart, ScenePartCollection, SceneQuery, ViewerContext,
};

use crate::BarChartSpaceView;

/// A bar chart scene, with everything needed to render it.
#[derive(Default)]
pub struct SceneBarChart {
pub charts: BTreeMap<EntityPath, Tensor>,
}

impl ScenePart<BarChartSpaceView> for SceneBarChart {
impl ScenePartCollection for SceneBarChart {
type Context = ();
type ScenePartData = ();

fn vec_mut(&mut self) -> Vec<&mut dyn ScenePart<Self>> {
vec![self]
}

fn as_any(&self) -> &dyn std::any::Any {
self
}
}

impl ScenePart<SceneBarChart> for SceneBarChart {
fn archetype(&self) -> ArchetypeDefinition {
vec1::vec1![Tensor::name()]
}
Expand All @@ -25,9 +36,7 @@ impl ScenePart<BarChartSpaceView> for SceneBarChart {
&mut self,
ctx: &mut ViewerContext<'_>,
query: &SceneQuery<'_>,
_state: &<BarChartSpaceView as SpaceViewClass>::State,
_scene_context: &<BarChartSpaceView as SpaceViewClass>::Context,
_highlights: &SpaceViewHighlights,
_scene_context: &(),
) -> Vec<re_renderer::QueueableDrawData> {
re_tracing::profile_function!();

Expand Down
12 changes: 6 additions & 6 deletions crates/re_space_view_bar_chart/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use re_components::TensorData;
use re_log_types::EntityPath;
use re_space_view::controls;
use re_viewer_context::{
auto_color, SpaceViewClass, SpaceViewClassName, SpaceViewId, TypedScene, ViewerContext,
auto_color, SceneQuery, SpaceViewClass, SpaceViewClassName, SpaceViewFrame, SpaceViewId,
ViewerContext,
};

use super::scene_part::SceneBarChart;
Expand All @@ -13,9 +14,7 @@ pub struct BarChartSpaceView;

impl SpaceViewClass for BarChartSpaceView {
type State = ();
type Context = ();
type SceneParts = SceneBarChart;
type ScenePartData = ();

fn name(&self) -> SpaceViewClassName {
"Bar Chart".into()
Expand Down Expand Up @@ -69,8 +68,9 @@ impl SpaceViewClass for BarChartSpaceView {
_ctx: &mut ViewerContext<'_>,
ui: &mut egui::Ui,
_state: &mut Self::State,
scene: &mut TypedScene<Self>,
_space_origin: &EntityPath,
frame: &mut SpaceViewFrame<Self>,
_query: SceneQuery<'_>,
_draw_data: Vec<re_renderer::QueueableDrawData>,
_space_view_id: SpaceViewId,
) {
use egui::plot::{Bar, BarChart, Legend, Plot};
Expand Down Expand Up @@ -102,7 +102,7 @@ impl SpaceViewClass for BarChartSpaceView {
.color(color)
}

for (ent_path, tensor) in &scene.parts.charts {
for (ent_path, tensor) in &frame.parts.charts {
let chart = match &tensor.data {
TensorData::U8(data) => {
create_bar_chart(ent_path, data.iter().copied())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ impl SceneContextPart for AnnotationSceneContext {
&mut self,
ctx: &mut re_viewer_context::ViewerContext<'_>,
query: &re_viewer_context::SceneQuery<'_>,
_space_view_state: &dyn re_viewer_context::SpaceViewState,
) {
self.0.load(ctx, query);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ impl SceneContextPart for EntityDepthOffsets {
&mut self,
ctx: &mut re_viewer_context::ViewerContext<'_>,
query: &re_viewer_context::SceneQuery<'_>,
_space_view_state: &dyn re_viewer_context::SpaceViewState,
) {
re_tracing::profile_function!();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ impl SceneContextPart for NonInteractiveEntities {
&mut self,
_ctx: &mut re_viewer_context::ViewerContext<'_>,
query: &re_viewer_context::SceneQuery<'_>,
_space_view_state: &dyn re_viewer_context::SpaceViewState,
) {
re_tracing::profile_function!();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ impl SceneContextPart for SharedRenderBuilders {
&mut self,
ctx: &mut re_viewer_context::ViewerContext<'_>,
_query: &re_viewer_context::SceneQuery<'_>,
_space_view_state: &dyn re_viewer_context::SpaceViewState,
) {
self.lines = Some(Mutex::new(
LineStripSeriesBuilder::new(ctx.render_ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ impl SceneContextPart for TransformContext {
&mut self,
ctx: &mut re_viewer_context::ViewerContext<'_>,
scene_query: &re_viewer_context::SceneQuery<'_>,
_space_view_state: &dyn re_viewer_context::SpaceViewState,
) {
re_tracing::profile_function!();

Expand Down
4 changes: 2 additions & 2 deletions crates/re_space_view_spatial/src/scene/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ahash::HashMap;
use re_components::{ClassId, InstanceKey, KeypointId};
use re_data_store::{EntityPath, InstancePathHash};
use re_renderer::{Color32, Size};
use re_viewer_context::{auto_color, TypedScene};
use re_viewer_context::{auto_color, SpaceViewFrame};

use crate::{ui::SpatialNavigationMode, SpatialSpaceView};

Expand Down Expand Up @@ -45,7 +45,7 @@ pub struct UiLabel {
}

/// Type alias for spatial scenes.
pub type SceneSpatial = TypedScene<SpatialSpaceView>;
pub type SceneSpatial = SpaceViewFrame<SpatialSpaceView>;

/// Collection of keypoints for annotation context.
pub type Keypoints = HashMap<(ClassId, i64), HashMap<KeypointId, glam::Vec3>>;
Expand Down
20 changes: 6 additions & 14 deletions crates/re_space_view_spatial/src/scene/parts/arrows3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@ use re_components::{Arrow3D, ColorRGBA, Component as _, InstanceKey, Label, Radi
use re_data_store::EntityPath;
use re_query::{EntityView, QueryError};
use re_renderer::{renderer::LineStripFlags, Size};
use re_viewer_context::{
ArchetypeDefinition, DefaultColor, ScenePart, SceneQuery, SpaceViewHighlights, ViewerContext,
};
use re_viewer_context::{ArchetypeDefinition, DefaultColor, ScenePart, SceneQuery, ViewerContext};

use super::{picking_id_from_instance_key, SpatialScenePartData, SpatialSpaceViewState};
use crate::{
scene::{
contexts::{SpatialSceneContext, SpatialSceneEntityContext},
parts::entity_iterator::process_entity_views,
},
SpatialSpaceView,
use super::{picking_id_from_instance_key, SpatialScenePartCollection, SpatialScenePartData};
use crate::scene::{
contexts::{SpatialSceneContext, SpatialSceneEntityContext},
parts::entity_iterator::process_entity_views,
};

#[derive(Default)]
Expand Down Expand Up @@ -89,7 +84,7 @@ impl Arrows3DPart {
}
}

impl ScenePart<SpatialSpaceView> for Arrows3DPart {
impl ScenePart<SpatialScenePartCollection> for Arrows3DPart {
fn archetype(&self) -> ArchetypeDefinition {
vec1::vec1![
Arrow3D::name(),
Expand All @@ -104,17 +99,14 @@ impl ScenePart<SpatialSpaceView> for Arrows3DPart {
&mut self,
ctx: &mut ViewerContext<'_>,
query: &SceneQuery<'_>,
_space_view_state: &SpatialSpaceViewState,
scene_context: &SpatialSceneContext,
highlights: &SpaceViewHighlights,
) -> Vec<re_renderer::QueueableDrawData> {
re_tracing::profile_scope!("Arrows3DPart");

process_entity_views::<Arrow3D, 5, _>(
ctx,
query,
scene_context,
highlights,
scene_context.depth_offsets.points,
self.archetype(),
|_ctx, ent_path, entity_view, ent_context| {
Expand Down
22 changes: 7 additions & 15 deletions crates/re_space_view_spatial/src/scene/parts/boxes2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@ use re_components::{ClassId, ColorRGBA, Component as _, InstanceKey, Label, Radi
use re_data_store::EntityPath;
use re_query::{EntityView, QueryError};
use re_renderer::Size;
use re_viewer_context::{
ArchetypeDefinition, DefaultColor, ScenePart, SceneQuery, SpaceViewHighlights, ViewerContext,
};
use re_viewer_context::{ArchetypeDefinition, DefaultColor, ScenePart, SceneQuery, ViewerContext};

use crate::{
scene::{
contexts::{SpatialSceneContext, SpatialSceneEntityContext},
parts::entity_iterator::process_entity_views,
UiLabel, UiLabelTarget,
},
SpatialSpaceView,
use crate::scene::{
contexts::{SpatialSceneContext, SpatialSceneEntityContext},
parts::entity_iterator::process_entity_views,
UiLabel, UiLabelTarget,
};

use super::{picking_id_from_instance_key, SpatialScenePartData, SpatialSpaceViewState};
use super::{picking_id_from_instance_key, SpatialScenePartCollection, SpatialScenePartData};

#[derive(Default)]
pub struct Boxes2DPart(SpatialScenePartData);
Expand Down Expand Up @@ -101,7 +96,7 @@ impl Boxes2DPart {
}
}

impl ScenePart<SpatialSpaceView> for Boxes2DPart {
impl ScenePart<SpatialScenePartCollection> for Boxes2DPart {
fn archetype(&self) -> ArchetypeDefinition {
vec1::vec1![
Rect2D::name(),
Expand All @@ -117,17 +112,14 @@ impl ScenePart<SpatialSpaceView> for Boxes2DPart {
&mut self,
ctx: &mut ViewerContext<'_>,
query: &SceneQuery<'_>,
_space_view_state: &SpatialSpaceViewState,
scene_context: &SpatialSceneContext,
highlights: &SpaceViewHighlights,
) -> Vec<re_renderer::QueueableDrawData> {
re_tracing::profile_scope!("Boxes2DPart");

process_entity_views::<Rect2D, 6, _>(
ctx,
query,
scene_context,
highlights,
scene_context.depth_offsets.points,
self.archetype(),
|_ctx, ent_path, entity_view, ent_context| {
Expand Down
22 changes: 7 additions & 15 deletions crates/re_space_view_spatial/src/scene/parts/boxes3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@ use re_components::{
use re_data_store::EntityPath;
use re_query::{EntityView, QueryError};
use re_renderer::Size;
use re_viewer_context::{
ArchetypeDefinition, DefaultColor, ScenePart, SceneQuery, SpaceViewHighlights, ViewerContext,
};
use re_viewer_context::{ArchetypeDefinition, DefaultColor, ScenePart, SceneQuery, ViewerContext};

use crate::{
scene::{
contexts::{SpatialSceneContext, SpatialSceneEntityContext},
parts::entity_iterator::process_entity_views,
UiLabel, UiLabelTarget,
},
SpatialSpaceView,
use crate::scene::{
contexts::{SpatialSceneContext, SpatialSceneEntityContext},
parts::entity_iterator::process_entity_views,
UiLabel, UiLabelTarget,
};

use super::{picking_id_from_instance_key, SpatialScenePartData, SpatialSpaceViewState};
use super::{picking_id_from_instance_key, SpatialScenePartCollection, SpatialScenePartData};

#[derive(Default)]
pub struct Boxes3DPart(SpatialScenePartData);
Expand Down Expand Up @@ -98,7 +93,7 @@ impl Boxes3DPart {
}
}

impl ScenePart<SpatialSpaceView> for Boxes3DPart {
impl ScenePart<SpatialScenePartCollection> for Boxes3DPart {
fn archetype(&self) -> ArchetypeDefinition {
vec1::vec1![
Box3D::name(),
Expand All @@ -116,17 +111,14 @@ impl ScenePart<SpatialSpaceView> for Boxes3DPart {
&mut self,
ctx: &mut ViewerContext<'_>,
query: &SceneQuery<'_>,
_space_view_state: &SpatialSpaceViewState,
scene_context: &SpatialSceneContext,
highlights: &SpaceViewHighlights,
) -> Vec<re_renderer::QueueableDrawData> {
re_tracing::profile_scope!("Boxes3DPart");

process_entity_views::<Box3D, 8, _>(
ctx,
query,
scene_context,
highlights,
scene_context.depth_offsets.points,
self.archetype(),
|_ctx, ent_path, entity_view, ent_context| {
Expand Down
Loading