use re_log_types::EntityPathHash;
use re_viewer_context::SystemExecutionOutput;
use super::UiLabel;
use crate::PickableTexturedRect;
use crate::SpaceKind;
use crate::visualizers::LoadingIndicator;
#[derive(Clone, Copy, Debug)]
pub struct SpatialViewBoundingBox {
pub entity_path_hash: EntityPathHash,
pub bounding_box: macaw::BoundingBox,
pub subspace: SpaceKind,
}
#[derive(Default)]
pub struct SpatialViewVisualizerData {
pub loading_indicators: Vec<LoadingIndicator>,
pub ui_labels: Vec<UiLabel>,
bounding_boxes: Vec<SpatialViewBoundingBox>,
regions_of_interest: Vec<SpatialViewBoundingBox>,
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_bounding_box(entity, 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_bounding_box(entity, bbox, world_from_obj, SpaceKind::TwoD);
}
fn add_bounding_box(
&mut self,
entity: EntityPathHash,
bbox: macaw::BoundingBox,
world_from_obj: glam::Affine3A,
subspace: SpaceKind,
) {
let transformed = bbox.transform_affine3(&world_from_obj);
self.bounding_boxes.push(SpatialViewBoundingBox {
entity_path_hash: entity,
bounding_box: transformed,
subspace,
});
self.regions_of_interest.push(SpatialViewBoundingBox {
entity_path_hash: entity,
bounding_box: transformed,
subspace,
});
}
pub fn add_bounding_box_and_region_of_interest(
&mut self,
entity: EntityPathHash,
bbox: macaw::BoundingBox,
region_of_interest: macaw::BoundingBox,
world_from_obj: glam::Affine3A,
subspace: SpaceKind,
) {
self.bounding_boxes.push(SpatialViewBoundingBox {
entity_path_hash: entity,
bounding_box: bbox.transform_affine3(&world_from_obj),
subspace,
});
self.regions_of_interest.push(SpatialViewBoundingBox {
entity_path_hash: entity,
bounding_box: region_of_interest.transform_affine3(&world_from_obj),
subspace,
});
}
pub fn add_pickable_rect_to_bounding_box(
&mut self,
pickable_rect: &PickableTexturedRect,
subspace: SpaceKind,
) {
let entity_path_hash = pickable_rect.ent_path.hash();
let bounding_box = pickable_rect.textured_rect.bounding_box();
self.bounding_boxes.push(SpatialViewBoundingBox {
entity_path_hash,
bounding_box,
subspace,
});
self.regions_of_interest.push(SpatialViewBoundingBox {
entity_path_hash,
bounding_box,
subspace,
});
}
pub fn iter_bounding_boxes(&self) -> impl ExactSizeIterator<Item = &SpatialViewBoundingBox> {
self.bounding_boxes.iter()
}
pub fn iter_regions_of_interest(
&self,
) -> impl ExactSizeIterator<Item = &SpatialViewBoundingBox> {
self.regions_of_interest.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>()
})
}