pyvista.PolyData

class PolyData(var_inp=None, faces=None, n_faces=None, lines=None, n_lines=None, deep=False, force_ext=None)

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_inpvtk.vtkPolyData, str, sequence, optional

Flexible input type. Can be a vtk.vtkPolyData, in which case this PolyData object will be copied if deep=True and will be a shallow copy if deep=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_facesint, optional

Number of faces in the faces connectivity array. While optional, setting this speeds up the creation of the PolyData.

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_linesint, optional

Number of lines in the lines connectivity array. While optional, setting this speeds up the creation of the PolyData.

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 is False.

force_extstr, 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.

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 a filename.

>>> mesh = pyvista.PolyData(examples.antfile)

Methods

PolyData.add_field_array(scalars, name[, deep])

Add field data.

PolyData.add_field_data(array, name[, deep])

Add field data.

PolyData.boolean_add(*args, **kwargs)

Merge two meshes together.

PolyData.boolean_cut(*args, **kwargs)

Cut two meshes.

PolyData.boolean_difference(other_mesh[, ...])

Perform a boolean difference operation between two meshes.

PolyData.boolean_intersection(other_mesh[, ...])

Perform a boolean intersection operation on two meshes.

PolyData.boolean_union(other_mesh[, ...])

Perform a boolean union operation on two meshes.

PolyData.cast_to_unstructured_grid()

Get a new representation of this object as a pyvista.UnstructuredGrid.

PolyData.cell_bounds(ind)

Return the bounding box of a cell.

PolyData.cell_centers([vertex, progress_bar])

Generate points at the center of the cells in this dataset.

PolyData.cell_data_to_point_data([...])

Transform cell data into point data.

PolyData.cell_n_points(ind)

Return the number of points in a cell.

PolyData.cell_points(ind)

Return the points in a cell.

PolyData.cell_type(ind)

Return the type of a cell.

PolyData.center_of_mass([scalars_weight])

Return the coordinates for the center of mass of the mesh.

PolyData.clean([point_merging, tolerance, ...])

Clean the mesh.

PolyData.clear_arrays()

Remove all arrays from point/cell/field data.

PolyData.clear_cell_arrays()

Remove all cell data.

PolyData.clear_cell_data()

Remove all cell arrays.

PolyData.clear_data()

Remove all arrays from point/cell/field data.

PolyData.clear_field_arrays()

Remove all field data.

PolyData.clear_field_data()

Remove all field data.

PolyData.clear_point_arrays()

Remove all point data.

PolyData.clear_point_data()

Remove all point arrays.

PolyData.clear_textures()

Clear the textures from this mesh.

PolyData.clip([normal, origin, invert, ...])

Clip a dataset by a plane by specifying the origin and normal.

PolyData.clip_box([bounds, invert, factor, ...])

Clip a dataset by a bounding box defined by the bounds.

PolyData.clip_closed_surface([normal, ...])

Clip a closed polydata surface with a plane.

PolyData.clip_scalar([scalars, invert, ...])

Clip a dataset by a scalar.

PolyData.clip_surface(surface[, invert, ...])

Clip any mesh type using a pyvista.PolyData surface mesh.

PolyData.collision(other_mesh[, ...])

Perform collision determination between two polyhedral surfaces.

PolyData.compute_arc_length([progress_bar])

Compute the arc length over the length of the probed line.

PolyData.compute_cell_quality([...])

Compute a function of (geometric) quality for each cell of a mesh.

PolyData.compute_cell_sizes([length, area, ...])

Compute sizes for 1D (length), 2D (area) and 3D (volume) cells.

PolyData.compute_derivative([scalars, ...])

Compute derivative-based quantities of point/cell scalar field.

PolyData.compute_implicit_distance(surface)

Compute the implicit distance from the points to a surface.

PolyData.compute_normals([cell_normals, ...])

Compute point and/or cell normals for a mesh.

PolyData.connectivity([largest, progress_bar])

Find and label connected bodies/volumes.

PolyData.contour([isosurfaces, scalars, ...])

Contour an input self by an array.

PolyData.copy([deep])

Return a copy of the object.

PolyData.copy_attributes(dataset)

Copy the data attributes of the input dataset object.

PolyData.copy_meta_from(ido)

Copy pyvista meta data onto this object from another object.

