summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony LaTorre <tlatorre9@gmail.com>2011-08-08 14:43:19 -0400
committerAnthony LaTorre <tlatorre9@gmail.com>2011-08-08 14:43:19 -0400
commited642493fccbcf13efef5491f73241c6a9434ad8 (patch)
tree654e86f40cb8e722aa4eb1de636dcd585ac60da6
parent8f3f0a9ca7d7fcaffc53a64798d2427342662115 (diff)
downloadchroma-ed642493fccbcf13efef5491f73241c6a9434ad8.tar.gz
chroma-ed642493fccbcf13efef5491f73241c6a9434ad8.tar.bz2
chroma-ed642493fccbcf13efef5491f73241c6a9434ad8.zip
toggle fullscreen mode with f11 key. use matplotlib colors maps defined in matplotlib.cm.
-rwxr-xr-xcamera.py41
-rw-r--r--color/colormap.py24
-rw-r--r--gpu.py4
-rwxr-xr-xsim.py2
4 files changed, 17 insertions, 54 deletions
diff --git a/camera.py b/camera.py
index f4439f5..2071d25 100755
--- a/camera.py
+++ b/camera.py
@@ -21,10 +21,6 @@ from subprocess import call
import shutil
import tempfile
-from histogram import *
-
-import matplotlib.pyplot as plt
-
def encode_movie(dir):
root, ext = 'movie', 'avi'
for i in count():
@@ -39,23 +35,11 @@ def encode_movie(dir):
print 'movie saved to %s.' % filename
-def get_rays(position, size = (800, 600), film_size = (0.035, 0.024), focal_length=0.05):
- """
- Generate ray positions and directions from a pinhole camera facing the negative y direction.
+def get_rays(position, size = (800, 600), width = 0.035, focal_length=0.05):
+ height = width*(size[1]/float(size[0]))
- Args:
- - position: tuple,
- Position of the camera.
- - size: tuple, *optional*
- Pixel array shape.
- - film_size: tuple, *optional*
- Physical size of photographic film. Defaults to 35mm film size.
- - focal_length: float, *optional*
- Focal length of camera.
- """
-
- x = np.linspace(-film_size[0]/2, film_size[0]/2, size[0])
- z = np.linspace(-film_size[1]/2, film_size[1]/2, size[1])
+ x = np.linspace(-width/2, width/2, size[0])
+ z = np.linspace(-height/2, height/2, size[1])
grid = np.array(tuple(product(x,[0],z)))
@@ -300,6 +284,9 @@ class Camera(Thread):
self.update_xyz_lookup(self.point)
self.source_position = self.point
+ elif event.key == K_F11:
+ pygame.display.toggle_fullscreen()
+
elif event.key == K_ESCAPE:
self.done = True
return
@@ -424,7 +411,7 @@ class EventViewer(Camera):
self.T = self.f.Get('T')
self.T.GetEntry(0)
- @timeit
+ #@timeit
def color_hit_pmts(self):
self.gpu.reset_colors()
@@ -437,15 +424,9 @@ class EventViewer(Camera):
t[i] = channel.t
q[i] = channel.q
- self.gpu.color_solids(solid_ids, map_to_color(t))
+ self.gpu.color_solids(solid_ids, map_to_color(t, (t.min(), t.mean())))
self.update()
- plt.clf()
- plt.hist(t*1e9, 100)
- plt.xlabel('Time (ns)')
- plt.ylabel('Entries')
- plt.draw()
-
def process_event(self, event):
if event.type == KEYDOWN:
if event.key == K_PAGEUP:
@@ -464,10 +445,6 @@ class EventViewer(Camera):
Camera.process_event(self, event)
- def run(self):
- plt.ion()
- Camera.run(self)
-
if __name__ == '__main__':
import optparse
import inspect
diff --git a/color/colormap.py b/color/colormap.py
index b3761ae..e5bd73e 100644
--- a/color/colormap.py
+++ b/color/colormap.py
@@ -1,27 +1,13 @@
import numpy as np
+import matplotlib.cm as cm
-import matplotlib.pyplot as plt
-
-def map_to_color(a, range=None):
+def map_to_color(a, range=None, map=cm.hsv):
a = np.asarray(a)
if range is None:
range = (a.min(), a.max())
- x = np.linspace(0, np.pi, 100)
-
- yr = np.cos(x)**2
- yr[x > np.pi/2] = 0.0
- yg = np.sin(x)**2
- yb = np.cos(x)**2
- yb[x < np.pi/2] = 0.0
-
- #plt.plot(x, yr, 'r-', x, yb, 'b-', x, yg, 'g-')
- #plt.show()
-
- ax = np.pi*(a - range[0])/(range[1]-range[0])
+ ax = (a - range[0])/(range[1]-range[0])
- r = (np.interp(ax, x, yr)*255).astype(np.uint32)
- g = (np.interp(ax, x, yg)*255).astype(np.uint32)
- b = (np.interp(ax, x, yb)*255).astype(np.uint32)
+ rgba = (map(ax)*255).astype(np.uint32)
- return r << 16 | g << 8 | b
+ return rgba[:,0] << 16 | rgba[:,1] << 8 | rgba[:,2]
diff --git a/gpu.py b/gpu.py
index 5eb2096..8de0f90 100644
--- a/gpu.py
+++ b/gpu.py
@@ -157,11 +157,11 @@ class GPU(object):
self.print_device_usage()
- @timeit
+ #@timeit
def reset_colors(self):
self.colors_gpu.set(self.geometry.colors.astype(np.uint32))
- @timeit
+ #@timeit
def color_solids(self, solid_ids, colors):
solid_ids_gpu = gpuarray.to_gpu(np.array(solid_ids, dtype=np.int32))
solid_colors_gpu = gpuarray.to_gpu(np.array(colors, dtype=np.uint32))
diff --git a/sim.py b/sim.py
index ed926f8..7520caf 100755
--- a/sim.py
+++ b/sim.py
@@ -39,7 +39,7 @@ if __name__ == '__main__':
parser.add_option('--particle', type='string', dest='particle', default='e-')
parser.add_option('--energy', type='float', dest='energy', default=100.0)
parser.add_option('--pos', type='string', dest='pos', default='(0,0,0)')
- parser.add_option('--dir', type='string', dest='dir', default='(1,0,0)')
+ parser.add_option('--dir', type='string', dest='dir', default='(0,1,0)')
options, args = parser.parse_args()
if len(args) != 1: