renderWindow.SetSize() limits?

I have been playing around with different sizes for the renderWindow… I use SetSize and then used .GetSize() to get back the values. If I did this without starting any rendering, I was able to set any dimensions to the renderWindow, however, if I rendered the size eventually had a limit (e.g. I set it to 2001, 801) and got back (1540, 801). How would I determine the limits of a renderWindow then?

As far as I understand, VTK itself doesn’t restrict the size of the window. VTK simply requests a certain size of window from the operating system, and then accepts whatever size the operating system provides.

It might be possible to find the maximum size by calling GetScreenSize() and then subtracting the number of vertical and horizontal pixels needed for menus, borders, and other decorations. But this is fiddly and not very robust.

VTK applications often rely on a GUI toolkit such as Qt to handle window sizing in situations like the one that you’re describing.

Just adding a bit more detail: the Qt QScreen class has a property called availableGeometry that provides the maximum size available for top-level windows. I’ve used availableGeometry in my own applications and it works well. VTK itself has no such method.

Thanks David,
I still cannot get my head around the fact that there is nothing regarding this issue.

Here is part of the code I have (the part that has to do with the rendering of the window):

# Visualize.
mapper = vtkDataSetMapper()
mapper.SetInputData(uGrid)

actor = vtkActor()
actor.GetProperty().SetColor(colors.GetColor3d("PeachPuff"))
actor.SetMapper(mapper)

renderer = vtkRenderer()
renderWindow = vtkRenderWindow()
renderWindow.SetSize(1801,801)
renderWindow.SetWindowName("Hexahedron")
renderWindow.AddRenderer(renderer)
renderWindowInteractor = vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)

renderer.AddActor(actor)
renderer.SetBackground(colors.GetColor3d("BkgColor"))
renderer.SetActiveCamera(camera)
renderWindow.Render()
renderWindowInteractor.Start()

And this is my following line:

renderWindow.GetSize()

with the following result: (1540, 801)

I am able to get windows larger than that so I am still trying to figure this out???

I am able to get windows larger than that so I am still trying to figure this out???

In order to help me understand better, what is the size of the “larger window” that you can get? And how do you get it? And what is your screen size? What operating system are you using (what does renderWindow.GetClassName() return?)

Thanks David. The operating system is windows. I get back is vtkWin32OpenGLRenderWindow. So ‘physically’ I should be able to get 1920 x 1080 (If I am interpreting things correctly).

You won’t be able to get 1920 x 1080 because when you call renderWindow.SetSize(), you are requesting the internal, drawable size of the window. Windows needs room to add the window decorations, such as the title bar and any window borders.

Hi David,

I just checked using renderWindow.GetScreenSize() and got (1536, 864) is that all my laptop can provide?

Since 1536 x 864 is a 16:9 ratio, it seems reasonable that it’s the true screen size. It’s a resolution that makes sense for a laptop.

You can check the display control panel on your laptop to see what the true resolution of your display is.

Hello,

I attached a 3159 x 1685 screen capture of a VTK canvas (in a Qt desktop program). I can resize it to whatever size I want, hence, whatever issue you’re having it is certainly not caused by VTK. Maybe the GUI system that creates the default window that backs vtkRenderWindow. Maybe that’s the resolution of your screen.

VTK_in_4K_display.zip (799.6 KB)

regards,

Paulo

Thank you Paulo for pointing this out!
Any idea how I can determine what GUI system I am using? What is the default for VTK?

Hi,

I believe the fallback case is a GLUT window. GLUT is a lightweight toolkit that provides very basic GUI functionality so unexperienced users and students can roll out their OpenGL applications without cumbersome GUI programming getting in the way. I’ve seen people having trouble with GLUT window sizing before but I’ve never heard of any hard limits. But I don’t work with GLUT since my undergrad years decades ago. As far as I know, OpenGL works with the limits returned by the OpenGL API backend, that is, the graphics driver. So, make sure your graphics driver is up-to-date and/or your graphics hardware is not too old.

In essence, you have to ask OpenGL what is the maximimum viewport size of your system. OpenGL API defines the C function glGetIntegerv() (Função glGetIntegerv (Gl.h) - Win32 apps | Microsoft Learn). You pass the GL_MAX_VIEWPORT_DIMS constant to it to query the maximum viewport size in pixels. Since you’re in Python, I believe you can pip install PyOpenGL in your system to access OpenGL and use a code like this (untested):

import OpenGL.GL as gl

(...)

viewport_max_sizes = gl.glGetIntegerv(gl.GL_MAX_VIEWPORT_DIMS)

From there, you can use Python’s exploration programming capabilities to get your viewport max sizes.

I hope this helps,

Paulo

VTK doesn’t use GLUT. On Windows, It uses the native Win32 API and WGL.

The place in the code where VTK creates a native Win32 window is here (in vtkWin32RenderWindow) and if my understanding is correct, any limitations on the size you get are due to display/desktop limits and are unrelated to OpenGL.

Since vtkWin32RenderWindow uses old Win32 API calls, I’m not sure how it will respond to recent Windows features like the “Scale” the Display Settings. It would be worth going to your display settings and changing the “Scale” to 100% to see if it changes the behavior of VTK. I notice, for example, that 1536 is 1920/1.25, so maybe your current “Scale” setting is 125%?

I beg to disagree here. There is indeed a maximum viewport size. In one of my computers it is 8192 x 8192 (see my post above on how to query it), which exceeds by far its 4K display, but the limit is there.

Thank you both for your comments.

@dgobbi David, you were right pointing out the issue about the scale factor. Indeed the scale was set to 125%. I set the scale to 100% and voilà I got a resolution of 1920x 1080 which appears the maximum my laptop can achieve (it is new laptop just bought it last month).

However, I am still interested in this question as the resolution affects the analysis I am interested in conducting. It would appear, following @Paulo_Carvalho that using Qt it might be possible to achieve larger resolutions. Is setting VTK with Qt hard to achieve? Can this be done using Python?

Thanks again both of you for your help and interest!!!

Hello,

Based on my experience, Qt certainly never imposed any limits. This does not mean that you can have limitless resolution. As stated above, the limit comes from underlying systems, namely the OpenGL backend, the OS, etc.

Please, take a look at this: Minimal working example of VTK embedding in PyQt with Qt5 · GitHub

regards,

Paulo

Great!

Thank you for the example, very useful!

1 Like