def equilateral_prism(width=1.0, height=1.0, parent=None, transform=None, material=None): half_width = width / 2 mid_point = half_width * tan(60 / 180 * pi) / 2 centre = Box(Point3D(-half_width * 1.001, 0, 0), Point3D(half_width * 1.001, height, width)) left = Box(Point3D(0, -height * 0.001, -width * 0.001), Point3D(width, height * 1.001, 2 * width), transform=translate(half_width, 0, 0) * rotate(30, 0, 0)) right = Box(Point3D(-width, -height * 0.001, -width * 0.001), Point3D(0.0, height * 1.001, 2 * width), transform=translate(-half_width, 0, 0) * rotate(-30, 0, 0)) csg_prism = Subtract(Subtract(centre, left), right, parent=parent, transform=transform * translate(0, 0, -mid_point), material=material) return csg_prism
def place_source(self): # self.source = Cylinder(radius=self.vessel_in_rad-0.002, height=self.vessel_width, # material=self.PlasmaEmit(shape=self.plasma_shape, count=self.plasma_count, center=self.plasma_center, # width=self.plasma_width, power_gain=self.plasma_power_gain, flatlen=self.plasma_flat), # parent=self.world, transform=translate(0, 0, 0) * rotate(0, 0, 0), name='PlasmaSource') self.source = Cylinder(radius=self.vessel_in_rad - 0.0015, height=self.vessel_width, parent=self.world, transform=translate(0, 0, 0) * rotate(0, 0, 0), name='PlasmaSource') self.lid_back = Cylinder( radius=self.vessel_in_rad + 0.002, height=0.001, material=AbsorbingSurface(), parent=self.world, transform=translate(0, 0, self.vessel_width + 0.0005) * rotate(0, 0, 0)) self.lid_front = Cylinder(radius=self.vessel_in_rad + 0.002, height=0.001, material=AbsorbingSurface(), parent=self.world, transform=translate(0, 0, -0.0015) * rotate(0, 0, 0))
def get_proj_matrix(self, pixel_side=60, out_file="proj_matrix1"): geo_matrix = np.empty((32, 0)) for pixel in range(pixel_side * pixel_side): print('Progress: ' + str(round(100 * pixel / (pixel_side * pixel_side), 1)) + " %") self.world = World() self.add_isttok() self.pixel_source = Cylinder(radius=self.vessel_in_rad - 0.0015, height=self.vessel_width, parent=self.world, transform=translate(0, 0, 0) * rotate(0, 0, 0), name='PlasmaSource') one_pixel = PixelMaterial(pixel_side=pixel_side, pixel_id=pixel, print=False) self.pixel_source.material = one_pixel self.simulate_rays() column = np.hstack((self.top_data, self.out_data)).reshape((32, 1)) geo_matrix = np.hstack((geo_matrix, column)) np.save(out_file, geo_matrix)
def place_single_pixel(self, pixel_id, pixel_side=60): pixel_material = PixelMaterial(pixel_side=pixel_side, pixel_id=pixel_id) self.pixel_source = Cylinder(radius=self.vessel_in_rad - 0.0015, height=self.vessel_width, parent=self.world, transform=translate(0, 0, 0) * rotate(0, 0, 0), name='PlasmaSource', material=pixel_material)
def equilateral_prism(width=1.0, height=1.0, parent=None, transform=None, material=None): half_width = width / 2 mid_point = half_width * tan(60/180*pi) / 2 centre = Box(Point3D(-half_width * 1.001, 0, 0), Point3D(half_width * 1.001, height, width)) left = Box(Point3D(0, -height * 0.001, -width * 0.001), Point3D(width, height * 1.001, 2 * width), transform=translate(half_width, 0, 0) * rotate(30, 0, 0)) right = Box(Point3D(-width, -height * 0.001, -width * 0.001), Point3D(0.0, height * 1.001, 2 * width), transform=translate(-half_width, 0, 0) * rotate(-30, 0, 0)) csg_prism = Subtract(Subtract(centre, left), right, parent=parent, transform=transform * translate(0, 0, -mid_point), material=material) return csg_prism
def place_plasma(self, shape='gaussian', emissiv_gain=1.0, mean=None, cov=None): fourier_plasma = PlasmaProf(shape=shape, emissiv_gain=emissiv_gain, mean=mean, cov=cov) # print(type(fourier_plasma)) self.plasma_source = Cylinder(radius=self.vessel_in_rad - 0.0015, height=self.vessel_width, parent=self.world, transform=translate(0, 0, 0) * rotate(0, 0, 0), name='PlasmaSource', material=fourier_plasma)
from matplotlib.pyplot import * from numpy import array from raysect.primitive import Sphere, Box, Cylinder, Union, Intersect, Subtract from raysect.optical import World, translate, rotate, Point3D, d65_white, InterpolatedSF from raysect.optical.material.emitter import UniformSurfaceEmitter, Checkerboard from raysect.optical.material.dielectric import Dielectric, Sellmeier from raysect.optical.library import schott from raysect.optical.observer import PinholeCamera, RGBPipeline2D, SpectralPowerPipeline2D 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)) # 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")) # Union(Union(cyl_x, cyl_y), cyl_z, world) Intersect(Intersect(cyl_x, cyl_y), cyl_z, world) # Intersect(cyl_x, cyl_y, world) # Union(cyl_y, cyl_z, world) # Union(cyl_z, cyl_x, world) camera = PinholeCamera((256, 256), parent=world, transform=translate(0, 0, -4) * rotate(0, 0, 0)) from raysect.vtk import visualise_scenegraph visualise_scenegraph(camera)
------------------------------------------------------- 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(
class CosGlow(InhomogeneousVolumeEmitter): def emission_function(self, point, direction, spectrum, world, ray, primitive, to_local, to_world): wvl_centre = 0.5 * (spectrum.max_wavelength + spectrum.min_wavelength) wvl_range = spectrum.min_wavelength - spectrum.max_wavelength shift = 2 * (spectrum.wavelengths - wvl_centre) / wvl_range radius = sqrt(point.x**2 + point.y**2) spectrum.samples += cos((shift + 5) * radius)**4 return spectrum # scene world = World() emitter = Box(Point3D(-1, -1, -0.25), Point3D(1, 1, 0.25), material=CosGlow(), parent=world, transform=translate(0, 1, 0) * rotate(30, 0, 0)) floor = Box(Point3D(-100, -0.1, -100), Point3D(100, 0, 100), world, material=RoughTitanium(0.1)) # camera rgb_pipeline = RGBPipeline2D(display_update_time=5) sampler = RGBAdaptiveSampler2D(rgb_pipeline, min_samples=100, fraction=0.2) camera = PinholeCamera((512, 512), parent=world, transform=translate(0, 4, -3.5) * rotate(0, -45, 0), pipelines=[rgb_pipeline], frame_sampler=sampler) camera.spectral_bins = 15 camera.spectral_rays = 1 camera.pixel_samples = 200 camera.render_engine = MulticoreEngine(4) # integration resolution emitter.material.integrator.step = 0.05 # start ray tracing
def emission_function(self, spectrum, cosine, back_face): spectrum.samples[:] = 1.0 spectrum.samples[spectrum.wavelengths > 500] = 2 * cosine return spectrum # 1. Create Primitives # -------------------- # Box defining the floor ground = Box(lower=Point3D(-100, -14.2, -100), upper=Point3D(100, -14.1, 100), material=RoughAluminium(0.05)) # Box defining the isotropic emitter emitterIsotropic = Box(lower=Point3D(-25, -10, -10), upper=Point3D(-5, 10, 10), material=UniformSurfaceEmitter(d65_white), transform=rotate(0, 0, 0)) # Box defining the anisotropic emitter emitterAnisotropic = Box(lower=Point3D(5, -10, -10), upper=Point3D(25, 10, 10), material=BlueYellowEmitter(), transform=rotate(0, 0, 0)) # 2. Add Observer # --------------- # camera camera = PinholeCamera((384, 384), transform=translate(0, 0, -80)) camera.fov = 45 camera.pixel_samples = 250 camera.pipelines[0].accumulate = False
white_reflectivity = InterpolatedSF(wavelengths, white) red_reflectivity = InterpolatedSF(wavelengths, red) green_reflectivity = InterpolatedSF(wavelengths, green) # define light spectrum light_spectrum = InterpolatedSF(array([400, 500, 600, 700]), array([0.0, 8.0, 15.6, 18.4])) # set-up scenegraph world = World() # enclosing box enclosure = Node(world) e_back = Box(Point3D(-1, -1, 0), Point3D(1, 1, 0), parent=enclosure, transform=translate(0, 0, 1) * rotate(0, 0, 0), material=Lambert(white_reflectivity)) e_bottom = Box(Point3D(-1, -1, 0), Point3D(1, 1, 0), parent=enclosure, transform=translate(0, -1, 0) * rotate(0, -90, 0), # material=m) material=Lambert(white_reflectivity)) e_top = Box(Point3D(-1, -1, 0), Point3D(1, 1, 0), parent=enclosure, transform=translate(0, 1, 0) * rotate(0, 90, 0), material=Lambert(white_reflectivity)) e_left = Box(Point3D(-1, -1, 0), Point3D(1, 1, 0), parent=enclosure,
from raysect.optical.observer import FibreOptic, PowerPipeline0D, SpectralPowerPipeline0D from raysect.optical.material import Lambert, Checkerboard from raysect.optical.library import schott from raysect.primitive import Sphere, Box from raysect.core.math import Vector3D # 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. Build Scenegraph # ------------------- world = World() sphere.parent = world ground.parent = world emitter.parent = world
# 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,
wvl_centre = 0.5 * (spectrum.max_wavelength + spectrum.min_wavelength) wvl_range = spectrum.min_wavelength - spectrum.max_wavelength shift = 2 * (spectrum.wavelengths - wvl_centre) / wvl_range radius = sqrt(point.x**2 + point.y**2) spectrum.samples += cos((shift + 5) * radius)**4 return spectrum # scene world = World() # boxes box_unshifted = Box( Point3D(-1, -1, -0.25), Point3D(1, 1, 0.25), material=CosGlow(), parent=world, transform=translate(3.2, 1, 0) * rotate(-30, 0, 0) ) box_down_shifted = Box( Point3D(-1, -1, -0.25), Point3D(1, 1, 0.25), material=VolumeTransform(CosGlow(), translate(0, 0.5, 0)), parent=world, transform=translate(1.1, 1, 0.8) * rotate(-10, 0, 0) ) box_up_shifted = Box( Point3D(-1, -1, -0.25), Point3D(1, 1, 0.25), material=VolumeTransform(CosGlow(), translate(0, -0.5, 0)), parent=world, transform=translate(-1.1, 1, 0.8) * rotate(10, 0, 0) ) box_rotated = Box(
from raysect.primitive import Sphere, Box, Cylinder from raysect.optical.observer import PinholeCamera, RGBPipeline2D from raysect.optical.material import UniformSurfaceEmitter from raysect.optical.library import * rough_max = 0.5 world = World() # glass spheres angle = 6 distance = 3 radius = 0.15 Sphere(radius, world, transform=rotate(-4 * angle, 0, 0) * translate(0, radius + 0.00001, distance), material=Aluminium()) Sphere(radius, world, transform=rotate(-3 * angle, 0, 0) * translate(0, radius + 0.00001, distance), material=RoughAluminium(0.125 * rough_max)) Sphere(radius, world, transform=rotate(-2 * angle, 0, 0) * translate(0, radius + 0.00001, distance), material=RoughAluminium(0.25 * rough_max)) Sphere(radius, world, transform=rotate(-1 * angle, 0, 0) * translate(0, radius + 0.00001, distance), material=RoughAluminium(0.375 * rough_max)) Sphere(radius, world, transform=rotate(0 * angle, 0, 0) * translate(0, radius + 0.00001, distance), material=RoughAluminium(0.5 * rough_max)) Sphere(radius, world, transform=rotate(1 * angle, 0, 0) * translate(0, radius + 0.00001, distance), material=RoughAluminium(0.625 * rough_max)) Sphere(radius, world, transform=rotate(2 * angle, 0, 0) * translate(0, radius + 0.00001, distance), material=RoughAluminium(0.750 * rough_max)) Sphere(radius, world, transform=rotate(3 * angle, 0, 0) * translate(0, radius + 0.00001, distance), material=RoughAluminium(0.875 * rough_max)) Sphere(radius, world, transform=rotate(4 * angle, 0, 0) * translate(0, radius + 0.00001, distance), material=RoughAluminium(1.0 * rough_max)) # metal spheres angle = 6 distance = 3.6 radius = 0.15 Sphere(radius, world, transform=rotate(-4 * angle, 0, 0) * translate(0, radius + 0.00001, distance), material=Copper())
from raysect.optical.library import schott from raysect.optical.observer import RGBPipeline2D, BayerPipeline2D, TargettedCCDArray, CCDArray, RGBAdaptiveSampler2D from raysect.optical.colour import ciexyz_x, ciexyz_y, ciexyz_z world = World() 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),
from raysect.optical import World, translate, rotate, Point3D, d65_white, ConstantSF from raysect.optical.observer import PinholeCamera from raysect.optical.library import Gold, Silver, Copper, Titanium, Aluminium from raysect.optical.material import Lambert, UniformSurfaceEmitter world = World() 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()) 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 = PinholeCamera((512, 512), parent=world, transform=translate(0, 4, -3.5) * rotate(0, -48, 0)) camera.spectral_bins = 15 camera.pixel_samples = 100 # start ray tracing ion() for p in range(1, 1000): print("Rendering pass {}...".format(p)) camera.observe() camera.pipelines[0].save("demo_metal_{}_samples.png".format(p)) print() # display final result ioff()
green_attn = array([0.0, 0.0, 1.0, 1.0, 0.0, 0.0]) * 0.85 blue_attn = array([1.0, 1.0, 0.0, 0.0, 0.0, 0.0]) * 0.98 yellow_attn = array([0.0, 0.0, 1.0, 1.0, 1.0, 1.0]) * 0.85 cyan_attn = array([1.0, 1.0, 1.0, 1.0, 0.0, 0.0]) * 0.85 purple_attn = array([1.0, 1.0, 0.0, 0.0, 1.0, 1.0]) * 0.95 red_glass = Dielectric(index=ConstantSF(1.4), transmission=InterpolatedSF(wavelengths, red_attn)) green_glass = Dielectric(index=ConstantSF(1.4), transmission=InterpolatedSF(wavelengths, green_attn)) blue_glass = Dielectric(index=ConstantSF(1.4), transmission=InterpolatedSF(wavelengths, blue_attn)) yellow_glass = Dielectric(index=ConstantSF(1.4), transmission=InterpolatedSF(wavelengths, yellow_attn)) cyan_glass = Dielectric(index=ConstantSF(1.4), transmission=InterpolatedSF(wavelengths, cyan_attn)) purple_glass = Dielectric(index=ConstantSF(1.4), transmission=InterpolatedSF(wavelengths, purple_attn)) Sphere(1000, world, material=UniformSurfaceEmitter(d65_white, 1.0)) node = Node(parent=world, transform=rotate(0, 0, 90)) Box(Point3D(-0.5, 0, -2.5), Point3D(0.5, 0.25, 0.5), node, rotate(0, 0, 0) * translate(0, 1, -0.500001), red_glass) Box(Point3D(-0.5, 0, -2.5), Point3D(0.5, 0.25, 0.5), node, rotate(0, 0, 60) * translate(0, 1, -0.500001), yellow_glass) Box(Point3D(-0.5, 0, -2.5), Point3D(0.5, 0.25, 0.5), node, rotate(0, 0, 120) * translate(0, 1, -0.500001), green_glass) Box(Point3D(-0.5, 0, -2.5), Point3D(0.5, 0.25, 0.5), node, rotate(0, 0, 180) * translate(0, 1, -0.500001), cyan_glass) Box(Point3D(-0.5, 0, -2.5), Point3D(0.5, 0.25, 0.5), node, rotate(0, 0, 240) * translate(0, 1, -0.500001), blue_glass) Box(Point3D(-0.5, 0, -2.5), Point3D(0.5, 0.25, 0.5), node, rotate(0, 0, 300) * translate(0, 1, -0.500001), purple_glass) camera = PinholeCamera((256, 256), fov=45, parent=world, transform=translate(0, 0, -6.5) * rotate(0, 0, 0)) ion() camera.ray_max_depth = 500 camera.ray_extinction_prob = 0.01 camera.pixel_samples = 100 camera.spectral_rays = 1 camera.spectral_bins = 21
def check_scene(self, max_iter=200): self.vessel.material = Lambert(blue) self.camera_outer.material = Lambert(yellow) self.camera_top.material = Lambert(yellow) self.source.material = Lambert(green) self.top_pinhole.material = Lambert(green) self.out_pinhole.material = Lambert(green) # cube walls bottom = Box(lower=Point3D(-0.99, -1.02, -0.99), upper=Point3D(0.99, -1.01, 0.99), parent=self.world, material=Lambert(red)) # top = Box(lower=Point3D(-0.99, 1.01, -0.99), upper=Point3D(0.99, 1.02, 0.99), parent=self.world, # material=Lambert(red)) left = Box(lower=Point3D(1.01, -0.99, -0.99), upper=Point3D(1.02, 0.99, 0.99), parent=self.world, material=Lambert(yellow)) # right = Box(lower=Point3D(-1.02, -0.99, -0.99), upper=Point3D(-1.01, 0.99, 0.99), parent=self.world, # material=Lambert(purple)) back = Box(lower=Point3D(-0.99, -0.99, 1.01), upper=Point3D(0.99, 0.99, 1.02), parent=self.world, material=Lambert(orange)) # various wall light sources light_front = Box(lower=Point3D(-1.5, -1.5, -10.1), upper=Point3D(1.5, 1.5, -10), parent=self.world, material=UniformSurfaceEmitter(d65_white, 1.0)) light_top = Box(lower=Point3D(-0.99, 1.01, -0.99), upper=Point3D(0.99, 1.02, 0.99), parent=self.world, material=UniformSurfaceEmitter(d65_white, 1.0), transform=translate(0, 1.0, 0)) light_bottom = Box(lower=Point3D(-0.99, -3.02, -0.99), upper=Point3D(0.99, -3.01, 0.99), parent=self.world, material=UniformSurfaceEmitter(d65_white, 1.0), transform=translate(0, 1.0, 0)) light_right = Box(lower=Point3D(-1.92, -0.99, -0.99), upper=Point3D(-1.91, 0.99, 0.99), parent=self.world, material=UniformSurfaceEmitter(d65_white, 1.0)) light_left = Box(lower=Point3D(1.91, -0.99, -0.99), upper=Point3D(1.92, 0.99, 0.99), parent=self.world, material=UniformSurfaceEmitter(d65_white, 1.0)) # Process the ray-traced spectra with the RGB pipeline. rgb = RGBPipeline2D() # camera pix = 1000 camera = PinholeCamera( (pix, pix), pipelines=[rgb], transform=translate(-0.01, 0.0, -0.25) * rotate(0, 0, 0)) # camera = PinholeCamera((pix, pix), pipelines=[rgb], transform=translate(0.0, 0.0, 0.4) * rotate(180, 0, 0)) # top view # camera = PinholeCamera((pix, pix), pipelines=[rgb], transform=translate(0.0, self.vessel_out_rad+0.15, self.vessel_width/2)*rotate(0, -90, 0)) # prof camera = PinholeCamera( (pix, pix), pipelines=[rgb], transform=translate(-0.13, 0.13, -0.2) * rotate(-25, -25.0, 0)) # camera top side # camera = PinholeCamera((pix, pix), pipelines=[rgb], transform=translate(self.x_shift_top, self.top_px_first_y+0.0004, self.top_px_z-self.cam_in_radius+0.005)*rotate(0, 0, 0)) # camera top down-up # camera = PinholeCamera((pix, pix), pipelines=[rgb], transform=translate(self.x_shift_top, self.top_px_first_y-0.01, self.vessel_width/2)*rotate(0, 90, 0)) # camera top up-down # camera = PinholeCamera((pix, pix), pipelines=[rgb], transform=translate(self.x_shift_top-0.004, self.top_px_first_y+self.lid_top+self.tube_height-0.01, self.vessel_width/2)*rotate(0, -90, 0)) # camera out side # camera = PinholeCamera((pix, pix), pipelines=[rgb], transform=translate(-self.vessel_out_rad-0.015, 0.000, self.vessel_width/2-self.cam_in_radius/2+0.0001)) # camera out down-up # camera = PinholeCamera((pix, pix), pipelines=[rgb], transform=translate(self.out_px_first_x+0.005+0.005, 0.0, self.vessel_width/2)*rotate(90, 0, 0)) # camera out up-down # camera = PinholeCamera((pix, pix), pipelines=[rgb], transform=translate(-self.vessel_out_rad-self.tube_height-0.01, 0.0, self.vessel_width/2-0.005)*rotate(-90, 0, 0)) # camera - pixel sampling settings camera.fov = 60 # 45 camera.pixel_samples = 10 # camera - ray sampling settings camera.spectral_rays = 1 camera.spectral_bins = 25 camera.parent = self.world plt.ion() p = 1 while not camera.render_complete: print("Rendering pass {}...".format(p)) camera.observe() print() p += 1 if p > max_iter: break plt.ioff() rgb.display()
the cartesian hit point of the ray with the materials in the scene (rabit and floor) is recorded. In Figure 1 the 3D hit point for each ray in the camera is plotted in 3D space. In Figure 2 the z coordinate of each hit point is scaled and plotted to indicate distance from the camera. Both methods allow simple visualisation of a scene and extraction of intersection geometry data. Bunny model source: Stanford University Computer Graphics Laboratory http://graphics.stanford.edu/data/3Dscanrep/ Converted to obj format using MeshLab """ world = World() mesh_path = path.join(path.dirname(__file__), "../resources/stanford_bunny.rsm") mesh = Mesh.from_file(mesh_path, parent=world, transform=rotate(180, 0, 0)) # 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) glass_outer = Box(Point3D(-0.10, -0.02, -0.10),
from raysect.optical import World, translate, rotate, Point3D, d65_white from raysect.optical.observer import PinholeCamera, RGBPipeline2D from raysect.optical.material import Lambert, Checkerboard from raysect.optical.library import schott from raysect.primitive import Sphere, Box # 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))
wvl_centre = 0.5 * (spectrum.max_wavelength + spectrum.min_wavelength) wvl_range = spectrum.min_wavelength - spectrum.max_wavelength shift = 2 * (spectrum.wavelengths - wvl_centre) / wvl_range radius = sqrt(point.x**2 + point.y**2) spectrum.samples += cos((shift + 5) * radius)**4 return spectrum # scene world = World() emitter = Box(Point3D(-1, -1, -0.25), Point3D(1, 1, 0.25), material=CosGlow(), parent=world, transform=translate(0, 1, 0) * rotate(30, 0, 0)) floor = Box(Point3D(-100, -0.1, -100), Point3D(100, 0, 100), world, material=RoughTitanium(0.1)) # camera rgb_pipeline = RGBPipeline2D(display_update_time=5) sampler = RGBAdaptiveSampler2D(rgb_pipeline, min_samples=100, fraction=0.2) camera = PinholeCamera((512, 512), parent=world, transform=translate(0, 4, -3.5) * rotate(0, -45, 0), pipelines=[rgb_pipeline], frame_sampler=sampler) camera.spectral_bins = 15 camera.spectral_rays = 1
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))
from raysect.primitive.parabola import Parabola rotation = 90.0 # Instantiate world object world = World() # Create lens objects # Parabola(radius=0.5, height=0.1, parent=world, material=schott("N-BK7"), transform=translate(0.05, 0, 0) * rotate(90, 0, 0)) # Parabola(radius=0.1, height=0.1, parent=world, material=Dielectric(ConstantSF(1.4), ConstantSF(0.01)), transform=translate(0.05, 0, 0) * rotate(0, 0, 0)) # Parabola(radius=0.25, height=0.5, parent=world, material=Gold(), transform=translate(0, 0, 0)*rotate(0, -90, 0)) Parabola(radius=0.1, height=0.2, parent=world, material=schott("N-BK7"), transform=translate(0, 0, 0) * rotate(0, 100, 0)) # Sphere(radius=0.1, parent=world, material=Dielectric(ConstantSF(1.0), ConstantSF(0.02)), transform=translate(0, 0, 0) * rotate(0, 0, 0)) # Parabola(radius=1000, height=0.1, parent=world, material=schott("N-BK7"), transform=translate(0, 0, 0) * rotate(0, 0, 0)) # Parabola(radius=0.1, height=0.05, parent=world, material=Lambert(), transform=translate(0, 0, 0) * rotate(270, 0, 0)) # Background Checkerboard Box(Point3D(-50.0, -50.0, 50), Point3D(50.0, 50.0, 50.1), world, material=Checkerboard(10, d65_white, d65_white, 0.4, 0.8)) # Instantiate camera object, and configure its settings. plt.ion() camera = PinholeCamera((256, 256), fov=45, parent=world,
from raysect.optical import World, translate, rotate from raysect.optical.observer import PinholeCamera from raysect.primitive import Sphere world = World() sphere = Sphere(parent=world, transform=translate(2, 0, 0)) camera = PinholeCamera((256, 256), fov=40, parent=world, transform=translate(0, 0.16, -0.4) * rotate(0, -12, 0)) from raysect_vtk import visualise_scenegraph visualise_scenegraph(camera, focal_distance=3, zoom=0.5)
rad_circle = 50. xsqr = np.linspace(-49.5, 49.5, 100) ** 2 rad = np.sqrt(xsqr[:, None] + xsqr[None, :]) voxel_map = np.zeros((100, 100), dtype=np.int) voxel_map[rad > 50.] = -1 # removing the area outside the circle for i in range(50): voxel_map[(rad < i + 1.) * (rad > i)] = i # mapping multiple grid cells to a single light source rtc.voxel_map = voxel_map # applying a voxel map # now we have only 50 light sources # creating ray transfer pipeline pipeline = RayTransferPipeline2D() # setting up the camera camera = PinholeCamera((256, 256), pipelines=[pipeline], frame_sampler=FullFrameSampler2D(), transform=translate(219., 0, 0) * rotate(90., 0., -90.), parent=world) camera.fov = 90 camera.pixel_samples = 500 camera.min_wavelength = 500. camera.max_wavelength = camera.min_wavelength + 1. camera.spectral_bins = rtc.bins # starting ray tracing camera.observe() # uncomment this to save ray transfer matrix to file # np.save('ray_transfer_map.npy', pipeline.matrix) # let's collapse the ray transfer matrix with some emission profiles # obtaining 30 images for 30 emission profiles
world = World() angle_increments = [-4, -3, -2, -1, 0, 1, 2, 3, 4] roughness = 0.25 colours = [yellow, orange, red_orange, red, purple, blue, light_blue, cyan, green] # coloured metal spheres angle = 6 radius = 0.12 distance = 3.2 for i in range(9): increment = angle_increments[i] Sphere(radius, world, transform=rotate(increment * angle, 0, 0) * translate(0, radius + 0.00001, distance), material=UniformSurfaceEmitter(colours[i])) # diffuse ground plane Box(Point3D(-100, -0.1, -100), Point3D(100, 0, 100), world, material=Lambert(ConstantSF(0.5))) rgb = RGBPipeline2D(name="sRGB") sampler = RGBAdaptiveSampler2D(rgb, ratio=10, fraction=0.2, min_samples=500, cutoff=0.05) # observer camera = PinholeCamera((512, 256), fov=42, parent=world, transform=translate(0, 3.3, 0) * rotate(0, -47, 0), pipelines=[rgb], frame_sampler=sampler) camera.spectral_bins = 25 camera.pixel_samples = 250 # start ray tracing ion()
from raysect.optical.material.emitter import Checkerboard from raysect.optical.library import schott from raysect.primitive import Sphere, Box, Cylinder, Intersect plt.ion() 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
from raysect.optical.library import schott from raysect.optical.observer import PinholeCamera, RGBPipeline2D, SpectralPowerPipeline2D red_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, 0.0, 0.0, 1.0, 1.0])*0.7)) 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))
# 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, transform=rotate(-35.5, 0, 0) * translate(0.10, 0, 0) * rotate(90, 0, 0)) # background light source top_light = Sphere(0.5, parent=world, transform=translate(0, 2, -1), material=UniformSurfaceEmitter(d65_white, scale=2))
from raysect.optical.observer import PinholeCamera, RGBPipeline2D from raysect.optical.material import UniformSurfaceEmitter from raysect.optical.library import * rough_max = 0.5 world = World() # glass spheres angle = 6 distance = 3 radius = 0.15 Sphere(radius, world, transform=rotate(-4 * angle, 0, 0) * translate(0, radius + 0.00001, distance), material=Aluminium()) Sphere(radius, world, transform=rotate(-3 * angle, 0, 0) * translate(0, radius + 0.00001, distance), material=RoughAluminium(0.125 * rough_max)) Sphere(radius, world, transform=rotate(-2 * angle, 0, 0) * translate(0, radius + 0.00001, distance), material=RoughAluminium(0.25 * rough_max)) Sphere(radius, world, transform=rotate(-1 * angle, 0, 0) *
from matplotlib.pyplot import * from numpy import array from raysect.primitive import Sphere, Box, Cylinder, Union, Intersect, Subtract from raysect.optical import World, translate, rotate, Point3D, d65_white, InterpolatedSF from raysect.optical.material.emitter import UniformSurfaceEmitter, Checkerboard from raysect.optical.material.dielectric import Dielectric, Sellmeier from raysect.optical.library import schott from raysect.optical.observer import PinholeCamera, RGBPipeline2D, SpectralPowerPipeline2D world = World() s1 = Sphere(1.0, transform=translate(0, 0, 0.25)) s2 = Sphere(1.0, transform=translate(0, 0, -0.25)) intersection = Intersect(s1, s2, transform=translate(0, 0, 0)) s3 = Sphere(1.0, transform=translate(0, 0.5, 0)) intersection = Union(intersection, s3, world, transform=translate(0.5, 0, 0)) camera = PinholeCamera((256, 256), parent=world, transform=translate(0, 0, -4) * rotate(0, 0, 0)) from raysect_vtk import visualise_scenegraph visualise_scenegraph(camera)
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, 0.12, transform=translate(0, 0, 0.015)), Cylinder(0.1998, 0.13, transform=translate(0, 0, 0.010)), transform=rotate(0, 90, 0)), parent=stand, material=Lambert(ConstantSF(1.0)))
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"))
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)
from raysect.optical import World, translate, rotate from raysect.optical.observer import PinholeCamera from raysect.primitive import Cylinder world = World() cylinder = Cylinder(parent=world, transform=translate(1.5, 0, 0)) camera = PinholeCamera((256, 256), fov=40, parent=world, transform=translate(0, 0.16, -0.4) * rotate(0, -12, 0)) from raysect_vtk import visualise_scenegraph visualise_scenegraph(camera, focal_distance=3, zoom=0.5)
from raysect.primitive import Sphere, Box from raysect.core.math import Vector3D # 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. Build Scenegraph # ------------------- world = World() sphere.parent = world ground.parent = world
diamond_material = Dielectric( Sellmeier(0.3306, 4.3356, 0.0, 0.1750**2, 0.1060**2, 0.0), ConstantSF(0.998)) diamond_material.importance = 2 world = World() base_path = os.path.split(os.path.realpath(__file__))[0] # the diamond diamond = import_obj(os.path.join(base_path, "../resources/diamond.obj"), scaling=0.01, smoothing=False, parent=world, transform=translate(0.0, 0.713001, 0.0) * rotate(-10, 0, 0), material=diamond_material) # floor Box(Point3D(-100, -0.1, -100), Point3D(100, 0, 100), world, material=RoughTitanium(0.1)) # front light Sphere(5, world, transform=translate(1, 8, -10), material=UniformVolumeEmitter(d65_white, 1.0)) # fill light
def add_isttok(self, pixel_samples=1000000): nickel_roughness = 0.23 min_wl = 50 max_wl = 51 # add vessel and cameras self.vessel = import_stl( "../isttok_3d/vessel5_stl.stl", scaling=1, mode='binary', parent=self.world, material=RoughNickel(nickel_roughness), #AbsorbingSurface(), transform=translate(0, 0, 0) * rotate(0, 0, 0)) self.camera_top = import_stl( "../isttok_3d/camera_top3_stl.stl", scaling=1, mode='binary', parent=self.world, material=AbsorbingSurface(), transform=translate( self.x_shift_top, self.y_shift_top + self.tube_height + self.lid_top, self.vessel_width / 2.0) * rotate(0, -90, 0)) # self.camera_outer = import_stl("../isttok_3d/camera_outer3_stl.stl", scaling=1, mode='binary', parent=self.world, # material=AbsorbingSurface(), # transform=translate(self.x_shift_outer - self.tube_height - self.lid_outer, # 0.0, # self.vessel_width / 2.0) * rotate(-90, 0, 0)) self.camera_outer = import_stl( "../isttok_3d/camera_outer4_newpin_stl.stl", scaling=1, mode='binary', parent=self.world, material=AbsorbingSurface(), transform=translate( self.x_shift_outer - self.tube_height - self.lid_outer, 0.0, self.vessel_width / 2.0) * rotate(-90, 0, 0)) pinhole_sphere_radius = 0.0005 # 0.0005 self.top_pinhole = Sphere(radius=pinhole_sphere_radius, parent=self.world, transform=translate(self.x_shift_top, self.y_shift_top, self.vessel_width / 2), material=Vacuum()) pinhole_sphere_radius = 0.00035 # 0.0005 self.out_pinhole = Sphere(radius=pinhole_sphere_radius, parent=self.world, transform=translate(self.x_shift_outer, 0.0, self.vessel_width / 2), material=Vacuum()) for i in range(16): self.top_power.append(PowerPipeline0D(accumulate=False)) self.out_power.append(PowerPipeline0D(accumulate=False)) top_px_x = self.top_px_first_x - i * 0.00095 top_px_y = self.top_px_first_y - i * 2 * (self.top_twist / 15) top_angle = degrees(asin(2 * self.top_twist / 0.01425)) out_px_y = self.out_px_first_y - i * 0.00095 out_px_x = self.out_px_first_x - i * 2 * (self.out_twist / 15) out_angle = -degrees(asin(2 * self.out_twist / 0.01425)) self.top_px.append( TargettedPixel( targets=[self.top_pinhole], targetted_path_prob=1.0, pipelines=[self.top_power[i]], x_width=0.00075, y_width=0.00405, min_wavelength=min_wl, max_wavelength=max_wl, spectral_bins=1, pixel_samples=pixel_samples, parent=self.world, quiet=True, ray_importance_sampling=True, ray_important_path_weight=0.05, ray_max_depth=50, transform=translate(top_px_x, top_px_y, self.top_px_z) * rotate(0, 0, top_angle) * rotate(0, -90, 0))) self.out_px.append( TargettedPixel( targets=[self.out_pinhole], targetted_path_prob=1.0, pipelines=[self.out_power[i]], x_width=0.00075, y_width=0.00405, min_wavelength=min_wl, max_wavelength=max_wl, spectral_bins=1, pixel_samples=pixel_samples, parent=self.world, quiet=True, ray_importance_sampling=True, ray_important_path_weight=0.05, ray_max_depth=50, transform=translate(out_px_x, out_px_y, self.out_px_z) * rotate(0, 0, out_angle) * rotate(-90, 0, 90)))
from raysect.optical.observer import PinholeCamera, RGBPipeline2D, RGBAdaptiveSampler2D from raysect.optical.library import RoughTitanium from raysect.optical.material import UniformSurfaceEmitter, UniformVolumeEmitter, Dielectric, Sellmeier # DIAMOND MATERIAL diamond_material = Dielectric(Sellmeier(0.3306, 4.3356, 0.0, 0.1750**2, 0.1060**2, 0.0), ConstantSF(1)) diamond_material.importance = 2 world = World() base_path = os.path.split(os.path.realpath(__file__))[0] # the diamond diamond = import_obj(os.path.join(base_path, "../resources/diamond.obj"), scaling=0.01, smoothing=False, parent=world, transform=translate(0.0, 0.713001, 0.0)*rotate(-10, 0, 0), material=diamond_material) # floor Box(Point3D(-100, -0.1, -100), Point3D(100, 0, 100), world, material=RoughTitanium(0.1)) # front light Sphere(5, world, transform=translate(1, 8, -10), material=UniformVolumeEmitter(d65_white, 1.0)) # fill light Sphere(10, world, transform=translate(7, 20, 20), material=UniformSurfaceEmitter(d65_white, 0.15)) # camera rgb_pipeline = RGBPipeline2D(display_update_time=15, display_unsaturated_fraction=0.998) sampler = RGBAdaptiveSampler2D(rgb_pipeline, min_samples=400, fraction=0.1) camera = PinholeCamera((1024, 1024), parent=world, transform=translate(0, 4, -3.5) * rotate(0, -46, 0), pipelines=[rgb_pipeline], frame_sampler=sampler) camera.spectral_bins = 18
# set-up scenegraph world = World() # background wall = Box(Point3D(-10, -8, 0), Point3D(10, 8, 0.1), world, transform=translate(0, -1, 10), material=UniformSurfaceEmitter(d65_white, 0.00005)) wall.material.importance = 0 # emitting spheres Sphere(radius=0.5, parent=world, transform=translate(-2, 3, 2), material=UniformSurfaceEmitter(light_blue)) Sphere(radius=0.2, parent=world, transform=translate(-0.667, 3, 2), material=UniformSurfaceEmitter(green, scale=0.5**2/0.2**2)) Sphere(radius=0.05, parent=world, transform=translate(0.667, 3, 2), material=UniformSurfaceEmitter(orange, scale=0.5**2/0.05**2)) Sphere(radius=0.008, parent=world, transform=translate(2, 3, 2), material=UniformSurfaceEmitter(red, scale=0.5**2/0.008**2)) # reflecting plates Box(lower=Point3D(-3, -0.1, -0.5), upper=Point3D(3, 0.1, 0.5), parent=world, transform=translate(0, 1.5, 2)*rotate(0, 45.5, 0), material=RoughAluminium(0.0003)) Box(lower=Point3D(-3, -0.1, -0.5), upper=Point3D(3, 0.1, 0.5), parent=world, transform=translate(0, 0.7, 1)*rotate(0, 32, 0), material=RoughAluminium(0.005)) Box(lower=Point3D(-3, -0.1, -0.5), upper=Point3D(3, 0.1, 0.5), parent=world, transform=translate(0, 0.05, 0)*rotate(0, 24.5, 0), material=RoughAluminium(0.03)) Box(lower=Point3D(-3, -0.1, -0.5), upper=Point3D(3, 0.1, 0.5), parent=world, transform=translate(0, -0.5, -1)*rotate(0, 19, 0), material=RoughAluminium(0.1)) ion() # Light sampling light_sampling = RGBPipeline2D(name="Light Sampling") light_sampling.display_sensitivity = 200
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
wvl_range = spectrum.min_wavelength - spectrum.max_wavelength shift = 2 * (spectrum.wavelengths - wvl_centre) / wvl_range radius = sqrt(point.x**2 + point.y**2) spectrum.samples += cos((shift + 5) * radius)**4 return spectrum # scene world = World() # boxes box_unshifted = Box(Point3D(-1, -1, -0.25), Point3D(1, 1, 0.25), material=CosGlow(), parent=world, transform=translate(3.2, 1, 0) * rotate(-30, 0, 0)) box_down_shifted = Box(Point3D(-1, -1, -0.25), Point3D(1, 1, 0.25), material=VolumeTransform(CosGlow(), translate(0, 0.5, 0)), parent=world, transform=translate(1.1, 1, 0.8) * rotate(-10, 0, 0)) box_up_shifted = Box(Point3D(-1, -1, -0.25), Point3D(1, 1, 0.25), material=VolumeTransform(CosGlow(), translate(0, -0.5, 0)), parent=world, transform=translate(-1.1, 1, 0.8) * rotate(10, 0, 0))
# creating ray transfer cylinder with 260 (m) outer radius, 140 (m) inner radius, # 160 (m) height and 60 deg peroid for cylindrical periodic emission profile defined # on a 12 x 16 x 16 (R, Phi, Z) gird rtc = RayTransferCylinder(260., 160., 12, 16, radius_inner=140., n_polar=16, period=60.) rtc.parent = world rtc.transform = translate(0, 0, -80.) # setting the integration step rtc.step = 0.2 # creating ray transfer pipeline pipeline = RayTransferPipeline2D() # setting up the camera camera = PinholeCamera((256, 256), pipelines=[pipeline], frame_sampler=FullFrameSampler2D(), transform=translate(258.9415, 149.5, 0) * rotate(90., -30., -90.), parent=world) camera.fov = 90 camera.pixel_samples = 500 camera.min_wavelength = 500. camera.max_wavelength = camera.min_wavelength + 1. camera.spectral_bins = rtc.bins # starting ray tracing camera.observe() # uncomment this to save ray transfer matrix to file # np.save('ray_transfer_cylinder_matrix.npy', pipeline.matrix) # let's collapse the ray transfer matrix with some emission profiles
# metal spheres angle = 6 distance = 3.6 radius = 0.15 for i in range(9): temperature = temperature_scan[i] increment = angle_increments[i] material = Add(RoughIron(0.05), UniformSurfaceEmitter(BlackBody(temperature)), surface_only=True) Sphere(radius, world, transform=rotate(increment * angle, 0, 0) * translate(0, radius + 0.00001, distance), material=material) # glass spheres angle = 6 distance = 3 radius = 0.15 for i in range(9): temperature = temperature_scan[i] increment = angle_increments[i] # WARNING: This is an unphysical demo, the attenuation of the glass is not applied to the black body emission. # WARNING: The full volume emission is simply added to the light transmitted through the glass. # WARNING: In practice, only all emitting volumes or all absorbing volumes should be physically combined.
angle = 6 distance = 3 radius = 0.15 for i in range(9): roughness = roughness_scan[i] increment = angle_increments[i] # use raw material if roughness = 0 if roughness == 0: material = schott("N-BK7") else: material = Roughen(schott("N-BK7"), roughness) Sphere(radius, world, transform=rotate(increment * angle, 0, 0) * translate(0, radius + 0.00001, distance), material=material) # metal spheres angle = 6 distance = 3.6 radius = 0.15 for i in range(9): roughness = roughness_scan[i] increment = angle_increments[i] # use raw material if roughness = 0 if roughness == 0: material = Aluminium() else:
c6_distribution = Maxwellian(c6_density, temperature, bulk_velocity, elements.carbon.atomic_weight * atomic_mass) ne10_distribution = Maxwellian(ne10_density, temperature, bulk_velocity, elements.neon.atomic_weight * atomic_mass) e_distribution = Maxwellian(e_density, temperature, bulk_velocity, electron_mass) d_species = Species(elements.deuterium, 1, d_distribution) he2_species = Species(elements.helium, 2, he2_distribution) c6_species = Species(elements.carbon, 6, c6_distribution) ne10_species = Species(elements.neon, 10, ne10_distribution) # define species plasma.b_field = ConstantVector3D(Vector3D(1.0, 1.0, 1.0)) plasma.electron_distribution = e_distribution plasma.composition = [d_species, he2_species, c6_species, ne10_species] # BEAM ------------------------------------------------------------------------ beam = Beam(parent=world, transform=translate(1.0, 0.0, 0) * rotate(90, 0, 0)) beam.plasma = plasma beam.atomic_data = adas beam.energy = 60000 beam.power = 3e6 beam.element = elements.deuterium beam.sigma = 0.025 beam.divergence_x = 0.5 beam.divergence_y = 0.5 beam.length = 3.0 beam.attenuator = SingleRayAttenuator(clamp_to_zero=True) beam.models = [ BeamCXLine(Line(elements.helium, 1, (4, 3))), BeamCXLine(Line(elements.helium, 1, (6, 4))), BeamCXLine(Line(elements.carbon, 5, (8, 7))), BeamCXLine(Line(elements.carbon, 5, (9, 8))),