python - Convert mayavi mlab.contour3d plot to vtkPolyData -
i trying triangulated vtkpolydata mlab.contour3d plot. using mayavi because seems fastest way minimal surfaces triangulated properly. need vtkpolydata because want save .stl file.
here mwe of code:
import numpy np mayavi import mlab def fun(x, y, z): return np.cos(x) + np.cos(y) + np.cos(z) x, y, z = np.mgrid[-1:1:100j, -1:1:100j, -1:1:100j] contour = mlab.contour3d(x, y, z, fun) mlab.show() what mayavi surface triangulated , displayed using vtk (or tvtk), should possible vtkpolydata there. way found far use mlab.savefig(test.obj) export .obj-file (which bad, because takes time save file everytime mayavi ui opens) , import file again using vtkobjreader, gives me vtkpolydata want.
does know more straight-forward way this?
edit: clarify problem bit more: can access data visualization e.g. mayavi.tools.pipeline.get_vtk_src(), comes in form of vtkimagedata. if knows way convert vtkpolydata, solution.
by total coincidence found solution.
import numpy np mayavi import mlab def fun(x, y, z): return np.cos(x) + np.cos(y) + np.cos(z) x, y, z = np.mgrid[-1:1:100j, -1:1:100j, -1:1:100j] contour = mlab.contour3d(x, y, z, fun) actor = contour.actor.actors[0] polydata = tvtk.to_vtk(actor.mapper.input) # solution mlab.show() the trick seems to access mapper pipeline, polydatamapper. use tvtk.to_vtk() function can continue vtk prefer on tvtk, @ least now.
Comments
Post a Comment