Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vedo Points becomes White or Transparent #1039

Open
DRLing2021 opened this issue Jan 30, 2024 · 20 comments
Open

Vedo Points becomes White or Transparent #1039

DRLing2021 opened this issue Jan 30, 2024 · 20 comments

Comments

@DRLing2021
Copy link

We encountered problems when plotting point cloud points by Vedo in a pyside2 environment. It was good before however, without any notice of system change, points become white or transparent when run the same code recently. We tried the explore5D sample code on our system and got the same issue. Are there any suggestions to fix it?

Attached the explore5D output as FYI
Python 3.9.7
vedo: 2023.5.0
matplotlib: 3.7.3
vedo_error

@marcomusy
Copy link
Owner

Thanks for reporting, this is a weird bug in VTK which happens only on some machines.
Try

mypoints.render_points_as_spheres(False)

@DRLing2021
Copy link
Author

Thank you Marcomusy! The code above did work initially.

Unfortunately, we passed the first plot but the later plot causes fatal errors. Due to biz reason we can't provide the code here. The working logic is simple: we first plot the raw point cloud, then do different works against those points and passed the new points, numpy array, to ploter to replot it. at the plotter we do:

mypoints = Points(self.xyz,c ="rainbow")
mypoints.render_points_as_spheres(False)
plt.show(mypoints,zoom=1.3,axes=1, title = plot_type)

This was running in a multithreading framework of pyside2. That means a worker to do the data process and the main thread deal with plotting. Data passed between them are numpy arrays.

The error codes are :

Windows fatal exception: access violation

Thread 0x00002af4 (most recent call first):
File "our_env\lib\concurrent\futures\thread.py", line 75 in _worker
File "our_env\lib\threading.py", line 910 in run
File "our_env\lib\threading.py", line 973 in _bootstrap_inner
File "our_env\lib\threading.py", line 930 in _bootstr

Appreciate if you can provide further assistance.
Regards

DR.

@DRLing2021
Copy link
Author

BTW, we did plt.clear() before the plotting

@DRLing2021
Copy link
Author

The code was running in a spyder console, The final error msg following above are :

Main thread:
Current thread 0x00002ac0 (most recent call first):
File "our_env\lib\site-packages\vedo\plotter.py", line 3235 in show
....
File "our_env\lib\site-packages\spyder_kernels\py3compat.py", line 356 in compat_exec
File "our_env\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 469 in exec_code
File "our_env\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 611 in _exec_file
File "our_env\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 524 in runfile
File "C:\Users\Complie-WIN10\AppData\Local\Temp\ipykernel_10088\3320116497.py", line 1 in

@marcomusy
Copy link
Owner

This seems related to the qt widget line 3235 is

        if self.qt_widget is not None:
            self.qt_widget.GetRenderWindow().AddRenderer(self.renderer)

can you try it on the dev version:

pip install -U git+https://github.com/marcomusy/vedo.git

@marcomusy
Copy link
Owner

PS: also add

settings.enable_default_mouse_callbacks = False
settings.enable_default_keyboard_callbacks = False
settings.enable_pipeline = False

@DRLing2021
Copy link
Author

Hello,2024.5.0+dev31 installed. where to pu the following settings? in my working py or vedo setting files?

settings.enable_default_mouse_callbacks = False
settings.enable_default_keyboard_callbacks = False
settings.enable_pipeline = False

@DRLing2021
Copy link
Author

Installed dev31 and put settings into our py code. The result2 are:

  1. The initial plot disappared from plot window but move to somewhere outside view. We need to zoom to find it

  2. The flowup plot got errors as following:

    self.plt.show(mypoints,zoom=1.3,axes=1, title= plot_type) ## axes= 1/7/11

File our_env\site-packages\vedo\plotter.py:3288 in show
bns = self.renderer.ComputeVisiblePropBounds()
AttributeError: 'NoneType' object has no attribute 'ComputeVisiblePropBounds'

@DRLing2021
Copy link
Author

We did further tests ,here are some information:

  1. comment out the mouse and keyboard call back settting (=False), the inital plotter remains at the central of window without errors
  2. remove the pipline settings cause plt.clear() errors as following:

File out_envs\lib\site-packages\vedo\plotter.py:3489 in clear
self.get_meshes()
File our_env\lib\site-packages\vedo\plotter.py:1211 in get_meshes
at = self.renderers.index(renderer)
ValueError: <vtkmodules.vtkRenderingOpenGL2.vtkOpenGLRenderer(0x000001DFF0442770) at 0x000001DFF7CCB460> is not in list

PS
If we want to clean up older points' show before plotting new points, are there any better way than plt.clear()? It looks like the clear() causes item 2 above.

