pyvista / pyacvd

Python implementation of surface mesh resampling algorithm ACVD
MIT License
202 stars 16 forks source link

How to use this with vtkPolyData? #24

Closed lassoan closed 1 year ago

lassoan commented 2 years ago

Thank you for providing this package! How can I use this package if I have the input as vtkPolyData and would need the processed mesh as vtkPolyData? All the examples use some pyvista mesh objects and I don't know how to convert those to/from vtkPolyData.

banesullivan commented 2 years ago

A pyvista.PolyData object is a vtk.vtkPolyData object. If using this package, PyVista is installed as it is a dependency so wrapping your already existing vtkPolyData object is a one-liner via pyvista.wrap().

If your mesh is currently a vtkPolyData instance, simply:

import vtk
import pyvista as pv
import pyacvd

mesh = ... # this is vtkPolyData

wrapped = pv.wrap(mesh)
clus = pyacvd.Clustering(wrapped)
clus.subdivide(3)
clus.cluster(20000)

# remesh
remesh = clus.create_mesh()  # returns pyvista.PolyData
# Sanity check that pyvista.PolyData is vtkPolyData
assert isinstance(remesh, vtk.vtkPolyData)
akaszynski commented 1 year ago

Thanks for responding here @banesullivan