pyvista.PolyDataFilters.compute_normals#

PolyDataFilters.compute_normals(
cell_normals=True,
point_normals=True,
split_vertices=False,
flip_normals=False,
consistent_normals=True,
auto_orient_normals=False,
non_manifold_traversal=True,
feature_angle=30.0,
inplace=False,
progress_bar=False,
)[source]#

Compute point and/or cell normals for a mesh.

The filter can reorder polygons to insure consistent orientation across polygon neighbors. Sharp edges can be split and points duplicated with separate normals to give crisp (rendered) surface definition. It is also possible to globally flip the normal orientation.

The algorithm works by determining normals for each polygon and then averaging them at shared points. When sharp edges are present, the edges are split and new points generated to prevent blurry edges (due to Phong shading).

An array named "Normals" is stored with the mesh.

Warning

  • Normals can only be computed for polygons and triangle strips. Point clouds are not supported.

  • Triangle strips are broken up into triangle polygons. You may want to restrip the triangles.

  • Previous arrays named "Normals" will be overwritten.

Parameters:
cell_normalsbool, default: True

Calculation of cell normals.

point_normalsbool, default: True

Calculation of point normals.

split_verticesbool, default: False

Splitting of sharp edges. Indices to the original points are tracked in the "pyvistaOriginalPointIds" array.

flip_normalsbool, default: False

Set global flipping of normal orientation. Flipping modifies both the normal direction and the order of a cell’s points.

consistent_normalsbool, default: True

Enforcement of consistent polygon ordering.

auto_orient_normalsbool, default: False

Turn on/off the automatic determination of correct normal orientation. NOTE: This assumes a completely closed surface (i.e. no boundary edges) and no non-manifold edges. If these constraints do not hold, all bets are off. This option adds some computational complexity, and is useful if you do not want to have to inspect the rendered image to determine whether to turn on the flip_normals flag. However, this flag can work with the flip_normals flag, and if both are set, all the normals in the output will point “inward”.

non_manifold_traversalbool, default: True

Turn on/off traversal across non-manifold edges. Changing this may prevent problems where the consistency of polygonal ordering is corrupted due to topological loops.

feature_anglefloat, default: 30.0

The angle that defines a sharp edge. If the difference in angle across neighboring polygons is greater than this value, the shared edge is considered “sharp”.

inplacebool, default: False

Updates mesh in-place.

progress_barbool, default: False

Display a progress bar to indicate progress.

Returns:
pyvista.PolyData

Updated mesh with cell and point normals.

Raises:
TypeError

If the mesh contains only LINE or VERTEX cell types. Normals cannot be computed for these cells.

See also

point_normals

Returns the array of point normals.

cell_normals

Returns the array of cell normals.

Examples

Compute the point normals of the surface of a sphere.

>>> import pyvista as pv
>>> sphere = pv.Sphere()
>>> sphere = sphere.compute_normals(cell_normals=False)
>>> normals = sphere['Normals']
>>> normals.shape
(842, 3)

Alternatively, create a new mesh when computing the normals and compute both cell and point normals.

>>> import pyvista as pv
>>> sphere = pv.Sphere()
>>> sphere_with_norm = sphere.compute_normals()
>>> sphere_with_norm.point_data['Normals'].shape
(842, 3)
>>> sphere_with_norm.cell_data['Normals'].shape
(1680, 3)

See Computing Surface Normals for more examples using this filter.