@@ -233,17 +233,17 @@ impl BVHAccel {
233
233
} else {
234
234
// compute bound of primitive centroids, choose split dimension _dim_
235
235
let mut centroid_bounds: Bounds3f = Bounds3f :: default ( ) ;
236
- for i in start.. end {
237
- centroid_bounds = bnd3_union_pnt3 ( & centroid_bounds, & primitive_info [ i ] . centroid ) ;
236
+ for item in primitive_info . iter ( ) . take ( end) . skip ( start ) {
237
+ centroid_bounds = bnd3_union_pnt3 ( & centroid_bounds, & item . centroid ) ;
238
238
}
239
239
let dim: u8 = centroid_bounds. maximum_extent ( ) ;
240
240
// partition primitives into two sets and build children
241
241
let mut mid: usize = ( start + end) / 2_usize ;
242
242
if centroid_bounds. p_max [ dim] == centroid_bounds. p_min [ dim] {
243
243
// create leaf _BVHBuildNode_
244
244
let first_prim_offset: usize = ordered_prims. len ( ) ;
245
- for i in start.. end {
246
- let prim_num: usize = primitive_info [ i ] . primitive_number ;
245
+ for item in primitive_info . iter ( ) . take ( end) . skip ( start ) {
246
+ let prim_num: usize = item . primitive_number ;
247
247
ordered_prims. push ( bvh. primitives [ prim_num] . clone ( ) ) ;
248
248
}
249
249
node. init_leaf ( first_prim_offset, n_primitives, & bounds) ;
@@ -271,9 +271,9 @@ impl BVHAccel {
271
271
let n_buckets: usize = 12 ;
272
272
let mut buckets: [ BucketInfo ; 12 ] = [ BucketInfo :: default ( ) ; 12 ] ;
273
273
// initialize _BucketInfo_ for SAH partition buckets
274
- for i in start.. end {
274
+ for item in primitive_info . iter ( ) . take ( end) . skip ( start ) {
275
275
let mut b: usize = ( n_buckets as Float
276
- * centroid_bounds. offset ( & primitive_info [ i ] . centroid ) [ dim] )
276
+ * centroid_bounds. offset ( & item . centroid ) [ dim] )
277
277
as usize ;
278
278
if b == n_buckets {
279
279
b = n_buckets - 1 ;
@@ -282,34 +282,34 @@ impl BVHAccel {
282
282
assert ! ( b < n_buckets, "b < {}" , n_buckets) ;
283
283
buckets[ b] . count += 1 ;
284
284
buckets[ b] . bounds =
285
- bnd3_union_bnd3 ( & buckets[ b] . bounds , & primitive_info [ i ] . bounds ) ;
285
+ bnd3_union_bnd3 ( & buckets[ b] . bounds , & item . bounds ) ;
286
286
}
287
287
// compute costs for splitting after each bucket
288
288
let mut cost: [ Float ; 11 ] = [ 0.0 ; 11 ] ;
289
- for i in 0 .. ( n_buckets - 1 ) {
289
+ for ( i , cost_item ) in cost . iter_mut ( ) . enumerate ( ) . take ( n_buckets - 1 ) {
290
290
let mut b0: Bounds3f = Bounds3f :: default ( ) ;
291
291
let mut b1: Bounds3f = Bounds3f :: default ( ) ;
292
292
let mut count0: usize = 0 ;
293
293
let mut count1: usize = 0 ;
294
- for j in 0 .. ( i + 1 ) {
295
- b0 = bnd3_union_bnd3 ( & b0, & buckets [ j ] . bounds ) ;
296
- count0 += buckets [ j ] . count ;
294
+ for item in buckets . iter ( ) . take ( i + 1 ) {
295
+ b0 = bnd3_union_bnd3 ( & b0, & item . bounds ) ;
296
+ count0 += item . count ;
297
297
}
298
- for j in ( i + 1 ) ..n_buckets {
299
- b1 = bnd3_union_bnd3 ( & b1, & buckets [ j ] . bounds ) ;
300
- count1 += buckets [ j ] . count ;
298
+ for item in buckets . iter ( ) . take ( n_buckets ) . skip ( i + 1 ) {
299
+ b1 = bnd3_union_bnd3 ( & b1, & item . bounds ) ;
300
+ count1 += item . count ;
301
301
}
302
- cost [ i ] = 1.0
302
+ * cost_item = 1.0
303
303
+ ( count0 as Float * b0. surface_area ( )
304
304
+ count1 as Float * b1. surface_area ( ) )
305
305
/ bounds. surface_area ( ) ;
306
306
}
307
307
// find bucket to split at that minimizes SAH metric
308
308
let mut min_cost: Float = cost[ 0 ] ;
309
309
let mut min_cost_split_bucket: usize = 0 ;
310
- for i in 0 .. ( n_buckets - 1 ) {
311
- if cost [ i ] < min_cost {
312
- min_cost = cost [ i ] ;
310
+ for ( i , item ) in cost . iter ( ) . enumerate ( ) . take ( n_buckets - 1 ) {
311
+ if item < & min_cost {
312
+ min_cost = * item ;
313
313
min_cost_split_bucket = i;
314
314
}
315
315
}
@@ -344,8 +344,8 @@ impl BVHAccel {
344
344
} else {
345
345
// create leaf _BVHBuildNode_
346
346
let first_prim_offset: usize = ordered_prims. len ( ) ;
347
- for i in start.. end {
348
- let prim_num: usize = primitive_info [ i ] . primitive_number ;
347
+ for item in primitive_info . iter ( ) . take ( end) . skip ( start ) {
348
+ let prim_num: usize = item . primitive_number ;
349
349
ordered_prims. push ( bvh. primitives [ prim_num] . clone ( ) ) ;
350
350
}
351
351
node. init_leaf ( first_prim_offset, n_primitives, & bounds) ;
0 commit comments