summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony LaTorre <devnull@localhost>2013-11-08 23:08:13 -0600
committertlatorre <tlatorre@uchicago.edu>2021-05-09 08:42:39 -0700
commit08682581c8fdbeb504b9dc6a93df6cd3ff32d124 (patch)
tree18334b45af42084a5187476841b99f33f2737318
parent8374553fcc23b127d0edd9d3f02239bc15d7d9d6 (diff)
downloadchroma-08682581c8fdbeb504b9dc6a93df6cd3ff32d124.tar.gz
chroma-08682581c8fdbeb504b9dc6a93df6cd3ff32d124.tar.bz2
chroma-08682581c8fdbeb504b9dc6a93df6cd3ff32d124.zip
move from_film function into tools
-rw-r--r--chroma/camera.py2
-rw-r--r--chroma/tools.py36
2 files changed, 37 insertions, 1 deletions
diff --git a/chroma/camera.py b/chroma/camera.py
index 80fc8f6..dd00a17 100644
--- a/chroma/camera.py
+++ b/chroma/camera.py
@@ -15,7 +15,7 @@ from pycuda import gpuarray as ga
from chroma.geometry import Mesh, Solid, Geometry, vacuum
from chroma.transform import rotate, make_rotation_matrix
from chroma.sample import uniform_sphere
-from chroma.project import from_film
+from chroma.tools import from_film
from chroma import make
from chroma import gpu
from chroma.loader import create_geometry_from_obj
diff --git a/chroma/tools.py b/chroma/tools.py
index 3a930c1..c62fe62 100644
--- a/chroma/tools.py
+++ b/chroma/tools.py
@@ -3,6 +3,7 @@ import time
import datetime
import sys
import math
+from chroma.transform import normalize
def count_nonzero(array):
'''Return the number of nonzero elements in this array'''
@@ -190,3 +191,38 @@ def argsort_direction(dir):
morton |= (theta & 1 << i) << (i) | \
(phi & 1 << i) << (i+1)
return np.argsort(morton)
+
+def from_film(position=(0,0,0), axis1=(0,0,1), axis2=(1,0,0), size=(800,600),
+ width=35.0, focal_length=18.0):
+ """Project rays from a piece of film whose focal point is located at
+ `position`. `axis1` and `axis2` specify the vectors pointing along the
+ length and height of the film respectively.
+ """
+
+ height = width*(size[1]/float(size[0]))
+
+ axis1 = normalize(axis1)
+ axis2 = normalize(axis2)
+
+ dx0 = width/size[0]
+ dx1 = height/size[1]
+
+ # for i in range(size[0]):
+ # for j in range(size[1]):
+ # grid[i*size[1]+j] = axis1*dx1*j - axis2*dx0*i
+
+ x = np.arange(size[0])
+ y = np.arange(size[1])
+
+ yy, xx = np.meshgrid(y,x)
+
+ n = size[0]*size[1]
+
+ grid = -np.tile(axis2, (n,1))*xx.ravel()[:,np.newaxis]*dx0 + \
+ np.tile(axis1, (n,1))*yy.ravel()[:,np.newaxis]*dx1
+
+ grid += axis2*width/2 - axis1*height/2
+ grid -= np.cross(axis1,axis2)*focal_length
+
+ return np.tile(position,(n,1)), normalize(-grid)
+