def test(): start0 = np.array([0., 5., 0.]) start1 = np.array([0., -5., 0.]) intersection = np.array([0., 0., 100.]) ray0 = raytracer.create_ray_from_two_points(start0, intersection) ray1 = raytracer.create_ray_from_two_points(start1, intersection) c0, c1 = raytracer.find_nearest_points(ray0, ray1) print(c0, c1) assert True == True
def batch_of_rays(entry, exit): """ Definition to generate a batch of rays with given entry point(s) and exit point(s). Note that the mapping is one to one, meaning nth item in your entry points list will exit from nth item in your exit list and generate that particular ray. Note that you can have a combination like nx3 points for entry or exit and 1 point for entry or exit. But if you have multiple points both for entry and exit, the number of points have to be same both for entry and exit. Parameters ---------- entry : ndarray Either a single point with size of 3 or multiple points with the size of nx3. exit : ndarray Either a single point with size of 3 or multiple points with the size of nx3. Returns ---------- rays : ndarray Generated batch of rays. """ norays = np.array([0, 0]) if len(entry.shape) == 1: entry = entry.reshape((1, 3)) if len(exit.shape) == 1: exit = exit.reshape((1, 3)) norays = np.amax(np.asarray([entry.shape[0], exit.shape[0]])) if norays > exit.shape[0]: exit = np.repeat(exit, norays, axis=0) elif norays > entry.shape[0]: entry = np.repeat(entry, norays, axis=0) rays = [] norays = int(norays) for i in range(norays): rays.append(create_ray_from_two_points(entry[i], exit[i])) rays = np.asarray(rays) return rays
def test_cylinder_intersection(): import odak.raytracing as raytracer ray = raytracer.create_ray_from_two_points([0., 0., 0.], [10., 0., 0.]) cylinder = raytracer.define_cylinder([0., 0., 0.], 5., rotation=[0., 90., 0.]) normal, distance = raytracer.intersect_w_cylinder(ray, cylinder) assert True == True
def test_multiple_rays_w_sphere(): import odak.raytracing as raytracer import odak.tools as tools end_points = tools.grid_sample(no=[5, 5], size=[10., 10.], center=[0., 0., 100.], angles=[0., 0., 0.]) start_point = [0., 0., 0.] rays = raytracer.create_ray_from_two_points(start_point, end_points) sphere = raytracer.define_sphere([0., 0., 100.], 20) normals, distances = raytracer.intersect_w_sphere(rays, sphere) assert True == True
def test(): sample_entry_points = grid_sample(no=[4, 4], size=[100., 100.], center=[0., 0., 0.], angles=[0., 0., 0.]) sample_exit_points = grid_sample(no=[4, 4], size=[100., 100.], center=[0., 0., 100.], angles=[0., 0., 0.]) rays = raytracer.create_ray_from_two_points(sample_entry_points, sample_exit_points) assert True == True
def detector_to_light_source(detector_location, triangle, light_source): center_of_triangle = raytracer.center_of_triangle(triangle) ray_detector_triangle = raytracer.create_ray_from_two_points( detector_location, center_of_triangle) normal_triangle, d_det_tri = raytracer.intersect_w_triangle( ray_detector_triangle, triangle) if d_det_tri == 0: return 0 ray_reflection = raytracer.reflect(ray_detector_triangle, normal_triangle) normal_source, d_tri_sou = raytracer.intersect_w_circle( ray_reflection, light_source) if d_tri_sou == 0: return 0 opl = d_det_tri + d_tri_sou return opl
def test(): sample_entry_points = grid_sample(no=[4, 4], size=[100., 100.], center=[0., 0., 0.], angles=[0., 0., 0.]) sample_exit_points = grid_sample(no=[4, 4], size=[100., 100.], center=[0., 0., 100.], angles=[0., 0., 0.]) rays = raytracer.create_ray_from_two_points(sample_entry_points, sample_exit_points) detector = catalog.detectors.plane_detector(resolution=[5, 5], shape=[50, 50], center=[0., 0., 200.], angles=[0., 10., 0.]) normals, distances = detector.raytrace(rays) print(detector.get_field()) assert True == True
def test(): sample_entry_points = grid_sample( no=[2,2], size=[100.,100.], center=[0.,0.,0.], angles=[0.,0.,0.] ) sample_exit_points = grid_sample( no=[2,2], size=[100.,100.], center=[0.,50.,100.], angles=[0.,0.,0.] ) rays = raytracer.create_ray_from_two_points( sample_entry_points, sample_exit_points ) diffuser = catalog.diffusers.thin_diffuser( shape=[50,50], center=[0.,0.,100.], angles=[0.,0.,0.], diffusion_no=[5,2], diffusion_angle=10. ) new_rays,normal,distance = diffuser.raytrace(rays) detector = catalog.detectors.plane_detector( resolution=[5,5], shape=[50,50], center=[0.,0.,200.], angles=[0.,0.,0.], ) normals,distances = detector.raytrace(new_rays) # import odak # ray_visualize = odak.visualize.rayshow(line_width=5) # ray_visualize.add_line(rays[:,0],normal[:,0]) # ray_visualize.add_line(new_rays[:,0],normals[:,0]) # ray_visualize.show() assert True==True
def test_plano_convex(): import odak.raytracing as raytracer import odak.tools as tools import odak.catalog as catalog end_points = tools.grid_sample( no=[5,5], size=[2.0,2.0], center=[0.,0.,0.], angles=[0.,0.,0.] ) start_point = [0.,0.,-5.] rays = raytracer.create_ray_from_two_points( start_point, end_points ) lens = catalog.plano_convex_lens() normals,distances = lens.intersect(rays) return True from odak import np import plotly import plotly.graph_objs as go if np.__name__ == 'cupy': df = np.asnumpy(normals[:,0]) dx = np.asnumpy(end_points) dy = np.asnumpy(start_point) else: df = normals[:,0] dx = end_points dy = start_point trace0 = go.Scatter3d(x=df[:,0],y=df[:,1],z=df[:,2]) trace1 = go.Scatter3d(x=dx[:,0],y=dx[:,1],z=dx[:,2]) trace2 = go.Scatter3d(x=[dy[0],],y=[dy[1],],z=[dy[2],]) data = [trace0,trace1,trace2] fig = dict(data=data) plotly.offline.plot(fig) assert True==True
def test_sphere_intersection(): import odak.raytracing as raytracer ray = raytracer.create_ray_from_two_points([-2., 0., 0.], [10., 0., 0.]) sphere = raytracer.define_sphere([0., 0., 0.], 10) normal, distance = raytracer.intersect_w_sphere(ray, sphere) assert True == True