1. The yt Project
  2. Untitled project
  3. yt-3.0

Commits

Sam Skillman  committed e3f254a

Fixing a bug in the interactive camera. Also changing the way transfer functions are displayed with the interactive camera. If people like this, we should change this for the normal TF.plot() as well.

  • Participants
  • Parent commits 27258ef
  • Branches yt

Comments (0)

Files changed (2)

File yt/visualization/volume_rendering/camera.py

View file
 
 class InteractiveCamera(Camera):
     frames = []
-
+    _pylab = None
     def snapshot(self, fn = None, clip_ratio = None):
-        import matplotlib
-        matplotlib.pylab.figure(2)
+        if self._pylab is None: 
+            import pylab
+            self._pylab = pylab
+        self._pylab.figure(2)
         self.transfer_function.show()
-        matplotlib.pylab.draw()
+        self._pylab.draw()
         im = Camera.snapshot(self, fn, clip_ratio)
-        matplotlib.pylab.figure(1)
-        matplotlib.pylab.imshow(im/im.max())
-        matplotlib.pylab.draw()
+        self._pylab.figure(1)
+        self._pylab.imshow(im/im.max())
+        self._pylab.draw()
         self.frames.append(im)
         
     def rotation(self, theta, n_steps, rot_vector=None):

File yt/visualization/volume_rendering/transfer_functions.py

View file
         from matplotlib.ticker import FuncFormatter
         pyplot.clf()
         ax = pyplot.axes()
+        alpha = self.red.y + self.green.y + self.blue.y
+        max_alpha = alpha.max()
+        norm = max_alpha
         i_data = na.zeros((self.alpha.x.size, self.funcs[0].y.size, 3))
-        i_data[:,:,0] = na.outer(na.ones(self.alpha.x.size), self.funcs[0].y)
-        i_data[:,:,1] = na.outer(na.ones(self.alpha.x.size), self.funcs[1].y)
-        i_data[:,:,2] = na.outer(na.ones(self.alpha.x.size), self.funcs[2].y)
-        ax.imshow(i_data, origin='lower')
-        ax.fill_between(na.arange(self.alpha.y.size), self.alpha.x.size * self.alpha.y, y2=self.alpha.x.size, color='white')
+        i_data[:,:,0] = na.outer(na.ones(self.alpha.x.size), self.funcs[0].y/norm)
+        i_data[:,:,1] = na.outer(na.ones(self.alpha.x.size), self.funcs[1].y/norm)
+        i_data[:,:,2] = na.outer(na.ones(self.alpha.x.size), self.funcs[2].y/norm)
+        ax.imshow(i_data, origin='lower', aspect='auto')
+        print max_alpha
+        #ax.fill_between(na.arange(self.alpha.y.size), alpha, y2=max_alpha, color='black')
+        ax.plot(na.arange(self.alpha.y.size), alpha, 'w')
         ax.set_xlim(0, self.alpha.x.size)
         xticks = na.arange(na.ceil(self.alpha.x[0]), na.floor(self.alpha.x[-1]) + 1, 1) - self.alpha.x[0]
         xticks *= self.alpha.x.size / (self.alpha.x[-1] - self.alpha.x[0])
+        if len(xticks) > 5:
+            xticks = xticks[::len(xticks)/5]
         ax.xaxis.set_ticks(xticks)
         def x_format(x, pos):
             return "%.1f" % (x * (self.alpha.x[-1] - self.alpha.x[0]) / (self.alpha.x.size) + self.alpha.x[0])
         ax.xaxis.set_major_formatter(FuncFormatter(x_format))
-        yticks = na.linspace(0,1,5) * self.alpha.y.size
+        yticks = na.linspace(0,1,5) * max_alpha
         ax.yaxis.set_ticks(yticks)
         def y_format(y, pos):
-            return (y / self.alpha.y.size)
+            s = '%0.2f' % ( y )
+            return s
         ax.yaxis.set_major_formatter(FuncFormatter(y_format))
-        ax.set_ylabel("Transmission")
+        ax.set_ylim(0., max_alpha)
+        ax.set_ylabel("Opacity")
         ax.set_xlabel("Value")
         
     def sample_colormap(self, v, w, alpha=None, colormap="gist_stern", col_bounds=None):