Get normals coordinates

Hi VTK community,

Is there any options to get X,Y,Z coordinates of the cell normals?

Currently I have the following code:

normals = vtk.vtkPPolyDataNormals()
normals.SetInputConnection(decimate.GetOutputPort())

normals.ComputeCellNormalsOn()

normals.SplittingOff()
normals.FlipNormalsOff()
normals.ConsistencyOn()
normals.AutoOrientNormalsOn()
normals.Update()

For my further processing steps I need to get coordinates (ot at least angle of the normals). I’ve found vtkDeflectNormals() class, however, I get this error with it: AttributeError: module ‘vtkmodules.all’ has no attribute ‘vtkDeflectNormals’

Normals are computed as float array and stored in cell data.

I don’t have the python code, in C++ one can do this

vtkFloatArray* normalsFloat = vtkFloatArray::SafeDownCast( polydata->GetCellData()->GetNormals() );
1 Like

Thanks for your comment, I’ve tried your solution, however it works only with VTK primitives such as sphere, for example. When I use polydata->GetCellData()->GetNormals() with STL file, the result is None:

filename = “loop.STL”
source = vtk.vtkSTLReader()

source.SetFileName(filename)
source.Update()

polydata = vtk.vtkPolyData()
polydata.ShallowCopy(source.GetOutput())

normals = polydata.GetCellData().GetNormals()
print(normals)

The result as I mentioned is None. I’ve tried different STL files here, but the problem persists. Is there any problem with my code or GetNormals() works only with primitives?

Get the polydata from STL reader and compute the normal as you originally posted. If you don’t compute normal you cannot expect them to be there.

Cheers!

To generate points at the (parametric) center of cells use vtkCellCenters