def main(): grating = Grating(pitch=3.3, height=100, angle=math.radians(0)) #print(repr(grating[0])) #print(repr(grating[1])) #disc = Disc(-50,10) #pencil = RayPencil().addBeam(disc,0.0).addMonitor(RayPath()) ip = ImagePlane(50, xsize=30) orders = [0, 1, 2, 3] for order in orders: pencil = RayPencil().addRays( -60, math.radians(0), [0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7]) pencil.addMonitor(RayPath()) pencil *= grating for ray in pencil: yi = ray.director.y ym = yi + order * ray.wavelength / grating.pitch zm = math.sqrt(1.0 - ym * ym) ray.director = Unit3d(0.0, ym, zm) pencil *= ip pencil.draw() grating.draw() ip.draw() plt.axis("equal") plt.grid() plt.show()
def __init__(self, pt=Vector3d(), xpixel=256, ypixel=None, xsize=200, ysize=None, wave=TriColour): """ Form the OpticalImage with either blank array of nmpy image array """ if isinstance(pt, ImagePlane): # Deal with ImagePlane ImagePlane.__init__(self, pt.point, pt.xsize, pt.ysize) else: if ysize == None: ysize = xsize ImagePlane.__init__(self, pt, xsize, ysize) # Set underying ImagePlane if isinstance(xpixel, int): if ypixel == None: ypixel = xpixel self.image = np.zeros((xpixel, ypixel, 3)) # Make array of zeros. else: self.image = xpixel # assume numpy array given self.xpixel, self.ypixel, c = self.image.shape # set xpixel and ypixel from image data self.wavelengths = wave
def getSurfaceInteraction(self, r): """ Method to get back the surface interaction information for a ray and also add the ray to the image This also add the ray intensity to the cloeset pixel. :return: SurfaceInteraction. """ # get interaction with super class info = ImagePlane.getSurfaceInteraction(self, r) # Add ray to pixel if not math.isnan(info.position.x) or not math.isnan(info.position.y): i = int( round(self.xpixel * (info.position.x + self.xsize / 2 - info.point.x) / self.xsize)) j = int( round(self.ypixel * (info.position.y + self.ysize / 2 - info.point.y) / self.ysize)) # Check if pixel is in image (note due to distrortions it may not be) if i >= 0 and i < self.xpixel and j >= 0 and j < self.ypixel: if r.wavelength == TriColour[0]: self.image[i, j, 0] += r.intensity # Add it to the image elif r.wavelength == TriColour[1]: self.image[i, j, 1] += r.intensity # Add it to the image else: self.image[i, j, 2] += r.intensity # Retun info to calling object return info
def main(): # Make a set of surface op = ImagePlane(-100, 30) ca = CircularAperture(-10, 20) ia = IrisAperture(50, 15).setRatio(0.7) fs = SphericalSurface(20, 0.025, 15, "BK7") bs = SphericalSurface(30, -0.025, 15, "air") ip = ImagePlane(60, 40) # Plot them in a simple diagram op.draw() ca.draw() ia.draw() fs.draw() bs.draw() ip.draw() plt.axis("equal") # Set the x/y axis to the same scale plt.show()
def __init__(self, pt=0.0, xsize=100.00, ysize=None, wavelength=Default): """ Constuctor with """ if isinstance(pt, ImagePlane): ImagePlane.__init__(self, pt, pt.xsize, pt.ysize) elif isinstance(pt, CircularAperture): ImagePlane.__init__(self, pt, 2 * pt.getRadius()) else: ImagePlane.__init__(self, pt, xsize, ysize) # Initialse underlying ImagePlane self.wavelength = wavelength self.targets = [] # List of targets to be added
def __str__(self): """ Update str """ return ImagePlane.__str__(self) + " targets : {0:d}".format( len(self.targets))