Changeset 8982
- Timestamp:
- 07/22/08 19:10:47
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gnuradio/branches/features/experimental-gui/plotter/waterfall_plotter.py
r8979 r8982 27 27 28 28 PADDING = 35, 60, 40, 60 #top, right, bottom, left 29 RGBA_ARRAY = \ 30 [numpy.array((0, 2*i, 1 - 2*i, 0), numpy.uint8) for i in range(0, 128)] + \ 31 [numpy.array((2*i - 1, 2 - 2*i, 0, 0), numpy.uint8) for i in range(128, 256)] 29 32 30 33 ################################################## … … 41 44 self._num_frames = 256 42 45 self._frame_ptr = 0 43 self._waterfall_buffer_bottom = GLuint(0) 44 self._waterfall_buffer_top = GLuint(0) 46 self._buffer_init = False 45 47 46 48 def _gl_init(self): … … 49 51 """ 50 52 self._grid_compiled_list_id = glGenLists(1) 53 self._waterfall_buffer_top = GLuint(0) 54 self._waterfall_buffer_bottom = GLuint(0) 55 glGenBuffers(1, self._waterfall_buffer_top) 56 glGenBuffers(1, self._waterfall_buffer_bottom) 57 self._buffer_init = True 51 58 52 59 def draw(self): … … 91 98 #draw top portion 92 99 glPixelZoom(x_zoom, y_zoom) 93 glBindBuffer(GL_PIXEL_UNPACK_BUFFER , self._waterfall_buffer_top)100 glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, self._waterfall_buffer_top) 94 101 glDrawPixels(self._fft_size, self._num_frames-self._frame_ptr, GL_RGBA, GL_UNSIGNED_BYTE, None) 95 102 #draw bottom portion 96 103 glPixelZoom(x_zoom, -y_zoom) 97 glBindBuffer(GL_PIXEL_UNPACK_BUFFER , self._waterfall_buffer_bottom)104 glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, self._waterfall_buffer_bottom) 98 105 glDrawPixels(self._fft_size, self._frame_ptr, GL_RGBA, GL_UNSIGNED_BYTE, None) 99 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0) #unbind 100 101 def _to_rgba(self, sample): 102 """! 103 Convert the sample into rgba color data. 104 @param sample a normalized floating point sample 105 @return a color array rgba with component values between 0 and 1 106 """ 107 if sample < 0.5: 108 colors = (0, 2*sample, 1 - 2*sample, 0) 109 else: 110 colors = (2*sample - 1, 2 - 2*sample, 0, 0) 111 #color data 112 return numpy.array(colors, numpy.float32) 106 glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0) #unbind 113 107 114 108 def plot_samples(self, samples, min, max): … … 123 117 self.semaphore.acquire(True) 124 118 #init or reinit the pixel buffer 125 if len(samples) != self._fft_size: 126 if self._fft_size is not None: 127 glDeleteBuffers(1, self._waterfall_buffer_top) 128 glDeleteBuffers(1, self._waterfall_buffer_bottom) 119 if self._buffer_init and len(samples) != self._fft_size: 129 120 self._fft_size = len(samples) 130 glGenBuffers(1, self._waterfall_buffer_top)131 glGenBuffers(1, self._waterfall_buffer_bottom)132 121 #initial data 133 data = (chr(0) + chr(0) + chr(0) + chr(0)) * self._fft_size*self._num_frames134 glBindBuffer(GL_PIXEL_UNPACK_BUFFER , self._waterfall_buffer_top)122 data = numpy.zeros(self._fft_size*self._num_frames*4, numpy.uint8).tostring() 123 glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, self._waterfall_buffer_top) 135 124 glBufferData( 136 GL_PIXEL_UNPACK_BUFFER ,125 GL_PIXEL_UNPACK_BUFFER_ARB, 137 126 len(data), data, 138 GL_ DYNAMIC_DRAW,127 GL_STATIC_DRAW, 139 128 ) 140 glBindBuffer(GL_PIXEL_UNPACK_BUFFER , self._waterfall_buffer_bottom)129 glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, self._waterfall_buffer_bottom) 141 130 glBufferData( 142 GL_PIXEL_UNPACK_BUFFER ,131 GL_PIXEL_UNPACK_BUFFER_ARB, 143 132 len(data), data, 144 GL_ DYNAMIC_DRAW,133 GL_STATIC_DRAW, 145 134 ) 146 135 #normalize the samples to min/max 147 samples = (samples - min)/(max-min) 148 samples = numpy.minimum(samples, 1) 149 samples = numpy.maximum(samples, 0) 150 data = numpy.array(255*numpy.concatenate(map(self._to_rgba, samples)), numpy.uint8).tostring() 136 samples = (samples - min)*float(255/(max-min)) 137 samples = numpy.minimum(samples, 255) #clip 138 samples = numpy.maximum(samples, 0) #clip 139 samples = numpy.array(samples, numpy.uint8) 140 data = numpy.array([RGBA_ARRAY[sample] for sample in samples]).tostring() 151 141 #load the color data into the pixel buffers 152 glBindBuffer(GL_PIXEL_UNPACK_BUFFER , self._waterfall_buffer_top)142 glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, self._waterfall_buffer_top) 153 143 glBufferSubData( 154 GL_PIXEL_UNPACK_BUFFER ,144 GL_PIXEL_UNPACK_BUFFER_ARB, 155 145 (self._num_frames-self._frame_ptr-1)*self._fft_size*4, 156 146 len(data), data, 157 147 ) 158 glBindBuffer(GL_PIXEL_UNPACK_BUFFER , self._waterfall_buffer_bottom)148 glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, self._waterfall_buffer_bottom) 159 149 glBufferSubData( 160 GL_PIXEL_UNPACK_BUFFER ,150 GL_PIXEL_UNPACK_BUFFER_ARB, 161 151 self._frame_ptr*self._fft_size*4, 162 152 len(data), data, 163 153 ) 164 glBindBuffer(GL_PIXEL_UNPACK_BUFFER , 0) #unbind154 glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0) #unbind 165 155 #increment the pointer 166 156 self._frame_ptr = (self._frame_ptr + 1)%self._num_frames
