Example #1
0
blue_glass = Dielectric(
    index=Sellmeier(1.03961212, 0.231792344, 1.01046945, 6.00069867e-3,
                    2.00179144e-2, 1.03560653e2),
    transmission=InterpolatedSF([300, 490, 510, 590, 610, 800],
                                array([1.0, 1.0, 0.0, 0.0, 0.0, 0.0]) * 0.7))

world = World()

cyl_x = Cylinder(1, 4.2, transform=rotate(90, 0, 0) * translate(0, 0, -2.1))
cyl_y = Cylinder(1, 4.2, transform=rotate(0, 90, 0) * translate(0, 0, -2.1))
cyl_z = Cylinder(1, 4.2, transform=rotate(0, 0, 0) * translate(0, 0, -2.1))
cube = Box(Point3D(-1.5, -1.5, -1.5), Point3D(1.5, 1.5, 1.5))
sphere = Sphere(2.0)

Intersect(sphere, Subtract(cube, Union(Union(cyl_x, cyl_y), cyl_z)), world,
          translate(-2.1, 2.1, 2.5) * rotate(30, -20, 0), schott("N-LAK9"))
Intersect(sphere, Subtract(cube, Union(Union(cyl_x, cyl_y), cyl_z)), world,
          translate(2.1, 2.1, 2.5) * rotate(-30, -20, 0), schott("SF6"))
Intersect(sphere, Subtract(cube, Union(Union(cyl_x, cyl_y), cyl_z)), world,
          translate(2.1, -2.1, 2.5) * rotate(-30, 20, 0), schott("LF5G19"))
Intersect(sphere, Subtract(cube, Union(Union(cyl_x, cyl_y), cyl_z)), world,
          translate(-2.1, -2.1, 2.5) * rotate(30, 20, 0), schott("N-BK7"))

s1 = Sphere(1.0, transform=translate(0, 0, 1.0 - 0.01))
s2 = Sphere(0.5, transform=translate(0, 0, -0.5 + 0.01))
Intersect(s1, s2, world,
          translate(0, 0, -3.6) * rotate(50, 50, 0), schott("N-BK7"))

