summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chroma/camera.py2
-rw-r--r--chroma/cuda/transform.cu11
-rw-r--r--chroma/event.py32
-rw-r--r--chroma/make.py4
-rw-r--r--chroma/sim.py2
-rw-r--r--chroma/transform.py21
6 files changed, 44 insertions, 28 deletions
diff --git a/chroma/camera.py b/chroma/camera.py
index 6f47df0..9f69f1a 100644
--- a/chroma/camera.py
+++ b/chroma/camera.py
@@ -80,6 +80,7 @@ class Camera(multiprocessing.Process):
self.spnav = False
def init_gpu(self):
+ print 'init_gpu()'
self.context = gpu.create_cuda_context(self.device_id)
self.gpu_geometry = gpu.GPUGeometry(self.geometry)
@@ -308,6 +309,7 @@ class Camera(multiprocessing.Process):
self.update()
def update_pixels(self, gpu_geometry=None, keep_last_render=False):
+ print 'self.point = ', self.point
if gpu_geometry is None:
gpu_geometry = self.gpu_geometry
diff --git a/chroma/cuda/transform.cu b/chroma/cuda/transform.cu
index 1f4405e..1c5a6cb 100644
--- a/chroma/cuda/transform.cu
+++ b/chroma/cuda/transform.cu
@@ -31,6 +31,17 @@ rotate(int nthreads, float3 *a, float phi, float3 axis)
a[id] = rotate(a[id], phi, axis);
}
+__global__ void
+rotate_(int nthreads, float3 *a, float phi, float3 axis)
+{
+ int id = blockIdx.x*blockDim.x + threadIdx.x;
+
+ if (id >= nthreads)
+ return;
+
+ a[id] = rotate(a[id], phi, axis);
+}
+
/* Rotate the points `a` through an angle `phi` counter-clockwise
(when looking towards +infinity along `axis`) about the axis defined
by the point `point` and the vector `axis` . */
diff --git a/chroma/event.py b/chroma/event.py
index f4971ce..6d1d93d 100644
--- a/chroma/event.py
+++ b/chroma/event.py
@@ -124,24 +124,32 @@ class Photons(object):
'''Returns the number of photons in self.'''
return len(self.pos)
+ def __getitem__(self, key):
+ return Photons(self.pos[key], self.dir[key], self.pol[key],
+ self.wavelengths[key], self.t[key],
+ self.last_hit_triangles[key], self.flags[key],
+ self.weights[key])
+
def reduced(self, reduction_factor=1.0):
'''Return a new Photons object with approximately
len(self)*reduction_factor photons. Photons are selected
randomly.'''
n = len(self)
choice = np.random.permutation(n)[:int(n*reduction_factor)]
- print len(choice)
- pos = self.pos[choice]
- dir = self.dir[choice]
- pol = self.pol[choice]
- wavelengths = self.wavelengths[choice]
- last_hit_triangles = self.last_hit_triangles[choice]
- t = self.t[choice]
- flags = self.flags[choice]
- weights = self.weights[choice]
-
- return Photons(pos, dir, pol, wavelengths, t,
- last_hit_triangles, flags, weights)
+ return self[choice]
+
+ # print len(choice)
+ # pos = self.pos[choice]
+ # dir = self.dir[choice]
+ # pol = self.pol[choice]
+ # wavelengths = self.wavelengths[choice]
+ # last_hit_triangles = self.last_hit_triangles[choice]
+ # t = self.t[choice]
+ # flags = self.flags[choice]
+ # weights = self.weights[choice]
+
+ # return Photons(pos, dir, pol, wavelengths, t,
+ # last_hit_triangles, flags, weights)
class Channels(object):
def __init__(self, hit, t, q, flags=None):
diff --git a/chroma/make.py b/chroma/make.py
index cef287a..0daea78 100644
--- a/chroma/make.py
+++ b/chroma/make.py
@@ -103,6 +103,10 @@ def cube(size, height=None, center=(0,0,0)):
return linear_extrude([-size/2.0,size/2.0,size/2.0,-size/2.0],[-size/2.0,-size/2.0,size/2.0,size/2.0], height=size, center=center)
+def cylinder_along_z(radius, height, points=100):
+ angles = np.linspace(0, 2*np.pi, points, endpoint=False)
+ return linear_extrude(radius*np.cos(angles), radius*np.sin(angles), height)
+
def cylinder(radius, height, radius2=None, nsteps=64):
"""
Return a cylinder mesh with a radius of length `radius`, and a height of
diff --git a/chroma/sim.py b/chroma/sim.py
index 1ffa7f3..cea23b8 100644
--- a/chroma/sim.py
+++ b/chroma/sim.py
@@ -53,7 +53,7 @@ class Simulation(object):
self.pdf_config = None
def simulate(self, iterable, keep_photons_beg=False,
- keep_photons_end=False, run_daq=True, max_steps=10):
+ keep_photons_end=False, run_daq=True, max_steps=1000):
try:
first_element, iterable = itertoolset.peek(iterable)
except TypeError:
diff --git a/chroma/transform.py b/chroma/transform.py
index 580dbf4..40df8f3 100644
--- a/chroma/transform.py
+++ b/chroma/transform.py
@@ -38,20 +38,11 @@ def rotate_matrix(x, phi, n):
rotation_matrix = make_rotation_matrix(phi, n)
return np.inner(np.asarray(x),rotation_matrix)
+def norm(x):
+ "Returns the norm of the vector `x`."
+ return np.sqrt((x*x).sum(-1))
+
def normalize(x):
"Returns unit vectors in the direction of `x`."
- x = np.asarray(x, dtype=float)
-
- if x.shape[-1] != 3:
- raise ValueError('dimension of last axis must be 3.')
-
- d = len(x.shape)
-
- if d == 1:
- norm = np.sqrt(x.dot(x))
- elif d == 2:
- norm = np.sqrt(np.sum(x*x, axis=1))[:,np.newaxis]
- else:
- raise ValueError('len(`x`.shape) must be zero or one.')
-
- return x/norm
+ x = np.atleast_2d(np.asarray(x, dtype=float))
+ return (x/norm(x)[:,np.newaxis]).squeeze()