summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony LaTorre <tlatorre9@gmail.com>2011-09-10 16:21:21 -0400
committerAnthony LaTorre <tlatorre9@gmail.com>2011-09-10 16:21:21 -0400
commite19f8046b479790a9b5f8feedf8a13678f75d350 (patch)
tree8940ac6f89115e0c5bfee37e49ab405d4b2bd24e
parent9ab99907d1969822285741256384ad853ca859b8 (diff)
downloadchroma-e19f8046b479790a9b5f8feedf8a13678f75d350.tar.gz
chroma-e19f8046b479790a9b5f8feedf8a13678f75d350.tar.bz2
chroma-e19f8046b479790a9b5f8feedf8a13678f75d350.zip
add ray_intersection unit test.
-rw-r--r--project.py2
-rw-r--r--tests/__init__.py0
-rw-r--r--tests/data/ray_intersection.npzbin0 -> 1920080 bytes
-rw-r--r--tests/test_ray_intersection.py27
4 files changed, 28 insertions, 1 deletions
diff --git a/project.py b/project.py
index 10254f2..7d9cabe 100644
--- a/project.py
+++ b/project.py
@@ -2,7 +2,7 @@ import numpy as np
from itertools import repeat
from chroma.transform import rotate, normalize
-def from_film(position, axis1=(0,0,1), axis2=(1,0,0), size=(800,600),
+def from_film(position=(0,0,0), axis1=(0,0,1), axis2=(1,0,0), size=(800,600),
width=0.035, focal_length=0.018):
"""Project rays from a piece of film located at whose focal point is
located at `position`. `axis1` and `axis2` specify the vectors pointing
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/__init__.py
diff --git a/tests/data/ray_intersection.npz b/tests/data/ray_intersection.npz
new file mode 100644
index 0000000..fba0e40
--- /dev/null
+++ b/tests/data/ray_intersection.npz
Binary files differ
diff --git a/tests/test_ray_intersection.py b/tests/test_ray_intersection.py
new file mode 100644
index 0000000..7d0c53c
--- /dev/null
+++ b/tests/test_ray_intersection.py
@@ -0,0 +1,27 @@
+import unittest
+import chroma
+import numpy as np
+import os
+from pycuda import gpuarray as ga
+
+class TestRayIntersection(unittest.TestCase):
+ def setUp(self):
+ self.context = chroma.gpu.create_cuda_context()
+ self.module = chroma.gpu.get_cu_module('mesh.h')
+ self.gpu_funcs = chroma.gpu.GPUFuncs(self.module)
+ self.box = chroma.gpu.GPUGeometry(chroma.build(chroma.make.cube()))
+
+ pos, dir = chroma.project.from_film()
+ self.pos_gpu = ga.to_gpu(chroma.gpu.to_float3(pos))
+ self.dir_gpu = ga.to_gpu(chroma.gpu.to_float3(dir))
+
+ testdir = os.path.dirname(os.path.abspath(chroma.tests.__file__))
+ self.dx_standard = np.load(os.path.join(testdir,
+ 'data/ray_intersection.npz'))
+ def test_intersection_distance(self):
+ dx = ga.zeros(self.pos_gpu.size, dtype=np.float32)
+ self.gpu_funcs.distance_to_mesh(np.int32(self.pos_gpu.size), self.pos_gpu, self.dir_gpu, self.box.gpudata, dx, block=(64,1,1), grid=(self.pos_gpu.size//64+1,1))
+ self.assertTrue((dx.get() == self.dx_standard).all())
+
+ def tearDown(self):
+ self.context.pop()