PolyData.copy_structure(dataset)

Copy the structure (geometry and topology) of the input dataset object.

PolyData.ctp([pass_cell_data, progress_bar])

Transform cell data into point data.

PolyData.curvature([curv_type, progress_bar])

Return the pointwise curvature of a mesh.

PolyData.decimate(target_reduction[, ...])

Reduce the number of triangles in a triangular mesh using vtkQuadricDecimation.

PolyData.decimate_boundary([...])

Return a decimated version of a triangulation of the boundary.

PolyData.decimate_pro(reduction[, ...])

Reduce the number of triangles in a triangular mesh.

PolyData.deep_copy(to_copy)

Overwrite this data object with another data object as a deep copy.

PolyData.delaunay_2d([tol, alpha, offset, ...])

Apply a 2D Delaunay filter along the best fitting plane.

PolyData.delaunay_3d([alpha, tol, offset, ...])

Construct a 3D Delaunay triangulation of the mesh.

PolyData.edge_mask(angle[, progress_bar])

Return a mask of the points of a surface mesh that has a surface angle greater than angle.

PolyData.elevation([low_point, high_point, ...])

Generate scalar values on a dataset.

PolyData.extract_all_edges([progress_bar])

Extract all the internal/external edges of the dataset as PolyData.

PolyData.extract_cells(ind[, progress_bar])

Return a subset of the grid.

PolyData.extract_feature_edges([...])

Extract edges from the surface of the mesh.

PolyData.extract_geometry([progress_bar])

Extract the outer surface of a volume or structured grid dataset.

PolyData.extract_largest([inplace, progress_bar])

Extract largest connected set in mesh.

PolyData.extract_points(ind[, ...])

Return a subset of the grid (with cells) that contains any of the given point indices.

PolyData.extract_surface([pass_pointid, ...])

Extract surface mesh of the grid.

PolyData.extrude(vector[, capping, inplace, ...])

Sweep polygonal data creating a "skirt" from free edges.

PolyData.extrude_rotate([resolution, ...])

Sweep polygonal data creating "skirt" from free edges and lines, and lines from vertices.

PolyData.fill_holes(hole_size[, inplace, ...])

Fill holes in a pyvista.PolyData or vtk.vtkPolyData object.

PolyData.find_closest_cell(point)

Find index of closest cell in this mesh to the given point.

PolyData.find_closest_point(point[, n])

Find index of closest point in this mesh to the given point.

PolyData.flip_normal(normal[, point, ...])

Flip mesh about the normal.

PolyData.flip_normals()

Flip normals of a triangular mesh by reversing the point ordering.

PolyData.flip_x([point, ...])

Flip mesh about the x-axis.

PolyData.flip_y([point, ...])

Flip mesh about the y-axis.

PolyData.flip_z([point, ...])

Flip mesh about the z-axis.

PolyData.geodesic(start_vertex, end_vertex)

Calculate the geodesic path between two vertices using Dijkstra's algorithm.

PolyData.geodesic_distance(start_vertex, ...)

Calculate the geodesic distance between two vertices using Dijkstra's algorithm.

PolyData.get_array(name[, preference])

Search both point, cell and field data for an array.

PolyData.get_array_association(name[, ...])

Get the association of an array.

PolyData.get_data_range([arr_var, preference])

Get the non-NaN min and max of a named array.

PolyData.glyph([orient, scale, factor, ...])

Copy a geometric representation (called a glyph) to the input dataset.

PolyData.head([display, html])

Return the header stats of this dataset.

PolyData.interpolate(target[, sharpness, ...])

Interpolate values onto this mesh from a given dataset.

PolyData.intersection(mesh[, split_first, ...])

Compute the intersection between two meshes.

PolyData.merge(dataset[, merge_points, ...])

Merge this mesh with one or more datasets.

PolyData.multi_ray_trace(origins, directions)

Perform multiple ray trace calculations.

PolyData.outline([generate_faces, progress_bar])

Produce an outline of the full extent for the input dataset.

PolyData.outline_corners([factor, progress_bar])

Produce an outline of the corners for the input dataset.

PolyData.overwrite(mesh)

Overwrite this dataset inplace with the new dataset's geometries and data.

PolyData.plot([off_screen, full_screen, ...])

Plot a vtk or numpy object.