Box(Point3D(-50, -50, 50),
    Point3D(50, 50, 50.1),
    world,
Example #2
0
# Import the new lens classes
from raysect.primitive.lens.spherical import *

rotation = 90.0

# Instantiate world object
world = World()

# Create lens objects
BiConvex(0.0254,
         0.0052,
         0.0506,
         0.0506,
         parent=world,
         transform=translate(0.02, 0.02, 0) * rotate(rotation, 0.0, 0.0),
         material=schott("N-BK7"))
BiConcave(0.0254,
          0.0030,
          0.052,
          0.052,
          parent=world,
          transform=translate(-0.02, 0.02, 0) * rotate(rotation, 0.0, 0.0),
          material=schott("N-BK7"))
PlanoConvex(0.0254,
            0.0053,
            0.0258,
            parent=world,
            transform=translate(0.02, -0.02, 0) * rotate(rotation, 0.0, 0.0),
            material=schott("N-BK7"))
PlanoConcave(0.0254,
             0.0035,
# from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

# Raysect imports
from raysect.optical import World, translate, rotate, Point3D, d65_white, Ray, Vector3D
from raysect.optical.material.absorber import AbsorbingSurface
from raysect.optical.library import schott
from raysect.primitive import Sphere, Box
from raysect.optical.loggingray import LoggingRay
from raysect.primitive.lens.spherical import *

world = World()

# Create a glass BiConvex lens we want to study
lens_glass = schott("N-BK7")
lens_glass.transmission_only = True
lens = BiConvex(0.0254,
                0.0052,
                0.0506,
                0.0506,
                parent=world,
                material=lens_glass)
lens.meta['viz-color'] = (66 / 255, 188 / 255, 244 / 255)
lens.meta['viz-opacity'] = 0.5

# lens.meta['viz']['color'] = (66/255, 188/255, 244/255)
# lens.meta['viz']['opacity'] = 0.5

# Create a target plane behind the lens.
target = Box(lower=Point3D(-0.05, -0.05, -0),
Example #4
0
A Diamond Stanford Bunny on an Illuminated Glass Pedestal
---------------------------------------------------------

Bunny model source:
  Stanford University Computer Graphics Laboratory
  http://graphics.stanford.edu/data/3Dscanrep/
  Converted to obj format using MeshLab
"""

base_path = os.path.split(os.path.realpath(__file__))[0]

world = World()

#  BUNNY
mesh = import_obj(os.path.join(base_path, "../resources/stanford_bunny.obj"), parent=world,
                      transform=translate(0, 0, 0)*rotate(165, 0, 0), material=schott("N-BK7"))


# LIGHT BOX
padding = 1e-5
enclosure_thickness = 0.001 + padding
glass_thickness = 0.003

light_box = Node(parent=world)

enclosure_outer = Box(Point3D(-0.10 - enclosure_thickness, -0.02 - enclosure_thickness, -0.10 - enclosure_thickness),
                      Point3D(0.10 + enclosure_thickness, 0.0, 0.10 + enclosure_thickness))
enclosure_inner = Box(Point3D(-0.10 - padding, -0.02 - padding, -0.10 - padding),
                      Point3D(0.10 + padding, 0.001, 0.10 + padding))
enclosure = Subtract(enclosure_outer, enclosure_inner, material=Lambert(ConstantSF(0.2)), parent=light_box)
Example #5
0

# 1. Create Primitives
# --------------------

# Box defining the ground plane
ground = Box(lower=Point3D(-50, -1.51, -50), upper=Point3D(50, -1.5, 50), material=Lambert())

# checker board wall that acts as emitter
emitter = Box(lower=Point3D(-10, -10, 10), upper=Point3D(10, 10, 10.1),
              material=Checkerboard(4, d65_white, d65_white, 0.1, 2.0), transform=rotate(45, 0, 0))

# Sphere
# Note that the sphere must be displaced slightly above the ground plane to prevent numerically issues that could
# cause a light leak at the intersection between the sphere and the ground.
sphere = Sphere(radius=1.5, transform=translate(0, 0.0001, 0), material=schott("N-BK7"))


# 2. Add Observer
# ---------------

# Process the ray-traced spectra with the RGB pipeline.
rgb = RGBPipeline2D()

# camera
camera = PinholeCamera((512, 512), pipelines=[rgb], transform=translate(0, 10, -10) * rotate(0, -45, 0))

# camera - pixel sampling settings
camera.fov = 45
camera.pixel_samples = 250
Example #6
0
green_glass = Dielectric(index=Sellmeier(1.03961212, 0.231792344, 1.01046945, 6.00069867e-3, 2.00179144e-2, 1.03560653e2),
                         transmission=InterpolatedSF([300, 490, 510, 590, 610, 800], array([0.0, 0.0, 1.0, 1.0, 0.0, 0.0])*0.7))

blue_glass = Dielectric(index=Sellmeier(1.03961212, 0.231792344, 1.01046945, 6.00069867e-3, 2.00179144e-2, 1.03560653e2),
                        transmission=InterpolatedSF([300, 490, 510, 590, 610, 800], array([1.0, 1.0, 0.0, 0.0, 0.0, 0.0])*0.7))

world = World()

cyl_x = Cylinder(1, 4.2, transform=rotate(90, 0, 0)*translate(0, 0, -2.1))
cyl_y = Cylinder(1, 4.2, transform=rotate(0, 90, 0)*translate(0, 0, -2.1))
cyl_z = Cylinder(1, 4.2, transform=rotate(0, 0, 0)*translate(0, 0, -2.1))
cube = Box(Point3D(-1.5, -1.5, -1.5), Point3D(1.5, 1.5, 1.5))
sphere = Sphere(2.0)

Intersect(sphere, Subtract(cube, Union(Union(cyl_x, cyl_y), cyl_z)), world, translate(-2.1,2.1,2.5)*rotate(30, -20, 0), schott("N-LAK9"))
Intersect(sphere, Subtract(cube, Union(Union(cyl_x, cyl_y), cyl_z)), world, translate(2.1,2.1,2.5)*rotate(-30, -20, 0), schott("SF6"))
Intersect(sphere, Subtract(cube, Union(Union(cyl_x, cyl_y), cyl_z)), world, translate(2.1,-2.1,2.5)*rotate(-30, 20, 0), schott("LF5G19"))
Intersect(sphere, Subtract(cube, Union(Union(cyl_x, cyl_y), cyl_z)), world, translate(-2.1,-2.1,2.5)*rotate(30, 20, 0), schott("N-BK7"))

s1 = Sphere(1.0, transform=translate(0, 0, 1.0-0.01))
s2 = Sphere(0.5, transform=translate(0, 0, -0.5+0.01))
Intersect(s1, s2, world, translate(0,0,-3.6)*rotate(50,50,0), schott("N-BK7"))

Box(Point3D(-50, -50, 50), Point3D(50, 50, 50.1), world, material=Checkerboard(4, d65_white, d65_white, 0.4, 0.8))
Box(Point3D(-100, -100, -100), Point3D(100, 100, 100), world, material=UniformSurfaceEmitter(d65_white, 0.1))

ion()

# create and setup the camera
rgb = RGBPipeline2D()
Example #7
0
    return node


world = World()

# construct diffuse floor surface
floor = Box(Point3D(-1000, -0.1, -1000),
            Point3D(1000, 0, 1000),
            parent=world,
            material=Lambert())

# construct prism from utility method
prism = equilateral_prism(0.06,
                          0.15,
                          parent=world,
                          material=schott("SF11"),
                          transform=translate(0, 0.0 + 1e-6, -0.01))

# Curved target screen for collecting rainbow light
stand = Intersect(
    Box(Point3D(-10, -10, -10), Point3D(10, 10, 0)),
    Subtract(Cylinder(0.21, 0.15),
             Cylinder(0.20, 0.16, transform=translate(0, 0, -0.005)),
             transform=rotate(0, 90, 0)),
    transform=translate(0.0, 1e-6, 0.0),
    parent=world,
    material=schott("N-BK7")  # RoughIron(0.25)
)

surface = Intersect(Box(Point3D(-10, -10, -10), Point3D(10, 10, -0.015)),
                    Subtract(Cylinder(0.1999,
Example #8
0
from raysect.optical.material.emitter import Checkerboard
from raysect.optical.library import schott

from raysect.primitive import Box


# Import the new lens classes
from raysect.primitive.lens.spherical import *

rotation = 90.0

# Instantiate world object
world = World()

# Create lens objects
BiConvex(0.0254, 0.0052, 0.0506, 0.0506, parent=world, transform=translate(0.02, 0.02, 0) * rotate(rotation, 0.0, 0.0), material=schott("N-BK7"))
BiConcave(0.0254, 0.0030, 0.052, 0.052, parent=world, transform=translate(-0.02, 0.02, 0) * rotate(rotation, 0.0, 0.0), material=schott("N-BK7"))
PlanoConvex(0.0254, 0.0053, 0.0258, parent=world, transform=translate(0.02, -0.02, 0) * rotate(rotation, 0.0, 0.0), material=schott("N-BK7"))
PlanoConcave(0.0254, 0.0035, 0.0257, parent=world, transform=translate(-0.02, -0.02, 0) * rotate(rotation, 0.0, 0.0), material=schott("N-BK7"))
Meniscus(0.0254, 0.0036, 0.0321, 0.0822, parent=world, transform=translate(0, 0, 0) * rotate(rotation, 0.0, 0.0), material=schott("N-BK7"))

# Background Checkerboard
Box(Point3D(-50.0, -50.0, 0.1), Point3D(50.0, 50.0, 0.2), world, material=Checkerboard(0.01, d65_white, d65_white, 0.4, 0.8))

# Instantiate camera object, and configure its settings.
plt.ion()
camera = PinholeCamera((512, 512), fov=45, parent=world, transform=translate(0, 0, -0.1) * rotate(0, 0, 0))
camera.pixel_samples = 100
camera.spectral_rays = 1
camera.spectral_bins = 20
Example #9
0
        material=UniformSurfaceEmitter(d65_white, 250))

    return node


world = World()


# construct diffuse floor surface
floor = Box(Point3D(-1000, -0.1, -1000), Point3D(1000, 0, 1000),
            parent=world, material=Lambert())


# construct prism from utility method
prism = equilateral_prism(0.06, 0.15, parent=world,
                          material=schott("SF11"), transform=translate(0, 0.0 + 1e-6, 0))


# Curved target screen for collecting rainbow light
screen = Intersect(
    Box(Point3D(-10, -10, -10), Point3D(10, 10, 0)),
    Subtract(Cylinder(0.22, 0.15),
             Cylinder(0.20, 0.16, transform=translate(0, 0, -0.005)),
             transform=rotate(0, 90, 0)),
    parent=world,
    material=Lambert()
)


# construct main collimated light source
prism_light = light_box(parent=world,
Example #10
0
enclosure_thickness = 0.001 + padding
glass_thickness = 0.003

light_box = Node(parent=world)

enclosure_outer = Box(Point3D(-0.10 - enclosure_thickness, -0.02 - enclosure_thickness, -0.10 - enclosure_thickness),
                      Point3D(0.10 + enclosure_thickness, 0.0, 0.10 + enclosure_thickness))
enclosure_inner = Box(Point3D(-0.10 - padding, -0.02 - padding, -0.10 - padding),
                      Point3D(0.10 + padding, 0.001, 0.10 + padding))
enclosure = Subtract(enclosure_outer, enclosure_inner, material=Lambert(ConstantSF(0.2)), parent=light_box)

glass_outer = Box(Point3D(-0.10, -0.02, -0.10),
                  Point3D(0.10, 0.0, 0.10))
glass_inner = Box(Point3D(-0.10 + glass_thickness, -0.02 + glass_thickness, -0.10 + glass_thickness),
                  Point3D(0.10 - glass_thickness, 0.0 - glass_thickness, 0.10 - glass_thickness))
glass = Subtract(glass_outer, glass_inner, material=schott("N-BK7"), parent=light_box)

emitter = Box(Point3D(-0.10 + glass_thickness + padding, -0.02 + glass_thickness + padding, -0.10 + glass_thickness + padding),
              Point3D(0.10 - glass_thickness - padding, 0.0 - glass_thickness - padding, 0.10 - glass_thickness - padding),
              material=UniformVolumeEmitter(d65_white, 50), parent=light_box)


fov = 45
num_pixels = 256


# Launch rays using the same geometry calculations as a pinhole camera
image_width = 2 * tan(PI / 180 * 0.5 * fov)
image_delta = image_width / num_pixels

image_start_x = 0.5 * num_pixels * image_delta
Example #11
0
world = World()


# Background checkerboard lightsource
Box(Point3D(-10, -10, 4.0), Point3D(10, 10, 4.1), world,
    material=Checkerboard(1, d65_white, d65_white, 0.2, 0.8))


# Build a CSG primitive from a number of basic underlying primitives
cyl_x = Cylinder(1, 4.2, transform=rotate(90, 0, 0)*translate(0, 0, -2.1))
cyl_y = Cylinder(1, 4.2, transform=rotate(0, 90, 0)*translate(0, 0, -2.1))
cyl_z = Cylinder(1, 4.2, transform=rotate(0, 0, 0)*translate(0, 0, -2.1))
cube = Box(Point3D(-1.5, -1.5, -1.5), Point3D(1.5, 1.5, 1.5))
sphere = Sphere(2.0)
target = Intersect(sphere, cube, parent=world, transform=translate(0, 0, 0)*rotate(0, 0, 0),
                   material=schott("N-BK7"))


# create and setup the camera
camera = PinholeCamera((256, 256), fov=45, parent=world, transform=translate(0, 0, -6) * rotate(0, 0, 0))
camera.spectral_rays = 9
camera.spectral_bins = 30
rgb = camera.pipelines[0]

# for each frame rotate the CSG primitive and re-render
num_frames = 25*20
full_rotation = 360
for frame in range(num_frames):

    print("Rendering frame {}:".format(frame))
Example #12
0
Sphere(0.5, world, transform=translate(1.2, 0.5001, 0.6), material=Gold())
Sphere(0.5, world, transform=translate(0.6, 0.5001, -0.6), material=Silver())
Sphere(0.5, world, transform=translate(0, 0.5001, 0.6), material=Copper())
Sphere(0.5, world, transform=translate(-0.6, 0.5001, -0.6), material=Titanium())
Sphere(0.5, world, transform=translate(-1.2, 0.5001, 0.6), material=Aluminium())
Sphere(0.5, world, transform=translate(0, 0.5001, -1.8), material=Beryllium())

Box(Point3D(-100, -0.1, -100), Point3D(100, 0, 100), world, material=Lambert(ConstantSF(1.0)))
Cylinder(3.0, 8.0, world, transform=translate(4, 8, 0) * rotate(90, 0, 0), material=UniformSurfaceEmitter(d65_white, 1.0))

camera = Node(parent=world, transform=translate(0, 4, -3.5) * rotate(0, -48, 180))

# b = BiConvex(0.0508, 0.0036, 1.0295, 1.0295, parent=camera, transform=translate(0, 0, 0.1), material=schott("N-BK7"))
# b = BiConvex(0.0508, 0.0062, 0.205, 0.205, parent=camera, transform=translate(0, 0, 0.05), material=schott("N-BK7"))
lens = BiConvex(0.0508, 0.0144, 0.0593, 0.0593, parent=camera, transform=translate(0, 0, 0.0536), material=schott("N-BK7"))

body = Subtract(
        Subtract(
            Cylinder(0.0260, 0.07, transform=translate(0, 0, 0)),
            Cylinder(0.0255, 0.06, transform=translate(0, 0, 0.005))
        ),
    Cylinder(0.015, 0.007, transform=translate(0, 0, 0.064)),
    parent=camera,
    transform=translate(0, 0, -0.01),
    material=AbsorbingSurface()
)

aperture = Cylinder(0.016, 0.0009, parent=camera, transform=translate(0, 0, 0.064), material=NullMaterial())

rgb = RGBPipeline2D(display_unsaturated_fraction=0.98, name="sRGB")