voxelops 0.1.0

Processing of dense voxel grids for scientific/medical data: thresholding, morphology (erode/dilate), and surface mesh extraction.
Documentation
  • Coverage
  • 100%
    33 out of 33 items documented1 out of 28 items with examples
  • Size
  • Source code size: 36.4 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 326.2 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • faizanali2k05/voxelops
    12 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • faizanali2k05

voxelops

Crates.io Documentation License

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 physical spacing and origin metadata, so results stay in real-world units (mm, µm, …).
  • Thresholding — segment a volume into a binary Mask with threshold.
  • Binary morphology — erode, dilate, open, and close on masks using a 6-connected (face-adjacent) structuring element.
  • Surface extraction — to_mesh emits an indexed triangle mesh of the boundary surface with interior faces culled, deduplicated vertices, and outward-facing winding; export to Wavefront OBJ with to_obj.
  • Measurement — Mesh::surface_area in physical units.

Installation

cargo add voxelops

Or add it to your Cargo.toml:

[dependencies]
voxelops = "0.1"

Quick start

use voxelops::VoxelGrid;

// An 8x8x8 volume with a bright 4x4x4 cube in the middle.
let mut vol = VoxelGrid::filled([8, 8, 8], 0.0f32);
for z in 2..6 {
    for y in 2..6 {
        for x in 2..6 {
            vol[[x, y, z]] = 100.0;
        }
    }
}

// Segment, then clean up small holes.
let mask = vol.threshold(50.0).close();
assert_eq!(mask.count(), 4 * 4 * 4);

// Extract the boundary surface and export it.
let mesh = mask.to_mesh();
assert_eq!(mesh.triangles.len(), 6 * 4 * 4 * 2);
std::fs::write("surface.obj", mesh.to_obj()).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 voxelops::VoxelGrid;

let mut mask = VoxelGrid::filled([64, 64, 40], false)
    .with_spacing([0.5, 0.5, 1.2]) // anisotropic slices, in mm
    .with_origin([-16.0, -16.0, 0.0]);

mask[[10, 10, 10]] = 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:

cargo run --example segment_and_export

Conventions

  • Voxel data is stored x-fastest (row-major over [z][y][x]); as_slice exposes it in that order for zero-copy interop with existing readers.
  • Indexing uses grid[[x, y, z]]. Use get for a bounds-checked Option<&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

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.