├── .gitattributes ├── .gitignore ├── Examples ├── Commands │ ├── Axicon.py │ ├── Gain.py │ ├── GaussAperture.py │ ├── GaussHermite.py │ ├── GaussLaguerre.py │ ├── GaussScreen.py │ ├── Lens.py │ ├── LensForvard.py │ ├── PipFFT.py │ ├── Steps.py │ ├── SubIntensity.py │ └── mask1.png ├── Diffraction │ ├── Poisson.py │ └── RoundHole.py ├── Interference │ ├── MachZehnder.py │ ├── Michelson.py │ └── Young.py └── Laser │ ├── StabRes.py │ └── UnstableRes.py ├── LightPipes-Packages ├── LightPipes-1.0.0-py2.7-linux-i686.egg ├── LightPipes-1.0.0-py2.7-linux-x86_64.egg ├── LightPipes-1.0.0-py2.7-macosx-10.6-intel.egg ├── LightPipes-1.0.0-py2.7-win32.egg ├── LightPipes-1.0.1-py2.7-win32.egg ├── LightPipes-1.0.2-py2.7-win32.egg ├── LightPipes-1.0.4-py2.7-linux-x86_64.egg ├── LightPipes-1.0.4-py2.7-macosx-10.11-intel.egg ├── LightPipes-1.0.4-py2.7-win32.egg ├── LightPipes-1.1.0-cp27-cp27mu-linux_x86_64.whl ├── LightPipes-1.1.0-cp34-cp34m-linux_x86_64.whl ├── LightPipes-1.1.0-py2.7-linux-x86_64.egg ├── LightPipes-1.1.0-py3.4-linux-x86_64.egg ├── LightPipes-1.1.1-cp27-cp27m-win32.whl ├── LightPipes-1.1.1-cp35-cp35m-win_amd64.whl ├── README.md ├── installation-instructions-Linux.md ├── installation-instructions-Mac.md ├── installation-instructions-Windows.md └── sources │ ├── LightPipes.cp35-win_amd64.pyd │ ├── LightPipes.cpp │ ├── LightPipes.pyx │ ├── Young.py │ ├── build │ ├── lib.win-amd64-3.5 │ │ └── LightPipes.cp35-win_amd64.pyd │ └── temp.win-amd64-3.5 │ │ └── Release │ │ ├── LightPipes.cp35-win_amd64.exp │ │ ├── LightPipes.cp35-win_amd64.lib │ │ ├── LightPipes.obj │ │ ├── fresnl.obj │ │ ├── lpspy.obj │ │ └── subs.obj │ ├── fftw3.h │ ├── fresnl.cpp │ ├── fresnl.h │ ├── libfftw3-3.dll │ ├── libfftw3-3.lib │ ├── lpspy.cpp │ ├── lpspy.h │ ├── setup.py │ ├── subs.cpp │ └── subs.h ├── README.md ├── command-reference.md └── img ├── twoholes1.png ├── twoholes2.png ├── twoholes3.png ├── twoholes4.png ├── twoholes5.png ├── twoholes6.png ├── twoholes7.png ├── twoholes8.png ├── twoholesPattern.png └── twoholesSetUp.png /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear on external disk 35 | .Spotlight-V100 36 | .Trashes 37 | 38 | # Directories potentially created on remote AFP share 39 | .AppleDB 40 | .AppleDesktop 41 | Network Trash Folder 42 | Temporary Items 43 | .apdisk 44 | -------------------------------------------------------------------------------- /Examples/Commands/Axicon.py: -------------------------------------------------------------------------------- 1 | import LightPipes 2 | import matplotlib.pyplot as plt 3 | Pi=3.1415 4 | m=1 5 | nm=1e-9*m 6 | um=1e-6*m 7 | mm=1e-3*m 8 | cm=1e-2*m 9 | deg=Pi/180.0 10 | 11 | try: 12 | LP=LightPipes.Init() 13 | 14 | wavelength=632.8*nm 15 | size=5.0*mm 16 | N=500 17 | phi=179.8*deg 18 | n1=1.5 19 | z=80*cm 20 | 21 | F=LP.Begin(size,wavelength,N) 22 | F=LP.Axicon(phi,n1,0,0,F) 23 | F=LP.Forvard(z,F) 24 | I=LP.Intensity(2,F) 25 | plt.imshow(I) 26 | plt.show() 27 | 28 | finally: 29 | del LightPipes 30 | -------------------------------------------------------------------------------- /Examples/Commands/Gain.py: -------------------------------------------------------------------------------- 1 | import LightPipes as lp 2 | import matplotlib.pyplot as plt 3 | m=1 4 | nm=1e-9*m 5 | um=1e-6*m 6 | mm=1e-3*m 7 | cm=1e-2*m 8 | 9 | try: 10 | LP=lp.Init() 11 | 12 | wavelength=500*nm 13 | size=5.0*mm 14 | N=100 15 | R=1*mm 16 | z=1*m 17 | f=1*m 18 | dx=0*mm 19 | dy=0*mm 20 | 21 | F=LP.Begin(size,wavelength,N) 22 | F=LP.CircAperture(R, 0, 0, F) 23 | F=LP.Lens(f,dx,dy,F) 24 | F=LP.Gain(3,2,10,F) 25 | F=LP.Forvard(z,F) 26 | I=LP.Intensity(2,F) 27 | #plt.imshow(I) 28 | plt.plot(I[N/2][:N]) 29 | plt.show() 30 | 31 | finally: 32 | del lp 33 | -------------------------------------------------------------------------------- /Examples/Commands/GaussAperture.py: -------------------------------------------------------------------------------- 1 | import LightPipes as lp 2 | import matplotlib.pyplot as plt 3 | m=1 4 | nm=1e-9*m 5 | um=1e-6*m 6 | mm=1e-3*m 7 | cm=1e-2*m 8 | 9 | try: 10 | LP=lp.Init() 11 | 12 | wavelength=500*nm 13 | size=5.0*mm 14 | N=100 15 | w=0.2*mm 16 | R=2 17 | z=1*m 18 | dx=1.0*mm 19 | dy=1.0*mm 20 | 21 | F=LP.Begin(size,wavelength,N) 22 | F=LP.GaussAperture(w,dx,dy,R,F) 23 | F=LP.Forvard(z,F) 24 | I=LP.Intensity(2,F) 25 | #plt.imshow(I) 26 | plt.plot(I[N/2][:N]) 27 | plt.show() 28 | 29 | finally: 30 | del lp 31 | -------------------------------------------------------------------------------- /Examples/Commands/GaussHermite.py: -------------------------------------------------------------------------------- 1 | import LightPipes as lp 2 | import matplotlib.pyplot as plt 3 | m=1 4 | nm=1e-9*m 5 | um=1e-6*m 6 | mm=1e-3*m 7 | cm=1e-2*m 8 | 9 | try: 10 | LP=lp.Init() 11 | 12 | wavelength=500*nm 13 | size=5.0*mm 14 | N=100 15 | w0=0.2*mm 16 | A=1 17 | z=1*m 18 | 19 | F=LP.Begin(size,wavelength,N) 20 | F=LP.GaussHermite(2,3,A,w0,F) 21 | F=LP.Fresnel(z,F) 22 | I=LP.Intensity(2,F) 23 | plt.imshow(I) 24 | plt.show() 25 | 26 | finally: 27 | del lp 28 | -------------------------------------------------------------------------------- /Examples/Commands/GaussLaguerre.py: -------------------------------------------------------------------------------- 1 | import LightPipes as lp 2 | import matplotlib.pyplot as plt 3 | m=1 4 | nm=1e-9*m 5 | um=1e-6*m 6 | mm=1e-3*m 7 | cm=1e-2*m 8 | 9 | try: 10 | LP=lp.Init() 11 | 12 | wavelength=500*nm 13 | size=10.0*mm 14 | N=500 15 | w0=0.2*mm 16 | A=1 17 | z=1*m 18 | 19 | F=LP.Begin(size,wavelength,N) 20 | F=LP.GaussLaguerre(1,4,A,w0,F) 21 | F=LP.Forvard(z,F) 22 | I=LP.Intensity(2,F) 23 | plt.imshow(I) 24 | plt.show() 25 | 26 | finally: 27 | del lp 28 | -------------------------------------------------------------------------------- /Examples/Commands/GaussScreen.py: -------------------------------------------------------------------------------- 1 | import LightPipes as lp 2 | import matplotlib.pyplot as plt 3 | m=1 4 | nm=1e-9*m 5 | um=1e-6*m 6 | mm=1e-3*m 7 | cm=1e-2*m 8 | 9 | try: 10 | LP=lp.Init() 11 | 12 | wavelength=500*nm 13 | size=5.0*mm 14 | N=100 15 | w=0.2*mm 16 | T=2 17 | z=1*m 18 | dx=1.0*mm 19 | dy=1.0*mm 20 | 21 | F=LP.Begin(size,wavelength,N) 22 | F=LP.GaussScreen(w,dx,dy,T,F) 23 | F=LP.Forvard(z,F) 24 | I=LP.Intensity(2,F) 25 | plt.imshow(I) 26 | #plt.plot(I[N/2][:N]) 27 | plt.show() 28 | 29 | finally: 30 | del lp 31 | -------------------------------------------------------------------------------- /Examples/Commands/Lens.py: -------------------------------------------------------------------------------- 1 | import LightPipes as lp 2 | import matplotlib.pyplot as plt 3 | import numpy as np 4 | m=1 5 | nm=1e-9*m 6 | um=1e-6*m 7 | mm=1e-3*m 8 | cm=1e-2*m 9 | 10 | try: 11 | LP=lp.Init() 12 | 13 | wavelength=500*nm 14 | size=5.0*mm 15 | N=100 16 | R=1*mm 17 | z=1*m 18 | f=1*m 19 | dx=0*mm 20 | dy=0*mm 21 | 22 | F=LP.Begin(size,wavelength,N) 23 | F=LP.CircAperture(R, 0, 0, F) 24 | F=LP.Lens(f,dx,dy,F) 25 | 26 | 27 | II=np.zeros((100,100)) 28 | F=LP.MultPhase(II,F) 29 | F=LP.Forvard(z,F) 30 | 31 | 32 | I=LP.Intensity(2,F) 33 | #plt.imshow(I) 34 | plt.plot(I[N/2][:N]) 35 | plt.show() 36 | 37 | finally: 38 | del lp 39 | -------------------------------------------------------------------------------- /Examples/Commands/LensForvard.py: -------------------------------------------------------------------------------- 1 | import LightPipes 2 | import matplotlib.pyplot as plt 3 | m=1 4 | nm=1e-9*m 5 | um=1e-6*m 6 | mm=1e-3*m 7 | cm=1e-2*m 8 | 9 | try: 10 | LP=LightPipes.Init() 11 | 12 | wavelength=1000*nm 13 | size=10*cm 14 | N=500 15 | w=25*mm 16 | f=200*m 17 | z=100000*m 18 | 19 | F=LP.Begin(size,wavelength,N) 20 | F=LP.CircAperture(w,0,0,F) 21 | F=LP.Lens(f,0,0,F) 22 | F=LP.LensFresnel(-f,z,F) 23 | F=LP.IntAttenuator(0.5,F) 24 | I=LP.Intensity(2,F) 25 | #plt.imshow(I) 26 | plt.plot(I[N/2][:N]) 27 | plt.show() 28 | 29 | finally: 30 | del LightPipes 31 | -------------------------------------------------------------------------------- /Examples/Commands/PipFFT.py: -------------------------------------------------------------------------------- 1 | import LightPipes 2 | import matplotlib.pyplot as plt 3 | import numpy as np 4 | m=1 5 | nm=1e-9*m 6 | um=1e-6*m 7 | mm=1e-3*m 8 | cm=1e-2*m 9 | 10 | LP=LightPipes.Init() 11 | F=LP.Begin(0.01,1e-6,500); 12 | F=LP.CircAperture(0.003,0,0,F); 13 | F=LP.RandomPhase(3,5,F); 14 | F=LP.Fresnel(1,F); 15 | Iunf=LP.Intensity(1,F); 16 | fig = plt.figure() 17 | plt.imshow(Iunf); 18 | F=LP.PipFFT(1,F); 19 | F=LP.CircAperture(0.0001,0,0,F); 20 | F=LP.PipFFT(-1,F); 21 | Ifil=LP.Intensity(1,F); 22 | fig = plt.figure() 23 | plt.imshow(Ifil); 24 | plt.show() 25 | -------------------------------------------------------------------------------- /Examples/Commands/Steps.py: -------------------------------------------------------------------------------- 1 | #LightPipes for Python, demonstration of the Steps command 2 | #Calcultion of the intensity distribution in the focus of a lens. 3 | # 4 | #Date: November 4, 2014 5 | #Author: Fred van Goor 6 | #File: PySteps.py 7 | # 8 | 9 | import LightPipes 10 | import numpy as np 11 | from mpl_toolkits.mplot3d import Axes3D 12 | import matplotlib.pyplot as plt 13 | 14 | m=1 15 | nm=1e-9*m 16 | um=1e-6*m 17 | mm=1e-3*m 18 | cm=1e-2*m 19 | 20 | try: 21 | LP=LightPipes.Init() 22 | 23 | wavelength=632.8*nm; 24 | size=4*mm; 25 | N=100; 26 | R=1.5*mm; 27 | dz=10*mm; 28 | Nsteps=100; 29 | f=50*cm; 30 | n=(1.0 + 0.1j)*np.ones((N,N)) 31 | Icross=np.zeros((Nsteps,N)) 32 | X=range(N) 33 | Z=range(Nsteps) 34 | X, Z=np.meshgrid(X,Z) 35 | F=LP.Begin(size,wavelength,N); 36 | F=LP.CircAperture(R,0,0,F); 37 | F=LP.Lens(f,0,0,F); 38 | for i in range(0,Nsteps): 39 | F=LP.Steps(dz,1,n,F); 40 | I=LP.Intensity(0,F); 41 | Icross[i][:N]=I[N/2][:N] 42 | 43 | fig = plt.figure() 44 | ax = fig.gca(projection='3d') 45 | ax.plot_surface(X, Z, Icross, rstride=1, cstride=1, 46 | cmap='rainbow', 47 | linewidth=0.0, 48 | ) 49 | plt.axis('off'); plt.title('intensity at focus'); plt.show(); 50 | 51 | finally: 52 | del LightPipes 53 | -------------------------------------------------------------------------------- /Examples/Commands/SubIntensity.py: -------------------------------------------------------------------------------- 1 | import LightPipes 2 | import matplotlib.pyplot as plt 3 | #from scipy import misc 4 | import matplotlib.image as mpimg 5 | import numpy as np 6 | from mpl_toolkits.mplot3d import Axes3D 7 | m=1 8 | nm=1e-9*m 9 | um=1e-6*m 10 | mm=1e-3*m 11 | cm=1e-2*m 12 | 13 | try: 14 | LP=LightPipes.Init() 15 | wavelength=1*um 16 | size=5.0*mm 17 | dz=10*mm 18 | N=100 19 | 20 | mask=mpimg.imread('mask1.png')[:,:,0] 21 | 22 | F=LP.Begin(size,wavelength,N) 23 | F=LP.SubIntensity(mask,F) 24 | I0=LP.Intensity(2,F) 25 | plt.imshow(I0) 26 | F=LP.Fresnel(0.5*m,F) 27 | I=LP.Intensity(2,F) 28 | 29 | fig = plt.figure() 30 | plt.imshow(I) 31 | plt.show() 32 | finally: 33 | del LightPipes 34 | -------------------------------------------------------------------------------- /Examples/Commands/mask1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/Examples/Commands/mask1.png -------------------------------------------------------------------------------- /Examples/Diffraction/Poisson.py: -------------------------------------------------------------------------------- 1 | import LightPipes 2 | import matplotlib.pyplot as plt 3 | m=1 4 | nm=1e-9*m 5 | um=1e-6*m 6 | mm=1e-3*m 7 | cm=1e-2*m 8 | 9 | try: 10 | LP=LightPipes.Init() 11 | 12 | wavelength=5*um 13 | size=25.0*mm 14 | N=500 15 | 16 | F=LP.Begin(size,wavelength,N) 17 | F=LP.GaussHermite(0,0,1,size/3,F) 18 | F=LP.CircScreen(3*mm,0*mm,0*mm,F) 19 | F=LP.Fresnel(20*cm,F) 20 | I=LP.Intensity(2,F) 21 | plt.imshow(I); plt.axis('off'); plt.title("Poisson's spot") 22 | plt.show() 23 | 24 | finally: 25 | del LightPipes 26 | -------------------------------------------------------------------------------- /Examples/Diffraction/RoundHole.py: -------------------------------------------------------------------------------- 1 | import LightPipes 2 | import matplotlib.pyplot as plt 3 | m=1 4 | nm=1e-9*m 5 | um=1e-6*m 6 | mm=1e-3*m 7 | cm=1e-2*m 8 | 9 | try: 10 | LP=LightPipes.Init() 11 | 12 | wavelength=1*um 13 | size=25.0*mm 14 | N=300 15 | 16 | F=LP.Begin(size,wavelength,N) 17 | F=LP.CircAperture(5*mm, 0, 0, F) 18 | #F=LP.CircScreen(5*mm, 0, 0, F) 19 | #F=LP.RectScreen(5*mm, 5*mm,0,0*mm,0,F) 20 | F=LP.Forvard(100*cm,F) 21 | #F=LP.Forvard(10*cm,F) 22 | #F=LP.Interpol(size*2,N/2,0,0,0,1,F) 23 | I=LP.Intensity(2,F) 24 | #plt.plot(I[N/2][:N]) 25 | plt.imshow(I) 26 | plt.show() 27 | 28 | finally: 29 | del LightPipes 30 | -------------------------------------------------------------------------------- /Examples/Interference/MachZehnder.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | try: 3 | import LightPipes 4 | except ImportError: 5 | print "LightPipes not present" 6 | exit() 7 | 8 | import matplotlib.pyplot as plt 9 | m=1 10 | nm=1e-9*m 11 | um=1e-6*m 12 | mm=1e-3*m 13 | cm=1e-2*m 14 | 15 | try: 16 | LP=LightPipes.Init() 17 | 18 | wavelength=500*nm 19 | size=8.0*mm 20 | N=400 21 | R=300*mm 22 | d1=340*mm 23 | d2=340*mm 24 | f=300*mm 25 | f1=3000*mm 26 | z=190*mm 27 | 28 | f2=1/(1/f-1/f1) 29 | 30 | F=LP.Begin(size,wavelength,N) 31 | F=LP.CircAperture(R, 0, 0, F) 32 | #I=LP.Intensity(2,F) 33 | F1=LP.Forvard(d1,F) 34 | F2=LP.Forvard(d2-z,F) 35 | F2=LP.Lens(f1,0,0,F2) 36 | F2=LP.LensForvard(f2,z,F2) 37 | F2=LP.Convert(F2) 38 | size_new=LP.getGridSize() 39 | #print(size_new/mm) 40 | F1=LP.Interpol(size_new,N,0,0,0,1,F1) 41 | F=LP.BeamMix(F1,F2) 42 | I=LP.Intensity(2,F) 43 | plt.imshow(I); plt.axis('off');plt.title('intensity pattern') 44 | plt.show() 45 | 46 | finally: 47 | del LightPipes 48 | -------------------------------------------------------------------------------- /Examples/Interference/Michelson.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | try: 3 | import LightPipes 4 | except ImportError: 5 | print "LightPipes not present" 6 | exit() 7 | 8 | import matplotlib.pyplot as plt 9 | m=1 10 | nm=1e-9*m 11 | um=1e-6*m 12 | mm=1e-3*m 13 | cm=1e-2*m 14 | rad=1 15 | mrad=1e-3*rad 16 | 17 | try: 18 | LP=LightPipes.Init() 19 | 20 | wavelength=632.8*nm #wavelength of HeNe laser 21 | size=10*mm # size of the grid 22 | N=300 # number (NxN) of grid pixels 23 | R=3*mm # laser beam radius 24 | z1=8*cm # length of arm 1 25 | z2=7*cm # length of arm 2 26 | z3=3*cm # distance laser to beamsplitter 27 | z4=5*cm # distance beamsplitter to screen 28 | Rbs=0.5 # reflection beam splitter 29 | ty=1*mrad; tx=0.0*mrad # tilt of mirror 1 30 | f=50*cm # focal length of positive lens 31 | 32 | 33 | 34 | #Generate a weak converging laser beam using a weak positive lens: 35 | F=LP.Begin(size,wavelength,N) 36 | F=LP.GaussHermite(0,0,1,R,F) 37 | F=LP.Lens(f,0,0,F) 38 | #Propagate to the beamsplitter: 39 | F=LP.Forvard(z3,F) 40 | #Split the beam and propagate to mirror #2: 41 | F2=LP.IntAttenuator(1-Rbs,F) 42 | F2=LP.Forvard(z2,F2) 43 | #Introduce tilt and propagate back to the beamsplitter: 44 | F2=LP.Tilt(tx,ty,F2) 45 | F2=LP.Forvard(z2,F2) 46 | F2=LP.IntAttenuator(Rbs,F2) 47 | #Split off the second beam and propagate to- and back from the mirror #1: 48 | F10=LP.IntAttenuator(Rbs,F) 49 | F1=LP.Forvard(z1*2,F10) 50 | F1=LP.IntAttenuator(1-Rbs,F1) 51 | #Recombine the two beams and propagate to the screen: 52 | F=LP.BeamMix(F1,F2) 53 | F=LP.Forvard(z4,F) 54 | I=LP.Intensity(1,F) 55 | plt.imshow(I); plt.axis('off');plt.title('intensity pattern') 56 | plt.show() 57 | 58 | finally: 59 | del LightPipes 60 | -------------------------------------------------------------------------------- /Examples/Interference/Young.py: -------------------------------------------------------------------------------- 1 | try: 2 | import LightPipes 3 | except ImportError: 4 | print "LightPipes not present" 5 | exit() 6 | 7 | import matplotlib.pyplot as plt 8 | m=1 9 | nm=1e-9*m 10 | um=1e-6*m 11 | mm=1e-3*m 12 | cm=1e-2*m 13 | 14 | try: 15 | LP=LightPipes.Init() 16 | 17 | wavelength=20*um 18 | size=30.0*mm 19 | N=250 20 | 21 | F=LP.Begin(size,wavelength,N) 22 | F1=LP.CircAperture(0.15*mm, 0, -0.6*mm, F) 23 | F2=LP.CircAperture(0.15*mm, 0, 0.6*mm, F) 24 | F=LP.BeamMix(F1,F2) 25 | F=LP.Fresnel(50*cm,F) 26 | I=LP.Intensity(2,F) 27 | plt.imshow(I); plt.axis('off');plt.title('intensity pattern') 28 | plt.show() 29 | 30 | finally: 31 | del LightPipes 32 | -------------------------------------------------------------------------------- /Examples/Laser/StabRes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg 4 | from matplotlib.figure import Figure 5 | import math 6 | import time 7 | import numpy as np 8 | import sys 9 | from Tkinter import * 10 | 11 | if sys.version_info[0] < 3: 12 | import Tkinter as Tk 13 | else: 14 | import tkinter as Tk 15 | try: 16 | import LightPipes 17 | except ImportError: 18 | print "LightPipes not present" 19 | exit() 20 | root = Tk.Tk() 21 | root.wm_title("Laser with stable resonator") 22 | 23 | m=1 24 | nm=1e-9*m 25 | um=1e-6*m 26 | mm=1e-3*m 27 | cm=1e-2*m 28 | rad=1; 29 | mrad=1e-3*rad; 30 | W=1 31 | mW=1e-3*W 32 | 33 | LP=LightPipes.Init() 34 | wavelength=10600*nm; 35 | size=20*mm; 36 | N=120; 37 | Isat=131*W/cm/cm; alpha=0.0067/cm; Lgain=30*cm; 38 | 39 | f1=2.0*m 40 | f2=5*m 41 | 42 | L=30*cm 43 | T=1; 44 | Reflect=0.9; 45 | w0=2.4*mm 46 | n=10; 47 | tx=0.00*mrad; 48 | ty=0.00*mrad; 49 | xwire=10.0*mm 50 | ywire=10.0*mm 51 | 52 | f = Figure(figsize = (5,5), dpi=N) 53 | canvas = FigureCanvasTkAgg(f, master=root) 54 | canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1) 55 | plt = f.add_subplot(211,navigate=False ) 56 | plt2=f.add_subplot(212,navigate=False ) 57 | 58 | F=LP.Begin(size,wavelength,N); 59 | x=range(-N/2,N/2) 60 | x=np.asarray(x)*size/N/mm 61 | def TheExample(): 62 | global F,f1,f2,L,w0 63 | w0=float(scale_w0.get())*mm/2 64 | xwire=float(scalexwire.get())*mm 65 | ywire=float(scaleywire.get())*mm 66 | f1=float(scale_f1.get()*cm)/2 67 | f2=float(scale_f2.get()*cm)/2 68 | L=float(scale_L.get())*cm 69 | Reflect=float(scale_Reflect.get()) 70 | tx=float(scale_tx.get())*mrad 71 | ty=float(scale_ty.get())*mrad 72 | 73 | F=LP.RandomIntensity(time.time(),1e-8,F) 74 | F=LP.CircAperture(w0,0,0,F) 75 | F=LP.RectScreen(size,0.2*mm,0.0,ywire,0.0,F) 76 | F=LP.RectScreen(0.2*mm,size,xwire,0.0,0.0,F) 77 | Iw=LP.Intensity(0,F) 78 | F=LP.Lens(f2,0,0,F); 79 | F=LP.Fresnel(L,F); F=LP.Gain(Isat,alpha,Lgain,F); 80 | F=LP.Lens(f1,0,0,F); 81 | F=LP.Tilt(tx,ty,F) 82 | F=LP.Fresnel(L,F); F=LP.Gain(Isat,alpha,Lgain,F); 83 | F=LP.IntAttenuator(Reflect,F) 84 | P=LP.Power(F)*(1-Reflect)*size/N*size/N 85 | #I=LP.Intensity(0,F) 86 | y=np.asarray(Iw[N/2]) 87 | #Iout=Isat*(alpha*Lgain-0.5*math.log(1/Reflect))*math.pi*w0*w0 88 | plt.clear() 89 | plt2.clear() 90 | g1=1-L/(2*f1); 91 | g2=1-L/(2*f2); 92 | g=g1*g2 93 | plt.text(0,-5,"Power=%5.3f W"% P) 94 | plt.text(150,-5,"g1=%5.3f"% g1) 95 | plt.text(150,15,"g2=%5.3f"% g2) 96 | plt.text(150,35,"g=%5.3f"% g) 97 | #plt.text(150,55,"Iout=%5.3f W"% Iout) 98 | plt.imshow(Iw); plt.axis('off') 99 | plt2.plot(x,y) 100 | canvas.show() 101 | 102 | def _quit(): 103 | root.quit() # stops mainloop 104 | root.destroy() # this is necessary on Windows to prevent 105 | # Fatal Python Error: PyEval_RestoreThread: NULL tstat 106 | def _eigenmode(): 107 | global F,f1,f2,L,w0 108 | g1=1-L/(2*f1); 109 | g2=1-L/(2*f2); 110 | g=g1*g2 111 | z1=L*g2*(1-g1)/(g1+g2-2*g1*g2); 112 | z2=L-z1; 113 | if (g>0): 114 | w0=math.sqrt(wavelength*L/math.pi)*(g1*g2*(1-g1*g2)/(g1+g2-2*g1*g2)**2)**0.25; 115 | mode_m=int(order_m.get()) 116 | mode_n=int(order_n.get()) 117 | F=LP.GaussHermite(mode_m,mode_n,1,w0,F); 118 | #F=LP.GaussLaguerre(2,3,1,w0,F); 119 | F=LP.Forvard(z2,F); 120 | 121 | frame2=Frame(root) 122 | frame2.pack(side=Tk.BOTTOM) 123 | frame3=Frame(frame2) 124 | frame3.pack(side=Tk.BOTTOM) 125 | frame4=Frame(frame3) 126 | frame4.pack(side=Tk.BOTTOM) 127 | frame5=Frame(frame4) 128 | frame5.pack(side=Tk.BOTTOM) 129 | 130 | scalexwire = Tk.Scale(root, orient='horizontal', label = 'x-wire position [mm]', length = 300, from_=-size/2/mm, to=size/2/mm, resolution = 0.001) 131 | scalexwire.pack(side = Tk.LEFT) 132 | scalexwire.set(xwire/mm) 133 | 134 | scaleywire = Tk.Scale(root, orient='horizontal', label = 'y-wire position [mm]', length = 300, from_=-size/2/mm, to=size/2/mm, resolution = 0.001) 135 | scaleywire.pack(side = Tk.LEFT) 136 | scaleywire.set(ywire/mm) 137 | 138 | scale_w0 = Tk.Scale(frame2, orient='horizontal', label = 'aperture diameter [mm]', length = 200, from_=0.0, to=size/mm, resolution = 0.01) 139 | scale_w0.pack(side = Tk.LEFT) 140 | scale_w0.set(2*w0/mm) 141 | 142 | scale_L = Tk.Scale(frame2, orient='horizontal', label = 'resonator length [cm]', length = 200, from_=10.0, to=100.0, resolution = 0.01) 143 | scale_L.pack(side = Tk.LEFT) 144 | scale_L.set(L/cm) 145 | 146 | scale_Reflect = Tk.Scale(frame2, orient='horizontal', label = 'outcoupler reflection', length = 200, from_=0.0, to=1.0, resolution = 0.01) 147 | scale_Reflect.pack(side = Tk.LEFT) 148 | scale_Reflect.set(Reflect) 149 | 150 | scale_f1 = Tk.Scale(frame3, orient='horizontal', label = 'mirror M1 radius [cm]', length = 300, from_=10.0, to=1000.0, resolution = 0.1) 151 | scale_f1.pack(side = Tk.LEFT) 152 | scale_f1.set(f1/cm) 153 | 154 | scale_f2 = Tk.Scale(frame3, orient='horizontal', label = 'mirror M2 radius [cm]', length = 300, from_=10.0, to=1000.0, resolution = 0.1) 155 | scale_f2.pack(side = Tk.LEFT) 156 | scale_f2.set(f2/cm) 157 | 158 | scale_tx = Tk.Scale(frame4, orient='horizontal', label = 'mirror M2 x-tilt [mrad]', length = 300, from_=-10.0, to=10.0, resolution = 0.1) 159 | scale_tx.pack(side = Tk.LEFT) 160 | scale_tx.set(tx/mrad) 161 | 162 | scale_ty = Tk.Scale(frame4, orient='horizontal', label = 'mirror M2 y-tilt [mrad]', length = 300, from_=-10.0, to=10.0, resolution = 0.1) 163 | scale_ty.pack(side = Tk.LEFT) 164 | scale_ty.set(ty/mrad) 165 | 166 | button = Tk.Button(frame5, width = 20, text='eigen mode', command=_eigenmode) 167 | button.pack(side=Tk.LEFT) 168 | 169 | order_m=Tk.Spinbox(frame5,width=1,from_=0, to=5) 170 | order_m.pack(side=Tk.LEFT) 171 | 172 | order_n=Tk.Spinbox(frame5,width=1,from_=0, to=5) 173 | order_n.pack(side=Tk.LEFT) 174 | 175 | button = Tk.Button(frame5, width = 20, text='Quit', command=_quit) 176 | button.pack(side=Tk.LEFT) 177 | 178 | def task(): 179 | TheExample() 180 | root.after(1, task) # reschedule event in 2 seconds 181 | 182 | root.after(1, task) 183 | root.mainloop() 184 | # If you put root.destroy() here, it will cause an error if 185 | # the window is closed with the window manager. 186 | 187 | -------------------------------------------------------------------------------- /Examples/Laser/UnstableRes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg 4 | from matplotlib.figure import Figure 5 | 6 | 7 | import sys 8 | if sys.version_info[0] < 3: 9 | import Tkinter as Tk 10 | else: 11 | import tkinter as Tk 12 | try: 13 | import LightPipes 14 | except ImportError: 15 | print "LightPipes not present" 16 | exit() 17 | root = Tk.Tk() 18 | root.wm_title("Young's experiment") 19 | 20 | m=1 21 | nm=1e-9*m 22 | um=1e-6*m 23 | mm=1e-3*m 24 | cm=1e-2*m 25 | 26 | LP=LightPipes.Init() 27 | wavelength = 308*nm 28 | size=14*mm 29 | N=100 30 | w=5.48*mm 31 | f1=-10*m; f2=20*m; L=10*m; Isat=1.0; alpha=1e-4; Lgain=1e4; 32 | tx=0.0; ty=0.00000; 33 | 34 | f = Figure(figsize = (3,3), dpi=75) 35 | canvas = FigureCanvasTkAgg(f, master=root) 36 | canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1) 37 | 38 | F=LP.Begin(size,wavelength,N); 39 | F=LP.RandomIntensity(2,1,F) 40 | F=LP.RandomPhase(5,1,F); 41 | def TheExample(): 42 | global F 43 | w=float(scale_w.get())*mm 44 | F=LP.RectAperture(w,w,0,0,0,F); F=LP.Gain(Isat,alpha,Lgain,F); 45 | F=LP.LensFresnel(f1,L,F); F=LP.Gain(Isat,alpha,Lgain,F); 46 | F=LP.LensFresnel(f2,L,F); 47 | F=LP.Tilt(tx,ty,F); 48 | F=LP.Interpol(size,N,0,0,0,1,F); 49 | F2=LP.RectScreen(w,w,0,0,0,F); 50 | I=LP.Intensity(0,F2) 51 | plt = f.add_subplot(111,navigate=False ) 52 | plt.imshow(I); plt.axis('off') 53 | canvas.show() 54 | 55 | def _quit(): 56 | root.quit() # stops mainloop 57 | root.destroy() # this is necessary on Windows to prevent 58 | # Fatal Python Error: PyEval_RestoreThread: NULL tstate 59 | 60 | #toolbar = NavigationToolbar2TkAgg( canvas, root ) 61 | #toolbar.set_message ('PIPO') 62 | 63 | scale_w = Tk.Scale(orient='horizontal', label = 'w/mm', length = 300, from_=1.0, to=8.0, resolution = 0.1, var = w) 64 | 65 | scale_w.pack() 66 | 67 | 68 | scale_w.set(w/mm) 69 | 70 | 71 | button = Tk.Button(master=root, width = 20, text='Quit', command=_quit) 72 | button.pack(side=Tk.BOTTOM) 73 | 74 | def task(): 75 | TheExample() 76 | root.after(1, task) # reschedule event in 2 seconds 77 | 78 | root.after(1, task) 79 | root.mainloop() 80 | # If you put root.destroy() here, it will cause an error if 81 | # the window is closed with the window manager. 82 | -------------------------------------------------------------------------------- /LightPipes-Packages/LightPipes-1.0.0-py2.7-linux-i686.egg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/LightPipes-Packages/LightPipes-1.0.0-py2.7-linux-i686.egg -------------------------------------------------------------------------------- /LightPipes-Packages/LightPipes-1.0.0-py2.7-linux-x86_64.egg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/LightPipes-Packages/LightPipes-1.0.0-py2.7-linux-x86_64.egg -------------------------------------------------------------------------------- /LightPipes-Packages/LightPipes-1.0.0-py2.7-macosx-10.6-intel.egg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/LightPipes-Packages/LightPipes-1.0.0-py2.7-macosx-10.6-intel.egg -------------------------------------------------------------------------------- /LightPipes-Packages/LightPipes-1.0.0-py2.7-win32.egg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/LightPipes-Packages/LightPipes-1.0.0-py2.7-win32.egg -------------------------------------------------------------------------------- /LightPipes-Packages/LightPipes-1.0.1-py2.7-win32.egg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/LightPipes-Packages/LightPipes-1.0.1-py2.7-win32.egg -------------------------------------------------------------------------------- /LightPipes-Packages/LightPipes-1.0.2-py2.7-win32.egg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/LightPipes-Packages/LightPipes-1.0.2-py2.7-win32.egg -------------------------------------------------------------------------------- /LightPipes-Packages/LightPipes-1.0.4-py2.7-linux-x86_64.egg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/LightPipes-Packages/LightPipes-1.0.4-py2.7-linux-x86_64.egg -------------------------------------------------------------------------------- /LightPipes-Packages/LightPipes-1.0.4-py2.7-macosx-10.11-intel.egg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/LightPipes-Packages/LightPipes-1.0.4-py2.7-macosx-10.11-intel.egg -------------------------------------------------------------------------------- /LightPipes-Packages/LightPipes-1.0.4-py2.7-win32.egg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/LightPipes-Packages/LightPipes-1.0.4-py2.7-win32.egg -------------------------------------------------------------------------------- /LightPipes-Packages/LightPipes-1.1.0-cp27-cp27mu-linux_x86_64.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/LightPipes-Packages/LightPipes-1.1.0-cp27-cp27mu-linux_x86_64.whl -------------------------------------------------------------------------------- /LightPipes-Packages/LightPipes-1.1.0-cp34-cp34m-linux_x86_64.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/LightPipes-Packages/LightPipes-1.1.0-cp34-cp34m-linux_x86_64.whl -------------------------------------------------------------------------------- /LightPipes-Packages/LightPipes-1.1.0-py2.7-linux-x86_64.egg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/LightPipes-Packages/LightPipes-1.1.0-py2.7-linux-x86_64.egg -------------------------------------------------------------------------------- /LightPipes-Packages/LightPipes-1.1.0-py3.4-linux-x86_64.egg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/LightPipes-Packages/LightPipes-1.1.0-py3.4-linux-x86_64.egg -------------------------------------------------------------------------------- /LightPipes-Packages/LightPipes-1.1.1-cp27-cp27m-win32.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/LightPipes-Packages/LightPipes-1.1.1-cp27-cp27m-win32.whl -------------------------------------------------------------------------------- /LightPipes-Packages/LightPipes-1.1.1-cp35-cp35m-win_amd64.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/LightPipes-Packages/LightPipes-1.1.1-cp35-cp35m-win_amd64.whl -------------------------------------------------------------------------------- /LightPipes-Packages/README.md: -------------------------------------------------------------------------------- 1 | #Installation of LightPipes for Python 2 | 3 | ### 1. [Windows 32 and 64 bits](./installation-instructions-Windows.md) 4 | ### 2. [Linux 32 and 64 bits](./installation-instructions-Linux.md) 5 | ### 3. [Macintosh](./installation-instructions-Mac.md) 6 | -------------------------------------------------------------------------------- /LightPipes-Packages/installation-instructions-Linux.md: -------------------------------------------------------------------------------- 1 | #Installation of LightPipes for Python on a UNIX machine 2 | 3 | Tested 32 and a 64 bit machines with linux MINT 17. 4 | 5 | ##1 Installation of Python: 6 | 7 | 1. Python 2.7 is already pre-installed in linux MINT. Otherwise download from the official Python site: [https://www.python.org/](https://www.python.org/). The *LightPipes* package is made for Python version 2.7, so download Python 2.7. (**Not version 3**) 8 | 9 | ##2. Installation of Python packages: 10 | 11 | 1. The packages *setuptools* and *pip* could be pre-installed. Otherwise go to [https://pythonhosted.org/setuptools/setuptools.html](https://pythonhosted.org/setuptools/setuptools.html) and [https://pip.pypa.io/en/latest/installing.html](https://pip.pypa.io/en/latest/installing.html) respectively and follow the instructions on these sites or use the software manager of (for example) MINT to install them (recommended). 12 | 2. For LightPipes you may need the *Numpy* package. For graphics the *matplotlib* package. 13 | 3. Open a terminal window and install *Numpy* by typing at the prompt: 14 | 15 | **pip install numpy** (takes a while…) 16 | 17 | or use the software manager. 18 | 19 | 4. Install *matplotlib* by typing at the prompt: 20 | 21 | **pip install matplotlib** 22 | 23 | or use the software manager (recommended). 24 | 25 | 5. Check the installed packages. Type: 26 | 27 | **pip list** 28 | 29 | 6. The response should be like: 30 | 31 | matplotlib(1.4.2) 32 | numpy(1.9.0) 33 | pip(1.5.6) 34 | pyparsing(2.0.3) 35 | python_dateutil(2.2) 36 | pytz(2014.7) 37 | setuptools(7.0) 38 | six(1.8.0) 39 | 40 | 7. Your system is now ready for *LightPipes for Python*. 41 | 42 | ##3. Install LightPipes for Python: 43 | 44 | 1. Open a terminal and type (copy/paste) at the prompt: 45 | 46 | **easy_install LightPipes** 47 | 48 | (newest version) 49 | 50 | **easy\_install https://github.com/FredvanGoor/LightPipes-for-Python/raw/master/LightPipes-Packages/LightPipes-1.0.0-py2.7- linux-x86_64.egg** 51 | 52 | for the 64-bits version or: 53 | 54 | **easy\_install https://github.com/FredvanGoor/LightPipes-for-Python/raw/master/LightPipes-Packages/LightPipes-1.0.0-py2.7- linux-i686.egg** 55 | 56 | for the 32-bits version. 57 | 2. This will download the installation and installs *LightPipes for Python*. 58 | 3. Type: 59 | 60 | **pip list** 61 | 62 | 4. *LightPipes(1.0.0)* or similar should be in the list now. 63 | 5. You could uninstall LightPipes by typing: 64 | 65 | **pip uninstall LightPipes** 66 | 67 | ##4. Installation of a very nice editor ‘Geany’: 68 | 69 | 1. *Geany* is a very useful editor for editing program files including *Python* scripts. 70 | 2. Download from: [http://www.geany.org/Download/Releases](http://www.geany.org/Download/Releases) *geany-1.2.6setup.exe*. 71 | 3. Execute: *geany-1.2.6setup.exe*. 72 | 4. Choose the default settings- and install directory. 73 | 74 | ##5. Make your first LightPipes script file. 75 | 76 | 1. Start *Geany*, open a new document and type (or copy/paste) the following script: 77 | 78 | import LightPipes 79 | import matplotlib.pyplot as plt 80 | m=1 81 | nm=1e-9*m 82 | um=1e-6*m 83 | mm=1e-3*m 84 | cm=1e-2*m 85 | 86 | try: 87 | LP=LightPipes.Init() 88 | 89 | wavelength=20*um 90 | size=30.0*mm 91 | N=1000 92 | 93 | F=LP.Begin(size,wavelength,N) 94 | F1=LP.CircAperture(0.15*mm, 0, -0.6*mm, F) 95 | F2=LP.CircAperture(0.15*mm, 0, 0.6*mm, F) 96 | F=LP.BeamMix(F1,F2) 97 | F=LP.Fresnel(10*cm,F) 98 | I=LP.Intensity(2,F) 99 | plt.imshow(I) 100 | plt.show() 101 | 102 | finally: 103 | del LightPipes 104 | 105 | 2. Save the document as ‘Young.py’, and push in *Geany* the execute button or open a terminal window and type at the prompt: 106 | 107 | **python Young.py** 108 | 109 | 3. After a few seconds a window with the output appears: 110 | 111 | ![](../img/twoholesPattern.png) 112 | 113 | 114 | ###6. Explanation of the commands 115 | 116 | Import LightPipes imports the LightPipes library (from ‘LightPipes.pyd’) 117 | 118 | import matplotlib.pyplot as plt imports matplotlib for the graphics 119 | LP=LightPipes.Init() initiates LightPipes 120 | (make a new instance of LightPipes called ‘LP’) 121 | for a grid-size, grid-dimension and wavelength defined by the Begin command. 122 | 123 | wavelength=20*um Define the wavelength, grid-size and grid-dimension. 124 | size=30.0*mm 125 | N=1000 126 | 127 | F=LP.Begin(size,wavelength,N) The simulation of Young’s experiment: 128 | F1=LP.CircAperture(0.15*mm, 0, -0.6*mm, F) A plane wave hits a screen with two holes. 129 | F2=LP.CircAperture(0.15*mm, 0, 0.6*mm, F) The interference pattern is observed at a distance of 10 cm. 130 | F=LP.BeamMix(F1,F2) 131 | F=LP.Fresnel(10*cm,F) 132 | I=LP.Intensity(2,F) 133 | 134 | plt.imshow(I) Plot and show the output interference pattern 135 | plt.show() 136 | 137 | del LightPipes Be sure that everything is cleaned-up after execution 138 | (this is normally not necessary but is good practice) 139 | 140 | Enjoy LightPipes for Python! 141 | 142 | Fred van Goor, 11/24/2015 11:49:43 AM 143 | -------------------------------------------------------------------------------- /LightPipes-Packages/installation-instructions-Mac.md: -------------------------------------------------------------------------------- 1 | #Installation of LightPipes for Python on a Macintosh. 2 | 3 | Tested on a MAC with a 64 bit Intel processor and Yosemite 10.6 OSX. 4 | 5 | ###1. Installation of Python: 6 | 7 | 1. *Python 2.7* is already pre-installed in Yosemite 10.6. Otherwise download from the official *Python* site: [https://www.python.org/downloads/mac-osx/](https://www.python.org/downloads/mac-osx/). The *LightPipes* package is made for *Python* version 2.7, so download *Python* 2.7. (Not version 3) 8 | 9 | ###2. Installation of Python packages: 10 | 11 | 1. The packages *setuptools* and *pip* are already installed in Yosemite 10.6. Otherwise go to [https://pythonhosted.org/setuptools/setuptools.html](https://pythonhosted.org/setuptools/setuptools.html) and [https://pip.pypa.io/en/latest/installing.html](https://pip.pypa.io/en/latest/installing.html) respectively and follow the instructions on these sites. 12 | 2. For *LightPipes* you might need the *Numpy* package. For graphics: *matplotlib* package. 13 | 3. Open a terminal window and install *Numpy* by typing at the prompt: 14 | 15 | **pip install numpy** (takes a while…) 16 | 17 | 4. Install *matplotlib* by typing at the prompt: 18 | 19 | **pip install matplotlib** 20 | 21 | 5. Check the installed packages: Type: 22 | 23 | **pip list** 24 | 25 | The response should be like: 26 | 27 | matplotlib(1.4.2) 28 | numpy(1.9.0) 29 | pip(1.5.6) 30 | pyparsing(2.0.3) 31 | python_dateutil(2.2) 32 | pytz(2014.7) 33 | setuptools(7.0) 34 | six(1.8.0) 35 | 36 | 6. Your system is now ready for LightPipes for Python. 37 | 38 | ###3. Install LightPipes for Python: 39 | 40 | 1. Open the terminal and type (copy/paste) at the prompt: 41 | 42 | 43 | **easy_install LightPipes** 44 | 45 | (newest version) 46 | 47 | or, from GitHub: 48 | 49 | 50 | **easy\_install https://github.com/FredvanGoor/LightPipes-for-Python/raw/master/LightPipes-Packages/LightPipes-1.0.0-py2.7-macosx-10.6-intel.egg** 51 | 52 | or, from the downloaded and extracted zip-file: 53 | 54 | **easy_install install\_directory\LightPipes-Packages\LightPipes-1.0.0-py2.7-macosx-10.6-intel.egg** 55 | 56 | where install\_directory is the directory in which you put the zip-file. 57 | 58 | 2. This will download the installation and installs LightPipes for Python. 59 | 3. Check by typing: 60 | 61 | **pip list** 62 | 63 | The list should now contain something like: 64 | 65 | lightpipes (1.0.0). 66 | 67 | 4. You could un-install LightPipes by typing: 68 | 69 | **pip uninstall LightPipes** 70 | 71 | ###4. Installation of a very nice editor Geany: 72 | Geany is a very useful editor for editing program files including Python scripts. 73 | Download and install from: [http://www.geany.org/Download/Releases](http://www.geany.org/Download/Releases): 74 | 75 | geany-1.26_osx.dmg 76 | 77 | 78 | 79 | ###5. Make your first LightPipes script file: 80 | 1. Start *Geany*, open a new document and type (or copy/paste) the following script: 81 | 82 | import LightPipes 83 | import matplotlib.pyplot as plt 84 | m=1 85 | nm=1e-9*m 86 | um=1e-6*m 87 | mm=1e-3*m 88 | cm=1e-2*m 89 | 90 | try: 91 | LP=LightPipes.Init() 92 | 93 | wavelength=20*um 94 | size=30.0*mm 95 | N=1000 96 | 97 | F=LP.Begin(size,wavelength,N) 98 | F1=LP.CircAperture(0.15*mm, 0, -0.6*mm, F) 99 | F2=LP.CircAperture(0.15*mm, 0, 0.6*mm, F) 100 | F=LP.BeamMix(F1,F2) 101 | F=LP.Fresnel(10*cm,F) 102 | I=LP.Intensity(2,F) 103 | plt.imshow(I) 104 | plt.show() 105 | 106 | finally: 107 | del LightPipes 108 | 109 | 2. Save the document as ‘Young.py’, and push in *Geany* the execute button or open a terminal window and type at the prompt: 110 | 111 | **python Young.py** 112 | 113 | 3. After a few seconds a window with the output appears: 114 | 115 | ![](../img/twoholesPattern.png) 116 | 117 | ###6. Explanation of the commands 118 | 119 | Import LightPipes imports the LightPipes library (from ‘LightPipes.pyd’) 120 | 121 | import matplotlib.pyplot as plt imports matplotlib for the graphics 122 | LP=LightPipes.Init() initiates LightPipes 123 | (make a new instance of LightPipes called ‘LP’) 124 | for a grid-size, grid-dimension and wavelength defined by the Begin command. 125 | 126 | wavelength=20*um Define the wavelength, grid-size and grid-dimension. 127 | size=30.0*mm 128 | N=1000 129 | 130 | F=LP.Begin(size,wavelength,N) The simulation of Young’s experiment: 131 | F1=LP.CircAperture(0.15*mm, 0, -0.6*mm, F) A plane wave hits a screen with two holes. 132 | F2=LP.CircAperture(0.15*mm, 0, 0.6*mm, F) The interference pattern is observed at a distance of 10 cm. 133 | F=LP.BeamMix(F1,F2) 134 | F=LP.Fresnel(10*cm,F) 135 | I=LP.Intensity(2,F) 136 | 137 | plt.imshow(I) Plot and show the output interference pattern 138 | plt.show() 139 | 140 | del LightPipes Be sure that everything is cleaned-up after execution 141 | (this is normally not necessary but is good practice) 142 | 143 | Enjoy LightPipes for Python! 144 | 145 | Fred van Goor, 11/24/2015 11:49:43 AM 146 | -------------------------------------------------------------------------------- /LightPipes-Packages/installation-instructions-Windows.md: -------------------------------------------------------------------------------- 1 | #Installation of LightPipes for Python on a Windows PC. 2 | 3 | Tested on Windows 7, 8.1, and 10, on 64- and 32 bits machines. 4 | 5 | ##1. Installation of Python: 6 | 7 | 1. [Download Python version 2 from: http://www.python.org/downloads/](http://www.python.org/downloads/) 8 | 9 | **Not version 3!** 10 | 2. Execute: ‘python-2.x.x.msi’ 11 | 3. Choose default directory: ‘C:\Python27’ 12 | 4. Choose: ‘*Add Python.exe to Path*’ and restart the computer 13 | 5. Test Python in command window(*cmd.exe*). Enter: 14 | 15 | **Python** 16 | 17 | The Python prompt (**>>>**) should appear. Type: 18 | 19 | **quit()** 20 | 21 | to leave it. 22 | 23 | 24 | ##2. Installation of Python packages: 25 | 26 | 1. The installation of some packages requires a c++ compiler. [Download command line compiler VCForPython27](http://aka.ms/vcpython27) 27 | 2. Execute ‘VCForPython27.msi’ to install the compiler 28 | 3. Modify the Path: right-click ‘Start, Computer’, ‘Properties’, ‘Advanced system settings’, ‘Environment Variables…’. Add to the Path variable: ‘C:\Python27\;C:Python27\Lib\site-packages\;’ and restart the computer. 29 | 4. [Download from: https://pypi.python.org/pypi/setuptools](https://pypi.python.org/pypi/setuptools) *ez_setup.py* (Save the python script displayed by: [https://bootstrap.pypa.io/ez_setup.py](https://bootstrap.pypa.io/ez_setup.py) in a text- file called *ez\_setup.py*) 30 | 5. Open command window (*cmd.exe*). Type: 31 | 32 | **cd C:\Python27\Scripts** 33 | 6. Type at the windows prompt: 34 | 35 | **python ez\_setup.py** 36 | 37 | 7. Type at the windows prompt: 38 | 39 | **easy_install pip** 40 | 41 | to install the python package installer *pip*. 42 | 8. Check at the windows prompt the installed packages by typing: 43 | 44 | **pip list** 45 | 46 | The response should be like: 47 | 48 | pip(1.5.6) 49 | setuptools(7.0) 50 | For LightPipes you need the ‘*Numpy*’ package. For graphics: the ‘*matplotlib*’ package. 51 | 9. Install ‘Numpy’ by typing at the windows prompt: 52 | 53 | **pip install numpy** (takes a while…) 54 | 55 | The *VCForPython27* compiler needs the [*.NET Framework 3.5*](https://www.microsoft.com/en-us/download/details.aspx?id=21). A window should pop-up to invite you to install it. If it does not, you must install it by hand. 56 | 10. Install *matplotlib* by typing at the windows prompt: 57 | 58 | **pip install matplotlib** 59 | 60 | 11. Check the installed packages again: Type: 61 | 62 | **pip list** 63 | 64 | The response should be like: 65 | 66 | matplotlib(1.4.2) 67 | numpy(1.9.0) 68 | pip(1.5.6) 69 | pyparsing(2.0.3) 70 | python_dateutil(2.2) 71 | pytz(2014.7) 72 | setuptools(7.0) 73 | six(1.8.0) 74 | 75 | 12. Your system is now ready for *LightPipes for Python*. 76 | 77 | ##3. Install LightPipes for Python: 78 | 79 | 1. To install LightPipes for Python, version 1.0.0., Open the windows command window and type (copy/paste) at the windows prompt: 80 | 81 | **easy_install LightPipes** 82 | 83 | (newest version) 84 | 85 | or, from GitHub: 86 | 87 | 88 | **easy\_install https://github.com/FredvanGoor/LightPipes-for-Python/raw/master/LightPipes-Packages/LightPipes-1.0.0-py2.7-win32.egg** 89 | 90 | or, from the downloaded and extracted zip-file: 91 | 92 | **easy_install install\_directory\LightPipes-Packages\LightPipes-1.0.0-py2.7-win32.egg** 93 | 94 | where install\_directory is the directory in which you put the zip-file. 95 | 96 | 2. This will download the installation and installs LightPipes for Python. 97 | 3. Check by typing: 98 | 99 | **pip list** 100 | 101 | The list should now contain something like: 102 | 103 | lightpipes (1.0.0). 104 | 105 | You could un-install LightPipes by typing: 106 | 107 | **pip uninstall LightPipes** 108 | 109 | ##4. Installation of a very nice editor ‘Geany’: 110 | 111 | 1. Geany is a very useful editor for editing program files including *Python* scripts. 112 | 2. Download from: [http://www.geany.org/Download/Releases](http://www.geany.org/Download/Releases) geany-1.2.6setup.exe. 113 | 3. Execute: geany-1.2.6setup.exe. 114 | 4. Choose the default settings- and install directory. 115 | 116 | ##5. Make your first LightPipes script file. 117 | 118 | 1. Start *Geany*, open a new document and type (or copy/paste) the following script: 119 | 120 | import LightPipes 121 | import matplotlib.pyplot as plt 122 | m=1 123 | nm=1e-9*m 124 | um=1e-6*m 125 | mm=1e-3*m 126 | cm=1e-2*m 127 | 128 | try: 129 | LP=LightPipes.Init() 130 | 131 | wavelength=20*um 132 | size=30.0*mm 133 | N=1000 134 | 135 | F=LP.Begin(size,wavelength,N) 136 | F1=LP.CircAperture(0.15*mm, 0, -0.6*mm, F) 137 | F2=LP.CircAperture(0.15*mm, 0, 0.6*mm, F) 138 | F=LP.BeamMix(F1,F2) 139 | F=LP.Fresnel(10*cm,F) 140 | I=LP.Intensity(2,F) 141 | plt.imshow(I) 142 | plt.show() 143 | 144 | finally: 145 | del LightPipes 146 | 147 | 2. Save the document as ‘Young.py’, and push in *Geany* the execute button or open a terminal window and type at the prompt: 148 | 149 | **python Young.py** 150 | 151 | 3. After a few seconds a window with the output appears: 152 | 153 | ![](../img/twoholesPattern.png) 154 | 155 | 156 | ###6. Explanation of the commands 157 | 158 | Import LightPipes imports the LightPipes library (from ‘LightPipes.pyd’) 159 | 160 | import matplotlib.pyplot as plt imports matplotlib for the graphics 161 | LP=LightPipes.Init() initiates LightPipes 162 | (make a new instance of LightPipes called ‘LP’) 163 | for a grid-size, grid-dimension and wavelength defined by the Begin command. 164 | 165 | wavelength=20*um Define the wavelength, grid-size and grid-dimension. 166 | size=30.0*mm 167 | N=1000 168 | 169 | F=LP.Begin(size,wavelength,N) The simulation of Young’s experiment: 170 | F1=LP.CircAperture(0.15*mm, 0, -0.6*mm, F) A plane wave hits a screen with two holes. 171 | F2=LP.CircAperture(0.15*mm, 0, 0.6*mm, F) The interference pattern is observed at a distance of 10 cm. 172 | F=LP.BeamMix(F1,F2) 173 | F=LP.Fresnel(10*cm,F) 174 | I=LP.Intensity(2,F) 175 | 176 | plt.imshow(I) Plot and show the output interference pattern 177 | plt.show() 178 | 179 | del LightPipes Be sure that everything is cleaned-up after execution 180 | (this is normally not necessary but is good practice) 181 | 182 | Enjoy LightPipes for Python! 183 | 184 | Fred van Goor, 11/24/2015 11:49:43 AM 185 | 186 | -------------------------------------------------------------------------------- /LightPipes-Packages/sources/LightPipes.cp35-win_amd64.pyd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/LightPipes-Packages/sources/LightPipes.cp35-win_amd64.pyd -------------------------------------------------------------------------------- /LightPipes-Packages/sources/LightPipes.pyx: -------------------------------------------------------------------------------- 1 | # distutils: language = c++ 2 | # distutils: sources = [lpspy.cpp, subs.cpp, fresnl.cpp] 3 | import numpy as np 4 | cimport numpy as np 5 | from libcpp.vector cimport vector 6 | import webbrowser 7 | 8 | 9 | cdef extern from "lpspy.h" namespace "std": 10 | cdef cppclass lpspy: 11 | LightPipes() except + 12 | vector[vector[complex]] Axicon(double, double, double, double, vector[vector[complex]]) 13 | vector[vector[complex]] BeamMix(vector[vector[complex]], vector[vector[complex]]) 14 | vector[vector[complex]] Begin(double, double, int) 15 | vector[vector[complex]] CircAperture(double, double, double, vector[vector[complex]]) 16 | vector[vector[complex]] CircScreen(double, double, double, vector[vector[complex]]) 17 | vector[vector[complex]] Convert(vector[vector[complex]]) 18 | vector[vector[complex]] Forvard(double, vector[vector[complex]]) 19 | vector[vector[complex]] Fresnel(double, vector[vector[complex]]) 20 | vector[vector[complex]] Gain(double, double, double, vector[vector[complex]]) 21 | vector[vector[complex]] GaussAperture(double, double, double, double, vector[vector[complex]]) 22 | vector[vector[complex]] GaussScreen(double, double, double, double, vector[vector[complex]]) 23 | vector[vector[complex]] GaussHermite(int, int, double, double, vector[vector[complex]]) 24 | vector[vector[complex]] GaussLaguerre(int, int, double, double, vector[vector[complex]]) 25 | vector[vector[complex]] IntAttenuator(double, vector[vector[complex]]) 26 | vector[vector[complex]] Lens(double, double, double, vector[vector[complex]]) 27 | vector[vector[complex]] LensForvard(double, double, vector[vector[complex]]) 28 | vector[vector[complex]] LensFresnel(double, double, vector[vector[complex]]) 29 | vector[vector[complex]] MultIntensity(vector[vector[double]], vector[vector[complex]]) 30 | vector[vector[complex]] MultPhase(vector[vector[double]], vector[vector[complex]]) 31 | vector[vector[complex]] Normal(vector[vector[complex]]) 32 | vector[vector[double]] Intensity(int, vector[vector[complex]]) 33 | vector[vector[complex]] Interpol(double, int, double, double, double, double, vector[vector[complex]]) 34 | vector[vector[double]] Phase(vector[vector[complex]]) 35 | vector[vector[double]] PhaseUnwrap(vector[vector[double]]) 36 | vector[vector[complex]] PipFFT(int, vector[vector[complex]]) 37 | double Power(vector[vector[complex]]); 38 | vector[vector[complex]] RandomIntensity(double, double, vector[vector[complex]]) 39 | vector[vector[complex]] RandomPhase(double, double, vector[vector[complex]]) 40 | vector[vector[complex]] RectAperture(double, double, double, double, double, vector[vector[complex]]) 41 | vector[vector[complex]] RectScreen(double, double, double, double, double, vector[vector[complex]]) 42 | vector[vector[complex]] Steps(double, int, vector[vector[complex]], vector[vector[complex]]) 43 | double Strehl(vector[vector[complex]]) 44 | vector[vector[complex]] SubIntensity(vector[vector[double]], vector[vector[complex]]) 45 | vector[vector[complex]] SubPhase(vector[vector[double]], vector[vector[complex]]) 46 | vector[vector[complex]] Tilt(double ,double, vector[vector[complex]]) 47 | vector[vector[complex]] Zernike(int, int, double ,double, vector[vector[complex]]) 48 | void version() 49 | double getGridSize() 50 | void setGridSize(double newGridSize) 51 | double getWavelength() 52 | void setWavelength(double newWavelength) 53 | int getGridDimension() 54 | 55 | cdef class Init: 56 | """ 57 | LP = LightPipes.Init() 58 | Initiates the LightPipes for Python optical toolbox. 59 | 60 | Example:: 61 | 62 | >>> import LightPipes 63 | >>> LP = LightPipes.Init() 64 | >>> LP.version() 65 | version = 1.0.7 66 | >>> F = LP.Begin(0.03, 500e-9, 500) 67 | >>> F = LP.CircAperture(0.005,0,0,F) 68 | . 69 | . 70 | . 71 | 72 | """ 73 | 74 | cdef lpspy *thisptr # hold a C++ instance which we're wrapping 75 | def __cinit__(self): 76 | self.thisptr = new lpspy() 77 | def __dealloc__(self): 78 | del self.thisptr 79 | def Axicon(self, phi, n1, x_shift, y_shift, Fin): 80 | """ 81 | Fout = Axicon(phi, n1, x_shift, y_shift, Fin) 82 | Propagates the field through an axicon. 83 | 84 | Args:: 85 | 86 | phi: top angle of the axicon in radians 87 | n1: refractive index of the axicon material 88 | x_shift, y_shift: shift from the center 89 | Fin: input field 90 | 91 | Returns:: 92 | 93 | Fout: output field (N x N square array of complex numbers). 94 | 95 | Example: 96 | 97 | :ref:`Bessel beam with axicon ` 98 | 99 | """ 100 | return self.thisptr.Axicon(phi, n1, x_shift, y_shift, Fin) 101 | def BeamMix(self, Fin1, Fin2): 102 | """ 103 | Fout = BeamMix(F1, F2) 104 | Addition of the fields F1 and F2. 105 | 106 | Args:: 107 | 108 | F1, F2: input fields 109 | 110 | Returns:: 111 | 112 | Fout: output field (N x N square array of complex numbers). 113 | 114 | Example: 115 | 116 | :ref:`Two holes interferometer ` 117 | 118 | """ 119 | return self.thisptr.BeamMix(Fin1, Fin2) 120 | def Begin(self,size,labda,N): 121 | """ 122 | F = Begin(GridSize, Wavelength, N) 123 | Creates a plane wave (phase = 0.0, amplitude = 1.0) 124 | 125 | Args:: 126 | 127 | GridSize: size of the grid 128 | Wavelength: wavelength of the field 129 | N: N x N grid points (N must be even) 130 | 131 | Returns:: 132 | 133 | F: N x N square array of complex numbers (1+0j). 134 | 135 | Example: 136 | 137 | :ref:`Diffraction from a circular aperture ` 138 | 139 | """ 140 | return self.thisptr.Begin(size, labda, N) 141 | def CircAperture(self, R, x_shift, y_shift, Fin): 142 | """ 143 | Fout = CircAperture(R, x_shift, y_shift, Fin) 144 | Propagates the field through a circular aperture. 145 | 146 | Args:: 147 | 148 | R: radius of the aperture 149 | x_shift, y_shift: shift from the center 150 | Fin: input field 151 | 152 | Returns:: 153 | 154 | Fout: output field (N x N square array of complex numbers). 155 | 156 | Example: 157 | 158 | :ref:`Diffraction from a circular aperture ` 159 | 160 | """ 161 | return self.thisptr.CircAperture(R, x_shift, y_shift, Fin) 162 | def CircScreen(self, R, x_shift, y_shift, Fin): 163 | """ 164 | Fout = CircScreen(R, x_shift, y_shift, Fin) 165 | Diffracts the field by a circular screen. 166 | 167 | Args:: 168 | 169 | R: radius of the screen 170 | x_shift, y_shift: shift from the center 171 | Fin: input field 172 | 173 | Returns:: 174 | 175 | Fout: output field (N x N square array of complex numbers). 176 | 177 | Example: 178 | 179 | :ref:`Spot of Poisson ` 180 | 181 | """ 182 | return self.thisptr.CircScreen(R, x_shift, y_shift, Fin) 183 | def Convert(self, Fin): 184 | """ 185 | Fout = Convert(Fin) 186 | Converts the field from a spherical variable coordinate to a normal coordinate system. 187 | 188 | Args:: 189 | 190 | Fin: input field 191 | 192 | Returns:: 193 | 194 | Fout: output field (N x N square array of complex numbers). 195 | 196 | Example: 197 | 198 | :ref:`Unstable resonator ` 199 | 200 | """ 201 | return self.thisptr.Convert( Fin) 202 | def Forvard(self, z, Fin): 203 | """ 204 | Fout = Forvard(z, Fin) 205 | Propagates the field using a FFT algorithm. 206 | 207 | Args:: 208 | 209 | z: propagation distance 210 | Fin: input field 211 | 212 | Returns:: 213 | 214 | Fout: output field (N x N square array of complex numbers). 215 | 216 | Example: 217 | 218 | :ref:`Diffraction from a circular aperture ` 219 | 220 | """ 221 | return self.thisptr.Forvard(z, Fin) 222 | def Fresnel(self, z, Fin): 223 | """ 224 | Fout = Fresnel(z, Fin) 225 | Propagates the field using a convolution method. 226 | 227 | Args:: 228 | 229 | z: propagation distance 230 | Fin: input field 231 | 232 | Returns:: 233 | 234 | Fout: output field (N x N square array of complex numbers). 235 | 236 | Example: 237 | 238 | :ref:`Two holes interferometer ` 239 | 240 | """ 241 | return self.thisptr.Fresnel(z, Fin) 242 | def Gain(self, Isat, alpha0, Lgain, Fin): 243 | """ 244 | Fout = Gain(Isat, alpha0, Lgain, Fin) 245 | Propagates the field through a thin saturable gain sheet. 246 | 247 | :math:`F_{out}(x,y) = F_{in}(x,y) e^{\\alpha L_{gain}}`, with 248 | :math:`\\alpha = \\dfrac{\\alpha_0}{1 + {2 I(x,y)}/{I_{sat}}}`. 249 | 250 | :math:`2\\alpha L_{gain}` is the net round-trip intensity gain. 251 | :math:`\\alpha_0` is the small-signal intensity gain and 252 | :math:`I_{sat}` is the saturation intensity of the gain medium 253 | with a length :math:`L_{gain}`. 254 | 255 | The intensity must be doubled because of the left- and right 256 | propagating fields in a normal resonator. (If only one field is propagating in one direction (ring 257 | laser) you should double :math:`I_{sat}` as well to remove the factor 2 in the denominator). 258 | 259 | The gain sheet should be at one of the mirrors of a (un)stable laser resonator. 260 | 261 | See: Rensch and Chester (1973). 262 | 263 | Args:: 264 | 265 | Isat: saturation intensity 266 | alpha0: small signal gain 267 | Lgain: length of the gain sheet 268 | Fin: input field 269 | 270 | Returns:: 271 | 272 | Fout: output field (N x N square array of complex numbers). 273 | 274 | Example: 275 | 276 | :ref:`Unstable resonator ` 277 | 278 | """ 279 | return self.thisptr.Gain(Isat, alpha0, Lgain, Fin) 280 | def GaussAperture(self, w, x_shift, y_shift, T, Fin): 281 | """ 282 | Fout = GaussAperture(w, x_shift, y_shift, T, Fin) 283 | Inserts an aperture with a Gaussian shape in the field. 284 | 285 | :math:`F_{out}(x,y)= \\sqrt{T}e^{ -\\frac{ x^{2}+y^{2} }{2w^{2}} } F_{in}(x,y)` 286 | Args:: 287 | 288 | w: 1/e intensity width 289 | x_shift, y_shift: shift from center 290 | T: center intensity transmission 291 | Fin: input field 292 | 293 | Returns:: 294 | 295 | Fout: output field (N x N square array of complex numbers). 296 | 297 | """ 298 | return self.thisptr.GaussAperture( w, x_shift, y_shift, T, Fin) 299 | def GaussScreen(self, w, x_shift, y_shift, T, Fin): 300 | """ 301 | Fout = GaussScreen(w, x_shift, y_shift, T, Fin) 302 | Inserts an screen with a Gaussian shape in the field. 303 | 304 | :math:`F_{out}(x,y)= \\sqrt{1-(1-T)e^{ -\\frac{ x^{2}+y^{2} }{w^{2}} }} F_{in}(x,y)` 305 | Args:: 306 | 307 | w: 1/e intensity width 308 | x_shift, y_shift: shift from center 309 | T: center intensity transmission 310 | Fin: input field 311 | 312 | Returns:: 313 | 314 | Fout: output field (N x N square array of complex numbers). 315 | 316 | """ 317 | return self.thisptr.GaussScreen( w, x_shift, y_shift, T, Fin) 318 | def GaussHermite(self, m, n, A, w0, Fin): 319 | """ 320 | Fout = GaussHermite(m, n, A, w0, Fin) 321 | Substitutes a Gauss-Hermite :math:`TEM_{m,n}` mode (beam waist) in the field. 322 | 323 | :math:`F_{m,n}(x,y,z=0) = A H_m\\left(\\dfrac{\\sqrt{2}x}{w_0}\\right)H_n\\left(\\dfrac{\\sqrt{2}y}{w_0}\\right)e^{-\\frac{x^2+y^2}{w_0^2}}` 324 | Args:: 325 | 326 | m, n: mode indices 327 | A: Amplitude 328 | w0: Guaussian spot size parameter in the beam waist (1/e amplitude point) 329 | Fin: input field 330 | 331 | Returns:: 332 | 333 | Fout: output field (N x N square array of complex numbers). 334 | 335 | Reference:: 336 | 337 | A. Siegman, "Lasers", p. 642 338 | """ 339 | return self.thisptr.GaussHermite( m, n, A, w0, Fin) 340 | def GaussLaguerre(self, p, m, A, w0, Fin): 341 | """ 342 | Fout = GaussLaguerre(p, m, A, w0, Fin) 343 | Substitutes a Gauss-Laguerre :math:`TEM_{p,m}` mode (beam waist) in the field. 344 | 345 | :math:`F_{p,m}(x,y,z=0) = A \\left(\\frac{\\rho}{2}\\right)^{\\frac{|m|}{2} }L^p_m\\left(\\rho\\right)e^{-\\frac{\\rho}{2}}\\cos(m\\theta)`, 346 | 347 | with :math:`\\rho=\\frac{2(x^2+y^2)}{w_0^2}` 348 | Args:: 349 | 350 | p, m: mode indices 351 | A: Amplitude 352 | w0: Guaussian spot size parameter in the beam waist (1/e amplitude point) 353 | Fin: input field 354 | 355 | Returns:: 356 | 357 | Fout: output field (N x N square array of complex numbers). 358 | 359 | Reference:: 360 | 361 | A. Siegman, "Lasers", p. 642 362 | """ 363 | 364 | return self.thisptr.GaussLaguerre( p, m, A, w0, Fin) 365 | def IntAttenuator(self, att, Fin): 366 | """ 367 | Fout = IntAttenuator(att, Fin) 368 | Attenuates the intensity of the field Fin by a factor :math:`att` 369 | 370 | :math:`F_{out}(x,y)=\\sqrt{att}F_{in}(x,y)` 371 | 372 | Args:: 373 | 374 | att: intensity attenuation factor 375 | Fin: input field 376 | 377 | Returns:: 378 | 379 | Fout: output field (N x N square array of complex numbers). 380 | """ 381 | return self.thisptr.IntAttenuator( att, Fin) 382 | def Lens(self, f, x_shift, y_shift, Fin): 383 | """ 384 | Fout = Lens(f, x_shift, y_shift, Fin) 385 | Propagates the field through an ideal, thin lens. 386 | It adds a phase given by: 387 | :math:`F_{out}(x,y)=e^{-j\\frac{2\\pi}{\\lambda}\\left(\\frac{(x-x_{shift})^2+(y-y_{shift})^2}{2f}\\right)}F_{in}(x,y)` 388 | Args:: 389 | 390 | f: focal length 391 | x_shift, y_shift: shift from center 392 | Fin: input field 393 | 394 | Returns:: 395 | 396 | Fout: output field (N x N square array of complex numbers). 397 | """ 398 | return self.thisptr.Lens(f, x_shift, y_shift, Fin) 399 | def LensForvard(self, f, z, Fin): 400 | return self.thisptr.LensForvard(f, z, Fin) 401 | def LensFresnel(self, f, z, Fin): 402 | return self.thisptr.LensFresnel(f, z, Fin) 403 | def MultIntensity(self, Intens, Fin): 404 | return self.thisptr.MultIntensity( Intens, Fin) 405 | def MultPhase(self, Phase, Fin): 406 | return self.thisptr.MultPhase( Phase, Fin) 407 | def Normal(self, Fin): 408 | return self.thisptr.Normal(Fin) 409 | def Intensity(self,flag,Fin): 410 | """ 411 | I=Intensity(flag,Fin) 412 | Calculates the intensity, :math:`I(x,y)` of the field :math:`F_{in}(x,y)` 413 | 414 | :math:`I(x,y)=F_{in}(x,y).F_{in}(x,y)^*` 415 | 416 | Args:: 417 | 418 | flag: 0= no normalization, 1=normalized to 1, 2=normalized to 255 (for bitmaps) 419 | Fin: input field 420 | 421 | Returns:: 422 | 423 | I: intensity distribution (N x N square array of doubles) 424 | """ 425 | return self.thisptr.Intensity(flag,Fin) 426 | def Interpol(self, new_size, new_number, x_shift, y_shift, angle, magnif, Fin): 427 | return self.thisptr.Interpol(new_size, new_number, x_shift, y_shift, angle, magnif, Fin) 428 | def Phase(self,Fin): 429 | return self.thisptr.Phase(Fin) 430 | def PhaseUnwrap(self,Phi): 431 | return self.thisptr.PhaseUnwrap(Phi) 432 | def PipFFT(self, index, Fin): 433 | return self.thisptr.PipFFT(index, Fin) 434 | def Power(self, Fin): 435 | return self.thisptr.Power(Fin) 436 | def RandomIntensity(self, seed, noise, Fin): 437 | return self.thisptr.RandomIntensity(seed, noise, Fin) 438 | def RandomPhase(self, seed, maxPhase, Fin): 439 | return self.thisptr.RandomPhase(seed, maxPhase, Fin) 440 | def RectAperture(self, sx, sy, x_shift, y_shift, angle, Fin): 441 | return self.thisptr.RectAperture(sx, sy, x_shift, y_shift, angle, Fin) 442 | def RectScreen(self, sx, sy, x_shift, y_shift, angle, Fin): 443 | return self.thisptr.RectScreen(sx, sy, x_shift, y_shift, angle, Fin) 444 | def Steps(self, z, nstep, refr, Fin): 445 | """ 446 | Fout = Steps(z, nstep, refr, Fin) 447 | Propagates the field a distance, z, in nstep steps in a 448 | medium with a complex refractive index stored in the 449 | square array refr. 450 | 451 | Args:: 452 | 453 | z: propagation distance 454 | nstep: number of steps 455 | refr: N x N array of complex numbers 456 | Fin: input field 457 | 458 | Returns:: 459 | 460 | Fout: ouput field (N x N square array of complex numbers). 461 | 462 | Example: 463 | 464 | :ref:`Focus of a lens ` 465 | 466 | """ 467 | return self.thisptr.Steps(z, nstep, refr, Fin) 468 | def Strehl(self, Fin): 469 | return self.thisptr.Strehl(Fin) 470 | def SubIntensity(self, Intens, Fin): 471 | return self.thisptr.SubIntensity( Intens, Fin) 472 | def SubPhase(self, Phase, Fin): 473 | return self.thisptr.SubPhase( Phase, Fin) 474 | def Tilt(self, tx, ty, Fin): 475 | return self.thisptr.Tilt( tx, ty, Fin) 476 | def Zernike(self, n, m, R, A, Fin): 477 | return self.thisptr.Zernike(n, m, R, A, Fin) 478 | def version(self): 479 | self.thisptr.version() 480 | def help(self): 481 | """ 482 | Go to the LightPipes documentation website on: 483 | 484 | http://pythonhosted.org/LightPipes/ 485 | """ 486 | webbrowser.open_new("https://pythonhosted.org/LightPipes/") 487 | def getGridSize(self): 488 | return self.thisptr.getGridSize() 489 | def setGridSize(self, newSize): 490 | self.thisptr.setGridSize(newSize) 491 | def getWavelength(self): 492 | return self.thisptr.getWavelength() 493 | def setGridWavelength(self, newWavelength): 494 | self.thisptr.setWavelength(newWavelength) 495 | def getGridDimension(self): 496 | return self.thisptr.getGridDimension() 497 | -------------------------------------------------------------------------------- /LightPipes-Packages/sources/Young.py: -------------------------------------------------------------------------------- 1 | #! python3 2 | import LightPipes as lp 3 | import time 4 | import sys 5 | import matplotlib.pyplot as plt 6 | print('Executed with python version:') 7 | print(sys.version);print('\n') 8 | 9 | start_time = time.time() 10 | 11 | m=1 12 | nm=1e-9*m 13 | um=1e-6*m 14 | mm=1e-3*m 15 | cm=1e-2*m 16 | 17 | try: 18 | LP=lp.Init() 19 | 20 | wavelength=20*um 21 | size=30.0*mm 22 | N=500 23 | print('using LightPipes version: ') 24 | LP.version();print('\n') 25 | #LP.help() 26 | F=LP.Begin(size,wavelength,N) 27 | F1=LP.CircAperture(0.15*mm, -0.6*mm,0, F) 28 | F2=LP.CircAperture(0.15*mm, 0.6*mm,0, F) 29 | F=LP.BeamMix(F1,F2) 30 | F=LP.Forvard(10*cm,F) 31 | I=LP.Intensity(2,F) 32 | print("Execution time: --- %4.2f seconds ---" % (time.time() - start_time)) 33 | #plt.imshow(I); 34 | plt.contourf(I,50); plt.axis('equal') 35 | plt.show() 36 | finally: 37 | del lp 38 | -------------------------------------------------------------------------------- /LightPipes-Packages/sources/build/lib.win-amd64-3.5/LightPipes.cp35-win_amd64.pyd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/LightPipes-Packages/sources/build/lib.win-amd64-3.5/LightPipes.cp35-win_amd64.pyd -------------------------------------------------------------------------------- /LightPipes-Packages/sources/build/temp.win-amd64-3.5/Release/LightPipes.cp35-win_amd64.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/LightPipes-Packages/sources/build/temp.win-amd64-3.5/Release/LightPipes.cp35-win_amd64.exp -------------------------------------------------------------------------------- /LightPipes-Packages/sources/build/temp.win-amd64-3.5/Release/LightPipes.cp35-win_amd64.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/LightPipes-Packages/sources/build/temp.win-amd64-3.5/Release/LightPipes.cp35-win_amd64.lib -------------------------------------------------------------------------------- /LightPipes-Packages/sources/build/temp.win-amd64-3.5/Release/LightPipes.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/LightPipes-Packages/sources/build/temp.win-amd64-3.5/Release/LightPipes.obj -------------------------------------------------------------------------------- /LightPipes-Packages/sources/build/temp.win-amd64-3.5/Release/fresnl.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/LightPipes-Packages/sources/build/temp.win-amd64-3.5/Release/fresnl.obj -------------------------------------------------------------------------------- /LightPipes-Packages/sources/build/temp.win-amd64-3.5/Release/lpspy.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/LightPipes-Packages/sources/build/temp.win-amd64-3.5/Release/lpspy.obj -------------------------------------------------------------------------------- /LightPipes-Packages/sources/build/temp.win-amd64-3.5/Release/subs.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/LightPipes-Packages/sources/build/temp.win-amd64-3.5/Release/subs.obj -------------------------------------------------------------------------------- /LightPipes-Packages/sources/fftw3.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003, 2007-14 Matteo Frigo 3 | * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology 4 | * 5 | * The following statement of license applies *only* to this header file, 6 | * and *not* to the other files distributed with FFTW or derived therefrom: 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 20 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 25 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /***************************** NOTE TO USERS ********************************* 33 | * 34 | * THIS IS A HEADER FILE, NOT A MANUAL 35 | * 36 | * If you want to know how to use FFTW, please read the manual, 37 | * online at http://www.fftw.org/doc/ and also included with FFTW. 38 | * For a quick start, see the manual's tutorial section. 39 | * 40 | * (Reading header files to learn how to use a library is a habit 41 | * stemming from code lacking a proper manual. Arguably, it's a 42 | * *bad* habit in most cases, because header files can contain 43 | * interfaces that are not part of the public, stable API.) 44 | * 45 | ****************************************************************************/ 46 | 47 | #ifndef FFTW3_H 48 | #define FFTW3_H 49 | 50 | #include 51 | 52 | #ifdef __cplusplus 53 | extern "C" 54 | { 55 | #endif /* __cplusplus */ 56 | 57 | /* If is included, use the C99 complex type. Otherwise 58 | define a type bit-compatible with C99 complex */ 59 | #if !defined(FFTW_NO_Complex) && defined(_Complex_I) && defined(complex) && defined(I) 60 | # define FFTW_DEFINE_COMPLEX(R, C) typedef R _Complex C 61 | #else 62 | # define FFTW_DEFINE_COMPLEX(R, C) typedef R C[2] 63 | #endif 64 | 65 | #define FFTW_CONCAT(prefix, name) prefix ## name 66 | #define FFTW_MANGLE_DOUBLE(name) FFTW_CONCAT(fftw_, name) 67 | #define FFTW_MANGLE_FLOAT(name) FFTW_CONCAT(fftwf_, name) 68 | #define FFTW_MANGLE_LONG_DOUBLE(name) FFTW_CONCAT(fftwl_, name) 69 | #define FFTW_MANGLE_QUAD(name) FFTW_CONCAT(fftwq_, name) 70 | 71 | /* IMPORTANT: for Windows compilers, you should add a line 72 | */ 73 | #define FFTW_DLL 74 | /* 75 | here and in kernel/ifftw.h if you are compiling/using FFTW as a 76 | DLL, in order to do the proper importing/exporting, or 77 | alternatively compile with -DFFTW_DLL or the equivalent 78 | command-line flag. This is not necessary under MinGW/Cygwin, where 79 | libtool does the imports/exports automatically. */ 80 | #if defined(FFTW_DLL) && (defined(_WIN32) || defined(__WIN32__)) 81 | /* annoying Windows syntax for shared-library declarations */ 82 | # if defined(COMPILING_FFTW) /* defined in api.h when compiling FFTW */ 83 | # define FFTW_EXTERN extern __declspec(dllexport) 84 | # else /* user is calling FFTW; import symbol */ 85 | # define FFTW_EXTERN extern __declspec(dllimport) 86 | # endif 87 | #else 88 | # define FFTW_EXTERN extern 89 | #endif 90 | 91 | enum fftw_r2r_kind_do_not_use_me { 92 | FFTW_R2HC=0, FFTW_HC2R=1, FFTW_DHT=2, 93 | FFTW_REDFT00=3, FFTW_REDFT01=4, FFTW_REDFT10=5, FFTW_REDFT11=6, 94 | FFTW_RODFT00=7, FFTW_RODFT01=8, FFTW_RODFT10=9, FFTW_RODFT11=10 95 | }; 96 | 97 | struct fftw_iodim_do_not_use_me { 98 | int n; /* dimension size */ 99 | int is; /* input stride */ 100 | int os; /* output stride */ 101 | }; 102 | 103 | #include /* for ptrdiff_t */ 104 | struct fftw_iodim64_do_not_use_me { 105 | ptrdiff_t n; /* dimension size */ 106 | ptrdiff_t is; /* input stride */ 107 | ptrdiff_t os; /* output stride */ 108 | }; 109 | 110 | typedef void (*fftw_write_char_func_do_not_use_me)(char c, void *); 111 | typedef int (*fftw_read_char_func_do_not_use_me)(void *); 112 | 113 | /* 114 | huge second-order macro that defines prototypes for all API 115 | functions. We expand this macro for each supported precision 116 | 117 | X: name-mangling macro 118 | R: real data type 119 | C: complex data type 120 | */ 121 | 122 | #define FFTW_DEFINE_API(X, R, C) \ 123 | \ 124 | FFTW_DEFINE_COMPLEX(R, C); \ 125 | \ 126 | typedef struct X(plan_s) *X(plan); \ 127 | \ 128 | typedef struct fftw_iodim_do_not_use_me X(iodim); \ 129 | typedef struct fftw_iodim64_do_not_use_me X(iodim64); \ 130 | \ 131 | typedef enum fftw_r2r_kind_do_not_use_me X(r2r_kind); \ 132 | \ 133 | typedef fftw_write_char_func_do_not_use_me X(write_char_func); \ 134 | typedef fftw_read_char_func_do_not_use_me X(read_char_func); \ 135 | \ 136 | FFTW_EXTERN void X(execute)(const X(plan) p); \ 137 | \ 138 | FFTW_EXTERN X(plan) X(plan_dft)(int rank, const int *n, \ 139 | C *in, C *out, int sign, unsigned flags); \ 140 | \ 141 | FFTW_EXTERN X(plan) X(plan_dft_1d)(int n, C *in, C *out, int sign, \ 142 | unsigned flags); \ 143 | FFTW_EXTERN X(plan) X(plan_dft_2d)(int n0, int n1, \ 144 | C *in, C *out, int sign, unsigned flags); \ 145 | FFTW_EXTERN X(plan) X(plan_dft_3d)(int n0, int n1, int n2, \ 146 | C *in, C *out, int sign, unsigned flags); \ 147 | \ 148 | FFTW_EXTERN X(plan) X(plan_many_dft)(int rank, const int *n, \ 149 | int howmany, \ 150 | C *in, const int *inembed, \ 151 | int istride, int idist, \ 152 | C *out, const int *onembed, \ 153 | int ostride, int odist, \ 154 | int sign, unsigned flags); \ 155 | \ 156 | FFTW_EXTERN X(plan) X(plan_guru_dft)(int rank, const X(iodim) *dims, \ 157 | int howmany_rank, \ 158 | const X(iodim) *howmany_dims, \ 159 | C *in, C *out, \ 160 | int sign, unsigned flags); \ 161 | FFTW_EXTERN X(plan) X(plan_guru_split_dft)(int rank, const X(iodim) *dims, \ 162 | int howmany_rank, \ 163 | const X(iodim) *howmany_dims, \ 164 | R *ri, R *ii, R *ro, R *io, \ 165 | unsigned flags); \ 166 | \ 167 | FFTW_EXTERN X(plan) X(plan_guru64_dft)(int rank, \ 168 | const X(iodim64) *dims, \ 169 | int howmany_rank, \ 170 | const X(iodim64) *howmany_dims, \ 171 | C *in, C *out, \ 172 | int sign, unsigned flags); \ 173 | FFTW_EXTERN X(plan) X(plan_guru64_split_dft)(int rank, \ 174 | const X(iodim64) *dims, \ 175 | int howmany_rank, \ 176 | const X(iodim64) *howmany_dims, \ 177 | R *ri, R *ii, R *ro, R *io, \ 178 | unsigned flags); \ 179 | \ 180 | FFTW_EXTERN void X(execute_dft)(const X(plan) p, C *in, C *out); \ 181 | FFTW_EXTERN void X(execute_split_dft)(const X(plan) p, R *ri, R *ii, \ 182 | R *ro, R *io); \ 183 | \ 184 | FFTW_EXTERN X(plan) X(plan_many_dft_r2c)(int rank, const int *n, \ 185 | int howmany, \ 186 | R *in, const int *inembed, \ 187 | int istride, int idist, \ 188 | C *out, const int *onembed, \ 189 | int ostride, int odist, \ 190 | unsigned flags); \ 191 | \ 192 | FFTW_EXTERN X(plan) X(plan_dft_r2c)(int rank, const int *n, \ 193 | R *in, C *out, unsigned flags); \ 194 | \ 195 | FFTW_EXTERN X(plan) X(plan_dft_r2c_1d)(int n,R *in,C *out,unsigned flags); \ 196 | FFTW_EXTERN X(plan) X(plan_dft_r2c_2d)(int n0, int n1, \ 197 | R *in, C *out, unsigned flags); \ 198 | FFTW_EXTERN X(plan) X(plan_dft_r2c_3d)(int n0, int n1, \ 199 | int n2, \ 200 | R *in, C *out, unsigned flags); \ 201 | \ 202 | \ 203 | FFTW_EXTERN X(plan) X(plan_many_dft_c2r)(int rank, const int *n, \ 204 | int howmany, \ 205 | C *in, const int *inembed, \ 206 | int istride, int idist, \ 207 | R *out, const int *onembed, \ 208 | int ostride, int odist, \ 209 | unsigned flags); \ 210 | \ 211 | FFTW_EXTERN X(plan) X(plan_dft_c2r)(int rank, const int *n, \ 212 | C *in, R *out, unsigned flags); \ 213 | \ 214 | FFTW_EXTERN X(plan) X(plan_dft_c2r_1d)(int n,C *in,R *out,unsigned flags); \ 215 | FFTW_EXTERN X(plan) X(plan_dft_c2r_2d)(int n0, int n1, \ 216 | C *in, R *out, unsigned flags); \ 217 | FFTW_EXTERN X(plan) X(plan_dft_c2r_3d)(int n0, int n1, \ 218 | int n2, \ 219 | C *in, R *out, unsigned flags); \ 220 | \ 221 | FFTW_EXTERN X(plan) X(plan_guru_dft_r2c)(int rank, const X(iodim) *dims, \ 222 | int howmany_rank, \ 223 | const X(iodim) *howmany_dims, \ 224 | R *in, C *out, \ 225 | unsigned flags); \ 226 | FFTW_EXTERN X(plan) X(plan_guru_dft_c2r)(int rank, const X(iodim) *dims, \ 227 | int howmany_rank, \ 228 | const X(iodim) *howmany_dims, \ 229 | C *in, R *out, \ 230 | unsigned flags); \ 231 | \ 232 | FFTW_EXTERN X(plan) X(plan_guru_split_dft_r2c)( \ 233 | int rank, const X(iodim) *dims, \ 234 | int howmany_rank, \ 235 | const X(iodim) *howmany_dims, \ 236 | R *in, R *ro, R *io, \ 237 | unsigned flags); \ 238 | FFTW_EXTERN X(plan) X(plan_guru_split_dft_c2r)( \ 239 | int rank, const X(iodim) *dims, \ 240 | int howmany_rank, \ 241 | const X(iodim) *howmany_dims, \ 242 | R *ri, R *ii, R *out, \ 243 | unsigned flags); \ 244 | \ 245 | FFTW_EXTERN X(plan) X(plan_guru64_dft_r2c)(int rank, \ 246 | const X(iodim64) *dims, \ 247 | int howmany_rank, \ 248 | const X(iodim64) *howmany_dims, \ 249 | R *in, C *out, \ 250 | unsigned flags); \ 251 | FFTW_EXTERN X(plan) X(plan_guru64_dft_c2r)(int rank, \ 252 | const X(iodim64) *dims, \ 253 | int howmany_rank, \ 254 | const X(iodim64) *howmany_dims, \ 255 | C *in, R *out, \ 256 | unsigned flags); \ 257 | \ 258 | FFTW_EXTERN X(plan) X(plan_guru64_split_dft_r2c)( \ 259 | int rank, const X(iodim64) *dims, \ 260 | int howmany_rank, \ 261 | const X(iodim64) *howmany_dims, \ 262 | R *in, R *ro, R *io, \ 263 | unsigned flags); \ 264 | FFTW_EXTERN X(plan) X(plan_guru64_split_dft_c2r)( \ 265 | int rank, const X(iodim64) *dims, \ 266 | int howmany_rank, \ 267 | const X(iodim64) *howmany_dims, \ 268 | R *ri, R *ii, R *out, \ 269 | unsigned flags); \ 270 | \ 271 | FFTW_EXTERN void X(execute_dft_r2c)(const X(plan) p, R *in, C *out); \ 272 | FFTW_EXTERN void X(execute_dft_c2r)(const X(plan) p, C *in, R *out); \ 273 | \ 274 | FFTW_EXTERN void X(execute_split_dft_r2c)(const X(plan) p, \ 275 | R *in, R *ro, R *io); \ 276 | FFTW_EXTERN void X(execute_split_dft_c2r)(const X(plan) p, \ 277 | R *ri, R *ii, R *out); \ 278 | \ 279 | FFTW_EXTERN X(plan) X(plan_many_r2r)(int rank, const int *n, \ 280 | int howmany, \ 281 | R *in, const int *inembed, \ 282 | int istride, int idist, \ 283 | R *out, const int *onembed, \ 284 | int ostride, int odist, \ 285 | const X(r2r_kind) *kind, unsigned flags); \ 286 | \ 287 | FFTW_EXTERN X(plan) X(plan_r2r)(int rank, const int *n, R *in, R *out, \ 288 | const X(r2r_kind) *kind, unsigned flags); \ 289 | \ 290 | FFTW_EXTERN X(plan) X(plan_r2r_1d)(int n, R *in, R *out, \ 291 | X(r2r_kind) kind, unsigned flags); \ 292 | FFTW_EXTERN X(plan) X(plan_r2r_2d)(int n0, int n1, R *in, R *out, \ 293 | X(r2r_kind) kind0, X(r2r_kind) kind1, \ 294 | unsigned flags); \ 295 | FFTW_EXTERN X(plan) X(plan_r2r_3d)(int n0, int n1, int n2, \ 296 | R *in, R *out, X(r2r_kind) kind0, \ 297 | X(r2r_kind) kind1, X(r2r_kind) kind2, \ 298 | unsigned flags); \ 299 | \ 300 | FFTW_EXTERN X(plan) X(plan_guru_r2r)(int rank, const X(iodim) *dims, \ 301 | int howmany_rank, \ 302 | const X(iodim) *howmany_dims, \ 303 | R *in, R *out, \ 304 | const X(r2r_kind) *kind, unsigned flags); \ 305 | \ 306 | FFTW_EXTERN X(plan) X(plan_guru64_r2r)(int rank, const X(iodim64) *dims, \ 307 | int howmany_rank, \ 308 | const X(iodim64) *howmany_dims, \ 309 | R *in, R *out, \ 310 | const X(r2r_kind) *kind, unsigned flags); \ 311 | \ 312 | FFTW_EXTERN void X(execute_r2r)(const X(plan) p, R *in, R *out); \ 313 | \ 314 | FFTW_EXTERN void X(destroy_plan)(X(plan) p); \ 315 | FFTW_EXTERN void X(forget_wisdom)(void); \ 316 | FFTW_EXTERN void X(cleanup)(void); \ 317 | \ 318 | FFTW_EXTERN void X(set_timelimit)(double t); \ 319 | \ 320 | FFTW_EXTERN void X(plan_with_nthreads)(int nthreads); \ 321 | FFTW_EXTERN int X(init_threads)(void); \ 322 | FFTW_EXTERN void X(cleanup_threads)(void); \ 323 | \ 324 | FFTW_EXTERN int X(export_wisdom_to_filename)(const char *filename); \ 325 | FFTW_EXTERN void X(export_wisdom_to_file)(FILE *output_file); \ 326 | FFTW_EXTERN char *X(export_wisdom_to_string)(void); \ 327 | FFTW_EXTERN void X(export_wisdom)(X(write_char_func) write_char, \ 328 | void *data); \ 329 | FFTW_EXTERN int X(import_system_wisdom)(void); \ 330 | FFTW_EXTERN int X(import_wisdom_from_filename)(const char *filename); \ 331 | FFTW_EXTERN int X(import_wisdom_from_file)(FILE *input_file); \ 332 | FFTW_EXTERN int X(import_wisdom_from_string)(const char *input_string); \ 333 | FFTW_EXTERN int X(import_wisdom)(X(read_char_func) read_char, void *data); \ 334 | \ 335 | FFTW_EXTERN void X(fprint_plan)(const X(plan) p, FILE *output_file); \ 336 | FFTW_EXTERN void X(print_plan)(const X(plan) p); \ 337 | FFTW_EXTERN char *X(sprint_plan)(const X(plan) p); \ 338 | \ 339 | FFTW_EXTERN void *X(malloc)(size_t n); \ 340 | FFTW_EXTERN R *X(alloc_real)(size_t n); \ 341 | FFTW_EXTERN C *X(alloc_complex)(size_t n); \ 342 | FFTW_EXTERN void X(free)(void *p); \ 343 | \ 344 | FFTW_EXTERN void X(flops)(const X(plan) p, \ 345 | double *add, double *mul, double *fmas); \ 346 | FFTW_EXTERN double X(estimate_cost)(const X(plan) p); \ 347 | FFTW_EXTERN double X(cost)(const X(plan) p); \ 348 | \ 349 | FFTW_EXTERN int X(alignment_of)(R *p); \ 350 | FFTW_EXTERN const char X(version)[]; \ 351 | FFTW_EXTERN const char X(cc)[]; \ 352 | FFTW_EXTERN const char X(codelet_optim)[]; 353 | 354 | 355 | /* end of FFTW_DEFINE_API macro */ 356 | 357 | FFTW_DEFINE_API(FFTW_MANGLE_DOUBLE, double, fftw_complex) 358 | FFTW_DEFINE_API(FFTW_MANGLE_FLOAT, float, fftwf_complex) 359 | FFTW_DEFINE_API(FFTW_MANGLE_LONG_DOUBLE, long double, fftwl_complex) 360 | 361 | /* __float128 (quad precision) is a gcc extension on i386, x86_64, and ia64 362 | for gcc >= 4.6 (compiled in FFTW with --enable-quad-precision) */ 363 | #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) \ 364 | && !(defined(__ICC) || defined(__INTEL_COMPILER)) \ 365 | && (defined(__i386__) || defined(__x86_64__) || defined(__ia64__)) 366 | # if !defined(FFTW_NO_Complex) && defined(_Complex_I) && defined(complex) && defined(I) 367 | /* note: __float128 is a typedef, which is not supported with the _Complex 368 | keyword in gcc, so instead we use this ugly __attribute__ version. 369 | However, we can't simply pass the __attribute__ version to 370 | FFTW_DEFINE_API because the __attribute__ confuses gcc in pointer 371 | types. Hence redefining FFTW_DEFINE_COMPLEX. Ugh. */ 372 | # undef FFTW_DEFINE_COMPLEX 373 | # define FFTW_DEFINE_COMPLEX(R, C) typedef _Complex float __attribute__((mode(TC))) C 374 | # endif 375 | FFTW_DEFINE_API(FFTW_MANGLE_QUAD, __float128, fftwq_complex) 376 | #endif 377 | 378 | #define FFTW_FORWARD (-1) 379 | #define FFTW_BACKWARD (+1) 380 | 381 | #define FFTW_NO_TIMELIMIT (-1.0) 382 | 383 | /* documented flags */ 384 | #define FFTW_MEASURE (0U) 385 | #define FFTW_DESTROY_INPUT (1U << 0) 386 | #define FFTW_UNALIGNED (1U << 1) 387 | #define FFTW_CONSERVE_MEMORY (1U << 2) 388 | #define FFTW_EXHAUSTIVE (1U << 3) /* NO_EXHAUSTIVE is default */ 389 | #define FFTW_PRESERVE_INPUT (1U << 4) /* cancels FFTW_DESTROY_INPUT */ 390 | #define FFTW_PATIENT (1U << 5) /* IMPATIENT is default */ 391 | #define FFTW_ESTIMATE (1U << 6) 392 | #define FFTW_WISDOM_ONLY (1U << 21) 393 | 394 | /* undocumented beyond-guru flags */ 395 | #define FFTW_ESTIMATE_PATIENT (1U << 7) 396 | #define FFTW_BELIEVE_PCOST (1U << 8) 397 | #define FFTW_NO_DFT_R2HC (1U << 9) 398 | #define FFTW_NO_NONTHREADED (1U << 10) 399 | #define FFTW_NO_BUFFERING (1U << 11) 400 | #define FFTW_NO_INDIRECT_OP (1U << 12) 401 | #define FFTW_ALLOW_LARGE_GENERIC (1U << 13) /* NO_LARGE_GENERIC is default */ 402 | #define FFTW_NO_RANK_SPLITS (1U << 14) 403 | #define FFTW_NO_VRANK_SPLITS (1U << 15) 404 | #define FFTW_NO_VRECURSE (1U << 16) 405 | #define FFTW_NO_SIMD (1U << 17) 406 | #define FFTW_NO_SLOW (1U << 18) 407 | #define FFTW_NO_FIXED_RADIX_LARGE_N (1U << 19) 408 | #define FFTW_ALLOW_PRUNING (1U << 20) 409 | 410 | #ifdef __cplusplus 411 | } /* extern "C" */ 412 | #endif /* __cplusplus */ 413 | 414 | #endif /* FFTW3_H */ 415 | -------------------------------------------------------------------------------- /LightPipes-Packages/sources/fresnl.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "fresnl.h" 4 | /* 5 | Fresnel Integrals from CEPHES 6 | Modified for portability by G. Vdovin (gleb@ei.et.tudelft.nl) 7 | Oct 1995 8 | */ 9 | 10 | /* 11 | Cephes Math Library Release 2.1: January, 1989 12 | Copyright 1984, 1987, 1989 by Stephen L. Moshier 13 | */ 14 | 15 | /* fresnl.c 16 | * 17 | * Fresnel integrals 18 | * 19 | * 20 | * 21 | * SYNOPSIS: 22 | * 23 | * double x, S, C; 24 | * int fresnl(); 25 | * 26 | * fresnl( x, _&S, _&C ); 27 | * 28 | * 29 | * DESCRIPTION: 30 | * 31 | * Evaluates the Fresnel integrals 32 | * 33 | * x 34 | * - 35 | * | | 36 | * C(x) = | cos(pi/2 t**2) dt, 37 | * | | 38 | * - 39 | * 0 40 | * 41 | * x 42 | * - 43 | * | | 44 | * S(x) = | sin(pi/2 t**2) dt. 45 | * | | 46 | * - 47 | * 0 48 | * 49 | * 50 | * The integrals are approximated by rational functions if x is small. 51 | * For large x, auxiliary functions f(x) and g(x) are employed 52 | * such that 53 | * 54 | * C(x) = 0.5 + f(x) sin( pi/2 x**2 ) - g(x) cos( pi/2 x**2 ) 55 | * S(x) = 0.5 - f(x) cos( pi/2 x**2 ) - g(x) sin( pi/2 x**2 ) . 56 | * 57 | * 58 | * 59 | * ACCURACY: 60 | * 61 | * Relative error. 62 | * 63 | * Arithmetic function domain # trials peak rms 64 | * IEEE S(x) 0, 10 10000 2.0e-15 3.2e-16 65 | * IEEE C(x) 0, 10 10000 1.8e-15 3.3e-16 66 | * DEC S(x) 0, 10 6000 2.2e-16 3.9e-17 67 | * DEC C(x) 0, 10 5000 2.3e-16 3.9e-17 68 | */ 69 | 70 | /* 71 | This is a test program 72 | 73 | */ 74 | 75 | /* 76 | 77 | int fresnl(); 78 | 79 | main(){ 80 | double a,b,c; 81 | int i, dum; 82 | for (i=-1000; i<= 1000; i++){ 83 | 84 | a=(double)(((double) i)/100.); 85 | 86 | dum=fresnl(a, &b, &c); 87 | 88 | printf("%e %e %e \n", a,b,c); 89 | 90 | } 91 | 92 | } 93 | */ 94 | 95 | double polevl(double x, const double *coeff, int N); 96 | double p1evl( double x, const double *coeff, int N); 97 | 98 | int fresnl(double xxa, double *ssa, double *cca ) 99 | { 100 | double f, g, cc, ss, c, s, t, u; 101 | double x, x2; 102 | 103 | 104 | double PII= 3.14159265358979323844; 105 | double PIO2 = 1.57079632679489661922; 106 | 107 | 108 | static double sn[6] = { 109 | -2.99181919401019853726E3, 110 | 7.08840045257738576863E5, 111 | -6.29741486205862506537E7, 112 | 2.54890880573376359104E9, 113 | -4.42979518059697779103E10, 114 | 3.18016297876567817986E11, 115 | }; 116 | static double sd[6] = { 117 | /* 1.00000000000000000000E0,*/ 118 | 2.81376268889994315696E2, 119 | 4.55847810806532581675E4, 120 | 5.17343888770096400730E6, 121 | 4.19320245898111231129E8, 122 | 2.24411795645340920940E10, 123 | 6.07366389490084639049E11, 124 | }; 125 | 126 | 127 | static double cn[6] = { 128 | -4.98843114573573548651E-8, 129 | 9.50428062829859605134E-6, 130 | -6.45191435683965050962E-4, 131 | 1.88843319396703850064E-2, 132 | -2.05525900955013891793E-1, 133 | 9.99999999999999998822E-1, 134 | }; 135 | static double cd[7] = { 136 | 3.99982968972495980367E-12, 137 | 9.15439215774657478799E-10, 138 | 1.25001862479598821474E-7, 139 | 1.22262789024179030997E-5, 140 | 8.68029542941784300606E-4, 141 | 4.12142090722199792936E-2, 142 | 1.00000000000000000118E0, 143 | }; 144 | 145 | static double fn[10] = { 146 | 4.21543555043677546506E-1, 147 | 1.43407919780758885261E-1, 148 | 1.15220955073585758835E-2, 149 | 3.45017939782574027900E-4, 150 | 4.63613749287867322088E-6, 151 | 3.05568983790257605827E-8, 152 | 1.02304514164907233465E-10, 153 | 1.72010743268161828879E-13, 154 | 1.34283276233062758925E-16, 155 | 3.76329711269987889006E-20, 156 | }; 157 | static double fd[10] = { 158 | /* 1.00000000000000000000E0,*/ 159 | 7.51586398353378947175E-1, 160 | 1.16888925859191382142E-1, 161 | 6.44051526508858611005E-3, 162 | 1.55934409164153020873E-4, 163 | 1.84627567348930545870E-6, 164 | 1.12699224763999035261E-8, 165 | 3.60140029589371370404E-11, 166 | 5.88754533621578410010E-14, 167 | 4.52001434074129701496E-17, 168 | 1.25443237090011264384E-20, 169 | }; 170 | 171 | 172 | 173 | 174 | static double gn[11] = { 175 | 5.04442073643383265887E-1, 176 | 1.97102833525523411709E-1, 177 | 1.87648584092575249293E-2, 178 | 6.84079380915393090172E-4, 179 | 1.15138826111884280931E-5, 180 | 9.82852443688422223854E-8, 181 | 4.45344415861750144738E-10, 182 | 1.08268041139020870318E-12, 183 | 1.37555460633261799868E-15, 184 | 8.36354435630677421531E-19, 185 | 1.86958710162783235106E-22, 186 | }; 187 | static double gd[11] = { 188 | /* 1.00000000000000000000E0,*/ 189 | 1.47495759925128324529E0, 190 | 3.37748989120019970451E-1, 191 | 2.53603741420338795122E-2, 192 | 8.14679107184306179049E-4, 193 | 1.27545075667729118702E-5, 194 | 1.04314589657571990585E-7, 195 | 4.60680728146520428211E-10, 196 | 1.10273215066240270757E-12, 197 | 1.38796531259578871258E-15, 198 | 8.39158816283118707363E-19, 199 | 1.86958710162783236342E-22, 200 | }; 201 | 202 | x = fabs(xxa); 203 | x2 = x * x; 204 | if( x2 < 2.5625 ) 205 | { 206 | t = x2 * x2; 207 | ss = x * x2 * polevl( t, sn, 5)/p1evl( t, sd, 6 ); 208 | cc = x * polevl( t, cn, 5)/polevl(t, cd, 6 ); 209 | goto done; 210 | } 211 | if( x > 36974.0 ) 212 | { 213 | cc = 0.5; 214 | ss = 0.5; 215 | goto done; 216 | } 217 | /* Auxiliary functions for large argument */ 218 | x2 = x * x; 219 | t = PII * x2; 220 | u = 1.0/(t * t); 221 | t = 1.0/t; 222 | f = 1.0 - u * polevl( u, fn, 9)/p1evl(u, fd, 10); 223 | g = t * polevl( u, gn, 10)/p1evl(u, gd, 11); 224 | 225 | t = PIO2 * x2; 226 | c = cos(t); 227 | s = sin(t); 228 | t = PII * x; 229 | cc = 0.5 + (f * s - g * c)/t; 230 | ss = 0.5 - (f * c + g * s)/t; 231 | done: 232 | if( xxa < 0.0 ) 233 | { 234 | cc = -cc; 235 | ss = -ss; 236 | } 237 | *cca = cc; 238 | *ssa = ss; 239 | return(0); 240 | } 241 | /* polevl.c 242 | * p1evl.c 243 | * 244 | * Evaluate polynomial 245 | * 246 | * 247 | * 248 | * SYNOPSIS: 249 | * 250 | * int N; 251 | * double x, y, coef[N+1], polevl[]; 252 | * 253 | * y = polevl( x, coef, N ); 254 | * 255 | * 256 | * 257 | * DESCRIPTION: 258 | * 259 | * Evaluates polynomial of degree N: 260 | * 261 | * 2 N 262 | * y = C + C x + C x +...+ C x 263 | * 0 1 2 N 264 | * 265 | * Coefficients are stored in reverse order: 266 | * 267 | * coef[0] = C , ..., coef[N] = C . 268 | * N 0 269 | * 270 | * The function p1evl() assumes that coef[N] = 1.0 and is 271 | * omitted from the array. Its calling arguments are 272 | * otherwise the same as polevl(). 273 | * 274 | * 275 | * SPEED: 276 | * 277 | * In the interest of speed, there are no checks for out 278 | * of bounds arithmetic. This routine is used by most of 279 | * the functions in the library. Depending on available 280 | * equipment features, the user may wish to rewrite the 281 | * program in microcode or assembly language. 282 | * 283 | */ 284 | 285 | 286 | /* 287 | Cephes Math Library Release 2.1: December, 1988 288 | Copyright 1984, 1987, 1988 by Stephen L. Moshier 289 | Direct inquiries to 30 Frost Street, Cambridge, MA 02140 290 | */ 291 | double polevl( double x, const double *coef, int N ) { 292 | 293 | double ans; 294 | ans = coef[0]; 295 | 296 | for(int i=1; i<=N; i++) { 297 | ans = ans*x+coef[i]; 298 | } 299 | 300 | return ans; 301 | } 302 | 303 | //double polevl(double x, double coef[], int N ) 304 | ////double x; 305 | ////double coef[]; 306 | ////int N; 307 | //{ 308 | //double ans; 309 | //int i; 310 | //double *p; 311 | 312 | //p = coef; 313 | //ans = *p++; 314 | //i = N; 315 | 316 | //do 317 | //ans = ans * x + *p++; 318 | //while( --i ); 319 | 320 | //return( ans ); 321 | //} 322 | 323 | /* p1evl() */ 324 | /* N 325 | * Evaluate polynomial when coefficient of x is 1.0. 326 | * Otherwise same as polevl. 327 | */ 328 | double p1evl( double x, const double *coef, int N ) { 329 | 330 | double ans; 331 | ans = x + coef[0]; 332 | 333 | for(int i=1; i0. 11 | // Thanks to guyskk@qq.com 12 | 13 | using namespace std; 14 | complex _j (0.0 , 1.0); 15 | lpspy::lpspy(){ 16 | N = 100; 17 | lambda = 500e-9; 18 | size = 30e-3; 19 | doub1 = 0.0; 20 | int1 = 0; 21 | } 22 | lpspy::~lpspy(){ 23 | } 24 | 25 | CMPLXVEC lpspy::Axicon(double phi, double n1, double x_shift, double y_shift, CMPLXVEC Field ){ 26 | double pi2, K, dx, x, x2, y, theta, Ktheta; 27 | int n2; 28 | pi2=Pi*2.; 29 | K=pi2/lambda; 30 | n2=(int) N/2; 31 | dx=size/N; 32 | theta=asin(n1*cos(phi/2)+phi/2-Pi/2); 33 | Ktheta=K*theta; 34 | for ( int i=0; i >(NN,1.0)); 61 | N=NN; 62 | size = Size; 63 | lambda = Lambda; 64 | int1 = 0; 65 | doub1 = 0.0; 66 | return Field; 67 | } 68 | CMPLXVEC lpspy::CircAperture(double R, double x_shift, double y_shift, CMPLXVEC Field ){ 69 | double RR, dx, x, y; 70 | int i2; 71 | RR=R*R; 72 | dx = size/N; 73 | i2 = (int ) N/2+1; 74 | for ( int i=0; i RR) 81 | { 82 | Field.at(i).at(j) = 0.0; 83 | 84 | } 85 | } 86 | } 87 | return Field; 88 | } 89 | CMPLXVEC lpspy::CircScreen(double R, double x_shift, double y_shift, CMPLXVEC Field ){ 90 | double RR, dx, x, y; 91 | int i2; 92 | RR=R*R; 93 | dx = size/N; 94 | i2 = (int ) N/2+1; 95 | for ( int i=0; i=0.) fftw_execute(planF); 160 | else fftw_execute(planB); 161 | if(zz >= 0.){ 162 | z1=z*lambda/2.; 163 | n12=N/2; 164 | ik=0; 165 | for (int i=0;i=0.) fftw_execute(planB); 208 | else fftw_execute(planF); 209 | ik=0; 210 | ii=ij=1; 211 | for (int i=0;i((in_out[ik][0]*ii*ij * cokz - in_out[ik][1]*ii*ij * sikz)/N/N,\ 216 | ( in_out[ik][1]*ii*ij * cokz + in_out[ik][0]*ii*ij * sikz)/N/N ); 217 | ij=-ij; 218 | ik++; 219 | } 220 | ii=-ii; 221 | } 222 | fftw_destroy_plan(planF); 223 | fftw_destroy_plan(planB); 224 | fftw_free(in_out); 225 | fftw_cleanup(); 226 | return Field; 227 | } 228 | CMPLXVEC lpspy::Fresnel(double z, CMPLXVEC Field ){ 229 | int i,j,fn2, fn22,io,jo,no2,dum,ii,ij,iiij; 230 | long ik, ik1, ik2, ik3, ik4; 231 | double RR, dx, pi2, kz, cokz, sikz, FR, FI; 232 | double cc, fc1, fs1, fc2, fs2, fc3, fs3, fc4, fs4, R1, R2, R3, R4; 233 | double c4c1, c2c3, c4s1, s4c1, s2c3, c2s1, s4c3, s2c1, c4s3, s2s3, s2s1, c2s3, s4s1, c4c3, s4s3, c2c1, sh; 234 | pi2=2.*3.141592654; 235 | 236 | dx=size/(N-1.); 237 | 238 | kz = pi2/lambda*z; 239 | cokz = cos(kz); 240 | sikz = sin(kz); 241 | 242 | /* Allocating a LOT OF MEMORY */ 243 | 244 | fn2=N*2; 245 | fftw_complex* in_outF = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * fn2 * fn2); 246 | fftw_complex* in_outK = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * fn2 * fn2); 247 | for (int i = 0;i( (FR * cokz - FI * sikz)/fn2/fn2, (FI * cokz + FR * sikz)/fn2/fn2); 346 | ik++; 347 | ij=-ij; 348 | } 349 | ii=-ii; 350 | } 351 | fftw_destroy_plan(planFF); 352 | fftw_destroy_plan(planFB); 353 | fftw_destroy_plan(planKF); 354 | fftw_destroy_plan(planKB); 355 | fftw_free(in_outF); 356 | fftw_free(in_outK); 357 | fftw_cleanup(); 358 | return Field; 359 | } 360 | CMPLXVEC lpspy::Gain( double Isat, double gain, double L, CMPLXVEC Field ){ 361 | double Io, Ii, ampl;; 362 | for (int i=0;i< N; i++){ 363 | for (int j=0;j< N; j++){ 364 | Ii = norm(Field.at(i).at(j)); 365 | if (Isat == 0.0) Io = Ii; 366 | else Io = Ii*exp(gain*L/(1 + 2.0 * Ii/Isat)); 367 | if (Ii == 0.0) ampl = 0.0; 368 | else ampl = sqrt(Io/Ii); 369 | Field.at(i).at(j) *= ampl; 370 | } 371 | } 372 | return Field; 373 | } 374 | CMPLXVEC lpspy::GaussAperture( double w, double x_shift, double y_shift, double R, CMPLXVEC Field ){ 375 | int n2; 376 | double x,y,dx,w2,cc,SqrtR,x2,y2; 377 | n2=(int)N/2; 378 | w2=w*w*2; 379 | SqrtR=sqrt(R); 380 | dx = size/N; 381 | for (int i=0;i< N; i++){ 382 | x=(i-n2)*dx-x_shift; 383 | x2=x*x; 384 | for (int j=0;j< N; j++){ 385 | y=(j-n2)*dx-y_shift; 386 | y2=y*y; 387 | cc=SqrtR*exp(-(x2+y2)/w2); 388 | Field.at(i).at(j) *= cc; 389 | } 390 | } 391 | return Field; 392 | } 393 | CMPLXVEC lpspy::GaussScreen( double w, double x_shift, double y_shift, double T, CMPLXVEC Field ){ 394 | int n2; 395 | double x,y,dx,w2,cc,x2,y2; 396 | n2=(int)N/2; 397 | w2=w*w; 398 | dx = size/N; 399 | for (int i=0;i< N; i++){ 400 | x=(i-n2)*dx-x_shift; 401 | x2=x*x; 402 | for (int j=0;j< N; j++){ 403 | y=(j-n2)*dx-y_shift; 404 | y2=y*y; 405 | cc=sqrt(1-(1-T)*exp(-(x2+y2)/w2)); 406 | Field.at(i).at(j) *= cc; 407 | } 408 | } 409 | return Field; 410 | } 411 | CMPLXVEC lpspy::GaussHermite( int n, int m, double A, double w0, CMPLXVEC Field ){ 412 | int n2; 413 | double sqrt2w0,sqrt2xw0,sqrt2yw0,w02,x,y,dx,x2,y2; 414 | 415 | sqrt2w0=sqrt(2.0)/w0; 416 | w02=w0*w0; 417 | n2=N/2; 418 | dx=size/N; 419 | 420 | for (int i=0;i< N; i++){ 421 | x=(i-n2)*dx; 422 | x2=x*x; 423 | sqrt2xw0=sqrt2w0*x; 424 | for (int j=0;j< N; j++){ 425 | y=(j-n2)*dx; 426 | y2=y*y; 427 | sqrt2yw0=sqrt2w0*y; 428 | Field.at(i).at(j) = complex (A*exp(-(x2+y2)/w02)*H(m,sqrt2xw0)*H(n,sqrt2yw0) , 0.0); 429 | } 430 | } 431 | return Field; 432 | } 433 | CMPLXVEC lpspy::GaussLaguerre( int p, int m, double A, double w0, CMPLXVEC Field ){ 434 | int n2, ma; 435 | double r,rho,theta,w02,x,y,dx,x2,y2; 436 | 437 | w02=w0*w0; 438 | n2=N/2; 439 | dx=size/N; 440 | ma=abs(m); 441 | for (int i=0;i< N; i++){ 442 | x=(i-n2)*dx; 443 | x2=x*x; 444 | for (int j=0;j< N; j++){ 445 | y=(j-n2)*dx; 446 | y2=y*y; 447 | r=sqrt(x2+y2); 448 | if (r==0.0) 449 | if (y>0.0) theta=Pi/2; 450 | else theta=-Pi/2; 451 | else theta=acos(y/r); 452 | rho=2*(x2+y2)/w02; 453 | Field.at(i).at(j) = complex( A*pow((rho/2),ma/2)*Laguerre1(p,m,rho)*exp(-rho/2)*cos(m*theta) , 0.0 ); 454 | } 455 | } 456 | return Field; 457 | } 458 | CMPLXVEC lpspy::Lens( double f, double x_shift, double y_shift, CMPLXVEC Field ){ 459 | double x,x2,y,dx,pi2,K; 460 | int n2; 461 | if (doub1 != 0.) printf("error in Lens: Spherical coordinates! Use Convert first\n"); 462 | pi2=3.1415926*2.; 463 | K=pi2/lambda; 464 | n2=(int) N/2; 465 | dx=size/N; 466 | for (int i=0;i< N; i++){ 467 | x=(i-n2)*dx-x_shift; 468 | x2=x*x; 469 | for (int j=0;j< N; j++){ 470 | double fi; 471 | y=(j-n2)*dx-y_shift; 472 | fi=-K*(x2+y*y)/(2.*f); 473 | Field.at(i).at(j) *= exp(_j * fi); 474 | } 475 | } 476 | return Field; 477 | } 478 | CMPLXVEC lpspy::LensForvard(double f, double z, CMPLXVEC Field ){ 479 | CMPLXVEC FieldTmp; 480 | double z1,f1,ampl_scale; 481 | double LARGENUMBER = 10000000.; 482 | f1=0.; 483 | if (doub1 !=0. ) f1=1./doub1; 484 | else f1 = LARGENUMBER * size*size/lambda; 485 | if( (f+f1) != 0.) f=(f*f1)/(f+f1); 486 | else f = LARGENUMBER * size*size/lambda; 487 | if ((z-f) == 0 ) z1 = LARGENUMBER; 488 | else z1= -z*f/(z-f); 489 | 490 | FieldTmp=Forvard(z1,Field); 491 | 492 | ampl_scale= (f-z)/f ; 493 | size *= ampl_scale; 494 | doub1= -1./(z-f); 495 | 496 | if (z1>=0.){ 497 | for (int i=0;i > Intens, CMPLXVEC Field ){ 556 | double Intens2; 557 | if ((int)Intens.at(0).size() != N || (int)Intens.size() != N){ 558 | printf( "Error in MultIntensity(Intens, Fin): array 'Intens' must be square and must have %d x %d elements\n",N,N); 559 | return Field; 560 | } 561 | for (int i=0;i< N; i++){ 562 | for (int j=0;j< N; j++){ 563 | Intens2=sqrt(Intens.at(j).at(i)); 564 | Field.at(i).at(j) *= Intens2; 565 | } 566 | } 567 | return Field; 568 | } 569 | CMPLXVEC lpspy::MultPhase( vector > Phase, CMPLXVEC Field ){ 570 | double phi; 571 | if ((int)Phase.at(0).size() != N || (int)Phase.size() != N){ 572 | printf( "Error in MultPhase(Phase, Fin): array 'Phase' must be square and must have %d x %d elements\n",N,N); 573 | return Field; 574 | } 575 | for (int i=0;i< N; i++){ 576 | for (int j=0;j< N; j++){ 577 | phi=Phase.at(j).at(i); 578 | Field.at(i).at(j) *= exp(_j * phi); 579 | } 580 | } 581 | return Field; 582 | } 583 | CMPLXVEC lpspy::Normal( CMPLXVEC Field ){ 584 | double sum, dx, dx2, asum; 585 | sum=0; 586 | dx =size/N; 587 | dx2 = dx*dx; 588 | for (int i=0;i< N; i++){ 589 | for (int j=0;j< N; j++){ 590 | sum += norm(Field.at(i).at(j)) * dx2; 591 | } 592 | } 593 | if (sum == 0.0){ 594 | printf("Error in 'Normal(Fin)': Zero beam power!"); 595 | return Field; 596 | } 597 | asum=sqrt(1./sum); 598 | for (int i=0;i< N; i++){ 599 | for (int j=0;j< N; j++){ 600 | Field.at(i).at(j) *= asum; 601 | } 602 | } 603 | return Field; 604 | } 605 | CMPLXVEC lpspy::Interpol( double new_size, int new_number, double x_shift, double y_shift, double angle, double magnif, CMPLXVEC Fin ){ 606 | CMPLXVEC Fout; 607 | Fout.resize(new_number, vector > (new_number)); 608 | double dx_new, dx_old, x_new, x_old, size_old, 609 | y_new, y_old, lower, upper, ss, cc, x0, y0; 610 | int i_old, j_old, old_number, on21, nn21; 611 | 612 | size_old = size; 613 | old_number = N; 614 | dx_new=new_size/(new_number-1); 615 | dx_old=size_old/(old_number-1); 616 | angle *= Pi/180.; 617 | 618 | on21=(int) old_number/2+1; 619 | nn21=(int) new_number/2+1; 620 | lower= (1-on21)*dx_old; 621 | upper= (old_number-on21)*dx_old; 622 | cc=cos(angle); 623 | ss=sin(angle); 624 | for (int i=0;i< new_number; i++){ 625 | for (int j=0;j< new_number; j++){ 626 | x0=(i-nn21+1)*dx_new-x_shift; 627 | y0=(j-nn21+1)*dx_new-y_shift; 628 | x_new=(x0*cc+y0*ss)/magnif; 629 | y_new=(-x0*ss+y0*cc)/magnif; 630 | i_old=(int) floor(x_new/dx_old+on21); 631 | x_old=(i_old-on21)*dx_old; 632 | j_old=(int) floor(y_new/dx_old+on21); 633 | y_old=(j_old-on21)*dx_old; 634 | if((x_new > lower) && (x_new < upper) && (y_new >lower) && (y_new < upper)){ 635 | Fout.at(i).at(j)= complex ( 636 | Inv_Squares(x_old, y_old, dx_old, 637 | Fin.at(i_old-1).at(j_old-1).real(), 638 | Fin.at(i_old).at(j_old-1).real(), 639 | Fin.at(i_old-1).at(j_old).real(), 640 | Fin.at(i_old).at(j_old).real(), 641 | x_new, y_new)/magnif , 642 | Inv_Squares(x_old, y_old, dx_old, 643 | Fin.at(i_old-1).at(j_old-1).imag(), 644 | Fin.at(i_old).at(j_old-1).imag(), 645 | Fin.at(i_old-1).at(j_old).imag(), 646 | Fin.at(i_old).at(j_old).imag(), 647 | x_new, y_new)/magnif ); 648 | } 649 | else{ 650 | Fout.at(i).at(j)= complex(0.0, 0.0); 651 | } 652 | } 653 | } 654 | N=new_number; 655 | size=new_size; 656 | return Fout; 657 | } 658 | vector > lpspy::Intensity(int flag, CMPLXVEC Field ){ 659 | vector > I; 660 | I.resize(N, vector (N)); 661 | for (int i=0; i Imax ) Imax=I.at(i).at(j); 673 | } 674 | } 675 | if (Imax == 0.0){ 676 | printf(" in Intensity: cannot normalize because of zero beam power.\n"); 677 | return I; 678 | } 679 | double InvImax=1/Imax; 680 | for (int i=0;i > lpspy::Phase(CMPLXVEC Field ){ 689 | vector > Phi; 690 | Phi.resize(N, vector (N)); 691 | for (int i=0; i > lpspy::PhaseUnwrap(vector > Phi ){ 701 | //phaseunwrap( &Phi.at(0).at(0),&Phi.at(0).at(0),0,N); 702 | cout << "PhaseUnwrap is not implemented" << endl; 703 | return Phi; 704 | } 705 | CMPLXVEC lpspy::PipFFT( int ind, CMPLXVEC Field ){ 706 | int i,j; 707 | int ii, ij, iiij; 708 | long ik; 709 | fftw_complex* in_out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N * N); 710 | if (in_out == NULL) return Field; 711 | fftw_plan planF = fftw_plan_dft_2d (N, N, in_out, in_out, FFTW_FORWARD, FFTW_ESTIMATE); 712 | if (planF == NULL) return Field; 713 | fftw_plan planB = fftw_plan_dft_2d (N, N, in_out, in_out, FFTW_BACKWARD, FFTW_ESTIMATE); 714 | if (planB == NULL) return Field; 715 | ik=0; 716 | for (i=0;i(in_out[ik][0] , in_out[ik][1]); 758 | ik++; 759 | } 760 | } 761 | fftw_destroy_plan(planF); 762 | fftw_destroy_plan(planB); 763 | fftw_free(in_out); 764 | fftw_cleanup(); 765 | return Field; 766 | } 767 | double lpspy::Power( CMPLXVEC Field ){ 768 | double sum; 769 | sum=0.0; 770 | for (int i=0; i< N ;i++){ 771 | for (int j=0;j < N ;j++){ 772 | sum += norm(Field.at(i).at(j)); 773 | } 774 | } 775 | return sum; 776 | } 777 | CMPLXVEC lpspy::RectAperture(double sx, double sy, double x_shift, double y_shift, double angle, CMPLXVEC Field ){ 778 | double dx,x,y,x0,y0,cc,ss; 779 | int i2; 780 | dx =size/N; 781 | i2=N/2+1; 782 | angle *= -Pi/180.; 783 | cc=cos(angle); 784 | ss=sin(angle); 785 | if(angle==0.0){ 786 | for (int i=0;i sx/2. || fabs(y) > sy/2. ) { 791 | Field.at(i).at(j) = 0.0; 792 | } 793 | } 794 | } 795 | } 796 | else{ 797 | for (int i=0;i sx/2. || fabs(y) > sy/2. ){ 804 | Field.at(i).at(j) = 0.0; 805 | } 806 | } 807 | } 808 | } 809 | return Field; 810 | } 811 | CMPLXVEC lpspy::RectScreen(double sx, double sy, double x_shift, double y_shift, double angle, CMPLXVEC Field ){ 812 | double dx,x,y,x0,y0,cc,ss; 813 | int i2; 814 | dx =size/N; 815 | i2=N/2+1; 816 | angle *= -Pi/180.; 817 | cc=cos(angle); 818 | ss=sin(angle); 819 | if(angle==0.0){ 820 | for (int i=0;i uij, uij1, uij_1, ui1j, ui_1j, medium; 870 | size_t i, j, jj, ii; 871 | int istep; 872 | vectors v; //the structure vectors is used to pass a lot of variables to function elim 873 | if (doub1 !=0.){ 874 | printf("error in 'Steps(z,nsteps, refr, Fin)': Spherical coordinates. Use Fout=Convert(Fin) first.\n"); 875 | return Field; 876 | } 877 | v.a.resize(N+3); 878 | v.b.resize(N+3); 879 | v.c.resize(N+3); 880 | v.u.resize(N+3); 881 | v.u1.resize(N+3); 882 | v.u2.resize(N+3); 883 | v.alpha.resize(N+3); 884 | v.beta.resize(N+3); 885 | v.p.resize(N+3); 886 | 887 | K=2.*Pi/lambda; 888 | z=z/2.; 889 | Pi4lz = 4.*Pi/lambda/z; 890 | std::complex imPi4lz (0.0,Pi4lz); 891 | delta=size/((double)(N-1.)); 892 | delta2 = delta*delta; 893 | 894 | /* absorption at the borders is described here */ 895 | AA= -10./z/nstep; /* total absorption */ 896 | band_pow=2.; /* profile of the absorption border, 2=quadratic*/ 897 | /* width of the absorption border */ 898 | i_left=N/2+1.0-0.4*N; 899 | i_right=N/2+1.0+0.4*N; 900 | /* end absorption */ 901 | 902 | for ( i=1; i <= N; i++){ 903 | v.u2.at(i) = 0.0; 904 | v.a.at(i) = std::complex( -1./delta2 , 0.0 ); 905 | v.b.at(i) = std::complex( -1./delta2 , 0.0 ); 906 | } 907 | medium= 0.0; 908 | dist =0.; 909 | 910 | /* Main loop, steps here */ 911 | for(istep = 1; istep <= nstep ; istep ++){ 912 | dist=dist + 2.*z; 913 | 914 | /* Elimination in the direction i, halfstep */ 915 | for (i=0; i< N; i++){ 916 | for( j=0; j< N; j++){ 917 | double fi; 918 | fi=0.25*K*z*(refr.at(i).at(j).real()-1.0); 919 | Field.at(i).at(j) *= exp(_j * fi); 920 | } 921 | } 922 | 923 | for(jj=2; jj <= N-2; jj += 2){ 924 | j=jj; 925 | for (i=2; i <= N-1; i++){ 926 | 927 | uij=Field.at(i-1).at(j-1); 928 | uij1=Field.at(i-1).at(j); 929 | uij_1=Field.at(i-1).at(j-2); 930 | v.p.at(i) = -1.0/delta2 * (uij_1 + uij1 -2.0 * uij) + imPi4lz * uij; 931 | } 932 | for ( i=1; i <= N; i++){ 933 | 934 | if (refr.at(i-1).at(j-1).imag() == 0.0) medium = std::complex (medium.real() , 0.0); 935 | else medium = std::complex(medium.real() , -2.0 * Pi * refr.at(i-1).at(j-1).imag() / lambda); 936 | 937 | v.c.at(i) = std::complex( -2.0 / delta2, Pi4lz + medium.imag() ); 938 | 939 | ///* absorption borders are formed here */ 940 | if( i <= i_left){ 941 | double iii=i_left-i+1; 942 | v.c.at(i) = std::complex (v.c.at(i).real() , v.c.at(i).imag() - (AA*K)*pow((double) iii/ ((double)(i_left)),band_pow)); 943 | } 944 | 945 | if( i >= i_right){ 946 | double iii=i-i_right+1; 947 | double im=N-i_right+1; 948 | v.c.at(i) = std::complex (v.c.at(i).real() , v.c.at(i).imag() - (AA*K)*pow((double) iii/ ((double)(im)),band_pow)); 949 | } 950 | ///* end absorption */ 951 | } 952 | 953 | elim(v,N); 954 | for ( i=1; i<= N; i++){ 955 | Field.at(i-1).at(j-2) = v.u2.at(i); 956 | v.u2.at(i)=v.u.at(i); 957 | } 958 | j=jj+1; 959 | for ( i=2; i <= N-1; i++){ 960 | uij=Field.at(i-1).at(j-1); 961 | uij1=Field.at(i-1).at(j); 962 | uij_1=Field.at(i-1).at(j-2); 963 | v.p.at(i) = -1.0/delta2 * (uij_1 + uij1 -2.0 * uij) + imPi4lz * uij; 964 | } 965 | for ( i=1; i <= N; i++){ 966 | if (refr.at(i-1).at(j-1).imag() == 0.0) medium = std::complex( medium.real() , 0.0 ); 967 | else medium = std::complex(medium.real() , -2.*Pi*refr.at(i-1).at(j-1).imag()/lambda); 968 | v.c.at(i) = std::complex(-2.0/delta2, Pi4lz + medium.imag()); 969 | 970 | ///* absorption borders are formed here */ 971 | if( i <= i_left){ 972 | double iii=i_left-i+1; 973 | v.c.at(i) = std::complex( v.c.at(i).real() , v.c.at(i).imag() - (AA*K)*pow((double) iii/ ((double)(i_left)),band_pow) ); 974 | } 975 | 976 | if( i >= i_right){ 977 | double iii=i-i_right; 978 | double im=N-i_right+1; 979 | //c.at(i).imag(c.at(i).imag() - (AA*2.0*K)*pow((double) iii/ ((double)(im)),band_pow)); /* Gleb's original */ 980 | v.c.at(i) = std::complex( v.c.at(i).real() , v.c.at(i).imag() - (AA*K)*pow((double) iii/ ((double)(im)),band_pow) ); 981 | } 982 | ///* end absorption */ 983 | } 984 | elim(v,N); 985 | for ( i=1; i <= N; i++){ 986 | Field.at(i-1).at(j-2) = v.u2.at(i); 987 | v.u2.at(i)=v.u.at(i); 988 | } 989 | } 990 | for ( i=1; i <= N; i++){ 991 | Field.at(i-1).at(N-1) = v.u2.at(i); 992 | } 993 | for ( i=0; i < N; i++){ 994 | for( j=0; j < N; j++){ 995 | fi=0.5*K*z*(refr.at(i).at(j).real()-1.0); 996 | Field.at(i).at(j) *= exp(_j * fi); 997 | } 998 | } 999 | 1000 | /* Elimination in the j direction is here, halfstep */ 1001 | 1002 | for ( i=1; i <= N; i++){ 1003 | v.u2.at(i)=0.0; 1004 | } 1005 | for(ii=2; ii <= N-2; ii += 2){ 1006 | i=ii; 1007 | for ( j=2; j <= N-1; j++){ 1008 | uij=Field.at(i-1).at(j-1); 1009 | ui1j=Field.at(i).at(j-1); 1010 | ui_1j=Field.at(i-2).at(j-1); 1011 | v.p.at(j) = -1.0/delta2 * (ui_1j + ui1j -2.0 * uij) + imPi4lz * uij; 1012 | } 1013 | for ( j=1; j <= N; j++){ 1014 | if (refr.at(i-1).at(j-1).imag() == 0.0) medium =std::complex(medium.real() , 0.0); 1015 | else medium= std::complex( medium.real() , -2.0 * Pi * refr.at(i-1).at(j-1).imag() / lambda ); 1016 | v.c.at(j) = std::complex( -2.0 / delta2 , Pi4lz + medium.imag() ); 1017 | 1018 | 1019 | /* absorption borders are formed here */ 1020 | if( j <= i_left){ 1021 | size_t iii=(long)i_left-j; 1022 | v.c.at(j) = std::complex( v.c.at(j).real() , v.c.at(j).imag() - (AA*K)*pow((double) iii/ ((double)(i_left)),band_pow) ); 1023 | } 1024 | 1025 | if( j >= i_right){ 1026 | size_t iii=j-(long)i_right; 1027 | double im=N-i_right+1; 1028 | v.c.at(j) = std::complex( v.c.at(j).real() , v.c.at(j).imag() - (AA*K)*pow((double) iii/ ((double)(im)),band_pow) ); 1029 | } 1030 | //* end absorption */ 1031 | } 1032 | elim(v,N); 1033 | 1034 | for ( j=1; j<= N; j++){ 1035 | Field.at(i-2).at(j-1) = v.u2.at(j); 1036 | v.u2.at(j)=v.u.at(j); 1037 | } 1038 | i=ii+1; 1039 | for ( j=2; j <= N-1; j++){ 1040 | uij=Field.at(i-1).at(j-1); 1041 | ui1j=Field.at(i).at(j-1); 1042 | ui_1j=Field.at(i-2).at(j-1); 1043 | v.p.at(j) = -1.0/delta2 * (ui_1j + ui1j -2.0 * uij) + imPi4lz * uij; 1044 | } 1045 | for ( j=1; j <= N; j++){ 1046 | if (refr.at(i-1).at(j-1).imag() == 0.0) medium = std::complex( medium.real() , 0.0); 1047 | else medium = std::complex( medium.real() , -2.*Pi*refr.at(i-1).at(j-1).imag()/lambda ); 1048 | v.c.at(j) = std::complex( -2.0/delta2 , Pi4lz + medium.imag() ); 1049 | /* absorption borders are formed here */ 1050 | if( j <= i_left){ 1051 | size_t iii=(long )i_left-j; 1052 | v.c.at(j) = std::complex( v.c.at(j).real(), v.c.at(j).imag() - (AA*K)*pow((double) iii/ ((double)(i_left)),band_pow) ); 1053 | } 1054 | 1055 | if( j >= i_right){ 1056 | size_t iii=j-(long )i_right; 1057 | double im=N-i_right+1; 1058 | v.c.at(j) = std::complex( v.c.at(j).real() , v.c.at(j).imag() - (AA*K)*pow((double) iii/ ((double)(im)),band_pow) ); 1059 | } 1060 | /* end absorption */ 1061 | } 1062 | 1063 | elim(v,N); 1064 | for ( j=1; j <= N; j++){ 1065 | Field.at(i-2).at(j-1) = v.u2.at(j); 1066 | v.u2.at(j)=v.u.at(j); 1067 | } 1068 | } 1069 | 1070 | for ( j=2; j <= N; j++){ 1071 | Field.at(i-1).at(j-2) = v.u2.at(j); 1072 | } 1073 | 1074 | ///* end j */ 1075 | 1076 | } 1077 | for ( i=0; i < N; i++){ 1078 | for(j=0; j < N; j++){ 1079 | fi=0.25*K*z*(refr.at(i).at(j).real()-1.0); 1080 | Field.at(i).at(j) *= exp(_j * fi); 1081 | } 1082 | } 1083 | return Field; 1084 | 1085 | 1086 | } 1087 | double lpspy::Strehl( CMPLXVEC Field ){ 1088 | double sum,sum1r,sum1i,sum1; 1089 | 1090 | sum=sum1r=sum1i=0.0; 1091 | for (int i=0; i< N ;i++){ 1092 | for (int j=0;j < N ;j++){ 1093 | sum += abs(Field.at(i).at(j)); 1094 | sum1r += Field.at(i).at(j).real(); 1095 | sum1i += Field.at(i).at(j).imag(); 1096 | } 1097 | } 1098 | sum1=(sum1r*sum1r+sum1i*sum1i); 1099 | if (sum == 0){ 1100 | cout<<"error in Strehl: Zero beam power"< > Intens, CMPLXVEC Field ){ 1106 | double Intens2, phi; 1107 | if ((unsigned long)Intens.at(0).size() != N || (unsigned long)Intens.size() != N){ 1108 | printf( "Error in SubIntensity(Intens, Fin): array 'Intens' must be square and must have %d x %d elements\n",N,N); 1109 | exit(1); 1110 | } 1111 | for (int i=0;i< N; i++){ 1112 | for (int j=0;j< N; j++){ 1113 | phi=arg(Field.at(i).at(j)); 1114 | Intens2=sqrt(Intens.at(j).at(i)); 1115 | Field.at(i).at(j) = Intens2 * exp(_j * phi); 1116 | } 1117 | } 1118 | return Field; 1119 | } 1120 | CMPLXVEC lpspy::SubPhase( vector > Phase, CMPLXVEC Field ){ 1121 | double Intens2, phi; 1122 | if ((unsigned long)Phase.at(0).size() != N || (unsigned long)Phase.size() != N){ 1123 | printf( "Error in SubPhase(Phase, Fin): array 'Phase' must be square and must have %d x %d elements\n",N,N); 1124 | exit(1); 1125 | } 1126 | for (int i=0;i< N; i++){ 1127 | for (int j=0;j< N; j++){ 1128 | phi=Phase.at(j).at(i); 1129 | Intens2=abs(Field.at(i).at(j)); 1130 | Field.at(i).at(j) = Intens2 * exp(_j * phi); 1131 | } 1132 | } 1133 | return Field; 1134 | } 1135 | CMPLXVEC lpspy::Tilt(double tx, double ty, CMPLXVEC Field ){ 1136 | int n2; 1137 | double fi, K, dx, x, y; 1138 | dx =size/N; 1139 | n2=N/2; 1140 | K=2*Pi/lambda; 1141 | for (int i=0;i= -n; ncheck -= 2) 1156 | if (ncheck == m ) ind=1; 1157 | if (ind == 0){ 1158 | cout << "error in 'Zernike(n ,m, R, A, Fin)': n must be larger than zero."< 4 | #include 5 | #include "fftw3.h" 6 | #define CMPLXVEC vector > > 7 | 8 | namespace std { 9 | class lpspy { 10 | public: 11 | int N; 12 | int int1; 13 | double size, lambda, doub1; 14 | lpspy(); 15 | ~lpspy(); 16 | CMPLXVEC Axicon(double phi, double n1, double x_shift, double y_shift, CMPLXVEC Fin); 17 | CMPLXVEC BeamMix(CMPLXVEC Fin1, CMPLXVEC Fin2 ); 18 | CMPLXVEC Begin(double size, double lambda, int NN); 19 | CMPLXVEC CircAperture(double R, double x_shift, double y_shift, CMPLXVEC Fin); 20 | CMPLXVEC CircScreen(double R, double x_shift, double y_shift, CMPLXVEC Fin); 21 | CMPLXVEC Convert( CMPLXVEC Fin ); 22 | CMPLXVEC Forvard(double z, CMPLXVEC Fin); 23 | CMPLXVEC Fresnel(double z, CMPLXVEC Fin); 24 | CMPLXVEC Gain( double Isat, double gain, double L, CMPLXVEC Fin ); 25 | CMPLXVEC GaussAperture( double w, double x_shift, double y_shift, double R, CMPLXVEC Fin ); 26 | CMPLXVEC GaussScreen( double w, double x_shift, double y_shift, double T, CMPLXVEC Fin ); 27 | CMPLXVEC GaussHermite( int n, int m, double A, double w0, CMPLXVEC Fin ); 28 | CMPLXVEC GaussLaguerre( int p, int m, double A, double w0, CMPLXVEC Fin ); 29 | CMPLXVEC IntAttenuator( double R, CMPLXVEC Fin ); 30 | vector > Intensity(int flag,CMPLXVEC Fin ); 31 | CMPLXVEC Interpol( double new_size, int new_number, double x_shift, double y_shift, double angle, double magnif, CMPLXVEC Fin ); 32 | CMPLXVEC Lens( double f, double x_shift, double y_shift, CMPLXVEC Fin ); 33 | CMPLXVEC LensForvard(double f, double z, CMPLXVEC Fin ); 34 | CMPLXVEC LensFresnel(double f, double z, CMPLXVEC Fin ); 35 | CMPLXVEC MultIntensity( vector > Intens, CMPLXVEC Fin ); 36 | CMPLXVEC MultPhase( vector > Phase, CMPLXVEC Fin ); 37 | CMPLXVEC Normal( CMPLXVEC Fin ); 38 | vector > Phase(CMPLXVEC Fin ); 39 | vector > PhaseUnwrap(vector > Phi ); 40 | CMPLXVEC PipFFT( int ind, CMPLXVEC Fin ); 41 | double Power( CMPLXVEC Fin ); 42 | CMPLXVEC RandomIntensity(double seed, double noise_level, CMPLXVEC Fin ); 43 | CMPLXVEC RandomPhase(double seed, double max, CMPLXVEC Fin ); 44 | CMPLXVEC RectAperture(double sx, double sy, double x_shift, double y_shift, double angle, CMPLXVEC Fin ); 45 | CMPLXVEC RectScreen(double sx, double sy, double x_shift, double y_shift, double angle, CMPLXVEC Fin ); 46 | CMPLXVEC Steps(double z, int nstep, CMPLXVEC refr, CMPLXVEC Fin ); 47 | double Strehl( CMPLXVEC Fin ); 48 | CMPLXVEC SubIntensity( vector > Intens, CMPLXVEC Fin ); 49 | CMPLXVEC SubPhase( vector > Phase, CMPLXVEC Fin ); 50 | CMPLXVEC Tilt(double tx, double ty, CMPLXVEC Fin ); 51 | CMPLXVEC Zernike(int n, int m, double R, double A, CMPLXVEC Fin ); 52 | void version(); 53 | double getGridSize(); 54 | void setGridSize(double newSize); 55 | double getWavelength(); 56 | void setWavelength(double newWavelength); 57 | int getGridDimension(); 58 | }; 59 | } 60 | -------------------------------------------------------------------------------- /LightPipes-Packages/sources/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | from setuptools.extension import Extension 3 | import numpy 4 | 5 | # Test if Cython is available 6 | try: 7 | from Cython.Distutils import build_ext 8 | USE_CYTHON = True 9 | except ImportError: 10 | USE_CYTHON = False 11 | 12 | print ("USE_CYTHON =", USE_CYTHON) 13 | 14 | # If no Cython, we assume a 'LightPipes.cpp' compiled with: 'cython -t --cplus LightPipes.pyx' 15 | ext = '.pyx' if USE_CYTHON else '.cpp' 16 | 17 | 18 | sources = [ 19 | 'LightPipes' + ext, 20 | 'fresnl.cpp', 21 | 'subs.cpp', 22 | 'lpspy.cpp' 23 | ] 24 | 25 | extensions = [ 26 | Extension( 27 | 'LightPipes', 28 | sources, 29 | #extra_compile_args = [''], 30 | include_dirs = [ numpy.get_include()], 31 | libraries = ['libfftw3-3'], 32 | language = "c++", 33 | ) 34 | ] 35 | 36 | # Select Extension 37 | if USE_CYTHON: 38 | from Cython.Build import cythonize 39 | extensions = cythonize(extensions) 40 | else: 41 | # If not using Cython, we have to add 'LightPipes.cpp' 42 | extensions[0].sources.append('LightPipes.cpp'); 43 | 44 | setup( name = 'LightPipes', 45 | package_data = { "LightPipes" : [ "libfftw3-3.dll"]}, 46 | include_package_data=True, 47 | version = '1.1.0', 48 | description = 'LightPipes for Python optical toolbox', 49 | author = 'Fred van Goor', 50 | author_email = 'Fred511949@gmail.com', 51 | license = 'MIT', 52 | classifiers = [ 53 | 'Development Status :: 3 - Alpha', 54 | 'Programming Language :: Python :: 3.5', 55 | ], 56 | url = 'https://GitHub.com/FredvanGoor/LightPipes-for-Python/', 57 | download_url = 'https://github.com/FredvanGoor/LightPipes-for-Python/raw/master/LightPipes-Packages/', 58 | platforms = ['win64'], 59 | ext_modules = extensions, 60 | ) 61 | -------------------------------------------------------------------------------- /LightPipes-Packages/sources/subs.cpp: -------------------------------------------------------------------------------- 1 | #include "subs.h" 2 | #define Pi 3.141592654 3 | #define UNWRAP(ol,co,ne)\ 4 | val = ol;\ 5 | if ((val - co) >= hfactor)\ 6 | while ((val - co) >= hfactor) val -= factor;\ 7 | else if ((val - co) <= -hfactor)\ 8 | while ((val - co) <= -hfactor) val += factor;\ 9 | *ne = val; 10 | double Y1getter(double a) 11 | { 12 | return a; 13 | } 14 | double H(int n,double x){ 15 | int k; 16 | double p1,p2,p3; 17 | p1=1.0; 18 | p2=0.0; 19 | if (n == 0 )return 1.0; 20 | for (k=1;k <=n; k++){ 21 | p3=p2; 22 | p2=p1; 23 | p1=2*x*p2-2*(k-1)*p3; 24 | } 25 | return p1; 26 | } 27 | 28 | double Laguerre1(int p,int m,double rho){ 29 | if (p==0) return 1.0; 30 | else 31 | if (p==1) return -1*rho+1+m; 32 | else 33 | return (2*p+m-1-rho)/p*Laguerre1(p-1,m,rho) - (p+m-1)/p*Laguerre1(p-2,m,rho); 34 | } 35 | 36 | double Laguerre(int p,int m, double rho){ 37 | double L0,L1,LaguerreL; 38 | int i; 39 | L1=0.0; 40 | LaguerreL=1.0; 41 | for (i=1;ix+dx+tol || y1y+dx+tol){ 77 | // cout<<"Out of Range error."<=0) return sum*cos(m*phi); 137 | else return -sum*sin(m*phi); 138 | } 139 | 140 | 141 | 142 | /* Factorial function */ 143 | double Factorial(int n){ 144 | double product; 145 | 146 | if (n<0) { 147 | fprintf(stderr,"factorial: argument is negative, exiting \n"); 148 | exit(1); 149 | } 150 | if (n==0) return 1.; 151 | else{ 152 | product =1; 153 | while(n>=1){ 154 | product *= n; 155 | --n; 156 | } 157 | return product; 158 | } 159 | } 160 | 161 | 162 | double phase(double y,double x){ 163 | if (x !=0.) return atan2 (y,x); 164 | else if (y>=0) return Pi/2.; 165 | else return Pi+Pi/2; 166 | } 167 | 168 | 169 | /*****************************************************************/ 170 | /***************** END of Zernike *********************/ 171 | int phaseunwrap(double* ibuffer, double* obuffer,int xsize, int ysize) { 172 | register short i, j; 173 | double *p, *q, *newpix; 174 | register short hxsize, hysize; 175 | double comval,oldpix; 176 | double hfactor, val; 177 | double factor=2.0*Pi; 178 | 179 | p = ibuffer; 180 | q = obuffer; 181 | 182 | hxsize = xsize>>1; 183 | hysize = ysize>>1; 184 | hfactor = Pi; 185 | /* position p in centre of image */ 186 | p += hysize*xsize + hxsize; 187 | q += hysize*xsize + hxsize; 188 | /* central pixel */ 189 | *q =*p; 190 | /* first shell of pixels */ 191 | comval = *q; 192 | oldpix = *(p - xsize); 193 | newpix = q - xsize; 194 | UNWRAP(oldpix,comval,newpix); /* north */ 195 | 196 | comval = (*(q - xsize) + *q)/2; 197 | oldpix = *(p + 1); 198 | newpix = q + 1; 199 | UNWRAP(oldpix,comval,newpix); /* east */ 200 | 201 | comval = (*(q + 1) + *q)/2; 202 | oldpix = *(p + xsize); 203 | newpix = q + xsize; 204 | UNWRAP(oldpix,comval,newpix); /* south */ 205 | 206 | comval = (*(q + xsize) + *q)/2; 207 | oldpix = *(p - 1); 208 | newpix = q - 1; 209 | UNWRAP(oldpix,comval,newpix); /* west */ 210 | 211 | comval = (*(q - xsize) + *(q - 1) + *q) / 3; 212 | oldpix = *(p - xsize - 1); 213 | newpix = q - xsize - 1; 214 | UNWRAP(oldpix,comval,newpix); /* north-west */ 215 | 216 | comval = (*(q - xsize) + *(q + 1) + *q) / 3; 217 | oldpix = *(p - xsize + 1); 218 | newpix = q - xsize + 1; 219 | UNWRAP(oldpix,comval,newpix); /* north-east */ 220 | 221 | comval = (*(q + xsize) + *(q + 1) + *q) / 3; 222 | oldpix = *(p + xsize + 1); 223 | newpix = q + xsize + 1; 224 | UNWRAP(oldpix,comval,newpix); /* south-east */ 225 | 226 | comval = (*(q + xsize) + *(q - 1) + *q) / 3; 227 | oldpix = *(p + xsize - 1); 228 | newpix = q + xsize - 1; 229 | UNWRAP(oldpix,comval,newpix); /* south-west */ 230 | /* next shells */ 231 | i = 1; 232 | while (++i < hxsize) { 233 | /* north */ 234 | comval = (*(q - (i-1)*xsize - i + 1) + *(q - (i-1)*xsize - 235 | i + 2))/2; 236 | oldpix = *(p - i*xsize - i + 1); 237 | newpix = q - i*xsize - i + 1; 238 | UNWRAP(oldpix,comval,newpix); 239 | j = i-1; 240 | while (--j > -i) { 241 | comval = (*(q - i*xsize - j - 1) + *(q - 242 | (i-1)*xsize - j) + *(q - (i-1)*xsize - j - 1)) / 3; 243 | oldpix = *(p - i*xsize - j); 244 | newpix = q - i*xsize - j; 245 | UNWRAP(oldpix,comval,newpix); 246 | } 247 | /* south */ 248 | comval = (*(q + (i-1)*xsize + i - 1) + *(q + (i-1)*xsize + 249 | i - 2))/2; 250 | oldpix = *(p + i*xsize + i - 1); 251 | newpix = q + i*xsize + i - 1; 252 | UNWRAP(oldpix,comval,newpix); 253 | j = i-1; 254 | while (--j > -i) { 255 | comval = (*(q + i*xsize + j + 1) + *(q + 256 | (i-1)*xsize + j) + *(q + (i-1)*xsize + j + 1)) / 3; 257 | oldpix = *(p + i*xsize + j); 258 | newpix = q + i*xsize + j; 259 | UNWRAP(oldpix,comval,newpix); 260 | } 261 | /* east */ 262 | comval = (*(q + i - 1 - (i-1)*xsize) + *(q + i - 1 - 263 | (i-2)*xsize))/2; 264 | oldpix = *(p + i - (i - 1)*xsize); 265 | newpix = q + i - (i - 1)*xsize; 266 | UNWRAP(oldpix,comval,newpix); 267 | j = i-1; 268 | while (--j > -i) { 269 | comval = (*(q + i - (j+1)*xsize) + *(q + i - 1 - 270 | (j+1)*xsize) + *(q + i - 1 - j*xsize)) / 3; 271 | oldpix = *(p + i - j*xsize); 272 | newpix = q + i - j*xsize; 273 | UNWRAP(oldpix,comval,newpix); 274 | } 275 | /* west */ 276 | comval = (*(q - i + 1 + (i-1)*xsize) + *(q - i + 1 + 277 | (i-2)*xsize))/2; 278 | oldpix = *(p - i + (i - 1)*xsize); 279 | newpix = q - i + (i - 1)*xsize; 280 | UNWRAP(oldpix,comval,newpix); 281 | j = i-1; 282 | while (--j > -i) { 283 | comval = (*(q - i + (j+1)*xsize) + *(q - i + 1 + 284 | (j+1)*xsize) + *(q - i + 1 + j*xsize)) / 3; 285 | oldpix = *(p - i + j*xsize); 286 | newpix = q - i + j*xsize; 287 | UNWRAP(oldpix,comval,newpix); 288 | } 289 | /* north-west */ 290 | comval = (*(q - (i-1)*xsize - i) + *(q - i*xsize - i + 1) + 291 | *(q - (i-1)*xsize - i + 1)) / 3; 292 | oldpix = *(p - i*xsize - i); 293 | newpix = q - i*xsize - i; 294 | UNWRAP(oldpix,comval,newpix); 295 | /* north-east */ 296 | comval = (*(q - (i-1)*xsize + i) + *(q - i*xsize + i - 1) + 297 | *(q - (i-1)*xsize + i - 1)) / 3; 298 | oldpix = *(p - i*xsize + i); 299 | newpix = q - i*xsize + i; 300 | UNWRAP(oldpix,comval,newpix); 301 | /* south-east */ 302 | comval = (*(q + (i-1)*xsize + i) + *(q + i*xsize + i - 1) + 303 | *(q + (i-1)*xsize + i - 1)) / 3; 304 | oldpix = *(p + i*xsize + i); 305 | newpix = q + i*xsize + i; 306 | UNWRAP(oldpix,comval,newpix); 307 | /* south-west */ 308 | comval = (*(q + (i-1)*xsize - i) + *(q + i*xsize - i + 1) + 309 | *(q + (i-1)*xsize - i + 1)) / 3; 310 | oldpix = *(p + i*xsize - i); 311 | newpix = q + i*xsize - i; 312 | UNWRAP(oldpix,comval,newpix); 313 | } 314 | /* upper line and left column */ 315 | /* upper line*/ 316 | comval = (*(q - (hxsize-1)*xsize - hxsize + 1) + *(q - 317 | (hxsize-1)*xsize - hxsize + 2))/2; 318 | oldpix = *(p - hxsize*xsize - hxsize + 1); 319 | newpix = q - hxsize*xsize - hxsize + 1; 320 | UNWRAP(oldpix,comval,newpix); 321 | j = hxsize-1; 322 | while (--j > -hxsize) { 323 | comval = (*(q - hxsize*xsize - j - 1) + *(q - 324 | (hxsize-1)*xsize - j) + *(q - (hxsize-1)*xsize - j - 1)) / 3; 325 | oldpix = *(p - hxsize*xsize - j); 326 | newpix = q - hxsize*xsize - j; 327 | UNWRAP(oldpix,comval,newpix); 328 | } 329 | /* left line */ 330 | comval = (*(q - hxsize + 1 + (hxsize-1)*xsize) + *(q - hxsize + 1 + 331 | (hxsize-2)*xsize))/2; 332 | oldpix = *(p - hxsize + (hxsize - 1)*xsize); 333 | newpix = q - hxsize + (hxsize - 1)*xsize; 334 | UNWRAP(oldpix,comval,newpix); 335 | j = hxsize-1; 336 | while (--j > -hxsize) { 337 | comval = (*(q - hxsize + (j+1)*xsize) + *(q - hxsize + 1 + 338 | (j+1)*xsize) + *(q - hxsize + 1 + j*xsize)) / 3; 339 | oldpix = *(p - hxsize + j*xsize); 340 | newpix = q - hxsize + j*xsize; 341 | UNWRAP(oldpix,comval,newpix); 342 | } 343 | /* upper left corner */ 344 | comval = (*(q - (hxsize-1)*xsize - hxsize) + *(q - hxsize*xsize - 345 | hxsize + 1) + *(q - (hxsize-1)*xsize - hxsize + 1)) / 3; 346 | oldpix = *(p - hxsize*xsize - hxsize); 347 | newpix = q - hxsize*xsize - hxsize; 348 | UNWRAP(oldpix,comval,newpix); 349 | 350 | return 0; 351 | } 352 | /*********************************************************************** 353 | * elim. Called by LPSteps 354 | ***********************************************************************/ 355 | void elim(vectors &v, int N){ 356 | int i; 357 | std::complex cc; 358 | /* initial condition, everything is going to be zero at the edge */ 359 | v.alpha.at(2) = 0.0; 360 | v.beta.at(2) = 0.0; 361 | 362 | v.alpha.at(N) = 0.0; 363 | v.beta.at(N) = 0.0; 364 | 365 | //* forward elimination */ 366 | for(i=2;i <= N-2; i++){ 367 | cc=v.c.at(i) - v.a.at(i) * v.alpha.at(i); 368 | v.alpha.at(i+1) = v.b.at(i) / cc; 369 | v.beta.at(i+1)=( v.p.at(i) + v.a.at(i) * v.beta.at(i) ) / cc; 370 | } 371 | i=N; 372 | cc = v.c.at(i) - v.a.at(i) * v.alpha.at(i); 373 | v.beta.at(N+1) = ( v.p.at(i) + v.a.at(i) * v.beta.at(i) )/cc; 374 | //* edge amplitude =0 */ 375 | v.u.at(N) = v.beta.at(N+1); 376 | //* backward elimination */ 377 | for(i=N-1; i >= 1; i--){ 378 | v.u.at(i)=v.alpha.at(i+1) * v.u.at(i+1) + v.beta.at(i+1); 379 | } 380 | } 381 | -------------------------------------------------------------------------------- /LightPipes-Packages/sources/subs.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | /*********************************************************************** 6 | * structure vectors is used to pass by reference a lot of variables to 7 | * elim and LPSteps. 8 | ***********************************************************************/ 9 | struct vectors{ 10 | std::vector > a, b, c, alpha, beta, u, p, u1, u2; 11 | }; 12 | double Y1getter(double a); 13 | double H(int n,double x); 14 | double Laguerre1(int p,int m,double rho); 15 | double Laguerre(int p, int m, double rho); 16 | int factorial(int num); 17 | double Inv_Squares(double x, double y, double dx, double z, double zx, double zy, double zxy, double x1, double y1); 18 | double zernike(int n, int m, double rho, double phi); 19 | double Factorial(int n); 20 | double phase(double y,double x); 21 | int phaseunwrap(double* ibuffer,double* obuffer,int xsize, int ysize); 22 | void elim(vectors &v,int N); 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LightPipes for Python 2 | 3 | # Note: This repository is obsolete and is not maintained anymore. It will be deleted in the future. A new repository for LightPipes for Python has been made. Please go to: [https://github.com/opticspy/lightpipes](https://github.com/opticspy/lightpipes) and to our website: [https://opticspy.github.io/lightpipes/](https://opticspy.github.io/lightpipes/). 4 | 5 | 6 | ### Simulations of optical phenomena where diffraction is essential 7 | 8 | *LightPipes for Python* is a set of functions written in C++. It is designed to model coherent optical devices when the diffraction is essential. The toolbox consists of a number of functions. Each function represents an optical element or a step in the light propagation. There are apertures, intensity filters, beam-splitters, lenses and models of free space diffraction. There are also more advanced tools for manipulating the phase and amplitude of the light. The program operates on a large data structure, containing square two-dimensional arrays of complex amplitudes of the optical field of the propagating light beam. 9 | The *LightPipes for Python* routines are modifications of the LightPipes C routines written by Gleb Vdovin for Unix, Linux, DOS and OS2 workstations. 10 | 11 | Visit the website of ***Flexible Optical***: [http://www.okotech.com](http://www.okotech.com), where you can find the source code of *LightPipes* and a *manual*. 12 | 13 | [Reference to the functions](./command-reference.md) 14 | ###Example: Young interferometer 15 | 16 | A plane wave is diffracted by two small holes, separated a distance, d. So two more or less spherical waves will propagate from these holes. 17 | 18 | ![](img/twoholesSetUp.png) 19 | 20 | The resulting interference pattern on a screen at distance z looks like: 21 | 22 | ![](img/twoholesPattern.png) 23 | 24 | ### The Python program, [Young.py](Examples/Interference/Young.py), described in detail. 25 | The first step in *Python* is to import the *LightPipes for Python* library: 26 | 27 | ![](img/twoholes1.png) 28 | 29 | If the *LightPipes for Python* library is successful installed on your computer Python can proceed with the next step. 30 | You probably want to plot the results, so import *matplotlib*: 31 | 32 | ![](img/twoholes2.png) 33 | 34 | I like to work with units. So define them: 35 | 36 | ![](img/twoholes3.png) 37 | 38 | We have to initiate *LightPipes for Python*. This is done with the following command: 39 | 40 | ![](img/twoholes4.png) 41 | 42 | Next we define some variables: a wavelength of 20 micrometer , a 30 x 30 mm2 square grid with 250 x 250 pixels. 43 | 44 | ![](img/twoholes5.png) 45 | 46 | Now we are ready to start the simulation. The *Begin* command generates a field with amplitude 1.0 and phase zero, a plane wave. So, all the 250 x 250 elements of array, F, contain the complex number: 1.0 + j0.0. 47 | The next commands generate two waves, F1 and F2, which are apertured by the two circular apertures and combined (simply added) by the *BeamMix* command. The combined wavefront is propagated a distance z=30 cm by the *Fresnel* command. After that the intensity is caculated and normalized to 255 (2 -> 255, 1 -> 1.0, 0 -> not normalized) by the *Intensity* command. 48 | 49 | ![](img/twoholes6.png) 50 | 51 | The result is plotted using the fantastic *matplot* routines. We are not interested in axis around the pattern and we like to write a title above the plot. 52 | 53 | ![](img/twoholes7.png) 54 | 55 | Finally it is good practice to clean up: 56 | 57 | ![](img/twoholes8.png) 58 | 59 | ###Install LightPipes for Python by opening a terminal window and type at the prompt: 60 | 61 | LightPipes is on [PyPi](https://pypi.python.org/pypi/LightPipes/), so for Windows win32 and win64 and Macintosh OSX simply type: **(sudo) pip install LightPipes** 62 | 63 | For LINUX '*wheels*' are [not (yet) accepted by *PyPi*](http://pythonwheels.com/), you must use *easy\_install*. (see below, *easy_install* also works for Windows and OSX) 64 | 65 | ####[WINDOWS 32 AND 64 BIT:](LightPipes-Packages) 66 | 67 | **pip install LightPipes** 68 | 69 | or: 70 | 71 | 72 | **easy_install LightPipes** 73 | 74 | or: 75 | 76 | **easy_install https://github.com/FredvanGoor/LightPipes-for-Python/raw/master/LightPipes-Packages/LightPipes-1.0.0-py2.7-win32.egg** 77 | 78 | ####[LINUX 64 BIT:](LightPipes-Packages) 79 | 80 | 81 | **easy_install LightPipes** 82 | 83 | or: 84 | 85 | **easy\_install https://github.com/FredvanGoor/LightPipes-for-Python/raw/master/LightPipes-Packages/LightPipes-1.0.0-py2.7-linux-x86_64.egg** 86 | 87 | ####[LINUX 32 BIT:](LightPipes-Packages) 88 | 89 | 90 | **easy_install LightPipes** 91 | 92 | or: 93 | 94 | **easy_install https://github.com/FredvanGoor/LightPipes-for-Python/raw/master/LightPipes-Packages/LightPipes-1.0.0-py2.7-linux-i686.egg** 95 | 96 | ####[MACINTOSH:](LightPipes-Packages) 97 | 98 | **pip install LightPipes** 99 | 100 | or: 101 | 102 | **easy_install LightPipes** 103 | 104 | or: 105 | 106 | **easy_install https://github.com/FredvanGoor/LightPipes-for-Python/raw/master/LightPipes-Packages/LightPipes-1.0.0-py2.7-macosx-10.6-intel.egg** 107 | -------------------------------------------------------------------------------- /command-reference.md: -------------------------------------------------------------------------------- 1 | #Command reference 2 | ---------- 3 | ### Axicon(*phi*, *n1*, *x\_shift*, *y\_shift*, *Field*) ### 4 | propagates the *Field* through an axicon. 5 | *phi*: top angle in radians; 6 | *n1*: refractive index (must be real); 7 | *x\_shift*, *y\_shift*: shift from the centre. 8 | 9 | ### BeamMix(*Field1*, *Field2*) ### 10 | Addition of *Field1* and *Field2*. 11 | 12 | ### Begin(*grid\_size*, *lambda*, *grid\_dimension*) ### 13 | initialises a uniform field with unity amplitude and zero phase. 14 | *grid\_size*: the size of the grid in units you choose, 15 | *lambda*: the wavelength of the field with the same units as the grid size, 16 | *grid\_dimension*: the dimension of the grid. This must be an even number. 17 | 18 | ###CircAperture(*R*, *x\_shift*, *y\_shift*, *Field*) 19 | circular aperture. 20 | *R*=radius, 21 | *x\_shift*, *y\_shift* = shift from centre. 22 | 23 | ###CircScreen(*R*, *x\_shift*, *y\_shift*, *Field*) 24 | circular screen. 25 | *R*=radius, 26 | *x\_shift*, *y\_shift* = shift from centre. 27 | 28 | ###Convert(*Field*) 29 | converts the *field* from a spherical grid to a normal grid. 30 | 31 | ###CylLens(fx, fy, x\_shift, y\_shift, Field) 32 | Cylinder lens. *fx, fy = focallengths in x- and y direction. x\_shift, y\_shift = shift from centre. 33 | * 34 | 35 | ###Forvard(*z*, *Field*) 36 | propagates the *field* a distance *z* using FFT. 37 | 38 | ###Forward(*z*, *new\_size*, *new\_number*, *Field*) 39 | propagates the *field* a distance *z*, using direct integration of the Kirchoff-Fresnel integral. 40 | 41 | ###Fresnel(*z*, *Field*) 42 | propagates the *field* a distance *z*. A convolution method has been used to calculate the diffraction integral 43 | 44 | ###Gain(*Isat*, *gain*, *length*, *Field*) 45 | Laser saturable gain sheet. 46 | *Isat*=saturation intensity, 47 | *gain*= small signal gain, 48 | *length*=length of gain medium 49 | 50 | ###GaussAperture(*R*, *x\_shift*, *y\_shift*, *T*, *Field*) 51 | Gauss aperture. 52 | *R*=radius, 53 | *x\_shift*, *y\_shift* = shift from centre; 54 | *T*= centre transmission 55 | 56 | ###GaussHermite(*n*, *m*, *A*, *w0*, *Field*) 57 | substitutes a TEMm,n Gauss Hermite mode with waist *w0* and amplitude *A* into the *Field* 58 | 59 | ###GaussLaguerre(*p*, *m*, *A*, *w0*, *Field*) 60 | substitutes a TEMp,m Gauss Laguerre mode with waist *w0* and amplitude *A* into the *Field* 61 | 62 | ###GaussScreen(*R*, *x\_shift*, *y\_shift*, *T*, *Field*) 63 | Gauss screen. 64 | *R*=radius, 65 | *x\_shift*, *y\_shift* = shift from centre; 66 | *T*= centre transmission 67 | 68 | ###IntAttenuator(*Att*, *Field*) 69 | Intensity Attenuator. Attenuates the *field*-intensity by a factor *Att* 70 | 71 | ###Intensity(*flag*, *Field*) 72 | calculates the intensity of the *field*. 73 | *flag*=0: no scaling; 74 | *flag*=1: normalisation of the intensity; 75 | *flag*=2: bitmap with gray scales 76 | 77 | ###Interpol(*new\_size*, *new\_n*, *xs*, *ys*, *phi*, *magn*, *Field*) 78 | interpolates the field to a new grid. 79 | *new\_size*: new grid size; 80 | *new\_n*: new grid dimension; 81 | *xs*, *ys* : the shifts of the field in the new grid; 82 | *phi*: angle of rotation (after the shifts); 83 | *magn*: magnification (last applied) 84 | 85 | ###Lens(*f*, *x\_shift*, *y\_shift*, *Field*) 86 | propagates the field through a lens. 87 | *f*: focal length; 88 | *x\_shift*, *y\_shift*: transverse shifts of the lens optical axis 89 | 90 | ###LensForvard(*f*, *z*, *Field*) 91 | propagates the *field* a distance *z* using a variable coordinate system. 92 | *f*: focal length of the input lens: 93 | *z*: distance to propagate 94 | 95 | ###LensFresnel(*f*, *z*, *Field*) 96 | propagates the *field* a distance *z* using a variable coordinate system. 97 | *f*: focal length of the input lens; 98 | *z*: distance to propagate 99 | 100 | ###MultIntensity(*Intensity*, *Field*) 101 | multiplies the *field* with an intensity profile stored in the array: *Intensity* 102 | 103 | ###MultPhase(*Phase*, *Field*) 104 | multiplies the *field* with a phase profile stored in the array: *Phase* 105 | 106 | ###Normal(*Field*) 107 | normalizes the *field*. 108 | 109 | ###Phase(*Field*) 110 | calculates the phase of the *field* 111 | 112 | ###PhaseUnwrap(*Phase*) 113 | unwraps *phase*. 114 | 115 | ###PipFFT(*Direction*, *Field*) 116 | Performs a Fourier transform to the *Field*. 117 | *Direction* = 1: Forward transform; 118 | *Direction* = -1: Inverse transform 119 | 120 | ###Power(*Field*) 121 | get the total power of the *Field* 122 | 123 | ###RandomIntensity(*seed*, *Field*) 124 | Random intensity mask. 125 | '*seed*' is an arbitrary number to initiate the random number generator 126 | 127 | ###RandomPhase(*seed*, *max*, *Field*) 128 | Random phase mask. 129 | '*seed*' is an arbitrary number to initiate the random number generator; 130 | '*max*' is the maximum value of the phase. 131 | 132 | ###RectAperture(*sx*, *sy*, *x\_shift*, *y\_shift*, *phi*, *Field*) 133 | rectangular aperture. 134 | *sx*, *sy*: dimensions of the aperture; 135 | *x\_shift*, *y\_shift*: shift from centre; 136 | *phi*: rotation angle. 137 | 138 | ###RectScreen(*sx*, *sy*, *x\_shift*, *y\_shift*, *phi*, *Field*) 139 | rectangular screen. 140 | *sx*, *sy*: dimensions of the screen; 141 | *x\_shift*, *y\_shift*: shift from centre; 142 | *phi*: rotation angle. 143 | 144 | ###Steps(*z*, *N\_steps*, *Refract[N, N]*, *Field*) 145 | Propagates '*Field*' a distance *z* in '*N\_steps*' steps in a medium with a complex refractive index stored in the NxN matrix '*Refract*'. '*N*' is the grid dimension. 146 | 147 | ###Strehl(*Field*) 148 | calculates the Strehl ratio. 149 | 150 | ###SubIntensity(*intensity*, *Field*) 151 | substitutes an intensity profile into the field. The profile must be stored in the array: Intens 152 | 153 | ###SubPhase(*phase*, *Field*) 154 | substitutes a phase profile into the field.The phase profile must be stored in the array: phase. 155 | 156 | ###Tilt(*tx*, *ty*, *Field*) 157 | introduces tilt in to the *field* distribution. *tx*, *ty* = tilt components in radians. 158 | 159 | ###Zernike(*n*, *m*, *R*, *A*, *Field*) 160 | Introduces arbitrary Zernike aberration into the *field*. 161 | *n* and *m* are the integer orders, (See Born and Wolf, 6th edition p.465, Pergamon 1993). 162 | *R* is the radius at which the phase amplitude reaches *A* (in radians) 163 | 164 | ###version() 165 | output the version of LightPipes 166 | 167 | ###description() 168 | get a short description of LightPipes() 169 | 170 | ###getGridSize() 171 | get the current grid size 172 | 173 | ###setGridSize(newSize) 174 | set the grid size to *newSize* 175 | 176 | ###getWavelength() 177 | get the current wavelength 178 | 179 | ###setWavelength(newWavelength) 180 | set the wavelength to *newWavelength* 181 | 182 | ###getGridDimension() 183 | get the grid dimension 184 | 185 | ###Help() 186 | output help 187 | 188 | ###Example() 189 | output the Young interferometer example 190 | -------------------------------------------------------------------------------- /img/twoholes1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/img/twoholes1.png -------------------------------------------------------------------------------- /img/twoholes2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/img/twoholes2.png -------------------------------------------------------------------------------- /img/twoholes3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/img/twoholes3.png -------------------------------------------------------------------------------- /img/twoholes4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/img/twoholes4.png -------------------------------------------------------------------------------- /img/twoholes5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/img/twoholes5.png -------------------------------------------------------------------------------- /img/twoholes6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/img/twoholes6.png -------------------------------------------------------------------------------- /img/twoholes7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/img/twoholes7.png -------------------------------------------------------------------------------- /img/twoholes8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/img/twoholes8.png -------------------------------------------------------------------------------- /img/twoholesPattern.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/img/twoholesPattern.png -------------------------------------------------------------------------------- /img/twoholesSetUp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredvanGoor/LightPipes-for-Python/1cfa8ec98061685adf130eb3ce5e780ec7948ae3/img/twoholesSetUp.png --------------------------------------------------------------------------------