示例#1
0
 def test_no_interaction(self):
     np.random.seed(0)
     mat = Dielectric.make_constant((400, 800), 1.0)
     root = Node(name="Root", parent=None)
     root.geometry = Sphere(radius=10.0, material=mat)
     a = Node(name="A", parent=root)
     a.geometry = Sphere(radius=1.0, material=mat)
     ray = Ray(position=(-1.0, 0.0, 0.0), direction=(1.0, 0.0, 0.0), wavelength=555.0, is_alive=True)
     volume = Volume(a, 2.0)
     new_ray = volume.trace(ray)
     expected = replace(ray, position=(1.0, 0.0, 0.0))
     assert new_ray == expected
示例#2
0
 def test_zero_reflection(self):
     np.random.seed(0)
     mat1 = Dielectric.make_constant((400, 800), 1.0)
     mat2 = Dielectric.make_constant((400, 800), 1.0)
     root = Node(name="Root", parent=None)
     root.geometry = Sphere(radius=10.0, material=mat1)
     a = Node(name="A", parent=root)
     a.geometry = Sphere(radius=1.0, material=mat2)
     ray = Ray(position=(-1.0, 0.0, 0.0), direction=(0.0, 0.0, 1.0), wavelength=555.0, is_alive=True)
     from_node = root
     to_node = a
     interface = DielectricInterface(from_node, to_node)
     new_ray = interface.trace(ray)
     expected = ray  # unchanged
     assert new_ray == expected
示例#3
0
 def test_is_entering_false(self):
     a = Node(name="A", parent=None)
     b = Node(name="B", parent=a)
     b.geometry = Sphere(radius=1.0)
     surface_point = (-1.0, 0.0, 0.0)
     entering_direction = (-1.0, 0.0, 0.0)
     assert b.geometry.is_entering(surface_point, entering_direction) == False
示例#4
0
 def test_is_entering_false(self):
     a = Node(name="A", parent=None)
     b = Node(name="B", parent=a)
     b.geometry = Sphere(radius=1.0)
     surface_point = (-1.0, 0.0, 0.0)
     entering_direction = (-1.0, 0.0, 0.0)
     assert b.geometry.is_entering(surface_point,
                                   entering_direction) == False
示例#5
0
 def test_intersections(self):
     a = Node(name="A", parent=None)
     b = Node(name="B", parent=a)
     b.geometry = Sphere(radius=1.0)
     loc = (-1.0, 0.0, 0.0)
     vec = (1.0, 0.0, 0.0)
     intersections = b.intersections(loc, vec)
     points = np.array([x.point for x in intersections])
     assert np.allclose(points, ((-1.0, 0.0, 0.0), (1.0, 0.0, 0.0)))
示例#6
0
 def test_intersections(self):
     a = Node(name="A", parent=None)
     b = Node(name="B", parent=a)
     b.geometry = Sphere(radius=1.0)
     loc = (-1.0, 0.0, 0.0)
     vec = (1.0, 0.0, 0.0)
     intersections = b.intersections(loc, vec)
     points = np.array([x.point for x in intersections])
     assert np.allclose(points, ((-1.0, 0.0, 0.0), (1.0, 0.0, 0.0)))
 def test_basic_scene(self):
     a = Node(name="A", parent=None)
     b = Node(name="B", parent=a)
     b.geometry = Sphere(radius=1.0)
     b.translate((2.0, 0.0, 0.0))
     s = Scene(root=a)
     r = MeshcatRenderer()
     r.render(s)
     time.sleep(0.5)
     r.remove(s)
 def test_basic_scene(self):
     a = Node(name="A", parent=None)
     b = Node(name="B", parent=a)
     b.geometry = Sphere(radius=1.0)
     b.translate((2.0, 0.0, 0.0))
     s = Scene(root=a)
     r = MeshcatRenderer(zmq_url='tcp://127.0.0.1:6000')
     r.render(s)
     time.sleep(0.5)
     r.remove(s)
示例#9
0
 def test_ray_reflecting_interaction(self):
     # low > very high refractive index
     np.random.seed(2)
     mat1 = Dielectric.make_constant((400, 800), 1.0)
     mat2 = Dielectric.make_constant((400, 800), 6.0)
     root = Node(name="Root", parent=None)
     root.geometry = Sphere(radius=10.0, material=mat1)
     a = Node(name="A", parent=root)
     a.geometry = Sphere(radius=1.0, material=mat2)
     ray = Ray(position=(-1.0, 0.0, 0.0), direction=norm((-0.2, 0.2, 1.0)), wavelength=555.0, is_alive=True)
     from_node = root
     to_node = a
     interface = DielectricInterface(from_node, to_node)
     new_ray = interface.trace(ray)
     assert np.sign(ray.direction[0]) != np.sign(new_ray.direction[0])  # Reflected
     # Direction should be different after refracting interface
     assert all([not np.allclose(new_ray.direction, ray.direction),
                 np.allclose(new_ray.position, ray.position),
                 new_ray.wavelength == ray.wavelength,
                 new_ray.is_alive == ray.is_alive])
