Skip to content

Commit

Permalink
reuse existing pyvista logic
Browse files Browse the repository at this point in the history
  • Loading branch information
akaszynski committed Jul 16, 2024
1 parent 29460c9 commit d705c78
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions stl_reader/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,17 @@ def _polydata_from_faces(points, faces):
"To use this functionality, install PyVista with:\n\npip install pyvista"
)

from pyvista import ID_TYPE
from vtkmodules.util.numpy_support import numpy_to_vtk, vtkConstants
from vtkmodules.vtkCommonDataModel import vtkCellArray
from pyvista import ID_TYPE, CellArray

if faces.ndim != 2:
raise ValueError("Expected a two dimensional face array.")
if faces.dtype != ID_TYPE:
faces = faces.astype(ID_TYPE)

# zero copy polydata creation
offset = np.arange(0, faces.size + 1, faces.shape[1], dtype=ID_TYPE)
pdata = pv.PolyData()
pdata.points = points
pdata.faces = CellArray.from_arrays(offset, faces)

carr = vtkCellArray()
offset = np.arange(0, faces.size + 1, faces.shape[1], dtype=ID_TYPE)
carr.SetData(
numpy_to_vtk(offset, deep=False, array_type=vtkConstants.VTK_ID_TYPE), # type: ignore
numpy_to_vtk(faces.ravel(), deep=False, array_type=vtkConstants.VTK_ID_TYPE), # type: ignore
)
pdata.SetPolys(carr)
return pdata


Expand Down

0 comments on commit d705c78

Please sign in to comment.