python - 获取 Mayavi 颜色图指定的颜色

标签 python vtk mayavi

我正在使用 mayavi 并使用 scalar 绘制我的三角形网格mlab.triangular_mesh 中的属性

model_plot = mlab.triangular_mesh(self.model.vx, self.model.vy, self.model.vz, self.model.triv,
                                          scalars=self.P_colors[:, np.newaxis],

                                          name='model')

结果
enter image description here
但我想更改网格中的特定值(例如将头部涂成绿色)。 为此,我尝试使用 LOT该图,但我不明白如何使用它(即从标量 X -> 到颜色 (R,G,B,A))

model_plot.module_manager.scalar_lut_manager.lut.table = model_colors


目标是以某种方式转移 (7000)标量数组,为 (7000,4) RGBA数组对应LOT .

最佳答案

终于找到这个问题的答案了。 只有2个关键点:

  • 标量

"This scalar value can be used to modulate the color and the size of the points."

  • 制作一个 RGBA LUT N*4 例如7000*4
#xyz= N*3  points
#tex = N*3  color_per_point,0~255
#tl = triangle_list of pints,  M*3

# N*4 0~255 RGBA color
color=np.hstack((tex,255.*np.ones((xyz.shape[0],1)))) 

s = np.arange(xyz.shape[0])
fig2=mlab.figure(figure="test2",fgcolor=(0., 0., 0.), bgcolor=(0, 0, 0))
mlab.figure(fig2)
mesh = mlab.triangular_mesh(xyz[:,0], xyz[:,1], xyz[:,2], tl,scalars=s,
                            representation='wireframe',
                            opacity=1)

mesh.module_manager.scalar_lut_manager.lut.number_of_colors = len(s)
mesh.module_manager.scalar_lut_manager.lut.table = color

mlab.draw()
mlab.show()

这有效

关于python - 获取 Mayavi 颜色图指定的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58084930/

相关文章:

python - 如何让 matplotlib 显示所有 x 坐标?

c++ - 从二进制文件中读取 double 值和 int 值

c++ - 在立方体面上应用图像 - VTK

c++11 - vtkImageResliceMapper 中的 VTK 相机更新问题

python - Mayavi contour3d 文档提到 "the arrows"时是什么意思?

python - 检查系列中的值是否出现在 df 列中的任何位置,且始终计算为 True

python - 如何找到在线性时间和常数空间中出现超过 N/3 次的值

python - 将图像映射到球体上并绘制3D轨迹

python - 如何使用 Mayavi 绘制 3D 椭球体

python - 重新加载与重新启动 uWSGI 以激活代码更改