The code is a real crap, I'm just trying the right way to get the thing working,
but Python + DelphiVCL + VTK looks like it could go.
from delphivcl import *
from vtkmodules.vtkRenderingCore import vtkRenderWindow
from vtkmodules.vtkRenderingUI import vtkGenericRenderWindowInteractor
BASE_CLASS_NAME = WinControl
class vclVTKRenderWindowInteractor(BASE_CLASS_NAME):
def __init__(self, owner):
BASE_CLASS_NAME.__init__(self, owner)
self._RenderWindow = None
self._Iren = None
def __getattr__(self, attr):
"""Makes the object behave like a vtkGenericRenderWindowInteractor"""
if attr == '__vtk__':
return lambda t=self._Iren: t
elif hasattr(self._Iren, attr):
return getattr(self._Iren, attr)
else:
raise AttributeError(self.__class__.__name__ + " has no attribute named " + attr)
def GetRenderWindow(self):
if self._RenderWindow is None:
hwnd = self.Handle
self._RenderWindow = vtkRenderWindow()
self._RenderWindow.SetWindowInfo(str(int(hwnd)))
self._Iren = vtkGenericRenderWindowInteractor()
self._Iren.SetRenderWindow(self._RenderWindow)
return self._RenderWindow
def Render(self):
self.update()
def vclVTKRenderWindowInteractorConeExample():
"""A simple example that uses the vclVTKRenderWindowInteractor class."""
from vtkmodules.vtkFiltersSources import vtkConeSource
from vtkmodules.vtkRenderingCore import vtkActor, vtkPolyDataMapper, vtkRenderer
import vtkmodules.vtkRenderingOpenGL2
import vtkmodules.vtkInteractionStyle
class MainView(Form):
def __init__(self, owner):
self.vtk_panel = vclVTKRenderWindowInteractor(self)
self.vtk_panel.Parent = self
self.vtk_panel.Align = 'alClient'
self.vtk_panel.AlignWithMargins = True
self.vtk_panel.BevelInner = 'bvNone'
self.vtk_panel.BevelKind = 'bkFlat'
self.vtk_panel.BevelOuter = 'bvNone'
self.vtk_panel.Color = clCream
self.vtk_panel.ParentBackground = False
self.vtk_panel.Caption = 'Hello World!'
# set main form events handlers
self.OnClose = self.__on_form_close
def __on_form_close(self, sender, action):
if sender is None:
return
if sender == self:
action.Value = caFree
# initialize application
Application.Initialize()
Application.Title = ""
# create and show view
view = MainView(Application)
try:
def on_timer(Sender):
coneActor.RotateX(10)
coneActor.RotateY(5)
coneActor.RotateY(2.5)
widget.GetRenderWindow().Render()
timer.interval = 100
view.Show()
widget = view.vtk_panel
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)
widget._Iren.Initialize() # Initialize the interactor
widget._Iren.Start() # Start the interactor
timer = Timer(None)
timer.Interval = 1000
timer.OnTimer = on_timer
FreeConsole()
Application.Run()
finally:
view.Destroy()
if __name__ == '__main__':
vclVTKRenderWindowInteractorConeExample()