[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r9153 - in gnuradio/branches/features/experimental-gui
From: |
jblum |
Subject: |
[Commit-gnuradio] r9153 - in gnuradio/branches/features/experimental-gui: . plotter |
Date: |
Sat, 2 Aug 2008 18:24:40 -0600 (MDT) |
Author: jblum
Date: 2008-08-02 18:24:38 -0600 (Sat, 02 Aug 2008)
New Revision: 9153
Modified:
gnuradio/branches/features/experimental-gui/plotter/plotter_base.py
gnuradio/branches/features/experimental-gui/plotter/waterfall_plotter.py
gnuradio/branches/features/experimental-gui/waterfall_window.py
Log:
waterfall: color scale work, more callbacks
Modified: gnuradio/branches/features/experimental-gui/plotter/plotter_base.py
===================================================================
--- gnuradio/branches/features/experimental-gui/plotter/plotter_base.py
2008-08-02 18:35:13 UTC (rev 9152)
+++ gnuradio/branches/features/experimental-gui/plotter/plotter_base.py
2008-08-03 00:24:38 UTC (rev 9153)
@@ -289,7 +289,7 @@
glVertex3f(*coor2)
glEnd()
- def _draw_rect(self, x, y, width, height):
+ def _draw_rect(self, x, y, width, height, fill=True):
"""!
Draw a rectangle on the x, y plane.
X and Y are the top-left corner.
@@ -297,10 +297,11 @@
@param y the top position of the rectangle
@param width the width of the rectangle
@param height the height of the rectangle
+ @param fill true to color inside of rectangle
"""
- glBegin(GL_QUADS)
- glVertex3f(x, y, 0)
- glVertex3f(x+width, y, 0)
- glVertex3f(x+width, y+height, 0)
- glVertex3f(x, y+height, 0)
+ glBegin(fill and GL_QUADS or GL_LINE_LOOP)
+ glVertex2f(x, y)
+ glVertex2f(x+width, y)
+ glVertex2f(x+width, y+height)
+ glVertex2f(x, y+height)
glEnd()
Modified:
gnuradio/branches/features/experimental-gui/plotter/waterfall_plotter.py
===================================================================
--- gnuradio/branches/features/experimental-gui/plotter/waterfall_plotter.py
2008-08-02 18:35:13 UTC (rev 9152)
+++ gnuradio/branches/features/experimental-gui/plotter/waterfall_plotter.py
2008-08-03 00:24:38 UTC (rev 9153)
@@ -30,10 +30,17 @@
LEGEND_NUM_BLOCKS = 10
LEGEND_BLOCK_WIDTH = 8
LEGEND_FONT_SIZE = 8
+LEGEND_BORDER_COLOR_SPEC = (0, 0, 0) #black
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)]
+_RGB_ARRAY = \
+ [numpy.array((0, 2*i, 255 - 2*i, 0), numpy.uint8) for i in range(0,
128)] + \
+ [numpy.array((2*i - 255, 511 - 2*i, 0, 0), numpy.uint8) for i in
range(128, 256)]
+_GRAY_ARRAY = \
+ [numpy.array((i, i, i, 0), numpy.uint8) for i in range(0, 256)]
+COLOR_ARRAY = {
+ 'rgb': _RGB_ARRAY,
+ 'gray': _GRAY_ARRAY,
+}
##################################################
# Waterfall Plotter
@@ -48,9 +55,10 @@
self._minimum = 0
self._maximum = 0
self._fft_size = 0
- self._num_lines = 0
self._buffer = ''
self._counter = 0
+ self.set_num_lines(0)
+ self.set_color_mode(COLOR_ARRAY.keys()[0])
def _gl_init(self):
"""!
@@ -98,30 +106,64 @@
"""!
Draw the color scale legend.
"""
+ if not self._color_mode: return
block_height =
float(self.height-self.padding_top-self.padding_bottom)/LEGEND_NUM_BLOCKS
+ x = self.width-self.padding_right + LEGEND_LEFT_PAD
#draw each legend block
for i in range(LEGEND_NUM_BLOCKS):
proportion = i/float(LEGEND_NUM_BLOCKS-1)
dB = proportion*(self._maximum - self._minimum) +
self._minimum
- color = RGBA_ARRAY[int(255*proportion)]
+ color =
COLOR_ARRAY[self._color_mode][int(255*proportion)]
glColor4f(*map(lambda c: c/255.0, color))
#coordinates
- x = self.width-self.padding_right + LEGEND_LEFT_PAD
y = self.height - (i+1)*block_height -
self.padding_bottom
#block
self._draw_rect(x, y, LEGEND_BLOCK_WIDTH, block_height)
#block label
txt = gltext.Text('%ddB'%int(dB),
font_size=LEGEND_FONT_SIZE)
txt.draw_text(wx.Point(x+LEGEND_BLOCK_WIDTH+LEGEND_RIGHT_PAD, y+block_height/4))
+ #draw rectangle around color scale border
+ glColor3f(*LEGEND_BORDER_COLOR_SPEC)
+ self._draw_rect(x, self.padding_top, LEGEND_BLOCK_WIDTH,
LEGEND_NUM_BLOCKS*block_height, fill=False)
- def set_samples(self, samples, minimum, maximum, num_lines):
+ def _resize_buffer(self):
"""!
+ Resize the buffer to fit the fft_size X num_lines.
+ If the buffer is too large, set samples will auto shrink.
+ """
+ self._buffer = self._buffer +
numpy.zeros(self._num_lines*self._fft_size*4, numpy.uint8).tostring()
+
+ def set_color_mode(self, color_mode):
+ """!
+ Set the color mode.
+ New samples will be converted to the new color mode.
+ Old samples will not be recolorized.
+ @param color_mode the new color mode string
+ """
+ self.semaphore.acquire(True)
+ if color_mode in COLOR_ARRAY.keys():
+ self._color_mode = color_mode
+ self.changed(True)
+ self.semaphore.release()
+
+ def set_num_lines(self, num_lines):
+ """!
+ Set number of lines.
+ The buffer will be resized accordingly.
+ @param num_lines the new number of lines
+ """
+ self.semaphore.acquire(True)
+ self._num_lines = num_lines
+ self._resize_buffer()
+ self.semaphore.release()
+
+ def set_samples(self, samples, minimum, maximum):
+ """!
Set the samples to the waterfall.
Convert the samples to color data.
@param samples the array of floats
@param minimum the minimum value to scale
@param maximum the maximum value to scale
- @param num_lines the number of lines
"""
self.semaphore.acquire(True)
#set the min, max values
@@ -129,17 +171,17 @@
self._minimum = minimum
self._maximum = maximum
self.changed(True)
- if self._fft_size != len(samples) or self._num_lines !=
num_lines:
+ if self._fft_size != len(samples):
self._fft_size = len(samples)
- self._num_lines = num_lines
- self._buffer = self._buffer +
numpy.zeros(self._num_lines*self._fft_size*4, numpy.uint8).tostring()
- self.changed(True)
+ self._resize_buffer()
#normalize the samples to min/max
samples = (samples - minimum)*float(255/(maximum-minimum))
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()
+ #convert the samples to RGBA data
+ color_array = COLOR_ARRAY[self._color_mode]
+ data = numpy.array([color_array[sample] for sample in
samples]).tostring()
self._buffer = (data +
self._buffer)[:self._num_lines*self._fft_size*4]
#selective update, dont update for sub-pixel counts
if self._counter == 0: self.update()
Modified: gnuradio/branches/features/experimental-gui/waterfall_window.py
===================================================================
--- gnuradio/branches/features/experimental-gui/waterfall_window.py
2008-08-02 18:35:13 UTC (rev 9152)
+++ gnuradio/branches/features/experimental-gui/waterfall_window.py
2008-08-03 00:24:38 UTC (rev 9153)
@@ -39,12 +39,17 @@
DIV_LEVELS = (1, 2, 5, 10, 20)
MIN_NUM_LINES, MAX_NUM_LINES = 10, 1000
MIN_DYNAMIC_RANGE, MAX_DYNAMIC_RANGE = 10, 200
+COLOR_MODES = (
+ ('RGB', 'rgb'),
+ ('Gray', 'gray'),
+)
DYNAMIC_RANGE_KEY = 'dynamic_range'
NUM_LINES_KEY = 'num_lines'
Y_DIVS_KEY = 'y_divs'
X_DIVS_KEY = 'x_divs'
REF_LEVEL_KEY = 'ref_level'
BASEBAND_FREQ_KEY = 'baseband_freq'
+COLOR_MODE_KEY = 'color_mode'
RUNNING_KEY = 'running'
##################################################
@@ -76,6 +81,10 @@
)
parent.ext_controller.add_listener(parent.average_key,
self.avg_alpha_slider.Enable)
control_box.Add(self.avg_alpha_slider, 0, wx.EXPAND)
+ #color mode
+ control_box.AddStretchSpacer()
+ self.color_mode_chooser = common.DropDownController(self,
'Color', COLOR_MODES, parent.controller, COLOR_MODE_KEY)
+ control_box.Add(self.color_mode_chooser, 0, wx.EXPAND)
#dyanmic range buttons
control_box.AddStretchSpacer()
control_box.Add(common.LabelText(self, 'Dynamic Range'), 0,
wx.ALIGN_CENTER)
@@ -90,7 +99,7 @@
control_box.Add(self._ref_lvl_buttons, 0, wx.ALIGN_CENTER)
#num lines buttons
control_box.AddStretchSpacer()
- control_box.Add(common.LabelText(self, 'Set Num Lines'), 0,
wx.ALIGN_CENTER)
+ control_box.Add(common.LabelText(self, 'Set Time Scale'), 0,
wx.ALIGN_CENTER)
control_box.AddSpacer(2)
self._num_lines_buttons = common.IncrDecrButtons(self,
self._on_incr_num_lines, self._on_decr_num_lines)
control_box.Add(self._num_lines_buttons, 0, wx.ALIGN_CENTER)
@@ -118,10 +127,10 @@
self.parent.controller[REF_LEVEL_KEY] -
self.parent.controller[DYNAMIC_RANGE_KEY]/10)
def _on_incr_num_lines(self, event):
self.parent.set_num_lines(
- min(self.parent.controller[NUM_LINES_KEY]+10,
MAX_NUM_LINES))
+
min(self.parent.controller[NUM_LINES_KEY]+self.parent.controller[NUM_LINES_KEY]/10,
MAX_NUM_LINES))
def _on_decr_num_lines(self, event):
self.parent.set_num_lines(
- max(self.parent.controller[NUM_LINES_KEY]-10,
MIN_NUM_LINES))
+
max(self.parent.controller[NUM_LINES_KEY]-self.parent.controller[NUM_LINES_KEY]/10,
MIN_NUM_LINES))
##################################################
# Waterfall window with plotter and control panel
@@ -164,15 +173,19 @@
main_box.Add(self.plotter, 1, wx.EXPAND)
main_box.Add(self.control_panel, 0, wx.EXPAND)
self.SetSizerAndFit(main_box)
+ #plotter listeners
+ self.controller.add_listener(COLOR_MODE_KEY,
self.plotter.set_color_mode)
+ self.controller.add_listener(NUM_LINES_KEY,
self.plotter.set_num_lines)
#initial setup
self.ext_controller[self.average_key] =
self.ext_controller[self.average_key]
self.ext_controller[self.avg_alpha_key] =
self.ext_controller[self.avg_alpha_key]
self._register_set_prop(self.controller, DYNAMIC_RANGE_KEY,
dynamic_range)
self._register_set_prop(self.controller, NUM_LINES_KEY, 256)
- self._register_set_prop(self.controller, Y_DIVS_KEY, 10)
+ self._register_set_prop(self.controller, Y_DIVS_KEY, 8)
self._register_set_prop(self.controller, X_DIVS_KEY, 8)
#approximate
self._register_set_prop(self.controller, REF_LEVEL_KEY,
ref_level)
self._register_set_prop(self.controller, BASEBAND_FREQ_KEY,
baseband_freq)
+ self._register_set_prop(self.controller, COLOR_MODE_KEY, 'rgb')
self._register_set_prop(self.controller, RUNNING_KEY, True)
#register events
self.ext_controller.add_listener(msg_key, self.handle_msg)
@@ -202,10 +215,9 @@
else: samples = numpy.concatenate((samples[num_samps/2+1:],
samples[:num_samps/2]))
#plot the fft
self.plotter.set_samples(
- samples,
- self.controller[REF_LEVEL_KEY],
- self.controller[DYNAMIC_RANGE_KEY] +
self.controller[REF_LEVEL_KEY],
- self.controller[NUM_LINES_KEY],
+ samples=samples,
+ minimum=self.controller[REF_LEVEL_KEY],
+ maximum=self.controller[DYNAMIC_RANGE_KEY] +
self.controller[REF_LEVEL_KEY],
)
def update_grid(self, *args):
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r9153 - in gnuradio/branches/features/experimental-gui: . plotter,
jblum <=