marcomusy / vedo

A python module for scientific analysis of 3D data based on VTK and Numpy
https://vedo.embl.es
MIT License
2.03k stars 265 forks source link

color of tube cap #1125

Closed IsabellaPa closed 4 months ago

IsabellaPa commented 4 months ago

Hello Marco,

I made a tube with a set of points. I then colored the tube with a cmap and a np array with some data. It's looking nice, but the caps of the tube now only fit the color of the tube end on one side.

image

Is there a way to change the color of the cap?

This is my code: ''' single_tube = Tube(point_array, r = 0.3) new_length = 504 new_color_array = np.interp(np.linspace(0, 1, new_length), np.linspace(0, 1, 40), color_array) # I had to stretch my data as I didn't have the same amount of data points of the color as the tube generates points single_tube .cmap('rainbow', new_color_array, vmin =0, vmax= 1) '''

marcomusy commented 4 months ago

Hi, consider the following example instead:

from vedo import *

x = np.linspace(0, 2*np.pi, num=20)
y = np.sin(x)
z = np.cos(x)
point_array = np.c_[x, y, z]
scalars = np.sqrt(np.linspace(12, 34, num=20))

line = Line(point_array)
line.pointdata["my_scalars"] = scalars

tube = Tube(line, r=0.5)
tube.cmap("rainbow", "my_scalars")
tube.add_scalarbar3d(":sqrt(myscalars)")

show(tube, axes=1)

Screenshot from 2024-05-27 16-24-48

in this way - by creating a Line - you will not need to make interpolations.

IsabellaPa commented 4 months ago

Weirdly, when I run this code I get these error messages and in the following a grey tube:

[vedo.visual] ERROR: in cmap(), cannot find points array my_scalars ...skip coloring. [vedo.visual] ERROR: in cmap(), cannot find any points active array ...skip coloring. [vedo.visual] ERROR: in cmap(), nr. of input cells scalars 0 != 1 ...skip coloring.

marcomusy commented 4 months ago

Try:

pip install vedo -U
IsabellaPa commented 4 months ago

Thank you, it works perfectly now :)