示例#10
0
 def test_intersection_when_on_surface(self):
     """ Make sure we return intersection points even with zero distance from ray.
     """
     a = Node(name="A", parent=None)
     a.geometry = Sphere(radius=1.0)
     loc = (-1.0, 0.0, 0.0)
     vec = (1.0, 0.0, 0.0)
     intersections = a.intersections(loc, vec)
     points = np.array([x.point for x in intersections])
     expected = np.array([(-1.0, 0.0, 0.0), (1.0, 0.0, 0.0)])
     assert np.allclose(points, expected)
示例#11
0
 def test_intersection_when_on_surface(self):
     """ Make sure we return intersection points even with zero distance from ray.
     """
     a = Node(name="A", parent=None)
     a.geometry = Sphere(radius=1.0)
     loc = (-1.0, 0.0, 0.0)
     vec = (1.0, 0.0, 0.0)
     intersections = a.intersections(loc, vec)
     points = np.array([x.point for x in intersections])
     expected = np.array([(-1.0, 0.0, 0.0), (1.0, 0.0, 0.0)])
     assert np.allclose(points, expected)
示例#12
0
 def test_intersection(self):
     root = Node(name='Root')
     a = Node(name="A", parent=root)
     b = Node(name="B", parent=a)
     b.geometry = Sphere(radius=1.0)
     a.translate((1.0, 0.0, 0.0))
     loc = (-2.0, 0.0, 0.0)
     vec = (1.0, 0.0, 0.0)
     scene = Scene(root=root)
     intersections = scene.intersections(loc, vec)
     points = tuple([x.point for x in intersections])
     # In frame of a everything is shifed 1 along x
     assert points == ((0.0, 0.0, 0.0), (2.0, 0.0, 0.0))
示例#13
0
 def test_intersection(self):
     root = Node(name='Root')
     a = Node(name="A", parent=root)
     b = Node(name="B", parent=a)
     b.geometry = Sphere(radius=1.0)
     a.translate((1.0, 0.0, 0.0))
     loc = (-2.0, 0.0, 0.0)
     vec = (1.0, 0.0, 0.0)
     scene = Scene(root=root)
     intersections = scene.intersections(loc, vec)
     points = tuple([x.point for x in intersections])
     # In frame of a everything is shifed 1 along x
     assert points == ((0.0, 0.0, 0.0), (2.0, 0.0, 0.0))
示例#14
0
 def test_intersection_with_rotation_around_z(self):
     root = Node(name='Root')
     a = Node(name="A", parent=root)
     b = Node(name="B", parent=a)
     b.geometry = Sphere(radius=1.0)
     a.translate((1.0, 0.0, 0.0))
     # This rotation make an z translation in b becomes a -y translation in a
     a.rotate(np.pi / 2, axis=(0.0, 0.0, 1.0))
     loc = (-2.0, 0.0, 0.0)
     vec = (1.0, 0.0, 0.0)
     scene = Scene(root=root)
     intersections = scene.intersections(loc, vec)
     points = tuple([x.point for x in intersections])
     assert np.allclose(points, ((0.0, 0.0, 0.0), (2.0, 0.0, 0.0)))
示例#15
0
 def test_intersection_with_rotation_around_x(self):
     root = Node(name='Root')
     a = Node(name="A", parent=root)
     b = Node(name="B", parent=a)
     b.geometry = Sphere(radius=1.0)
     b.translate((1.0, 0.0, 0.0))
     # Rotation around x therefore no displace in x
     b.rotate(np.pi / 2, (1.0, 0.0, 0.0))
     loc = (-2.0, 0.0, 0.0)
     vec = (1.0, 0.0, 0.0)
     scene = Scene(root=root)
     intersections = scene.intersections(loc, vec)
     points = tuple([x.point for x in intersections])
     assert points == ((0.0, 0.0, 0.0), (2.0, 0.0, 0.0))
