use re_arrow_store::LatestAtQuery;
use re_log_types::{
external::arrow2_convert::deserialize::arrow_array_deserialize_iterator, msg_bundle::Component,
EntityPath, Transform,
};
use crate::log_db::EntityDb;
#[derive(Clone, Default)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct EntityPropertyMap {
props: nohash_hasher::IntMap<EntityPath, EntityProperties>,
}
impl EntityPropertyMap {
pub fn get(&self, entity_path: &EntityPath) -> EntityProperties {
self.props.get(entity_path).cloned().unwrap_or_default()
}
pub fn set(&mut self, entity_path: EntityPath, prop: EntityProperties) {
if prop == EntityProperties::default() {
self.props.remove(&entity_path); } else {
self.props.insert(entity_path, prop);
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "serde", serde(default))]
pub struct EntityProperties {
pub visible: bool,
pub visible_history: ExtraQueryHistory,
pub interactive: bool,
pinhole_image_plane_distance: Option<ordered_float::NotNan<f32>>,
}
impl EntityProperties {
pub fn pinhole_image_plane_distance(&self, pinhole: &re_log_types::Pinhole) -> f32 {
self.pinhole_image_plane_distance
.unwrap_or_else(|| {
let distance = pinhole
.focal_length()
.unwrap_or_else(|| pinhole.focal_length_in_pixels().y());
ordered_float::NotNan::new(distance).unwrap_or_default()
})
.into()
}
pub fn set_pinhole_image_plane_distance(&mut self, distance: f32) {
self.pinhole_image_plane_distance = ordered_float::NotNan::new(distance).ok();
}
pub fn with_child(&self, child: &Self) -> Self {
Self {
visible: self.visible && child.visible,
visible_history: self.visible_history.with_child(&child.visible_history),
interactive: self.interactive && child.interactive,
pinhole_image_plane_distance: child
.pinhole_image_plane_distance
.or(self.pinhole_image_plane_distance),
}
}
}
impl Default for EntityProperties {
fn default() -> Self {
Self {
visible: true,
visible_history: ExtraQueryHistory::default(),
interactive: true,
pinhole_image_plane_distance: None,
}
}
}
#[derive(Clone, Copy, Default, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "serde", serde(default))]
pub struct ExtraQueryHistory {
pub nanos: i64,
pub sequences: i64,
}
impl ExtraQueryHistory {
fn with_child(&self, child: &Self) -> Self {
Self {
nanos: self.nanos.max(child.nanos),
sequences: self.sequences.max(child.sequences),
}
}
}
pub fn query_transform(
entity_db: &EntityDb,
entity_path: &EntityPath,
query: &LatestAtQuery,
) -> Option<Transform> {
crate::profile_function!();
let data_store = &entity_db.data_store;
let components = [Transform::name()];
let row_indices = data_store.latest_at(query, entity_path, Transform::name(), &components)?;
let results = data_store.get(&components, &row_indices);
let arr = results.get(0)?.as_ref()?.as_ref();
let mut iter = arrow_array_deserialize_iterator::<Transform>(arr).ok()?;
let transform = iter.next();
if iter.next().is_some() {
re_log::warn_once!("Unexpected batch for Transform at: {}", entity_path);
}
transform
}