@DRLing2021
Copy link
Author

DRLing2021 commented Jan 31, 2024 via email

@DRLing2021
Copy link
Author

Hi Marco, would you please advise what to do to deal with the new error messages?

File our_env\site-packages\vedo\plotter.py:3288 in show
bns = self.renderer.ComputeVisiblePropBounds()
AttributeError: 'NoneType' object has no attribute 'ComputeVisiblePropBounds'

@marcomusy
Copy link
Owner

Sorry, i was away, you put the senttings in your script on top E.g.:

import vedo

vedo.settings.enable_default_mouse_callbacks = False
vedo.settings.enable_default_keyboard_callbacks = False

to add and remove object do not use clear() rather give individual objects a name and add/remove them individualy:

def mycallback(event):
    # in some callback:
    obj1 = vedo.Points(...)
    obj1.name = "mypoints"
    # remove some other previous Points and add the new one:
    plotter.remove("mypoints").add(obj1, obj2, ...) 
    # plotter.reset_camera()  # if needed
    plotter.render()

plotter = vedo.Plotter()
plotter.add_callback("key press", mycallback)
plotter.show(some objects, ....)

there are many examples showing this mechanism e.g.:
examples/basic/mousehighlight.py
examples/volumetric/slicer2.py
...
make sure you can reproduce those.

vedo --search remove

@DRLing2021
Copy link
Author

No problem Macro. We did what you suggested with some changes as the plots' show use different parms as following:

The first plot use no remove command as there is nothing yet but we give it a name
self.Show_PC = Points(self.xyz,c="green") ### actors of points
self.Show_PC.name = "last" ##
self.Show_PC.render_points_as_spheres(False)
print("Points Gened")
self.Show_PC.cmap('viridis', Z)
self.plt.show(self.Show_PC,zoom=1.3,axes=1, title= plot_type)

The following re-plots with new data we use the following codes:
self.Show_PC = Points(self.xyz,c="green") ### actors of points
self.Show_PC.name = "last" ##
self.Show_PC.render_points_as_spheres(False)
print("Tiered Gened")
self.Show_PC.cmap('viridis', Z) #,name="mydata")

        self.plt.remove("last")  ##.add(self.Show_PC)  we use show below but not
        self.plt.show(self.Show_PC,zoom=2.35axes=1, title= plot_type) 

Unfortunately we got following errors:

self.plt.remove("last") ##.add(self.Show_PC)

File our_env\lib\site-packages\vedo\plotter.py:995 in remove
for a in self.get_actors(include_non_pickables=True):
File our_env\lib\site-packages\vedo\plotter.py:1287 in get_actors
at = self.renderers.index(renderer)
ValueError: None is not in list

1 similar comment
@DRLing2021
Copy link
Author

No problem Macro. We did what you suggested with some changes as the plots' show use different parms as following:

The first plot use no remove command as there is nothing yet but we give it a name
self.Show_PC = Points(self.xyz,c="green") ### actors of points
self.Show_PC.name = "last" ##
self.Show_PC.render_points_as_spheres(False)
print("Points Gened")
self.Show_PC.cmap('viridis', Z)
self.plt.show(self.Show_PC,zoom=1.3,axes=1, title= plot_type)

The following re-plots with new data we use the following codes:
self.Show_PC = Points(self.xyz,c="green") ### actors of points
self.Show_PC.name = "last" ##
self.Show_PC.render_points_as_spheres(False)
print("Tiered Gened")
self.Show_PC.cmap('viridis', Z) #,name="mydata")

        self.plt.remove("last")  ##.add(self.Show_PC)  we use show below but not
        self.plt.show(self.Show_PC,zoom=2.35axes=1, title= plot_type) 

Unfortunately we got following errors:

self.plt.remove("last") ##.add(self.Show_PC)

File our_env\lib\site-packages\vedo\plotter.py:995 in remove
for a in self.get_actors(include_non_pickables=True):
File our_env\lib\site-packages\vedo\plotter.py:1287 in get_actors
at = self.renderers.index(renderer)
ValueError: None is not in list

@DRLing2021
Copy link
Author

Hi Macro,

We‘ve tried serval ways but the "remove " seems never work. Basically what we do are as:
Step1: Plot the raw data

        self.Show_PC = Points(self.xyz,c="green")  <=== convert numpy to Points 
        self.Show_PC.name = "last"   <=== give Points a name "last"
        self.Show_PC.render_points_as_spheres(False)    <=== To fix the White/Transparent issue
        self.Show_PC.cmap('viridis', Z)   <=== assign a cmap 
        self.plt.add(self.Show_PC)   <=== add "last " to Plotter
        self.plt.show(zoom=1.3,axes=1, title= plot_type)   <=== render with parms (this is different from what you 
                             said and from samples )

