use re_log_types::EntityPathHash;
use re_renderer::RobustBounds;
use re_viewer_context::SystemExecutionOutput;
use super::UiLabel;
use crate::PickableTexturedRect;
use crate::SpaceKind;
use crate::visualizers::LoadingIndicator;
#[derive(Clone, Copy, Debug)]
pub struct SpatialViewBounds {
pub entity_path_hash: EntityPathHash,
pub bounds: RobustBounds,
pub subspace: SpaceKind,
}
#[derive(Default)]
pub struct SpatialViewVisualizerData {
pub loading_indicators: Vec<LoadingIndicator>,
pub ui_labels: Vec<UiLabel>,
bounds: Vec<SpatialViewBounds>,
pub pickable_rects: Vec<PickableTexturedRect>,
}
impl SpatialViewVisualizerData {
pub fn add_pickable_rect(&mut self, pickable_rect: PickableTexturedRect, subspace: SpaceKind) {
self.add_pickable_rect_to_bounding_box(&pickable_rect, subspace);
self.pickable_rects.push(pickable_rect);
}
pub fn add_bounding_box_3d(
&mut self,
entity: EntityPathHash,
bbox: macaw::BoundingBox,
world_from_obj: glam::Affine3A,
) {
self.add_bounds(
entity,
RobustBounds::from_bbox(bbox),
world_from_obj,
SpaceKind::ThreeD,
);
}
pub fn add_bounding_box_2d(
&mut self,
entity: EntityPathHash,
bbox: macaw::BoundingBox,
world_from_obj: glam::Affine3A,
) {
self.add_bounds(
entity,
RobustBounds::from_bbox(bbox),
world_from_obj,
SpaceKind::TwoD,
);
}
pub fn add_bounds(
&mut self,
entity: EntityPathHash,
bounds: RobustBounds,
world_from_obj: glam::Affine3A,
subspace: SpaceKind,
) {
self.bounds.push(SpatialViewBounds {
entity_path_hash: entity,
bounds: bounds.transform_affine3(&world_from_obj),
subspace,
});
}
pub fn add_pickable_rect_to_bounding_box(
&mut self,
pickable_rect: &PickableTexturedRect,
subspace: SpaceKind,
) {
self.bounds.push(SpatialViewBounds {
entity_path_hash: pickable_rect.ent_path.hash(),
bounds: RobustBounds::from_bbox(pickable_rect.textured_rect.bounding_box()),
subspace,
});
}
pub fn iter_bounds(&self) -> impl ExactSizeIterator<Item = &SpatialViewBounds> {
self.bounds.iter()
}
}
pub fn iter_spatial_data(
system_output: &SystemExecutionOutput,
) -> impl Iterator<Item = &SpatialViewVisualizerData> {
system_output
.visualizer_execution_output
.per_visualizer
.values()
.filter_map(|result| {
let output = result.as_ref().ok()?;
output.get_visualizer_data::<SpatialViewVisualizerData>()
})
}