Text archives Help
- From: abe@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [Manta] r1666 - trunk/SwigInterface
- Date: Sun, 19 Aug 2007 14:46:34 -0600 (MDT)
Author: abe
Date: Sun Aug 19 14:46:33 2007
New Revision: 1666
Added:
trunk/SwigInterface/MantaCameraPath.py
trunk/SwigInterface/MantaCapture.py
Modified:
trunk/SwigInterface/wxManta.py
Log:
Added camera path dialog for creating and executing camera paths, and
frame capture dialog for capturing frames during an interactive
session. I can't guarantee that these are completely bug free but they
were functional enough for me to capture RT07 image sequences
Moved menu options from Manta menu to Camera and Lights menus.
M SwigInterface/wxManta.py
A SwigInterface/MantaCapture.py
A SwigInterface/MantaCameraPath.py
Added: trunk/SwigInterface/MantaCameraPath.py
==============================================================================
--- (empty file)
+++ trunk/SwigInterface/MantaCameraPath.py Sun Aug 19 14:46:33 2007
@@ -0,0 +1,554 @@
+
+
+import wx
+import sys
+import time
+
+from wxPython.glcanvas import wxGLCanvas
+from wx.glcanvas import WX_GL_DOUBLEBUFFER as GL_DOUBLEBUFFER
+
+import threading
+import math
+import wx.lib.colourselect as csel
+import os
+
+from manta import *
+from pycallback import *
+
+from MantaCapture import *
+# from MantaPlot import *
+
+import FloatSpin as FS
+
+
+
+###############################################################################
+# Manta Image Sequence Capture Frame.
+# This class ports functionality of FMantaCapture dialog to wxManta.
+
+class MantaCameraPathPanel(wx.Panel):
+ def __init__(self, parent, engine, channel=0 ):
+
+ wx.Panel.__init__(self, parent )
+
+ self.engine = engine
+ self.channel = channel
+ self.parent = parent
+
+ # Load/Create Path.
+ self.load_path_button = wx.Button( self, -1, "Load Path" )
+ self.new_path_button = wx.Button( self, -1, "New Path" )
+ self.save_path_button = wx.Button( self, -1, "Save Path" )
+ self.record_interval = wx.SpinCtrl( self, -1 )
+ self.record_interval.SetRange( 1, 60000 )
+ self.record_interval.SetValue( 500 )
+
+ self.record_timer = wx.Timer( self )
+ self.new_path_counter = 0
+
+ # List of available paths.
+ self.path_list = wx.ListCtrl( self, -1,
size=(400,-1),style=wx.LC_REPORT|wx.LC_EDIT_LABELS )
+ self.path_list.InsertColumn( 0, "Path Name" )
+ self.path_list.InsertColumn( 1, "Key Frames" )
+ self.path_list.InsertColumn( 2, "Delta time" )
+ self.path_list.InsertColumn( 3, "Delta t" )
+
+ self.path_list.SetColumnWidth(0, 100)
+ self.path_list.SetColumnWidth(1, 100)
+ self.path_list.SetColumnWidth(2, 100)
+ self.path_list.SetColumnWidth(3, 100)
+
+ self.path_loop_check = wx.CheckBox( self, -1, "Play in a loop." )
+
+ self.automator = []; # Empty list.
+
+ # Capture frames from a path.
+ self.capture_frames_check = wx.CheckBox( self, -1, "Capture frames
from path" )
+ self.capture_panel = MantaCapturePanel( self, engine, channel );
+ self.capture_panel.Disable()
+ self.capture_separate_check = wx.CheckBox( self, -1, "Record in
multiple passes." )
+ self.capture_pass = 0
+
+ # Run a benchmark using a path.
+ self.benchmark_check = wx.CheckBox( self, -1, "Benchmark path" )
+ self.benchmark_list = wx.ListCtrl( self, -1,
size=(400,-1),style=wx.LC_REPORT|wx.LC_EDIT_LABELS )
+ self.benchmark_list.InsertColumn( 0, "Path Name" )
+ self.benchmark_list.InsertColumn( 1, "Total Samples" )
+ self.benchmark_list.InsertColumn( 2, "Average FPS" )
+
+ self.benchmark_list.SetColumnWidth(0, 100)
+ self.benchmark_list.SetColumnWidth(1, 100)
+ self.benchmark_list.SetColumnWidth(2, 100)
+
+ self.benchmarks = []; # Empty list.
+
+ # Just run a freaking path!
+ self.start_button = wx.Button( self, -1, "Start" )
+ self.pause_button = wx.Button( self, -1, "Pause" )
+ self.stop_button = wx.Button( self, -1, "Stop" )
+
+ # Arrange gui components.
+ vsizer = wx.BoxSizer(wx.VERTICAL);
+
+ # Load, New Buttons.
+ hsizer = wx.BoxSizer(wx.HORIZONTAL);
+ hsizer.Add( self.load_path_button, wx.ALIGN_CENTER )
+ hsizer.Add( self.new_path_button, wx.ALIGN_CENTER )
+ vsizer.Add( hsizer, wx.ALIGN_CENTER )
+
+ hsizer = wx.BoxSizer(wx.HORIZONTAL);
+ hsizer.Add( wx.StaticText( self, -1, "Record Interval " ),
wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER)
+ hsizer.Add( self.record_interval, 0, wx.ALIGN_CENTER )
+ hsizer.Add( wx.StaticText( self, -1, "ms" ),
wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER)
+ hsizer.Add( self.save_path_button, wx.ALIGN_CENTER )
+ vsizer.Add( hsizer, wx.ALIGN_CENTER )
+
+ # Path List.
+ vsizer.Add( self.path_list, 0, wx.EXPAND )
+ vsizer.Add( self.path_loop_check, 0, wx.ALIGN_LEFT )
+
+ self.path_list.Bind( wx.EVT_RIGHT_UP, self.OnPathRightClick )
+
+ # Capture.
+ hsizer = wx.BoxSizer(wx.HORIZONTAL);
+ hsizer.Add( self.capture_frames_check, wx.ALIGN_CENTER )
+ hsizer.Add( self.capture_separate_check, wx.ALIGN_CENTER )
+ vsizer.Add( hsizer, wx.ALIGN_CENTER )
+ vsizer.Add( self.capture_panel, wx.EXPAND )
+
+ # Benchmark.
+ hsizer = wx.BoxSizer(wx.HORIZONTAL);
+ hsizer.Add( self.benchmark_check, wx.ALIGN_CENTER )
+ vsizer.Add( hsizer, wx.ALIGN_CENTER )
+ vsizer.Add( self.benchmark_list, 0, wx.EXPAND )
+
+ # self.benchmark_list.Bind( wx.EVT_RIGHT_UP, self.OnListRightClick )
+
+ # Controls.
+ hsizer = wx.BoxSizer(wx.HORIZONTAL);
+ hsizer.Add( self.start_button, wx.ALIGN_CENTER )
+ hsizer.Add( self.pause_button, wx.ALIGN_CENTER )
+ hsizer.Add( self.stop_button, wx.ALIGN_CENTER )
+ vsizer.Add( hsizer, wx.ALIGN_CENTER )
+
+ self.SetSizerAndFit(vsizer)
+
+ # Bind events.
+ self.Bind(wx.EVT_BUTTON, self.OnLoadPathButton,
self.load_path_button)
+ self.Bind(wx.EVT_BUTTON, self.OnNewPathButton,
self.new_path_button)
+ self.Bind(wx.EVT_BUTTON, self.OnSavePathButton,
self.save_path_button)
+ self.Bind(wx.EVT_BUTTON, self.OnStartButton,
self.start_button)
+ self.Bind(wx.EVT_BUTTON, self.OnStopButton,
self.stop_button)
+
+ self.Bind(wx.EVT_CHECKBOX, self.OnCaptureFramesCheck,
self.capture_frames_check)
+ self.Bind(wx.EVT_TIMER, self.OnRecordTimer )
+
+
###########################################################################
+ # Gui interactions.
+ def OnLoadPathButton( self, event ):
+
+ # Get the filename.
+ dialog = wx.FileDialog( self,
+ message="Choose path file",
+ defaultDir=os.getcwd(),
+ defaultFile="",
+ wildcard="Text files (*.txt)|*.txt|All Files
(*.*)|*.*",
+ style=wx.OPEN|wx.CHANGE_DIR )
+
+ # Determine the file to open.
+ if (dialog.ShowModal() == wx.ID_OK):
+
+ # Attempt to add a path per file selected.
+ files = dialog.GetPaths()
+ index = -1
+
+ for name in files:
+ # Parse the file.
+ try:
+ automator = manta_new(CameraPathAutomator( self.engine,
0, 0, str(name) ))
+ self.AddAutomator( automator, name )
+ except:
+ print "Failed to load: " + name
+
+ # Check to see if any were successful.
+ if (index >= 0):
+ # Enable Buttons.
+ self.start_button.Enable()
+ self.path_list.SetItemState( index, wx.LIST_STATE_SELECTED,
wx.LIST_STATE_SELECTED )
+
+
+ def AddAutomator( self, automator, name ):
+
+ # Specifiy that the automator should wait for additional commands
after running.
+ automator.set_automator_mode( AutomatorUI.AUTOMATOR_KEEPALIVE )
+
+ cbArgs = ( automator, )
+ automator.set_terminate_callback(
manta_new(createMantaTransaction(self.MantaCameraPathComplete, cbArgs )))
+
+ # Add the automator the list.
+ index = self.path_list.InsertStringItem( sys.maxint, name )
+ self.path_list.SetStringItem( index, 1,
str(automator.get_total_points()) );
+ self.path_list.SetStringItem( index, 2,
str(automator.get_delta_time()) );
+ self.path_list.SetStringItem( index, 3, str(automator.get_delta_t())
);
+
+ # Store the automator
+ self.automator.append(automator)
+
+ def OnNewPathButton( self, event ):
+
+ if (self.record_timer.IsRunning()):
+
+ # Stop recording.
+ self.record_timer.Stop()
+
+ # Toggle buttons.
+ self.new_path_button.SetLabel( "New Path" )
+
+ # Create a new automator.
+ automator = CameraPathAutomator( self.engine, 0, 0,
+ self.new_path_data,
+ self.record_delta_t,
+ self.record_delta_time )
+ self.AddAutomator( automator, "NewPath" +
str(self.new_path_counter) + ".txt" )
+ self.new_path_counter += 1
+
+ # Remove temporary storage.
+ self.new_path_data.Clear()
+
+ else:
+ # Determine the interval
+ interval = self.record_interval.GetValue()
+
+ # Create a camera data list.
+ self.new_path_data = CameraPathDataVector()
+
+ # Add a timer to record camera position information.
+ self.record_timer.Start( interval )
+ self.record_prev_frame = self.engine.getCurrentFrame()
+ self.record_prev_time = time.time()
+
+ # Toggle buttons.
+ self.new_path_button.SetLabel( "Done" )
+
+ def OnRecordTimer( self, event ):
+
+ # Record camera position.
+ camera_data = self.engine.getCamera( self.channel
).getBasicCameraData()
+
+ # Compute elapse time and frames.
+ current_frame = self.engine.getCurrentFrame()
+ current_time = time.time()
+
+ elapse_frames = current_frame - self.record_prev_frame;
+ elapse_time = current_time - self.record_prev_time;
+
+ if (elapse_frames > 0):
+
+ # Compute delta t and time.
+ self.record_delta_t = 1.0 / elapse_frames;
+ self.record_delta_time = elapse_time / elapse_frames;
+
+ # Add the position to the current path.
+ self.new_path_data.PushBack( camera_data )
+
+ self.record_prev_frame = current_frame;
+ self.record_prev_time = current_time;
+
+ def OnSavePathButton( self, event ):
+
+ # Determine the currently selected automator.
+ index = self.path_list.GetNextItem( -1, wx.LIST_NEXT_ALL,
wx.LIST_STATE_SELECTED )
+ if (index >= 0):
+
+ automator = self.automator[index]
+ filename = self.path_list.GetItemText( index )
+
+ dialog = wx.FileDialog( self,
+ message = "Save path as...",
+ defaultDir = os.getcwd(),
+ defaultFile = filename,
+ wildcard="Text files (*.txt)|*.txt|All
Files (*.*)|*.*",
+ style=wx.SAVE|wx.CHANGE_DIR )
+
+ if (dialog.ShowModal() == wx.ID_OK):
+
+ # Get the pathname.
+ filename = dialog.GetPath()
+
+ # Write to a file.
+ automator.write_path( str(filename) )
+
+ def OnStartButton( self, event ):
+
+ # Determine the currently selected automator.
+ index = self.path_list.GetNextItem( -1, wx.LIST_NEXT_ALL,
wx.LIST_STATE_SELECTED )
+ if (index >= 0):
+
+ automator = self.automator[index]
+
+ # Set the loop behavior.
+ if (self.path_loop_check.GetValue()):
+ automator.set_loop_behavior( CameraPathAutomator.PATH_LOOP )
+ else:
+ automator.set_loop_behavior( CameraPathAutomator.PATH_STOP )
+
+ # Initialize Benchmark
+ if (self.benchmark_check.IsChecked()):
+
+ # Synchronzie the automator thread with Manta every frame.
+ automator.set_sync_frames( 1 )
+ automator.set_sync_quiet( True )
+
+ else:
+ automator.set_sync_frames( 0 )
+
+ # Start camera path if necessary.
+ if (self.capture_frames_check.IsChecked()):
+
+ # Check if multiple passes should be used.
+ if (self.capture_separate_check.IsChecked()):
+
+ # Controlled capture mode.
+ self.benchmark_check.SetValue( False )
+ self.capture_pass += 1
+
+ if (self.capture_pass == 1):
+
+ # Pass 1 collect performance data.
+ automator.set_sync_frames( 1 )
+ automator.set_sync_quiet( True )
+
+ self.parent.statusbar.SetStatusText( "Pass 1 collect
performance data." )
+
+ if(self.capture_pass == 2):
+
+ # Pass 2 capture frame images.
+ automator.set_sync_frames( 1 )
+ automator.set_sync_quiet( True )
+
+ self.parent.statusbar.SetStatusText( "Pass 2 capture
frame images." )
+ self.capture_panel.OnStartButton(())
+
+ else:
+ # Normal capture mode.
+ self.parent.statusbar.SetStatusText( "Capturing frame
images." )
+ self.capture_panel.OnStartButton(())
+
+ # Toggle buttons.
+ self.load_path_button.Disable()
+ self.new_path_button.Disable()
+ self.start_button.Disable()
+ self.stop_button.Enable()
+
+ # Start the asynchronous thread.
+ automator.restart()
+ else:
+ self.parent.statusbar.SetStatusText( "Select a Path" )
+
+
+ def OnStopButton( self, event ):
+
+ # Determine the currently selected automator.
+ index = self.path_list.GetNextItem( -1, wx.LIST_NEXT_ALL,
wx.LIST_STATE_SELECTED )
+ if (index >= 0):
+
+ # Access the automator.
+ automator = self.automator[index]
+
+ # Start camera path if necessary.
+ if (self.capture_frames_check.IsChecked()):
+ self.capture_panel.OnStopButton(())
+
+ # Cause the automator to abort and call its termination callback.
+ automator.set_loop_behavior ( CameraPathAutomator.PATH_ABORT )
+ automator.set_automator_mode( AutomatorUI.AUTOMATOR_EXIT )
+
+ def OnCaptureFramesCheck( self, event ):
+
+ if (self.capture_frames_check.IsChecked()):
+ self.capture_panel.Enable()
+ else:
+ self.capture_panel.Disable()
+
+ def OnPathRightClick( self, event ):
+
+ # Popup menu options.
+ self.POPUP_GLYPH = wx.NewId()
+ self.Bind(wx.EVT_MENU, self.OnPopupGlyphCheck,
id=self.POPUP_GLYPH )
+
+ menu = wx.Menu()
+ menu.Append( self.POPUP_GLYPH, "Toggle Glyphs" )
+
+ self.path_list.PopupMenu( menu )
+ menu.Destroy()
+
+ def OnPopupGlyphCheck( self, event ):
+
+ # Get the selected automator.
+ index = self.path_list.GetFirstSelected()
+ automator = self.automator[index]
+
+ # Create a Group containing glyphs for each control point.
+ group = manta_new(Group())
+ total = automator.get_total_points()
+ for i in range(0,total):
+
+ # Place a Cone glyph at the control point.
+ c = automator.GetControlPoint( i )
+
+ material =
manta_new(Flat(Color(RGBColor((float(i)/float(total)),0.1,0.1))))
+ glyph = manta_new(Sphere( material, c.eye, 15.0 ))
+ group.add(manta_new( glyph ))
+
+ # Build an acceleration structure for the group.
+ self.glyph_bvh = manta_new( DynBVH() )
+ self.glyph_bvh.rebuild( group )
+
+ # Add the group to manta in a transaction.
+ cbArgs = ( self.glyph_bvh, )
+ self.engine.addTransaction("Manta Add Glyph",
+
manta_new(createMantaTransaction(self.MantaAddGlyph, cbArgs)))
+
+
+ def MantaAddGlyph(self, glyph_bvh ):
+
+ scene = self.engine.getScene()
+
+ new_world = manta_new( Group() )
+ new_world.add( glyph_bvh )
+ new_world.add( scene.getObject() )
+
+ scene.setObject( new_world )
+
+ def OnListRightClick( self, event ):
+
+ # Popup menu options.
+ self.POPUP_RENAME = wx.NewId()
+ self.POPUP_HISTOGRAM = wx.NewId()
+ self.POPUP_PLOT = wx.NewId()
+
+ self.Bind(wx.EVT_MENU, self.OnPopupRename, id=self.POPUP_RENAME )
+ self.Bind(wx.EVT_MENU, self.OnPopupHistogram,
id=self.POPUP_HISTOGRAM )
+ self.Bind(wx.EVT_MENU, self.OnPopupPlot, id=self.POPUP_PLOT )
+
+ menu = wx.Menu()
+ # menu.Append( self.POPUP_RENAME, "Rename" )
+ menu.Append( self.POPUP_HISTOGRAM, "Histogram" )
+ menu.Append( self.POPUP_PLOT, "Plot" )
+
+ self.benchmark_list.PopupMenu( menu )
+ menu.Destroy()
+
+ def OnPopupRename( self, event ):
+
+ # Lookup selected item.
+ index = self.benchmark_list.GetFirstSelected()
+
+ print "Unimplemented."
+
+ def OnPopupPlot( self, event ):
+
+ # Look up the performance vector.
+ index = self.benchmark_list.GetFirstSelected()
+ plotable = self.benchmarks[index];
+
+ # Look up the path name.
+ plotname = self.path_list.GetItemText( index )
+
+ # Fps Histogram
+ plot_frame = PlotFrame( self, plotable, plotname );
+ plot_frame.Show()
+
+ def OnPopupHistogram( self, event ):
+
+ # Look up the performance vector.
+ index = self.benchmark_list.GetFirstSelected()
+ plotable = self.benchmarks[index];
+
+ # Look up the path name.
+ plotname = self.path_list.GetItemText( index )
+
+ # Fps Histogram
+ plot_frame = HistogramFrame( self, plotable, plotname );
+ plot_frame.Show()
+
+
+
###########################################################################
+ # Manta Transactions
+ def MantaCameraPathComplete( self, automator ):
+
+ # Stop capturing frames.
+ if (self.capture_frames_check.IsChecked()):
+
+ # Check if multiple passes should be used.
+ if (self.capture_separate_check.IsChecked()):
+
+ # Controlled capture mode.
+ if (self.capture_pass == 1):
+
+ # Pass 1 collect performance data.
+ self.parent.statusbar.SetStatusText( "First Pass
Complete" )
+ self.capture_performance = automator.get_performance()
+
+ wx.CallAfter( self.OnStartButton, () )
+
+ if (self.capture_pass == 2):
+
+ # Pass 2 captured frame images.
+ self.capture_pass = 0
+ self.capture_panel.OnStopButton(())
+
+ # Reprocess images.
+ self.parent.statusbar.SetStatusText( "Resampling
frames." )
+
+ wx.CallAfter( ResampleCapturedFrames,
self.capture_panel.GetPrefix(),
+
self.capture_performance )
+
+ # Cleanup.
+ self.capture_performance = ()
+ else:
+ # Normal capture mode.
+ self.capture_panel.OnStopButton(())
+
+ # Add results to benchmark table.
+ if (self.benchmark_check.IsChecked()):
+
+ # Copy the performance data.
+ performance = automator.get_performance()
+ self.benchmarks.append( performance )
+
+ # Lookup the path name.
+ index = self.automator.index( automator )
+ filename = self.path_list.GetItemText( index )
+
+ # Add a row to the benchmark table.
+ index = self.benchmark_list.InsertStringItem( sys.maxint,
filename )
+ self.benchmark_list.SetStringItem( index, 1,
str(performance.size()) );
+ self.benchmark_list.SetStringItem( index, 2,
str(automator.get_average_fps()) );
+
+ self.parent.statusbar.SetStatusText( "Right click to plot
performance." )
+
+ # Renable buttons.
+ self.load_path_button.Enable()
+ self.new_path_button.Enable()
+ self.start_button.Enable()
+ self.stop_button.Disable()
+
+class MantaCameraPathFrame(wx.Frame):
+ def __init__(self, parent, engine, channel=0 ):
+ wx.Frame.__init__(self, parent=parent, title="Camera Paths")
+
+ # Create a Capture Panel.
+ self.panel = MantaCameraPathPanel( self, engine, channel )
+ self.statusbar = self.CreateStatusBar()
+
+ self.SetClientSize(self.panel.GetSize())
+
+ self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
+
+
+
+ def OnCloseWindow(self, event):
+
+ self.Destroy()
+
Added: trunk/SwigInterface/MantaCapture.py
==============================================================================
--- (empty file)
+++ trunk/SwigInterface/MantaCapture.py Sun Aug 19 14:46:33 2007
@@ -0,0 +1,307 @@
+import wx
+import sys
+import time
+
+from wxPython.glcanvas import wxGLCanvas
+from wx.glcanvas import WX_GL_DOUBLEBUFFER as GL_DOUBLEBUFFER
+
+import threading
+import math
+import wx.lib.colourselect as csel
+import os
+import re
+import shutil
+import math
+
+from manta import *
+from pycallback import *
+
+import FloatSpin as FS
+
+###############################################################################
+# Manta Image Sequence Capture Frame.
+# This class ports functionality of FMantaCapture dialog to wxManta.
+
+class MantaCapturePanel(wx.Panel):
+ def __init__(self, parent, engine, channel=0 ):
+
+ wx.Panel.__init__(self, parent )
+
+ self.engine = engine
+ self.channel = channel
+
+ # GUI Components.
+ self.prefix_field = wx.TextCtrl(self, -1, "manta", size=(125,-1))
+
+ type_list = ['png','nrrd']
+ self.type_box = wx.ComboBox( self, -1, "", (-1,-1), (-1, -1),
type_list, wx.CB_DROPDOWN )
+ self.type_box.SetSelection(0)
+ self.skip_spinner = wx.SpinCtrl( self, -1, "", (30,50));
+ self.skip_spinner.SetValue(1)
+ self.timestamp_check = wx.CheckBox( self, -1, "Use timestamp for
filename." )
+
+ # Arrange gui components.
+ vsizer = wx.BoxSizer(wx.VERTICAL);
+ hsizer = wx.BoxSizer(wx.HORIZONTAL);
+ hsizer.Add( wx.StaticText(self,-1,"Image sequence prefix:"),
wx.ALIGN_CENTER )
+ hsizer.Add( self.prefix_field, wx.ALIGN_CENTER )
+ hsizer.Add( self.type_box, wx.ALIGN_CENTER )
+ vsizer.Add( hsizer, wx.ALIGN_CENTER );
+
+ hsizer = wx.BoxSizer(wx.HORIZONTAL);
+ hsizer.Add( wx.StaticText(self,-1,"Record every:"), wx.ALIGN_CENTER )
+ hsizer.Add( self.skip_spinner, wx.ALIGN_CENTER )
+ hsizer.Add( wx.StaticText(self,-1,"frames."), wx.ALIGN_CENTER )
+ vsizer.Add( hsizer, wx.ALIGN_CENTER );
+
+ vsizer.Add( self.timestamp_check, wx.ALIGN_CENTER )
+
+ self.SetSizerAndFit(vsizer)
+
+
###########################################################################
+ # Gui interactions.
+ def OnStartButton( self, event ):
+
+ # Look up arguments
+ prefix = self.prefix_field.GetValue()
+ file_type = self.type_box.GetString(self.type_box.GetSelection())
+ skip = self.skip_spinner.GetValue()
+ use_timestamp = self.timestamp_check.GetValue()
+
+ # Send a transaction to manta.
+ cbArgs = ( self.channel, prefix, file_type, skip, use_timestamp )
+ self.engine.addTransaction("Capture Start",
+
manta_new(createMantaTransaction(self.MantaStart, cbArgs)))
+
+ # Disable UI.
+ self.skip_spinner.Disable()
+
+ def OnStopButton( self, event ):
+
+ # Send a transaction to Manta.
+ cbArgs = ( self.channel, )
+ self.engine.addTransaction("Capture Stop",
+
manta_new(createMantaTransaction(self.MantaStop, cbArgs)))
+ # Enable UI.
+ self.skip_spinner.Enable()
+
+ def GetPrefix( self ):
+ return self.prefix_field.GetValue()
+
+ def GetType( self ):
+ self.type_box.GetString(self.type_box.GetSelection())
+
+ def OnCaptureButton( self, event ):
+
+ # Look up arguments
+ prefix = self.GetPrefix()
+ file_type = self.GetType()
+ skip = self.skip_spinner.GetValue()
+
+ # Send a transaction to manta.
+ cbArgs = ( self.channel, prefix, file_type, skip )
+ self.engine.addTransaction("Capture Start",
+
manta_new(createMantaTransaction(self.MantaStart, cbArgs)),
+ TransactionBase.CONTINUE )
+
+ cbArgs = ( self.channel, )
+ self.engine.addTransaction("Capture Stop",
+
manta_new(createMantaTransaction(self.MantaStop, cbArgs)),
+ TransactionBase.CONTINUE )
+
+
+
###########################################################################
+ # Manta Transactions
+ def MantaStart( self, channel, prefix, file_type, skip, use_timestamp ):
+
+ # Create a file display
+ file_display = manta_new(FileDisplay( str(prefix), str(file_type),
0, skip, use_timestamp ))
+
+ # Obtain the current image display.
+ current = self.engine.getImageDisplay( channel )
+
+ # Create a multi-display.
+ self.multi = manta_new(MultiDisplay())
+ self.multi.add( current )
+ self.multi.add( file_display )
+
+ # Set the new image display for the channel.
+ self.engine.setImageDisplay( channel, self.multi )
+
+ def MantaStop( self, channel ):
+
+ # Replace the image display with the previous.
+ self.engine.setImageDisplay( channel, self.multi.get(0) )
+
+ # Delete the temporary displays
+ manta_delete( self.multi.get( 1 ) )
+ manta_delete( self.multi )
+
+ self.multi = None
+
+ # How to overload this function??
+ def Destroy(self):
+
+ # Stop recording.
+ if (self.stop_button.IsEnabled()):
+ self.OnStopButton(())
+
+ wx.Panel.Destroy()
+
+class MantaCaptureFrame(wx.Frame):
+ def __init__(self, parent, engine, channel=0 ):
+ wx.Frame.__init__(self, parent=parent, title="Capture Frames")
+
+ panel = wx.Panel( self )
+
+ # Create a Capture Panel.
+ self.capture_panel = MantaCapturePanel( panel, engine, channel )
+
+ self.start_button = wx.Button( panel, -1, "Start" )
+ self.stop_button = wx.Button( panel, -1, "Stop" )
+ self.stop_button.Disable()
+ self.capture_button = wx.Button( panel, -1, "Capture One Frame")
+
+ vsizer = wx.BoxSizer(wx.VERTICAL)
+ vsizer.Add( self.capture_panel, 0, wx.EXPAND )
+
+ hsizer = wx.BoxSizer(wx.HORIZONTAL);
+ hsizer.Add( self.start_button, wx.ALIGN_CENTER )
+ hsizer.Add( self.stop_button, wx.ALIGN_CENTER )
+ # hsizer.Add( self.capture_button, wx.ALIGN_CENTER )
+ vsizer.Add( hsizer, 0, wx.EXPAND )
+
+ panel.SetSizerAndFit( vsizer )
+
+ self.SetClientSize(panel.GetSize())
+
+ # Bind events.
+ self.Bind(wx.EVT_BUTTON, self.OnStartButton, self.start_button)
+ self.Bind(wx.EVT_BUTTON, self.OnStopButton, self.stop_button)
+ self.Bind(wx.EVT_BUTTON, self.OnCaptureButton, self.capture_button)
+ self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
+
+ def OnStartButton( self, event ):
+
+ self.capture_panel.OnStartButton( event )
+
+ self.start_button.Disable()
+ self.stop_button.Enable()
+ self.capture_button.Disable()
+
+
+ def OnStopButton( self, event ):
+
+ self.capture_panel.OnStopButton( event )
+
+ self.start_button.Enable()
+ self.stop_button.Disable()
+ self.capture_button.Enable()
+
+
+ def OnCaptureButton( self, event ):
+
+ self.capture_panel.OnCaptureButton( event )
+
+
+ def OnCloseWindow(self, event):
+
+ self.Destroy()
+
+
+def ResampleCapturedFrames( prefix, performance ):
+
+ # Determine the prefix directory and file name.
+ m = re.match("(.*)\/(.*)$", prefix);
+ if (m):
+ prefix_dir = m.group(1)
+ prefix_file = m.group(2)
+ else:
+ prefix_dir = os.getcwd()
+ prefix_file = prefix
+
+ print prefix_dir
+ print prefix_file
+
+ # Make a list of matching files.
+ file_list = [];
+ pattern = re.compile( "^" + prefix_file + "_\d+" );
+
+ file_type = "png"
+
+ # Examine the prefix directory
+ files = os.listdir( prefix_dir )
+ for name in files:
+ # Check to see if each file matches the prefix.
+ if (pattern.match( name )):
+ # print "Found: " + name
+ file_list.append( name )
+
+ # Sort by alpha.
+ file_list.sort(key=str.lower)
+
+ # Check to see if the number of performance numbers matches the
+ # the number of files.
+ # if (len(file_list) < performance.size()):
+ # print "Length mismatch"
+
+ # print "performance: " + str(performance.size())
+
+ # Find the total time.
+ total_time = 0.0
+ for i in range(performance.size()):
+ performance[i] = (1.0/performance[i])
+ total_time += performance[i]
+
+ # Determine total number of frames.
+ frame_time = 1.0/30.0;
+ total_frames = total_time / frame_time;
+
+ # print "Total time: " + str(total_time)
+ # print "Total frames: " + str(total_frames)
+
+ frame_counter = 0
+
+ # Copy frames as necessary.
+ i = 0
+ while (i < performance.size()):
+
+ times_displayed = performance[i] / frame_time
+ # print "performance: " + str(performance[i])
+ # print "Times displayed: " + str(times_displayed)
+
+ # if (times_displayed < 1.0):
+
+ # Skip frames until "frametime" ms has passed.
+ # skip = int(1.0/times_displayed)
+ # print "skip: " + str(skip)
+ # i += skip
+ # times_displayed = 1;
+
+ for t in range(int(times_displayed)):
+ # Output current frame
+ output_file = prefix_file + "_resampled_" + "%010d" %
frame_counter + "." + file_type
+ # print file_list[i] + " -> " + output_file
+
+ # Copy file.
+ try:
+ shutil.copyfile(file_list[i],output_file)
+ except:
+ print "Error: " + file_list[i] + " -> " + output_file
+ frame_counter += 1
+
+ # Delete the temporary file.
+ os.unlink( file_list[i] )
+ i += 1
+
+ print "Output frames: " + str(frame_counter)
+
+ return 1.0 / frame_time;
+
+
+
+
+
+
+
+
Modified: trunk/SwigInterface/wxManta.py
==============================================================================
--- trunk/SwigInterface/wxManta.py (original)
+++ trunk/SwigInterface/wxManta.py Sun Aug 19 14:46:33 2007
@@ -18,6 +18,8 @@
from manta import *
from pycallback import *
+from MantaCameraPath import *
+
import FloatSpin as FS
@@ -602,16 +604,8 @@
manta_menu.Append(wx.NewId(), "About Manta"))
self.Bind(wx.EVT_MENU, self.OnCloseWindow,
manta_menu.Append(wx.NewId(), "&Quit Manta"))
- light_dialog_id = wx.NewId()
- self.dialog_map[light_dialog_id] = LightFrame
- self.Bind(wx.EVT_MENU, self.OnShowDialog,
- manta_menu.Append(light_dialog_id, "Edit Lights"))
- camera_dialog_id = wx.NewId()
- self.dialog_map[camera_dialog_id] = CameraFrame
- self.Bind(wx.EVT_MENU, self.OnShowDialog,
- manta_menu.Append(camera_dialog_id, "Edit Camera"))
self.menuBar.Append(manta_menu, "&Manta")
-
+
file_menu = wx.Menu()
self.Bind(wx.EVT_MENU, self.OnImportPython,
file_menu.Append(wx.NewId(), "Import &Python"))
@@ -620,7 +614,36 @@
view_menu = wx.Menu()
self.Bind(wx.EVT_MENU, self.OnAutoView,
view_menu.Append(wx.NewId(), "&Auto View"))
- self.menuBar.Append(view_menu, "&View")
+
+ # Edit camera dialog.
+ camera_dialog_id = wx.NewId()
+ self.dialog_map[camera_dialog_id] = CameraFrame
+ self.Bind(wx.EVT_MENU, self.OnShowDialog,
+ view_menu.Append(camera_dialog_id, "Edit Camera"))
+
+ # Camera Path dialog.
+ dialog_id = wx.NewId()
+ self.dialog_map[dialog_id] = MantaCameraPathFrame
+ self.Bind( wx.EVT_MENU, self.OnShowDialog,
+ view_menu.Append(dialog_id, "Camera Paths"))
+
+ # Capture frames dialog.
+ dialog_id = wx.NewId()
+ self.dialog_map[dialog_id] = MantaCaptureFrame
+ self.Bind( wx.EVT_MENU, self.OnShowDialog,
+ view_menu.Append(dialog_id, "Capture Frames"))
+
+ self.menuBar.Append(view_menu, "&Camera")
+
+ # Edit ligts.
+ light_menu = wx.Menu()
+
+ light_dialog_id = wx.NewId()
+ self.dialog_map[light_dialog_id] = LightFrame
+ self.Bind(wx.EVT_MENU, self.OnShowDialog,
+ light_menu.Append(light_dialog_id, "Edit Lights"))
+ self.menuBar.Append(light_menu, "&Lights")
+
self.SetMenuBar(self.menuBar)
- [Manta] r1666 - trunk/SwigInterface, abe, 08/19/2007
Archive powered by MHonArc 2.6.16.