Skip to main content

ImageData

Struct ImageData 

Source
pub struct ImageData { /* private fields */ }
Expand description

Regular grid with implicit point coordinates computed from extent, spacing, and origin.

Analogous to VTK’s vtkImageData. Points are not stored explicitly — their coordinates are computed as: point(i,j,k) = origin + spacing * [i, j, k].

The extent is [x_min, x_max, y_min, y_max, z_min, z_max] in index space.

§Examples

use crate::data::ImageData;

// Create a 10x10x10 grid
let img = ImageData::with_dimensions(10, 10, 10);
assert_eq!(img.dimensions(), [10, 10, 10]);

Implementations§

Source§

impl ImageData

Source

pub fn new() -> Self

Source

pub fn with_dimensions(nx: usize, ny: usize, nz: usize) -> Self

Create an ImageData with given dimensions (number of points in each direction).

Source

pub fn extent(&self) -> [i64; 6]

Source

pub fn set_extent(&mut self, extent: [i64; 6])

Source

pub fn spacing(&self) -> [f64; 3]

Source

pub fn set_spacing(&mut self, spacing: [f64; 3])

Source

pub fn origin(&self) -> [f64; 3]

Source

pub fn set_origin(&mut self, origin: [f64; 3])

Source

pub fn dimensions(&self) -> [usize; 3]

Number of points in each dimension.

Source

pub fn point_from_ijk(&self, i: usize, j: usize, k: usize) -> [f64; 3]

Compute the world-space position of a point given its (i, j, k) index.

Source

pub fn ijk_from_index(&self, idx: usize) -> (usize, usize, usize)

Convert a flat point index to (i, j, k).

Source

pub fn point_at(&self, idx: usize) -> [f64; 3]

Get point coordinates by flat index (equivalent to point_from_ijk(ijk_from_index(idx))).

Source

pub fn index_from_ijk(&self, i: usize, j: usize, k: usize) -> usize

Convert (i, j, k) to a flat point index.

Source

pub fn scalar_at(&self, i: usize, j: usize, k: usize) -> Option<f64>

Get the active scalar value at grid position (i, j, k).

Returns None if no active scalars are set.

Source

pub fn point_positions(&self) -> Vec<[f64; 3]>

Iterate over all point coordinates in index order.

Source

pub fn num_points(&self) -> usize

Number of points.

Source

pub fn point_data(&self) -> &DataSetAttributes

Source

pub fn point_data_mut(&mut self) -> &mut DataSetAttributes

Source

pub fn cell_data(&self) -> &DataSetAttributes

Source

pub fn cell_data_mut(&mut self) -> &mut DataSetAttributes

Source

pub fn with_spacing(self, spacing: [f64; 3]) -> Self

Builder: set spacing.

Source

pub fn with_origin(self, origin: [f64; 3]) -> Self

Builder: set origin.

Source

pub fn from_function( dims: [usize; 3], spacing: [f64; 3], origin: [f64; 3], name: &str, f: impl Fn(f64, f64, f64) -> f64, ) -> Self

Create an ImageData with a scalar field generated from a function.

The function receives (x, y, z) world coordinates and returns a scalar value. The result is stored as point data with the given name.

§Examples
use crate::data::ImageData;

// Create a sphere distance field
let img = ImageData::from_function(
    [10, 10, 10], [0.1, 0.1, 0.1], [-0.5, -0.5, -0.5],
    "distance",
    |x, y, z| (x*x + y*y + z*z).sqrt(),
);
assert_eq!(img.dimensions(), [10, 10, 10]);
Source

pub fn with_point_array(self, array: AnyDataArray) -> Self

Builder: add a point data array.

Trait Implementations§

Source§

impl Clone for ImageData

Source§

fn clone(&self) -> ImageData

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 DataObject for ImageData

Source§

impl DataSet for ImageData

Source§

fn num_points(&self) -> usize

Source§

fn num_cells(&self) -> usize

Source§

fn point(&self, idx: usize) -> [f64; 3]

Source§

fn bounds(&self) -> BoundingBox

Source§

fn point_data(&self) -> &DataSetAttributes

Source§

fn point_data_mut(&mut self) -> &mut DataSetAttributes

Source§

fn cell_data(&self) -> &DataSetAttributes

Source§

fn cell_data_mut(&mut self) -> &mut DataSetAttributes

Source§

fn center(&self) -> [f64; 3]

Center of the bounding box.
Source§

fn diagonal(&self) -> f64

Diagonal length of the bounding box.
Source§

fn is_empty(&self) -> bool

Whether the dataset has no points.
Source§

fn num_point_arrays(&self) -> usize

Number of point data arrays.
Source§

fn num_cell_arrays(&self) -> usize

Number of cell data arrays.
Source§

impl Debug for ImageData

Source§

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

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

impl Default for ImageData

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for ImageData

Source§

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

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

impl From<ImageData> for AnyDataSet

Source§

fn from(d: ImageData) -> Self

Converts to this type from the input type.
Source§

impl From<ImageData> for Block

Source§

fn from(id: ImageData) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.