Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1299 - in trunk: Image SwigInterface


Chronological Thread 
  • From: bigler@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1299 - in trunk: Image SwigInterface
  • Date: Tue, 13 Mar 2007 16:05:33 -0700 (MST)

Author: bigler
Date: Tue Mar 13 16:05:33 2007
New Revision: 1299

Modified:
   trunk/Image/ImageMagickFile.cc
   trunk/SwigInterface/FloatSpin.py
   trunk/SwigInterface/runwxmanta.py
   trunk/SwigInterface/wxManta.py
Log:

Image/ImageMagickFile.cc

  QuantumRange isn't defined for older versions of ImageMagick.  This
  is to provide a backward compatibility.

SwigInterface/FloatSpin.py

  The min and max of the range can now be separately set to None to
  allow for open ranges.

SwigInterface/runwxmanta.py

  You can now specify a scene library from the commandline a la
  bin/manta.

SwigInterface/wxManta.py

  Added clampZeroTo255 function.

  The lights can now be scaled.  This will allow lights to be brighter
  than 1.


Modified: trunk/Image/ImageMagickFile.cc
==============================================================================
--- trunk/Image/ImageMagickFile.cc      (original)
+++ trunk/Image/ImageMagickFile.cc      Tue Mar 13 16:05:33 2007
@@ -44,6 +44,11 @@
 using MagickLib::Quantum;
 using MagickLib::MagickRealType;
 
+// This is bacward compatibility with previous versions of ImageMagick
+#ifndef QuantumRange
+#define QuantumRange MaxRGB
+#endif
+
 extern "C" void writeImageMagick( Image const *image,
                                   std::string const &file_name,
                                   int which )

Modified: trunk/SwigInterface/FloatSpin.py
==============================================================================
--- trunk/SwigInterface/FloatSpin.py    (original)
+++ trunk/SwigInterface/FloatSpin.py    Tue Mar 13 16:05:33 2007
@@ -203,15 +203,15 @@
 class FloatSpin(wx.PyControl):
 
     def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
-                 size=(95,-1), style=0, value=0.0, min=0.0, max=100.0,
+                 size=(95,-1), style=0, value=0.0, min_val=None, 
max_val=None,
                  increment=1.0, digits=-1, extrastyle=FS_LEFT,
                  name="FloatSpin"):
         """
         Default Class Constructor. Non-Default Parameters Are:
         
         - value: Is The Current Value For FloatSpin;
-        - min: The Minimum Value;
-        - max: The Maximum Value;
+        - min: The Minimum Value, ignored if None
+        - max: The Maximum Value, ignored if None
         - increment: The Increment For Every EVT_FLOATSPIN Events;
         - digits: Number Of Representative Digits For Your Floating Point 
Numbers;
         - extrastyle: One Of The Following:
@@ -227,17 +227,10 @@
                               wx.NO_FULL_REPAINT_ON_RESIZE | 
wx.CLIP_CHILDREN,
                               wx.DefaultValidator, name)
 
-        self._min = FixedPoint(str(min), 20)
-        self._max = FixedPoint(str(max), 20)
-
-        if (min <= max):
-            if value < min:
-                value = min
-            elif value > max:
-                value = max
-        
-            
-        self._value = FixedPoint(str(value), 20)
+        # Don't call SetRange here, because it will try to modify
+        # self._value whose value doesn't exist yet.
+        self.SetRangeDontClampValue(min_val, max_val)
+        self._value = self.ClampValue(FixedPoint(str(value), 20))
         self._defaultvalue = self._value
         self._increment = FixedPoint(str(increment), 20)
         self._spinmodifier = FixedPoint(str(1.0), 20)
@@ -560,22 +553,51 @@
         return self._value
 
 
+    def SetRangeDontClampValue(self, min_val, max_val):
+        """
+        Set the allowed range. If max_val or min_val are None, then
+        they are ignored.  Doesn't modify the current value.
+        """
+        
+        if (min_val != None):
+            self._min = FixedPoint(str(min_val), 20)
+        else:
+            self._min = None
+        if (max_val != None):
+            self._max = FixedPoint(str(max_val), 20)
+        else:
+            self._max = None
+
+            
     def SetRange(self, min_val, max_val):
         """
-        Set The Allowed Range, If max_val < min_val Then No Range And All
-        Values Are Allowed.
+        Set The Allowed Range. If max_val or min_val are None, then
+        they are ignored.
         """
         
-        self._min = FixedPoint(str(min_val), 20)
-        self._max = FixedPoint(str(max_val), 20)
+        self.SetRangeDontClampValue(min_value, max_value)
 
-        if self.HasRange():
-            if self._value > self._max:
-                self.SetValue(self._max)
-            elif self._value < self._min:
-                self.SetValue(self._min)
-    
+        value = self.ClampValue(self._value)
+        if (value != self._value):
+            self.SetValue(value)
+
+    def ClampValue(self, var):
+        """
+        Clamps var between _min and _max depending on if the range has
+        been specified.
 
