Esempio n. 1
0
    def move_ray(x=0.0, y=0.0, z=0.0, theta=0.0, phi=0.0, nanometers=555.0):
        # Clear old objects
        [vis.remove_object(_id) for _id in ray_ids]

        # Create new array with position from the interact UI
        ray = Ray(
            position=(x, y, z),
            direction=(np.sin(np.radians(theta)) * np.cos(np.radians(phi)),
                       np.sin(np.radians(theta)) * np.sin(np.radians(phi)),
                       np.cos(np.radians(theta))),
            wavelength=nanometers)

        # Re-create the scene with the new ray but reuse the renderers
        steps = photon_tracer.follow(scene, ray, maxsteps=10)
        path, events = zip(*steps)
        vis.render(scene)

        # Remove old rays; add new rays
        ray_ids.clear()
        ray_ids.extend(vis.add_ray_path(path))
Esempio n. 2
0
            ),
            parent=cil1)

# Add source of photons
light = Node(
    name="Light (555nm)",
    parent=world,
    light=Light(
        direction=functools.partial(phase_functions.cone, np.radians(30))))

light.translate((0, 0, -1))
#light.rotate(np.pi/2, (1, 0, 0))

# Use meshcat to render the scene (optional)
viewer = MeshcatRenderer(open_browser=True,
                         transparency=False,
                         opacity=0.5,
                         wireframe=True)
scene = Scene(world)
viewer.render(scene)
for ray in scene.emit(100):
    history = photon_tracer.follow(scene, ray)
    path, events = zip(*history)
    viewer.add_ray_path(path)

# Keep the script alive until Ctrl-C (optional)
while True:
    try:
        time.sleep(0.1)
    except KeyboardInterrupt:
        break
Esempio n. 3
0
                                                (x, emission_spectrum)),
                                            quantum_yield=1.0,
                                            phase_function=isotropic),
                                        Absorber(coefficient=0.1)
                                    ]),
              ),
              parent=world)
ray = Ray(position=(-1.0, 0.0, 0.9),
          direction=(1.0, 0.0, 0.0),
          wavelength=555.0)
scene = Scene(world)
np.random.seed(0)
vis = MeshcatRenderer(wireframe=True)
vis.render(scene)
for _ in range(10):
    steps = photon_tracer.follow(scene, ray)
    path, decisions = zip(*steps)
    vis.add_ray_path(path)
#vis.vis.jupyter_cell()
vis.vis.open()

# Multiple components can be added simultaneously,
#
# ```python
# components=[
#     Luminophore(
#         coefficient=np.column_stack((x, absorption_spectrum)),
#         emission=np.column_stack((x, emission_spectrum)),
#         quantum_yield=1.0,
#         phase_function=isotropic
#     ),