summaryrefslogtreecommitdiff
path: root/test/test_ray_intersection.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_ray_intersection.py')
-rw-r--r--test/test_ray_intersection.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/test_ray_intersection.py b/test/test_ray_intersection.py
new file mode 100644
index 0000000..7d0c53c
--- /dev/null
+++ b/test/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()