(
grid: &UniformGrid<I, R>,
compact_support_radius: R,
cube_size: R,
particle_rest_mass: R,
)
| 582 | // TODO: Maybe remove allowed domain check? And require this is done before, using the active_particles array? |
| 583 | impl<I: Index, R: Real> SparseDensityMapGenerator<I, R> { |
| 584 | fn try_new( |
| 585 | grid: &UniformGrid<I, R>, |
| 586 | compact_support_radius: R, |
| 587 | cube_size: R, |
| 588 | particle_rest_mass: R, |
| 589 | ) -> Result<Self, DensityMapError<R>> { |
| 590 | let GridKernelExtents { |
| 591 | half_supported_cells, |
| 592 | supported_points, |
| 593 | kernel_evaluation_radius, |
| 594 | } = compute_kernel_evaluation_radius(compact_support_radius, cube_size); |
| 595 | |
| 596 | // Pre-compute the kernel which can be queried using squared distances |
| 597 | let kernel_evaluation_radius_sq = kernel_evaluation_radius * kernel_evaluation_radius; |
| 598 | let kernel = CubicSplineKernel::new(compact_support_radius); |
| 599 | |
| 600 | // Shrink the allowed domain for particles by the kernel evaluation radius. This ensures that all cells/points |
| 601 | // that are affected by a particle are actually part of the domain/grid, so it does not have to be checked in the loops below. |
| 602 | // However, any particles inside of this margin, close to the border of the originally requested domain will be ignored. |
| 603 | // |
| 604 | // This also implies that this density map should always represent a closed surfaces. |
| 605 | // If particles were closer to the AABB boundary than this margin, there could be holes in the resulting level-set. |
| 606 | let allowed_domain = { |
| 607 | let mut aabb = grid.aabb().clone(); |
| 608 | aabb.grow_uniformly(kernel_evaluation_radius.neg()); |
| 609 | aabb |
| 610 | }; |
| 611 | |
| 612 | if allowed_domain.is_degenerate() || !allowed_domain.is_consistent() { |
| 613 | warn!( |
| 614 | "The allowed domain of particles for a subdomain is inconsistent/degenerate: {:?}", |
| 615 | allowed_domain |
| 616 | ); |
| 617 | warn!( |
| 618 | "No particles can be found in this domain. Increase the domain of the surface reconstruction to avoid this." |
| 619 | ); |
| 620 | Err(DensityMapError::InvalidDomain { |
| 621 | margin: kernel_evaluation_radius, |
| 622 | domain: allowed_domain, |
| 623 | }) |
| 624 | } else { |
| 625 | Ok(Self { |
| 626 | half_supported_cells, |
| 627 | supported_points, |
| 628 | kernel_evaluation_radius_sq, |
| 629 | kernel, |
| 630 | allowed_domain, |
| 631 | particle_rest_mass, |
| 632 | }) |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | /// Computes all density contributions of a particle to the background grid into the given map |
| 637 | fn compute_particle_density_contribution( |
nothing calls this directly
no test coverage detected