PolyData#
- class PolyData(*args, **kwargs)[source]#
Dataset consisting of surface geometry (for example, vertices, lines, and polygons).
The surface geometry is defined by its
pointsand four separate cell connectivity arrays:vertsfor 0-dimensionalVERTEXandPOLY_VERTEXcells.stripsfor 2-dimensionalTRIANGLE_STRIPcells.
Cell types can be mixed, and any combination of cell connectivity arrays may be specified.
PolyDatacan be initialized in several ways:Create an empty mesh
Initialize from a vtkPolyData
Using points only
Using points with
verts, faces, lines, and/or stripsFrom a file
If a points array is provided with no cell connectivity, the
vertsconnectivity is populated by default, and each point is automatically associated with a singleVERTEXto create a point cloud wheren_vertsequalsn_points.- Parameters:
- var_inpvtkPolyData,
str, sequence,optional Flexible input type. Can be a vtkPolyData, in which case this PolyData object will be copied if
deep=Trueand will be a shallow copy ifdeep=False.Also accepts a path, which may be local path as in
'my_mesh.stl'or global path like'/tmp/my_mesh.ply'or'C:/Users/user/my_mesh.ply'.Otherwise, this must be a points array or list containing one or more points. Each point must have 3 dimensions. If
faces,lines,strips, andvertsare allNone, then thePolyDataobject will be created with vertex cells withn_vertsequal to the number ofpoints.- faces
CellArrayLike,optional Connectivity of polygonal
faces. Can be either a padded connectivity array or an explicit cell array object.In the padded array format, faces must contain padding indicating the number of points in the face. For example, the two faces
[10, 11, 12]and[20, 21, 22, 23]will be represented as[3, 10, 11, 12, 4, 20, 21, 22, 23]. This lets you have an arbitrary number of points per face.- lines
CellArrayLike,optional Connectivity of
lines. Likefaces, this can be either a padded connectivity array or an explicit cell array object. The padded array format requires padding indicating the number of points in a line segment. For example, the two line segments[0, 1]and[1, 2, 3, 4]will be represented as[2, 0, 1, 4, 1, 2, 3, 4].- strips
CellArrayLikeoptional Connectivity of triangle
strips. Triangle strips require an initial triangle, and the following points of the strip. Each triangle is built with the new point and the two previous points.Just as in
linesandfaces, this connectivity can be specified as either a padded array or an explicit cell array object. The padded array requires a padding indicating the number of points. For example, a single triangle strip of the 10 point indices[0, 1, 2, 3, 6, 7, 4, 5, 0, 1]requires padding of10and should be input as[10, 0, 1, 2, 3, 6, 7, 4, 5, 0, 1].- deepbool,
optional Whether to copy the inputs, or to create a mesh from them without copying them. Setting
deep=Trueensures that the original arrays can be modified outside the mesh without affecting the mesh. Default isFalse.- force_ext
str,optional If initializing from a file, force the reader to treat the file as if it had this extension as opposed to the one in the file.
- force_floatbool,
optional Casts the datatype to
float32if points datatype is non-float. DefaultTrue. Set this toFalseto allow non-float types, though this may lead to truncation of intermediate floats when transforming datasets.- verts
CellArrayLike,optional The
vertsconnectivity. Likefaces,lines, andstripsthis can be supplied as either a padded array or an explicit cell array object. In the padded array format, the padding indicates the number of vertices in each cell. For example,[1, 0, 1, 1, 1, 2]indicates three vertex cells each with one point, and[2, 0, 1, 2, 2, 3]indicates two polyvertex cells each with two points.- validatebool |
MeshValidationFields| sequence[MeshValidationFields], default:False Validate the mesh using
validate_mesh()after initialization. Set this toTrueto validate all fields, or specify any combination of fields allowed byvalidate_mesh.Added in version 0.47.
- var_inpvtkPolyData,
Examples#
Download Python source code | Download Jupyter notebook
>>> import vtk
>>> import numpy as np
>>> from pyvista import examples
>>> import pyvista as pv
Seed random number generator for reproducible plots
>>> rng = np.random.default_rng(seed=0)
Create an empty mesh.
>>> mesh = pv.PolyData()
Initialize from a vtkPolyData object.
>>> vtkobj = vtk.vtkPolyData()
>>> mesh = pv.PolyData(vtkobj)
Initialize from just points, creating vertices
>>> points = np.array([[0, 0, 0], [1, 0, 0], [1, 0.5, 0], [0, 0.5, 0]])
>>> mesh = pv.PolyData(points)
Initialize from points and faces, creating polygonal faces.
Initialize from points and lines.
Initialize from points and triangle strips.
>>> strips = np.hstack([[4, 0, 1, 3, 2]])
>>> mesh = pv.PolyData(points, strips=strips)
It is also possible to create with multiple cell types.
Initialize from a filename.
>>> mesh = pv.PolyData(examples.antfile)
Construct a set of random line segments using a pv.CellArray.
Because every line in this example has the same size, in this case
two points, we can use pv.CellArray.from_regular_cells to
construct the lines cell array. This is the most efficient
method to construct a cell array.
>>> n_points = 20
>>> n_lines = n_points // 2
>>> points = rng.random((n_points, 3))
>>> lines = rng.integers(low=0, high=n_points, size=(n_lines, 2))
>>> mesh = pv.PolyData(points, lines=pv.CellArray.from_regular_cells(lines))
>>> mesh.cell_data['line_idx'] = np.arange(n_lines)
>>> mesh.plot(scalars='line_idx')
Construct a set of random triangle strips using a pv.CellArray.
Because each strip in this example can have a different number
of points, we use pv.CellArray.from_irregular_cells to construct
the strips cell array.
>>> n_strips = 4
>>> n_verts_per_strip = rng.integers(low=3, high=7, size=n_strips)
>>> n_points = 10 * sum(n_verts_per_strip)
>>> points = rng.random((n_points, 3))
>>> strips = [
... rng.integers(low=0, high=n_points, size=nv) for nv in n_verts_per_strip
... ]
>>> mesh = pv.PolyData(
... points, strips=pv.CellArray.from_irregular_cells(strips)
... )
>>> mesh.cell_data['strip_idx'] = np.arange(n_strips)
>>> mesh.plot(show_edges=True, scalars='strip_idx')
Construct a mesh reusing the faces pv.CellArray from another
mesh. The VTK methods GetPolys, GetLines, GetStrips, and
GetVerts return the underlying CellArray objects for the faces,
lines, strips, and verts properties respectively.
Reusing cell arrays like this can be a performance optimization for
large meshes because it avoids allocating new arrays.
>>> small_sphere = pv.Sphere().compute_normals()
>>> inflated_points = (
... small_sphere.points + 0.1 * small_sphere.point_data['Normals']
... )
>>> larger_sphere = pv.PolyData(inflated_points, faces=small_sphere.GetPolys())
>>> pl = pv.Plotter()
>>> _ = pl.add_mesh(small_sphere, color='red', show_edges=True)
>>> _ = pl.add_mesh(larger_sphere, color='blue', opacity=0.3, show_edges=True)
>>> pl.show()
See Also#
Used In#
Guides
- PyVista Data Model (4 uses)
- Transitioning From VTK to PyVista (2 uses)
- Overview (1 use)
- What Is a Mesh? (1 use)
Docstring Examples
Actor.clear_point_sprite_shape(1 use)Actor.disable_maximum_intensity_projection(1 use)Actor.enable_maximum_intensity_projection(1 use)Actor.set_point_sprite_shape(1 use)DataObjectFilters.sample(1 use)32 more
DataSet.is_empty(1 use)DataSetFilters.interpolate(1 use)DataSetFilters.sample_over_line(1 use)DataSetFilters.sample_over_multiple_lines(1 use)MultiBlock.clean(1 use)MultiBlock.flatten(1 use)MultiBlock.get(1 use)MultiBlock.get_block(1 use)Plotter.add_mesh(1 use)Plotter.export_gltf(1 use)PointGaussianMapper.scale_array(1 use)PolyData.n_faces(1 use)PolyData.n_strips(1 use)PolyData.n_verts(1 use)PolyData.vert_connectivity(1 use)PolyData.vert_offsets(1 use)PolyData.verts(1 use)PolyDataFilters.clean(1 use)PolyDataFilters.decimate_polyline(1 use)PolyDataFilters.delaunay_2d(1 use)PolyDataFilters.remove_unused_points(1 use)PolyDataFilters.ribbon(1 use)PolyDataFilters.ruled_surface(1 use)PolyDataFilters.subdivide_adaptive(1 use)Readers and Writers(1 use)Theme.allow_empty_mesh(1 use)Transform.apply(1 use)UnstructuredGridFilters.delaunay_2d(1 use)allow_new_attributes(1 use)register_dataset_accessor(1 use)set_new_attribute(1 use)vtk_snake_case(1 use)
Gallery Examples
Inheritance#
Inherited members are documented on _PointSetBase, DataSet, _BoundsSizeMixin, PolyDataFilters, DataSetFilters, DataObjectFilters, DataObject.
See them all under Inherited Attributes, Inherited Methods and Filters.
Wraps vtkPolyData.
Attributes#
Return the cell normals. |
|
Return the connectivity array of the polygonal faces. |
|
Return the cell normals. |
|
Return the offsets array of the polygonal faces. |
|
Return the polygonal faces padded connectivity array. |
|
Return a tuple of face arrays. |
|
Return if all the faces of the |
|
Return if the mesh is manifold (no open edges). |
|
Return the connectivity array of the line cells. |
|
Return the offsets array of the line cells. |
|
Return the lines connectivity array. |
|
Return the number of polygonal faces. |
|
Return the number of polygonal faces. |
|
Return the number of line cells. |
|
Return the number of open edges on this mesh. |
|
Return the number of triangle strips. |
|
Return the number of vertex cells. |
|
Return the OBB tree of the polydata. |
|
Return the point normals. |
|
Return a face array of point indices when all faces have the same size. |
|
Return the connectivity array of the triangle strips. |
|
Return the offsets array of the triangle strips. |
|
Return or set the strips padded connectivity array. |
|
Return the connectivity array of the vertex cells. |
|
Return the offsets array of the vertex cells. |
|
Return or set the vertex padded connectivity array. |
|
Return the approximate volume of the dataset. |
Inherited Attributes#
Return the active normals as an array. |
|
Return the active scalars as an array. |
|
Return the active scalar’s association and name. |
|
Return the name of the active scalars. |
|
Return the active tensors array. |
|
Return the active tensor’s field and name: [field, name]. |
|
Return the name of the active tensor array. |
|
Return the active texture coordinates on the points. |
|
Return the active vectors array. |
|
Return the active vector’s association and name. |
|
Return the name of the active vectors array. |
|
Return the actual size of the dataset object. |
|
Return the mesh area if 2D. |
|
Return a list of array names for the dataset. |
|
Return a glyph representation of the active vector data as arrows. |
|
Compute the radius and center of a bounding sphere. |
|
Return the bounding box of this dataset. |
|
Return the size of each axis of the object’s bounding box. |
|
A generator that provides an easy way to loop over all cells. |
|
Return cell data as DataSetAttributes. |
|
Set or return the center of the bounding box. |
|
Return the number of spatial dimensions spanned by this dataset’s points. |
|
Return the set of distinct cell types in this dataset. |
|
Return FieldData as DataSetAttributes. |
|
Return True if the mesh contains any non-linear cells. |
|
Return |
|
Return the length of the diagonal of the bounding box. |
|
Return the maximum spatial dimensionality of all cells in this mesh. |
|
Get address of the underlying VTK C++ object. |
|
Get the minimum spatial dimensionality of all cells in this mesh. |
|
Return the number of arrays present in the dataset. |
|
Return the number of cells in the entire dataset. |
|
Return the number of points in the entire dataset. |
|
Return the number of cells. |
|
Return the number of points. |
|
Return point data as DataSetAttributes. |
|
Return a reference to the points as a NumPy object. |
|
Set or return a user-specified data dictionary. |
Methods#
|
Alternate |
|
Alternate |
|
Write a surface mesh to disk. |
Inherited Methods#
Add field data. |
|
Convert this |
|
Extract the points of this dataset and return a |
|
Extract the points of this dataset and return a |
|
Get a new representation of this object as a |
|
Get the cell neighbors of the ind-th cell. |
|
Get consecutive levels of cell neighbors. |
|
Return the coordinates for the center of mass of the mesh. |
|
Remove all cell arrays. |
|
Remove all arrays from point/cell/field data. |
|
Remove all field data. |
|
Remove all point arrays. |
|
Return a copy of the object. |
|
Copy the data attributes of the input dataset object. |
|
Overwrite this dataset in-place with the new dataset’s geometries and data. |
|
Copy pyvista meta data onto this object from another object. |
|
Copy the structure (geometry and topology) of the input dataset object. |
|
Overwrite this data object with another data object as a deep copy. |
|
Find the index of cells whose bounds intersect a line. |
|
Find the index of cells that intersect a line. |
|
Find the index of cells in this mesh within bounds. |
|
Find index of closest cell in this mesh to the given point. |
|
Find index of closest point in this mesh to the given point. |
|
Find index of a cell that contains the given point. |
|
Search both point, cell, and field data for an array. |
|
Get the association of an array. |
|
Return a |
|
Get the min and max of a named array. |
|
Return the header stats of this dataset. |
|
Locate points and cell ids that intersect a line. |
|
Plot a PyVista, NumPy, or VTK object. |
|
Get the cell IDs that use the ind-th point. |
|
Return whether one or more points are inside a cell. |
|
Get the point neighbors of the ind-th point. |
|
Get consecutive levels of point neighbors. |
|
Convert the points datatype to double precision. |
|
Remove cells. |
|
Change array name by searching for the array then renaming it. |
|
Find the scalars by name and appropriately sets it as active. |
|
Find the tensors by name and appropriately sets it as active. |
|
Find the vectors by name and appropriately sets it as active. |
|
Create a shallow copy from a different dataset into this one. |
|
Return this dataset’s point or cell arrays as a |
|
Return this dataset’s point or cell arrays as a |
Filters#
Align a dataset to another. |
|
Align a dataset to the x-y-z axes. |
|
Append one or more PolyData into this one. |
|
Perform a boolean difference operation between two meshes. |
|
Perform a boolean intersection operation on two meshes. |
|
Perform a boolean union operation on two meshes. |
|
Return a bounding box for this dataset. |
|
Generate points at the center of the cells in this dataset. |
|
Transform cell data into point data. |
|
Compute a function of (geometric) quality for each cell of a mesh. |
|
Check the validity of each cell in this dataset. |
|
Clean the mesh. |
|
Clip a dataset by a plane by specifying the origin and normal. |
|
Clip a dataset by a bounding box defined by the bounds. |
|
Clip a closed polydata surface with a plane. |
|
Clip a dataset by a scalar. |
|
Clip a dataset by a slab of finite thickness around a plane. |
|
Clip any mesh type using a |
|
Perform collision determination between two polyhedral surfaces. |
|
Add RGB(A) scalars to labeled data. |
|
Compute the arc length over the length of the probed line. |
|
Compute metrics on the boundary faces of a mesh. |
|
Compute sizes for 0D (vertex count), 1D (length), 2D (area) and 3D (volume) cells. |
|
Compute derivative-based quantities of point/cell scalar field. |
|
Compute the implicit distance from the points to a surface. |
|
Compute point and/or cell normals for a mesh. |
|
Find and label connected regions. |
|
Contour an input self by an array. |
|
Generate filled contours. |
|
Compute the convex hull from this mesh’s points. |
|
Transform cell data into point data. |
|
Return the point-wise curvature of a mesh. |
|
Reduce the number of triangles in a triangular mesh using vtkQuadricDecimation. |
|
Return a decimated version of a triangulation of the boundary. |
|
Reduce the number of lines in a polyline mesh. |
|
Reduce the number of triangles in a triangular mesh. |
|
Apply a 2D Delaunay filter along the best fitting plane. |
|
Construct a 3D Delaunay triangulation of the mesh. |
|
Return a mask of the points of a surface mesh with a surface angle greater than angle. |
|
Generate scalar values on a dataset. |
|
Push each individual cell away from the center of the dataset. |
|
Extract all the internal/external edges of the dataset as PolyData. |
|
Return a subset of the grid. |
|
Extract cells of a specified type. |
|
Extract edges from the surface of the mesh. |
|
Extract the outer surface of a volume or structured grid dataset. |
|
Extract largest connected set in mesh. |
|
Return a subset of the grid (with cells) that contains any of the given point indices. |
|
Extract surface geometry of the mesh as |
|
Return a subset of the mesh based on the values of point or cell data. |
|
Sweep polygonal data creating a “skirt” from free edges. |
|
Sweep polygonal data creating “skirt” from free edges/lines, and lines from vertices. |
|
Extrude polygonal data trimmed by a surface. |
|
Fill holes in a |
|
Flip the orientation of the faces. |
|
Flip mesh about the normal. |
|
Flip the direction of the mesh’s point and cell normal vectors. |
|
Flip normals of a triangular mesh by reversing the point ordering. |
|
Flip mesh about the x-axis. |
|
Flip mesh about the y-axis. |
|
Flip mesh about the z-axis. |
|
Splat points into a volume using a Gaussian distribution. |
|
Calculate the geodesic path between two vertices using Dijkstra’s algorithm. |
|
Calculate the geodesic distance between two vertices using Dijkstra’s algorithm. |
|
Copy a geometric representation (called a glyph) to the input dataset. |
|
Integrate point and cell data. |
|
Interpolate values onto this mesh from a given dataset. |
|
Compute the intersection between two meshes. |
|
Merge this mesh with one or more datasets. |
|
Merge duplicate points in this mesh. |
|
Perform multiple ray trace calculations. |
|
Return an oriented bounding box (OBB) for this dataset. |
|
Produce an outline of the full extent for the input dataset. |
|
Produce an outline of the corners for the input dataset. |
|
Renumber labeled data such that labels are contiguous. |
|
Break down input dataset into a requested number of partitions. |
|
Plot boundaries of a mesh. |
|
Plot the curvature. |
|
Plot the point normals of a mesh. |
|
Sample a dataset along a circular arc and plot it. |
|
Sample a dataset along a circular arc defined by a normal and polar vector and plot it. |
|
Sample a dataset along a high resolution line and plot. |
|
Transform point data into cell data. |
|
Project points of this mesh to a plane. |
|
Generate protein ribbon. |
|
Transform point data into cell data. |
|
Perform a single ray trace calculation. |
|
Reconstruct a surface from the points in this dataset. |
|
Reflect a dataset across a plane. |
|
Remove cells whose scalar values are NaN. |
|
Rebuild a mesh by removing points. |
|
Remove points which are not used by any cells. |
|
Resize the dataset’s bounds. |
|
Create a ribbon of the lines in this dataset. |
|
Rotate mesh about a point with a rotation matrix or |
|
Rotate mesh about a vector. |
|
Rotate mesh about the x-axis. |
|
Rotate mesh about the y-axis. |
|
Rotate mesh about the z-axis. |
|
Create a ruled surface from a polyline. |
|
Resample array data from a passed mesh onto this mesh. |
|
Sample a dataset over a circular arc. |
|
Sample a dataset over a circular arc defined by a normal and polar vector and plot it. |
|
Sample a dataset onto a line. |
|
Sample a dataset onto a multiple lines. |
|
Scale the mesh. |
|
Mark points as to whether they are inside a closed surface. |
|
Mark points from this mesh as inside or outside relative to a closed surface. |
|
Return a copy of the dataset with separated cells with no shared points. |
|
Shrink the individual faces of a mesh. |
|
Slice a dataset by a plane at the specified origin and normal vector orientation. |
|
Create many slices of the input dataset along a specified axis. |
|
Slice a dataset using a polyline/spline as the path. |
|
Slice a dataset by a VTK implicit function. |
|
Create three orthogonal slices through the dataset on the three Cartesian planes. |
|
Adjust point coordinates using Laplacian smoothing. |
|
Smooth a PolyData DataSet with Taubin smoothing. |
|
Sort labeled data by number of points or cells. |
|
Find, label, and split connected bodies/volumes. |
|
Split mesh into separate sub-meshes using point or cell data. |
|
Integrate a vector field to generate streamlines. |
|
Generate evenly spaced streamlines on a 2D dataset. |
|
Generate streamlines of vectors from the points of a source mesh. |
|
Strip poly data cells. |
|
Increase the number of triangles in a single, connected triangular mesh. |
|
Increase the number of triangles in a triangular mesh based on edge and/or area metrics. |
|
Return the surface indices of a grid. |
|
Tessellate a mesh. |
|
Texture map this dataset to a user defined plane. |
|
Texture map this dataset to a user defined sphere. |
|
Apply a vtkThreshold filter to the input dataset. |
|
Threshold the dataset by a percentage of its range on the active scalars array. |
|
Transform this mesh with a 4x4 transform. |
|
Translate the mesh. |
|
Return an all triangle mesh. |
|
Triangulate and fill all 2D contours to create polygons. |
|
Generate a tube around each input line. |
|
Validate this mesh’s array data, points, and cells. |
|
Voxelize mesh to UnstructuredGrid. |
|
Voxelize mesh as a binary |
|
Voxelize mesh to create a RectilinearGrid voxel volume. |
|
Warp the dataset’s points by a point data scalars array’s values. |
|
Warp the dataset’s points by a point data vectors array’s values. |