pub struct SdfGrid {
pub nx: usize,
pub ny: usize,
pub nz: usize,
pub dx: f64,
pub origin: [f64; 3],
pub values: Vec<f64>,
}Expand description
A 3-D signed distance field stored on a uniform Cartesian grid.
Fields§
§nx: usizeNumber of cells in the x direction.
ny: usizeNumber of cells in the y direction.
nz: usizeNumber of cells in the z direction.
dx: f64Uniform cell spacing (same in all directions).
origin: [f64; 3]World-space coordinate of the (0,0,0) grid corner.
values: Vec<f64>Flat storage: index = i*ny*nz + j*nz + k.
Implementations§
Source§impl SdfGrid
impl SdfGrid
Sourcepub fn new(nx: usize, ny: usize, nz: usize, dx: f64, origin: [f64; 3]) -> Self
pub fn new(nx: usize, ny: usize, nz: usize, dx: f64, origin: [f64; 3]) -> Self
Create a new grid filled with f64::MAX.
Sourcepub fn world_pos(&self, i: usize, j: usize, k: usize) -> [f64; 3]
pub fn world_pos(&self, i: usize, j: usize, k: usize) -> [f64; 3]
World-space centre of cell (i, j, k).
Sourcepub fn compute_sphere_sdf(&mut self, center: [f64; 3], radius: f64)
pub fn compute_sphere_sdf(&mut self, center: [f64; 3], radius: f64)
Fill the grid with the signed distance to a sphere.
Sourcepub fn compute_box_sdf(&mut self, box_center: [f64; 3], half_extents: [f64; 3])
pub fn compute_box_sdf(&mut self, box_center: [f64; 3], half_extents: [f64; 3])
Fill the grid with the signed distance to an axis-aligned box.
Sourcepub fn compute_cylinder_sdf(
&mut self,
center: [f64; 2],
radius: f64,
half_height: f64,
)
pub fn compute_cylinder_sdf( &mut self, center: [f64; 2], radius: f64, half_height: f64, )
Fill the grid with the signed distance to an infinite cylinder aligned along the z-axis.
Sourcepub fn compute_torus_sdf(
&mut self,
center: [f64; 3],
major_radius: f64,
minor_radius: f64,
)
pub fn compute_torus_sdf( &mut self, center: [f64; 3], major_radius: f64, minor_radius: f64, )
Fill the grid with the signed distance to a torus centred at the origin in the xz-plane.
Sourcepub fn gradient_at(&self, i: usize, j: usize, k: usize) -> [f64; 3]
pub fn gradient_at(&self, i: usize, j: usize, k: usize) -> [f64; 3]
Estimate the gradient of the SDF at (i, j, k) using central differences.
Sourcepub fn total_cells(&self) -> usize
pub fn total_cells(&self) -> usize
Total number of cells in the grid.
Auto Trait Implementations§
impl Freeze for SdfGrid
impl RefUnwindSafe for SdfGrid
impl Send for SdfGrid
impl Sync for SdfGrid
impl Unpin for SdfGrid
impl UnsafeUnpin for SdfGrid
impl UnwindSafe for SdfGrid
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more