Skip to content

Commit 5a52172

Browse files
committed
Add AABB to octree nodes
1 parent 809d1f5 commit 5a52172

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

splashsurf_lib/src/octree.rs

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use crate::topology::{Axis, Direction};
77
use crate::uniform_grid::{PointIndex, UniformGrid};
88
use crate::utils::{ChunkSize, ParallelPolicy};
99
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,
1212
};
1313
use arrayvec::ArrayVec;
1414
use log::info;
@@ -52,6 +52,8 @@ pub struct OctreeNode<I: Index, R: Real> {
5252
min_corner: PointIndex<I>,
5353
/// Upper corner point of the octree node on the background grid
5454
max_corner: PointIndex<I>,
55+
/// AABB of the octree node
56+
aabb: AxisAlignedBoundingBox3d<R>,
5557
/// Additional data associated to this octree node
5658
data: NodeData<I, R>,
5759
}
@@ -141,8 +143,6 @@ impl<I: Index, R: Real> Octree<I, R> {
141143
) -> Self {
142144
let mut tree = Octree::new(&grid, particle_positions.len());
143145

144-
println!("Margin: {}", margin);
145-
146146
if enable_multi_threading {
147147
tree.subdivide_recursively_margin_par(
148148
grid,
@@ -321,8 +321,13 @@ impl<I: Index, R: Real> Octree<I, R> {
321321
}
322322

323323
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)
326331
}
327332

328333
fn new_root(grid: &UniformGrid<I, R>, n_particles: usize) -> Self {
@@ -340,6 +345,7 @@ impl<I: Index, R: Real> OctreeNode<I, R> {
340345
.expect("Cannot get lower corner of grid"),
341346
grid.get_point(max_point)
342347
.expect("Cannot get upper corner of grid"),
348+
grid.aabb().clone(),
343349
NodeData::new_particle_set((0..n_particles).collect::<SmallVec<_>>(), 0),
344350
)
345351
}
@@ -348,13 +354,15 @@ impl<I: Index, R: Real> OctreeNode<I, R> {
348354
id: usize,
349355
min_corner: PointIndex<I>,
350356
max_corner: PointIndex<I>,
357+
aabb: AxisAlignedBoundingBox3d<R>,
351358
data: NodeData<I, R>,
352359
) -> Self {
353360
Self {
354361
id,
355362
children: Default::default(),
356363
min_corner,
357364
max_corner,
365+
aabb,
358366
data,
359367
}
360368
}
@@ -385,11 +393,8 @@ impl<I: Index, R: Real> OctreeNode<I, R> {
385393
}
386394

387395
/// 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
393398
}
394399

395400
/// 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> {
431436
let mut counters: [usize; 8] = [0, 0, 0, 0, 0, 0, 0, 0];
432437
let mut non_ghost_counters: [usize; 8] = [0, 0, 0, 0, 0, 0, 0, 0];
433438

434-
let node_aabb = AxisAlignedBoundingBox3d::new(
435-
grid.point_coordinates(&self.min_corner),
436-
grid.point_coordinates(&self.max_corner),
437-
);
438-
439439
// Classify all particles of this leaf into the halfspaces relative to the split point
440440
assert_eq!(particles.len(), halfspace_flags.len());
441441
for (particle_idx, particle_halfspace_flags) in
@@ -444,7 +444,7 @@ impl<I: Index, R: Real> OctreeNode<I, R> {
444444
let pos = particle_positions[particle_idx];
445445
let relative_pos = pos - split_coordinates;
446446

447-
let is_ghost_particle = !node_aabb.contains_point(&pos);
447+
let is_ghost_particle = !self.aabb.contains_point(&pos);
448448

449449
// Check what the main octant (without margin) of the particle is to count ghost particles later
450450
if !is_ghost_particle {
@@ -485,6 +485,11 @@ impl<I: Index, R: Real> OctreeNode<I, R> {
485485
.combine_point_index(grid, &split_point, &self.max_corner)
486486
.expect("Failed to get corner point of octree subcell");
487487

488+
let child_aabb = AxisAlignedBoundingBox3d::new(
489+
grid.point_coordinates(&min_corner),
490+
grid.point_coordinates(&max_corner),
491+
);
492+
488493
let mut octant_particles = SmallVec::with_capacity(octant_particle_count);
489494
octant_particles.extend(
490495
particles
@@ -503,6 +508,7 @@ impl<I: Index, R: Real> OctreeNode<I, R> {
503508
next_id.fetch_add(1, Ordering::SeqCst),
504509
min_corner,
505510
max_corner,
511+
child_aabb,
506512
NodeData::new_particle_set(
507513
octant_particles,
508514
octant_particle_count - octant_non_ghost_count,
@@ -546,11 +552,6 @@ impl<I: Index, R: Real> OctreeNode<I, R> {
546552
let tl_counters = ThreadLocal::new();
547553
let chunk_size = ChunkSize::new(parallel_policy, particles.len()).chunk_size;
548554

549-
let node_aabb = AxisAlignedBoundingBox3d::new(
550-
grid.point_coordinates(&self.min_corner),
551-
grid.point_coordinates(&self.max_corner),
552-
);
553-
554555
// Classify all particles of this leaf into its octants
555556
assert_eq!(particles.len(), octant_flags.len());
556557
particles
@@ -571,7 +572,7 @@ impl<I: Index, R: Real> OctreeNode<I, R> {
571572
let pos = particle_positions[particle_idx];
572573
let relative_pos = particle_positions[particle_idx] - split_coordinates;
573574

574-
let is_ghost_particle = !node_aabb.contains_point(&pos);
575+
let is_ghost_particle = !self.aabb.contains_point(&pos);
575576

576577
// Check what the main octant of the particle is (to count ghost particles)
577578
if !is_ghost_particle {
@@ -629,6 +630,11 @@ impl<I: Index, R: Real> OctreeNode<I, R> {
629630
.combine_point_index(grid, &split_point, &self.max_corner)
630631
.expect("Failed to get corner point of octree subcell");
631632

633+
let child_aabb = AxisAlignedBoundingBox3d::new(
634+
grid.point_coordinates(&min_corner),
635+
grid.point_coordinates(&max_corner),
636+
);
637+
632638
let mut octant_particles = SmallVec::with_capacity(octant_particle_count);
633639
octant_particles.extend(
634640
particles
@@ -647,6 +653,7 @@ impl<I: Index, R: Real> OctreeNode<I, R> {
647653
next_id.fetch_add(1, Ordering::SeqCst),
648654
min_corner,
649655
max_corner,
656+
child_aabb,
650657
NodeData::new_particle_set(
651658
octant_particles,
652659
octant_particle_count - octant_non_ghost_count,

splashsurf_lib/src/reconstruction.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,8 @@ impl<I: Index, R: Real> SurfaceReconstructionOctreeVisitor<I, R> {
269269
fn extract_node_subdomain(&self, octree_node: &OctreeNode<I, R>) -> OwningSubdomainGrid<I, R> {
270270
let grid = &self.grid;
271271

272-
let leaf_aabb = octree_node.aabb(grid);
273272
let subdomain_grid = octree_node
274-
.grid(leaf_aabb.min(), grid.cell_size())
273+
.grid(octree_node.aabb().min(), grid.cell_size())
275274
.expect("Unable to construct Octree node grid");
276275
let subdomain_offset = octree_node.min_corner();
277276
subdomain_grid.log_grid_info();

0 commit comments

Comments
 (0)