DsCpp
DsCpp

Reputation: 2489

get the colors assigned by mayavi colormap

I'm using mayavi and plotting my triangular mesh using the scalar attribute in 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')

With the resulting
enter image description here
But I would like to change specific values in the mesh (e.g paint the head in green). For that, I tried to use the LOT of the figure, but I don't understand how to use it (I.e, from scalar X -> to color (R,G,B,A))

model_plot.module_manager.scalar_lut_manager.lut.table = model_colors


The goal is somehow to transfer the (7000) scalar array, to a (7000,4) RGBA array corresponds to the LOT.

Upvotes: 1

Views: 1032

Answers (2)

Eli
Eli

Reputation: 53

Finally, I find the solution of this question. Just 2 key point:

  • scalar

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

  • make a RGBA LUT N*4 e.g. 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()

this works

Upvotes: 1

Felipe Lema
Felipe Lema

Reputation: 2718

Easiest way would be to filter the head out of the original mesh, and plot it separately and then assign it a single-color-LUT

Upvotes: 0

Related Questions