def setUp(self): self.num_rays = 10 dir = N.tile(N.c_[[0, 0, -1]], (1, self.num_rays)) theta = N.linspace(0, 2 * N.pi, self.num_rays, endpoint=False) position = N.vstack( (N.cos(theta), N.sin(theta), N.ones(self.num_rays))) self._bund = RayBundle(position, dir) # The boundary is positioned to create a bottom hemisphere. boundary = BoundarySphere(radius=4., location=N.r_[0., 0., -4 * N.sqrt(3) / 2.]) self.gm = CutSphereGM(2., boundary) self.prm = self.gm.find_intersections(N.eye(4), self._bund)
def setUp(self): self.assembly = Assembly() surface1 = Surface(FlatGeometryManager(), opt.RefractiveHomogenous(1., 1.5), location=N.array([0, 0, -1.])) surface2 = Surface(FlatGeometryManager(), opt.RefractiveHomogenous(1., 1.5), location=N.array([0, 0, 1.])) object1 = AssembledObject(surfs=[surface1, surface2]) boundary = BoundarySphere(location=N.r_[0, 0., 3], radius=3.) surface3 = Surface(CutSphereGM(2., boundary), opt.perfect_mirror) object2 = AssembledObject(surfs=[surface3], transform=translate(0., 0., 2.)) self.assembly = Assembly(objects=[object1, object2]) x = 1. / (math.sqrt(2)) dir = N.c_[[0, 1., 0.], [0, x, x], [0, 0, 1.]] position = N.c_[[0, 0, 2.], [0, 0, 2.], [0, 0., 2.]] self._bund = RayBundle(position, dir, ref_index=N.ones(3), energy=N.ones(3)) self.engine = TracerEngine(self.assembly)
def setUp(self): self.assembly = Assembly() surface1 = Surface(flat_surface.FlatGeometryManager(), optics_callables.RefractiveHomogenous(1., 1.5), location=N.array([0, 0, -1.])) surface2 = Surface(flat_surface.FlatGeometryManager(), optics_callables.RefractiveHomogenous(1., 1.5), location=N.array([0, 0, 1.])) self.object1 = AssembledObject() self.object1.add_surface(surface1) self.object1.add_surface(surface2) boundary = BoundarySphere(location=N.r_[0, 0., 3], radius=3.) surface3 = Surface(CutSphereGM(2., boundary), optics_callables.perfect_mirror) self.object2 = AssembledObject() self.object2.add_surface(surface3) self.transform = generate_transform(N.r_[1, 0., 0], 0., N.c_[[0., 0, 2]]) self.assembly.add_object(self.object1) self.assembly.add_object(self.object2, self.transform) x = 1. / (math.sqrt(2)) dir = N.c_[[0, 1., 0.], [0, x, x], [0, 0, 1.]] position = N.c_[[0, 0, 2.], [0, 0, 2.], [0, 0., 2.]] self._bund = RayBundle(position, dir, energy=N.ones(3), ref_index=N.ones(3))
class TestInterface(unittest.TestCase): def setUp(self): self.num_rays = 10 dir = N.tile(N.c_[[0, 0, -1]], (1, self.num_rays)) theta = N.linspace(0, 2*N.pi, self.num_rays, endpoint=False) position = N.vstack((N.cos(theta), N.sin(theta), N.ones(self.num_rays))) self._bund = RayBundle(position, dir) # The boundary is positioned to create a bottom hemisphere. boundary = BoundarySphere(radius=4., location=N.r_[0., 0., -4*N.sqrt(3)/2.]) self.gm = CutSphereGM(2., boundary) self.prm = self.gm.find_intersections(N.eye(4), self._bund) def test_find_intersections(self): """The correct parametric locations are found for cut sphere geometry""" self.failUnlessEqual(self.prm.shape, (self.num_rays,)) N.testing.assert_array_almost_equal(self.prm, 1 + 2*N.sin(N.pi/3)) def test_get_normals(self): """Cut sphere surface returns center-pointing normals""" self.gm.select_rays(N.arange(self.num_rays)) n = self.gm.get_normals() N.testing.assert_array_almost_equal(n[-1,0], n[-1,1:]) N.testing.assert_array_almost_equal(self._bund.get_vertices()[:2], -n[:2]/N.sqrt((n[:2]**2).sum(axis=0))) def test_inters_points_global(self): """Cut sphere returns correct intersections""" self.gm.select_rays(N.arange(self.num_rays)) pts = self.gm.get_intersection_points_global() N.testing.assert_array_equal(pts[:2], self._bund.get_vertices()[:2]) N.testing.assert_array_almost_equal(pts[2], -2*N.sin(N.pi/3))
def setUp(self): self.num_rays = 10 dir = N.tile(N.c_[[0, 0, -1]], (1, self.num_rays)) theta = N.linspace(0, 2*N.pi, self.num_rays, endpoint=False) position = N.vstack((N.cos(theta), N.sin(theta), N.ones(self.num_rays))) self._bund = RayBundle(position, dir) # The boundary is positioned to create a bottom hemisphere. boundary = BoundarySphere(radius=4., location=N.r_[0., 0., -4*N.sqrt(3)/2.]) self.gm = CutSphereGM(2., boundary) self.prm = self.gm.find_intersections(N.eye(4), self._bund)
def setUp(self): self.assembly = Assembly() surface1 = Surface(FlatGeometryManager(), opt.perfect_mirror) self.object1 = AssembledObject() self.object1.add_surface(surface1) boundary = BoundarySphere(location=N.r_[0, 0., 3], radius=3.) surface3 = Surface(CutSphereGM(2., boundary), opt.perfect_mirror) self.object2 = AssembledObject() self.object2.add_surface(surface3) self.transform1 = generate_transform(N.r_[1., 0, 0], N.pi / 4, N.c_[[0, 0, -1.]]) self.transform2 = translate(0., 0., 2.) self.assembly.add_object(self.object1, self.transform1) self.assembly.add_object(self.object2, self.transform2)
class TestInterface(unittest.TestCase): def setUp(self): self.num_rays = 10 dir = N.tile(N.c_[[0, 0, -1]], (1, self.num_rays)) theta = N.linspace(0, 2 * N.pi, self.num_rays, endpoint=False) position = N.vstack( (N.cos(theta), N.sin(theta), N.ones(self.num_rays))) self._bund = RayBundle(position, dir) # The boundary is positioned to create a bottom hemisphere. boundary = BoundarySphere(radius=4., location=N.r_[0., 0., -4 * N.sqrt(3) / 2.]) self.gm = CutSphereGM(2., boundary) self.prm = self.gm.find_intersections(N.eye(4), self._bund) def test_find_intersections(self): """The correct parametric locations are found for cut sphere geometry""" self.failUnlessEqual(self.prm.shape, (self.num_rays, )) N.testing.assert_array_almost_equal(self.prm, 1 + 2 * N.sin(N.pi / 3)) def test_get_normals(self): """Cut sphere surface returns center-pointing normals""" self.gm.select_rays(N.arange(self.num_rays)) n = self.gm.get_normals() N.testing.assert_array_almost_equal(n[-1, 0], n[-1, 1:]) N.testing.assert_array_almost_equal( self._bund.get_vertices()[:2], -n[:2] / N.sqrt( (n[:2]**2).sum(axis=0))) def test_inters_points_global(self): """Cut sphere returns correct intersections""" self.gm.select_rays(N.arange(self.num_rays)) pts = self.gm.get_intersection_points_global() N.testing.assert_array_equal(pts[:2], self._bund.get_vertices()[:2]) N.testing.assert_array_almost_equal(pts[2], -2 * N.sin(N.pi / 3))