PolyData.plot_boundaries([edge_color, ...])

Plot boundaries of a mesh.

PolyData.plot_curvature([curv_type])

Plot the curvature.

PolyData.plot_normals([show_mesh, mag, ...])

Plot the point normals of a mesh.

PolyData.plot_over_circular_arc(pointa, ...)

Sample a dataset along a circular arc and plot it.

PolyData.plot_over_circular_arc_normal(center)

Sample a dataset along a resolution circular arc defined by a normal and polar vector and plot it.

PolyData.plot_over_line(pointa, pointb[, ...])

Sample a dataset along a high resolution line and plot.

PolyData.point_data_to_cell_data([...])

Transform point data into cell data.

PolyData.points_to_double()

Convert the points datatype to double precision.

PolyData.probe(points[, tolerance, ...])

Sample data values at specified point locations.

PolyData.project_points_to_plane([origin, ...])

Project points of this mesh to a plane.

PolyData.ptc([pass_point_data, progress_bar])

Transform point data into cell data.

PolyData.ray_trace(origin, end_point[, ...])

Perform a single ray trace calculation.

PolyData.reconstruct_surface([nbr_sz, ...])

Reconstruct a surface from the points in this dataset.

PolyData.reflect(normal[, point, inplace, ...])

Reflect a dataset across a plane.

PolyData.remove_cells(ind[, inplace])

Remove cells.

PolyData.remove_points(remove[, mode, ...])

Rebuild a mesh by removing points.

PolyData.rename_array(old_name, new_name[, ...])

Change array name by searching for the array then renaming it.

PolyData.ribbon([width, scalars, angle, ...])

Create a ribbon of the lines in this dataset.

PolyData.rotate_vector(vector, angle[, ...])

Rotate mesh about a vector.

PolyData.rotate_x(angle[, point, ...])

Rotate mesh about the x-axis.

PolyData.rotate_y(angle[, point, ...])

Rotate mesh about the y-axis.

PolyData.rotate_z(angle[, point, ...])

Rotate mesh about the z-axis.

PolyData.sample(target[, tolerance, ...])

Resample array data from a passed mesh onto this mesh.

PolyData.sample_over_circular_arc(pointa, ...)

Sample a dataset over a circular arc.

PolyData.sample_over_circular_arc_normal(center)

Sample a dataset over a circular arc defined by a normal and polar vector and plot it.

PolyData.sample_over_line(pointa, pointb[, ...])

Sample a dataset onto a line.

PolyData.save(filename[, binary, texture])

Write a surface mesh to disk.

PolyData.scale(xyz)

Scale the mesh.

PolyData.select_enclosed_points(surface[, ...])

Mark points as to whether they are inside a closed surface.

PolyData.set_active_scalars(name[, preference])

Find the scalars by name and appropriately sets it as active.

PolyData.set_active_tensors(name[, preference])

Find the tensors by name and appropriately sets it as active.

PolyData.set_active_vectors(name[, preference])

Find the vectors by name and appropriately sets it as active.

PolyData.shallow_copy(to_copy)

Create a shallow copy from a different dataset into this one.

PolyData.shrink([shrink_factor, progress_bar])

Shrink the individual faces of a mesh.

PolyData.slice([normal, origin, ...])

Slice a dataset by a plane at the specified origin and normal vector orientation.

PolyData.slice_along_axis([n, axis, ...])

Create many slices of the input dataset along a specified axis.

PolyData.slice_along_line(line[, ...])

Slice a dataset using a polyline/spline as the path.

PolyData.slice_orthogonal([x, y, z, ...])

Create three orthogonal slices through the dataset on the three cartesian planes.

PolyData.smooth([n_iter, relaxation_factor, ...])

Adjust point coordinates using Laplacian smoothing.

PolyData.split_bodies([label, progress_bar])

Find, label, and split connected bodies/volumes.

PolyData.streamlines([vectors, ...])

Integrate a vector field to generate streamlines.

PolyData.streamlines_evenly_spaced_2D([...])

Generate evenly spaced streamlines on a 2D dataset.

PolyData.streamlines_from_source(source[, ...])

Generate streamlines of vectors from the points of a source mesh.

PolyData.strip([join, max_length, ...])

Strip poly data cells.

