Skip to main content

Crate voxelops

Crate voxelops 

Source
Expand description

§voxelops

Operations on dense 3D voxel grids, aimed at scientific and medical data (MRI/CT volumes, microscopy, simulation output) rather than game rendering.

v0.1 features:

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;
}}}

let mask = vol.threshold(50.0);
assert_eq!(mask.count(), 4 * 4 * 4);

let eroded = mask.erode();
assert_eq!(eroded.count(), 2 * 2 * 2);

let mesh = mask.to_mesh();
assert_eq!(mesh.triangles.len(), 6 * 4 * 4 * 2); // 6 cube faces, 16 quads each
let obj = mesh.to_obj();
assert!(obj.starts_with("v "));

§Conventions

  • Voxel data is stored x-fastest (row-major over [z][y][x]); VoxelGrid::as_slice exposes it in that order for interop with existing volume readers.
  • Indexing is grid[[x, y, z]]; use VoxelGrid::get for a bounds-checked Option.
  • Erosion treats out-of-bounds as background, so voxels touching the grid boundary always erode.
  • Mesh vertices sit on grid corners, not voxel centres, and are placed at origin + index * spacing. A single voxel therefore yields a closed cube of 8 vertices and 12 triangles.

The crate has no dependencies and forbids unsafe.

Structs§

Mesh
An indexed triangle mesh in physical coordinates.
VoxelGrid
A dense 3D voxel grid with physical metadata.

Type Aliases§

Mask
A binary segmentation mask; alias of VoxelGrid<bool>.