- 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)#
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 and faces
From a file
Flexible input type. Can be a
vtk.vtkPolyData, in which case this PolyData object will be copied if
deep=Trueand will be a shallow copy if
Also accepts a path, which may be local path as in
'my_mesh.stl'or global path like
Otherwise, this must be a points array or list containing one or more points. Each point must have 3 dimensions.
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.
Number of faces in the
facesconnectivity array. While optional, setting this speeds up the creation of the
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
[1, 2, 3, 4]will be represented as
[2, 0, 1, 4, 1, 2, 3, 4].
Number of lines in the
linesconnectivity array. While optional, setting this speeds up the creation of the
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
faces, 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 of
10and should input as
[10, 0, 1, 2, 3, 6, 7, 4, 5, 0, 1].
Number of strips in the
stripsconnectivity array. While optional, setting this speeds up the creation of the
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 is
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.
Casts the datatype to
float32if points datatype is non-float. Default
True. Set this to
Falseto allow non-float types, though this may lead to truncation of intermediate floats when transforming datasets.
>>> import vtk >>> import numpy as np >>> from pyvista import examples >>> import pyvista
Create an empty mesh.
>>> mesh = pyvista.PolyData()
Initialize from a
>>> 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.
PolyData.from_regular_faces(points, faces[, ...])
Alternate pyvista.PolyData convenience constructor from point and regular face arrays.
PolyData.save(filename[, binary, texture, ...])
Write a surface mesh to disk.
Return the cell normals.
Return the cell normals.
Return the connectivity array of the faces of this PolyData.
Return if all the faces of the
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 obbTree of the polydata.
Return the point normals.
Return a face array of point indices when all faces have the same size.
Return a pointer to the strips as a numpy array.
Get the vertex cells.
Return the approximate volume of the dataset.