Skip to content

Commit 4e99df5

Browse files
committed
images with a shared root & an explicit draw order all go to the same space view now
1 parent 2ad6d9c commit 4e99df5

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

crates/re_viewer/src/ui/space_view_heuristics.rs

+36-13
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,13 @@ fn default_created_space_views_from_candidates(
171171

172172
// Spatial views with images get extra treatment as well.
173173
if candidate.category == ViewCategory::Spatial {
174-
let mut images_by_size: HashMap<(u64, u64), Vec<EntityPath>> = HashMap::default();
174+
#[derive(Hash, PartialEq, Eq)]
175+
enum ImageBucketing {
176+
BySize((u64, u64)),
177+
ExplicitDrawOrder,
178+
}
179+
180+
let mut images_by_bucket: HashMap<ImageBucketing, Vec<EntityPath>> = HashMap::default();
175181

176182
// For this we're only interested in the direct children.
177183
for entity_path in &candidate.data_blueprint.root_group().entities {
@@ -184,24 +190,41 @@ fn default_created_space_views_from_candidates(
184190
for tensor in entity_view.iter_primary_flattened() {
185191
if tensor.is_shaped_like_an_image() {
186192
debug_assert!(matches!(tensor.shape.len(), 2 | 3));
187-
let dim = (tensor.shape[0].size, tensor.shape[1].size);
188-
images_by_size
189-
.entry(dim)
190-
.or_default()
191-
.push(entity_path.clone());
193+
194+
if query_latest_single::<re_log_types::DrawOrder>(
195+
entity_db,
196+
entity_path,
197+
&query,
198+
)
199+
.is_some()
200+
{
201+
// Put everything in the same bucket if it has a draw order.
202+
images_by_bucket
203+
.entry(ImageBucketing::ExplicitDrawOrder)
204+
.or_default()
205+
.push(entity_path.clone());
206+
} else {
207+
// Otherwise, distinguish buckets by image size.
208+
let dim = (tensor.shape[0].size, tensor.shape[1].size);
209+
images_by_bucket
210+
.entry(ImageBucketing::BySize(dim))
211+
.or_default()
212+
.push(entity_path.clone());
213+
}
192214
}
193215
}
194216
}
195217
}
196218

197-
// If all images are the same size, proceed with the candidate as is. Otherwise...
198-
if images_by_size.len() > 1 {
199-
// ...stack images of the same size, but no others.
200-
for dim in images_by_size.keys() {
201-
// Ignore every image that has a different size.
202-
let images_of_different_size = images_by_size
219+
if images_by_bucket.len() > 1 {
220+
// If all images end up in the same bucket, proceed as normal. Otherwise stack images as instructed.
221+
for bucket in images_by_bucket.keys() {
222+
// Ignore every image from antoher bucket. Keep all other entities.
223+
let images_of_different_size = images_by_bucket
203224
.iter()
204-
.filter_map(|(other_dim, images)| (dim != other_dim).then_some(images))
225+
.filter_map(|(other_bucket, images)| {
226+
(bucket != other_bucket).then_some(images)
227+
})
205228
.flatten()
206229
.cloned()
207230
.collect::<IntSet<_>>();

0 commit comments

Comments
 (0)