def IdealTLens( shape=Rectangular(size=(50, 50)), ap_shape=Rectangular(size=(40, 40)), f=100, d=20 ): """Function to define an ideal thick lens.""" S1 = IdealPPlanes(shape=shape, f=f, d=d) S2 = Aperture(shape=Rectangular(size=(50, 50)), ap_shape=ap_shape) S3 = Aperture(shape=Rectangular(size=(50, 50)), ap_shape=ap_shape) A1 = Component( surflist=[ (S2, (0, 0, 0), (0, 0, 0)), ] ) A2 = Component( surflist=[ (S3, (0, 0, 0), (0, 0, 0)), ] ) L1 = Component( surflist=[ (S1, (0, 0, 0), (0, 0, 0)), ] ) Si = System( complist=[ (L1, (0, 0, 0), (0, 0, 0)), (A1, (0, 0, -1.001 * d / 2), (0, 0, 0)), (A2, (0, 0, 1.001 * d / 2), (0, 0, 0)), ], n=1, ) return Si
def IdealTLens(shape=Rectangular(size=(50,50)), ap_shape=Rectangular(size=(40,40)), f=100,d=20): """Funcion envoltorio que representa una lente ideal gruesa """ S1=IdealPPlanes(shape=shape, f=f,d=d) S2=Aperture(shape=Rectangular(size=(50,50)),ap_shape=ap_shape) S3=Aperture(shape=Rectangular(size=(50,50)),ap_shape=ap_shape) A1=Component(surflist=[(S2,(0,0,0),(0,0,0)),]) A2=Component(surflist=[(S3,(0,0,0),(0,0,0)),]) L1=Component(surflist=[(S1,(0,0,0),(0,0,0)),]) Si=System(complist=[(L1,(0,0,0),(0,0,0)), (A1,(0,0,-1.001*d/2),(0,0,0)), (A2,(0,0, 1.001*d/2),(0,0,0)),],n=1) return Si
def evaluate_geometry(): lightsources = [] components = [] apertures = [] for obj_key in bpy.data.objects.keys(): obj = bpy.data.objects[obj_key] if not 'source' in obj.data.name: if 'n' in obj.keys(): # for this to be true, n must be define as custom property in Blender "Object Properties" <- NOT Mesh Properties mw = obj.matrix_world mesh = obj.data mesh.calc_loop_triangles() loop_triangles = mesh.loop_triangles S_list = [] for tri in loop_triangles: tri_center = np.array(mw @ tri.center.to_3d()) # get global vertice coordinate-vectors from mesh by their index tri_vertices = [ mw @ mesh.vertices[index].co for index in tri.vertices ] # convert to arrays vertices = [ np.array(vertice.to_3d()) for vertice in tri_vertices ] S = surfaces.Plane(reflectivity=0, shape=shapes.Triangular( (vertices[0], vertices[1], vertices[2]))) S_list.append(S) C = Component(surflist=S_list, material=np.float(obj['n'])) components.append(C) else: print( obj.name, 'not included in ray-trace; no refractive index defined.') else: mw = obj.matrix_world mesh = obj.data mesh.calc_loop_triangles() loop_triangles = mesh.loop_triangles for tri in loop_triangles: tri_vertices = [ mw @ mesh.vertices[index].co for index in tri.vertices ] # convert to arrays vertices = [ np.array(vertice.to_3d()) for vertice in tri_vertices ] apertures.append(vertices) try: Sys = System(complist=components, n=bpy.data.worlds['World']['n']) except KeyError: Sys = System(complist=components, n=1.0) print('Geometries evaluated.') return Sys, apertures
def IdealLens(shape=Rectangular(size=(50,50)), f=100): """Function to create a component that behaves as an ideal lens :param shape: Shape of the lens :type shape: :class:`~pyoptools.raytrace.shape.shape.Shape` """ S1=IdealSurface(shape=shape, f=f) L1=Component(surflist=[(S1,(0,0,0),(0,0,0))]) return L1
def get_optical_path_ep(opsys, opaxis, raylist, stop=None, r=None): """Returns the optical path traveled by a ray up to the exit pupil The optical path is measured from the ray origin until it crosses the exit pupil of the system. If a stop (aperture) is not given, the measurement is made up to the primary principal plane. Arguments: opsys Optical system under analisis opaxis Ray indicating the optical axis the origin of the optical axis, must be the position of the object used in the image formation. This is needed to be able to calculate the radius of the reference sphere. raylist List of rays that will be used to sample the optical path stop Aperture stop of the system. It must belong to opsys. In not given it will be assumed that the exit pupil is at the primary principal plane. r If None, measure up to the exit pupil plane. If given, use a reference sphere with a vertex coinciding with the optical vertex. Return Value (hcl,opl,pc) hcl List containing the coordinates of the hits in the pupil coordinate system. opl list containing the optical paths measured pc intersection point between the optical axis, and the pupil plane. hcl[i] corresponds to opl[i] Note: This method only works if the optical axis coincides with the Z axis. This must be corrected. """ if stop != None: enp, exp = pupil_location(opsys, stop, opaxis) else: exp = find_ppp(opsys, opaxis) #Reset the system opsys.clear_ray_list() opsys.reset() # Propagate the rays #print "***", raylist opsys.ray_add(raylist) opsys.propagate() #pf=PlotFrame(opsys=opsys) rl = [] l = [] # Get the optical path up to the final element in the system for i in raylist: a = i.get_final_rays() if a[0].intensity != 0: # Reverse the rays to calculate the optical path from the final element #to the exit pupil nray = a[0].reverse() rl.append(nray) #TODO: This should not be done using the label nray.label = str(a[0].optical_path_parent()) # Create a dummy system to calculate the wavefront at the exit pupil if r == None: #TODO: This ccd should be infinitely big. Have to see how this can be done ccd = CCD(size=(1000, 1000)) else: ccds = Spherical(shape=Circular(radius=0.9 * r), curvature=1. / r) ccd = Component(surflist=[ (ccds, (0, 0, 0), (0, 0, 0)), ]) #print rl dummy = System(complist=[ (ccd, exp, (0, 0, 0)), ], n=1.) #Calculate the optical path from the final element to the exit pupil plane dummy.ray_add(rl) dummy.propagate() #PlotFrame(opsys=dummy) hcl = [] opl = [] for ip, r in ccd.hit_list: #print ip x, y, z = ip #TODO: This should not be done using the label d = float(r.label) - r.optical_path() hcl.append((x, y, z)) opl.append(d) return (hcl, opl, exp)
def IdealLens(shape=Rectangular(size=(50,50)), f=100): """Funcion envoltorio que representa una lente ideal """ S1=IdealSurface(shape=shape, f=f) L1=Component(surflist=[(S1,(0,0,0),(0,0,0))]) return L1