def setUp(self): dir = N.c_[[0, 0, 1], [0, 0, -1], [0, -1, -1]] position = N.c_[[0, 0, 1], [0, 1, 2], [0, 0, 1]] self._bund = RayBundle() self._bund.set_vertices(position) self._bund.set_directions(dir)
def setUp(self): self._surf = FlatSurface() dir = N.array([[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1] ]).T / math.sqrt(3) position = c_[[0, 0, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]] self._bund = RayBundle() self._bund.set_vertices(position) self._bund.set_directions(dir)
def setUp(self): dir = N.array([[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1] ]).T / math.sqrt(3) position = N.c_[[0, 0, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]] self._bund = RayBundle() self._bund.set_vertices(position) self._bund.set_directions(dir) energy = N.array([1, 1, 1, 1]) self._bund.set_energy(energy) objects = [FlatSurface()] self.engine = TracerEngine(objects)
def setUp(self): self.x = 1 / (math.sqrt(2)) dir = N.c_[[0, -self.x, self.x], [0, 0, -1]] position = N.c_[[0, 2, 1], [0, 2, 1]] self._bund = RayBundle() self._bund.set_vertices(position) self._bund.set_directions(dir) rot1 = general_axis_rotation([1, 0, 0], N.pi / 4) energy = N.array([1, 1]) self._bund.set_energy(energy) objects = [ FlatSurface(rotation=rot1, width=10, height=10), FlatSurface(width=10, height=10) ] self.engine = TracerEngine(objects)
def setUp(self): self._surf = FlatSurface() dir = N.array([[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1]]).T / math.sqrt(3) position = c_[[0,0,1], [1,-1,1], [1,1,1], [-1,1,1]] self._bund = RayBundle() self._bund.set_vertices(position) self._bund.set_directions(dir)
class TestTraceProtocol(unittest.TestCase): def setUp(self): self._surf = FlatSurface() dir = N.array([[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1]]).T / math.sqrt(3) position = c_[[0,0,1], [1,-1,1], [1,1,1], [-1,1,1]] self._bund = RayBundle() self._bund.set_vertices(position) self._bund.set_directions(dir) def test_register_incoming(self): """A simple bundle is registered correctly""" correct_params = r_[[math.sqrt(3)]*3] params = self._surf.register_incoming(self._bund) self.failUnless(params[0] == N.inf) N.testing.assert_array_almost_equal(params[1:], correct_params)
class TestTraceProtocol(unittest.TestCase): def setUp(self): self._surf = FlatSurface() dir = N.array([[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1] ]).T / math.sqrt(3) position = c_[[0, 0, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]] self._bund = RayBundle() self._bund.set_vertices(position) self._bund.set_directions(dir) def test_register_incoming(self): """A simple bundle is registered correctly""" correct_params = r_[[math.sqrt(3)] * 3] params = self._surf.register_incoming(self._bund) self.failUnless(params[0] == N.inf) N.testing.assert_array_almost_equal(params[1:], correct_params)
class TestTraceProtocol4(unittest.TestCase): """ Tests intersect_ray and the bundle driver with two planes, where the rays hit different surfaces """ def setUp(self): self.x = 1 / (math.sqrt(2)) dir = N.c_[[0, -self.x, self.x], [0, 0, -1]] position = N.c_[[0, 2, 1], [0, 2, 1]] self._bund = RayBundle() self._bund.set_vertices(position) self._bund.set_directions(dir) rot1 = general_axis_rotation([1, 0, 0], N.pi / 4) energy = N.array([1, 1]) self._bund.set_energy(energy) objects = [ FlatSurface(rotation=rot1, width=10, height=10), FlatSurface(width=10, height=10) ] self.engine = TracerEngine(objects) def test_ray_tracer1(self): params = self.engine.ray_tracer(self._bund, 1) correct_params = N.c_[[0, 1.5, 1.5], [0, 2, 0]] N.testing.assert_array_almost_equal(params, correct_params) def test_ray_tracer2(self): params = self.engine.ray_tracer(self._bund, 2) correct_params = N.c_[[0, 2, 2], [0, 3, 0]] N.testing.assert_array_almost_equal(params, correct_params)
class TestTraceProtocol1(unittest.TestCase): """ Tests intersect_ray and the bundle driver with a single flat surface, not rotated, with a single interation """ def setUp(self): dir = N.array([[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1] ]).T / math.sqrt(3) position = N.c_[[0, 0, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]] self._bund = RayBundle() self._bund.set_vertices(position) self._bund.set_directions(dir) energy = N.array([1, 1, 1, 1]) self._bund.set_energy(energy) objects = [FlatSurface()] self.engine = TracerEngine(objects) def test_intersect_ray1(self): correct_params = N.r_[[False, True, True, True]] params = self.engine.intersect_ray(self._bund)[0] N.testing.assert_array_almost_equal(params, correct_params) def test_ray_tracer(self): params = self.engine.ray_tracer(self._bund, 1) correct_params = N.c_[[0, 0, 0], [0, 0, 0], [0, 0, 0]] N.testing.assert_array_almost_equal(params, correct_params)
class TestTraceProtocol2(unittest.TestCase): """ Tests intersect_ray with a flat surface rotated around the x axis 45 degrees """ def setUp(self): dir = N.c_[[0, 0, 1], [0, 0, -1], [0, -1, -1]] position = N.c_[[0, 0, 1], [0, 1, 2], [0, 0, 1]] self._bund = RayBundle() self._bund.set_vertices(position) self._bund.set_directions(dir) def test_intersect_ray2(self): rot = general_axis_rotation([1, 0, 0], N.pi / 4) objects = [FlatSurface(rotation=rot, width=4, height=4)] engine = TracerEngine(objects) params = engine.intersect_ray(self._bund)[0] correct_params = N.r_[[False, True, False]] N.testing.assert_array_almost_equal(params, correct_params)
def get_outgoing(self, selector): """Generates a new ray bundle, which is the reflections/refractions of the user-selected rays out of the incoming ray-bundle that was previously registered. Arguments: selector - a boolean array specifying which rays of the incoming bundle are still relevant. Returns: a RayBundle object with the new bundle, with vertices on the panel and directions according to optics laws. """ vertices = N.dot(self.get_rotation()[:, :2], self._current_params[:, selector]) + \ self.get_location()[:, None] dirs = optics.reflections(self._current_bundle.get_directions()[:, selector], self.get_rotation()[:, 2][:,None]) outg = RayBundle() outg.set_vertices(vertices) outg.set_directions(dirs) return outg
class TestTraceProtocol3(unittest.TestCase): """ Tests intersect_ray and the bundle driver with two rotated planes, with a single iteration """ def setUp(self): self.x = 1 / (math.sqrt(2)) dir = N.c_[[0, self.x, -self.x], [0, 1, 0]] position = N.c_[[0, 0, 1], [0, 0, 1]] self._bund = RayBundle() self._bund.set_vertices(position) self._bund.set_directions(dir) rot1 = general_axis_rotation([1, 0, 0], N.pi / 4) rot2 = general_axis_rotation([1, 0, 0], N.pi / (-4)) objects = [ FlatSurface(rotation=rot1, width=4, height=4), FlatSurface(rotation=rot2, width=4, height=4) ] energy = N.array([1, 1]) self._bund.set_energy(energy) self.engine = TracerEngine(objects) def test_intersect_ray(self): params = self.engine.intersect_ray(self._bund) correct_params = N.array([[True, True], [False, False]]) N.testing.assert_array_almost_equal(params, correct_params) def test_ray_tracer1(self): params = self.engine.ray_tracer(self._bund, 1) correct_params = N.c_[[0, .5, .5], [0, 1, 1]] N.testing.assert_array_almost_equal(params, correct_params)