[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8771 - gnuradio/branches/developers/jblum/gr-wxglgui/
From: |
jblum |
Subject: |
[Commit-gnuradio] r8771 - gnuradio/branches/developers/jblum/gr-wxglgui/src/python |
Date: |
Wed, 2 Jul 2008 01:18:07 -0600 (MDT) |
Author: jblum
Date: 2008-07-02 01:18:06 -0600 (Wed, 02 Jul 2008)
New Revision: 8771
Modified:
gnuradio/branches/developers/jblum/gr-wxglgui/src/python/plotter.py
Log:
matrix translation
Modified: gnuradio/branches/developers/jblum/gr-wxglgui/src/python/plotter.py
===================================================================
--- gnuradio/branches/developers/jblum/gr-wxglgui/src/python/plotter.py
2008-07-02 00:13:18 UTC (rev 8770)
+++ gnuradio/branches/developers/jblum/gr-wxglgui/src/python/plotter.py
2008-07-02 07:18:06 UTC (rev 8771)
@@ -22,8 +22,6 @@
import wx
import wx.glcanvas
-from OpenGL.GLUT import *
-from OpenGL.GLU import *
from OpenGL.GL import *
import threading
@@ -46,7 +44,7 @@
Plotter base class for all plot types.
"""
- def __init__(self, parent):
+ def __init__(self, parent):
"""!
Create a new plotter base.
Initialize GL and register events.
@@ -73,7 +71,6 @@
self.SetCurrent()
#check if gl was initialized
if not self._gl_init_flag:
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
glClearColor(*BACKGROUND_COLOR_SPEC)
glEnableClientState(GL_VERTEX_ARRAY)
self._gl_init_flag = True
@@ -83,16 +80,16 @@
glViewport(0, 0, self.width, self.height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
- glOrtho(0, self.width, self.height, 0, 1, 0)
+ glOrtho(0, self.width, self.height, 0, 1, 0)
glMatrixMode(GL_MODELVIEW)
- glLoadIdentity()
- self._resized_flag = False
- self._changed = True
+ glLoadIdentity()
+ self._resized_flag = False
+ self._changed = True
self.draw()
def update(self): wx.PostEvent(self, wx.PaintEvent())
- def clear(self): glClear(GL_COLOR_BUFFER_BIT)
+ def clear(self): glClear(GL_COLOR_BUFFER_BIT)
class grid_plotter(_plotter_base):
@@ -102,17 +99,17 @@
"""
self.semaphore = threading.Semaphore(1)
self.grid_compiled_list_id = wx.NewId()
- self.channels = dict()
+ self.channels = dict()
#store title and unit strings
self.set_legend(False)
self.set_title('Title')
- self.set_x_units('X Units (xx)')
+ self.set_x_units('X Units (xx)')
self.set_y_units('Y Units (yy)')
- #store padding
+ #store padding
self.padding_top, self.padding_right, self.padding_bottom,
self.padding_left = PADDING
- #init the grid to some value
- self.set_x_grid(-1, 1, 1)
- self.set_y_grid(-1, 1, 1)
+ #init the grid to some value
+ self.set_x_grid(-1, 1, 1)
+ self.set_y_grid(-1, 1, 1)
_plotter_base.__init__(self, parent)
def set_legend(self, legend):
@@ -123,7 +120,7 @@
self.semaphore.acquire(True)
self.legend = legend
self._changed = True
- self.semaphore.release()
+ self.semaphore.release()
def set_title(self, title):
"""!
@@ -213,22 +210,32 @@
for channel in reversed(sorted(self.channels.keys())):
samples, color_spec, marker = self.channels[channel]
num_samps = len(samples)
- #use numpy to scale the waveform
- x_scalar =
(self.width-self.padding_left-self.padding_right)
+ #use opengl to scale the waveform
+ glPushMatrix()
+ glTranslated(self.padding_left, self.padding_top, 0)
+ glScaled(
+
(self.width-self.padding_left-self.padding_right),
+
(self.height-self.padding_top-self.padding_bottom),
+ 1,
+ )
+ glTranslated(0, 1, 0)
if isinstance(samples, tuple):
- x_arr = x_scalar*(samples[0] -
self.x_min)/(self.x_max-self.x_min) + self.padding_left
- samples = samples[1]
+ x_arr, y_arr = samples
+ glScaled(1.0/(self.x_max-self.x_min),
-1.0/(self.y_max-self.y_min), 1)
+ glTranslated(-self.x_min, -self.y_min, 0)
else:
- x_arr = x_scalar*numpy.arange(0,
num_samps)/float(num_samps-1) + self.padding_left
- y_scalar =
(self.height-self.padding_top-self.padding_bottom)
- y_arr = y_scalar*(1 - (numpy.array(samples) -
self.y_min)/(self.y_max-self.y_min)) + self.padding_top
- #draw the points/lines
+ x_arr = numpy.arange(0, num_samps)
+ y_arr = samples
+ glScaled(1.0/(num_samps-1),
-1.0/(self.y_max-self.y_min), 1)
+ glTranslated(0, -self.y_min, 0)
+ #draw the points/lines
glColor3f(*color_spec)
- points = zip(x_arr, y_arr)
- if marker == '+':
- points = numpy.concatenate([((x, y+4), (x,
y-4), (x+4, y), (x-4, y)) for x, y in points])
+ points = zip(x_arr, y_arr)
+ #if marker == '+': #TODO make a texture?
+ # points = numpy.concatenate([((x, y+4), (x,
y-4), (x+4, y), (x-4, y)) for x, y in points])
glVertexPointer(2, GL_FLOAT, 0, points)
glDrawArrays({None: GL_LINE_STRIP, '.': GL_POINTS, '+':
GL_LINES}[marker], 0, len(points))
+ glPopMatrix()
def _draw_grid(self):
"""!
@@ -265,7 +272,7 @@
self._draw_line(
(scaled_tick, self.padding_top, 0),
(scaled_tick, self.height-self.padding_bottom,
0),
- )
+ )
self._draw_tick_label(tick, (scaled_tick,
self.height-.75*self.padding_bottom))
##################################################
@@ -278,7 +285,7 @@
self._draw_line(
(self.padding_left, scaled_tick, 0),
(self.width-self.padding_right, scaled_tick,
0),
- )
+ )
self._draw_tick_label(tick, (.75*self.padding_left,
scaled_tick))
##################################################
@@ -317,7 +324,7 @@
for i, channel in
enumerate(sorted(self.channels.keys())):
x_off =
1.1*LEGEND_BOX_WIDTH*(len(self.channels) - i - 1) + LEGEND_BOX_WIDTH/2
color_spec = self.channels[channel][1]
- #draw colored rectangle
+ #draw colored rectangle
glColor3f(*color_spec)
self._draw_rect(
self.width - self.padding_right - x_off
- LEGEND_BOX_WIDTH/2,
@@ -327,7 +334,7 @@
)
#draw label text
txt = gltext.Text('Ch%s'%channel,
font_size=LEGEND_TEXT_FONT_SIZE, centered=True)
- txt.draw_text(wx.Point(self.width -
self.padding_right - x_off, self.padding_top/2.0))
+ txt.draw_text(wx.Point(self.width -
self.padding_right - x_off, self.padding_top/2.0))
def _draw_tick_label(self, tick, coor):
"""!
@@ -341,7 +348,7 @@
base = int(tick/10**exp)
if abs(exp) >= 3: tick_str = '%de%d'%(base, exp)
else: tick_str = '%g'%tick
- #draw
+ #draw
txt = gltext.Text(tick_str, font_size=TICK_TEXT_FONT_SIZE,
centered=True)
txt.draw_text(wx.Point(*coor))
@@ -409,12 +416,12 @@
vbox = wx.BoxSizer(wx.VERTICAL)
plotter = grid_plotter(frame)
- plotter.set_x_grid(-1, 1, .2)
+ plotter.set_x_grid(-1, 1, .2)
plotter.set_y_grid(-1, 1, .4)
vbox.Add(plotter, 1, wx.EXPAND)
plotter = grid_plotter(frame)
- plotter.set_x_grid(-1, 1, .2)
+ plotter.set_x_grid(-1, 1, .2)
plotter.set_y_grid(-1, 1, .4)
vbox.Add(plotter, 1, wx.EXPAND)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r8771 - gnuradio/branches/developers/jblum/gr-wxglgui/src/python,
jblum <=