pub struct Volume<T: Scalar> { /* private fields */ }Expand description
A regular 3D grid of scalar values stored contiguously in memory.
The memory layout is X-fastest (row-major in image terms):
data[x + y * nx + z * nx * ny] for single-component data.
§VTK Equivalent
vtkImageData with scalar data in PointData.
§Type Parameter
T must implement Scalar, which is sealed to known numeric types.
Implementations§
Source§impl<T: Scalar> Volume<T>
impl<T: Scalar> Volume<T>
Sourcepub fn from_data(
data: Vec<T>,
dimensions: UVec3,
spacing: DVec3,
origin: DVec3,
direction: DMat3,
components: u32,
) -> Result<Self, VolumeError>
pub fn from_data( data: Vec<T>, dimensions: UVec3, spacing: DVec3, origin: DVec3, direction: DMat3, components: u32, ) -> Result<Self, VolumeError>
Create a volume from a flat voxel buffer.
data.len() must equal dimensions.x * dimensions.y * dimensions.z * components.
§Errors
Returns VolumeError if dimensions, spacing, or data length are invalid.
Sourcepub fn from_slices(
slices: &[&[T]],
width: u32,
height: u32,
spacing: DVec3,
origin: DVec3,
direction: DMat3,
) -> Result<Self, VolumeError>
pub fn from_slices( slices: &[&[T]], width: u32, height: u32, spacing: DVec3, origin: DVec3, direction: DMat3, ) -> Result<Self, VolumeError>
Assemble a volume from a sequence of 2D frames stacked along Z.
Each slice must have exactly width * height scalars in row-major order
(X-fastest). Useful when building a volume from DICOM slices.
§Errors
Returns VolumeError if any slice has the wrong length or inputs are invalid.
Sourcepub fn get(&self, x: u32, y: u32, z: u32) -> Option<T>
pub fn get(&self, x: u32, y: u32, z: u32) -> Option<T>
Direct voxel access by integer index (component 0).
Returns None if any index is out of bounds.
Sourcepub fn sample_linear(&self, ijk: DVec3) -> Option<f64>
pub fn sample_linear(&self, ijk: DVec3) -> Option<f64>
Sample with trilinear interpolation at a continuous voxel index.
Returns None if the index falls outside [0, dims-1] on any axis.
Only samples the first component for multi-component volumes.
Sourcepub fn sample_nearest(&self, ijk: DVec3) -> Option<T>
pub fn sample_nearest(&self, ijk: DVec3) -> Option<T>
Sample nearest-neighbour at a continuous voxel index.
Returns None if the index falls outside the volume.
Sourcepub fn scalar_range(&self) -> (f64, f64)
pub fn scalar_range(&self) -> (f64, f64)
Compute the (min, max) scalar range of all voxels.
The result is computed once and cached.
Trait Implementations§
Source§impl<T: Scalar> VolumeInfo for Volume<T>
impl<T: Scalar> VolumeInfo for Volume<T>
Source§fn dimensions(&self) -> UVec3
fn dimensions(&self) -> UVec3
[nx, ny, nz].Source§fn spacing(&self) -> DVec3
fn spacing(&self) -> DVec3
Source§fn direction(&self) -> DMat3
fn direction(&self) -> DMat3
Source§fn components(&self) -> u32
fn components(&self) -> u32
Source§fn index_to_world(&self, ijk: DVec3) -> DVec3
fn index_to_world(&self, ijk: DVec3) -> DVec3
(i, j, k) to world coordinates. Read more