Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[Manta] r2374 - trunk/scenes/csafe/python


Chronological Thread 
  • From:
  • To:
  • Subject: [Manta] r2374 - trunk/scenes/csafe/python
  • Date: Fri, 6 Feb 2009 02:04:45 -0700 (MST)

Author: brownlee
Date: Fri Feb  6 02:04:44 2009
New Revision: 2374

Modified:
   trunk/scenes/csafe/python/TransferF.py
Log:
adding zooming to transfer function editor

Modified: trunk/scenes/csafe/python/TransferF.py
==============================================================================
--- trunk/scenes/csafe/python/TransferF.py      (original)
+++ trunk/scenes/csafe/python/TransferF.py      Fri Feb  6 02:04:44 2009
@@ -130,20 +130,27 @@
         
 
 class TransferFPanel(wx.Panel):
-    def __init__(self, parent, width, height, transferF, 
updateFunction=None):
+    def __init__(self, parent, width, height, transferF, scene, 
updateFunction=None):
 
         path = setup.csafe_scene_path
-
+        self.scene = scene
         self.backgroundIMG = wx.Image(opj(path+'images/bckgrnd.png'), 
wx.BITMAP_TYPE_PNG).ConvertToBitmap()
         self.paddingW = 20.0
-        self.paddingH = 20.0
+        self.paddingH = 30.0
         self.transferF = transferF
         self.width = width
         self.height = height
         self.parentC = parent
+        self.zoomMin = 0.0  # zoom into min value, [0,1]
+        self.zoomMax = 1.0
+        self.zoomDMin = 0.0  # data value of zoomMin/max
+        self.zoomDMax = 1.0
+        self.absoluteDMin = 0.0  # min/max data values
+        self.absoluteDMax = 1.0
         self.updateFunction = updateFunction
         panel = wx.Panel.__init__(self, parent, -1, (0, 0), (width + 
self.paddingW, height + self.paddingH) )
         wx.EVT_PAINT(self, self.OnPaint)
+        self.histogramGroup = None
         self.Update()
         self.Bind(wx.EVT_LEFT_DOWN, self.OnClick)
         self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
@@ -154,8 +161,30 @@
         self.colorSelectorWidth = 10.0
         self.selected = None
         self.dSelected = None
-        self.histogramGroup = None
         self.SetBackgroundColour(wx.Colour(90,90,90))
+        self.Bind( wx.EVT_MOUSEWHEEL, self.OnMouseWheel )
+
+    def OnMouseWheel(self, evt):
+        pos = float(evt.GetPosition().x - 
self.paddingW/2.0)/float(self.width)
+        delta = evt.GetWheelDelta()
+        rot = evt.GetWheelRotation()/delta
+        # zoom in if rot > 0, out if ro < 0
+        zoomRange = self.zoomMax - self.zoomMin
+        zoomAmount = 0.75 # the smaller the more zooming
+        if (rot > 0):
+#            self.zooms.append( (self.zoomDMin, self.zoomDMax))
+            self.zoomMin = (pos-zoomAmount*pos)*zoomRange + self.zoomMin
+            self.zoomMax = (pos+zoomAmount*(1.0-pos))*zoomRange + 
self.zoomMin
+        if (rot < 0):
+            self.zoomMin -= (pos-zoomAmount*pos)*zoomRange
+            self.zoomMax += (pos+zoomAmount*(1.0-pos))*zoomRange
+        
+        if (self.zoomMin < 0.0):
+           self.zoomMin = 0.0
+        if (self.zoomMax > 1.0):
+           self.zoomMax = 1.0
+            
+        self.Update()
         
     def SetUpdateFunction(self, function):
         self.updateFunction = function
@@ -172,13 +201,16 @@
         self.UpdateHistogram()
     
     def OnRightClick(self, evt):
+        zoomRange = self.zoomMax-self.zoomMin
         x = evt.GetPosition().x - self.paddingW/2.0
         y = evt.GetPosition().y - self.paddingH/2.0
+        pos = float(x)/float(self.width)*zoomRange + self.zoomMin
         # did they click on a color picker?
         clicked = False
         index = -1
         for i in range(len(self.transferF.colors)):
-            if abs(x - self.transferF.colors[i][0]*self.width) < 
self.colorSelectorWidth/2.0:
+            colorx = (self.transferF.colors[i][0] - self.zoomMin)/zoomRange
+            if abs(x - colorx*self.width) < self.colorSelectorWidth/2.0:
                 clicked = True 
                 index = i
         
@@ -223,7 +255,6 @@
                 color[0] /= 255.0
                 color[1] /= 255.0
                 color[2] /= 255.0
-                pos = float(x)/float(self.width)
                 self.transferF.AddColor( color, pos)
                 self.Update()
                 
@@ -240,11 +271,13 @@
        self.transferF.UpdateColorMap()
     
     def OnClick(self, evt):
+        zoomRange = self.zoomMax-self.zoomMin
         x = evt.GetPosition().x - self.paddingW/2.0
         if self.selected == None:
             index = -1
             for i in range(len(self.transferF.colors)):
-                if abs(x - self.transferF.colors[i][0]*self.width) < 
self.colorSelectorWidth/2.0:
+                colorx = (self.transferF.colors[i][0] - 
self.zoomMin)/zoomRange
+                if abs(x - colorx*self.width) < self.colorSelectorWidth/2.0:
                     clicked = True 
                     index = i
             if index >= 0:
@@ -260,6 +293,7 @@
         self.UpdateHistogram()
         
     def OnMotion(self, evt):
+        zoomRange = self.zoomMax-self.zoomMin
         x = evt.GetPosition().x - self.paddingW/2.0
        if (x < 0.0):
            x = 0.0
