commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r8982 - gnuradio/branches/features/experimental-gui/pl


From: jblum
Subject: [Commit-gnuradio] r8982 - gnuradio/branches/features/experimental-gui/plotter
Date: Tue, 22 Jul 2008 19:10:48 -0600 (MDT)

Author: jblum
Date: 2008-07-22 19:10:47 -0600 (Tue, 22 Jul 2008)
New Revision: 8982

Modified:
   gnuradio/branches/features/experimental-gui/plotter/waterfall_plotter.py
Log:
some enhancements

Modified: 
gnuradio/branches/features/experimental-gui/plotter/waterfall_plotter.py
===================================================================
--- gnuradio/branches/features/experimental-gui/plotter/waterfall_plotter.py    
2008-07-23 00:32:14 UTC (rev 8981)
+++ gnuradio/branches/features/experimental-gui/plotter/waterfall_plotter.py    
2008-07-23 01:10:47 UTC (rev 8982)
@@ -26,6 +26,9 @@
 import gltext
 
 PADDING = 35, 60, 40, 60 #top, right, bottom, left
+RGBA_ARRAY = \
+       [numpy.array((0, 2*i, 1 - 2*i, 0), numpy.uint8) for i in range(0, 128)] 
+ \
+       [numpy.array((2*i - 1, 2 - 2*i, 0, 0), numpy.uint8) for i in range(128, 
256)]
 
 ##################################################
 # Waterfall Plotter
@@ -40,14 +43,18 @@
                self._fft_size = None #must be None on init
                self._num_frames = 256
                self._frame_ptr = 0
-               self._waterfall_buffer_bottom = GLuint(0)
-               self._waterfall_buffer_top = GLuint(0)
+               self._buffer_init = False
 
        def _gl_init(self):
                """!
                Run gl initialization tasks.
                """
                self._grid_compiled_list_id = glGenLists(1)
+               self._waterfall_buffer_top = GLuint(0)
+               self._waterfall_buffer_bottom = GLuint(0)
+               glGenBuffers(1, self._waterfall_buffer_top)
+               glGenBuffers(1, self._waterfall_buffer_bottom)
+               self._buffer_init = True
 
        def draw(self):
                """!
@@ -90,27 +97,14 @@
                glRasterPos2f(self.padding_left+1, 
self.padding_top+((self._num_frames-self._frame_ptr)*y_zoom)-1)
                #draw top portion
                glPixelZoom(x_zoom, y_zoom)
-               glBindBuffer(GL_PIXEL_UNPACK_BUFFER, self._waterfall_buffer_top)
+               glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 
self._waterfall_buffer_top)
                glDrawPixels(self._fft_size, self._num_frames-self._frame_ptr, 
GL_RGBA, GL_UNSIGNED_BYTE, None)
                #draw bottom portion
                glPixelZoom(x_zoom, -y_zoom)
-               glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 
self._waterfall_buffer_bottom)
+               glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 
self._waterfall_buffer_bottom)
                glDrawPixels(self._fft_size, self._frame_ptr, GL_RGBA, 
GL_UNSIGNED_BYTE, None)
-               glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0) #unbind
+               glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0) #unbind
 
-       def _to_rgba(self, sample):
-               """!
-               Convert the sample into rgba color data.
-               @param sample a normalized floating point sample
-               @return a color array rgba with component values between 0 and 1
-               """
-               if sample < 0.5:
-                       colors = (0, 2*sample, 1 - 2*sample, 0)
-               else:
-                       colors = (2*sample - 1, 2 - 2*sample, 0, 0)
-               #color data
-               return numpy.array(colors, numpy.float32)
-
        def plot_samples(self, samples, min, max):
                """!
                Plot the samples onto a time slice of the waterfall.
@@ -122,46 +116,42 @@
                """
                self.semaphore.acquire(True)
                #init or reinit the pixel buffer
-               if len(samples) != self._fft_size:
-                       if self._fft_size is not None:
-                               glDeleteBuffers(1, self._waterfall_buffer_top)
-                               glDeleteBuffers(1, 
self._waterfall_buffer_bottom)
+               if self._buffer_init and len(samples) != self._fft_size:
                        self._fft_size = len(samples)
-                       glGenBuffers(1, self._waterfall_buffer_top)
-                       glGenBuffers(1, self._waterfall_buffer_bottom)
                        #initial data
-                       data = (chr(0) + chr(0) + chr(0) + chr(0)) * 
self._fft_size*self._num_frames
-                       glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 
self._waterfall_buffer_top)
+                       data = numpy.zeros(self._fft_size*self._num_frames*4, 
numpy.uint8).tostring()
+                       glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 
self._waterfall_buffer_top)
                        glBufferData(
-                               GL_PIXEL_UNPACK_BUFFER,
+                               GL_PIXEL_UNPACK_BUFFER_ARB,
                                len(data), data,
-                               GL_DYNAMIC_DRAW,
+                               GL_STATIC_DRAW,
                        )
-                       glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 
self._waterfall_buffer_bottom)
+                       glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 
self._waterfall_buffer_bottom)
                        glBufferData(
-                               GL_PIXEL_UNPACK_BUFFER,
+                               GL_PIXEL_UNPACK_BUFFER_ARB,
                                len(data), data,
-                               GL_DYNAMIC_DRAW,
+                               GL_STATIC_DRAW,
                        )
                #normalize the samples to min/max
-               samples = (samples - min)/(max-min)
-               samples = numpy.minimum(samples, 1)
-               samples = numpy.maximum(samples, 0)
-               data = numpy.array(255*numpy.concatenate(map(self._to_rgba, 
samples)), numpy.uint8).tostring()
+               samples = (samples - min)*float(255/(max-min))
+               samples = numpy.minimum(samples, 255) #clip
+               samples = numpy.maximum(samples, 0) #clip
+               samples = numpy.array(samples, numpy.uint8)
+               data = numpy.array([RGBA_ARRAY[sample] for sample in 
samples]).tostring()
                #load the color data into the pixel buffers
-               glBindBuffer(GL_PIXEL_UNPACK_BUFFER, self._waterfall_buffer_top)
+               glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 
self._waterfall_buffer_top)
                glBufferSubData(
-                       GL_PIXEL_UNPACK_BUFFER,
+                       GL_PIXEL_UNPACK_BUFFER_ARB,
                        (self._num_frames-self._frame_ptr-1)*self._fft_size*4,
                        len(data), data,
                )
-               glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 
self._waterfall_buffer_bottom)
+               glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 
self._waterfall_buffer_bottom)
                glBufferSubData(
-                       GL_PIXEL_UNPACK_BUFFER,
+                       GL_PIXEL_UNPACK_BUFFER_ARB,
                        self._frame_ptr*self._fft_size*4,
                        len(data), data,
                )
-               glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0) #unbind
+               glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0) #unbind
                #increment the pointer
                self._frame_ptr = (self._frame_ptr + 1)%self._num_frames
                self.semaphore.release()





reply via email to

[Prev in Thread] Current Thread [Next in Thread]