Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1142 - in trunk: Engine/Control Interface SwigInterface


Chronological Thread 
  • From: bigler@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1142 - in trunk: Engine/Control Interface SwigInterface
  • Date: Mon, 17 Jul 2006 14:25:21 -0600 (MDT)

Author: bigler
Date: Mon Jul 17 14:25:20 2006
New Revision: 1142

Modified:
   trunk/Engine/Control/RTRT.cc
   trunk/Engine/Control/RTRT.h
   trunk/Interface/Callback.h
   trunk/Interface/CallbackHelpers.h
   trunk/SwigInterface/pycallback.cc
   trunk/SwigInterface/pycallback.h
   trunk/SwigInterface/pycallback.i
   trunk/SwigInterface/wxManta.py
Log:

Engine/Control/RTRT.cc
Engine/Control/RTRT.h

  Channel::id is now the index into the channels array that is used
  for all the other functions that index into it.  createChannel now
  returns this as the index.

  Changed "AtomicCounter ids" to a "Mutex channel_create_lock".

Interface/Callback.h
Interface/CallbackHelpers.h

  Added Callback_Static_2Data_2Arg and Callback_Static_3Data_2Arg
  classes for the callbacks used by MantaInterface.

SwigInterface/pycallback.cc
SwigInterface/pycallback.h

  Added ability to create oneShotCallback functions.  These are the
  ones with call time bound arguments.  Using this function as an
  example you can add others as needed.

  Changed createMantaCallback to createMantaTransaction to more match
  what type of call back function it creates.

  Pulled out the code that did the actual python function calling and
  error checking into a static function that could be used by multiple
  functions.

SwigInterface/pycallback.i

  Added stuff for help with Callbacks with call time bound parameters.

SwigInterface/wxManta.py

  Default to num processors to 1.

  Resizing is mostly working.  It does a resizing at the beginning
  that makes it 20x20.  Once you resize the window it snaps back.

  Changed createMantaCallback to createMantaTransaction.


Modified: trunk/Engine/Control/RTRT.cc
==============================================================================
--- trunk/Engine/Control/RTRT.cc        (original)
+++ trunk/Engine/Control/RTRT.cc        Mon Jul 17 14:25:20 2006
@@ -82,7 +82,7 @@
     barrier2("RTRT frame barrier #2"),
     barrier3("RTRT frame barrier #3"),
     transaction_lock("RTRT transaction lock"),
-    ids("RTRT id counter", 1),
+    channel_create_lock("RTRT channel creation lock"),
     thread_storage( 0 )
 {
   workersWanted=0;
@@ -691,7 +691,14 @@
 
   // Create the channel.
   Channel* channel = new Channel;
-  channel->id      = ids++;
+
+  // Add the channel to the renderer.
+  channel_create_lock.lock();
+  channel->id      = static_cast<int>(channels.size());
+  channels.push_back(channel);
+  channel_create_lock.unlock();
+
+  // Set up the parameters
   channel->display = image_display;
   channel->stereo  = stereo;
   channel->xres    = xres;
@@ -708,8 +715,6 @@
 
   pipelineNeedsSetup = true;
 
-  // Add the channel to the renderer.
-  channels.push_back(channel);
   return channel->id;
 }
 

Modified: trunk/Engine/Control/RTRT.h
==============================================================================
--- trunk/Engine/Control/RTRT.h (original)
+++ trunk/Engine/Control/RTRT.h Mon Jul 17 14:25:20 2006
@@ -300,7 +300,10 @@
     char pad2[MAXCACHELINESIZE];
 
     struct Channel {
-      int id;
+      int id;                   // The index into the list of
+                                // channels, use this index to access
+                                // channel specifics through other
+                                // functions.
       ImageDisplay* display;
       int xres, yres;
       bool stereo;
@@ -319,7 +322,7 @@
     Scene* scene;
     string scenePath;
 
-    SCIRun::AtomicCounter ids;
+    SCIRun::Mutex channel_create_lock;
 
     Scene* readMOScene(const string& name, const vector<string>& args,
                        bool printErrors);

Modified: trunk/Interface/Callback.h
==============================================================================
--- trunk/Interface/Callback.h  (original)
+++ trunk/Interface/Callback.h  Mon Jul 17 14:25:20 2006
@@ -44,6 +44,22 @@
       return new Callback_Static_0Data_2Arg<Arg1,Arg2>(pmf, arg1, arg2);
     }
 
