@@ -171,7 +171,13 @@ fn default_created_space_views_from_candidates(
171
171
172
172
// Spatial views with images get extra treatment as well.
173
173
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 ( ) ;
175
181
176
182
// For this we're only interested in the direct children.
177
183
for entity_path in & candidate. data_blueprint . root_group ( ) . entities {
@@ -184,24 +190,41 @@ fn default_created_space_views_from_candidates(
184
190
for tensor in entity_view. iter_primary_flattened ( ) {
185
191
if tensor. is_shaped_like_an_image ( ) {
186
192
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
+ }
192
214
}
193
215
}
194
216
}
195
217
}
196
218
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
203
224
. 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
+ } )
205
228
. flatten ( )
206
229
. cloned ( )
207
230
. collect :: < IntSet < _ > > ( ) ;
0 commit comments