Skip to content

Commit

Permalink
Merge branch 'main' into jan/prepare-code-examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jprochazk committed Mar 8, 2024
2 parents d8e8259 + 8834a8a commit 449f399
Show file tree
Hide file tree
Showing 73 changed files with 1,592 additions and 622 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion crates/re_entity_db/src/entity_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,11 @@ impl EntityDb {

// Clears don't affect `Clear` components themselves, therefore we cannot have recursive
// cascades, thus this whole process must stabilize after one iteration.
debug_assert!(clear_cascade.is_empty());
if !clear_cascade.is_empty() {
re_log::debug!(
"recursive clear cascade detected -- might just have been logged this way"
);
}

// We inform the stats last, since it measures e2e latency.
self.stats.on_events(original_store_events);
Expand Down
2 changes: 1 addition & 1 deletion crates/re_entity_db/src/entity_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl Default for EntityProperties {
visible_history: re_query::ExtraQueryHistory::default(),
interactive: true,
color_mapper: EditableAutoValue::default(),
pinhole_image_plane_distance: EditableAutoValue::default(),
pinhole_image_plane_distance: EditableAutoValue::Auto(1.0),
backproject_depth: EditableAutoValue::Auto(true),
depth_from_world_scale: EditableAutoValue::Auto(1.0),
backproject_radius_scale: EditableAutoValue::Auto(1.0),
Expand Down
12 changes: 12 additions & 0 deletions crates/re_log_types/src/path/entity_path_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ pub struct EntityPathFilter {
rules: BTreeMap<EntityPathRule, RuleEffect>,
}

impl std::hash::Hash for EntityPathFilter {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.formatted().hash(state);
}
}

impl std::fmt::Debug for EntityPathFilter {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "EntityPathFilter({:?})", self.formatted())
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct EntityPathRule {
pub path: EntityPath,
Expand Down
3 changes: 1 addition & 2 deletions crates/re_space_view/src/space_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ impl SpaceViewBlueprint {
pub fn clear(&self, ctx: &ViewerContext<'_>) {
let clear = Clear::recursive();
ctx.save_blueprint_component(&self.entity_path(), &clear.is_recursive);
self.contents.clear(ctx);
}

#[inline]
Expand Down Expand Up @@ -434,7 +433,7 @@ impl SpaceViewBlueprint {
DataResult {
entity_path: entity_path.clone(),
visualizers: Default::default(),
direct_included: true,
tree_prefix_only: false,
property_overrides: Some(PropertyOverrides {
accumulated_properties,
individual_properties,
Expand Down
49 changes: 15 additions & 34 deletions crates/re_space_view/src/space_view_contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ use re_entity_db::{
};
use re_log_types::{path::RuleEffect, EntityPath, EntityPathFilter, EntityPathRule, StoreKind};
use re_types::{
blueprint::{
archetypes as blueprint_archetypes,
components::{EntitiesDeterminedByUser, QueryExpression},
},
blueprint::{archetypes as blueprint_archetypes, components::QueryExpression},
Archetype as _,
};
use re_types_core::{archetypes::Clear, components::VisualizerOverrides, ComponentName};
use re_types_core::{components::VisualizerOverrides, ComponentName};
use re_viewer_context::{
DataQueryResult, DataResult, DataResultHandle, DataResultNode, DataResultTree,
IndicatedEntities, PerVisualizer, PropertyOverrides, SpaceViewClassIdentifier, SpaceViewId,
Expand Down Expand Up @@ -42,9 +39,6 @@ pub struct SpaceViewContents {

pub space_view_class_identifier: SpaceViewClassIdentifier,
pub entity_path_filter: EntityPathFilter,

/// True if the user is expected to add entities themselves. False otherwise.
pub entities_determined_by_user: bool,
}

impl SpaceViewContents {
Expand Down Expand Up @@ -94,7 +88,6 @@ impl SpaceViewContents {
blueprint_entity_path,
space_view_class_identifier,
entity_path_filter,
entities_determined_by_user: false,
}
}

Expand All @@ -109,10 +102,7 @@ impl SpaceViewContents {
blueprint_archetypes::SpaceViewContents,
>(id, blueprint_db, query);

let blueprint_archetypes::SpaceViewContents {
query,
entities_determined_by_user,
} = contents.unwrap_or_else(|err| {
let blueprint_archetypes::SpaceViewContents { query } = contents.unwrap_or_else(|err| {
re_log::warn_once!(
"Failed to load SpaceViewContents for {:?} from blueprint store at {:?}: {}",
id,
Expand All @@ -128,7 +118,6 @@ impl SpaceViewContents {
blueprint_entity_path,
space_view_class_identifier,
entity_path_filter,
entities_determined_by_user: entities_determined_by_user.map_or(false, |b| b.0),
}
}

Expand All @@ -141,8 +130,7 @@ impl SpaceViewContents {
pub fn save_to_blueprint_store(&self, ctx: &ViewerContext<'_>) {
ctx.save_blueprint_archetype(
self.blueprint_entity_path.clone(),
&blueprint_archetypes::SpaceViewContents::new(self.entity_path_filter.formatted())
.with_entities_determined_by_user(self.entities_determined_by_user),
&blueprint_archetypes::SpaceViewContents::new(self.entity_path_filter.formatted()),
);
}

Expand All @@ -159,18 +147,6 @@ impl SpaceViewContents {
&self.blueprint_entity_path,
&QueryExpression(new_entity_path_filter.formatted().into()),
);

if !self.entities_determined_by_user {
ctx.save_blueprint_component(
&self.blueprint_entity_path,
&EntitiesDeterminedByUser(true),
);
}
}

pub fn clear(&self, ctx: &ViewerContext<'_>) {
let clear = Clear::recursive();
ctx.save_blueprint_component(&self.blueprint_entity_path, &clear.is_recursive);
}

pub fn build_resolver<'a>(
Expand Down Expand Up @@ -288,16 +264,21 @@ impl<'a> QueryExpressionEvaluator<'a> {

let entity_path = &tree.path;

let tree_prefix_only = !self.entity_path_filter.is_included(entity_path);

// TODO(#5067): For now, we always start by setting visualizers to the full list of available visualizers.
// This is currently important for evaluating auto-properties during the space-view `on_frame_start`, which
// is called before the property-overrider has a chance to update this list.
// This list will be updated below during `update_overrides_recursive` by calling `choose_default_visualizers`
// on the space view.
let visualizers: SmallVec<[_; 4]> = self
.visualizable_entities_for_visualizer_systems
.iter()
.filter_map(|(visualizer, ents)| ents.contains(entity_path).then_some(*visualizer))
.collect();
let visualizers: SmallVec<[_; 4]> = if tree_prefix_only {
Default::default()
} else {
self.visualizable_entities_for_visualizer_systems
.iter()
.filter_map(|(visualizer, ents)| ents.contains(entity_path).then_some(*visualizer))
.collect()
};

let children: SmallVec<[_; 4]> = tree
.children
Expand All @@ -316,7 +297,7 @@ impl<'a> QueryExpressionEvaluator<'a> {
data_result: DataResult {
entity_path: entity_path.clone(),
visualizers,
direct_included: self.entity_path_filter.is_included(entity_path),
tree_prefix_only,
property_overrides: None,
},
children,
Expand Down
16 changes: 15 additions & 1 deletion crates/re_space_view_spatial/src/space_view_2d.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ahash::HashSet;
use nohash_hasher::{IntMap, IntSet};

use re_entity_db::{EntityProperties, EntityTree};
use re_entity_db::{EntityDb, EntityProperties, EntityTree};
use re_log_types::{EntityPath, EntityPathFilter};
use re_types::{
archetypes::{DepthImage, Image},
Expand Down Expand Up @@ -77,6 +77,20 @@ impl SpaceViewClass for SpatialSpaceView2D {
re_viewer_context::SpaceViewClassLayoutPriority::High
}

fn recommended_root_for_entities(
&self,
entities: &IntSet<EntityPath>,
entity_db: &EntityDb,
) -> Option<EntityPath> {
let common_ancestor = EntityPath::common_ancestor_of(entities.iter());

// For a 2D space view, the origin of the subspace defined by the common ancestor is always
// better.
SpatialTopology::access(entity_db.store_id(), |topo| {
topo.subspace_for_entity(&common_ancestor).origin.clone()
})
}

fn visualizable_filter_context(
&self,
space_origin: &EntityPath,
Expand Down
42 changes: 41 additions & 1 deletion crates/re_space_view_spatial/src/space_view_3d.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use itertools::Itertools;
use nohash_hasher::IntSet;
use re_entity_db::EntityProperties;
use re_entity_db::{EntityDb, EntityProperties};
use re_log_types::{EntityPath, EntityPathFilter};
use re_types::{components::ViewCoordinates, Loggable};
use re_viewer_context::{
Expand Down Expand Up @@ -71,6 +71,46 @@ impl SpaceViewClass for SpatialSpaceView3D {
re_viewer_context::SpaceViewClassLayoutPriority::High
}

fn recommended_root_for_entities(
&self,
entities: &IntSet<EntityPath>,
entity_db: &EntityDb,
) -> Option<EntityPath> {
let common_ancestor = EntityPath::common_ancestor_of(entities.iter());

// For 3D space view, the origin of the subspace defined by the common ancestor is usually
// the best choice. However, if the subspace is defined by a pinhole, we should use its
// parent.
//
// Also, if a ViewCoordinate3D is logged somewhere between the common ancestor and the
// subspace origin, we use it as origin.
SpatialTopology::access(entity_db.store_id(), |topo| {
let subspace = topo.subspace_for_entity(&common_ancestor);

let subspace_origin = if subspace.supports_3d_content() {
Some(subspace)
} else {
topo.subspace_for_subspace_origin(subspace.parent_space)
}
.map(|subspace| subspace.origin.clone());

// Find the first ViewCoordinates3d logged, walking up from the common ancestor to the
// subspace origin.
EntityPath::incremental_walk(subspace_origin.as_ref(), &common_ancestor)
.collect::<Vec<_>>()
.into_iter()
.rev()
.find(|path| {
subspace
.heuristic_hints
.get(path)
.is_some_and(|hint| hint.contains(HeuristicHints::ViewCoordinates3d))
})
.or(subspace_origin)
})
.flatten()
}

fn visualizable_filter_context(
&self,
space_origin: &EntityPath,
Expand Down
1 change: 1 addition & 0 deletions crates/re_time_panel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ re_log_types.workspace = true
re_tracing.workspace = true
re_ui.workspace = true
re_viewer_context.workspace = true
re_viewport.workspace = true # TODO(#5421): remove this dependency in favor of re_viewport_blueprint when it exists

egui.workspace = true
itertools.workspace = true
Expand Down

0 comments on commit 449f399

Please sign in to comment.