Commit 2efae2161771ab70db9e355726936b3256f7fb96

  • avatar
  • MichaƂ Januszewski <spock @gen…oo.org>
  • Wed Feb 10 10:36:04 CET 2010
Make it possible to change colormaps on the fly.
  
3232 glDepthFunc(GL_LEQUAL)
3333 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
3434
35def _vis_rgb(v):
36 r = numpy.sqrt(v)
37 g = numpy.power(v, 3)
38 b = numpy.sin(v * math.pi)
39 return numpy.vstack((r,g,b))
40
41def _vis_scl(v):
42 col = numpy.zeros((3, len(v)), dtype=numpy.float32)
43 col[1,:] = v
44 return col
45
46colormaps = {
47 'rgb': _vis_rgb,
48 'scl': _vis_scl,
49 }
50
3551class FluidSurfaceVis(object):
3652 display_flags = pygame.OPENGL | pygame.DOUBLEBUF | pygame.RESIZABLE
3753 display_depth = 24
8686 self._paused = False
8787 self._reset()
8888
89 self._minh = -0.2
90 self._maxh = 0.2
89 self._colormap = colormaps.keys()[0]
90 self._minh = -0.1
91 self._maxh = 0.1
9192
9293 pygame.key.set_repeat(100,50)
9394
141141 res = numpy.dstack((a, b, c, d))
142142 vtx = numpy.ravel(res)
143143
144 col = numpy.zeros((3, self.mesh_n), dtype=numpy.float32)
145144 min_ = numpy.min(mesh_z)
146145 max_ = numpy.max(mesh_z)
147146
148147 self._minh = min(self._minh, numpy.min(mesh_z))
149148 self._maxh = max(self._maxh, numpy.max(mesh_z))
150149
151 tmp = vtx[2::3]
152 col[1,:] = (tmp[:]-self._minh)/(self._maxh-self._minh)
150 col = colormaps[self._colormap]((vtx[2::3]-self._minh)/(self._maxh-self._minh))
153151 col = numpy.ravel(numpy.transpose(col))
154152
155153 vtx.shape = (self.mesh_n, 3)
189189 self.display_flags, self.display_depth)
190190 _GL_resize(*event.size)
191191 elif event.type == pygame.MOUSEBUTTONDOWN:
192 if event.button == 4:
192 if event.button == 5:
193193 self._zoom -= 0.05
194 elif event.button == 5:
194 elif event.button == 4:
195195 self._zoom += 0.05
196196 elif event.type == pygame.KEYDOWN:
197197 if event.key == pygame.K_v:
249249 self._angle_z += 3.0
250250 else:
251251 self._angle_z += 1.0
252 elif event.key == pygame.K_c:
253 idx = colormaps.keys().index(self._colormap) + 1
254 idx %= len(colormaps.keys())
255 self._colormap = colormaps.keys()[idx]
252256
253257 def main(self):
254258 t_prev = time.time()