Skip to main content

PolyData

Struct PolyData 

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

Implementations§

Source§

impl PolyData

Source

pub fn new() -> Self

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

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.

Source

pub fn from_vertices(points: Vec<[f64; 3]>) -> Self

Create a PolyData with vertex cells (one vertex per point).

Source

pub fn from_polyline(points: Vec<[f64; 3]>) -> Self

Create a PolyData with a single polyline through all points.

Source

pub fn push_point(&mut self, point: [f64; 3]) -> i64

Push a single point and return its index.

Source

pub fn push_triangle(&mut self, i0: i64, i1: i64, i2: i64)

Push a triangle cell from 3 point indices.

Source

pub fn push_quad(&mut self, i0: i64, i1: i64, i2: i64, i3: i64)

Push a quad cell from 4 point indices.

Source

pub fn push_line(&mut self, i0: i64, i1: i64)

Push a line cell from 2 point indices.

Source

pub fn total_cells(&self) -> usize

Total number of cells across all four categories.

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 field_data(&self) -> &FieldData

Access field data directly (convenience, same as DataObject::field_data).

Source

pub fn field_data_mut(&mut self) -> &mut FieldData

Mutable access to field data.

Source

pub fn reverse_cells(&mut self)

Reverse the winding order of all polygon cells.

Useful for flipping normals direction.

Source

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

Builder: add a point data array.

Source

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

Builder: add a cell data array.

Source

pub fn with_active_scalars(self, name: &str) -> Self

Builder: set active scalars by name.

Source

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.

Source

pub fn append(&mut self, other: &PolyData)

Append another PolyData in-place (mutates self).

Source

pub fn num_polys(&self) -> usize

Number of polygon faces.

Source

pub fn num_triangles(&self) -> usize

Count actual triangles (cells with exactly 3 points).

Source

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

Compute the centroid (average position of all points).

Source

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

Compute a bounding sphere: (center, radius).

Source

pub fn is_all_triangles(&self) -> bool

Whether all polygon cells are triangles.

Source

pub fn num_lines(&self) -> usize

Number of line cells.

Source

pub fn num_verts(&self) -> usize

Number of vertex cells.

Source

pub fn num_edges(&self) -> usize

Count unique edges in the polygon mesh.

Source

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]));
Source

pub fn add_vectors(&mut self, name: &str, values: Vec<[f64; 3]>)

Add a vector (3-component f64) point data array.

Source

pub fn get_scalars(&self, name: &str) -> Option<Vec<f64>>

Get scalar values by name as Vec<f64>. Returns None if array not found.

Source

pub fn get_vectors(&self, name: &str) -> Option<Vec<[f64; 3]>>

Get vector values by name. Returns None if array not found.

Source

pub fn summary(&self) -> String

Human-readable summary of the PolyData.

Source

pub fn to_table(&self) -> Table

Convert point coordinates and point data to a Table.

Creates columns “x”, “y”, “z” from point coordinates, plus one column per point data array.

Source

pub fn approx_eq(&self, other: &PolyData, tolerance: f64) -> bool

Check approximate equality with another PolyData (for testing).

Trait Implementations§

Source§

impl Clone for PolyData

Source§

fn clone(&self) -> PolyData

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 PolyData

Source§

impl DataSet for PolyData

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 PolyData

Source§

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

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

impl Default for PolyData

Source§

fn default() -> PolyData

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

impl Display for PolyData

Source§

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

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

impl From<PolyData> for AnyDataSet

Source§

fn from(d: PolyData) -> Self

Converts to this type from the input type.
Source§

impl From<PolyData> for Block

Source§

fn from(pd: PolyData) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for PolyData

Source§

fn eq(&self, other: &PolyData) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for PolyData

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.