pyvistaqt icon indicating copy to clipboard operation
pyvistaqt copied to clipboard

Screenshot dimensions inconsistent between plotters

Open GuillaumeFavelier opened this issue 4 years ago • 6 comments

Describe the bug, what's wrong, and what you expect:

The dimensions of screenshot images are different between Plotter and BackgroundPlotter.


To Reproduce

# Insert code here
import pyvista as pv

window_size = (600, 600)
sphere = pv.Sphere()

p = pv.BackgroundPlotter(window_size=window_size)
p.add_mesh(sphere)
img1 = p.screenshot()

p = pv.Plotter(window_size=window_size)
p.add_mesh(sphere)
p.show()
img2 = p.screenshot()

print(img1.shape)
print(img2.shape)

# Result obtained:
# (546, 586, 3)
# (600, 600, 3)

# Result expected:
# (600, 600, 3)
# (600, 600, 3)


System Information:

--------------------------------------------------------------------------------
  Date: Wed Apr 29 14:42:41 2020 CEST

                OS : Linux
            CPU(s) : 4
           Machine : x86_64
      Architecture : 64bit
               RAM : 7.7 GB
       Environment : IPython
        GPU Vendor : NVIDIA Corporation
      GPU Renderer : GeForce GTX 960M/PCIe/SSE2
       GPU Version : 4.5.0 NVIDIA 430.64

  Python 3.7.6 (default, Jan  8 2020, 19:59:22)  [GCC 7.3.0]

           pyvista : 0.24.1
               vtk : 8.1.2
             numpy : 1.18.1
           imageio : 2.6.1
           appdirs : 1.4.3
            scooby : 0.5.2
            meshio : 4.0.9
        matplotlib : 3.1.3
             PyQt5 : 5.14.2
           IPython : 7.13.0
          colorcet : 1.0.0
           cmocean : 2.0
             scipy : 1.4.1
        itkwidgets : 0.26.1
              tqdm : 4.36.1

  Intel(R) Math Kernel Library Version 2020.0.0 Product Build 20191122 for
  Intel(R) 64 architecture applications
--------------------------------------------------------------------------------

GuillaumeFavelier avatar Apr 29 '20 12:04 GuillaumeFavelier

I inspected the code and this is where window_size is set:

Plotter:

https://github.com/pyvista/pyvista/blob/master/pyvista/plotting/plotting.py#L600-L603

BackgroundPlotter:

https://github.com/pyvista/pyvista/blob/master/pyvista/plotting/qt_plotting.py#L856-L862

GuillaumeFavelier avatar Apr 29 '20 12:04 GuillaumeFavelier

Saw this in the source:

# NOTE: setting BasePlotter is unnecessary and Segfaults CI

My guess is that we're not setting the window size using a signal. If we use a signal and set the window size that way, we should have the correct window size. My guess is that the window size of the widget is smaller because it's inside of the main window which includes toolbars, menus, and the border of the window itself.

akaszynski avatar Apr 29 '20 17:04 akaszynski

My guess is that the window size of the widget is smaller because it's inside of the main window which includes toolbars, menus, and the border of the window itself.

I think Alex is right. A while back, I ran into some really weird behavior when tracking the viewport coordinates of the mouse (or maybe it was widget placement) over the BackgroundPlotter... I can't remember if I posted about it or not... I'll try to dig it up

banesullivan avatar Apr 29 '20 23:04 banesullivan

I think this can be moved to pyvistaqt :)

GuillaumeFavelier avatar Oct 09 '20 12:10 GuillaumeFavelier

Has this issue been fixed in BackgroundPlotter? I had the same issue when trying to use off_screen=True. No matter what, the screenshot window_size was (300, 300). This is an edge case, since I could just use pv.Plotter() in the off_screen case, but perhaps BackgroundPlotter should not support off_screen=True, directing the user to use pv.Plotter().

benjamindkilleen avatar Mar 11 '21 12:03 benjamindkilleen

AFAIK, it's still not resolved. In MNE-Python, where we use BackgroundPlotter currently, we had to use a "tweak" to ensure the proper size of the 3d viewer.

GuillaumeFavelier avatar Mar 11 '21 17:03 GuillaumeFavelier