-
Notifications
You must be signed in to change notification settings - Fork 373
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
Improve heuristics around 2D vs 3D space-view creation #3822
Changes from all commits
8273ce8
396c2ca
14ae2db
1696142
bae63aa
62966a3
680bf58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ use re_types::{ | |
Archetype as _, ComponentNameSet, | ||
}; | ||
use re_viewer_context::{ | ||
default_heuristic_filter, gpu_bridge, DefaultColor, SpaceViewClass, | ||
default_heuristic_filter, gpu_bridge, DefaultColor, HeuristicFilterContext, SpaceViewClass, | ||
SpaceViewSystemExecutionError, TensorDecodeCache, TensorStatsCache, ViewPartSystem, ViewQuery, | ||
ViewerContext, | ||
}; | ||
|
@@ -681,13 +681,19 @@ impl ViewPartSystem for ImagesPart { | |
&self, | ||
store: &re_arrow_store::DataStore, | ||
ent_path: &EntityPath, | ||
ctx: HeuristicFilterContext, | ||
query: &LatestAtQuery, | ||
entity_components: &ComponentNameSet, | ||
) -> bool { | ||
if !default_heuristic_filter(entity_components, &self.indicator_components()) { | ||
return false; | ||
} | ||
|
||
// If this is a 3D view and there's no parent pinhole, do not include this part. | ||
if ctx.class == "3D" && !ctx.has_ancestor_pinhole { | ||
return false; | ||
} | ||
Comment on lines
+692
to
+695
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why though? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can already read the Rust code and see what it does, I want to know why it does it! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
// NOTE: We want to make sure we query at the right time, otherwise we might take into | ||
// account a `Clear()` that actually only applies into the future, and then | ||
// `is_shaped_like_an_image` will righfully fail because of the empty tensor. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
use re_arrow_store::LatestAtQuery; | ||
use re_data_store::{EntityPath, InstancePathHash}; | ||
use re_query::{ArchetypeView, QueryError}; | ||
use re_types::{ | ||
|
@@ -6,8 +7,8 @@ use re_types::{ | |
Archetype, ComponentNameSet, | ||
}; | ||
use re_viewer_context::{ | ||
NamedViewSystem, ResolvedAnnotationInfos, SpaceViewSystemExecutionError, ViewContextCollection, | ||
ViewPartSystem, ViewQuery, ViewerContext, | ||
default_heuristic_filter, HeuristicFilterContext, NamedViewSystem, ResolvedAnnotationInfos, | ||
SpaceViewSystemExecutionError, ViewContextCollection, ViewPartSystem, ViewQuery, ViewerContext, | ||
}; | ||
|
||
use crate::{ | ||
|
@@ -199,6 +200,26 @@ impl ViewPartSystem for Points2DPart { | |
std::iter::once(Points2D::indicator().name()).collect() | ||
} | ||
|
||
fn heuristic_filter( | ||
&self, | ||
_store: &re_arrow_store::DataStore, | ||
_ent_path: &EntityPath, | ||
ctx: HeuristicFilterContext, | ||
_query: &LatestAtQuery, | ||
entity_components: &ComponentNameSet, | ||
) -> bool { | ||
if !default_heuristic_filter(entity_components, &self.indicator_components()) { | ||
return false; | ||
} | ||
|
||
// If this is a 3D view and there's no parent pinhole, do not include this part. | ||
if ctx.class == "3D" && !ctx.has_ancestor_pinhole { | ||
return false; | ||
} | ||
Comment on lines
+215
to
+218
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've read this many times now |
||
|
||
true | ||
} | ||
|
||
fn execute( | ||
&mut self, | ||
ctx: &mut ViewerContext<'_>, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ use re_viewer_context::{ | |
use crate::{ | ||
contexts::{register_spatial_contexts, PrimitiveCounter}, | ||
heuristics::{auto_spawn_heuristic, update_object_property_heuristics}, | ||
parts::{calculate_bounding_box, register_2d_spatial_parts}, | ||
parts::{calculate_bounding_box, register_2d_spatial_parts, SpatialViewPartData}, | ||
ui::SpatialSpaceViewState, | ||
view_kind::SpatialSpaceViewKind, | ||
}; | ||
|
@@ -69,10 +69,51 @@ impl SpaceViewClass for SpatialSpaceView2D { | |
fn auto_spawn_heuristic( | ||
&self, | ||
ctx: &ViewerContext<'_>, | ||
_space_origin: &EntityPath, | ||
ent_paths: &PerSystemEntities, | ||
space_origin: &EntityPath, | ||
per_system_entities: &PerSystemEntities, | ||
) -> AutoSpawnHeuristic { | ||
auto_spawn_heuristic(&self.name(), ctx, ent_paths, SpatialSpaceViewKind::TwoD) | ||
let mut score = auto_spawn_heuristic( | ||
&self.name(), | ||
ctx, | ||
per_system_entities, | ||
SpatialSpaceViewKind::TwoD, | ||
); | ||
|
||
// If this is the root space view, and it contains a part that would | ||
// prefer to be 3D, don't spawn the 2D view. This is because it's never | ||
// possible to correctly project 3d objects to a root 2d view since the | ||
// the pinhole would go past the root. | ||
Comment on lines
+84
to
+85
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I follow this. "go past the root"? |
||
if space_origin.is_root() { | ||
let parts = ctx | ||
.space_view_class_registry | ||
.get_system_registry_or_log_error(&self.name()) | ||
.new_part_collection(); | ||
|
||
for part in per_system_entities.keys() { | ||
if let Ok(part) = parts.get_by_name(*part) { | ||
if let Some(part_data) = part | ||
.data() | ||
.and_then(|d| d.downcast_ref::<SpatialViewPartData>()) | ||
{ | ||
if part_data.preferred_view_kind == Some(SpatialSpaceViewKind::ThreeD) { | ||
return AutoSpawnHeuristic::NeverSpawn; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
if let AutoSpawnHeuristic::SpawnClassWithHighestScoreForRoot(score) = &mut score { | ||
// If a 2D view contains nothing inherently 2D in nature, don't | ||
// spawn it, though in all other cases default to 2D over 3D as a tie-breaker. | ||
if *score == 0.0 { | ||
return AutoSpawnHeuristic::NeverSpawn; | ||
} else { | ||
*score += 0.1; | ||
} | ||
} | ||
|
||
score | ||
} | ||
|
||
fn selection_ui( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again - why?