+    template<typename Data1, typename Data2,
+             typename Arg1, typename Arg2> static
+    CallbackBase_2Data<Data1, Data2>*
+    create(void (*pmf)(Data1, Data2, Arg1, Arg2),
+           Arg1 arg1, Arg2 arg2) {
+      return new Callback_Static_2Data_2Arg<Data1, Data2, Arg1, Arg2>(pmf, 
arg1, arg2);
+    }
+
+    template<typename Data1, typename Data2, typename Data3,
+             typename Arg1, typename Arg2> static
+    CallbackBase_3Data<Data1, Data2, Data3>*
+    create(void (*pmf)(Data1, Data2, Data3, Arg1, Arg2),
+           Arg1 arg1, Arg2 arg2) {
+      return new Callback_Static_3Data_2Arg<Data1, Data2, Data3, Arg1, 
Arg2>(pmf, arg1, arg2);
+    }
+
     ///////////////////////////////////////////////////////////
     // Class member functions
 

Modified: trunk/Interface/CallbackHelpers.h
==============================================================================
--- trunk/Interface/CallbackHelpers.h   (original)
+++ trunk/Interface/CallbackHelpers.h   Mon Jul 17 14:25:20 2006
@@ -187,6 +187,52 @@
     Arg2 arg2;
   };
   
+  // 2 Data
+  template<typename Data1, typename Data2,
+           typename Arg1, typename Arg2>
+  class Callback_Static_2Data_2Arg : public CallbackBase_2Data<Data1, Data2> 
{
+  public:
+    Callback_Static_2Data_2Arg(void (*pmf)(Data1, Data2, Arg1, Arg2),
+                               Arg1 arg1, Arg2 arg2)
+      : pmf(pmf), arg1(arg1), arg2(arg2)
+    {
+    }
+    virtual ~Callback_Static_2Data_2Arg()
+    {
+    }
+    virtual void call(Data1 data1, Data2 data2)
+    {
+      pmf(data1, data2, arg1, arg2);
+    }
+  private:
+    void (*pmf)(Data1, Data2, Arg1, Arg2);
+    Arg1 arg1;
+    Arg2 arg2;
+  };
+
+  // 3 Data
+  template<typename Data1, typename Data2, typename Data3,
+           typename Arg1, typename Arg2>
+  class Callback_Static_3Data_2Arg : public CallbackBase_3Data<Data1, Data2, 
Data3> {
+  public:
+    Callback_Static_3Data_2Arg(void (*pmf)(Data1, Data2, Data3, Arg1, Arg2),
+                               Arg1 arg1, Arg2 arg2)
+      : pmf(pmf), arg1(arg1), arg2(arg2)
+    {
+    }
+    virtual ~Callback_Static_3Data_2Arg()
+    {
+    }
+    virtual void call(Data1 data1, Data2 data2, Data3 data3)
+    {
+      pmf(data1, data2, data3, arg1, arg2);
+    }
+  private:
+    void (*pmf)(Data1, Data2, Data3, Arg1, Arg2);
+    Arg1 arg1;
+    Arg2 arg2;
+  };
+
   ///////////////////////////////////////////////////////////
   // Class member functions
   

Modified: trunk/SwigInterface/pycallback.cc
==============================================================================
--- trunk/SwigInterface/pycallback.cc   (original)
+++ trunk/SwigInterface/pycallback.cc   Mon Jul 17 14:25:20 2006
@@ -29,7 +29,11 @@
 #include <SwigInterface/pycallback.h>
 #include <Interface/Callback.h>
 
+#include <iostream>
+
 using namespace Manta;
+using namespace std;
+
 
 // #define DECREMENT_PYTHON_REFERENCE_COUNTER 1
 
@@ -112,16 +116,11 @@
     callFromC2(function, new_args);
 }
 
-void
-PyCallback::callFromC2(PyObjectContainer function,
-                       PyObjectContainer args)
+static
+void makePyCall(PyObject* function, PyObject* args)
 {
-  // Get ready to call python code
-  PyGILState_STATE gstate;
-  gstate = PyGILState_Ensure();
-
   // Call the python function
-  PyObject* result = PyEval_CallObject(function(), args());
+  PyObject* result = PyEval_CallObject(function, args);
   
   // Check the result
   if (result == NULL) {
@@ -134,21 +133,72 @@
     // We don't care what the result is
     Py_DECREF(result);
   }
+}
 
+void
+PyCallback::callFromC2(PyObjectContainer function,
+                       PyObjectContainer args)
+{
+  // Get ready to call python code
+  PyGILState_STATE gstate;
+  gstate = PyGILState_Ensure();
+
+  makePyCall(function(), args());
+  
   // Done with python code
   PyGILState_Release(gstate);
 }
 
 CallbackBase_0Data*
