Skip to main content

Voxels

Struct Voxels 

Source
pub struct Voxels { /* private fields */ }
Expand description

A mesh rasterised onto a grid of cubes.

The grid is the mesh’s own bounding box, grown to whole cells, with the shape sitting inside it. Cells are inside or outside — there is no partial cell, because the domains this feeds have no partial cell either.

Implementations§

Source§

impl Voxels

Source

pub fn of(mesh: &Mesh, cell: Length) -> Result<Voxels, String>

Rasterise mesh onto cubes of side cell.

§By scanline, and why the crossings are counted a row at a time

A point-in-mesh test per cell would cast one ray per cell and cost cells × triangles. Casting one ray along x for each (j, k) row and filling between sorted pairs of crossings costs rows × triangles — the same answer for a factor of nx less work, and it is not only faster: a whole row decided from one sorted list of crossings cannot disagree with itself about parity, where per-cell tests can and do near a surface.

§Degenerate rays are detected, perturbed deterministically, and then admitted

Detected, and that word is doing the work. Parity is not enough to find them. A ray through the edge two triangles share hits both, so the count stays even and the two crossings coincide; the row pairs them against each other, fills nothing, and reports success. A cube loses a whole diagonal plane of rows to this at every resolution — 64 cells of 512 on an eight-cell cube — with no error anywhere. So a hit on an edge is a case of its own, distinct from both a miss and a clean crossing, and a row that produces one is retried whatever its parity says.

The retry moves the ray, and the offsets are fixed — a short list of small multiples of the cell — so the same mesh and cell size give bit-for-bit the same voxels on every platform and at every optimisation level, which is a promise the whole workspace makes.

A row still degenerate or still odd after all of them is left empty and counted in Loss::ambiguous_rows. Empty is the honest failure: a hole is visible, and a row filled by guessing which crossing to drop is a wrong shape that looks right.

Refuses an open mesh, because parity has no meaning through a surface with a hole in it.

Source

pub fn onto( mesh: &Mesh, origin: LengthVec, counts: (usize, usize, usize), cell: Length, ) -> Result<Voxels, String>

Rasterise mesh onto a grid somebody else chose: a stated origin, cell count and cell.

This is what assembly needs. Voxels::of gives every mesh its own box and its own origin, so two parts come back on two grids that share no cell and cannot be adjacent to each other — ARCHITECTURE.md names that as the gap that arrives first in practice. Rasterised onto one grid, two parts occupy neighbouring cells of the same array, and a domain that fills from both gets a conducting interface between them for free, because its stencil already crosses a face between cells of different materials.

The grid is the caller’s and the mesh’s coordinates are read as they are written: an STL carries absolute positions, so where two parts sit relative to each other is what their files already say. No pose is applied here — Pose places a domain, and both parts are inside one domain now.

A mesh that does not fit is refused, with both boxes named. Cropping it silently is the failure this workspace keeps finding: a part with its corner cut off runs, audits, renders and answers a question about a different shape.

Source

pub fn counts(&self) -> (usize, usize, usize)

Cells along each axis.

Source

pub fn cell(&self) -> Length

The cell side.

Source

pub fn origin(&self) -> LengthVec

The low corner of cell (0, 0, 0).

Source

pub fn contains(&self, i: usize, j: usize, k: usize) -> bool

Whether a cell is inside the surface. Out-of-range indices are outside.

This is the predicate a domain’s fill takes, and the whole coupling between this crate and the physics:

block(&|i, j, k| voxels.contains(i, j, k));
Source

pub fn filled(&self) -> usize

How many cells are inside.

Source

pub fn volume(&self) -> Volume

The volume those cells occupy.

Source

pub fn loss(&self) -> Loss

What the rasterisation lost. See Loss.

Trait Implementations§

Source§

impl Clone for Voxels

Source§

fn clone(&self) -> Voxels

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Voxels

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.