<commit_before>import numpy as np
from matplotlib.pyplot import imshow, imsave, show, ion, ioff, clf, figure, draw, pause
from multiprocessing import Pool, Queue, Pipe, Process, cpu_count, Manager
from time import time

from raysect.optical.colour import resample_ciexyz, spectrum_to_ciexyz, ciexyz_to_srgb
from raysect.optical import World, translate, rotate, Point, Vector, Ray, d65_white, ConstantSF, SampledSF
from raysect.optical.material.emitter import UniformVolumeEmitter, UniformSurfaceEmitter, Checkerboard
from raysect.primitive import Sphere, Box, Cylinder, Union, Intersect, Subtract
from raysect.optical.material.glass_libraries import schott

# kludge to fix matplotlib 1.4 ion() idiocy
import sys
sys.ps1 = 'SOMETHING'


def display(rgb_frame):

    clf()
    imshow(rgb_frame, aspect="equal", origin="upper")
    draw()
    show()

    # workaround for interactivity for QT backend
    pause(0.1)


def producer(pixels, image_start_x, image_start_y, image_delta,
             min_wavelength, max_wavelength, spectral_samples, max_depth,
             task_queue):

    for y in range(0, pixels[1]):

        # submit tasks for current line
        for x in range(0, pixels[0]):

            # calculate ray parameters
            origin = Point(0, 0, -4)
            direction = Vector(image_start_x - image_delta * x,
                               image_start_y - image_delta * y,
                               1.0).normalise()

            # build task
            ray = Ray(origin, direction, min_wavelength=min_wavelength, max_wavelength=max_wavelength, num_samples=spectral_samples, max_depth=max_depth)
            task = ((x, y), ray)

            # submit task
            task_queue.put(task)


def worker(pid, world, task_queue, result_queue):

    while True:

        # request next task
        task = task_queue.get()

        # have we been commanded to shutdown?
        if task == "STOP":
            break

        # decode task
        (id, ray) = task

        # trace
        spectrum = ray.trace(world)

        # encode result and send
        result = (id, spectrum)
        result_queue.put(result)


# setup render
fov = 60
pixels = (200, 100)
min_wavelength, max_wavelength, spectral_samples = 375.0, 740.0, 20
max_depth = 20
display_update_time = 10
num_processes = cpu_count()
ion()

# world
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(Point(-1.5, -1.5, -1.5), Point(1.5, 1.5, 1.5))
sphere = Sphere(2.0)

# Intersect(sphere, cube, world, translate(-2.1,2.1,2.5)*rotate(30, -20, 0), schott("N-LAK9"))
# Intersect(sphere, cube, world, translate(2.1,2.1,2.5)*rotate(-30, -20, 0), schott("SF6"))
# Intersect(sphere, cube, world, translate(2.1,-2.1,2.5)*rotate(-30, 20, 0), schott("LF5G19"))
# Intersect(sphere, cube, world, translate(-2.1,-2.1,2.5)*rotate(30, 20, 0), schott("N-BK7"))

# Sphere(2.0, world, translate(-2.1,2.1,2.5)*rotate(30, -20, 0), schott("N-LAK9"))
# Sphere(2.0, world, translate(2.1,2.1,2.5)*rotate(-30, -20, 0), schott("SF6"))
# Sphere(2.0, world, translate(2.1,-2.1,2.5)*rotate(-30, 20, 0), schott("LF5G19"))
# Sphere(2.0, world, translate(-2.1,-2.1,2.5)*rotate(30, 20, 0), schott("N-BK7"))

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"))

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

# setup queues
#task_queue = Queue()
#result_queue = Queue()
<commit_msg>Added a few test objects.<commit_after>import numpy as np
from matplotlib.pyplot import imshow, imsave, show, ion, ioff, clf, figure, draw, pause
from multiprocessing import Pool, Queue, Pipe, Process, cpu_count, Manager
from time import time

from raysect.optical.colour import resample_ciexyz, spectrum_to_ciexyz, ciexyz_to_srgb
from raysect.optical import World, translate, rotate, Point, Vector, Ray, d65_white, ConstantSF, SampledSF
from raysect.optical.material.emitter import UniformVolumeEmitter, UniformSurfaceEmitter, Checkerboard
from raysect.primitive import Sphere, Box, Cylinder, Union, Intersect, Subtract
from raysect.optical.material.glass_libraries import schott

# kludge to fix matplotlib 1.4 ion() idiocy
import sys
sys.ps1 = 'SOMETHING'


def display(rgb_frame):

    clf()
    imshow(rgb_frame, aspect="equal", origin="upper")
    draw()
    show()

    # workaround for interactivity for QT backend
    pause(0.1)


def producer(pixels, image_start_x, image_start_y, image_delta,
             min_wavelength, max_wavelength, spectral_samples, max_depth,
             task_queue):

    for y in range(0, pixels[1]):

        # submit tasks for current line
        for x in range(0, pixels[0]):

            # calculate ray parameters
            origin = Point(0, 0, -4)
            direction = Vector(image_start_x - image_delta * x,
                               image_start_y - image_delta * y,
                               1.0).normalise()

            # build task
            ray = Ray(origin, direction, min_wavelength=min_wavelength, max_wavelength=max_wavelength, num_samples=spectral_samples, max_depth=max_depth)
            task = ((x, y), ray)

            # submit task
            task_queue.put(task)


def worker(pid, world, task_queue, result_queue):

    while True:

        # request next task
        task = task_queue.get()

        # have we been commanded to shutdown?
        if task == "STOP":
            break

        # decode task
        (id, ray) = task

        # trace
        spectrum = ray.trace(world)

        # encode result and send
        result = (id, spectrum)
        result_queue.put(result)


# setup render
fov = 60
pixels = (1024, 1024)
min_wavelength, max_wavelength, spectral_samples = 375.0, 740.0, 20
max_depth = 20
display_update_time = 10
num_processes = cpu_count()
ion()

# world
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(Point(-1.5, -1.5, -1.5), Point(1.5, 1.5, 1.5))
sphere = Sphere(2.0)

# Intersect(sphere, cube, world, translate(-2.1,2.1,2.5)*rotate(30, -20, 0), schott("N-LAK9"))
# Intersect(sphere, cube, world, translate(2.1,2.1,2.5)*rotate(-30, -20, 0), schott("SF6"))
# Intersect(sphere, cube, world, translate(2.1,-2.1,2.5)*rotate(-30, 20, 0), schott("LF5G19"))
# Intersect(sphere, cube, world, translate(-2.1,-2.1,2.5)*rotate(30, 20, 0), schott("N-BK7"))

# Sphere(2.0, world, translate(-2.1,2.1,2.5)*rotate(30, -20, 0), schott("N-LAK9"))
# Sphere(2.0, world, translate(2.1,2.1,2.5)*rotate(-30, -20, 0), schott("SF6"))
# Sphere(2.0, world, translate(2.1,-2.1,2.5)*rotate(-30, 20, 0), schott("LF5G19"))
# Sphere(2.0, world, translate(-2.1,-2.1,2.5)*rotate(30, 20, 0), schott("N-BK7"))

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"))

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

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(65,30,0), schott("N-BK7"))

# setup queues
{'fraction_non_alphanumeric': 0.16273639971982257, 'fraction_numerical': 0.07074480504319403, 'mean_word_length': 3.7123212321232124, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1498063', 'n_tokens_mistral': 3514, 'n_tokens_neox': 3165, 'n_words': 737}