Commit 0a7c28ab authored by Taddeus Kroes's avatar Taddeus Kroes

Started implementing VTK interactor.

parent 3cced022
v 0.000000 2.000000 2.000000
v 0.000000 0.000000 2.000000
v 2.000000 0.000000 2.000000
v 2.000000 2.000000 2.000000
v 0.000000 2.000000 0.000000
v 0.000000 0.000000 0.000000
v 2.000000 0.000000 0.000000
v 2.000000 2.000000 0.000000
f 1 2 3 4
f 8 7 6 5
f 4 3 7 8
f 5 1 4 8
f 5 6 2 1
f 2 6 7 3
#!/usr/bin/env python
import vtk
def read_obj(filename):
reader = vtk.vtkOBJReader()
reader.SetFileName(filename)
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(reader.GetOutput())
del reader
return mapper
def main():
# Create render window and interactor
ren = vtk.vtkRenderer()
win = vtk.vtkRenderWindow()
win.AddRenderer(ren)
#iren = vtk.vtkRenderWindowInteractor()
#iren.SetRenderWindow(win)
# Read OBJ file
cubemapper = read_obj('cube.obj')
# Create actor
cubeactor = vtk.vtkActor()
cubeactor.SetMapper(cubemapper)
ren.AddActor(cubeactor)
#iren.Initialize()
win.Render()
#iren.Start()
try:
cam = ren.GetActiveCamera()
while True:
win.Render()
# Rotate
cam.Roll(.01)
# Horizontal drag
cam.Azimuth(.01)
#cam.Elevation(.01)
except KeyboardInterrupt:
return
if __name__ == '__main__':
main()
import vtk
from threading import Thread
from math import degrees
from src.gesture_server import GestureServer
from src.trackers.transform import TransformationTracker
from src.trackers.tap import TapTracker
from src.window import FullscreenWindow
class vtkMultitouchInteractor():
def __init__(self):
self.iren = vtk.vtkRenderWindowInteractor()
self.server = GestureServer()
self.window = FullscreenWindow(server=self.server)
transform = TransformationTracker(window=self.window)
transform.rotate(self.on_rotate)
transform.pinch(self.on_pinch)
tap = TapTracker(window=self.window)
tap.tap(self.on_tap)
def SetRenderWindow(self, window):
self.iren.SetRenderWindow(window)
self.window = window
def Initialize(self):
self.iren.Initialize()
self.renderer.ResetCamera()
def Start(self):
#t = Thread(target=self.iren.Start)
#t.daemon = True
#t.start()
#self.server.start()
thread = Thread(target=self.server.start)
thread.daemon = True
thread.start()
#self.iren.Start()
try:
import time
while True:
self.window.Render()
time.sleep(1. / 60)
except KeyboardInterrupt:
return
def SetRenderer(self, renderer):
self.renderer = renderer
self.camera = renderer.GetActiveCamera()
def on_rotate(self, gesture):
print 'rotate', gesture
self.camera.Roll(degrees(gesture.get_angle()))
def on_pinch(self, gesture):
pass
def on_tap(self, gesture):
print 'tap:', gesture
if __name__ == '__main__':
from tests.objreader import read_obj
# Create render window and interactor
ren = vtk.vtkRenderer()
win = vtk.vtkRenderWindow()
win.AddRenderer(ren)
mt = vtkMultitouchInteractor()
mt.SetRenderWindow(win)
# Read OBJ file
cubemapper = read_obj('tests/cube.obj')
# Create actor
cubeactor = vtk.vtkActor()
cubeactor.SetMapper(cubemapper)
ren.AddActor(cubeactor)
mt.SetRenderer(ren)
mt.Initialize()
win.Render()
mt.Start()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment