我正在使用 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')
结果
但我想更改网格中的特定值(例如将头部涂成绿色)。
为此,我尝试使用 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/