Ejemplo n.º 1
0
 def test_intersection_coordinate_system(self):
     root = Node(name="Root", geometry=Sphere(radius=10.0))
     a = Node(name="A", parent=root, geometry=Sphere(radius=1.0))
     a.translate((1.0, 0.0, 0.0))
     scene = Scene(root)
     initial_ray = Ray(
         position=(-2.0, 0.0, 0.0),
         direction=(1.0, 0.0, 0.0),
         wavelength=None,
         is_alive=True,
     )
     scene_intersections = scene.intersections(initial_ray.position,
                                               initial_ray.direction)
     a_intersections = tuple(map(lambda x: x.to(root), scene_intersections))
     assert scene_intersections == a_intersections
Ejemplo n.º 2
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
Ejemplo n.º 3
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)))
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
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))
Ejemplo n.º 7
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)))
Ejemplo n.º 8
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))
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
def make_touching_scene(n1=1.5, n2=1.5, n3=1.5):
    world = Node(
        name="world (air)",
        geometry=Sphere(
            radius=10.0,
            material=Dielectric.air()
        )
    )
    box1 = Node(
        name="box one (glass)",
        geometry=Box(
            (1.0, 1.0, 1.0),
            material=Dielectric.make_constant(
                x_range=(300.0, 4000.0), refractive_index=n1
            )
        ),
        parent=world
    )
    box2 = Node(
        name="box two (glass)",
        geometry=Box(
            (1.0, 1.0, 1.0),
            material=Dielectric.make_constant(
                x_range=(300.0, 4000.0), refractive_index=n2
            )
        ),
        parent=world
    )
    box2.translate((0.0, 0.0, 1.0))
    box3 = Node(
        name="box three (glass)",
        geometry=Box(
            (1.0, 1.0, 1.0),
            material=Dielectric.make_constant(
                x_range=(300.0, 4000.0), refractive_index=n3
            )
        ),
        parent=world
    )
    box3.translate((0.0, 0.0, 2.0))
    scene = Scene(world)
    return scene, world, box1, box2, box3
Ejemplo n.º 11
0
def make_embedded_scene(n1=1.5):
    world = Node(
        name="world (air)",
        geometry=Sphere(
            radius=10.0,
            material=Dielectric.air()
        )
    )
    box = Node(
        name="box (glass)",
        geometry=Box(
            (1.0, 1.0, 1.0),
            material=Dielectric.make_constant(
                x_range=(300.0, 4000.0), refractive_index=n1
            )
        ),
        parent=world
    )
    scene = Scene(world)
    return scene, world, box
Ejemplo n.º 12
0
def make_embedded_lumophore_scene(n1=1.5):
    world = Node(
        name="world (air)",
        geometry=Sphere(
            radius=10.0,
            material=Dielectric.air()
        )
    )
    box = Node(
        name="box (lumophore)",
        geometry=Box(
            (1.0, 1.0, 1.0),
            material=Lumophore.make_lumogen_f_red(
                x=np.linspace(300.0, 4000.0),
                absorption_coefficient=10.0,
                quantum_yield=1.0
            )
        ),
        parent=world
    )
    scene = Scene(world)
    return scene, world, box
Ejemplo n.º 13
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
    )
)
Ejemplo n.º 14
0
 def test_init(self):
     assert type(Sphere(radius=1)) == Sphere
Ejemplo n.º 15
0
 def test_is_entering_false(self):
     s = Sphere(radius=1)
     assert s.is_entering((-1.0, 0.0, 0.0), (-1.0, 0.0, 0.0)) == False
Ejemplo n.º 16
0
 def test_is_entering_true(self):
     s = Sphere(radius=1)
     assert s.is_entering((-1.0, 0.0, 0.0), (1.0, 0.0, 0.0)) == True
Ejemplo n.º 17
0
 def test_normal(self):
     s = Sphere(radius=1)
     assert np.allclose(s.normal((0.0, 0.0, 1.0)), (0.0, 0.0, 1.0))
Ejemplo n.º 18
0
 def test_intersection(self):
     s = Sphere(radius=1)
     ro = (-2.0, 0.0, 0.0)
     rd = (1.0, 0.0, 0.0)
     assert s.intersections(ro, rd) == ((-1.0, 0.0, 0.0), (1.0, 0.0, 0.0))
Ejemplo n.º 19
0
 def test_contains(self):
     s = Sphere(radius=1)
     assert s.contains((0.0, 0.0, 2.0)) == False
     assert s.contains((0.0, 0.0, 1.0)) == False
     assert s.contains((0.0, 0.0, 0.0)) == True
Ejemplo n.º 20
0
 def test_is_on_surface(self):
     s = Sphere(radius=1)
     assert s.is_on_surface((0.0, 0.0, 1.0)) == True
     assert s.is_on_surface((0.0, 0.0, 0.0)) == False
Ejemplo n.º 21
0
from pvtrace.geometry.cylinder import Cylinder
from pvtrace.geometry.sphere import Sphere
from pvtrace.scene.renderer import MeshcatRenderer
from pvtrace.scene.scene import Scene
from pvtrace.scene.node import Node
from pvtrace.light.light import Light
from pvtrace.algorithm import photon_tracer
from pvtrace.material.dielectric import Dielectric
import numpy as np
import functools
import sys
import time

# World node contains the simulation; large sphere filled with air
world = Node(name="world (air)",
             geometry=Sphere(radius=10.0, material=Dielectric.air()))

# A small cylinder shape made from glass
cylinder = Node(name="cylinder (glass)",
                geometry=Cylinder(length=1.0,
                                  radius=1.0,
                                  material=Dielectric.glass()),
                parent=world)

# A light source with 60-deg divergence
light = Node(name="light (555nm laser)",
             light=Light(divergence_delegate=functools.partial(
                 Light.cone_divergence, np.radians(60))),
             parent=world)
light.translate((0.0, 0.0, -1.0))