Hi, I was doing some testing with VTK and WXPython in a MacBook Air M1. I’m using VTK 9.1.0 and WXPython 4.1.1. One thing that I noticed is vtkRenderer and vtkRenderWindow when inside a wxVTKRenderWindowInteractor have the size doubled of wxVTKRenderWindowInteractor. I’m using this Python script as test, when you move the mouse it’ll print the size of vtkRenderer, vtkRenderWindow and wxVTKRenderWindowInteractor, something like:
iren: (400, 372), rwin: (800, 744), ren: (800, 744)
You can see that RenderWindow have its size two times greater than RenderWindowInteractor. Is that expected? Or is it a bug? Then I use vtkRenderWindowInteractor this doesn’t happen. Thanks!
The script:
from vtkmodules.vtkFiltersSources import vtkConeSource
from vtkmodules.vtkRenderingCore import vtkActor, vtkPolyDataMapper, vtkRenderer
from vtk.wx.wxVTKRenderWindowInteractor import wxVTKRenderWindowInteractor
import wx
def onMouseMove(obj, evt):
iren = obj
rwin = obj.GetRenderWindow()
ren = rwin.GetRenderers().GetFirstRenderer()
print(f"iren: {iren.GetSize()}, rwin: {rwin.GetSize()}, ren: {ren.GetSize()}")
# every wx app needs an app
app = wx.App(False)
# create the top-level frame, sizer and wxVTKRWI
frame = wx.Frame(None, -1, "wxVTKRenderWindowInteractor", size=(400,400))
widget = wxVTKRenderWindowInteractor(frame, -1)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(widget, 1, wx.EXPAND)
frame.SetSizer(sizer)
frame.Layout()
# It would be more correct (API-wise) to call widget.Initialize() and
# widget.Start() here, but Initialize() calls RenderWindow.Render().
# That Render() call will get through before we can setup the
# RenderWindow() to render via the wxWidgets-created context; this
# causes flashing on some platforms and downright breaks things on
# other platforms. Instead, we call widget.Enable(). This means
# that the RWI::Initialized ivar is not set, but in THIS SPECIFIC CASE,
# that doesn't matter.
widget.Enable(1)
widget.AddObserver("ExitEvent", lambda o,e,f=frame: f.Close())
widget.AddObserver("MouseMoveEvent", onMouseMove)
ren = vtkRenderer()
widget.GetRenderWindow().AddRenderer(ren)
cone = vtkConeSource()
cone.SetResolution(8)
coneMapper = vtkPolyDataMapper()
coneMapper.SetInputConnection(cone.GetOutputPort())
coneActor = vtkActor()
coneActor.SetMapper(coneMapper)
ren.AddActor(coneActor)
# show the window
frame.Show()
app.MainLoop()