voxelops
Processing of dense 3D voxel grids for scientific and medical data — MRI/CT volumes, microscopy stacks, and simulation output — rather than game rendering.
Zero dependencies, #![forbid(unsafe_code)], MSRV 1.75.
Features
VoxelGrid<T>— a dense 3D grid carrying physicalspacingandoriginmetadata, so results stay in real-world units (mm, µm, …).- Thresholding — segment a volume into a binary
Maskwiththreshold. - Binary morphology —
erode,dilate,open, andcloseon masks using a 6-connected (face-adjacent) structuring element. - Surface extraction —
to_meshemits an indexed triangle mesh of the boundary surface with interior faces culled, deduplicated vertices, and outward-facing winding; export to Wavefront OBJ withto_obj. - Measurement —
Mesh::surface_areain physical units.
Installation
Or add it to your Cargo.toml:
[]
= "0.1"
Quick start
use VoxelGrid;
// An 8x8x8 volume with a bright 4x4x4 cube in the middle.
let mut vol = filled;
for z in 2..6
// Segment, then clean up small holes.
let mask = vol.threshold.close;
assert_eq!;
// Extract the boundary surface and export it.
let mesh = mask.to_mesh;
assert_eq!;
write.unwrap;
Physical coordinates
A grid indexed in voxels can carry the scanner geometry it came from. Meshes
are emitted in those physical coordinates, so surface_area is directly
meaningful:
use VoxelGrid;
let mut mask = filled
.with_spacing // anisotropic slices, in mm
.with_origin;
mask = true;
let area_mm2 = mask.to_mesh.surface_area;
Examples
Run the bundled example, which writes a sphere.obj you can open in any 3D
viewer:
Conventions
- Voxel data is stored x-fastest (row-major over
[z][y][x]);as_sliceexposes it in that order for zero-copy interop with existing readers. - Indexing uses
grid[[x, y, z]]. Usegetfor a bounds-checkedOption<&T>. - Erosion treats out-of-bounds as background, so voxels touching the grid boundary always erode.
- Mesh vertices sit on grid corners, not voxel centres: a single voxel produces a closed cube of 8 vertices and 12 triangles.
Roadmap
v0.1 covers dense grids, 6-connectivity morphology, and boundary-face meshing.
Planned: marching cubes for smooth isosurfaces, 26-connectivity structuring
elements, connected-component labelling, and distance transforms.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.