vedo
vedo copied to clipboard
Surface with opacity < 1 not showing
@marcomusy nice package! Thanks.
I have just started to play with vedo, and would like to visualise some terrain with water over the top. I need to make the water transparent, so tried to use opacity = 0.5. But on my system this seems to completely make the layer disappear.
I tried one of your examples, examples/advanced/geological_model.py and have a screen dump below. I hope you can see that some of the data sets are missing (the ones which have an opacity set).
My system is from vedo --info
is
_________________________________________________________________
vedo version : 2022.2.3 https://vedo.embl.es
vtk version : 9.1.0
python version : 3.9.12 | packaged by conda-forge | (main, Mar 24 2022, 23:25:59) [GCC 10.3.0]
python interpreter: /home/anuga/miniforge3/envs/anuga39/bin/python
vedo installation : /home/anuga/miniforge3/envs/anuga39/lib/python3.9/site-packages/vedo
system : Linux 5.4.72-microsoft-standard-WSL2 posix x86_64
monitor (primary) : default, resolution=(1368, 912), x=0, y=0
I use MobaXrerm as my XServer.
By the way I am also getting this warning/error
File "/home/anuga/miniforge3/envs/anuga39/lib/python3.9/site-packages/vedo/plotter.py", line 3720, in _keypress
elif "KP_" in key: # change axes style
TypeError: argument of type 'NoneType' is not iterable
Hi Stephen, try with
pip install vtk==9.0.3
(the latest vtk seems to have some problems with the rendering of transparent objects)
Thanks @marcomusy, changed the version of vtk
. Unfortunately still have the transparency problem. Just verify that vedo
is now using vtk
version 9.0.3. Here is the output from vedo --info
_________________________________________________________________
vedo version : 2022.2.3 https://vedo.embl.es
vtk version : 9.0.3
python version : 3.9.12 | packaged by conda-forge | (main, Mar 24 2022, 23:25:59) [GCC 10.3.0]
python interpreter: /home/anuga/miniforge3/envs/anuga39/bin/python3.9
vedo installation : /home/anuga/miniforge3/envs/anuga39/lib/python3.9/site-packages/vedo
system : Linux 5.4.72-microsoft-standard-WSL2 posix x86_64
monitor (primary) : default, resolution=(1368, 912), x=0, y=0
I had thought it might be my Xserver
but I tried your napari
example and the transparency is working. Below is the output from napari --info
.
So I guess napari
doesn't use vtk
.
WARNING: QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-anuga'
WARNING:vispy:QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-anuga'
napari: 0.4.14
Platform: Linux-5.4.72-microsoft-standard-WSL2-x86_64-with-glibc2.31
System: Ubuntu 20.04.3 LTS
Python: 3.9.12 | packaged by conda-forge | (main, Mar 24 2022, 23:25:59) [GCC 10.3.0]
Qt: 5.12.9
PyQt5: 5.12.3
NumPy: 1.21.6
SciPy: 1.8.0
Dask: 2022.05.2
VisPy: 0.10.0
OpenGL:
- GL version: 3.1 Mesa 21.0.3
- MAX_TEXTURE_SIZE: 16384
Screens:
- screen 1: resolution 1368x912, scale 1.0
Plugins:
- console: 0.0.4
- scikit-image: 0.4.14
- svg: 0.1.6
hi thanks for reporting, that is very strange.. can you reproduce this:
import vtk
source = vtk.vtkCubeSource()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(source.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetOpacity(0.5)
renderer = vtk.vtkRenderer()
renderer.AddActor(actor)
renderWindow = vtk.vtkRenderWindow()
renderWindow.AddRenderer(renderer)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renderWindow)
iren.Initialize()
renderer.ResetCamera()
iren.Start()
![Screenshot 2022-05-29 at 11 27 30](https://user-images.githubusercontent.com/32848391/170861318-14d95fbb-15b1-4da1-9744-e1059b6729f4.png)
@marcomusy, your simple vtk code works fine!
OK. What about this:
import vtk
import vedo
actor = vedo.Cube().alpha(0.5)
renderer = vtk.vtkRenderer()
renderer.AddActor(actor)
renderWindow = vtk.vtkRenderWindow()
renderWindow.AddRenderer(renderer)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renderWindow)
iren.Initialize()
renderer.ResetCamera()
iren.Start()
if so, what about
import vedo
actor = vedo.Cube().alpha(0.5)
vedo.show(actor)
thanks for your patience :)
@marcomusy both of your examples worked, but adding vedo.settings.useDepthPeeling = True
caused the problem.
To be honest, I don't know what this line does!
So the following code doesn't display the cube.
import vedo
vedo.settings.useDepthPeeling = True
actor = vedo.Cube().alpha(0.9)
vedo.show(actor)
i was suspecting that! this is what it does: https://en.wikipedia.org/wiki/Depth_peeling
It's probably a graphics card issue, but i'm not sure, I guess you can live without it?
Yes I can definitely live without it!
Thanks for helping so much in tracking down the problem.
@marcomusy Thank you for the amazing package! I had the same problem: whenever I tried to tune the opacity with the attribute "alpha", the object with alpha < 1 was transparent. I tried to add settings.useDepthPeeling = False but with no luck, the object was still transparent. I tried each example you posted and they all worked well. This was the code that didn't show the object two:
from vedo import *
settings.use_depth_peeling = False
one = Mesh("right-temporal.obj", c="green").alpha(1)
two = Mesh("right-zygomatic.obj", c="red").alpha(0.9)
plt = Plotter(bg='white').add_shadows()
plt.show(one, two)
Then I found this discussion on vtk forum and I saw that someone was speaking about shadows, so I tried to delete add_shadows() from Plotter and now the object shows up! I also tried to remove the add_depth_peeling = False and was still working. This is the final working code:
from vedo import *
one = Mesh("right-temporal.obj", c="green").alpha(1)
two = Mesh("right-zygomatic.obj", c="red").alpha(0.9)
plt = Plotter(bg='white')
plt.show(one, two)
I add the output of vedo --info
_________________________________________________________________
vedo version : 2022.4.2 https://vedo.embl.es
vtk version : 9.2.5
numpy version : 1.22.4
python version : 3.10.5 (tags/v3.10.5:f377153, Jun 6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)]
python interpreter: C:\Users\X\AppData\Local\Programs\Python\Python310\python.exe
vedo installation : C:\Users\X\AppData\Local\Programs\Python\Python310\lib\site-packages\vedo
system : Windows 10 nt AMD64
monitor (primary) : \\.\DISPLAY1, resolution=(1920, 1200), x=0, y=0
If you need me to do any other test, let me know.
Hi Francesco, thanks for reporting this. Keep in mind that you can generate sort-of "fake" shadows to individual meshes which can be useful sometimes.
from vedo import *
one = Mesh(dataurl+"bunny.obj", c="green").alpha(1)
two = Mesh(dataurl+"bunny.obj", c="red").shift(0.4,0,0).alpha(0.9)
one.add_shadow("z", -0.1)
two.add_shadow("z", -0.1)
plt = Plotter(axes=1)
plt.show(one, two)
plt.close()