Step2: Processed the raw data and get new data
Setp2: Plot the new data

        self.Show_PC = Points(self.xyz,c="green")  <=== assign new data to Points 
        self.Show_PC.name = "last"  <=== give a name, same as before, to new Points
        self.Show_PC.render_points_as_spheres(False)  <=== To fix the White/Transparent issue
        self.Show_PC.cmap('viridis', Z)    <=== assign a cmap 
        self.plt.remove("last").add(self.Show_PC)  <=== this is where ERROR reported  
        self.plt.show(zoom=1.3,axes=1, title= plot_type)  ## axes= 1/7/11

The error msg are:

 File our_env\lib\site-packages\vedo\plotter.py:995 in remove
   for a in self.get_actors(include_non_pickables=True):

 File our_env\lib\site-packages\vedo\plotter.py:1287 in get_actors
   at = self.renderers.index(renderer)

  ValueError: None is not in list

Would you mind to advice what to do to fix it? Do we do it in a right way or are there something missing here to make it run? We need to fix it to move the work ahead. Your help is highly appreciated.

@DRLing2021
Copy link
Author

The definition of self.plt in our code is

self.vtkWidget = QVTKRenderWindowInteractor(self.Plot_Frame_3d)
self.plt = Plotter(qt_widget=self.vtkWidget,axes=1)

This is different from the sample codes we got from vedo --search xxxx. It this reason why we encountered those errors?

@DRLing2021
Copy link
Author

Hi Macro, we did further investigation and got the latest results as following:

  1. Vedo sample code, examples/volumetric/slicer2.py, runs well with the desired result

vedo_error_slice_works

  1. Our Vedo scrip still stuck with the errors:

    File our_env\lib\site-packages\vedo\plotter.py:995 in remove
    for a in self.get_actors(include_non_pickables=True):

    File our_env\lib\site-packages\vedo\plotter.py:1287 in get_actors
    at = self.renderers.index(renderer)

    ValueError: None is not in list

Our running enviroment:
VTK: 9.26.
Qt interrface: PySide2 <===== suspect this is the error causer?
We checked the Plotter code line 995 and later. It seems that the renderer is not picked correctly when running our working code. But it is ok for the slicer2.py sample code. One major difference between the codes is that ours runs in a qt framework through pyside2 interface.
self.Plot_Frame_3d = QFrame(self.centralwidget)
...
self.vtkWidget = QVTKRenderWindowInteractor(self.Plot_Frame_3d)
self.plt = Plotter(qt_widget=self.vtkWidget,axes=1)

  1. We suspect the error relates to pysideX version. After checking Vedo Github we found that in vtkmodules_9.2.6_hierarchy.txt there is no pyside* information rather in vtkmodules_9.3.0_hierarchy.txt there is one place says:
    vtkmodules.qt.QVTKRenderWindowInteractor.PySide6
    Does it mean that we should upgrade to pyside6 and vtk 9.3.0? Since upgrade from pyside2 to pyside6 needs lots script changes we haven't done this step yet.

Would you mind to kindely help us to move it forward as our work has been suspended for days waiting to see the visual result to descide the next step. Thanks in advance.! @marcomusy

@DRLing2021
Copy link
Author

Hi Marcro, Just want to let you know that after various experiments, we figured out that if Show() is BEFORE add(), things are ok. This is weired. But add/remove issues is fixed !

@marcomusy
Copy link
Owner

Hi @DRLing2021 sorry for the delay - i'm happy that you managed to fix the problem, just to confirm that the general structure is

def somecallback():
  # here you call add(), remove(), render() 
  # or plt += some_object
  # but NOT show()

# in your main script you define the Plotter and call show() only once, which does a number of inittializations
plt = Plotter()
plt += Sphere()
...
plt.add_callback("key press", somecallback)
plt.show()

Obviously you can have plt as a member of a class, but the general idea is the same.
Please look at some examples, especially the ones in examples/other/qt_*.py

@DRLing2021
Copy link
Author

Hi Marco, thanks for you coments. Sorry for late update as I have been on leave last weeks. The code we run on experimental env is different from what suggested above in that the plotter.show() has to be BEFORE add(). The sample code is as following:

Vedo_Show.txt
Gen_3D_Data.txt

The questions regarding above codes are :

  1. Are there anything wrong, or double wrong, in the codes that cause the show() has to be BEFORE add()?
  2. The code is suppose to increase the Z value scale after each button press. it results in the points zoom out of view. Is there anyway to set "autoscale" so that all points fit into the show window?

PS we use pyside2 that is different from the sample examples/other/qt_*.py, We guess it should not be a problem

Regards.
DR, Ling

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants