volren-rs
A pure-Rust volume rendering library for medical imaging, inspired by VTK's domain knowledge.
Built around a two-crate architecture — a CPU-side core with no GPU dependency, and a wgpu-based renderer — so headless pipelines, tests, and server-side code never need a graphics context.
Crates
| Crate | Purpose |
|---|---|
| volren-core | Volume data model, camera, transfer functions, window/level, reslice planes, interaction styles, picking — zero GPU deps |
| volren-gpu | wgpu render pipelines: raycasting, MPR slicing, overlays |
Features
- Volume data model — generic
Volume<T>over sealedScalartypes (u8, i8, u16, i16, f32, f64), type-erasedDynVolume, trilinear sampling, index↔world coordinate transforms - Camera — perspective & orthographic projection, orbit/pan/dolly/zoom, azimuth/elevation/roll
- Transfer functions — piecewise-linear colour & opacity TFs, region-based 2D TFs, RGB/HSV/Lab interpolation, baked LUTs for GPU upload
- Window/level — DICOM-standard mapping with clinical presets (CT Bone, Lung, Brain, Abdomen)
- Reslice (MPR) —
SlicePlanewith axial/coronal/sagittal constructors,point_to_world/world_to_point, thick-slab support - Interaction — windowing-agnostic
MouseEvent/KeyEventtypes,TrackballStyleandImageSliceStyleinteractors - Picking — CPU ray-AABB intersection,
pick_volume()returning world position + voxel value - GPU raycasting — wgpu pipeline with composite/MIP/MinIP/average/additive/isosurface blend modes, Blinn-Phong shading, gradient opacity, adaptive step sizing, clip planes, cropping, opacity correction
- Viewer building blocks — slice rendering, thick-slab MPR, crosshair overlays, orientation marker, off-screen render targets, reduced-resolution interactive rendering
- Large-volume friendly upload — chunked 3D texture uploads avoid single giant staging writes for bigger datasets
- No I/O, no windowing — designed as a library; bring your own data loader and event loop
Quick start
use ;
use ;
// Create a volume from raw voxel data
let volume = from_data.unwrap;
let camera = new_perspective;
let params = builder
.window_level
.step_size_factor
.build;
For GPU rendering, create a VolumeRenderer with your wgpu device:
use DynVolume;
use ;
let dyn_volume: DynVolume = volume.into;
let mut renderer = new;
renderer.set_volume;
renderer.set_render_params?;
renderer.render_volume?;
Design principles
- No
unsafe— both crates use#![deny(unsafe_code)] - No allocations on the render path — uniforms are stack-allocated, LUTs pre-baked
- Separation of concerns — core crate is pure math/data, GPU crate is pure rendering
- Idiomatic Rust — builder patterns,
thiserrorerrors, sealed traits,#[must_use], comprehensive docs - Testable — 94 tests today, including
proptestproperty-based checks for coordinate transforms
Building
Requires Rust 1.87+. The GPU crate needs a wgpu-compatible graphics driver for runtime use, but compiles without one.
Integration with medical imaging
volren-rs is designed to be consumed by a medical viewer application. It pairs naturally with dicom-toolkit-rs for DICOM parsing — feed pixel data into Volume::from_slices() and render.
License
MIT OR Apache-2.0