def drawsurf1(self,steplist=None): 'drawsurf1(self,steplist=None) - draw spectrum surface cell by stepwise' self.clearcanvas() self.createAxis() # use color table if ctable is set if self.ctable: p = reshape(self.CT[self.ct],(256,3)) spec=[] for i in range(256): pp = p[i] st = '#%02x%02x%02x' % (int(pp[0]),int(pp[1]),int(pp[2])) spec.append(st) self.ctc = spec da = self.data dv = self.vmax-self.vmin if dv != 0.: data = divide(subtract(da,self.vmin),dv/self.maxY) da1 = divide(subtract(da,self.vmin),dv/255) else: data = da da1 = divide(da,self.vmin/255) rows= len(data) steps= len(data[0]) lasthv = self.maxY*self.yfac xadj = float(self.xincr)/4.0 if xadj < 2: xadj=2 if steplist == None: steplist = range(steps-1) # for cidx in range(steps-1): for cidx in steplist: for row in range(rows-1): rootx = self.xorg + cidx*self.xincr - row*self.hoff/self.rows rooty = self.yorg + row*self.voff/self.rows datum = [data[rows-1-row][cidx+1],data[rows-1-row][cidx],data[rows-1-row-1][cidx],data[rows-1-row-1][cidx+1]] lside = multiply(datum,self.yfac) if self.ctable: if not(self.average): ind = int(da1[rows-1-row,cidx]) else: ind = int((da1[rows-1-row,cidx]+da1[rows-1-row-1,cidx]+ da1[rows-1-row,cidx+1]+da1[rows-1-row-1,cidx+1])/4) color = self.ctc[ind] else: color = self.spectrum[cidx] self.canvas.create_polygon( rootx+self.xincr,rooty-lside[0], rootx,rooty-lside[1], rootx-self.hroff,rooty-lside[2]+self.vroff, rootx+self.xincr-self.hroff,rooty-lside[3]+self.vroff, fill=color, outline=color, width=xadj) self.root.update()
def drawrows(self,list=None): 'drawrows(self,list=None) - draw all or list of rows in 3D coordinates' self.clearcanvas() self.createAxis() da = self.data dv = self.vmax-self.vmin if dv != 0.0: data = divide(subtract(da,self.vmin),dv/self.maxY) else: data = da rows= len(data) steps= len(data[0]) lasthv = self.maxY*self.yfac if list == None: list = range(rows) for row in list: if row < rows and row >=0 : # rootx = self.xorg - row*self.hoff/self.rows # rooty = self.yorg + row*self.voff/self.rows # rowdata1 = data[rows-1-row] rootx = self.xorg - (rows-1-row)*self.hoff/self.rows rooty = self.yorg + (rows-1-row)*self.voff/self.rows rowdata1 = data[row] for cidx in range(steps-1): datum = [rowdata1[cidx],rowdata1[cidx+1]] lside = multiply(datum,self.yfac) self.canvas.create_line( rootx,rooty-lside[0], rootx+self.xincr,rooty-lside[1], capstyle=ROUND, width=self.linewidth,fill='darkblue') rootx = rootx + self.xincr self.root.update()
def drawsurf(self,type=None): 'drawsurf(self,type=None) - draw spectrum surface with/without skirt' da = self.data dv = self.vmax-self.vmin if dv != 0.: data = divide(subtract(da,self.vmin),dv/self.maxY) else: data = da rows= len(data) steps= len(data[0]) lasthv = self.maxY*self.yfac for row in range(rows): rootx = self.xorg - row*self.hoff/self.rows rooty = self.yorg + row*self.voff/self.rows rowdata = data[rows-1-row] for cidx in range(steps): datum = rowdata[cidx] lside = datum*self.yfac color = self.spectrum[cidx] if type == None: self.canvas.create_polygon(rootx, rooty-lside, fill=color, outline=color, width=self.xincr) else: self.canvas.create_polygon(rootx, rooty-lside, rootx+self.hroff, rooty-lside-self.vroff, rootx+self.hroff, rooty-self.vroff, rootx,rooty-lside, fill=color, outline=color, width=self.xincr) rootx = rootx + self.xincr self.root.update()
def applyTransform(self, distance, elevation, azimuth, position): """This applies the camera's modelview matrix transform. Note that position is now the position the camera orbits around, and elevation specifies how far the camera is above the XY plane, in degrees. """ glLoadIdentity() glTranslatef(0, 0, -distance) glRotatef(elevation - 90, 1.0, 0.0, 0.0) glRotatef(-(azimuth + self.azimuthOffset), 0.0, 0.0, 1.0) glTranslatef(*subtract((0,0,0), position))
def draw(self): 'draw(self) - draw 3D spectrum plot and 2D image plot of input data array' da = self.data dv = self.vmax-self.vmin for i in range(self.rows): if dv == 0: data = self.steps* [1.] else: data = divide(subtract(da[self.maxY-1-i],self.vmin),dv/self.maxY) self.plotData(i, data) self.root.update() self.drawImage()
def draw(self): 'draw(self) - draw 3D spectrum plot and 2D image plot of input data array' da = self.data dv = self.vmax - self.vmin for i in range(self.rows): if dv == 0: data = self.steps * [1.] else: data = divide(subtract(da[self.maxY - 1 - i], self.vmin), dv / self.maxY) self.plotData(i, data) self.root.update() self.drawImage()
def drawstepSline(self, list=None): 'drawstepSline(self,list=None) - draw selected step slices in spectrum color' self.clearcanvas() self.createAxis() da = self.data dv = self.vmax - self.vmin if dv != 0.0: data = divide(subtract(da, self.vmin), dv / self.maxY) else: data = da rows = len(data) steps = len(data[0]) lasthv = self.maxY * self.yfac if list == None: list = range(steps) else: ll = [] for i in range(len(list)): if list[i] < steps: ll.append(list[i]) list = ll np = len(list) for row in range(rows - 1): rootx = self.xorg - row * self.hoff / self.rows rooty = self.yorg + row * self.voff / self.rows rowdata1 = data[rows - 1 - row] rowdata2 = data[rows - 1 - row - 1] for i in range(np): cidx = list[i] if cidx >= 0 and cidx < steps: datum = [rowdata2[cidx], rowdata1[cidx]] lside = multiply(datum, self.yfac) color = self.spectrum[cidx] self.canvas.create_polygon(rootx - self.hroff, rooty - lside[0] + self.vroff, rootx, rooty - lside[1], rootx, rooty, rootx - self.hroff, rooty + self.vroff, outline=color, width=self.linewidth, fill=color) if np < steps: if i < (np - 1): rootx = rootx + self.xincr * (list[i + 1] - cidx) else: rootx = rootx + self.xincr self.root.update()
def render(self): GLOrtho.setup() # Set the square inside our viewport by one # pixel so the antialiased lines won't be chopped in half. GLOrtho.translate(1,1) size = subtract(self.viewport.size, (2,2)) # Translucent filling GLOrtho.setColor(0,0,0,0.3) GLOrtho.filledRect(size) # Bright border GLOrtho.setColor(1,1,1,1) GLOrtho.rectOutline(size)
def drawstepSline(self,list=None): 'drawstepSline(self,list=None) - draw selected step slices in spectrum color' self.clearcanvas() self.createAxis() da = self.data dv = self.vmax-self.vmin if dv != 0.0: data = divide(subtract(da,self.vmin),dv/self.maxY) else: data = da rows= len(data) steps= len(data[0]) lasthv = self.maxY*self.yfac if list == None: list=range(steps) else: ll = [] for i in range(len(list)): if list[i] < steps: ll.append(list[i]) list = ll np = len(list) for row in range(rows-1): rootx = self.xorg - row*self.hoff/self.rows rooty = self.yorg + row*self.voff/self.rows rowdata1 = data[rows-1-row] rowdata2 = data[rows-1-row-1] for i in range(np): cidx = list[i] if cidx >=0 and cidx < steps: datum = [rowdata2[cidx],rowdata1[cidx]] lside = multiply(datum,self.yfac) color = self.spectrum[cidx] self.canvas.create_polygon( rootx-self.hroff,rooty-lside[0]+self.vroff, rootx,rooty-lside[1], rootx,rooty, rootx-self.hroff,rooty+self.vroff, outline=color,width=self.linewidth, fill=color) if np < steps: if i < (np-1): rootx = rootx + self.xincr*(list[i+1]-cidx) else: rootx = rootx + self.xincr self.root.update()
def drawsteps(self, list=None): 'drawsteps(self,list=None) - draw all or selected step list in 3D coordinates' self.clearcanvas() self.createAxis() da = self.data dv = self.vmax - self.vmin if dv != 0.0: data = divide(subtract(da, self.vmin), dv / self.maxY) else: data = da rows = len(data) steps = len(data[0]) lasthv = self.maxY * self.yfac if list == None: list = range(steps) else: ll = [] for i in range(len(list)): if list[i] < steps: ll.append(list[i]) list = ll np = len(list) for row in range(rows - 1): rootx = self.xorg - row * self.hoff / self.rows rooty = self.yorg + row * self.voff / self.rows rowdata1 = data[rows - 1 - row] rowdata2 = data[rows - 1 - row - 1] for i in range(np): cidx = list[i] if cidx >= 0 and cidx < steps: datum = [rowdata1[cidx], rowdata2[cidx]] lside = multiply(datum, self.yfac) self.canvas.create_line( rootx, rooty - lside[0], rootx - self.hroff, rooty - lside[1] + self.vroff, # capstyle=ROUND, width=self.linewidth, fill='darkblue') if np < steps: if i < (np - 1): rootx = rootx + self.xincr * (list[i + 1] - cidx) else: rootx = rootx + self.xincr self.root.update()
def drawsteps(self,list=None): 'drawsteps(self,list=None) - draw all or selected step list in 3D coordinates' self.clearcanvas() self.createAxis() da = self.data dv = self.vmax-self.vmin if dv != 0.0: data = divide(subtract(da,self.vmin),dv/self.maxY) else: data = da rows= len(data) steps= len(data[0]) lasthv = self.maxY*self.yfac if list == None: list=range(steps) else: ll = [] for i in range(len(list)): if list[i] < steps: ll.append(list[i]) list = ll np = len(list) for row in range(rows-1): rootx = self.xorg - row*self.hoff/self.rows rooty = self.yorg + row*self.voff/self.rows rowdata1 = data[rows-1-row] rowdata2 = data[rows-1-row-1] for i in range(np): cidx = list[i] if cidx >=0 and cidx < steps: datum = [rowdata1[cidx],rowdata2[cidx]] lside = multiply(datum,self.yfac) self.canvas.create_line( rootx,rooty-lside[0], rootx-self.hroff,rooty-lside[1]+self.vroff, # capstyle=ROUND, width=self.linewidth,fill='darkblue') if np < steps: if i < (np-1): rootx = rootx + self.xincr*(list[i+1]-cidx) else: rootx = rootx + self.xincr self.root.update()
def drawmesh(self): 'drawmesh(self) - draw surface elements as mesh elements' self.clearcanvas() self.createAxis() da = self.data dv = self.vmax - self.vmin if dv != 0.: data = divide(subtract(da, self.vmin), dv / self.maxY) else: data = da rows = len(data) steps = len(data[0]) lasthv = self.maxY * self.yfac for row in range(rows - 1): rootx = self.xorg - row * self.hoff / self.rows rooty = self.yorg + row * self.voff / self.rows rowdata1 = data[rows - 1 - row] rowdata2 = data[rows - 1 - row - 1] for cidx in range(steps - 1): datum = [ rowdata2[cidx], rowdata1[cidx], rowdata1[cidx + 1], rowdata2[cidx + 1] ] lside = multiply(datum, self.yfac) self.canvas.create_line(rootx - self.hroff, rooty - lside[0] + self.vroff, rootx, rooty - lside[1], rootx + self.xincr, rooty - lside[2], rootx + self.xincr - self.hroff, rooty - lside[3] + self.vroff, fill='darkblue') if (row + 1) == (rows - 1): self.canvas.create_line(rootx + self.xincr - self.hroff, rooty - lside[3] + self.vroff, rootx - self.hroff, rooty - lside[0] + self.vroff, fill='darkblue') rootx = rootx + self.xincr self.root.update()
def drawsurf(self, type=None): 'drawsurf(self,type=None) - draw spectrum surface with/without skirt' da = self.data dv = self.vmax - self.vmin if dv != 0.: data = divide(subtract(da, self.vmin), dv / self.maxY) else: data = da rows = len(data) steps = len(data[0]) lasthv = self.maxY * self.yfac for row in range(rows): rootx = self.xorg - row * self.hoff / self.rows rooty = self.yorg + row * self.voff / self.rows rowdata = data[rows - 1 - row] for cidx in range(steps): datum = rowdata[cidx] lside = datum * self.yfac color = self.spectrum[cidx] if type == None: self.canvas.create_polygon(rootx, rooty - lside, fill=color, outline=color, width=self.xincr) else: self.canvas.create_polygon(rootx, rooty - lside, rootx + self.hroff, rooty - lside - self.vroff, rootx + self.hroff, rooty - self.vroff, rootx, rooty - lside, fill=color, outline=color, width=self.xincr) rootx = rootx + self.xincr self.root.update()
def drawmesh(self): 'drawmesh(self) - draw surface elements as mesh elements' self.clearcanvas() self.createAxis() da = self.data dv = self.vmax-self.vmin if dv != 0.: data = divide(subtract(da,self.vmin),dv/self.maxY) else: data = da rows= len(data) steps= len(data[0]) lasthv = self.maxY*self.yfac for row in range(rows-1): rootx = self.xorg - row*self.hoff/self.rows rooty = self.yorg + row*self.voff/self.rows rowdata1 = data[rows-1-row] rowdata2 = data[rows-1-row-1] for cidx in range(steps-1): datum = [rowdata2[cidx],rowdata1[cidx],rowdata1[cidx+1],rowdata2[cidx+1]] lside = multiply(datum,self.yfac) self.canvas.create_line( rootx-self.hroff,rooty-lside[0]+self.vroff, rootx,rooty-lside[1], rootx+self.xincr,rooty-lside[2], rootx+self.xincr-self.hroff,rooty-lside[3]+self.vroff, fill='darkblue') if (row+1) == (rows-1): self.canvas.create_line( rootx+self.xincr-self.hroff,rooty-lside[3]+self.vroff, rootx-self.hroff,rooty-lside[0]+self.vroff, fill='darkblue') rootx = rootx + self.xincr self.root.update()
def drawrows(self, list=None): 'drawrows(self,list=None) - draw all or list of rows in 3D coordinates' self.clearcanvas() self.createAxis() da = self.data dv = self.vmax - self.vmin if dv != 0.0: data = divide(subtract(da, self.vmin), dv / self.maxY) else: data = da rows = len(data) steps = len(data[0]) lasthv = self.maxY * self.yfac if list == None: list = range(rows) for row in list: if row < rows and row >= 0: # rootx = self.xorg - row*self.hoff/self.rows # rooty = self.yorg + row*self.voff/self.rows # rowdata1 = data[rows-1-row] rootx = self.xorg - (rows - 1 - row) * self.hoff / self.rows rooty = self.yorg + (rows - 1 - row) * self.voff / self.rows rowdata1 = data[row] for cidx in range(steps - 1): datum = [rowdata1[cidx], rowdata1[cidx + 1]] lside = multiply(datum, self.yfac) self.canvas.create_line(rootx, rooty - lside[0], rootx + self.xincr, rooty - lside[1], capstyle=ROUND, width=self.linewidth, fill='darkblue') rootx = rootx + self.xincr self.root.update()
def drawsurf1(self, steplist=None): 'drawsurf1(self,steplist=None) - draw spectrum surface cell by stepwise' self.clearcanvas() self.createAxis() # use color table if ctable is set if self.ctable: p = reshape(self.CT[self.ct], (256, 3)) spec = [] for i in range(256): pp = p[i] st = '#%02x%02x%02x' % (int(pp[0]), int(pp[1]), int(pp[2])) spec.append(st) self.ctc = spec da = self.data dv = self.vmax - self.vmin if dv != 0.: data = divide(subtract(da, self.vmin), dv / self.maxY) da1 = divide(subtract(da, self.vmin), dv / 255) else: data = da da1 = divide(da, self.vmin / 255) rows = len(data) steps = len(data[0]) lasthv = self.maxY * self.yfac xadj = float(self.xincr) / 4.0 if xadj < 2: xadj = 2 if steplist == None: steplist = range(steps - 1) # for cidx in range(steps-1): for cidx in steplist: for row in range(rows - 1): rootx = self.xorg + cidx * self.xincr - row * self.hoff / self.rows rooty = self.yorg + row * self.voff / self.rows datum = [ data[rows - 1 - row][cidx + 1], data[rows - 1 - row][cidx], data[rows - 1 - row - 1][cidx], data[rows - 1 - row - 1][cidx + 1] ] lside = multiply(datum, self.yfac) if self.ctable: if not (self.average): ind = int(da1[rows - 1 - row, cidx]) else: ind = int((da1[rows - 1 - row, cidx] + da1[rows - 1 - row - 1, cidx] + da1[rows - 1 - row, cidx + 1] + da1[rows - 1 - row - 1, cidx + 1]) / 4) color = self.ctc[ind] else: color = self.spectrum[cidx] self.canvas.create_polygon(rootx + self.xincr, rooty - lside[0], rootx, rooty - lside[1], rootx - self.hroff, rooty - lside[2] + self.vroff, rootx + self.xincr - self.hroff, rooty - lside[3] + self.vroff, fill=color, outline=color, width=xadj) self.root.update()