def draw_grid(): glLineWidth(1) set_color(0.5, 0.5, 0.5, "grid") start_x = -18.0 stop_x = 20.0 n = int(stop_x - start_x) dx = 1.0 #(stop_x-start_x)/n pos = start_x glBegin(GL_LINES) for i in range(0, n + 1): glVertex3f(start_x, 0.0, pos) glVertex3f(stop_x, 0.0, pos) pos = pos + dx start_z = -18.0 stop_z = 20.0 dz = 1.0 #(stop_z-start_z)/n pos = start_z for i in range(0, n + 1): glVertex3f(pos, 0, start_z) glVertex3f(pos, 0, stop_z) pos = pos + dz glEnd()
def draw_stars(): global stars if len(stars) == 0: for i in range(0, 5000): phi = random.uniform(0, 2 * pi) costheta = random.uniform(-1, 1) theta = acos(costheta) r = 70 + random.uniform(0, 300) x = r * sin(theta) * cos(phi) y = r * sin(theta) * sin(phi) z = r * cos(theta) color = random.uniform(0, 1.0) r = color g = color b = color s = random.uniform(1, 3) stars.append([x, y, z, r, g, b, s]) stars.append([x, 4, z, 0.5, 0.0, 0.0, 5]) for i in range(0, len(stars)): glPointSize(stars[i][6]) set_color(stars[i][3], stars[i][4], stars[i][5], "star") glBegin(GL_POINTS) glVertex3f(stars[i][0], stars[i][1], stars[i][2]) #glVertex3f(-1.0,-1.0,0.0) glEnd()
def draw_mode(z_size, depth): glLineWidth(5) set_color(1.0, 1.0, 1.0, "mode") glBegin(GL_LINES) t = [] s = [] z = [] start = 0.0 data = dat_file() path = os.path.join(get_sim_path(), "light_dump", "light_1d_photons_tot_norm.dat") if dat_file_read(data, path) == True: array_len = data.y_len s = data.data[0][0] s.reverse() #print(path) #print(data.data) for i in range(1, array_len): glVertex3f(0.0, start + (z_size * (i - 1) / array_len), depth + s[i - 1] * 0.5) glVertex3f(0.0, start + (z_size * i / array_len), depth + s[i] * 0.5) glEnd()
def tab(x,y,z,w,h,d): glBegin(GL_QUADS) set_color(0.0,0.0,1.0,"tab") glVertex3f(x+w+0.05,y,z) glVertex3f(x+w+0.2,y ,z) glVertex3f(x+w+0.2,y+h ,z) glVertex3f(x+w+0.05,y+h ,z) glEnd()
def draw_photon(x,y,z,up): gl_save_add("photon",x,-1.0,z,[int(up)]) glLineWidth(3) length=0.9 if up==True: set_color(0.0, 0.0, 1.0,"photon",alpha=0.5) else: set_color(0.0, 1.0, 0.0,"photon",alpha=0.5) wx=np.arange(0, length , 0.025) wy=np.sin(wx*3.14159*8)*0.2 start_y=y+length stop_y=y glBegin(GL_LINES) for i in range(1,len(wx)): glVertex3f(x, start_y-wx[i-1], z+wy[i-1]) glVertex3f(x, start_y-wx[i], z+wy[i]) glEnd() if up==False: glBegin(GL_TRIANGLES) glVertex3f(x-0.1, stop_y,z) glVertex3f(x+0.1, stop_y ,z) glVertex3f(x,stop_y-0.1 ,z) glEnd() else: glBegin(GL_TRIANGLES) glVertex3f(x-0.1, start_y,z) glVertex3f(x+0.1, start_y ,z) glVertex3f(x,start_y+0.1 ,z) glEnd()
def render(self): #print("do draw") clear_color() glClearColor(self.view.bg_color[0], self.view.bg_color[1], self.view.bg_color[2], 0.5) gl_save_clear() dos_start=-1 dos_stop=-1 epi_y_len=epitaxy_get_y_len() if epi_y_len<=0: return self.x_mul=1e3 self.y_mul=self.gl_device_height/epi_y_len self.z_mul=1e3 x_len=mesh_get_xlen() max_gui_device_x=x_len*self.x_mul max_gui_device_y=1.0 max_gui_device_z=mesh_get_zlen()*self.z_mul l=epitaxy_get_layers()-1 xpoints=int(mesh_get_xpoints()) ypoints=int(mesh_get_ypoints()) zpoints=int(mesh_get_zpoints()) if ypoints>10: ypoints=10 if xpoints>10: xpoints=10 if ypoints>10: ypoints=10 self.emission=False self.ray_model=False lines=inp_load_file(os.path.join(get_sim_path(),"led.inp")) if lines!=False: self.ray_model=val=str2bool(inp_search_token_value(lines, "#led_on")) lines=[] for i in range(0,epitaxy_get_layers()): if epitaxy_get_pl_file(i)!="none": lines=inp_load_file(os.path.join(get_sim_path(),epitaxy_get_pl_file(i)+".inp")) if lines!=False: if str2bool(lines[1])==True: self.emission=True glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() glTranslatef(self.view.x_pos, self.view.y_pos, self.view.zoom) # Move Into The Screen glRotatef(self.view.xRot, 1.0, 0.0, 0.0) glRotatef(self.view.yRot, 0.0, 1.0, 0.0) glRotatef(self.view.zRot, 0.0, 0.0, 1.0) glColor3f( 1.0, 1.5, 0.0 ) glPolygonMode(GL_FRONT, GL_FILL); threed_files=glob.glob("*.3d") if len(threed_files)>0: gl_save_load() gl_save_draw() draw_grid() return #glClearColor(0.92, 0.92, 0.92, 0.5) # Clear to black. lines=[] pos=0.0 for i in range(0,epitaxy_get_layers()): thick=epitaxy_get_width(l-i)*self.y_mul obj=epitaxy_get_layer(l-i) red=obj.r green=obj.g blue=obj.b alpha=obj.alpha if i==l-self.selected_layer: box_lines(0.0,pos,0,max_gui_device_x,thick,max_gui_device_z) if epitaxy_get_electrical_layer(l-i).startswith("dos")==True and ypoints!=0 and xpoints!=0 and zpoints!=0: dy=thick/float(ypoints) dx=max_gui_device_x/float(xpoints) dz=max_gui_device_z/float(zpoints) xshrink=0.8 zshrink=0.8 if dos_start==-1: dos_start=pos dos_stop=pos+thick if xpoints==1: xshrink=1.0 if zpoints==1: zshrink=1.0 if xpoints==1 and zpoints==1: box(0.0,pos,0,max_gui_device_x,thick,max_gui_device_z,red,green,blue,alpha) else: for y in range(0,ypoints): for x in range(0,xpoints): for z in range(0,zpoints): box(dx*x,pos+y*(dy),z*dz,dx*xshrink,dy*0.8,dz*zshrink,red,green,blue,alpha) if self.tab_active_layers==True: tab(0.0,pos,max_gui_device_z,max_gui_device_x,thick,max_gui_device_z) elif epitaxy_get_electrical_layer(l-i).lower()=="contact" and (i==l or i==0): for c in contacts_get_array(): if (c.position=="top" and i==l) or (c.position=="bottom" and i==0): if xpoints==1 and zpoints==1: xstart=0.0 xwidth=max_gui_device_x else: xstart=max_gui_device_x*(c.start/x_len) xwidth=max_gui_device_x*(c.width/x_len) #print("contacts",xstart,xwidth,c.width,x_len) if (c.start+c.width)>x_len: xwidth=max_gui_device_x-xstart if c.depth>0.0: etch_depth=c.depth*self.y_mul if c.position=="top": box(xstart,pos-etch_depth-self.dy_layer_offset,0,xwidth,etch_depth,max_gui_device_z,0.0,0.0,1.0,1.0) else: box(xstart,pos+self.dy_layer_offset+thick,0,xwidth,etch_depth,max_gui_device_z,0.0,0.0,1.0,1.0) if c.active==True: box(xstart,pos,0,xwidth,thick,max_gui_device_z,0.0,1.0,0.0,alpha) else: box(xstart,pos,0,xwidth,thick,max_gui_device_z,red,green,blue,alpha) else: box(0.0,pos,0,max_gui_device_x,thick,max_gui_device_z,red,green,blue,alpha) if self.view.render_text==True: if epitaxy_get_electrical_layer(l-i).startswith("dos")==True: text=epitaxy_get_name(l-i)+" ("+_("active")+")" else: text=epitaxy_get_name(l-i) set_color(1.0,1.0,1.0,"text") font = QFont("Arial") font.setPointSize(18) if self.view.zoom>-20: self.renderText (max_gui_device_x+0.1,pos+thick/2,max_gui_device_z, text,font) pos=pos+thick+self.dy_layer_offset draw_mode(pos-self.dy_layer_offset,max_gui_device_z) draw_rays(self.ray_file,pos-self.dy_layer_offset,max_gui_device_x,self.y_mul,max_gui_device_z*1.05) #print(self.graph_path) if self.view.render_photons==True: #print(pos) self.draw_photons(max_gui_device_x,pos,max_gui_device_z) full_data_range=self.graph_z_max-self.graph_z_min graph(0.0,dos_start,max_gui_device_z+0.5,max_gui_device_x,dos_stop-dos_start,full_data_range,self.graph_data) if self.view.render_grid==True: draw_grid() if self.view.zoom<-60: draw_stars()
def box(x, y, z, w, h, d, r, g, b, alpha): gl_save_add("box", x, y, z, [w, h, d, r, g, b, alpha]) red = r green = g blue = b #btm set_color(red, green, blue, "box_lines", alpha=alpha) glBegin(GL_QUADS) glVertex3f(x + 0.0, y + 0.0, z + 0.0) glVertex3f(x + w, y + 0.0, z + 0.0) glVertex3f(x + w, y + 0.0, z + d) glVertex3f(x + 0.0, y + 0.0, z + d) glEnd() #back red = red * 0.95 green = green * 0.95 blue = blue * 0.95 set_color(red, green, blue, "box_lines", alpha=alpha) glBegin(GL_QUADS) glVertex3f(x + 0.0, y + h, z + 0.0) glVertex3f(x + w, y + h, z + 0.0) glVertex3f(x + w, y + h, z + d) glVertex3f(x + 0.0, y + h, z + d) glEnd() #right red = red * 0.95 green = green * 0.95 blue = blue * 0.95 set_color(red, green, blue, "box_lines", alpha=alpha) glBegin(GL_QUADS) glVertex3f(x + w, y, z) glVertex3f(x + w, y + h, z) glVertex3f(x + w, y + h, z + d) glVertex3f(x + w, y, z + d) glEnd() #left red = red * 0.95 green = green * 0.95 blue = blue * 0.95 set_color(red, green, blue, "box_lines", alpha=alpha) glBegin(GL_QUADS) glVertex3f(x, y, z) glVertex3f(x, y + h, z) glVertex3f(x, y + h, z + d) glVertex3f(x, y, z + d) glEnd() #front red = r green = g blue = b set_color(red, green, blue, "box_lines", alpha=alpha) glBegin(GL_QUADS) glVertex3f(x, y, z + d) glVertex3f(x + w, y, z + d) glVertex3f(x + w, y + h, z + d) glVertex3f(x, y + h, z + d) glEnd() red = red * 0.8 green = green * 0.8 blue = blue * 0.8 #top set_color(red, green, blue, "box_lines", alpha=alpha) glBegin(GL_QUADS) glVertex3f(x, y + h, z) glVertex3f(x + w, y + h, z) glVertex3f(x + w, y + h, z + d) glVertex3f(x, y + h, z + d) glEnd()
def box_lines(x, y, z, w, h, d): glLineWidth(10) set_color(1.0, 1.0, 0.0, "box_lines") glBegin(GL_LINES) #btm glVertex3f(x + 0.0, y + 0.0, z + 0.0) glVertex3f(x + w, y + 0.0, z + 0.0) glVertex3f(x + w, y + 0.0, z + 0.0) glVertex3f(x + w, y + 0.0, z + d) glVertex3f(x + w, y + 0.0, z + d) glVertex3f(x + 0.0, y + 0.0, z + d) # glVertex3f(x + 0.0, y + h, z + 0.0) glVertex3f(x + w, y + h, z + 0.0) glVertex3f(x + w, y + h, z + 0.0) glVertex3f(x + w, y + h, z + d) glVertex3f(x + w, y + h, z + d) glVertex3f(x + 0.0, y + h, z + d) #right glVertex3f(x + w, y, z) glVertex3f(x + w, y + h, z) glVertex3f(x + w, y + h, z) glVertex3f(x + w, y + h, z + d) glVertex3f(x + w, y + h, z + d) glVertex3f(x + w, y, z + d) #left glVertex3f(x, y, z) glVertex3f(x, y + h, z) glVertex3f(x, y + h, z) glVertex3f(x, y + h, z + d) glVertex3f(x, y + h, z + d) glVertex3f(x, y, z + d) # glVertex3f(x, y, z + d) glVertex3f(x + w, y, z + d) glVertex3f(x + w, y, z + d) glVertex3f(x + w, y + h, z + d) glVertex3f(x + w, y + h, z + d) glVertex3f(x, y + h, z + d) #top glVertex3f(x, y + h, z) glVertex3f(x + w, y + h, z) glVertex3f(x + w, y + h, z) glVertex3f(x + w, y + h, z + d) glVertex3f(x + w, y + h, z + d) glVertex3f(x, y + h, z + d) glEnd()