@@ -7,8 +7,8 @@ use crate::topology::{Axis, Direction};
7
7
use crate :: uniform_grid:: { PointIndex , UniformGrid } ;
8
8
use crate :: utils:: { ChunkSize , ParallelPolicy } ;
9
9
use crate :: {
10
- marching_cubes, new_map, profile, AxisAlignedBoundingBox , AxisAlignedBoundingBox3d ,
11
- GridConstructionError , Index , MapType , Real ,
10
+ marching_cubes, new_map, profile, AxisAlignedBoundingBox3d , GridConstructionError , Index ,
11
+ MapType , Real ,
12
12
} ;
13
13
use arrayvec:: ArrayVec ;
14
14
use log:: info;
@@ -52,6 +52,8 @@ pub struct OctreeNode<I: Index, R: Real> {
52
52
min_corner : PointIndex < I > ,
53
53
/// Upper corner point of the octree node on the background grid
54
54
max_corner : PointIndex < I > ,
55
+ /// AABB of the octree node
56
+ aabb : AxisAlignedBoundingBox3d < R > ,
55
57
/// Additional data associated to this octree node
56
58
data : NodeData < I , R > ,
57
59
}
@@ -141,8 +143,6 @@ impl<I: Index, R: Real> Octree<I, R> {
141
143
) -> Self {
142
144
let mut tree = Octree :: new ( & grid, particle_positions. len ( ) ) ;
143
145
144
- println ! ( "Margin: {}" , margin) ;
145
-
146
146
if enable_multi_threading {
147
147
tree. subdivide_recursively_margin_par (
148
148
grid,
@@ -321,8 +321,13 @@ impl<I: Index, R: Real> Octree<I, R> {
321
321
}
322
322
323
323
impl < I : Index , R : Real > OctreeNode < I , R > {
324
- pub fn new ( id : usize , min_corner : PointIndex < I > , max_corner : PointIndex < I > ) -> Self {
325
- Self :: with_data ( id, min_corner, max_corner, NodeData :: None )
324
+ pub fn new (
325
+ id : usize ,
326
+ min_corner : PointIndex < I > ,
327
+ max_corner : PointIndex < I > ,
328
+ aabb : AxisAlignedBoundingBox3d < R > ,
329
+ ) -> Self {
330
+ Self :: with_data ( id, min_corner, max_corner, aabb, NodeData :: None )
326
331
}
327
332
328
333
fn new_root ( grid : & UniformGrid < I , R > , n_particles : usize ) -> Self {
@@ -340,6 +345,7 @@ impl<I: Index, R: Real> OctreeNode<I, R> {
340
345
. expect ( "Cannot get lower corner of grid" ) ,
341
346
grid. get_point ( max_point)
342
347
. expect ( "Cannot get upper corner of grid" ) ,
348
+ grid. aabb ( ) . clone ( ) ,
343
349
NodeData :: new_particle_set ( ( 0 ..n_particles) . collect :: < SmallVec < _ > > ( ) , 0 ) ,
344
350
)
345
351
}
@@ -348,13 +354,15 @@ impl<I: Index, R: Real> OctreeNode<I, R> {
348
354
id : usize ,
349
355
min_corner : PointIndex < I > ,
350
356
max_corner : PointIndex < I > ,
357
+ aabb : AxisAlignedBoundingBox3d < R > ,
351
358
data : NodeData < I , R > ,
352
359
) -> Self {
353
360
Self {
354
361
id,
355
362
children : Default :: default ( ) ,
356
363
min_corner,
357
364
max_corner,
365
+ aabb,
358
366
data,
359
367
}
360
368
}
@@ -385,11 +393,8 @@ impl<I: Index, R: Real> OctreeNode<I, R> {
385
393
}
386
394
387
395
/// Returns the AABB represented by this octree node
388
- pub fn aabb ( & self , grid : & UniformGrid < I , R > ) -> AxisAlignedBoundingBox3d < R > {
389
- AxisAlignedBoundingBox :: new (
390
- grid. point_coordinates ( & self . min_corner ) ,
391
- grid. point_coordinates ( & self . max_corner ) ,
392
- )
396
+ pub fn aabb ( & self ) -> & AxisAlignedBoundingBox3d < R > {
397
+ & self . aabb
393
398
}
394
399
395
400
/// Constructs a [`UniformGrid`](crate::UniformGrid) that represents the domain of this octree node
@@ -431,11 +436,6 @@ impl<I: Index, R: Real> OctreeNode<I, R> {
431
436
let mut counters: [ usize ; 8 ] = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ;
432
437
let mut non_ghost_counters: [ usize ; 8 ] = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ;
433
438
434
- let node_aabb = AxisAlignedBoundingBox3d :: new (
435
- grid. point_coordinates ( & self . min_corner ) ,
436
- grid. point_coordinates ( & self . max_corner ) ,
437
- ) ;
438
-
439
439
// Classify all particles of this leaf into the halfspaces relative to the split point
440
440
assert_eq ! ( particles. len( ) , halfspace_flags. len( ) ) ;
441
441
for ( particle_idx, particle_halfspace_flags) in
@@ -444,7 +444,7 @@ impl<I: Index, R: Real> OctreeNode<I, R> {
444
444
let pos = particle_positions[ particle_idx] ;
445
445
let relative_pos = pos - split_coordinates;
446
446
447
- let is_ghost_particle = !node_aabb . contains_point ( & pos) ;
447
+ let is_ghost_particle = !self . aabb . contains_point ( & pos) ;
448
448
449
449
// Check what the main octant (without margin) of the particle is to count ghost particles later
450
450
if !is_ghost_particle {
@@ -485,6 +485,11 @@ impl<I: Index, R: Real> OctreeNode<I, R> {
485
485
. combine_point_index ( grid, & split_point, & self . max_corner )
486
486
. expect ( "Failed to get corner point of octree subcell" ) ;
487
487
488
+ let child_aabb = AxisAlignedBoundingBox3d :: new (
489
+ grid. point_coordinates ( & min_corner) ,
490
+ grid. point_coordinates ( & max_corner) ,
491
+ ) ;
492
+
488
493
let mut octant_particles = SmallVec :: with_capacity ( octant_particle_count) ;
489
494
octant_particles. extend (
490
495
particles
@@ -503,6 +508,7 @@ impl<I: Index, R: Real> OctreeNode<I, R> {
503
508
next_id. fetch_add ( 1 , Ordering :: SeqCst ) ,
504
509
min_corner,
505
510
max_corner,
511
+ child_aabb,
506
512
NodeData :: new_particle_set (
507
513
octant_particles,
508
514
octant_particle_count - octant_non_ghost_count,
@@ -546,11 +552,6 @@ impl<I: Index, R: Real> OctreeNode<I, R> {
546
552
let tl_counters = ThreadLocal :: new ( ) ;
547
553
let chunk_size = ChunkSize :: new ( parallel_policy, particles. len ( ) ) . chunk_size ;
548
554
549
- let node_aabb = AxisAlignedBoundingBox3d :: new (
550
- grid. point_coordinates ( & self . min_corner ) ,
551
- grid. point_coordinates ( & self . max_corner ) ,
552
- ) ;
553
-
554
555
// Classify all particles of this leaf into its octants
555
556
assert_eq ! ( particles. len( ) , octant_flags. len( ) ) ;
556
557
particles
@@ -571,7 +572,7 @@ impl<I: Index, R: Real> OctreeNode<I, R> {
571
572
let pos = particle_positions[ particle_idx] ;
572
573
let relative_pos = particle_positions[ particle_idx] - split_coordinates;
573
574
574
- let is_ghost_particle = !node_aabb . contains_point ( & pos) ;
575
+ let is_ghost_particle = !self . aabb . contains_point ( & pos) ;
575
576
576
577
// Check what the main octant of the particle is (to count ghost particles)
577
578
if !is_ghost_particle {
@@ -629,6 +630,11 @@ impl<I: Index, R: Real> OctreeNode<I, R> {
629
630
. combine_point_index ( grid, & split_point, & self . max_corner )
630
631
. expect ( "Failed to get corner point of octree subcell" ) ;
631
632
633
+ let child_aabb = AxisAlignedBoundingBox3d :: new (
634
+ grid. point_coordinates ( & min_corner) ,
635
+ grid. point_coordinates ( & max_corner) ,
636
+ ) ;
637
+
632
638
let mut octant_particles = SmallVec :: with_capacity ( octant_particle_count) ;
633
639
octant_particles. extend (
634
640
particles
@@ -647,6 +653,7 @@ impl<I: Index, R: Real> OctreeNode<I, R> {
647
653
next_id. fetch_add ( 1 , Ordering :: SeqCst ) ,
648
654
min_corner,
649
655
max_corner,
656
+ child_aabb,
650
657
NodeData :: new_particle_set (
651
658
octant_particles,
652
659
octant_particle_count - octant_non_ghost_count,
0 commit comments