[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r9167 - in gnuradio/branches/features/experimental-gui
From: |
jblum |
Subject: |
[Commit-gnuradio] r9167 - in gnuradio/branches/features/experimental-gui: . plotter |
Date: |
Mon, 4 Aug 2008 03:11:29 -0600 (MDT) |
Author: jblum
Date: 2008-08-04 03:11:28 -0600 (Mon, 04 Aug 2008)
New Revision: 9167
Modified:
gnuradio/branches/features/experimental-gui/plotter/waterfall_plotter.py
gnuradio/branches/features/experimental-gui/waterfall_window.py
Log:
experimenting with color maps
Modified:
gnuradio/branches/features/experimental-gui/plotter/waterfall_plotter.py
===================================================================
--- gnuradio/branches/features/experimental-gui/plotter/waterfall_plotter.py
2008-08-04 06:36:48 UTC (rev 9166)
+++ gnuradio/branches/features/experimental-gui/plotter/waterfall_plotter.py
2008-08-04 09:11:28 UTC (rev 9167)
@@ -27,19 +27,54 @@
LEGEND_LEFT_PAD = 7
LEGEND_RIGHT_PAD = 3
-LEGEND_NUM_BLOCKS = 10
-LEGEND_BLOCK_WIDTH = 8
+LEGEND_NUM_BLOCKS = 256
+LEGEND_NUM_LABELS = 8
+LEGEND_WIDTH = 8
LEGEND_FONT_SIZE = 8
LEGEND_BORDER_COLOR_SPEC = (0, 0, 0) #black
PADDING = 35, 60, 40, 60 #top, right, bottom, left
-_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,
+
+def _get_rbga(red_pts, green_pts, blue_pts, alpha_pts):
+ """!
+ Get an array of 256 rgba values where each index maps to a color.
+ The scaling for red, green, blue, alpha are specified in piece-wise
functions.
+ The piece-wise functions consist of a set of x, y coordinates.
+ The x and y values of the coordinates range from 0 to 1.
+ The coordinates must be specified so that x increases with the index
value.
+ Resulting values are calculated along the line formed between 2
coordinates.
+ @return array of rbga values (4 bytes) each
+ """
+ def _fcn(x, pw):
+ for (x1, y1), (x2, y2) in zip(pw, pw[1:]):
+ m = float(y1 - y2)/(x1 - x2)
+ b = y1 - m*x1
+ if x <= x2: return m*x + b
+ raise Exception
+ return [numpy.array(map(
+ lambda pw: int(255*_fcn(i/255.0, pw)),
+ (red_pts, green_pts, blue_pts, alpha_pts),
+ ), numpy.uint8) for i in range(0, 256)
+ ]
+
+COLORS = {
+ 'rgb1': _get_rbga(
#http://www.ks.uiuc.edu/Research/vmd/vmd-1.7.1/ug/img47.gif
+ red_pts = [(0, 0), (.5, 0), (1, 1)],
+ green_pts = [(0, 0), (.5, 1), (1, 0)],
+ blue_pts = [(0, 1), (.5, 0), (1, 0)],
+ alpha_pts = [(0, 0), (1, 0)],
+ ),
+ 'rgb2': _get_rbga(
#http://xtide.ldeo.columbia.edu/~krahmann/coledit/screen.jpg
+ red_pts = [(0, 0), (3.0/8, 0), (5.0/8, 1), (7.0/8, 1), (1, .5)],
+ green_pts = [(0, 0), (1.0/8, 0), (3.0/8, 1), (5.0/8, 1),
(7.0/8, 0), (1, 0)],
+ blue_pts = [(0, .5), (1.0/8, 1), (3.0/8, 1), (5.0/8, 0), (1,
0)],
+ alpha_pts = [(0, 0), (1, 0)],
+ ),
+ 'gray': _get_rbga(
+ red_pts = [(0, 0), (1, 1)],
+ green_pts = [(0, 0), (1, 1)],
+ blue_pts = [(0, 0), (1, 1)],
+ alpha_pts = [(0, 0), (1, 0)],
+ ),
}
##################################################
@@ -58,7 +93,7 @@
self._buffer = ''
self._counter = 0
self.set_num_lines(0)
- self.set_color_mode(COLOR_ARRAY.keys()[0])
+ self.set_color_mode(COLORS.keys()[0])
def _gl_init(self):
"""!
@@ -107,24 +142,26 @@
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
+ legend_height = self.height-self.padding_top-self.padding_bottom
+ block_height = float(legend_height)/LEGEND_NUM_BLOCKS
+ label_spacing = float(legend_height)/(LEGEND_NUM_LABELS-1)
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 =
COLOR_ARRAY[self._color_mode][int(255*proportion)]
+ color =
COLORS[self._color_mode][int(255*i/float(LEGEND_NUM_BLOCKS-1))]
glColor4f(*map(lambda c: c/255.0, color))
- #coordinates
y = self.height - (i+1)*block_height -
self.padding_bottom
- #block
- self._draw_rect(x, y, LEGEND_BLOCK_WIDTH, block_height)
- #block label
+ self._draw_rect(x, y, LEGEND_WIDTH, block_height)
+ #draw each legend label
+ for i in range(LEGEND_NUM_LABELS):
+ proportion = i/float(LEGEND_NUM_LABELS-1)
+ dB = proportion*(self._maximum - self._minimum) +
self._minimum
+ y = self.height - i*label_spacing - self.padding_bottom
- label_spacing/4
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))
+ txt.draw_text(wx.Point(x+LEGEND_WIDTH+LEGEND_RIGHT_PAD,
y))
#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)
+ self._draw_rect(x, self.padding_top, LEGEND_WIDTH,
legend_height, fill=False)
def _resize_buffer(self):
"""!
@@ -141,7 +178,7 @@
@param color_mode the new color mode string
"""
self.semaphore.acquire(True)
- if color_mode in COLOR_ARRAY.keys():
+ if color_mode in COLORS.keys():
self._color_mode = color_mode
self.changed(True)
self.semaphore.release()
@@ -173,6 +210,7 @@
self.changed(True)
if self._fft_size != len(samples):
self._fft_size = len(samples)
+ self._buffer = '' #empty buffer before resize
self._resize_buffer()
#normalize the samples to min/max
samples = (samples - minimum)*float(255/(maximum-minimum))
@@ -180,7 +218,7 @@
samples = numpy.maximum(samples, 0) #clip
samples = numpy.array(samples, numpy.uint8)
#convert the samples to RGBA data
- color_array = COLOR_ARRAY[self._color_mode]
+ color_array = COLORS[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
Modified: gnuradio/branches/features/experimental-gui/waterfall_window.py
===================================================================
--- gnuradio/branches/features/experimental-gui/waterfall_window.py
2008-08-04 06:36:48 UTC (rev 9166)
+++ gnuradio/branches/features/experimental-gui/waterfall_window.py
2008-08-04 09:11:28 UTC (rev 9167)
@@ -40,7 +40,8 @@
MIN_NUM_LINES, MAX_NUM_LINES = 10, 1000
MIN_DYNAMIC_RANGE, MAX_DYNAMIC_RANGE = 10, 200
COLOR_MODES = (
- ('RGB', 'rgb'),
+ ('RGB1', 'rgb1'),
+ ('RGB2', 'rgb2'),
('Gray', 'gray'),
)
DYNAMIC_RANGE_KEY = 'dynamic_range'
@@ -185,7 +186,7 @@
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, COLOR_MODE_KEY,
COLOR_MODES[0][1])
self._register_set_prop(self.controller, RUNNING_KEY, True)
#register events
self.ext_controller.subscribe(msg_key, self.handle_msg)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r9167 - in gnuradio/branches/features/experimental-gui: . plotter,
jblum <=