pub struct PolyData {
pub points: Points<f64>,
pub verts: CellArray,
pub lines: CellArray,
pub polys: CellArray,
pub strips: CellArray,
/* private fields */
}Expand description
Polygonal mesh consisting of vertices, lines, polygons, and triangle strips.
Analogous to VTK’s vtkPolyData. Points are stored explicitly, with four
separate CellArrays for the four cell categories.
§Examples
use crate::data::PolyData;
// Create a triangle mesh
let pd = PolyData::from_triangles(
vec![[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]],
vec![[0, 1, 2]],
);
assert_eq!(pd.points.len(), 3);
assert_eq!(pd.polys.num_cells(), 1);Fields§
§points: Points<f64>§verts: CellArray§lines: CellArray§polys: CellArray§strips: CellArrayImplementations§
Source§impl PolyData
impl PolyData
pub fn new() -> Self
Sourcepub fn from_triangles(points: Vec<[f64; 3]>, triangles: Vec<[i64; 3]>) -> Self
pub fn from_triangles(points: Vec<[f64; 3]>, triangles: Vec<[i64; 3]>) -> Self
Create a PolyData from points and triangle connectivity.
Each element of triangles is [i0, i1, i2] indexing into points.
Sourcepub fn from_polygons(points: Vec<[f64; 3]>, cells: Vec<Vec<i64>>) -> Self
pub fn from_polygons(points: Vec<[f64; 3]>, cells: Vec<Vec<i64>>) -> Self
Create a PolyData from points and generic polygon cells.
Each element of cells is a Vec of point indices for one polygon.
Supports mixed triangle/quad/polygon meshes.
Sourcepub fn from_quads(points: Vec<[f64; 3]>, quads: Vec<[i64; 4]>) -> Self
pub fn from_quads(points: Vec<[f64; 3]>, quads: Vec<[i64; 4]>) -> Self
Create a PolyData from points and quad connectivity.
Each element of quads is [i0, i1, i2, i3] indexing into points.
Sourcepub fn from_lines(points: Vec<[f64; 3]>, segments: Vec<[i64; 2]>) -> Self
pub fn from_lines(points: Vec<[f64; 3]>, segments: Vec<[i64; 2]>) -> Self
Create a PolyData with line cells.
Each element of segments is [i0, i1] indexing into points.
Sourcepub fn from_flat_arrays(coords: &[f64], indices: &[i64]) -> Self
pub fn from_flat_arrays(coords: &[f64], indices: &[i64]) -> Self
Create a PolyData from flat coordinate and index arrays.
coords is [x0,y0,z0, x1,y1,z1, ...] (length must be divisible by 3).
indices is [i0,i1,i2, i3,i4,i5, ...] (length must be divisible by 3, triangles).
This is the most common format when receiving data from other libraries, GPU buffers, or numpy arrays.
use crate::data::PolyData;
let pd = PolyData::from_flat_arrays(
&[0.0,0.0,0.0, 1.0,0.0,0.0, 0.0,1.0,0.0],
&[0, 1, 2],
);
assert_eq!(pd.points.len(), 3);
assert_eq!(pd.polys.num_cells(), 1);Sourcepub fn from_points(points: Vec<[f64; 3]>) -> Self
pub fn from_points(points: Vec<[f64; 3]>) -> Self
Create a PolyData with points only (no cells).
Useful for point clouds that will later have cells added.
Sourcepub fn from_vertices(points: Vec<[f64; 3]>) -> Self
pub fn from_vertices(points: Vec<[f64; 3]>) -> Self
Create a PolyData with vertex cells (one vertex per point).
Sourcepub fn from_polyline(points: Vec<[f64; 3]>) -> Self
pub fn from_polyline(points: Vec<[f64; 3]>) -> Self
Create a PolyData with a single polyline through all points.
Sourcepub fn push_point(&mut self, point: [f64; 3]) -> i64
pub fn push_point(&mut self, point: [f64; 3]) -> i64
Push a single point and return its index.
Sourcepub fn push_triangle(&mut self, i0: i64, i1: i64, i2: i64)
pub fn push_triangle(&mut self, i0: i64, i1: i64, i2: i64)
Push a triangle cell from 3 point indices.
Sourcepub fn push_quad(&mut self, i0: i64, i1: i64, i2: i64, i3: i64)
pub fn push_quad(&mut self, i0: i64, i1: i64, i2: i64, i3: i64)
Push a quad cell from 4 point indices.
Sourcepub fn total_cells(&self) -> usize
pub fn total_cells(&self) -> usize
Total number of cells across all four categories.
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 field_data(&self) -> &FieldData
pub fn field_data(&self) -> &FieldData
Access field data directly (convenience, same as DataObject::field_data).
Sourcepub fn field_data_mut(&mut self) -> &mut FieldData
pub fn field_data_mut(&mut self) -> &mut FieldData
Mutable access to field data.
Sourcepub fn reverse_cells(&mut self)
pub fn reverse_cells(&mut self)
Reverse the winding order of all polygon cells.
Useful for flipping normals direction.
Sourcepub fn with_point_array(self, array: AnyDataArray) -> Self
pub fn with_point_array(self, array: AnyDataArray) -> Self
Builder: add a point data array.
Sourcepub fn with_cell_array(self, array: AnyDataArray) -> Self
pub fn with_cell_array(self, array: AnyDataArray) -> Self
Builder: add a cell data array.
Sourcepub fn with_active_scalars(self, name: &str) -> Self
pub fn with_active_scalars(self, name: &str) -> Self
Builder: set active scalars by name.
Sourcepub fn from_xyz_arrays(
x: &[f64],
y: &[f64],
z: &[f64],
triangles: &[[i64; 3]],
) -> Self
pub fn from_xyz_arrays( x: &[f64], y: &[f64], z: &[f64], triangles: &[[i64; 3]], ) -> Self
Create from separate X, Y, Z coordinate arrays and triangle indices.
Sourcepub fn num_triangles(&self) -> usize
pub fn num_triangles(&self) -> usize
Count actual triangles (cells with exactly 3 points).
Sourcepub fn bounding_sphere(&self) -> ([f64; 3], f64)
pub fn bounding_sphere(&self) -> ([f64; 3], f64)
Compute a bounding sphere: (center, radius).
Sourcepub fn is_all_triangles(&self) -> bool
pub fn is_all_triangles(&self) -> bool
Whether all polygon cells are triangles.
Sourcepub fn add_scalars(&mut self, name: &str, values: Vec<f64>)
pub fn add_scalars(&mut self, name: &str, values: Vec<f64>)
Add a scalar (1-component f64) point data array and set it as active scalars.
use crate::data::PolyData;
let mut pd = PolyData::from_triangles(
vec![[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]],
vec![[0, 1, 2]],
);
pd.add_scalars("temperature", vec![10.0, 20.0, 30.0]);
assert_eq!(pd.get_scalars("temperature"), Some(vec![10.0, 20.0, 30.0]));Sourcepub fn add_vectors(&mut self, name: &str, values: Vec<[f64; 3]>)
pub fn add_vectors(&mut self, name: &str, values: Vec<[f64; 3]>)
Add a vector (3-component f64) point data array.
Sourcepub fn get_scalars(&self, name: &str) -> Option<Vec<f64>>
pub fn get_scalars(&self, name: &str) -> Option<Vec<f64>>
Get scalar values by name as Vec<f64>. Returns None if array not found.
Sourcepub fn get_vectors(&self, name: &str) -> Option<Vec<[f64; 3]>>
pub fn get_vectors(&self, name: &str) -> Option<Vec<[f64; 3]>>
Get vector values by name. Returns None if array not found.
Trait Implementations§
Source§impl DataObject for PolyData
impl DataObject for PolyData
fn field_data(&self) -> &FieldData
fn field_data_mut(&mut self) -> &mut FieldData
Source§impl DataSet for PolyData
impl DataSet for PolyData
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<PolyData> for AnyDataSet
impl From<PolyData> for AnyDataSet
impl StructuralPartialEq for PolyData
Auto Trait Implementations§
impl Freeze for PolyData
impl RefUnwindSafe for PolyData
impl Send for PolyData
impl Sync for PolyData
impl Unpin for PolyData
impl UnsafeUnpin for PolyData
impl UnwindSafe for PolyData
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