pyvista.PolyData#
- class PolyData(var_inp=None, faces=None, n_faces=None, lines=None, n_lines=None, strips=None, n_strips=None, deep=False, force_ext=None, force_float=True)[source]#
Dataset consisting of surface geometry (e.g. vertices, lines, and polygons).
Can be initialized in several ways:
Create an empty mesh
Initialize from a vtk.vtkPolyData
Using vertices
Using vertices and faces
From a file
- Parameters:
- var_inp
vtk.vtkPolyData
,str
, sequence,optional
Flexible input type. Can be a
vtk.vtkPolyData
, in which case this PolyData object will be copied ifdeep=True
and 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.
- facessequence,
optional
Face connectivity array. 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.When not including the face connectivity array, each point will be assigned to a single vertex. This is used for point clouds that have no connectivity.
- n_faces
int
,optional
Number of faces in the
faces
connectivity array. While optional, setting this speeds up the creation of thePolyData
.- linessequence,
optional
The line connectivity array. Like
faces
, this array 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]
.- n_lines
int
,optional
Number of lines in the
lines
connectivity array. While optional, setting this speeds up the creation of thePolyData
.- stripssequence,
optional
Triangle strips connectivity array. 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
lines
andfaces
, this array requires a padding indicating the number of points. For example, a single triangle strip of[0, 1, 2, 3, 6, 7, 4, 5, 0, 1]
requires padding of10
and should input as[10, 0, 1, 2, 3, 6, 7, 4, 5, 0, 1]
.- n_strips
int
,optional
Number of strips in the
strips
connectivity array. While optional, setting this speeds up the creation of thePolyData
.- deepbool,
optional
Whether to copy the inputs, or to create a mesh from them without copying them. Setting
deep=True
ensures 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
float32
if points datatype is non-float. DefaultTrue
. Set this toFalse
to allow non-float types, though this may lead to truncation of intermediate floats when transforming datasets.
- var_inp
Examples
>>> import vtk >>> import numpy as np >>> from pyvista import examples >>> import pyvista
Create an empty mesh.
>>> mesh = pyvista.PolyData()
Initialize from a
vtk.vtkPolyData
object.>>> vtkobj = vtk.vtkPolyData() >>> mesh = pyvista.PolyData(vtkobj)
Initialize from just vertices.
>>> vertices = np.array([[0, 0, 0], [1, 0, 0], [1, 0.5, 0], [0, 0.5, 0]]) >>> mesh = pyvista.PolyData(vertices)
Initialize from vertices and faces.
>>> faces = np.hstack([[3, 0, 1, 2], [3, 0, 3, 2]]) >>> mesh = pyvista.PolyData(vertices, faces)
Initialize from vertices and lines.
>>> lines = np.hstack([[2, 0, 1], [2, 1, 2]]) >>> mesh = pyvista.PolyData(vertices, lines=lines)
Initialize from vertices and triangle strips.
>>> strips = np.hstack([[4, 0, 1, 3, 2]]) >>> mesh = pyvista.PolyData(vertices, strips=strips)
Initialize from a filename.
>>> mesh = pyvista.PolyData(examples.antfile)
See Create PolyData for more examples.
Methods
PolyData.save
(filename[, binary, texture, ...])Write a surface mesh to disk.
Attributes
Return the cell normals.
Return the cell normals.
Return a pointer to the faces as a numpy array.
Return if all the faces of the
pyvista.PolyData
are triangles.Return if the mesh is manifold (no open edges).
Return a pointer to the lines as a numpy array.
Return the number of cells.
Return the number of lines.
Return the number of open edges on this mesh.
Return the number of strips.
Return the number of vertices.
Return the number of cells.
Return the obbTree of the polydata.
Return the point normals.
Return a pointer to the strips as a numpy array.
Get the vertex cells.
Return the approximate volume of the dataset.