Skip to main content

Volume

Struct Volume 

Source
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>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn scalar_range(&self) -> (f64, f64)

Compute the (min, max) scalar range of all voxels.

The result is computed once and cached.

Source

pub fn as_bytes(&self) -> &[u8]

Raw byte slice of the voxel data, suitable for GPU upload.

Source

pub fn data(&self) -> &[T]

Borrow the typed scalar buffer.

Trait Implementations§

Source§

impl<T: Clone + Scalar> Clone for Volume<T>

Source§

fn clone(&self) -> Volume<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Scalar> Debug for Volume<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Volume<f32>> for DynVolume

Source§

fn from(v: Volume<f32>) -> Self

Converts to this type from the input type.
Source§

impl From<Volume<f64>> for DynVolume

Source§

fn from(v: Volume<f64>) -> Self

Converts to this type from the input type.
Source§

impl From<Volume<i16>> for DynVolume

Source§

fn from(v: Volume<i16>) -> Self

Converts to this type from the input type.
Source§

impl From<Volume<i32>> for DynVolume

Source§

fn from(v: Volume<i32>) -> Self

Converts to this type from the input type.
Source§

impl From<Volume<i8>> for DynVolume

Source§

fn from(v: Volume<i8>) -> Self

Converts to this type from the input type.
Source§

impl From<Volume<u16>> for DynVolume

Source§

fn from(v: Volume<u16>) -> Self

Converts to this type from the input type.
Source§

impl From<Volume<u32>> for DynVolume

Source§

fn from(v: Volume<u32>) -> Self

Converts to this type from the input type.
Source§

impl From<Volume<u8>> for DynVolume

Source§

fn from(v: Volume<u8>) -> Self

Converts to this type from the input type.
Source§

impl<T: Scalar> VolumeInfo for Volume<T>

Source§

fn dimensions(&self) -> UVec3

Number of voxels along each axis: [nx, ny, nz].
Source§

fn spacing(&self) -> DVec3

Physical size of each voxel in world units (typically millimetres).
Source§

fn origin(&self) -> DVec3

World-space position of voxel (0, 0, 0).
Source§

fn direction(&self) -> DMat3

3×3 orientation matrix whose columns are the axis directions. For axis-aligned volumes this is the identity matrix.
Source§

fn components(&self) -> u32

Number of scalar values stored per voxel (1 for grayscale).
Source§

fn index_to_world(&self, ijk: DVec3) -> DVec3

Convert a continuous voxel index (i, j, k) to world coordinates. Read more
Source§

fn world_to_index(&self, xyz: DVec3) -> DVec3

Convert world coordinates to a continuous voxel index. Read more
Source§

fn world_bounds(&self) -> Aabb

Axis-aligned bounding box enclosing all voxel centres in world space.

Auto Trait Implementations§

§

impl<T> !Freeze for Volume<T>

§

impl<T> !RefUnwindSafe for Volume<T>

§

impl<T> Send for Volume<T>

§

impl<T> !Sync for Volume<T>

§

impl<T> Unpin for Volume<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Volume<T>

§

impl<T> UnwindSafe for Volume<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.