marcomusy / vedo

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

Mesh.backcolor disables mesh coloring #845

Open paul0noah opened 1 year ago

paul0noah commented 1 year ago

Hi Marco,

i have colorised a mesh with per-vertex rgb values:

cmap = ... # np.array of size (mesh.npoints, 3)
mesh.pointdata['vertex_colors'] = cmap
mesh.pointdata.select('vertex_colors')

with some additional uv mapping i obtain the following result:

Screenshot 2023-03-29 at 14 32 05

Since the mesh is "open", I want to display the inside without the coloring but rather with a custom color:

Screenshot 2023-03-29 at 14 33 23

For that i used mesh.backcolor([0, 0, 0]) but this function causes that the color of the mesh disappears and the figure looks as follows:

Screenshot 2023-03-29 at 14 36 12

My current solution is to create a second instance of mesh which i call mesh_interior with the following options:

mesh_interior = Mesh([mesh.points(), mesh.faces()])
mesh.backface_culling(True) # makes interior of mesh invisible
mesh_interior.frontface_culling(True) # makes exterior of mesh_interior invisible
mesh_interior.backcolor([0, 0, 0])

This is quite ugly as i now have two instances of the same mesh in my code which i have to manage (e.g. have to remove both for dynamic scenes etc.).

Is there a better way to do this or do you plan to improve backcolor function so that it doesnt destroy color of mesh?

marcomusy commented 1 year ago

Hi Thanks for reporting the issue unfortunately is seems to me that VTK is not supporting this... eg.

from vedo import * 

sphere = Sphere()
sphere.cut_with_plane()
scals = sphere.points()[:, 0]

sphere.pointdata["scalars"] = scals
sphere.cmap("rainbow", scals, on="points")
sphere.add_scalarbar()
sphere.backcolor("white")
sphere.mapper().ScalarVisibilityOn()

show(sphere, axes=1).close()

still shows Screenshot from 2023-03-29 15-49-35

paul0noah commented 1 year ago

Thats very interesting. On my Machine (M1 Macbook) i have the following output for:

from vedo import * 

sphere = Sphere()
sphere.cut_with_plane()
scals = sphere.points()[:, 0]

sphere.pointdata["scalars"] = scals
sphere.cmap("rainbow", scals, on="points")
sphere.add_scalarbar()
sphere.backcolor("white")

show(sphere, axes=1).close()
Screenshot 2023-03-29 at 15 57 15

and for

from vedo import * 

sphere = Sphere()
sphere.cut_with_plane()
scals = sphere.points()[:, 0]

sphere.pointdata["scalars"] = scals
sphere.cmap("rainbow", scals, on="points")
sphere.add_scalarbar()
sphere.backcolor("white")
sphere.mapper().ScalarVisibilityOn()

show(sphere, axes=1).close()
Screenshot 2023-03-29 at 15 58 02

As a conclusion i guess i have to live with my workaround?

marcomusy commented 1 year ago

As a conclusion i guess i have to live with my workaround?

yes i'm afraid :( I will investigate more the thing with vtk experts because i'm a bit surprised that it cannot be done..

paul0noah commented 1 year ago

Alright. Well at least it is do-able somehow 👍 You can close the issue already if you want to.

marcomusy commented 1 year ago

let's leave it open so I don't forget :)