Text archives Help
- From: abe@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [Manta] r1964 - trunk/SwigInterface
- Date: Thu, 3 Jan 2008 17:53:19 -0700 (MST)
Author: abe
Date: Thu Jan 3 17:53:18 2008
New Revision: 1964
Added:
trunk/SwigInterface/CameraFrame.py
trunk/SwigInterface/LightFrame.py
trunk/SwigInterface/MiscFrames.py
Modified:
trunk/SwigInterface/runwxmanta.py
trunk/SwigInterface/wxManta.py
Log:
Reorganized some of Manta's python interface (in the process of adding
support for different image traversers from python).
M SwigInterface/runwxmanta.py
M SwigInterface/wxManta.py
Added access to a python shell prompt.
A SwigInterface/MiscFrames.py
Updated the camera edit dialog to update displayed values as the user
moves the camera.
A SwigInterface/CameraFrame.py
Updated the layout & size of the frame.
A SwigInterface/LightFrame.py
Added: trunk/SwigInterface/CameraFrame.py
==============================================================================
--- (empty file)
+++ trunk/SwigInterface/CameraFrame.py Thu Jan 3 17:53:18 2008
@@ -0,0 +1,235 @@
+import wx;
+import re;
+
+from manta import *
+from pycallback import *
+from wx.lib.evtmgr import eventManager as EventManager;
+
+import FloatSpin as FS
+
+###############################################################################
+###############################################################################
+# CAMERA FRAME CAMERA FRAME CAMERA FRAME CAMERA
FRAME
+###############################################################################
+###############################################################################
+
+class CameraFrame(wx.Frame):
+ def __init__(self, parent, engine):
+ wx.Frame.__init__(self, parent=parent, title="Camera")
+
+ data = engine.getCamera(0).getBasicCameraData()
+ eye = data.eye
+ lookat = data.lookat
+ up = data.up
+ hfov = data.hfov
+ vfov = data.vfov
+
+ self.engine = engine
+ self.parent = parent
+
+ vsizer = wx.BoxSizer(wx.VERTICAL)
+ gsizer = wx.GridBagSizer(6,4);
+
+ self.channelST = wx.StaticText(self, -1, "Channel: ")
+ self.channelSP = wx.SpinCtrl(self, -1, "", (30,50))
+ self.channelSP.SetRange(0,100)
+ self.channelSP.SetValue(0)
+ gsizer.Add(self.channelST, (0,0))
+ gsizer.Add(self.channelSP, (0,1))
+
+ self.eyeST = wx.StaticText(self, -1, "eye: " )
+ self.eyeXSP = self.addSpinner(self, eye.x())
+ self.eyeYSP = self.addSpinner(self, eye.y())
+ self.eyeZSP = self.addSpinner(self, eye.z())
+ gsizer.Add(self.eyeST, (1,0))
+ gsizer.Add(self.eyeXSP, (1,1))
+ gsizer.Add(self.eyeYSP, (1,2))
+ gsizer.Add(self.eyeZSP, (1,3))
+
+ self.lookatST = wx.StaticText(self, -1, "lookat: ")
+ self.lookXSP = self.addSpinner(self, lookat.x())
+ self.lookYSP = self.addSpinner(self, lookat.y())
+ self.lookZSP = self.addSpinner(self,lookat.z())
+ # self.lookZTCL = wx.TextCtrl(self, -1, str(lookat.z()),
size=(125,-1))
+ gsizer.Add(self.lookatST, (2,0))
+ gsizer.Add(self.lookXSP, (2,1))
+ gsizer.Add(self.lookYSP, (2,2))
+ gsizer.Add(self.lookZSP, (2,3))
+
+ self.upST = wx.StaticText(self, -1, "up: ")
+ self.upXSP = self.addSpinner(self, up.x())
+ self.upYSP = self.addSpinner(self, up.y())
+ self.upZSP = self.addSpinner(self, up.z())
+ gsizer.Add(self.upST, (3,0))
+ gsizer.Add(self.upXSP, (3,1))
+ gsizer.Add(self.upYSP, (3,2))
+ gsizer.Add(self.upZSP, (3,3))
+
+ gsizer.Add(wx.StaticText(self, -1, "fov horiz: "), (4,0))
+ self.fovXSP = self.addSpinner(self, hfov)
+ gsizer.Add(self.fovXSP, (4,1))
+
+ gsizer.Add(wx.StaticText(self, -1, "vert: "), (4,2))
+ self.fovYSP = self.addSpinner(self, vfov)
+ gsizer.Add(self.fovYSP, (4,3))
+ vsizer.Add(gsizer, 0, wx.ALIGN_CENTER )
+
+ vsizer.Add(wx.StaticText(self,-1,"Enter camera description:"), 0,
wx.ALIGN_LEFT );
+
+ self.stringTCL = wx.TextCtrl(self, -1, "camera string",
size=(-1,50), style=wx.TE_MULTILINE)
+ self.ComputeString()
+ self.stringB = wx.Button(self, -1, "Set")
+ vsizer.Add(self.stringTCL, 1, wx.EXPAND )
+ vsizer.Add(self.stringB, 0, wx.ALIGN_RIGHT)
+
+ hsizer = wx.BoxSizer( wx.HORIZONTAL );
+ self.okButton = wx.Button(self, wx.ID_OK)
+ self.applyButton = wx.Button(self, wx.ID_APPLY)
+ hsizer.Add(self.okButton, 0, wx.ALIGN_CENTER)
+ hsizer.Add(self.applyButton, 0, wx.ALIGN_CENTER)
+ vsizer.Add(hsizer, 0, wx.ALIGN_CENTER);
+
+ self.SetSizerAndFit(vsizer);
+
+ self.Bind(wx.EVT_BUTTON, self.OnClickOK, self.okButton)
+ self.Bind(wx.EVT_BUTTON, self.OnClickApply, self.applyButton)
+ self.Bind(wx.EVT_BUTTON, self.OnClickSet, self.stringB)
+ self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
+
+ # Double bind mouse events in the Manta canvas.
+ EventManager.Register( self.OnManipulation, wx.EVT_MOTION,
self.parent.canvas );
+ EventManager.Register( self.OnManipulation, wx.EVT_MOUSEWHEEL,
self.parent.canvas );
+
+ def OnManipulation(self,event):
+
+ data = self.engine.getCamera(0).getBasicCameraData();
+ self.UpdateBasicCameraData(data);
+
+ def UpdateBasicCameraData(self,data):
+
+ eye = data.eye
+ lookat = data.lookat
+ up = data.up
+ hfov = data.hfov
+ vfov = data.vfov
+
+ self.eyeXSP.SetValue( eye.x() );
+ self.eyeYSP.SetValue( eye.y() );
+ self.eyeZSP.SetValue( eye.z() );
+
+ self.lookXSP.SetValue( lookat.x() );
+ self.lookYSP.SetValue( lookat.y() );
+ self.lookZSP.SetValue( lookat.z() );
+
+ self.upXSP.SetValue( up.x() );
+ self.upYSP.SetValue( up.y() );
+ self.upZSP.SetValue( up.z() );
+
+ self.fovXSP.SetValue( hfov );
+ self.fovYSP.SetValue( vfov );
+
+ self.ComputeString()
+
+ def OnClickSet(self, evt):
+
+ print "Note this still doesn't match the standard basic camera
format"
+
+ p = re.compile('(-?\d+\.?\d*)')
+ s = p.findall(self.stringTCL.GetValue())
+ print s
+ try:
+ self.eyeXSP.SetValue(float(s[0]))
+ self.eyeYSP.SetValue(float(s[1]))
+ self.eyeZSP.SetValue(float(s[2]))
+ self.lookXSP.SetValue(float(s[3]))
+ self.lookYSP.SetValue(float(s[4]))
+ self.lookZSP.SetValue(float(s[5]))
+ self.upXSP.SetValue(float(s[6]))
+ self.upYSP.SetValue(float(s[7]))
+ self.upZSP.SetValue(float(s[8]))
+ self.fovXSP.SetValue(float(s[9]))
+ self.fovYSP.SetValue(float(s[10]))
+ except ValueError:
+ print "incorrect string value"
+
+ def ComputeString(self):
+
+ ex = float(self.eyeXSP.GetValue())
+ ey = float(self.eyeYSP.GetValue())
+ ez = float(self.eyeZSP.GetValue())
+
+ lx = float(self.lookXSP.GetValue()) #float(self.lookXTCL.GetValue())
+ ly = float(self.lookYSP.GetValue())
+ lz = float(self.lookZSP.GetValue())
+
+ ux = float(self.upXSP.GetValue())
+ uy = float(self.upYSP.GetValue())
+ uz = float(self.upZSP.GetValue())
+ hfov = float(self.fovXSP.GetValue())
+ vfov = float(self.fovYSP.GetValue())
+
+ s = '-eye %f %f %f -lookat %f %f %f -up %f %f %f -hfov %f -vfov %f'
% (ex,ey,ez,lx,ly,lz,ux,uy,uz,hfov,vfov)
+ self.stringTCL.SetValue(s)
+
+
+ def addSpinner(self, where, value, id=wx.ID_ANY):
+ floatspin = FS.FloatSpin(where, id,
+ increment=0.01, value=value,
+ extrastyle=FS.FS_LEFT)
+ floatspin.SetFormat("%g")
+ floatspin.SetDigits(5)
+ floatspin.Bind(FS.EVT_FLOATSPIN, self.OnFloatSpin)
+ return floatspin
+
+ def OnFloatSpin(self, event):
+ # Pull out the new value
+ # spinner = event.GetEventObject()
+ # x = float(spinner.GetValue())
+ self.ApplySettings()
+ self.ComputeString()
+
+ def OnClickOK(self, evt):
+ self.ApplySettings()
+ self.Close(True)
+
+ def OnClickApply(self, evt):
+ self.ApplySettings()
+
+ def ApplySettings(self):
+
+ channel = int(self.channelSP.GetValue())
+ ex = float(self.eyeXSP.GetValue())
+ ey = float(self.eyeYSP.GetValue())
+ ez = float(self.eyeZSP.GetValue())
+
+ lx = float(self.lookXSP.GetValue()) #float(self.lookXTCL.GetValue())
+ ly = float(self.lookYSP.GetValue())
+ lz = float(self.lookZSP.GetValue())
+
+ ux = float(self.upXSP.GetValue())
+ uy = float(self.upYSP.GetValue())
+ uz = float(self.upZSP.GetValue())
+
+ eye = manta_new(Vector(ex,ey,ez))
+ lookat = manta_new(Vector(lx,ly,lz))
+ up = manta_new(Vector(ux, uy,uz))
+ fovx = float(self.fovXSP.GetValue())
+ fovy = float(self.fovYSP.GetValue())
+
+ data = manta_new(BasicCameraData(eye, lookat, up, fovx, fovy))
+
+ # Send a transaction to manta to update the camera.
+ cbArgs = ( data, )
+ self.engine.addTransaction("Set basic camera data",
+
manta_new(createMantaTransaction(self.engine.getCamera(channel).setBasicCameraData,
cbArgs)))
+
+
+ def OnCloseWindow(self, evt):
+
+ # Disconnect from events...
+ EventManager.DeregisterListener( self.OnManipulation );
+
+ self.Destroy()
+
+
+
Added: trunk/SwigInterface/LightFrame.py
==============================================================================
--- (empty file)
+++ trunk/SwigInterface/LightFrame.py Thu Jan 3 17:53:18 2008
@@ -0,0 +1,221 @@
+import wx
+from manta import *
+from pycallback import *
+
+import FloatSpin as FS
+import wx.lib.colourselect as csel
+
+# Clamps values between 0 and 255
+def clampZeroTo255(val):
+ return max(0,min(255,val))
+
+###############################################################################
+###############################################################################
+# LIGHT FRAME LIGHT FRAME LIGHT FRAME LIGHT FRAME
+###############################################################################
+###############################################################################
+class LightFrame(wx.Frame):
+ def __init__(self, parent, engine):
+ wx.Frame.__init__(self, parent=parent, title="Lights")
+
+ self.engine = engine
+ self.colorButtonRefs = {}
+
+ vsizer = wx.BoxSizer( wx.VERTICAL );
+
+ hsizer = wx.BoxSizer( wx.HORIZONTAL );
+ hsizer.Add( wx.StaticText( self, -1, "Changes applied interactively"
), 0, wx.ALIGN_CENTER );
+ vsizer.Add( hsizer );
+
+ panel= wx.Panel(self, -1)
+ gbs = wx.GridBagSizer(5,7)
+
+ lights = engine.getScene().getLights()
+ for i in range(lights.numLights()):
+ gbs.Add( self.addLight(panel, lights.getLight(i)), (i, 0),
flag=wx.ALIGN_CENTER_VERTICAL )
+
+ button = wx.Button(self, -1, "Close")
+ panel.SetSizer(gbs)
+
+ vsizer.Add( panel, 0, wx.EXPAND );
+
+ hsizer = wx.BoxSizer( wx.HORIZONTAL );
+ hsizer.Add( button, 0, wx.ALIGN_CENTER );
+
+ vsizer.Add( hsizer, 0, wx.ALIGN_CENTER );
+ self.SetSizerAndFit( vsizer );
+
+ self.Bind(wx.EVT_BUTTON, self.OnCloseMe, button)
+ self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
+
+ def OnCloseMe(self, event):
+ self.Close(True)
+
+ def OnCloseWindow(self, event):
+ self.Destroy()
+
+ def addLight(self, where, light):
+ point_light = PointLight.fromLight(light)
+ if (point_light != None):
+ return self.addPointLight(where, point_light)
+ head_light = HeadLight.fromLight(light)
+ if (head_light != None):
+ return self.addHeadLight(where, head_light)
+
+ def addHeadLight(self, where, light):
+ offset = light.getOffset()
+
+ panel = wx.Panel(where, -1)
+
+ gbs = wx.GridBagSizer(5,1)
+ gbs.Add( wx.StaticText(panel, -1, "Offset"), (0,0))
+ spinnerOffset = self.addSpinner(panel, offset)
+ spinnerOffset.light = light
+ # Override the callback function
+ spinnerOffset.Bind(FS.EVT_FLOATSPIN, self.OnOffsetSpin)
+ gbs.Add( spinnerOffset, (0,1))
+
+ colorWidgets = self.AddColorButton(light, panel)
+ gbs.Add( colorWidgets["colorButton"], (0,2))
+ gbs.Add( wx.StaticText(where, -1, "Color Scale"), (0,3))
+ gbs.Add( colorWidgets["colorScaleSpinner"], (0,4) )
+
+ panel.SetSizer(gbs)
+ return panel
+
+ def addPointLight(self, where, light):
+ location = light.getPosition()
+
+ panel = wx.Panel(where, -1)
+
+ gbs = wx.GridBagSizer(7,1)
+ gbs.Add( wx.StaticText(panel, -1, "Location"), (0,0),
flag=wx.ALIGN_CENTER_VERTICAL )
+ spinnerX = self.addSpinner(panel, location.x())
+ spinnerY = self.addSpinner(panel, location.y())
+ spinnerZ = self.addSpinner(panel, location.z())
+ spinnerX.light = light
+ spinnerX.X = spinnerX
+ spinnerX.Y = spinnerY
+ spinnerX.Z = spinnerZ
+ spinnerY.light = light
+ spinnerY.X = spinnerX
+ spinnerY.Y = spinnerY
+ spinnerY.Z = spinnerZ
+ spinnerZ.light = light
+ spinnerZ.X = spinnerX
+ spinnerZ.Y = spinnerY
+ spinnerZ.Z = spinnerZ
+ gbs.Add( spinnerX, (0,1), flag=wx.ALIGN_CENTER_VERTICAL)
+ gbs.Add( spinnerY, (0,2), flag=wx.ALIGN_CENTER_VERTICAL)
+ gbs.Add( spinnerZ, (0,3), flag=wx.ALIGN_CENTER_VERTICAL)
+
+ colorWidgets = self.AddColorButton(light, panel)
+ gbs.Add( colorWidgets["colorButton"], (0,4),
flag=wx.ALIGN_CENTER_VERTICAL)
+ gbs.Add( wx.StaticText(where, -1, "Color Scale"), (0,5),
flag=wx.ALIGN_CENTER_VERTICAL)
+ gbs.Add( colorWidgets["colorScaleSpinner"], (0,6),
flag=wx.ALIGN_CENTER_VERTICAL )
+
+
+ panel.SetSizer(gbs)
+ return panel
+
+ def addSpinner(self, where, value, id=wx.ID_ANY):
+ floatspin = FS.FloatSpin(where, id,
+ increment=0.01, value=value,
+ extrastyle=FS.FS_LEFT)
+ floatspin.SetFormat("%g")
+ floatspin.SetDigits(5)
+ floatspin.Bind(FS.EVT_FLOATSPIN, self.OnFloatSpin)
+ return floatspin
+
+ def OnFloatSpin(self, event):
+ # Pull out the new value
+ spinner = event.GetEventObject()
+ x = float(spinner.X.GetValue())
+ y = float(spinner.Y.GetValue())
+ z = float(spinner.Z.GetValue())
+ newPosition = Vector(x,y,z)
+ cbArgs = ( newPosition, )
+ self.engine.addTransaction("Light Position",
+
manta_new(createMantaTransaction(spinner.light.setPosition, cbArgs)))
+
+ def OnOffsetSpin(self, event):
+ # Pull out the new value
+ spinner = event.GetEventObject()
+ offset = float(spinner.GetValue())
+ cbArgs = ( offset, )
+ self.engine.addTransaction("Light Offset",
+
manta_new(createMantaTransaction(spinner.light.setOffset, cbArgs)))
+
+ def AddColorButton(self, light, where):
+ color = light.getColor().convertRGB()
+
+ # Because our colors can be more than one we need to do a
+ # little bit of work. The color selector can't deal with
+ # floating point colors, and it must work with ranges [0,255].
+ # In order to overcome this limitation, we are going to use a
+ # scale. If all your color components are less than 1, then
+ # the scale will be 1, otherwise it will be scaled by the
+ # maximum component.
+ colorTupRaw = [ color.r(), color.g(), color.b() ]
+ maxComponent = max(colorTupRaw)
+ print "maxComponent = %g" % (maxComponent)
+ if (maxComponent <= 1):
+ colorScale = 1
+ else:
+ colorScale = maxComponent
+ colorTup = map(lambda c:clampZeroTo255(int(c*255/colorScale)),
+ colorTupRaw)
+
+ colorButton = csel.ColourSelect(where, wx.ID_ANY, "Color",
+ tuple(colorTup))
+ colorButton.Bind(csel.EVT_COLOURSELECT, self.OnSelectColor)
+ # You have to use these refs, because the event you get in
+ # your callback doesn't contain the actual colorButton object.
+ # All you can be sure of is the ID.
+ self.colorButtonRefs[colorButton.GetId()] = colorButton
+ colorButton.light = light
+
+
+ # Add the scale
+ print "colorScale = %g, maxComponent = %g" %
(colorScale,maxComponent)
+ # I tried to make the ID the same as the colorButton and bind
+ # it to the same callback, but wxMac didn't like it. Thus,
+ # the spinner now gets its own callback.
+ colorScaleSpinner = FS.FloatSpin(where, wx.ID_ANY,
+ min_val=1, increment=0.01,
+ value=colorScale,
+ extrastyle=FS.FS_LEFT)
+ colorScaleSpinner.SetFormat("%g")
+ colorScaleSpinner.SetDigits(5)
+ colorScaleSpinner.Bind(FS.EVT_FLOATSPIN, self.OnColorScaleSpin)
+ colorScaleSpinner.button = colorButton
+ colorButton.spinner = colorScaleSpinner
+
+ # Shoving multiple results in a dictionary will make things a little
easier to read.
+ results = {"colorButton":colorButton,
"colorScaleSpinner":colorScaleSpinner}
+ return results
+
+ def UpdateColor(self, colorButton):
+ color = colorButton.GetColour()
+ colorScale = float(colorButton.spinner.GetValue()) / 255.0
+ rgbColor = RGBColor(color.Red() * colorScale,
+ color.Green() * colorScale,
+ color.Blue() * colorScale)
+ cbArgs = ( Color(rgbColor), )
+ self.engine.addTransaction("Light Color",
+
manta_new(createMantaTransaction(colorButton.light.setColor, cbArgs)))
+
+ def OnColorScaleSpin(self, event):
+ try:
+ colorButton = event.GetEventObject().button
+ self.UpdateColor(colorButton)
+ except:
+ wx.LogError("Button not found")
+
+ def OnSelectColor(self, event):
+ try:
+ colorButton = self.colorButtonRefs[event.GetId()]
+ self.UpdateColor(colorButton)
+ except:
+ wx.LogError("Button not found")
+
Added: trunk/SwigInterface/MiscFrames.py
==============================================================================
--- (empty file)
+++ trunk/SwigInterface/MiscFrames.py Thu Jan 3 17:53:18 2008
@@ -0,0 +1,22 @@
+
+import wx;
+import wx.py;
+
+class MantaShellFrame(wx.Frame):
+ def __init__(self, parent, engine):
+ wx.Frame.__init__(self, parent=parent, title="Manta Shell",
size=(512,512))
+
+ self.frame = parent;
+ self.engine = engine;
+
+ # Add a pycrust window.
+ vsizer = wx.BoxSizer( wx.VERTICAL );
+ self.crust = wx.py.crust.Crust( self, -1 );
+ vsizer.Add(self.crust,1,wx.EXPAND);
+ self.SetSizer( vsizer );
+
+ # Setup locals in the shell.
+ self.crust.shell.interp.locals['frame'] = self.frame
+ self.crust.shell.interp.locals['engine'] = self.engine
+
+
Modified: trunk/SwigInterface/runwxmanta.py
==============================================================================
--- trunk/SwigInterface/runwxmanta.py (original)
+++ trunk/SwigInterface/runwxmanta.py Thu Jan 3 17:53:18 2008
@@ -1,23 +1,26 @@
import wxManta
import getopt, sys
+import re
def usage():
print "Usage: python test.py [options]"
print "Where options contains one or more of:"
print "-n --np=<threads>"
print "-s --scene=\"<scene name>( <scene args > )\""
+ print "-r --res=<width>x<height>"
def main():
# Default options.
num_workers = 1
+ size = (512, 512)
sceneCreator = wxManta.createDefaultScenePython
# Parse command line options. Note these have to conform to getopt
# So -np would be parsed as -n <space> p. Use --np=<threads> instead.
try:
- opts, args = getopt.getopt(sys.argv[1:], "n:s:", ["np=","scene="] )
+ opts, args = getopt.getopt(sys.argv[1:], "n:s:r:",
["np=","scene=","res="] )
except getopt.GetoptError:
usage()
@@ -33,6 +36,14 @@
if o in ("-s", "--scene"):
sceneArg = str(a)
sceneCreator = lambda frame,engine:
wxManta.createPluginScene(frame, engine, sceneArg)
+ if o in ("-r", "--res"):
+ m = re.match("^(\d+)x(\d+)$", a );
+ if (m):
+ size = (int(m.group(1)), int(m.group(2)))
+ else:
+ print "Bad resolution string"
+ usage()
+ sys.exit(2)
# Add additional command line args here.
@@ -42,7 +53,7 @@
# Create the application.
print "num_workers = "
print num_workers
- app = wxManta.MantaApp( sceneCreator, num_workers )
+ app = wxManta.MantaApp( sceneCreator, num_workers, renderSize=size )
###########################################################################
Modified: trunk/SwigInterface/wxManta.py
==============================================================================
--- trunk/SwigInterface/wxManta.py (original)
+++ trunk/SwigInterface/wxManta.py Thu Jan 3 17:53:18 2008
@@ -13,18 +13,23 @@
import re
from wx import glcanvas
+import FloatSpin as FS
+import wx.py
import threading
import math
-import wx.lib.colourselect as csel
import os
from manta import *
from pycallback import *
+
from MantaCameraPath import *
+from CameraFrame import *
+from LightFrame import *
+from MiscFrames import *
-import FloatSpin as FS
+from wx.lib.evtmgr import eventManager as EventManager;
# import traceback # Use traceback.print_stack() for a stack trace.
@@ -32,16 +37,6 @@
xres = 512
yres = 512
-# Clamps values between 0 and 255
-def clampZeroTo255(val):
- if (val > 0):
- if (val < 255):
- return val
- else:
- return 255
- else:
- return 0
-
###############################################################################
###############################################################################
# ParseCommandLine.
@@ -87,6 +82,10 @@
# Default Scene.
# Unlike make_scene, this function doesn't return anything. It must call
# engine.setScene( ... ) explicitly.
+#
+# engine is of type MantaInterface.
+# frame is of type MantaFrame (see below)
+#
###############################################################################
###############################################################################
@@ -221,400 +220,6 @@
self.updateFramerate(framerate)
self.prev_time = current_time
-###############################################################################
-###############################################################################
-# CAMERA FRAME CAMERA FRAME CAMERA FRAME CAMERA
FRAME
-###############################################################################
-###############################################################################
-#send complaints to: brownlee@cs.utah.edu
-
-class CameraFrame(wx.Frame):
- def __init__(self, parent, engine):
- wx.Frame.__init__(self, parent=parent, title="Camera")
-
- data = engine.getCamera(0).getBasicCameraData()
- eye = data.eye
- lookat = data.lookat
- up = data.up
- hfov = data.hfov
- vfov = data.vfov
-
- panel = wx.Panel(self, -1)
- self.engine = engine
- self.parent = parent
- sizer = wx.BoxSizer(wx.VERTICAL)
-
- hSizer0 = wx.BoxSizer(wx.HORIZONTAL)
- self.channelST = wx.StaticText(panel, -1, "Channel: ")
- self.channelSP = wx.SpinCtrl(panel, -1, "", (30,50))
- self.channelSP.SetRange(0,100)
- self.channelSP.SetValue(0)
- hSizer0.Add(self.channelST)
- hSizer0.Add(self.channelSP)
-
- hSizer1 = wx.BoxSizer(wx.HORIZONTAL)
- self.eyeST = wx.StaticText(panel, -1, "eye x,y,z: " )
- self.eyeXSP = self.addSpinner(panel, eye.x())
- self.eyeYSP = self.addSpinner(panel, eye.y())
- self.eyeZSP = self.addSpinner(panel, eye.z())
- hSizer1.Add(self.eyeST)
- hSizer1.Add(self.eyeXSP)
- hSizer1.Add(self.eyeYSP)
- hSizer1.Add(self.eyeZSP)
-
- hSizer2 = wx.BoxSizer(wx.HORIZONTAL)
- self.lookatST = wx.StaticText(panel, -1, "lookat x,y,z: ")
- self.lookXSP = self.addSpinner(panel, lookat.x())
- self.lookYSP = self.addSpinner(panel, lookat.y())
- self.lookZSP = self.addSpinner(panel,lookat.z())
- #self.lookZTCL = wx.TextCtrl(panel, -1, str(lookat.z()),
size=(125,-1))
- hSizer2.Add(self.lookatST)
- hSizer2.Add(self.lookXSP)
- hSizer2.Add(self.lookYSP)
- hSizer2.Add(self.lookZSP)
-
- hSizer3 = wx.BoxSizer(wx.HORIZONTAL)
- self.upST = wx.StaticText(panel, -1, "up vector x,y,z: ")
- self.upXSP = self.addSpinner(panel, up.x())
- self.upYSP = self.addSpinner(panel, up.y())
- self.upZSP = self.addSpinner(panel, up.z())
- hSizer3.Add(self.upST)
- hSizer3.Add(self.upXSP)
- hSizer3.Add(self.upYSP)
- hSizer3.Add(self.upZSP)
-
- hSizer4 = wx.BoxSizer(wx.HORIZONTAL)
- self.fovST = wx.StaticText(panel, -1, "fov horizontal, vertical: ")
- self.fovXSP = self.addSpinner(panel, hfov)
- self.fovYSP = self.addSpinner(panel, vfov)
- hSizer4.Add(self.fovST)
- hSizer4.Add(self.fovXSP)
- hSizer4.Add(self.fovYSP)
-
- hSizer6 = wx.BoxSizer(wx.HORIZONTAL)
- self.stringTCL = wx.TextCtrl(panel, -1, "camera string",
size=(400,-1))
- self.ComputeString()
- self.stringB = wx.Button(panel, -1, "Set")
- hSizer6.Add(self.stringTCL)
- hSizer6.Add(self.stringB)
-
- hSizer5 = wx.BoxSizer(wx.HORIZONTAL)
- self.okButton = wx.Button(panel, wx.ID_OK)
- self.cancelButton = wx.Button(panel, wx.ID_CANCEL)
- self.applyButton = wx.Button(panel, wx.ID_APPLY)
- hSizer5.Add(self.okButton, wx.ALIGN_CENTER)
- hSizer5.Add(self.cancelButton, wx.ALIGN_CENTER)
- hSizer5.Add(self.applyButton, wx.ALIGN_CENTER)
-
- sizer.Add(hSizer0, wx.ALIGN_CENTER, 2)
- sizer.Add(hSizer1, wx.ALIGN_CENTER, 2)
- sizer.Add(hSizer2, wx.ALIGN_CENTER,2)
- sizer.Add(hSizer3, wx.ALIGN_CENTER,2)
- sizer.Add(hSizer4, wx.ALIGN_CENTER,2)
- sizer.Add(hSizer6, wx.ALIGN_CENTER, 2)
- sizer.Add(hSizer5, wx.ALIGN_CENTER,2)
- panel.SetSizer(sizer)
- selfSizer = wx.BoxSizer()
- selfSizer.Add(panel, -1, wx.EXPAND|wx.ALIGN_CENTER)
- self.SetSizer(selfSizer)
- self.SetAutoLayout(True)
-
- self.Bind(wx.EVT_BUTTON, self.OnClickOK, self.okButton)
- self.Bind(wx.EVT_BUTTON, self.OnClickCancel, self.cancelButton)
- self.Bind(wx.EVT_BUTTON, self.OnClickApply, self.applyButton)
- self.Bind(wx.EVT_BUTTON, self.OnClickSet, self.stringB)
- self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
-
- def OnClickSet(self, evt):
- p = re.compile('-?\d+\.?\d*')
- s = p.findall(self.stringTCL.GetValue())
- print s
- try:
- self.eyeXSP.SetValue(float(s[0]))
- self.eyeYSP.SetValue(float(s[1]))
- self.eyeZSP.SetValue(float(s[2]))
- self.lookXSP.SetValue(float(s[3]))
- self.lookYSP.SetValue(float(s[4]))
- self.lookZSP.SetValue(float(s[5]))
- self.upXSP.SetValue(float(s[6]))
- self.upYSP.SetValue(float(s[7]))
- self.upZSP.SetValue(float(s[8]))
- self.fovXSP.SetValue(float(s[9]))
- self.fovYSP.SetValue(float(s[10]))
- except ValueError:
- print "incorrect string value"
-
- def ComputeString(self):
- ex = float(self.eyeXSP.GetValue())
- ey = float(self.eyeYSP.GetValue())
- ez = float(self.eyeZSP.GetValue())
-
- lx = float(self.lookXSP.GetValue()) #float(self.lookXTCL.GetValue())
- ly = float(self.lookYSP.GetValue())
- lz = float(self.lookZSP.GetValue())
-
- ux = float(self.upXSP.GetValue())
- uy = float(self.upYSP.GetValue())
- uz = float(self.upZSP.GetValue())
- hfov = float(self.fovXSP.GetValue())
- vfov = float(self.fovYSP.GetValue())
-
- s = 'eye: (%f %f %f) lookat: (%f, %f, %f) up: (%f, %f, %f) hfov: %f
vfov: %f' % (ex,ey,ez,lx,ly,lz,ux,uy,uz,hfov,vfov)
- self.stringTCL.SetValue(s)
-
-
- def addSpinner(self, where, value, id=wx.ID_ANY):
- floatspin = FS.FloatSpin(where, id,
- increment=0.01, value=value,
- extrastyle=FS.FS_LEFT)
- floatspin.SetFormat("%g")
- floatspin.SetDigits(5)
- floatspin.Bind(FS.EVT_FLOATSPIN, self.OnFloatSpin)
- return floatspin
-
- def OnFloatSpin(self, event):
- # Pull out the new value
- #spinner = event.GetEventObject()
- #x = float(spinner.GetValue())
- self.ApplySettings()
- self.ComputeString()
-
- def OnClickOK(self, evt):
- self.ApplySettings()
- self.Close(True)
-
- def OnClickApply(self, evt):
- self.ApplySettings()
-
- def ApplySettings(self):
- channel = int(self.channelSP.GetValue())
- ex = float(self.eyeXSP.GetValue())
- ey = float(self.eyeYSP.GetValue())
- ez = float(self.eyeZSP.GetValue())
-
- lx = float(self.lookXSP.GetValue()) #float(self.lookXTCL.GetValue())
- ly = float(self.lookYSP.GetValue())
- lz = float(self.lookZSP.GetValue())
-
- ux = float(self.upXSP.GetValue())
- uy = float(self.upYSP.GetValue())
- uz = float(self.upZSP.GetValue())
-
- eye = manta_new(Vector(ex,ey,ez))
- lookat = manta_new(Vector(lx,ly,lz))
- up = manta_new(Vector(ux, uy,uz))
- fovx = float(self.fovXSP.GetValue())
- fovy = float(self.fovYSP.GetValue())
-
- data = manta_new(BasicCameraData(eye, lookat, up, fovx, fovy))
- self.engine.getCamera(channel).setBasicCameraData(data)
-
- def OnClickCancel(self, evt):
- self.Close(True)
-
- def OnCloseWindow(self, evt):
- self.Destroy()
-
-
-
-###############################################################################
-###############################################################################
-# LIGHT FRAME LIGHT FRAME LIGHT FRAME LIGHT FRAME
-###############################################################################
-###############################################################################
-class LightFrame(wx.Frame):
- def __init__(self, parent, engine):
- wx.Frame.__init__(self, parent=parent, title="Lights")
-
- self.engine = engine
- self.colorButtonRefs = {}
-
- panel= wx.Panel(self, -1)
-
- gbs = wx.GridBagSizer(5,5)
-
- lights = engine.getScene().getLights()
- for i in range(lights.numLights()):
- gbs.Add( self.addLight(panel, lights.getLight(i)), (i, 0))
-
- button = wx.Button(panel, -1, "Close")
- gbs.Add( button, (lights.numLights(),0) )
- self.Bind(wx.EVT_BUTTON, self.OnCloseMe, button)
- self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
-
- panel.SetSizerAndFit(gbs)
- self.SetClientSize(panel.GetSize())
-
- def OnCloseMe(self, event):
- self.Close(True)
-
- def OnCloseWindow(self, event):
- self.Destroy()
-
- def addLight(self, where, light):
- point_light = PointLight.fromLight(light)
- if (point_light != None):
- return self.addPointLight(where, point_light)
- head_light = HeadLight.fromLight(light)
- if (head_light != None):
- return self.addHeadLight(where, head_light)
-
- def addHeadLight(self, where, light):
- offset = light.getOffset()
-
- panel = wx.Panel(where, -1)
-
- gbs = wx.GridBagSizer(5,1)
- gbs.Add( wx.StaticText(panel, -1, "Offset"), (0,0))
- spinnerOffset = self.addSpinner(panel, offset)
- spinnerOffset.light = light
- # Override the callback function
- spinnerOffset.Bind(FS.EVT_FLOATSPIN, self.OnOffsetSpin)
- gbs.Add( spinnerOffset, (0,1))
-
- colorWidgets = self.AddColorButton(light, panel)
- gbs.Add( colorWidgets["colorButton"], (0,2))
- gbs.Add( wx.StaticText(where, -1, "Color Scale"), (0,3))
- gbs.Add( colorWidgets["colorScaleSpinner"], (0,4) )
-
- panel.SetSizerAndFit(gbs)
- return panel
-
- def addPointLight(self, where, light):
- location = light.getPosition()
-
- panel = wx.Panel(where, -1)
-
- gbs = wx.GridBagSizer(7,1)
- gbs.Add( wx.StaticText(panel, -1, "Location"), (0,0))
- spinnerX = self.addSpinner(panel, location.x())
- spinnerY = self.addSpinner(panel, location.y())
- spinnerZ = self.addSpinner(panel, location.z())
- spinnerX.light = light
- spinnerX.X = spinnerX
- spinnerX.Y = spinnerY
- spinnerX.Z = spinnerZ
- spinnerY.light = light
- spinnerY.X = spinnerX
- spinnerY.Y = spinnerY
- spinnerY.Z = spinnerZ
- spinnerZ.light = light
- spinnerZ.X = spinnerX
- spinnerZ.Y = spinnerY
- spinnerZ.Z = spinnerZ
- gbs.Add( spinnerX, (0,1))
- gbs.Add( spinnerY, (0,2))
- gbs.Add( spinnerZ, (0,3))
-
- colorWidgets = self.AddColorButton(light, panel)
- gbs.Add( colorWidgets["colorButton"], (0,4))
- gbs.Add( wx.StaticText(where, -1, "Color Scale"), (0,5))
- gbs.Add( colorWidgets["colorScaleSpinner"], (0,6) )
-
-
- panel.SetSizerAndFit(gbs)
- return panel
-
- def addSpinner(self, where, value, id=wx.ID_ANY):
- floatspin = FS.FloatSpin(where, id,
- increment=0.01, value=value,
- extrastyle=FS.FS_LEFT)
- floatspin.SetFormat("%g")
- floatspin.SetDigits(5)
- floatspin.Bind(FS.EVT_FLOATSPIN, self.OnFloatSpin)
- return floatspin
-
- def OnFloatSpin(self, event):
- # Pull out the new value
- spinner = event.GetEventObject()
- x = float(spinner.X.GetValue())
- y = float(spinner.Y.GetValue())
- z = float(spinner.Z.GetValue())
- newPosition = Vector(x,y,z)
- cbArgs = ( newPosition, )
- self.engine.addTransaction("Light Position",
-
manta_new(createMantaTransaction(spinner.light.setPosition, cbArgs)))
-
- def OnOffsetSpin(self, event):
- # Pull out the new value
- spinner = event.GetEventObject()
- offset = float(spinner.GetValue())
- cbArgs = ( offset, )
- self.engine.addTransaction("Light Offset",
-
manta_new(createMantaTransaction(spinner.light.setOffset, cbArgs)))
-
- def AddColorButton(self, light, where):
- color = light.getColor().convertRGB()
-
- # Because our colors can be more than one we need to do a
- # little bit of work. The color selector can't deal with
- # floating point colors, and it must work with ranges [0,255].
- # In order to overcome this limitation, we are going to use a
- # scale. If all your color components are less than 1, then
- # the scale will be 1, otherwise it will be scaled by the
- # maximum component.
- colorTupRaw = [ color.r(), color.g(), color.b() ]
- maxComponent = max(colorTupRaw)
- print "maxComponent = %g" % (maxComponent)
- if (maxComponent <= 1):
- colorScale = 1
- else:
- colorScale = maxComponent
- colorTup = map(lambda c:clampZeroTo255(int(c*255/colorScale)),
- colorTupRaw)
-
- colorButton = csel.ColourSelect(where, wx.ID_ANY, "Color",
- tuple(colorTup))
- colorButton.Bind(csel.EVT_COLOURSELECT, self.OnSelectColor)
- # You have to use these refs, because the event you get in
- # your callback doesn't contain the actual colorButton object.
- # All you can be sure of is the ID.
- self.colorButtonRefs[colorButton.GetId()] = colorButton
- colorButton.light = light
-
-
- # Add the scale
- print "colorScale = %g, maxComponent = %g" %
(colorScale,maxComponent)
- # I tried to make the ID the same as the colorButton and bind
- # it to the same callback, but wxMac didn't like it. Thus,
- # the spinner now gets its own callback.
- colorScaleSpinner = FS.FloatSpin(where, wx.ID_ANY,
- min_val=1, increment=0.01,
- value=colorScale,
- extrastyle=FS.FS_LEFT)
- colorScaleSpinner.SetFormat("%g")
- colorScaleSpinner.SetDigits(5)
- colorScaleSpinner.Bind(FS.EVT_FLOATSPIN, self.OnColorScaleSpin)
- colorScaleSpinner.button = colorButton
- colorButton.spinner = colorScaleSpinner
-
- # Shoving multiple results in a dictionary will make things a little
easier to read.
- results = {"colorButton":colorButton,
"colorScaleSpinner":colorScaleSpinner}
- return results
-
- def UpdateColor(self, colorButton):
- color = colorButton.GetColour()
- colorScale = float(colorButton.spinner.GetValue()) / 255.0
- rgbColor = RGBColor(color.Red() * colorScale,
- color.Green() * colorScale,
- color.Blue() * colorScale)
- cbArgs = ( Color(rgbColor), )
- self.engine.addTransaction("Light Color",
-
manta_new(createMantaTransaction(colorButton.light.setColor, cbArgs)))
-
- def OnColorScaleSpin(self, event):
- try:
- colorButton = event.GetEventObject().button
- self.UpdateColor(colorButton)
- except:
- wx.LogError("Button not found")
-
- def OnSelectColor(self, event):
- try:
- colorButton = self.colorButtonRefs[event.GetId()]
- self.UpdateColor(colorButton)
- except:
- wx.LogError("Button not found")
###############################################################################
###############################################################################
@@ -647,6 +252,14 @@
manta_menu = wx.Menu()
self.Bind(wx.EVT_MENU, self.OnAbout,
manta_menu.Append(wx.NewId(), "About Manta"))
+
+ # Python Shell
+ dialog_id = wx.NewId()
+ self.dialog_map[dialog_id] = MantaShellFrame
+ self.Bind(wx.EVT_MENU, self.OnShowDialog,
+ manta_menu.Append(dialog_id, "Python Shell"))
+
+
self.Bind(wx.EVT_MENU, self.OnCloseWindow,
manta_menu.Append(wx.NewId(), "&Quit Manta"))
self.menuBar.Append(manta_menu, "&Manta")
@@ -661,10 +274,10 @@
view_menu.Append(wx.NewId(), "&Auto View"))
# Edit camera dialog.
- camera_dialog_id = wx.NewId()
- self.dialog_map[camera_dialog_id] = CameraFrame
+ dialog_id = wx.NewId()
+ self.dialog_map[dialog_id] = CameraFrame
self.Bind(wx.EVT_MENU, self.OnShowDialog,
- view_menu.Append(camera_dialog_id, "Edit Camera"))
+ view_menu.Append(dialog_id, "Edit Camera"))
# Camera Path dialog.
dialog_id = wx.NewId()
@@ -777,16 +390,17 @@
#######################################################################
# Setup the UI events.
- self.canvas.Bind( wx.EVT_MOTION, self.OnMotion )
- self.canvas.Bind( wx.EVT_LEFT_DOWN, self.OnLeftDown )
- self.canvas.Bind( wx.EVT_LEFT_DCLICK, self.OnLeftDClick )
- self.canvas.Bind( wx.EVT_LEFT_UP, self.OnLeftUp )
- self.canvas.Bind( wx.EVT_RIGHT_DOWN, self.OnRightDown )
- self.canvas.Bind( wx.EVT_RIGHT_UP, self.OnRightUp )
- self.canvas.Bind( wx.EVT_MOUSEWHEEL, self.OnMouseWheel )
+ EventManager.Register( self.OnMotion, wx.EVT_MOTION, self.canvas
)
+ EventManager.Register( self.OnLeftDown, wx.EVT_LEFT_DOWN,
self.canvas )
+ EventManager.Register( self.OnLeftDClick, wx.EVT_LEFT_DCLICK,
self.canvas )
+ EventManager.Register( self.OnLeftUp, wx.EVT_LEFT_UP,
self.canvas )
+ EventManager.Register( self.OnRightDown, wx.EVT_RIGHT_DOWN,
self.canvas )
+ EventManager.Register( self.OnRightUp, wx.EVT_RIGHT_UP,
self.canvas )
+ EventManager.Register( self.OnMouseWheel, wx.EVT_MOUSEWHEEL,
self.canvas )
+
# Keyboard events are ignored for wx.Frame.
- self.canvas.Bind( wx.EVT_KEY_DOWN, self.OnChar )
+ EventManager.Register( self.OnChar, wx.EVT_KEY_DOWN, self.canvas )
# Make canvas the initial focus
wx.CallAfter(self.canvas.SetFocus)
@@ -952,6 +566,8 @@
if (dialog == None):
wx.LogError("Unknown dialog ID")
return
+
+ # Invoke the constructor.
dialog(self, self.engine).Show()
###########################################################################
@@ -968,6 +584,7 @@
wx.MessageBox( message, "About Manta",
wx.TE_MULTILINE | wx.OK | wx.ICON_INFORMATION, self)
+
###########################################################################
## OnAutoView
- [Manta] r1964 - trunk/SwigInterface, abe, 01/03/2008
Archive powered by MHonArc 2.6.16.