def light_box(parent, transform=None): # Notice that this function is creating and returning a parent node which holds references # to the underlying primitives. node = Node(parent=parent, transform=transform) outer = Box(Point3D(-0.01, 0, -0.05), Point3D(0.01, 0.15, 0.0)) slit = Box(Point3D(-0.0015, 0.03, -0.045), Point3D(0.0015, 0.12, 0.0001)) Subtract(outer, slit, parent=node, material=Lambert(reflectivity=ConstantSF(0.1))) Box(Point3D(-0.0015, 0.03, -0.045), Point3D(0.0015, 0.12, -0.04), parent=node, material=UniformSurfaceEmitter(d65_white, 250)) return node
def __init__(self, xmax, ymax, zmax, nx, ny, nz, step=None, voxel_map=None, mask=None, parent=None, transform=None): grid_shape = (nx, ny, nz) dx = xmax / nx dy = ymax / ny dz = zmax / nz grid_steps = (dx, dy, dz) eps_x = 1.e-5 * dx eps_y = 1.e-5 * dy eps_z = 1.e-5 * dz step = step or 0.1 * min(dx, dy, dz) material = CartesianRayTransferEmitter(grid_shape, grid_steps, mask=mask, voxel_map=voxel_map, integrator=CartesianRayTransferIntegrator(step)) primitive = Box(lower=Point3D(0, 0, 0), upper=Point3D(xmax - eps_x, ymax - eps_y, zmax - eps_z), material=material, parent=parent, transform=transform) super().__init__(primitive)
def test_evaluate_function(self): """ Unlike test_integration() in TestRayTransferBox here we test how CartesianRayTransferEmitter works with NumericalIntegrator. """ world = World() material = CartesianRayTransferEmitter( (3, 3, 3), (1., 1., 1.), integrator=NumericalIntegrator(0.0001)) box = Box(lower=Point3D(0, 0, 0), upper=Point3D(2.99999, 2.99999, 2.99999), material=material, parent=world) ray = Ray(origin=Point3D(4., 4., 4.), direction=Vector3D(-1., -1., -1.) / np.sqrt(3), min_wavelength=500., max_wavelength=501., bins=material.bins) spectrum = ray.trace(world) spectrum_test = np.zeros(material.bins) spectrum_test[0] = spectrum_test[13] = spectrum_test[26] = np.sqrt(3.) self.assertTrue( np.allclose(spectrum_test, spectrum.samples, atol=0.001))
def __init__(self, slit_id, centre_point, basis_x, dx, basis_y, dy, dz=0.001, parent=None, csg_aperture=False): self._centre_point = centre_point self._basis_x = basis_x.normalise() self.dx = dx self._basis_y = basis_y.normalise() self.dy = dy self.dz = dz # NOTE - target primitive and aperture surface cannot be co-incident otherwise numerics will cause Raysect # to be blind to one of the two surfaces. slit_normal = basis_x.cross(basis_y) transform = translate(centre_point.x, centre_point.y, centre_point.z) * rotate_basis( slit_normal, basis_y) super().__init__(parent=parent, transform=transform, name=slit_id) self.target = Box(lower=Point3D(-dx / 2 * 1.01, -dy / 2 * 1.01, -dz / 2), upper=Point3D(dx / 2 * 1.01, dy / 2 * 1.01, dz / 2), transform=None, material=NullMaterial(), parent=self, name=slit_id + ' - target') self._csg_aperture = None self.csg_aperture = csg_aperture
width = 1.0 length = 1.0 height = 3.0 peak_density = 5e19 pedestal_top = 1 neutral_temperature = 0.5 peak_temperature = 2500 impurities = [(carbon, 6, 0.005)] world = World() adas = OpenADAS(permit_extrapolation=True, missing_rates_return_null=True) plasma = Plasma(parent=world) plasma.atomic_data = adas plasma.geometry = Box(Point3D(0, -width / 2, -height / 2), Point3D(length, width / 2, height / 2)) species = [] # make a non-zero velocity profile for the plasma vy_profile = IonFunction(1E5, 0, pedestal_top=pedestal_top) def vectorfunction3d(x, y, z): vy = vy_profile(x, y, z) return Vector3D(0, vy, 0) velocity_profile = PythonVectorFunction3D(vectorfunction3d) # define neutral species distribution
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) # Create a target plane behind the lens. target = Box(lower=Point3D(-50, -50, -0), upper=Point3D(50, 50, 0), material=AbsorbingSurface(), transform=translate(0, 0, 0.1), parent=world) # for each sample direction trace a logging ray and plot the ray trajectory plt.ion() fig = plt.figure() ax = fig.gca(projection='3d') for u in np.linspace(-0.006, 0.006, 5): for v in np.linspace(-0.012, 0.012, 11): start = Point3D(v, u, -0.05) log_ray = LoggingRay(start, Vector3D(0, 0, 1)) log_ray.trace(world)
material=RoughCopper(0.75 * rough_max)) Sphere(radius, world, transform=rotate(3 * angle, 0, 0) * translate(0, radius + 0.00001, distance), material=RoughCopper(0.875 * rough_max)) Sphere(radius, world, transform=rotate(4 * angle, 0, 0) * translate(0, radius + 0.00001, distance), material=RoughCopper(1.0 * rough_max)) # rough titanium ground plane # Box(Point3D(-100, -0.1, -100), Point3D(100, 0, 100), world, material=Roughen(Titanium(), 0.1)) Box(Point3D(-100, -0.1, -100), Point3D(100, 0, 100), world, material=RoughTungsten(0.2)) # four strip lights Cylinder(0.5, 1.0, world, transform=translate(0.5, 5, 8) * rotate(90, 0, 0), material=UniformSurfaceEmitter(d65_white, 1.0)) Cylinder(0.5, 1.0, world, transform=translate(0.5, 5, 6) * rotate(90, 0, 0), material=UniformSurfaceEmitter(d65_white, 1.0)) Cylinder(0.5, 1.0,
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)
# Construct our anisotropic emitter class BlueYellowEmitter(AnisotropicSurfaceEmitter): 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
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,
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
from raysect.optical.material import UnitySurfaceEmitter SAMPLES = 100000 world = World() # # create a small emitting box, simulating a 1x10 mm slit 100 mm from a 10x10 mm pixel surface, 20mm off axis # emitter = Box(Point3D(-0.005, -0.0005, -0.0005), Point3D(0.005, 0.0005, 0.0005), world, translate(0.02, 0, 0.10), UnitySurfaceEmitter()) # targets = [emitter] # create a small emitting box, same as above, but split into 10 1x1x1mm cubes so that the bounding spheres are a tighter fit to the slit. emitter = Node(parent=world, transform=translate(0.02, 0, 0.10)) targets = [] for i in range(10): section = Box(Point3D(-0.0005, -0.0005, -0.0005), Point3D(0.0005, 0.0005, 0.0005), emitter, translate(0.001 * i - 0.0045, 0, 0), UnitySurfaceEmitter()) targets.append(section) # setup basic pixel basic_pipeline = PowerPipeline0D(name="Basic Pixel Observer") basic_pixel = Pixel(parent=world, pixel_samples=SAMPLES, pipelines=[basic_pipeline]) # setup targetted pixel targetted_pipeline = PowerPipeline0D(name="Targeted Pixel Observer") targetted_pixel = TargettedPixel(parent=world, targets=targets, pixel_samples=SAMPLES, pipelines=[targetted_pipeline])
ph_dxd_factor = max(ph_xwidth / ph_ywidth, ph_ywidth / ph_xwidth) ph_normal = pinhole.basis_x.cross(pinhole.basis_y).normalise() cos_phi = detector_to_pinhole.dot(ph_normal) phi = np.rad2deg(np.arccos(np.abs(cos_phi))) print("dx: {:.4G}".format(ph_xwidth), "dy: {:.4G}".format(ph_ywidth), "dxd-factor: {:.4G}".format(ph_dxd_factor)) print("phi: {:.3G}".format(phi), "cos_phi: {:.4G}".format(cos_phi)) separation = detector.centre_point.distance_to(detector.slit.centre_point) normalised_separation = separation / d print("Distances") print("separation: {:.4G}".format(separation), "normalised separation: {:.4G}".format(normalised_separation)) point_sampler = RectangleSampler3D(width=det_xwidth, height=det_ywidth) target_plane = Box(Point3D(-100000, -100000, -0.000001), Point3D(100000, 100000, 0.000001)) hole = Box(Point3D(-det_xwidth / 2, -det_ywidth / 2, -0.00001), Point3D(det_xwidth / 2, det_ywidth / 2, 0.00001), parent=world, material=NullMaterial()) pinhole = Subtract(target_plane, hole, parent=world, material=AbsorbingSurface()) analytic_value = analytic_etendue(area_detector, area_pinhole, separation, theta, phi) raytraced_value, raytraced_error = raytraced_etendue( separation, point_sampler, area_detector)
from raysect.optical import World, translate, rotate from raysect.optical.observer import PinholeCamera from raysect.primitive import Box from raysect_vtk.primitives.to_mesh import box_to_mesh world = World() box = Box(parent=None) box_mesh = box_to_mesh(box) box_mesh.parent = world 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)
parent=node, material=Lambert(reflectivity=ConstantSF(0.1))) Box(Point3D(-0.0015, 0.03, -0.045), Point3D(0.0015, 0.12, -0.04), parent=node, 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.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)),
# External imports import matplotlib.pyplot as plt # Raysect imports 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.
input('pause...') world = World() Intersect(s1, s2, parent=world) visualise_scenegraph(world) input('pause...') world = World() Subtract(s1, s2, parent=world) visualise_scenegraph(world) input('pause...') ######################################################################################################################## # Cubes b1 = Box(Point3D(0, 0, 0), Point3D(1, 1, 1)) b2 = Box(Point3D(0, 0, 0), Point3D(1, 1, 1), transform=translate(0.6, 0.6, 0.6)) world = World() Union(b1, b2, parent=world) visualise_scenegraph(world) input('pause...') world = World() Intersect(b1, b2, parent=world) visualise_scenegraph(world) input('pause...') world = World()