@@ -277,7 +311,7 @@
             y = 0
 
         if self.selected != None:
-            pos = float(x) / float(self.width)
+            pos = (float(x) / float(self.width))*zoomRange + self.zoomMin
             self.transferF.MoveColor(self.selected, pos)
             colord = self.transferF.GetColorAtIndex(self.selected)
             a = float(self.height - y)/float(self.height)
@@ -292,6 +326,13 @@
             self.Update()
         
     def Update(self):
+        if (self.histogramGroup != None):
+          histo = self.histogramGroup.histogram
+          self.absoluteDMin = histo.colorDMin
+          self.absoluteDMax = histo.colorDMax
+          absoluteRange = self.absoluteDMax - self.absoluteDMin
+          self.zoomDMin = self.absoluteDMin + self.zoomMin*absoluteRange
+          self.zoomDMax = self.absoluteDMin + self.zoomMax*absoluteRange
         width = self.width - 2.0
         height = self.height - 2.0
         self.barWidth = 1.0
@@ -300,8 +341,9 @@
         bly = 0.0 + self.height + self.barWidth/2.0 - 2.0 + self.paddingH/2.0
 
         self.lines = []
+        zoomRange = self.zoomMax - self.zoomMin
         for i in range(0, int(width)):
-            color = self.transferF.GetColor( float(i)/float(width) )
+            color = self.transferF.GetColor( 
(float(i)/float(width))*zoomRange +self.zoomMin )
             self.lines.append( (color, ( blx + i*self.barWidth, bly, blx + 
i*self.barWidth, (bly - height) ) ) )
         self.parentC.Refresh()
         self.Refresh()
@@ -397,7 +439,11 @@
              penColor = wx.Colour(r,g,b)
             dc.SetPen(wx.Pen(penColor, self.barWidth + 1) )
             dc.DrawLine( lines[i][1][0], lines[i][1][1], lines[i][1][2], 
lines[i][1][3])
+        zoomRange = self.zoomMax-self.zoomMin
         for i in range(len(colors)):
+            colorx = (colors[i][0]-self.zoomMin)/zoomRange
+            if (colorx < 0.0 or colorx > 1.0):
+                continue
             dc.SetPen(wx.Pen('GRAY', 2) )
             color = self.transferF.GetColor( colors[i][0] )
            try:
@@ -407,9 +453,48 @@
             if i == self.dSelected:
                dc.SetBrush(wx.Brush( (128,128,128), wx.SOLID ) )
             recWidth = self.colorSelectorWidth
-            x = colors[i][0]*self.width - recWidth/2.0 + left
+            x = colorx*self.width - recWidth/2.0 + left
             y = self.height - recWidth + top
             dc.DrawRectangle(x,y - color[3]*self.height + recWidth/2.0, 
recWidth, recWidth)
+        dc.SetTextForeground(wx.Colour(0,0,0))
+        self.SetForegroundColour(wx.Colour(255,0,0))
+        dc.SetPen(wx.Pen(wx.Colour(255,255,255), 1))
+        dc.SetBrush(wx.Brush(wx.Colour(255,255,255)))
+        fontSize = 10
+        if self.scene.biggify == True:
+                fontSize = 12
+        dc.SetFont(wx.Font(fontSize, wx.FONTFAMILY_DEFAULT, wx.NORMAL, 
wx.FONTWEIGHT_BOLD))
+        string = str("%1.2g" % self.zoomDMin)
+        extent = dc.GetTextExtent(string)
+        xpos = extent[0]/2.0 + self.paddingW/2.0
+        diff = xpos - self.paddingW/2.0
+        if diff < 0:
+            xpos -= diff
+        ypos = self.height+5
+        dc.DrawTextPoint(string, (xpos,ypos))
+        string = str("%1.2g" % self.zoomDMax)
+        extent = dc.GetTextExtent(string)
+        xpos = self.width - extent[0]/2.0 + self.paddingW/2.0
+        diff = xpos + extent[0] - (self.width + self.paddingW/2.0)
+        if (diff > 0 ):
+           xpos -= diff
+        dc.DrawTextPoint(string, (xpos,ypos))
+        
+        # draw min/max text
+        ypos = self.height+extent[1]+5
+        if self.scene.biggify:
+              ypos = self.height
+        string = str("%1.2g" %self.absoluteDMin)
+        extent = dc.GetTextExtent(string)
+        xpos = extent[0]/2.0 + self.paddingW/2.0
+        dc.DrawTextPoint(string, (xpos,ypos))
+        string = str("%1.2g" % self.absoluteDMax)
+        extent = dc.GetTextExtent(string)
+        xpos = self.width - extent[0]/2.0 + self.paddingW/2.0
+        diff = xpos + extent[0] - (self.width + self.paddingW/2.0)
+        if (diff > 0 ):
+           xpos -= diff
+        dc.DrawTextPoint(string, (xpos,ypos))
 
 class TransferFGroup(wx.Panel):
     def __init__(self, parent, width, height, transferF, title, scene):
@@ -426,7 +511,7 @@
 
         self.box1_title.SetForegroundColour( wx.WHITE ) # Make label 
readable!
         
-        self.transferFPanel = TransferFPanel(self, width, height, transferF)
+        self.transferFPanel = TransferFPanel(self, width, height, transferF, 
scene)
         box1 = self.box1 = wx.StaticBoxSizer( self.box1_title, wx.VERTICAL )
         self.gbs = gbs = wx.GridBagSizer(5,5)
         self.sizer = box1


  • [Manta] r2374 - trunk/scenes/csafe/python, brownlee, 02/06/2009

Archive powered by MHonArc 2.6.16.

Top of page