[Yt-svn] yt: 2 new changesets
hg at spacepope.org
hg at spacepope.org
Wed May 26 14:55:08 PDT 2010
hg Repository: yt
details: yt/rev/c613dab051c9
changeset: 1702:c613dab051c9
user: Matthew Turk <matthewturk at gmail.com>
date:
Sun May 23 12:39:58 2010 -0700
description:
Updates to the OpenGL viewer, to abstract out a bit of the camera handling and
keypress events
hg Repository: yt
details: yt/rev/7d0aba88a756
changeset: 1703:7d0aba88a756
user: Matthew Turk <matthewturk at gmail.com>
date:
Wed May 26 14:54:56 2010 -0700
description:
Fixed an off-by-one with the volume renderer. This should get rid of a lot of
the waffling previously seen.
diffstat:
yt/_amr_utils/VolumeIntegrator.pyx | 8 +-
yt/extensions/opengl_image_viewer.py | 96 +++++++++++++++++--------------
2 files changed, 58 insertions(+), 46 deletions(-)
diffs (163 lines):
diff -r 81e8e9eef5cc -r 7d0aba88a756 yt/_amr_utils/VolumeIntegrator.pyx
--- a/yt/_amr_utils/VolumeIntegrator.pyx Sun May 23 12:36:11 2010 -0700
+++ b/yt/_amr_utils/VolumeIntegrator.pyx Wed May 26 14:54:56 2010 -0700
@@ -497,19 +497,21 @@
cdef np.float64_t grad[3], ds[3]
grad[0] = grad[1] = grad[2] = 0.0
cdef int dti, i
- dt = (exit_t - enter_t) / (tf.ns) # 4 samples should be dt=0.25
+ dt = (exit_t - enter_t) / tf.ns # 4 samples should be dt=0.25
for i in range(3):
+ # temp is the left edge of the current cell
temp = ci[i] * self.dds[i] + self.left_edge[i]
+ # this gets us dp as the current first sample position
dp[i] = (enter_t + 0.5 * dt) * v_dir[i] + v_pos[i] - temp
dp[i] *= self.idds[i]
ds[i] = v_dir[i] * self.idds[i] * dt
for dti in range(tf.ns):
- for i in range(3):
- dp[i] += ds[i]
for i in range(self.n_fields):
self.dvs[i] = trilinear_interpolate(self.dims, ci, dp, self.data[i])
#if (dv < tf.x_bounds[0]) or (dv > tf.x_bounds[1]):
# continue
+ for i in range(3):
+ dp[i] += ds[i]
tf.eval_transfer(dt, self.dvs, rgba, grad)
cdef class GridFace:
diff -r 81e8e9eef5cc -r 7d0aba88a756 yt/extensions/opengl_image_viewer.py
--- a/yt/extensions/opengl_image_viewer.py Sun May 23 12:36:11 2010 -0700
+++ b/yt/extensions/opengl_image_viewer.py Wed May 26 14:54:56 2010 -0700
@@ -35,6 +35,37 @@
ESCAPE = '\033'
+class ViewHandler3D(object):
+ def __init__(self, scene):
+ # We
+ self.scene = scene
+ self.dispatch_table = dict(
+ q = (scene.translate, (1, 1.0)),
+ e = (scene.translate, (1, -1.0)),
+ w = (scene.translate, (2, 1.0)),
+ s = (scene.translate, (2, -1.0)),
+ a = (scene.translate, (0, 1.0)),
+ d = (scene.translate, (0, -1.0)),
+
+ Q = (scene.rotate, (1, 1.0)),
+ E = (scene.rotate, (1, -1.0)),
+ W = (scene.rotate, (2, 1.0)),
+ S = (scene.rotate, (2, -1.0)),
+ A = (scene.rotate, (0, 1.0)),
+ D = (scene.rotate, (0, -1.0)),
+
+ ESCAPE = (sys.exit, (0,))
+ )
+
+ def __call__(self, *args):
+ # We set up our standard handlers, and then anything additional can get
+ # called if none of our dispatch mechanisms work.
+ if args[0] in self.dispatch_table:
+ func, args = self.dispatch_table[args[0]]
+ func(*args)
+ # always draw when handling a keypress, even if it's one time too many
+ self.scene.draw()
+
class GenericGLUTScene(object):
def __init__(self, width, height):
@@ -415,6 +446,9 @@
self.mi, self.ma = 1e30, -1e30
self.pf = pf
self.coord = 0.0
+ self.tfac = 10.0
+ self.rfac = 0.5
+ self._setup_keypress_handler()
GenericGLUTScene.__init__(self, 800, 800)
num = len(pf.h.grids) * 6 * 4
@@ -423,8 +457,9 @@
self.vertices = vbo.VBO(self.v)
self.ng = len(pf.h.grids)
- self.ox = self.oy = self.rx = self.ry = self.rz = 0
- self.oz = -2
+ self.position = na.zeros(3, dtype='float')
+ self.rotation = na.zeros(3, dtype='float')
+ self.position[2] = -2 # Offset backwards a bit
self._setup_grids()
@@ -486,10 +521,10 @@
GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE)
GL.glLoadIdentity()
- GL.glTranslatef(self.ox, self.oy, self.oz)
- GL.glRotatef(self.rx, 0, 0, 1)
- GL.glRotatef(self.ry, 0, 1, 0)
- GL.glRotatef(self.rz, 1, 0, 0)
+ GL.glTranslatef(*self.position)
+ GL.glRotatef(self.rotation[0], 0, 0, 1)
+ GL.glRotatef(self.rotation[1], 0, 1, 0)
+ GL.glRotatef(self.rotation[2], 1, 0, 0)
self.vertices.bind()
GL.glColor3f(0.0, 0.0, 0.0)
@@ -550,44 +585,19 @@
def move_slice(self, value):
self.coord += value
+
+ def rotate(self, axis, value):
+ self.rotation[axis] += value/self.rfac
+
+ def translate(self, axis, value):
+ self.position[axis] += value/self.tfac
- def keypress_handler(self, *args):
- tfac = 10.0
- rfac = 0.5
- if args[0] == ESCAPE:
- sys.exit()
- elif args[0] == 'a':
- self.ox += 1.0/tfac
- elif args[0] == 'd':
- self.ox -= 1.0/tfac
- elif args[0] == 's':
- self.oz -= 1.0/tfac
- elif args[0] == 'w':
- self.oz += 1.0/tfac
- elif args[0] == 'q':
- self.oy -= 1.0/tfac
- elif args[0] == 'e':
- self.oy += 1.0/tfac
- # Now, rotations
- elif args[0] == 'A':
- self.rx -= 1.0/rfac
- elif args[0] == 'D':
- self.rx += 1.0/rfac
- elif args[0] == 'S':
- self.rz -= 1.0/rfac
- elif args[0] == 'W':
- self.rz += 1.0/rfac
- elif args[0] == 'Q':
- self.ry -= 1.0/rfac
- elif args[0] == 'E':
- self.ry += 1.0/rfac
- elif args[0] == 'y':
- self.move_slice(0.05)
- elif args[0] == 'h':
- self.move_slice(-0.05)
- else:
- return
- self.draw()
+ def _setup_keypress_handler(self):
+ self.keypress_handler = ViewHandler3D(self)
+ self.keypress_handler.dispatch_table.update(dict(
+ y = (self.move_slice, ( 0.05,)),
+ h = (self.move_slice, (-0.05,))
+ ))
if __name__ == "__main__":
if sys.argv[-2] == '-g':
More information about the yt-svn
mailing list