示例#16
0
 def test_intersection_with_rotation_around_x(self):
     root = Node(name='Root')
     a = Node(name="A", parent=root)
     b = Node(name="B", parent=a)
     b.geometry = Sphere(radius=1.0)
     b.translate((1.0, 0.0, 0.0))
     # Rotation around x therefore no displace in x
     b.rotate(np.pi/2, (1.0, 0.0, 0.0))
     loc = (-2.0, 0.0, 0.0)
     vec = (1.0, 0.0, 0.0)
     scene = Scene(root=root)
     intersections = scene.intersections(loc, vec)
     points = tuple([x.point for x in intersections])
     assert points == ((0.0, 0.0, 0.0), (2.0, 0.0, 0.0))
示例#17
0
 def test_intersection_with_rotation_around_z(self):
     root = Node(name='Root')
     a = Node(name="A", parent=root)
     b = Node(name="B", parent=a)
     b.geometry = Sphere(radius=1.0)
     a.translate((1.0, 0.0, 0.0))
     # This rotation make an z translation in b becomes a -y translation in a
     a.rotate(np.pi/2, axis=(0.0, 0.0, 1.0))
     loc = (-2.0, 0.0, 0.0)
     vec = (1.0, 0.0, 0.0)
     scene = Scene(root=root)
     intersections = scene.intersections(loc, vec)
     points = tuple([x.point for x in intersections])
     assert np.allclose(points, ((0.0, 0.0, 0.0), (2.0, 0.0, 0.0)))
示例#18
0
 def test_intersection_with_translation(self):
     a = Node(name="A", parent=None)
     b = Node(name="B", parent=a)
     b.geometry = Sphere(radius=1.0)
     b.translate((1.0, 0.0, 0.0))
     aloc = (-2.0, 0.0, 0.0)
     avec = (1.0, 0.0, 0.0)
     bloc = b.point_to_node(aloc, b)
     bvec = b.vector_to_node(avec, b)
     intersections = b.intersections(bloc, bvec)
     points = tuple(x.point for x in intersections)
     assert np.allclose(points, ((-1.0, 0.0, 0.0), (1.0, 0.0, 0.0)))
     # In local frame of b sphere is at origin
     intersections = a.intersections(aloc, avec)
     points = np.array(tuple(x.to(a).point for x in intersections))
     expected = np.array(((0.0, 0.0, 0.0), (2.0, 0.0, 0.0)))
     # In frame of a everything is shifed 1 along x
     assert np.allclose(points, expected)
示例#19
0
 def test_intersection_with_translation(self):
     a = Node(name="A", parent=None)
     b = Node(name="B", parent=a)
     b.geometry = Sphere(radius=1.0)
     b.translate((1.0, 0.0, 0.0))
     aloc = (-2.0, 0.0, 0.0)
     avec = (1.0, 0.0, 0.0)
     bloc = b.point_to_node(aloc, b)
     bvec = b.vector_to_node(avec, b)
     intersections = b.intersections(bloc, bvec)
     points = tuple(x.point for x in intersections)
     assert np.allclose(points, ((-1.0, 0.0, 0.0), (1.0, 0.0, 0.0)))
     # In local frame of b sphere is at origin
     intersections = a.intersections(aloc, avec)
     points = np.array(tuple(x.to(a).point for x in intersections))
     expected = np.array(((0.0, 0.0, 0.0), (2.0, 0.0, 0.0)))
     # In frame of a everything is shifed 1 along x
     assert np.allclose(points, expected)
示例#20
0
import logging

# We want to see pvtrace logging here
#logging.getLogger('pvtrace').setLevel(logging.CRITICAL)
logging.getLogger('trimesh').setLevel(logging.CRITICAL)
logging.getLogger('matplotlib').setLevel(logging.CRITICAL)

wavelength_range = (200, 800)
wavelength = np.linspace(*wavelength_range, 1000)
lumogen = Lumophore.make_lumogen_f_red(wavelength, 1000, 1.0)
linear_background = Lumophore.make_linear_background(wavelength, 1.0)

# Make a world coordinate system
world_node = Node(name='world')
world_node.geometry = Sphere(
    radius=10.0,
    material=Dielectric.make_constant((300, 1000.0), 1.0)
)

refractive_index = np.column_stack(
    (wavelength, np.ones(wavelength.shape) * 1.5)
)
# Add LSC
size = (1.0, 1.0, 0.02)
lsc = Node(name="LSC", parent=world_node)
lsc.geometry = Box(
    size, 
    material=Host(
        refractive_index,  # LSC refractive index
        [linear_background, lumogen]          # LSC list of lumophore materials
    )
)