Color mesh by vector component

Hi all,

I’m trying to plot an UnstructuredGrid mesh with color based on a single vector component with trame.

The vtu is defined as follow:

<PointData Scalars="'Press'" Vectors="'U','UR'" >
<DataArray type="Float32" Name="U" NumberOfComponents="3" ComponentName0="U1" ComponentName1="U2" ComponentName2="U3" format="ascii">
0.0 0.0 0.0 

The pipeline for coloring the mesh is defined as:

def color_by_array(actor, array, component_idx):
    _min, _max = array.get("range")
    mapper = actor.GetMapper()
    lut = mapper.GetLookupTable()
    lut.SetRange(_min, _max)
    if array.get("type") == vtkDataObject.FIELD_ASSOCIATION_POINTS:

In main_var there’s, for example, the string ‘U’.

Anyway the code seems to work only for the first component (component_idx = 0), while it doesn’t work for different components (it changes only the range coming from the array object). Even if I use the legacy ColorByArrayComponent function I obtain the same wrong result.

Do you have any suggestion to deal with this?


I just tried the geometry example using
sphere.vtp (4.6 KB) and coloring by the various normal components and everything seems fine.

But now that I read more carefully your message, I’m realizing your code is in Python and not JS which means, you have a server and a client.

Can you specify what kind of setup you are using?

Actually i’m using Trame 2.2.6 on python 3.10.3

With the VtkLocalView or VtkRemoteView?

Actually the problem occurs with VtkLocalView. I will test also with remoteview

The RemoteView is key to make sure your VTK server code is correct. The LocalView is still wip and is more likely to miss something. If the RemoteView works when you interact with the scene, that probably means you forget to call update() on your view via the controller or direct method ref.

1 Like

RemoteView is working, thanks!
When usingLocalView I was calling update() on my views but the SetVectorComponent seems to do nothing (only changes the color range via SetRange).
Anyway, I can deal with RemoteView for my task. Thanks again Sebastien!

Great, thanks for the update… That means the scene serializer is missing those LUT settings and miss the propagation to the client side.

Tracked issue here

Should be fixed in trame-vtk>=2.3.2