1

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.

DsCpp
  • 2,259
  • 3
  • 18
  • 46
  • Would this example help? https://docs.enthought.com/mayavi/mayavi/auto/example_custom_colormap.html#example-custom-colormap – Patol75 Oct 02 '19 at 08:47
  • Thanks for the answer but no, the LUT from `# The lut is a 255x4 array, with the columns representing RGBA ` is 255*4, (the RGB mapping) where I want the `7k*4` map, i.e color per vertex in my mesh. – DsCpp Oct 02 '19 at 10:52
  • My understanding here is that each node is coloured according to its value in the array given to `scalars` and to the colormap which is used. This means that if you keep the current colormap, making the values of `self.P_colors` for the head the same as the ones for the lower belly would make the head green. Or, if `self.P_colors` stays the same, then making your own colormap (https://matplotlib.org/3.1.1/tutorials/colors/colormap-manipulation.html) and giving it to `colormap` is probably the solution. – Patol75 Oct 02 '19 at 14:24
  • You are definitely correct, but if I for example want to use the exact color map in a different software (e.g. MeshLab) I would like to use the same colors. Isn't there a way to create a `7000*4` colormap from the LUT? there must be, as they do it internally no? (and the name is literally Look Up table:p ) – DsCpp Oct 03 '19 at 05:44
  • Have a look here (https://matplotlib.org/3.1.0/tutorials/colors/colormap-manipulation.html), here (https://stackoverflow.com/questions/28144142/how-can-i-generate-a-colormap-array-from-a-simple-array-in-matplotlib) and here (https://stackoverflow.com/questions/16834861/create-own-colormap-using-matplotlib-and-plot-color-scale). For something internal to Mayavi, try adding `mlab.options.backend = 'envisage'` to your code. Then, double-click on Colors and Legends of the object you are interested into and try `Launch LUT editor`. It does not work for me, but who knows, maybe it is just me. – Patol75 Oct 03 '19 at 06:26

2 Answers2

1

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

Eli
  • 53
  • 6
  • This is beautiful Eli, Thanks!, but for consistency with the rest of my figures, I wanted to "reverse engineer" the color pallet of mayavi, I.e take their colors for my scalars, and only alter some. (I.e I don't have `tex`, only `s`) – DsCpp Nov 11 '19 at 09:14
0

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

Felipe Lema
  • 2,700
  • 12
  • 19
  • Thats a great method, But I would like to actually find the per vertex color, to paint the same figure with different softwares as well. – DsCpp Oct 03 '19 at 05:44