Example #1
0
    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)
Example #2
0
    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)
Example #3
0
    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)
Example #4
0
    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)
Example #5
0
 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)
Example #6
0
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)
Example #7
0
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)
Example #8
0
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)
Example #9
0
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)
Example #10
0
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)
Example #11
0
    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
Example #12
0
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)