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
impl ImageData
pub fn new() -> Self
Sourcepub fn with_dimensions(nx: usize, ny: usize, nz: usize) -> Self
pub fn with_dimensions(nx: usize, ny: usize, nz: usize) -> Self
Create an ImageData with given dimensions (number of points in each direction).
pub fn extent(&self) -> [i64; 6]
pub fn set_extent(&mut self, extent: [i64; 6])
pub fn spacing(&self) -> [f64; 3]
pub fn set_spacing(&mut self, spacing: [f64; 3])
pub fn origin(&self) -> [f64; 3]
pub fn set_origin(&mut self, origin: [f64; 3])
Sourcepub fn dimensions(&self) -> [usize; 3]
pub fn dimensions(&self) -> [usize; 3]
Number of points in each dimension.
Sourcepub fn point_from_ijk(&self, i: usize, j: usize, k: usize) -> [f64; 3]
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.
Sourcepub fn ijk_from_index(&self, idx: usize) -> (usize, usize, usize)
pub fn ijk_from_index(&self, idx: usize) -> (usize, usize, usize)
Convert a flat point index to (i, j, k).
Sourcepub fn point_at(&self, idx: usize) -> [f64; 3]
pub fn point_at(&self, idx: usize) -> [f64; 3]
Get point coordinates by flat index (equivalent to point_from_ijk(ijk_from_index(idx))).
Sourcepub fn index_from_ijk(&self, i: usize, j: usize, k: usize) -> usize
pub fn index_from_ijk(&self, i: usize, j: usize, k: usize) -> usize
Convert (i, j, k) to a flat point index.
Sourcepub fn scalar_at(&self, i: usize, j: usize, k: usize) -> Option<f64>
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.
Sourcepub fn point_positions(&self) -> Vec<[f64; 3]>
pub fn point_positions(&self) -> Vec<[f64; 3]>
Iterate over all point coordinates in index order.
Sourcepub fn num_points(&self) -> usize
pub fn num_points(&self) -> usize
Number of points.
pub fn point_data(&self) -> &DataSetAttributes
pub fn point_data_mut(&mut self) -> &mut DataSetAttributes
pub fn cell_data(&self) -> &DataSetAttributes
pub fn cell_data_mut(&mut self) -> &mut DataSetAttributes
Sourcepub fn with_spacing(self, spacing: [f64; 3]) -> Self
pub fn with_spacing(self, spacing: [f64; 3]) -> Self
Builder: set spacing.
Sourcepub fn with_origin(self, origin: [f64; 3]) -> Self
pub fn with_origin(self, origin: [f64; 3]) -> Self
Builder: set origin.
Sourcepub fn from_function(
dims: [usize; 3],
spacing: [f64; 3],
origin: [f64; 3],
name: &str,
f: impl Fn(f64, f64, f64) -> f64,
) -> Self
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]);Sourcepub fn with_point_array(self, array: AnyDataArray) -> Self
pub fn with_point_array(self, array: AnyDataArray) -> Self
Builder: add a point data array.
Trait Implementations§
Source§impl DataObject for ImageData
impl DataObject for ImageData
fn field_data(&self) -> &FieldData
fn field_data_mut(&mut self) -> &mut FieldData
Source§impl DataSet for ImageData
impl DataSet for ImageData
fn num_points(&self) -> usize
fn num_cells(&self) -> usize
fn point(&self, idx: usize) -> [f64; 3]
fn bounds(&self) -> BoundingBox
fn point_data(&self) -> &DataSetAttributes
fn point_data_mut(&mut self) -> &mut DataSetAttributes
fn cell_data(&self) -> &DataSetAttributes
fn cell_data_mut(&mut self) -> &mut DataSetAttributes
Source§fn num_point_arrays(&self) -> usize
fn num_point_arrays(&self) -> usize
Source§fn num_cell_arrays(&self) -> usize
fn num_cell_arrays(&self) -> usize
Source§impl From<ImageData> for AnyDataSet
impl From<ImageData> for AnyDataSet
Auto Trait Implementations§
impl Freeze for ImageData
impl RefUnwindSafe for ImageData
impl Send for ImageData
impl Sync for ImageData
impl Unpin for ImageData
impl UnsafeUnpin for ImageData
impl UnwindSafe for ImageData
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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