Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform a shallow copy when converting to pyvista.PolyData #12

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions stl_reader/reader.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Read a STL file using a wrapper of https://github.com/aki5/libstl."""

import numpy as np
from stl_reader import _stlfile_wrapper

Expand All @@ -21,27 +22,20 @@ def _polydata_from_faces(points, faces):
import pyvista as pv
except ModuleNotFoundError:
raise ModuleNotFoundError(
"To use this functionality, install PyVista with\n\npip install pyvista"
"To use this functionality, install PyVista with:\n\npip install pyvista"
)

from pyvista import ID_TYPE

try:
from pyvista.core.utilities import numpy_to_idarr
except ModuleNotFoundError: # pragma: no cover
from pyvista.utilities.cells import numpy_to_idarr
from vtkmodules.vtkCommonDataModel import vtkCellArray
from pyvista import ID_TYPE, CellArray

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

# 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_idarr(offset, deep=True), numpy_to_idarr(faces, deep=True))
pdata.SetPolys(carr)
return pdata


Expand Down
Loading