PolyData.subdivide(nsub[, subfilter, ...])

Increase the number of triangles in a single, connected triangular mesh.

PolyData.subdivide_adaptive([max_edge_len, ...])

Increase the number of triangles in a triangular mesh based on edge and/or area metrics.

PolyData.surface_indices([progress_bar])

Return the surface indices of a grid.

PolyData.texture_map_to_plane([origin, ...])

Texture map this dataset to a user defined plane.

PolyData.texture_map_to_sphere([center, ...])

Texture map this dataset to a user defined sphere.

PolyData.threshold([value, scalars, invert, ...])

Apply a vtkThreshold filter to the input dataset.

PolyData.threshold_percent([percent, ...])

Threshold the dataset by a percentage of its range on the active scalars array.

PolyData.transform(trans[, ...])

Transform this mesh with a 4x4 transform.

PolyData.translate(xyz)

Translate the mesh.

PolyData.triangulate([inplace, progress_bar])

Return an all triangle mesh.

PolyData.tube([radius, scalars, capping, ...])

Generate a tube around each input line.

PolyData.warp_by_scalar([scalars, factor, ...])

Warp the dataset's points by a point data scalars array's values.

PolyData.warp_by_vector([vectors, factor, ...])

Warp the dataset's points by a point data vectors array's values.

Attributes

PolyData.active_normals

Return the active normals as an array.

PolyData.active_scalars

Return the active scalars as an array.

PolyData.active_scalars_info

Return the active scalar's association and name.

PolyData.active_scalars_name

Return the name of the active scalars.

PolyData.active_t_coords

Return or set the active texture coordinates on the points.

PolyData.active_tensors

Return the active tensors array.

PolyData.active_tensors_info

Return the active tensor's field and name: [field, name].

PolyData.active_tensors_name

Return the name of the active tensor array.

PolyData.active_vectors

Return the active vectors array.

PolyData.active_vectors_info

Return the active vector's association and name.

PolyData.active_vectors_name

Return the name of the active vectors array.

PolyData.actual_memory_size

Return the actual size of the dataset object.

PolyData.area

Return the mesh surface area.

PolyData.array_names

Return a list of array names for the dataset.

PolyData.arrows

Return a glyph representation of the active vector data as arrows.

PolyData.bounds

Return the bounding box of this dataset.

PolyData.cell_arrays

Return vtkCellData as DataSetAttributes.

PolyData.cell_data

Return vtkCellData as DataSetAttributes.

PolyData.cell_normals

Return the cell normals.

PolyData.center

Return the center of the bounding box.

PolyData.extent

Return the range of the bounding box.

PolyData.face_normals

Return the cell normals.

PolyData.faces

Return a pointer to the faces as a numpy array.

PolyData.field_arrays

Return vtkFieldData as DataSetAttributes.

PolyData.field_data

Return FieldData as DataSetAttributes.

PolyData.is_all_triangles

Return if all the faces of the pyvista.PolyData are triangles.

PolyData.length

Return the length of the diagonal of the bounding box.

PolyData.lines

Return a pointer to the lines as a numpy array.

PolyData.memory_address

Get address of the underlying VTK C++ object.

PolyData.n_arrays

Return the number of arrays present in the dataset.

PolyData.n_cells

Return the number of cells in the entire dataset.

PolyData.n_faces

Return the number of cells.

PolyData.n_lines

Return the number of lines.

PolyData.n_open_edges

Return the number of open edges on this mesh.

PolyData.n_points

Return the number of points in the entire dataset.

PolyData.n_verts

Return the number of vertices.

PolyData.number_of_cells

Return the number of cells.

PolyData.number_of_faces

Return the number of cells.

PolyData.number_of_points

Return the number of points.

PolyData.obbTree

Return the obbTree of the polydata.

PolyData.point_arrays

Return vtkPointData as DataSetAttributes.

PolyData.point_data

Return vtkPointData as DataSetAttributes.

PolyData.point_normals

Return the point normals.

PolyData.points

Return a reference to the points as a numpy object.

PolyData.t_coords

Return the active texture coordinates on the points.

PolyData.textures

Return a dictionary to hold compatible vtk.vtkTexture objects.

PolyData.vectors

Return active vectors.

PolyData.verts

Get the vertex cells.

PolyData.volume

Return the mesh volume.