ScalarCutPlane mayavi 未显示 Mayavi 等值面图的横截面(轮廓)

ScalarCutPlane mayavi is not showing the cross-section(outline) of Mayavi iso-surface plot

我想获取类似于this Whosebug question. But when I am trying to do the same I am not able to get the outline of the plot but I am getting mayavi iso-surface plot and scalar_cut_plane or plot opacity=0.0的横截面图像。

但是我想要的是像Whosebug ex and Whosebug ex image2

这样的横截面图

可重现代码:

import numpy as np
from numpy import cos
from mayavi.mlab import contour3d
from mayavi import mlab

fig = mlab.figure(size=(800, 600), fgcolor=(0, 0, 0),bgcolor=(0.5,0.5,0.5))
x, y, z = np.ogrid[-3:3:60j, -3:3:60j, -3:3:60j]
t = 0

H1   =   0.45+((x*cos(t))*(x*cos(t)) + (y*cos(t))*(y*cos(t))-(z*cos(t))*(z*cos(t)))
obj1 = contour3d(H1, contours=[0], transparent=False, opacity=1.0)

H1_handle=mlab.gcf()
mlab.outline(obj1,figure=fig)

plane=mlab.pipeline.scalar_cut_plane(obj1.module_manager.source, plane_orientation='z_axes', figure=fig, )
plane.implicit_plane.widget.enabled = True
mlab.show()

上面提到的问题也没有回答。得到交叉图像后,我想进一步处理它,所以在这方面的任何帮助也将不胜感激。

提前致谢!!

终于找到了使用 and this question 的解决方案。

诀窍是将 mayavi mlab.contour3d 数据转换为 vtkPolyData。对于其余部分,我使用与上述相同的方法 question.

代码:

from mayavi import mlab
import numpy as np
from numpy import cos
from tvtk.api import tvtk
from mayavi.mlab import contour3d

fig = mlab.figure(size=(800, 600), bgcolor=(1, 1, 1), fgcolor=(0, 0, 0))
ap = tvtk.AppendPolyData()

x, y, z = np.ogrid[-3:3:60j, -3:3:60j, -3:3:60j]
t = 0

H1   =   0.45+((x*cos(t))*(x*cos(t)) + (y*cos(t))*(y*cos(t))-(z*cos(t))*(z*cos(t)))
src = contour3d(H1, contours=[0], transparent=False,opacity=0.0)


fig.remove_child(fig.children[0])
data_out = src.module_manager.source.get_output_dataset()
actor = src.actor.actors[0]
polydata = tvtk.to_vtk(actor.mapper.input)
ap.add_input_data(polydata)
ap.update()

surf = mlab.pipeline.surface(ap.output, figure=fig)
surf.visible = False
vcp = mlab.pipeline.scalar_cut_plane(ap.output, plane_orientation='z_axes', figure=fig)
outline = mlab.outline(surf, figure=fig)

mlab.show()