+        Returns a clamped copy of var.
+        """
+        
+        if (self._min != None):
+            if (var < self._min):
+                var = self._min
+                return var
+        if (self._max != None):
+            if (var > self._max):
+                var = self._max
+        return var
+    
     def SetIncrement(self, increment):
         """ Sets The Increment For Every EVT_FLOATSPIN Event. """
 
@@ -679,7 +701,7 @@
     def GetSnapToTicks(self):
         """ Returns Whether The Snap To Ticks Option Is Active Or Not. """
         
-        return self._snapticks        
+        return self._snapticks
     
 
     def OnFocus(self, event):
@@ -718,11 +740,8 @@
             if force_valid or not self.HasRange() or self.InRange(curr):
             
                 if force_valid and self.HasRange():
-                
-                    if curr > self.GetMax():
-                        curr = self.GetMax()
-                    elif curr < self.GetMin(): 
-                        curr = self.GetMin()
+
+                    curr = self.ClampValue(curr)
                 
                 if self._value != curr:
                     self.SetValue(curr)
@@ -758,27 +777,37 @@
 
 
     def GetMin(self):
-        """ Returns The Minimum Value For FloatSpin. """
+        """ Returns The Minimum Value For FloatSpin. It can be a
+        number or None if no minimum is present."""
         
         return self._min
 
 
     def GetMax(self):
-        """ Returns The Maximum Value For FloatSpin. """
+        """ Returns The Maximum Value For FloatSpin. It cabe be a
+        number or None if no maximum is present."""
 
         return self._max
 
 
     def HasRange(self):
         """ Returns Whether FloatSpin Has A Range Or Not. """
-        
-        return self._min <= self._max        
+
+        return (self._min != None) or (self._max != None)
 
 
     def InRange(self, value):
         """ Returns Whether A Value Is Inside FloatSpin Range. """
 
-        return not self.HasRange() or (value >= self._min and value <= 
self._max)
+        if (not self.HasRange()):
+            return True
+        if (self._min != None):
+            if (value < self._min):
+                return False
+        if (self._max != None):
+            if (value > self._max):
+                return False
+        return True
 
 
     def GetTextCtrl(self):
@@ -1072,6 +1101,8 @@
     __copy__ = __deepcopy__ = copy
 
     def __cmp__(self, other):
+        if (other == None):
+            return 1
         xn, yn, p = _norm(self, other)
         return cmp(xn, yn)
 

Modified: trunk/SwigInterface/runwxmanta.py
==============================================================================
--- trunk/SwigInterface/runwxmanta.py   (original)
+++ trunk/SwigInterface/runwxmanta.py   Tue Mar 13 16:05:33 2007
@@ -6,16 +6,18 @@
     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 > )\""
 
 def main():
 
     # Default options.
     num_workers = 1
+    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:", ["np="] )
+        opts, args = getopt.getopt(sys.argv[1:], "n:s:", ["np=","scene="] )
 
     except getopt.GetoptError:
         usage()
@@ -28,14 +30,16 @@
             except ValueError:
                 usage()
                 sys.exit(2)
+        if o in ("-s", "--scene"):
+            sceneCreator = lambda frame,engine: 
wxManta.createPluginScene(frame, engine, a)
+            
 
         # Add additional command line args here.
         
 
     
###########################################################################
     # Create the application.
-    app = wxManta.MantaApp( wxManta.createDefaultScenePython,
-                            num_workers )
+    app = wxManta.MantaApp( sceneCreator, num_workers )
 
 
     
###########################################################################

Modified: trunk/SwigInterface/wxManta.py
==============================================================================
--- trunk/SwigInterface/wxManta.py      (original)
+++ trunk/SwigInterface/wxManta.py      Tue Mar 13 16:05:33 2007
@@ -19,6 +19,16 @@
 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
+
 
###############################################################################
 
###############################################################################
 # Default Scene.
@@ -64,6 +74,9 @@
 
     engine.setScene( scene )
 
+def createPluginScene( frame, engine, scene_parameters ):
+    scene = frame.factory.readScene(scene_parameters)
+    
 class DisplayThread(threading.Thread):
     """Display Thread that will trigger a display event when the manta 
pipeline is ready to display an image."""
     def __init__(self, notify_window, sync_display):
@@ -195,7 +208,7 @@
 
         panel = wx.Panel(where, -1)
         
-        gbs = wx.GridBagSizer(5,5)
+        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())
@@ -216,23 +229,50 @@
         gbs.Add( spinnerY, (0,2))
         gbs.Add( spinnerZ, (0,3))
 
-        # Shortcut for namespace
-        colorTup = ( int(color.r() * 255),
-                     int(color.g() * 255),
-                     int(color.b() * 255) )
+        # 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(panel, -1, "Color",
-                                                        colorTup)
+                                                        tuple(colorTup))
         colorButton.Bind(csel.EVT_COLOURSELECT, self.OnSelectColor)
         self.colorButtonRefs[colorButton.GetId()] = colorButton
         colorButton.light = light
 
         gbs.Add( colorButton, (0,4))
 
+        # Add the scale
+        print "colorScale = %g, maxComponent = %g" % 
(colorScale,maxComponent)
+        gbs.Add( wx.StaticText(panel, -1, "Color Scale"), (0,5))
+        colorScaleSpinner = FS.FloatSpin(panel, colorButton.GetId(),
+                                         min_val=1, increment=0.01,
+                                         value=colorScale,
+                                         extrastyle=FS.FS_LEFT)
+        colorScaleSpinner.SetFormat("%g")
+        colorScaleSpinner.SetDigits(5)
+        colorScaleSpinner.Bind(FS.EVT_FLOATSPIN, self.OnSelectColor)
+        colorButton.spinner = colorScaleSpinner
+        gbs.Add( colorScaleSpinner, (0,6) )
+        
+
         panel.SetSizerAndFit(gbs)
         return panel
 
-    def addSpinner(self, where, value):
-        floatspin = FS.FloatSpin(where, -1, min=1, max=0,
+    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")
@@ -263,10 +303,11 @@
             dlg.ShowModal()
             dlg.Destroy()
             return
-        color = event.GetValue()
-        rgbColor = RGBColor(color.Red()  /255.0,
-                            color.Green()/255.0,
-                            color.Blue() /255.0)
+        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)))




  • [MANTA] r1299 - in trunk: Image SwigInterface, bigler, 03/13/2007

Archive powered by MHonArc 2.6.16.

Top of page