def dummycreate4(self): self.os = OpticalSystem(objectDistance=20.0) # reinit os #self.os.surfaces[1].shape.sdia.val = 1e10 def nfun(x, y, z): return 0.5*np.exp(-x**2 - 4.*y**2)+1.0#(2.5 - (x**2 + 100.0*y**4)/10.**2) def ndx(x, y, z): return -2.*x*0.5*np.exp(-x**2 - 4.*y**2)#-2*x/10.**2 def ndy(x, y, z): return -2.*4.*y*0.5*np.exp(-x**2 - 4.*y**2) #-100.0*4.0*y**3/10.**2 def ndz(x, y, z): return np.zeros_like(x) def boundarycheck(x, y, z): return np.ones_like(x, dtype=bool) self.os.insertSurface(1, Surface(surfShape.Conic(curv=-1./24.), thickness = 30.0, material=material.GrinMaterial(nfun, ndx, ndy, ndz, 0.01, 1e-3, boundarycheck), aperture=aperture.CircularAperture(5.0) ) ) self.os.insertSurface(2, Surface(surfShape.Conic(curv=1./24.), thickness = 10.0, aperture=aperture.CircularAperture(5.0) ) )
def dummycreate( self): # should only create the demo system, will be removed later self.os = OpticalSystem(objectDistance=2.0) # reinit os #self.os.surfaces[1].shape.sdia.val = 1e10 # radius of image plane may not be zero to be sure to catch all rays self.os.insertSurface( 1, Surface(surfShape.Conic(curv=1 / -5.922), thickness=3.0, material=material.ConstantIndexGlass(1.7))) # 0.55 self.os.insertSurface(2, Surface(surfShape.Conic(curv=1 / -3.160), thickness=5.0)) # 1.0 self.os.insertSurface( 3, Surface(surfShape.Conic(curv=1 / 15.884), thickness=3.0, material=material.ConstantIndexGlass(1.7))) # 1.3 self.os.insertSurface(4, Surface(surfShape.Conic(curv=1 / -12.756), thickness=3.0)) # 1.3 self.os.insertSurface(5, Surface(surfShape.Conic(), thickness=2.0)) # semidiam=1.01 # STOP self.os.insertSurface( 6, Surface(surfShape.Conic(curv=1 / 3.125), thickness=3.0, material=material.ConstantIndexGlass(1.5))) # semidiam=1.0 self.os.insertSurface(7, Surface(surfShape.Conic(curv=1 / 1.479), thickness=19.0)) # semidiam=1.0
def dummycreate2(self): self.os = OpticalSystem(objectDistance=20.0) # reinit os #self.os.surfaces[1].shape.sdia.val = 1e10 self.os.insertSurface( 1, Surface(surfShape.Conic(curv=-1. / 24.), thickness=-30.0, material=material.Mirror(), aperture=aperture.CircularAperture(5.0)))
def dummycreate4(self): self.os = OpticalSystem() # reinit os self.os.surfaces[0].thickness.val = 20.0 #self.os.surfaces[1].shape.sdia.val = 1e10 def nfun(x, y, z): return 0.5*np.exp(-x**2 - 4.*y**2)+1.0#(2.5 - (x**2 + 100.0*y**4)/10.**2) def ndx(x, y, z): return -2.*x*0.5*np.exp(-x**2 - 4.*y**2)#-2*x/10.**2 def ndy(x, y, z): return -2.*4.*y*0.5*np.exp(-x**2 - 4.*y**2) #-100.0*4.0*y**3/10.**2 def ndz(x, y, z): return np.zeros_like(x) def boundarycheck(x, y, z): return np.ones_like(x, dtype=bool) self.os.insertSurface(1, Surface(core.surfShape.Conic(curv=-1./24.,semidiam=5.0), thickness = 30.0, material=core.material.GrinMaterial(nfun, ndx, ndy, ndz, 0.01, 1e-3, boundarycheck), aperture=core.aperture.CircularAperture(5.0) ) ) self.os.insertSurface(2, Surface(core.surfShape.Conic(curv=1./24.,semidiam=5.0), thickness = 10.0, aperture=core.aperture.CircularAperture(5.0) ) )
def initDemoSystem(self): s = OpticalSystem() lc0 = s.addLocalCoordinateSystem(LocalCoordinates(name="object", decz=0.0), refname=s.rootcoordinatesystem.name) lc1 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf1", decz=2.0), refname=lc0.name) # objectDist lc2 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf2", decz=3.0), refname=lc1.name) lc3 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf3", decz=5.0, tiltx=0.0*math.pi/180.0), refname=lc2.name) lc4 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf4", decz=3.0), refname=lc3.name) lc5 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf5", decz=3.0), refname=lc4.name) lc6 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf6", decz=2.0), refname=lc5.name) lc7 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf7", decz=3.0), refname=lc6.name) lc8 = s.addLocalCoordinateSystem(LocalCoordinates(name="image", decz=19.0), refname=lc7.name) objectsurf = Surface(lc0) surf1 = Surface(lc1, shape=surfShape.Conic(lc1, curv=1/-5.922)) surf2 = Surface(lc2, shape=surfShape.Conic(lc2, curv=1/-3.160)) surf3 = Surface(lc3, shape=surfShape.Conic(lc3, curv=1/15.884)) surf4 = Surface(lc4, shape=surfShape.Conic(lc4, curv=1/-12.756)) stopsurf = Surface(lc5) surf6 = Surface(lc6, shape=surfShape.Conic(lc6, curv=1/3.125)) surf7 = Surface(lc7, shape=surfShape.Conic(lc7, curv=1/1.479)) image = Surface(lc8) elem = OpticalElement(lc0, label="lenssystem") glass = material_isotropic.ConstantIndexGlass(lc0, n=1.7) glass2 = material_isotropic.ConstantIndexGlass(lc0, n=1.5) elem.addMaterial("glass", glass) elem.addMaterial("glass2", glass2) elem.addSurface("object", objectsurf, (None, None)) elem.addSurface("surf1", surf1, (None, "glass")) elem.addSurface("surf2", surf2, ("glass", None)) elem.addSurface("surf3", surf3, (None, "glass")) elem.addSurface("surf4", surf4, ("glass", None)) elem.addSurface("stop", stopsurf, (None, None)) elem.addSurface("surf6", surf6, (None, "glass2")) elem.addSurface("surf7", surf7, ("glass2", None)) elem.addSurface("image", image, (None, None)) s.addElement("lenssys", elem) return s
def dummycreate(self): # should only create the demo system, will be removed later self.os = OpticalSystem() # reinit os self.os.surfaces[0].thickness.val = 2.0 # it is not good give the object itself a thickness if the user is not aware of that #self.os.surfaces[1].shape.sdia.val = 1e10 # radius of image plane may not be zero to be sure to catch all rays self.os.insertSurface(1, Surface(core.surfShape.Conic(curv=1/-5.922, semidiam=0.55), thickness=3.0, material=core.material.ConstantIndexGlass(1.7))) # 0.55 self.os.insertSurface(2, Surface(core.surfShape.Conic(curv=1/-3.160, semidiam=1.0), thickness=5.0)) # 1.0 self.os.insertSurface(3, Surface(core.surfShape.Conic(curv=1/15.884, semidiam=1.3), thickness=3.0, material=core.material.ConstantIndexGlass(1.7))) # 1.3 self.os.insertSurface(4, Surface(core.surfShape.Conic(curv=1/-12.756, semidiam=1.3), thickness=3.0)) # 1.3 self.os.insertSurface(5, Surface(core.surfShape.Conic(semidiam=1.01), thickness=2.0)) # semidiam=1.01 # STOP self.os.insertSurface(6, Surface(core.surfShape.Conic(curv=1/3.125, semidiam=1.0), thickness=3.0, material=core.material.ConstantIndexGlass(1.5))) # semidiam=1.0 self.os.insertSurface(7, Surface(core.surfShape.Conic(curv=1/1.479, semidiam=1.0), thickness=19.0)) # semidiam=1.0
def dummycreate2(self): self.os = OpticalSystem() # reinit os self.os.surfaces[0].thickness.val = 20.0 #self.os.surfaces[1].shape.sdia.val = 1e10 self.os.insertSurface(1, Surface(core.surfShape.Conic(curv=-1./24.,semidiam=5.0), thickness = -30.0, material=core.material.Mirror(), aperture=core.aperture.CircularAperture(5.0) ) )
def __init__(self): self.outputstream = FreeCADOutputStream() self.stdout_backup = sys.stdout sys.stdout = self.outputstream self.surfaceviews = [] self.surfaceobs = [] self.rayobs = [] self.rayviews = [] self.intersectptsobs = [] self.aiminitialized = False self.fieldwaveinitialized = False self.fieldpoints = [[0., 0.], [0., 3.0]] self.wavelength = 0.55 self.shownumrays = 10 self.aimfinitestopdata = None self.aimy = None self.os = OpticalSystem()
logging.basicConfig(level=logging.DEBUG) import core.helpers wavelength = 0.5876e-3 rnd_data1 = np.random.random((3, 3)) #np.eye(3) rnd_data2 = np.random.random((3, 3)) #np.zeros((3, 3))# lc = LocalCoordinates("1") myeps = np.eye(3) + 0.1 * rnd_data1 + 0.01 * complex( 0, 1) * rnd_data2 # aggressive complex choice of myeps #myeps = np.eye(3) + 0.01*np.random.random((3, 3)) crystal = AnisotropicMaterial(lc, myeps) # definition of optical system s = OpticalSystem(matbackground=crystal) lc0 = s.addLocalCoordinateSystem(LocalCoordinates(name="object", decz=0.0), refname=s.rootcoordinatesystem.name) lc1 = s.addLocalCoordinateSystem(LocalCoordinates(name="m1", decz=50.0, tiltx=-math.pi / 8), refname=lc0.name) # objectDist lc2 = s.addLocalCoordinateSystem(LocalCoordinates(name="m2_stop", decz=-50.0, decy=-20, tiltx=math.pi / 16), refname=lc1.name) lc3 = s.addLocalCoordinateSystem(LocalCoordinates(name="m3", decz=50.0, decy=-30,
class OpticalSystemInterface(object): def __init__(self): self.outputstream = FreeCADOutputStream() self.stdout_backup = sys.stdout sys.stdout = self.outputstream self.surfaceviews = [] self.surfaceobs = [] self.rayobs = [] self.rayviews = [] self.intersectptsobs = [] self.aiminitialized = False self.fieldwaveinitialized = False self.fieldpoints = [[0., 0.], [0., 3.0]] self.wavelength = 0.55 self.shownumrays = 10 self.aimfinitestopdata = None self.aimy = None self.os = OpticalSystem() def __exit__(self, exc_type, exc_value, traceback): sys.stdout = self.stdout_backup def dummycreate(self): # should only create the demo system, will be removed later self.os = OpticalSystem(objectDistance=2.0) # reinit os #self.os.surfaces[1].shape.sdia.val = 1e10 # radius of image plane may not be zero to be sure to catch all rays self.os.insertSurface(1, Surface(surfShape.Conic(curv=1/-5.922), thickness=3.0, material=material.ConstantIndexGlass(1.7))) # 0.55 self.os.insertSurface(2, Surface(surfShape.Conic(curv=1/-3.160), thickness=5.0)) # 1.0 self.os.insertSurface(3, Surface(surfShape.Conic(curv=1/15.884), thickness=3.0, material=material.ConstantIndexGlass(1.7))) # 1.3 self.os.insertSurface(4, Surface(surfShape.Conic(curv=1/-12.756), thickness=3.0)) # 1.3 self.os.insertSurface(5, Surface(surfShape.Conic(), thickness=2.0)) # semidiam=1.01 # STOP self.os.insertSurface(6, Surface(surfShape.Conic(curv=1/3.125), thickness=3.0, material=material.ConstantIndexGlass(1.5))) # semidiam=1.0 self.os.insertSurface(7, Surface(surfShape.Conic(curv=1/1.479), thickness=19.0)) # semidiam=1.0 def dummycreate2(self): self.os = OpticalSystem(objectDistance=20.0) # reinit os #self.os.surfaces[1].shape.sdia.val = 1e10 self.os.insertSurface(1, Surface(surfShape.Conic(curv=-1./24.), thickness = -30.0, material=material.Mirror(), aperture=aperture.CircularAperture(5.0) ) ) def dummycreate3(self): # should only create the demo system, will be removed later self.os = OpticalSystem(objectDistance=2.0) # reinit os #self.os.surfaces[1].shape.sdia.val = 1e10 # radius of image plane may not be zero to be sure to catch all rays self.os.insertSurface(1, Surface(surfShape.Conic(curv=1/-5.922), thickness=3.0, material=material.ConstantIndexGlass(1.7), aperture=aperture.CircularAperture(0.55))) # 0.55 self.os.insertSurface(2, Surface(surfShape.Conic(curv=1/-3.160), thickness=5.0, aperture=aperture.CircularAperture(1.0))) # 1.0 self.os.insertSurface(3, Surface(surfShape.Conic(curv=1/15.884), thickness=3.0, material=material.ConstantIndexGlass(1.7), aperture=aperture.CircularAperture(1.3))) # 1.3 self.os.insertSurface(4, Surface(surfShape.Conic(curv=1/-12.756), thickness=3.0, aperture=aperture.CircularAperture(1.3))) # 1.3 self.os.insertSurface(5, Surface(surfShape.Conic(), thickness=2.0, aperture=aperture.CircularAperture(1.01))) # semidiam=1.01 # STOP self.os.insertSurface(6, Surface(surfShape.Conic(curv=1/3.125), thickness=3.0, material=material.ConstantIndexGlass(1.5), aperture=aperture.CircularAperture(1.0))) # semidiam=1.0 self.os.insertSurface(7, Surface(surfShape.Conic(curv=0.1*1/1.479), thickness=19.0, aperture=aperture.CircularAperture(1.0))) # semidiam=1.0 def dummycreate4(self): self.os = OpticalSystem(objectDistance=20.0) # reinit os #self.os.surfaces[1].shape.sdia.val = 1e10 def nfun(x, y, z): return 0.5*np.exp(-x**2 - 4.*y**2)+1.0#(2.5 - (x**2 + 100.0*y**4)/10.**2) def ndx(x, y, z): return -2.*x*0.5*np.exp(-x**2 - 4.*y**2)#-2*x/10.**2 def ndy(x, y, z): return -2.*4.*y*0.5*np.exp(-x**2 - 4.*y**2) #-100.0*4.0*y**3/10.**2 def ndz(x, y, z): return np.zeros_like(x) def boundarycheck(x, y, z): return np.ones_like(x, dtype=bool) self.os.insertSurface(1, Surface(surfShape.Conic(curv=-1./24.), thickness = 30.0, material=material.GrinMaterial(nfun, ndx, ndy, ndz, 0.01, 1e-3, boundarycheck), aperture=aperture.CircularAperture(5.0) ) ) self.os.insertSurface(2, Surface(surfShape.Conic(curv=1./24.), thickness = 10.0, aperture=aperture.CircularAperture(5.0) ) ) def makeSurfaceFromSag(self, surface, startpoint = [0,0,0], R=50.0, rpoints=10, phipoints=12): # TODO: sdia parameter not valid anymore, change behaviour here, too. depending on the type of aperture surPoints = [] pts = Points.Points() pclpoints = [] for r in np.linspace(0,R,rpoints): points = [] for a in np.linspace(0.0, 360.0-360/float(phipoints), phipoints): x = r * math.cos(a*math.pi/180.0)# + startpoint[0] y = r * math.sin(a*math.pi/180.0)# + startpoint[1] z = surface.shape.getSag(x, y)# + startpoint[2] p = FreeCAD.Base.Vector(x,y,z) p2 = FreeCAD.Base.Vector(x+startpoint[0], y+startpoint[1], z+startpoint[2]) points.append(p) pclpoints.append(p2) surPoints.append(points) pts.addPoints(pclpoints) sur = Part.BSplineSurface() sur.interpolate(surPoints) sur.setVPeriodic() surshape = sur.toShape() surshape.translate(tuple(startpoint)) return (surshape, pts) def createSurfaceViews(self, doc): offset = [0, 0, 0] for (index, surf) in enumerate(self.os.surfaces): # all accesses to the surface internal variables should be performed by appropriate supervised functions # to not violate the privacy of the class FCsurfaceobj = doc.addObject("Part::Feature", "Surf_"+str(index)) FCsurfaceview = FCsurfaceobj.ViewObject if surf.aperture.getTypicalDimension() > 0.5 and surf.aperture.getTypicalDimension() < 1000.0: # TODO: boundaries for drawing the surfaces, should be substituted by appropriate drawing conditions # TODO: implement point list returned by aperture property to wireframe at least the aperture (FCsurface, FCptcloud) = self.makeSurfaceFromSag(surf, offset, surf.aperture.getTypicalDimension(), 10, 36) #Points.show(ptcloud) #Part.show(surface) #pointcloudview = ptcloud.ViewObject FCsurfaceobj.Shape = FCsurface FCsurfaceview.ShapeColor = (0.0, 0.0, 1.0) #surfaceview.show() else: FCplaneshape = Part.makePlane(2,2) newoffset = [offset[0] - 1, offset[1] - 1, offset[2]] FCplaneshape.translate(tuple(newoffset)) FCsurfaceobj.Shape = FCplaneshape FCsurfaceview.ShapeColor = (1.0, 0.0, 0.0) offset[2] += surf.getThickness() # may be substituted later by a real coordinate transformation (coordinate break) #time.sleep(0.1) self.surfaceobs.append(FCsurfaceobj) # update lists self.surfaceviews.append(FCsurfaceview) # update lists doc.recompute() def makeRayBundle(self, raybundle, offset): raysorigin = raybundle.o nrays = np.shape(raysorigin)[1] pp = Points.Points() sectionpoints = [] res = [] for i in range(nrays): if abs(raybundle.t[i]) > 1e-6: x1 = raysorigin[0, i] + offset[0] y1 = raysorigin[1, i] + offset[1] z1 = raysorigin[2, i] + offset[2] x2 = x1 + raybundle.t[i] * raybundle.rayDir[0, i] y2 = y1 + raybundle.t[i] * raybundle.rayDir[1, i] z2 = z1 + raybundle.t[i] * raybundle.rayDir[2, i] res.append(Part.makeLine((x1,y1,z1),(x2,y2,z2))) # draw ray sectionpoints.append((x2,y2,z2)) pp.addPoints(sectionpoints) #Points.show(pp) # draw intersection points per raybundle per field point return (pp, res) def makeRaysFromRayPath(self, raypath, offset, color = (0.5, 0.5, 0.5)): def shift(l, n): return l[n:] + l[:n] #grincolor = (np.random.random(), np.random.random(), np.random.random()) doc = FreeCAD.ActiveDocument # in initialisierung auslagern Nraybundles = len(raypath.raybundles) offx = offset[0] offy = offset[1] offz = offset[2] for i in np.arange(Nraybundles): offz += self.os.surfaces[i].getThickness() (intersectionpts, rays) = self.makeRayBundle(raypath.raybundles[i], offset=(offx, offy, offz)) try: pointsq = self.os.surfaces[i].material.pointstodraw FreeCAD.Console.PrintMessage('dims: '+str(np.shape(pointsq))+"\n") FCptsgrinobj = doc.addObject("Points::Feature", "Surf_"+str(i)+"_GrinPoints") tmpppgrin = Points.Points() for stepsq in pointsq: #FreeCAD.Console.PrintMessage(str(ind)+": "+str(np.shape(stepsq))+"\n") ptslice = map(lambda s: (s[0] + offx, s[1] + offy, s[2] + offz), list(stepsq.T)) #FreeCAD.Console.PrintMessage(str(type(ptslice)) + ": " + str(ptslice) + "\n") tmpppgrin.addPoints(ptslice) FCptsgrinobj.Points = tmpppgrin FCptsgrinview = FCptsgrinobj.ViewObject FCptsgrinview.PointSize = 1.0#5.0 FCptsgrinview.ShapeColor = color self.rayobs.append(FCptsgrinobj) except AttributeError: pass #FreeCAD.Console.PrintMessage(str(intersectionpts)+'\n') FCptsobj = doc.addObject("Points::Feature", "Surf_"+str(i)+"_Intersectionpoints") FCptsobj.Points = intersectionpts FCptsview = FCptsobj.ViewObject FCptsview.PointSize = 5.0 FCptsview.ShapeColor = (1.0, 1.0, 0.0) self.intersectptsobs.append(FCptsobj) for (n, ray) in enumerate(rays): FCrayobj = doc.addObject("Part::Feature", "Surf_"+str(i)+"_Ray_"+str(n)) FCrayobj.Shape = ray FCrayview = FCrayobj.ViewObject FCrayview.LineColor = color FCrayview.PointColor = (1.0, 1.0, 0.0) self.rayobs.append(FCrayobj) def showAimFiniteSurfaceStopDialog(self): #self.aimfinitestopdata = (pupiltype, pupilsize, fieldType, rasterType, stopPosition) if self.aimfinitestopdata == None: pupiltype = pupil.EntrancePupilDiameter pupilsize = 2.0 fieldType = field.ObjectHeight rasterType = raster.RectGrid stopPosition = 1 numrays = 10 else: pupiltype = self.aimfinitestopdata[0] pupilsize = self.aimfinitestopdata[1] fieldType = self.aimfinitestopdata[2] rasterType = self.aimfinitestopdata[3] stopPosition = self.aimfinitestopdata[4] numrays = self.shownumrays # TODO: do not reset to default values ad = AimDialog(pupilsize, stopPosition, numrays) # TODO: init with aimy object and return aimy object ad.exec_() if ad.pupiltype != "": pupiltype = eval("pupil."+ad.pupiltype) # eval is evil but who cares :p if ad.pupilsize != 0.0: pupilsize = ad.pupilsize if ad.fieldtype != "": fieldType = eval("field."+ad.fieldtype) if ad.rastertype != "": rasterType = eval("raster."+ad.rastertype) if ad.stopposition != 0: stopPosition = ad.stopposition self.shownumrays = ad.numrays self.aimfinitestopdata = (pupiltype, pupilsize, fieldType, rasterType, stopPosition) self.aiminitialized = True # has to be performed at least one time # TODO: nrays changeable (depends on whether spot diagram or graphical 3d representation) # TODO: let this dialog return aimy object self.aimy = aim.aimFiniteByMakingASurfaceTheStop(self.os, pupilType= pupiltype, \ pupilSizeParameter=pupilsize, \ fieldType= fieldType, \ rasterType= rasterType, \ nray=self.shownumrays, wavelength=self.wavelength, \ stopPosition=stopPosition) return self.aimfinitestopdata def showFieldWaveLengthDialog(self): fd = FieldDialog(self.fieldpoints, self.wavelength) fd.exec_() fieldvariables = fd.fieldpoints wavelength = fd.wavelength res = (fieldvariables, wavelength) self.fieldpoints = fieldvariables self.wavelength = wavelength self.fieldwaveinitialized = True # has to be performed at least one time return res def showSpotDiagrams(self, numrays): # todo: spotdiagramm in extra commando # todo: aktualisieren vom 3d layout # todo: so, dass man nach der optimierung gucken kann (pupiltype, pupilsize, fieldtype, rastertype, stopposition) = self.aimfinitestopdata aimy = self.aimy # aimy = aim.aimFiniteByMakingASurfaceTheStop(self.os, pupilType= pupiltype, \ # pupilSizeParameter=pupilsize, \ # fieldType= fieldtype, \ # rasterType= rastertype, \ # nray=numrays, wavelength=self.wavelength, \ # stopPosition=stopposition) fig = plt.figure(1) numplots = len(self.fieldpoints) for index, fp in enumerate(self.fieldpoints): initialBundle = aimy.getInitialRayBundle(self.os, fieldXY=np.array(fp), wavelength=self.wavelength) rp = RayPath(initialBundle, self.os) ax = fig.add_subplot(numplots, 1, index) ax.axis('equal') plots.drawSpotDiagram(ax, self.os, rp, -1) plt.show() def createRayViews(self, doc, numrays): if not self.aiminitialized or not self.fieldwaveinitialized: QtGui.QMessageBox.critical(None, Title_MessageBoxes, "Either aimy or field/wavelength matrix was not initialized. Please do that!") return #numrays = 100 #pupilsize = 2.0 # fix to appropriate system pupilsize #stopposition = 1 # fix to appropriate system stop position #wavelengthparam = 0.55 #fieldvariable = [0., 0.] #fieldvariable2 = [0., 3.0] # (pupiltype, pupilsize, fieldType, rasterType, stopPosition) (pupiltype, pupilsize, fieldtype, rastertype, stopposition) = self.aimfinitestopdata print str(self.aimfinitestopdata) # TODO: aimy may not be called all the time due to recalculation of stopdiameter which should be fixed aimy = self.aimy #aimy = aim.aimFiniteByMakingASurfaceTheStop(self.os, pupilType= pupiltype, \ # pupilSizeParameter=pupilsize, \ # fieldType= fieldtype, \ # rasterType= rastertype, \ # nray=numrays, wavelength=self.wavelength, \ # stopPosition=stopposition) print str(aimy.stopDiameter) #aimy = aim.aimFiniteByMakingASurfaceTheStop(self.os, pupilType= pupil.EntrancePupilDiameter, \ # pupilSizeParameter=pupilsize, \ # fieldType= field.ObjectHeight, \ # rasterType= raster.RectGrid, \ # nray=numrays, wavelength=wavelengthparam, \ # stopPosition=stopposition) #aimy.setPupilRaster(rasterType= raster.ChiefAndComa, nray=numrays) #aimy.setPupilRaster(rasterType= raster.RectGrid, nray=numrays) #aimy.setPupilRaster(rasterType= raster.PoissonDiskSampling, nray=numrays) for fp in self.fieldpoints: initialBundle = aimy.getInitialRayBundle(self.os, fieldXY=np.array(fp), wavelength=self.wavelength) rp = RayPath(initialBundle, self.os) self.makeRaysFromRayPath(rp,offset=(0,0,0), color=(np.random.random(), np.random.random(), np.random.random())) for obj in doc.Objects: obj.touch() doc.recompute() def deleteSurfaces(self, doc): for so in OSinterface.surfaceobs: doc.removeObject(so.Label) OSinterface.surfaceobs[:] = [] OSinterface.surfaceviews[:] = [] def deleteRays(self, doc): for ro in OSinterface.rayobs: doc.removeObject(ro.Label) for pto in OSinterface.intersectptsobs: doc.removeObject(pto.Label) OSinterface.intersectptsobs[:] = [] # empty list OSinterface.rayobs[:] = [] OSinterface.rayviews[:] = [] def returnPrescriptionData(self): pass
class OpticalSystemInterface(object): def __init__(self): self.outputstream = FreeCADOutputStream() self.stdout_backup = sys.stdout sys.stdout = self.outputstream self.surfaceviews = [] self.surfaceobs = [] self.rayobs = [] self.rayviews = [] self.intersectptsobs = [] self.aiminitialized = False self.fieldwaveinitialized = False self.fieldpoints = [[0., 0.], [0., 3.0]] self.wavelength = 0.55 self.shownumrays = 10 self.aimfinitestopdata = None self.aimy = None self.os = OpticalSystem() def __exit__(self, exc_type, exc_value, traceback): sys.stdout = self.stdout_backup def dummycreate(self): # should only create the demo system, will be removed later self.os = OpticalSystem() # reinit os self.os.surfaces[0].thickness.val = 2.0 # it is not good give the object itself a thickness if the user is not aware of that #self.os.surfaces[1].shape.sdia.val = 1e10 # radius of image plane may not be zero to be sure to catch all rays self.os.insertSurface(1, Surface(core.surfShape.Conic(curv=1/-5.922, semidiam=0.55), thickness=3.0, material=core.material.ConstantIndexGlass(1.7))) # 0.55 self.os.insertSurface(2, Surface(core.surfShape.Conic(curv=1/-3.160, semidiam=1.0), thickness=5.0)) # 1.0 self.os.insertSurface(3, Surface(core.surfShape.Conic(curv=1/15.884, semidiam=1.3), thickness=3.0, material=core.material.ConstantIndexGlass(1.7))) # 1.3 self.os.insertSurface(4, Surface(core.surfShape.Conic(curv=1/-12.756, semidiam=1.3), thickness=3.0)) # 1.3 self.os.insertSurface(5, Surface(core.surfShape.Conic(semidiam=1.01), thickness=2.0)) # semidiam=1.01 # STOP self.os.insertSurface(6, Surface(core.surfShape.Conic(curv=1/3.125, semidiam=1.0), thickness=3.0, material=core.material.ConstantIndexGlass(1.5))) # semidiam=1.0 self.os.insertSurface(7, Surface(core.surfShape.Conic(curv=1/1.479, semidiam=1.0), thickness=19.0)) # semidiam=1.0 def dummycreate2(self): self.os = OpticalSystem() # reinit os self.os.surfaces[0].thickness.val = 20.0 #self.os.surfaces[1].shape.sdia.val = 1e10 self.os.insertSurface(1, Surface(core.surfShape.Conic(curv=-1./24.,semidiam=5.0), thickness = -30.0, material=core.material.Mirror(), aperture=core.aperture.CircularAperture(5.0) ) ) def dummycreate3(self): # should only create the demo system, will be removed later self.os = OpticalSystem() # reinit os self.os.surfaces[0].thickness.val = 2.0 # it is not good give the object itself a thickness if the user is not aware of that #self.os.surfaces[1].shape.sdia.val = 1e10 # radius of image plane may not be zero to be sure to catch all rays self.os.insertSurface(1, Surface(core.surfShape.Conic(curv=1/-5.922, semidiam=0.55), thickness=3.0, material=core.material.ConstantIndexGlass(1.7), aperture=core.aperture.CircularAperture(0.55))) # 0.55 self.os.insertSurface(2, Surface(core.surfShape.Conic(curv=1/-3.160, semidiam=1.0), thickness=5.0, aperture=core.aperture.CircularAperture(1.0))) # 1.0 self.os.insertSurface(3, Surface(core.surfShape.Conic(curv=1/15.884, semidiam=1.3), thickness=3.0, material=core.material.ConstantIndexGlass(1.7), aperture=core.aperture.CircularAperture(1.3))) # 1.3 self.os.insertSurface(4, Surface(core.surfShape.Conic(curv=1/-12.756, semidiam=1.3), thickness=3.0, aperture=core.aperture.CircularAperture(1.3))) # 1.3 self.os.insertSurface(5, Surface(core.surfShape.Conic(semidiam=1.01), thickness=2.0, aperture=core.aperture.CircularAperture(1.01))) # semidiam=1.01 # STOP self.os.insertSurface(6, Surface(core.surfShape.Conic(curv=1/3.125, semidiam=1.0), thickness=3.0, material=core.material.ConstantIndexGlass(1.5), aperture=core.aperture.CircularAperture(1.0))) # semidiam=1.0 self.os.insertSurface(7, Surface(core.surfShape.Conic(curv=0.1*1/1.479, semidiam=1.0), thickness=19.0, aperture=core.aperture.CircularAperture(1.0))) # semidiam=1.0 def dummycreate4(self): self.os = OpticalSystem() # reinit os self.os.surfaces[0].thickness.val = 20.0 #self.os.surfaces[1].shape.sdia.val = 1e10 def nfun(x, y, z): return 0.5*np.exp(-x**2 - 4.*y**2)+1.0#(2.5 - (x**2 + 100.0*y**4)/10.**2) def ndx(x, y, z): return -2.*x*0.5*np.exp(-x**2 - 4.*y**2)#-2*x/10.**2 def ndy(x, y, z): return -2.*4.*y*0.5*np.exp(-x**2 - 4.*y**2) #-100.0*4.0*y**3/10.**2 def ndz(x, y, z): return np.zeros_like(x) def boundarycheck(x, y, z): return np.ones_like(x, dtype=bool) self.os.insertSurface(1, Surface(core.surfShape.Conic(curv=-1./24.,semidiam=5.0), thickness = 30.0, material=core.material.GrinMaterial(nfun, ndx, ndy, ndz, 0.01, 1e-3, boundarycheck), aperture=core.aperture.CircularAperture(5.0) ) ) self.os.insertSurface(2, Surface(core.surfShape.Conic(curv=1./24.,semidiam=5.0), thickness = 10.0, aperture=core.aperture.CircularAperture(5.0) ) ) def makeSurfaceFromSag(self, surface, startpoint = [0,0,0], R=50.0, rpoints=10, phipoints=12): # TODO: sdia parameter not valid anymore, change behaviour here, too. depending on the type of aperture surPoints = [] pts = Points.Points() pclpoints = [] for r in np.linspace(0,R,rpoints): points = [] for a in np.linspace(0.0, 360.0-360/float(phipoints), phipoints): x = r * math.cos(a*math.pi/180.0)# + startpoint[0] y = r * math.sin(a*math.pi/180.0)# + startpoint[1] z = surface.shape.getSag(x, y)# + startpoint[2] p = FreeCAD.Base.Vector(x,y,z) p2 = FreeCAD.Base.Vector(x+startpoint[0], y+startpoint[1], z+startpoint[2]) points.append(p) pclpoints.append(p2) surPoints.append(points) pts.addPoints(pclpoints) sur = Part.BSplineSurface() sur.interpolate(surPoints) sur.setVPeriodic() surshape = sur.toShape() surshape.translate(tuple(startpoint)) return (surshape, pts) def createSurfaceViews(self, doc): offset = [0, 0, 0] for (index, surf) in enumerate(self.os.surfaces): # all accesses to the surface internal variables should be performed by appropriate supervised functions # to not violate the privacy of the class FCsurfaceobj = doc.addObject("Part::Feature", "Surf_"+str(index)) FCsurfaceview = FCsurfaceobj.ViewObject if surf.aperture.getTypicalDimension() > 0.5 and surf.aperture.getTypicalDimension() < 1000.0: # TODO: boundaries for drawing the surfaces, should be substituted by appropriate drawing conditions # TODO: implement point list returned by aperture property to wireframe at least the aperture (FCsurface, FCptcloud) = self.makeSurfaceFromSag(surf, offset, surf.aperture.getTypicalDimension(), 10, 36) #Points.show(ptcloud) #Part.show(surface) #pointcloudview = ptcloud.ViewObject FCsurfaceobj.Shape = FCsurface FCsurfaceview.ShapeColor = (0.0, 0.0, 1.0) #surfaceview.show() else: FCplaneshape = Part.makePlane(2,2) newoffset = [offset[0] - 1, offset[1] - 1, offset[2]] FCplaneshape.translate(tuple(newoffset)) FCsurfaceobj.Shape = FCplaneshape FCsurfaceview.ShapeColor = (1.0, 0.0, 0.0) offset[2] += surf.getThickness() # may be substituted later by a real coordinate transformation (coordinate break) #time.sleep(0.1) self.surfaceobs.append(FCsurfaceobj) # update lists self.surfaceviews.append(FCsurfaceview) # update lists doc.recompute() def makeRayBundle(self, raybundle, offset): raysorigin = raybundle.o nrays = np.shape(raysorigin)[1] pp = Points.Points() sectionpoints = [] res = [] for i in range(nrays): if abs(raybundle.t[i]) > 1e-6: x1 = raysorigin[0, i] + offset[0] y1 = raysorigin[1, i] + offset[1] z1 = raysorigin[2, i] + offset[2] x2 = x1 + raybundle.t[i] * raybundle.rayDir[0, i] y2 = y1 + raybundle.t[i] * raybundle.rayDir[1, i] z2 = z1 + raybundle.t[i] * raybundle.rayDir[2, i] res.append(Part.makeLine((x1,y1,z1),(x2,y2,z2))) # draw ray sectionpoints.append((x2,y2,z2)) pp.addPoints(sectionpoints) #Points.show(pp) # draw intersection points per raybundle per field point return (pp, res) def makeRaysFromRayPath(self, raypath, offset, color = (0.5, 0.5, 0.5)): def shift(l, n): return l[n:] + l[:n] #grincolor = (np.random.random(), np.random.random(), np.random.random()) doc = FreeCAD.ActiveDocument # in initialisierung auslagern Nraybundles = len(raypath.raybundles) offx = offset[0] offy = offset[1] offz = offset[2] for i in np.arange(Nraybundles): offz += self.os.surfaces[i].getThickness() (intersectionpts, rays) = self.makeRayBundle(raypath.raybundles[i], offset=(offx, offy, offz)) try: pointsq = self.os.surfaces[i].material.pointstodraw FreeCAD.Console.PrintMessage('dims: '+str(np.shape(pointsq))+"\n") FCptsgrinobj = doc.addObject("Points::Feature", "Surf_"+str(i)+"_GrinPoints") tmpppgrin = Points.Points() for stepsq in pointsq: #FreeCAD.Console.PrintMessage(str(ind)+": "+str(np.shape(stepsq))+"\n") ptslice = map(lambda s: (s[0] + offx, s[1] + offy, s[2] + offz), list(stepsq.T)) #FreeCAD.Console.PrintMessage(str(type(ptslice)) + ": " + str(ptslice) + "\n") tmpppgrin.addPoints(ptslice) FCptsgrinobj.Points = tmpppgrin FCptsgrinview = FCptsgrinobj.ViewObject FCptsgrinview.PointSize = 1.0#5.0 FCptsgrinview.ShapeColor = color self.rayobs.append(FCptsgrinobj) except AttributeError: pass #FreeCAD.Console.PrintMessage(str(intersectionpts)+'\n') FCptsobj = doc.addObject("Points::Feature", "Surf_"+str(i)+"_Intersectionpoints") FCptsobj.Points = intersectionpts FCptsview = FCptsobj.ViewObject FCptsview.PointSize = 5.0 FCptsview.ShapeColor = (1.0, 1.0, 0.0) self.intersectptsobs.append(FCptsobj) for (n, ray) in enumerate(rays): FCrayobj = doc.addObject("Part::Feature", "Surf_"+str(i)+"_Ray_"+str(n)) FCrayobj.Shape = ray FCrayview = FCrayobj.ViewObject FCrayview.LineColor = color FCrayview.PointColor = (1.0, 1.0, 0.0) self.rayobs.append(FCrayobj) def showAimFiniteSurfaceStopDialog(self): #self.aimfinitestopdata = (pupiltype, pupilsize, fieldType, rasterType, stopPosition) if self.aimfinitestopdata == None: pupiltype = core.pupil.EntrancePupilDiameter pupilsize = 2.0 fieldType = core.field.ObjectHeight rasterType = core.raster.RectGrid stopPosition = 1 numrays = 10 else: pupiltype = self.aimfinitestopdata[0] pupilsize = self.aimfinitestopdata[1] fieldType = self.aimfinitestopdata[2] rasterType = self.aimfinitestopdata[3] stopPosition = self.aimfinitestopdata[4] numrays = self.shownumrays # TODO: do not reset to default values ad = AimDialog(pupilsize, stopPosition, numrays) # TODO: init with aimy object and return aimy object ad.exec_() if ad.pupiltype != "": pupiltype = eval("core.pupil."+ad.pupiltype) # eval is evil but who cares :p if ad.pupilsize != 0.0: pupilsize = ad.pupilsize if ad.fieldtype != "": fieldType = eval("core.field."+ad.fieldtype) if ad.rastertype != "": rasterType = eval("core.raster."+ad.rastertype) if ad.stopposition != 0: stopPosition = ad.stopposition self.shownumrays = ad.numrays self.aimfinitestopdata = (pupiltype, pupilsize, fieldType, rasterType, stopPosition) self.aiminitialized = True # has to be performed at least one time # TODO: nrays changeable (depends on whether spot diagram or graphical 3d representation) # TODO: let this dialog return aimy object self.aimy = core.aim.aimFiniteByMakingASurfaceTheStop(self.os, pupilType= pupiltype, \ pupilSizeParameter=pupilsize, \ fieldType= fieldType, \ rasterType= rasterType, \ nray=self.shownumrays, wavelength=self.wavelength, \ stopPosition=stopPosition) return self.aimfinitestopdata def showFieldWaveLengthDialog(self): fd = FieldDialog(self.fieldpoints, self.wavelength) fd.exec_() fieldvariables = fd.fieldpoints wavelength = fd.wavelength res = (fieldvariables, wavelength) self.fieldpoints = fieldvariables self.wavelength = wavelength self.fieldwaveinitialized = True # has to be performed at least one time return res def showSpotDiagrams(self, numrays): # todo: spotdiagramm in extra commando # todo: aktualisieren vom 3d layout # todo: so, dass man nach der optimierung gucken kann (pupiltype, pupilsize, fieldtype, rastertype, stopposition) = self.aimfinitestopdata aimy = self.aimy # aimy = core.aim.aimFiniteByMakingASurfaceTheStop(self.os, pupilType= pupiltype, \ # pupilSizeParameter=pupilsize, \ # fieldType= fieldtype, \ # rasterType= rastertype, \ # nray=numrays, wavelength=self.wavelength, \ # stopPosition=stopposition) fig = plt.figure(1) numplots = len(self.fieldpoints) for index, fp in enumerate(self.fieldpoints): initialBundle = aimy.getInitialRayBundle(self.os, fieldXY=np.array(fp), wavelength=self.wavelength) rp = RayPath(initialBundle, self.os) ax = fig.add_subplot(numplots, 1, index) ax.axis('equal') core.plots.drawSpotDiagram(ax, self.os, rp, -1) plt.show() def createRayViews(self, doc, numrays): if not self.aiminitialized or not self.fieldwaveinitialized: QtGui.QMessageBox.critical(None, "Pyrate", "Either aimy or field/wavelength matrix was not initialized. Please do that!") return #numrays = 100 #pupilsize = 2.0 # fix to appropriate system pupilsize #stopposition = 1 # fix to appropriate system stop position #wavelengthparam = 0.55 #fieldvariable = [0., 0.] #fieldvariable2 = [0., 3.0] # (pupiltype, pupilsize, fieldType, rasterType, stopPosition) (pupiltype, pupilsize, fieldtype, rastertype, stopposition) = self.aimfinitestopdata print str(self.aimfinitestopdata) # TODO: aimy may not be called all the time due to recalculation of stopdiameter which should be fixed aimy = self.aimy #aimy = core.aim.aimFiniteByMakingASurfaceTheStop(self.os, pupilType= pupiltype, \ # pupilSizeParameter=pupilsize, \ # fieldType= fieldtype, \ # rasterType= rastertype, \ # nray=numrays, wavelength=self.wavelength, \ # stopPosition=stopposition) print str(aimy.stopDiameter) #aimy = core.aim.aimFiniteByMakingASurfaceTheStop(self.os, pupilType= core.pupil.EntrancePupilDiameter, \ # pupilSizeParameter=pupilsize, \ # fieldType= core.field.ObjectHeight, \ # rasterType= core.raster.RectGrid, \ # nray=numrays, wavelength=wavelengthparam, \ # stopPosition=stopposition) #aimy.setPupilRaster(rasterType= raster.ChiefAndComa, nray=numrays) #aimy.setPupilRaster(rasterType= raster.RectGrid, nray=numrays) #aimy.setPupilRaster(rasterType= core.raster.PoissonDiskSampling, nray=numrays) for fp in self.fieldpoints: initialBundle = aimy.getInitialRayBundle(self.os, fieldXY=np.array(fp), wavelength=self.wavelength) rp = RayPath(initialBundle, self.os) self.makeRaysFromRayPath(rp,offset=(0,0,0), color=(np.random.random(), np.random.random(), np.random.random())) for obj in doc.Objects: obj.touch() doc.recompute() def deleteSurfaces(self, doc): for so in OSinterface.surfaceobs: doc.removeObject(so.Label) OSinterface.surfaceobs[:] = [] OSinterface.surfaceviews[:] = [] def deleteRays(self, doc): for ro in OSinterface.rayobs: doc.removeObject(ro.Label) for pto in OSinterface.intersectptsobs: doc.removeObject(pto.Label) OSinterface.intersectptsobs[:] = [] # empty list OSinterface.rayobs[:] = [] OSinterface.rayviews[:] = [] def returnPrescriptionData(self): pass
from core.localcoordinates import LocalCoordinates from core.globalconstants import canonical_ey, degree, standard_wavelength import math import core.helpers # definition of optical system # Design: US patent no. 5701202 A, inventor: Koichi Takahashi # and also: Bo Chen, Alois M. Herkommer, Opt. Express 24, 26999 (2016) logging.basicConfig(level=logging.INFO) s = OpticalSystem() lc0 = s.addLocalCoordinateSystem(LocalCoordinates(name="object", decz=0.0), refname=s.rootcoordinatesystem.name) air = ConstantIndexGlass(lc0, 1.0) glass = ConstantIndexGlass(lc0, 1.492) s.material_background = air si = -1. lcD1 = s.addLocalCoordinateSystem(LocalCoordinates(name="D1", decz=30.002), refname=lc0.name) lcS1 = s.addLocalCoordinateSystem(LocalCoordinates(name="S1", decy=-24.028, decz=26.360,
def __init__(self, doc, name): self.__doc = doc obj = doc.addObject("App::FeaturePython", name) self.__obj = obj obj.Proxy = self self.__NameOSGroup = Group_OS_Label + "_" + uuidToName(uuid.uuid4()) self.__NameSurfaceGroup = Group_Surface_Label + "_" + uuidToName(uuid.uuid4()) self.__NameFunctionsGroup = Group_Functions_Label + "_" + uuidToName(uuid.uuid4()) self.__NameCoordinatesGroup = Group_Coordinates_Label + "_" + uuidToName(uuid.uuid4()) self.__group = doc.addObject("App::DocumentObjectGroup", self.__NameOSGroup) self.__group.addObject(obj) self.__surfacegroup = doc.addObject("App::DocumentObjectGroup", self.__NameSurfaceGroup) self.__functionsgroup = doc.addObject("App::DocumentObjectGroup", self.__NameFunctionsGroup) self.__coordinatesgroup = doc.addObject("App::DocumentObjectGroup", self.__NameCoordinatesGroup) self.__group.addObject(self.__surfacegroup) self.__group.addObject(self.__functionsgroup) self.__group.addObject(self.__coordinatesgroup) self.__functionsgroup.Label = Group_Functions_Label + "_" + name self.__surfacegroup.Label = Group_Surface_Label + "_" + name self.__coordinatesgroup.Label = Group_Coordinates_Label + "_" + name self.__group.Label = Group_OS_Label + "_" + name # TODO: all properties are not really operational # group links obj.addProperty("App::PropertyString", "NameOSGroup", "Groups", "Name of OS Group").NameOSGroup = self.__NameOSGroup obj.addProperty("App::PropertyString", "NameFunctionsGroup", "Groups", "Name of Functions Group").NameFunctionsGroup = self.__NameFunctionsGroup obj.addProperty("App::PropertyString", "NameSurfaceGroup", "Groups", "Name of Surface Group").NameSurfaceGroup = self.__NameSurfaceGroup obj.addProperty("App::PropertyString", "NameCoordinatesGroup", "Groups", "Name of Coordinates Group").NameCoordinatesGroup = self.__NameCoordinatesGroup obj.setEditorMode("NameOSGroup", 1) # readonly obj.setEditorMode("NameFunctionsGroup", 1) # readonly obj.setEditorMode("NameSurfaceGroup", 1) # readonly obj.setEditorMode("NameCoordinatesGroup", 1) # readonly # OS Properties obj.addProperty("App::PropertyPythonObject", "osclass", "OS", "os class interface").osclass = OpticalSystem() obj.addProperty("App::PropertyPythonObject", "coords", "OS", "os coords interface").coords = LC(None, obj.osclass.rootcoordinatesystem, doc, self.__coordinatesgroup) obj.addProperty("App::PropertyFloatList", "wavelengths", "OS", "wavelengths list").wavelengths = [550.0e-6] obj.addProperty("App::PropertyLinkList", "surfaces", "OS", "surface list").surfaces = [] # Field properties obj.addProperty("App::PropertyPythonObject", "fieldpoints", "Field", "Field points").fieldpoints = np.array([[0, 0]]) obj.addProperty("App::PropertyPythonObject", "fieldpointsbool", "Field", "Field points used?").fieldpointsbool = np.array([True], dtype=bool) obj.addProperty("App::PropertyEnumeration", "fieldtype", "Field", "Type of field?").fieldtype = \ ["ObjectHeight", "ObjectChiefAngle", "ParaxialImageHeight"] # Aiming properties obj.addProperty("App::PropertyInteger", "stopposition", "Aiming", "Which surface is stop?").stopposition = 0 obj.addProperty("App::PropertyEnumeration", "pupiltype", "Aiming", "Type of pupil?").pupiltype = \ ["EntrancePupilDiameter", "EntrancePupilRadius", "StopDiameter", "StopRadius", "ExitPupilDiameter", "ExitPupilRadius", "InfiniteConjugateImageSpaceFNumber", "InfiniteConjugateObjectSpaceFNumber", "WorkingImageSpaceFNumber", "WorkingObjectSpaceFNumber", "ObjectSpaceNA", "ImageSpaceNA"] obj.addProperty("App::PropertyDistance", "pupilsize", "Aiming", "Pupil size?").pupilsize = 1.0 obj.addProperty("App::PropertyEnumeration", "rastertype", "Aiming", "Type of pupil rasterization?").rastertype = \ ["RectGrid", "HexGrid", "RandomGrid", "PoissonDiskSampling", "MeridionalFan", "SagitalFan", "ChiefAndComa", "Single"] # TODO: -> text file obj.addProperty("App::PropertyInteger", "numrays", "Aiming", "How many rays to be drawn?").numrays = 10
from core.ray import RayBundle from core.aperture import CircularAperture from core.localcoordinates import LocalCoordinates from core.globalconstants import canonical_ey import math wavelength = 0.5876e-3 wave_red = 0.700e-3 wave_blue = 0.470e-3 # definition of optical system s = OpticalSystem() deg = math.pi / 180. dropletradius = 0.01 lc0 = s.addLocalCoordinateSystem(LocalCoordinates(name="stop", decz=0.0), refname=s.rootcoordinatesystem.name) lccomprism = s.addLocalCoordinateSystem(LocalCoordinates(name="dropletcenter", decz=2. * dropletradius), refname=lc0.name) lc1 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf1", decz=-dropletradius), refname=lccomprism.name) # objectDist lc2 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf2",
from core.ray import RayBundle from core.aperture import CircularAperture from core.localcoordinates import LocalCoordinates from core.globalconstants import canonical_ey import math wavelength = 0.5876e-3 wave_red = 0.700e-3 wave_blue = 0.470e-3 # definition of optical system s = OpticalSystem() deg = math.pi / 180. lc0 = s.addLocalCoordinateSystem(LocalCoordinates(name="stop", decz=0.0), refname=s.rootcoordinatesystem.name) lccomprism = s.addLocalCoordinateSystem(LocalCoordinates(name="prismcenter", decz=50.0), refname=lc0.name) lc1 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf1", decz=-10.0, tiltx=30. * deg), refname=lccomprism.name) # objectDist lc2 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf2", decz=10.0,
from core.optical_element import OpticalElement from core.surface import Surface from core.optical_system import OpticalSystem from core.ray import RayBundle from core.aperture import CircularAperture from core.localcoordinates import LocalCoordinates from core.globalconstants import canonical_ey import math wavelength = 0.5876e-3 # definition of optical system s = OpticalSystem() lc0 = s.addLocalCoordinateSystem(LocalCoordinates(name="obj", decz=0.0), refname=s.rootcoordinatesystem.name) lc1 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf1", decz=10.0, tiltx=5. * math.pi / 180.0), refname=lc0.name) # objectDist lc2 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf2", decz=20.0, tiltx=10. * math.pi / 180.0), refname=lc1.name) lc3 = s.addLocalCoordinateSystem(LocalCoordinates(name="image", decz=10.0), refname=lc2.name) stopsurf = Surface(lc0)
from core.ray import RayBundle from core.aperture import CircularAperture from core.localcoordinates import LocalCoordinates from core.globalconstants import canonical_ey from core.optimize import Optimizer from core.optimize_backends import ScipyBackend import math wavelength = 0.5876e-3 # definition of optical system s = OpticalSystem() lc0 = s.addLocalCoordinateSystem(LocalCoordinates(name="stop", decz=0.0), refname=s.rootcoordinatesystem.name) lc1 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf1", decz=5.0), refname=lc0.name) # objectDist lc2 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf2", decz=20.0), refname=lc1.name) lc3 = s.addLocalCoordinateSystem(LocalCoordinates(name="image", decz=100.0), refname=lc2.name) stopsurf = Surface(lc0) frontsurf = Surface(lc1, shape=surfShape.Conic(lc1), apert=CircularAperture(lc1, 12.7)) backsurf = Surface(lc2,
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. """ import jsonpickle from core.optical_system import OpticalSystem # definition of optical system s = OpticalSystem() print "pickle dump" frozen = jsonpickle.encode(s) with open('optical_sys.jpkl', 'w') as output: output.write(frozen) # WARNING: code is operational, but not tested
from core.optical_system import OpticalSystem from core.ray import RayBundle from core.aperture import CircularAperture from core.localcoordinates import LocalCoordinates from core.globalconstants import canonical_ey import math import logging logging.basicConfig(level=logging.DEBUG) wavelength = 0.5876e-3 # definition of optical system s = OpticalSystem(name='os') lc0 = s.addLocalCoordinateSystem(LocalCoordinates(name="stop", decz=0.0), refname=s.rootcoordinatesystem.name) lc1 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf1", decz=-1.048), refname=lc0.name) # objectDist lc2 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf2", decz=4.0), refname=lc1.name) lc3 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf3", decz=2.5), refname=lc2.name) lc4 = s.addLocalCoordinateSystem(LocalCoordinates(name="image", decz=97.2), refname=lc3.name) stopsurf = Surface(lc0, name="stopsurf") frontsurf = Surface(lc1, name="frontsurf", shape=surfShape.Conic(lc1, curv=1./62.8, name='conic1'), apert=CircularAperture(lc1, 12.7)) cementsurf = Surface(lc2, name="cementsurf", shape=surfShape.Conic(lc2, curv=-1./45.7, name='conic2'), apert=CircularAperture(lc2, 12.7)) rearsurf = Surface(lc3, name="rearsurf", shape=surfShape.Conic(lc3, curv=-1./128.2, name='conic3'), apert=CircularAperture(lc3, 12.7)) image = Surface(lc4, name="imagesurf")
from core.ray import RayBundle from core.aperture import CircularAperture from core.localcoordinates import LocalCoordinates from core.globalconstants import canonical_ey import math import logging logging.basicConfig(level=logging.DEBUG) wavelength = 0.5876e-3 # definition of optical system s = OpticalSystem() lc0 = s.addLocalCoordinateSystem(LocalCoordinates(name="stop", decz=1.0), refname=s.rootcoordinatesystem.name) lc1 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf1", decz=10.0), refname=lc0.name) # objectDist lc2 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf2", decz=5.0), refname=lc1.name) lc3 = s.addLocalCoordinateSystem(LocalCoordinates(name="image", decz=10.0), refname=lc2.name) stopsurf = Surface(lc0) frontsurf = Surface(lc1, shape=surfShape.Conic(lc1, curv=0), apert=CircularAperture(lc1, 10.0)) rearsurf = Surface(lc2,
from core.globalconstants import canonical_ey import math import core.helpers wavelength = 0.5876e-3 # definition of optical system #v = np.ones(3)# + 0.001*np.random.random(3) #myeps = np.diag(v) s = OpticalSystem() lc0 = s.addLocalCoordinateSystem(LocalCoordinates(name="object", decz=0.0), refname=s.rootcoordinatesystem.name) #air = AnisotropicMaterial(lc0, myeps) # tests for anisotropic mirror air = ConstantIndexGlass(lc0, 1.0) s.material_background = air lc1 = s.addLocalCoordinateSystem(LocalCoordinates(name="m1", decz=50.0, tiltx=-math.pi/8), refname=lc0.name) # objectDist lc2 = s.addLocalCoordinateSystem(LocalCoordinates(name="m2_stop", decz=-50.0, decy=-20, tiltx=math.pi/16), refname=lc1.name) lc3 = s.addLocalCoordinateSystem(LocalCoordinates(name="m3", decz=50.0, decy=-30, tiltx=3*math.pi/32), refname=lc2.name) lc4 = s.addLocalCoordinateSystem(LocalCoordinates(name="image1", decz=-50, decy=-15, tiltx=-math.pi/16), refname=lc3.name) lc5 = s.addLocalCoordinateSystem(LocalCoordinates(name="oapara", decz=-100, decy=-35), refname=lc4.name) lc5ap = s.addLocalCoordinateSystem(LocalCoordinates(name="oaparaap", decz=0, decy=35), refname=lc5.name) lc6 = s.addLocalCoordinateSystem(LocalCoordinates(name="image2", decz=55, tiltx=1*math.pi/32), refname=lc5.name) lc7 = s.addLocalCoordinateSystem(LocalCoordinates(name="image3", decz=5), refname=lc6.name)
from core.optical_element import OpticalElement from core.optical_system import OpticalSystem from core.surface import Surface from core.globalconstants import canonical_ey from core.optical_system_analysis import OpticalSystemAnalysis from core.surfShape_analysis import ShapeAnalysis wavelength = standard_wavelength logging.basicConfig(level=logging.DEBUG) # definition of optical system s = OpticalSystem() # objectDistance = 2.0 lc0 = s.addLocalCoordinateSystem(LocalCoordinates(name="object", decz=0.0), refname=s.rootcoordinatesystem.name) lc1 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf1", decz=2.0), refname=lc0.name) # objectDist lc2 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf2", decz=3.0), refname=lc1.name) lc3 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf3", decz=5.0, tiltx=2.5 * math.pi / 180.0), refname=lc2.name) lc4 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf4", decz=3.0), refname=lc3.name) lc5 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf5", decz=3.0), refname=lc4.name)