-PyCallback::createMantaCallback(PyObject* new_args) {
+PyCallback::createMantaTransaction(PyObject* new_args)
+{
   return Callback::create(this, &PyCallback::callFromC,
                           PyObjectContainer(new_args));
 }
 
 CallbackBase_0Data*
-PyCallback::static_createMantaCallback(PyObject* function,
-                                       PyObject* args) {
+PyCallback::static_createMantaTransaction(PyObject* function,
+                                          PyObject* args)
+{
   return Callback::create(PyCallback::callFromC2,
+                          PyObjectContainer(function),
+                          PyObjectContainer(args));
+}
+
+void
+PyCallback::callFromC_OneShot(int a1, int a2,
+                              PyObjectContainer function,
+                              PyObjectContainer args)
+{
+  // Get ready to call python code
+  PyGILState_STATE gstate;
+  gstate = PyGILState_Ensure();
+
+  // Create a new Touple to accomodate the new args
+  int num_args = PyTuple_Size(args());
+  //  cerr << "PyCallback::callFromC_OneShot:: num_args = "<<num_args<<"\n";
+  PyObject* new_args = PyTuple_New(num_args + 2);
+  // Pack the new args to the arguments
+  PyTuple_SET_ITEM(new_args, 0, PyInt_FromLong(a1));
+  PyTuple_SET_ITEM(new_args, 1, PyInt_FromLong(a2));
+  for(int i = 0; i < num_args; ++i) {
+    PyTuple_SET_ITEM(new_args, i+2, PyTuple_GET_ITEM(args(), i));
+  }
+  //  cerr << "new_args.size = "<<PyTuple_Size(new_args)<<"\n";
+  
+  makePyCall(function(), new_args);
+
+  Py_DECREF(new_args);
+
+  // Done with python code
+  PyGILState_Release(gstate);
+}
+
+CallbackBase_2Data<int, int>*
+PyCallback::static_createMantaOneShotCallback(PyObject* function,
+                                              PyObject* args)
+{
+  return Callback::create(PyCallback::callFromC_OneShot,
                           PyObjectContainer(function),
                           PyObjectContainer(args));
 }

Modified: trunk/SwigInterface/pycallback.h
==============================================================================
--- trunk/SwigInterface/pycallback.h    (original)
+++ trunk/SwigInterface/pycallback.h    Mon Jul 17 14:25:20 2006
@@ -32,11 +32,12 @@
 
 #include <Python.h>
 
+#include <Interface/Callback.h>
+
 #include <stdio.h>
 
 namespace Manta {
-  class CallbackBase_0Data;
-
+  
   /* This is the thing that is supposed to keep reference counts on
      our objects.  Unfortunately, when a pointer to a swig proxy class
      is passed in it causes a seg fault when deleted.  Since we have
@@ -84,10 +85,18 @@
     void callFromC2(PyObjectContainer function,
                     PyObjectContainer args);
 
-    CallbackBase_0Data* createMantaCallback(PyObject* new_args = 0);
+    Manta::CallbackBase_0Data* createMantaTransaction(PyObject* new_args = 
0);
+
+    static Manta::CallbackBase_0Data*
+           static_createMantaTransaction(PyObject* function, PyObject* args);
+
     static
-    CallbackBase_0Data* static_createMantaCallback(PyObject* function,
-                                                   PyObject* args);
+    void callFromC_OneShot(int a1, int a2,
+                           PyObjectContainer function,
+                           PyObjectContainer args);
+    static Manta::CallbackBase_2Data<int, int>*
+           static_createMantaOneShotCallback(PyObject* function,
+                                             PyObject* args);
 
     PyObject* setArgs(PyObject* new_args);
   protected:

Modified: trunk/SwigInterface/pycallback.i
==============================================================================
--- trunk/SwigInterface/pycallback.i    (original)
+++ trunk/SwigInterface/pycallback.i    Mon Jul 17 14:25:20 2006
@@ -26,7 +26,15 @@
 
 %{
 #include <SwigInterface/pycallback.h>
+#include <Interface/Callback.h>
+#include <Interface/CallbackHelpers.h>
 %}
 
 %include <SwigInterface/pycallback.h>
+%include <Interface/CallbackHelpers.h>
+
+namespace Manta {
+  %template(CallbackBase_2Data_Int_Int) CallbackBase_2Data<int, int>;
+}
+
 

Modified: trunk/SwigInterface/wxManta.py
==============================================================================
--- trunk/SwigInterface/wxManta.py      (original)
+++ trunk/SwigInterface/wxManta.py      Mon Jul 17 14:25:20 2006
@@ -15,7 +15,7 @@
 
 
 # Number of workers.
-numworkers = 2
+numworkers = 1
 
 # Determine frame resolution.
 xres = 512
@@ -99,9 +99,14 @@
         self.prev_time = time.time()
         self.updateFramerate = updateFramerate
 
+        self.Bind(wx.EVT_SIZE, self.OnSize)
+
     def printSize(self, name, size):
         print "%s size = (%d, %d)" % (name, size.x, size.y)
 
+    def OnSize(self, event):
+        print "event.size = %s" % event.GetSize()
+        
     def OnPaint(self, event):
         # Note that you must always generate a wxPaintDC object,
         # otherwise certain platforms will not think that you painted
@@ -234,7 +239,7 @@
         newPosition = Vector(x,y,z)
         cbArgs = ( newPosition, )
         self.engine.addTransaction("Light Position",
-                                   
manta_new(PyCallback.static_createMantaCallback(spinner.light.setPosition, 
cbArgs)))
+                                   
manta_new(PyCallback.static_createMantaTransaction(spinner.light.setPosition, 
cbArgs)))
 
 
     def OnSelectColor(self, event):
@@ -254,8 +259,7 @@
                             color.Blue() /255.0)
         cbArgs = ( Color(rgbColor), )
         self.engine.addTransaction("Light Color",
-                                   
manta_new(PyCallback.static_createMantaCallback(colorButton.light.setColor, 
cbArgs)))
-
+                                   
manta_new(PyCallback.static_createMantaTransaction(colorButton.light.setColor,
 cbArgs)))
 
 class MantaFrame(wx.Frame):
     def __init__(self, parent=None, title="Manta",
@@ -264,6 +268,7 @@
 
         # Setup events
         self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
+        self.Bind(wx.EVT_SIZE, self.OnSize)
 
         # Create the StatusBar
         self.statusbar = self.CreateStatusBar()
@@ -282,13 +287,13 @@
 
         # Create the Main panel that will hold the renderer
         self.panel = wx.Panel(self)
-        self.panel.SetSize(renderSize)
 
         ############################################################
         # Layout
         box = wx.BoxSizer(wx.HORIZONTAL)
         box.Add(self.panel, 1, wx.EXPAND)
-        self.SetSizerAndFit(box)
+        self.SetSizer(box)
+        self.SetClientSize(renderSize)
 
         
         
#######################################################################
@@ -337,7 +342,8 @@
             self.sync_thread = DisplayThread(self.canvas, self.sync_display)
 
         # Create a display channel.
-        self.engine.createChannel( display, camera, use_stereo, xres, yres )
+        self.channelID = self.engine.createChannel( display, camera,
+                                                    use_stereo, xres, yres )
 
         # Basic scene.
         self.engine.setScene( createDefaultScenePython() )
@@ -364,6 +370,25 @@
     
###########################################################################
     ## OnCloseWindow
     
###########################################################################
+    def OnSize(self, event):
+        panelSize = self.panel.GetSize()
+        print "Size panel  to %s" % panelSize
+        print "Size canvas to %s" % self.canvas.GetSize()
+        self.canvas.SetSize(panelSize)
+        cbArgs = (self.channelID, panelSize.width, panelSize.height)
+        self.engine.addOneShotCallback(MantaInterface.Relative, 0,
+                                       
manta_new(PyCallback.static_createMantaOneShotCallback(self.changeResolution, 
cbArgs)))
+        event.Skip(True)
+
+    def changeResolution(self, a, b, channel, new_xres, new_yres):
+        print "a = %s, b = %s" % (a, b)
+        print "channel = %s" % channel
+        print "new_res = (%s, %s)" % (new_xres, new_yres)
+        self.engine.changeResolution(channel, new_xres, new_yres, True);
+        
+    
###########################################################################
+    ## OnCloseWindow
+    
###########################################################################
     def OnCloseWindow(self, event):
         self.ShutdownEngine()
         self.Destroy()
@@ -477,7 +502,7 @@
         camera = self.engine.getCamera(channel)
         cbArgs = ( trans, Camera.LookAt )
         self.engine.addTransaction("rotate",
-                                   
manta_new(PyCallback.static_createMantaCallback(camera.transform, cbArgs)))
+                                   
manta_new(PyCallback.static_createMantaTransaction(camera.transform, cbArgs)))
         self.last_x = mouse_pos.x;
         self.last_y = mouse_pos.y;
 




  • [MANTA] r1142 - in trunk: Engine/Control Interface SwigInterface, bigler, 07/17/2006

Archive powered by MHonArc 2.6.16.

Top of page