def create_all_sep(a_sep): all_sep = inlib.sg_separator() #all_sep.thisown = 0 camera = inlib.sg_ortho() camera.thisown = 0 camera.position.value(inlib.vec3f(0, 0, 5)) camera.focal.value(5) camera.height.value(7) camera.znear.value(0.1) camera.zfar.value(100) all_sep.add(camera) light = inlib.sg_head_light() light.thisown = 0 light.direction.value(inlib.vec3f(1, -1, -10)) #light.on.value(False) all_sep.add(light) m = inlib.sg_matrix() m.thisown = 0 m.set_rotate(0, 1, 0, 0.5) m.mul_translate(-0.5, 2.5, 0) all_sep.add(m) a_sep.thisown = 0 all_sep.add(a_sep) return all_sep
def vis_img(a_img,a_stop): if a_img.is_empty() == True : return #////////////////////////////////////////////////////////// #/// create scene graph /////////////////////////////////// #////////////////////////////////////////////////////////// sep = inlib.sg_separator() sep.thisown = 0 camera = inlib.sg_ortho() camera.thisown = 0 camera.height.value(2) camera.znear.value(0.1) sep.add(camera) mat = inlib.sg_rgba() mat.thisown = 0 mat.color.value(inlib.colorf_white()) sep.add(mat) _img = inlib.sg_tex_rect() _img.thisown = 0 #_img.img.value(a_img) _img.img.value().transfer(a_img) sep.add(_img) #////////////////////////////////////////////////////////// #/// visualize //////////////////////////////////////////// #////////////////////////////////////////////////////////// smgr = exlib.session(inlib.get_cout()) # screen manager if smgr.is_valid() == True : viewer = exlib.sg_viewer(smgr,0,0,700,500) if viewer.has_window() == True : viewer.sg().add(sep) viewer.show() print('steer...') #smgr.steer() # it blocks input from the prompt (because threading module is not a truely multi-thread system). import time while True: if a_stop() == True : break if smgr.sync() == False : break time.sleep(0.01) print('end steer.') del viewer del smgr
def __init__(self, a_out, a_cols, a_rows, a_width, a_height): inlib.env_append_path('EXLIB_FONT_PATH', './res') inlib.env_append_path('EXLIB_FONT_PATH', '../res') #////////////////////////////////////////////////////////// #////////////////////////////////////////////////////////// #////////////////////////////////////////////////////////// self.m_gl2ps_mgr = exlib.sg_gl2ps_manager() self.m_zb_mgr = inlib.sg_zb_manager() self.m_ttf = exlib.sg_text_freetype() #////////////////////////////////////////////////////////// #/// scene graph : //////////////////////////////////////// #////////////////////////////////////////////////////////// self.m_sep = inlib.sg_separator() camera = inlib.sg_ortho() camera.thisown = 0 camera.height.value(1) z = 10 * 1 camera.znear.value(0.1 * z) camera.zfar.value(10 * z) # 100*z induces problems with lego rendering. camera.position.value(inlib.vec3f(0, 0, z)) camera.orientation.value(inlib.rotf(inlib.vec3f(0, 0, 1), 0)) camera.focal.value(z) self.m_sep.add(camera) #blend = inlib.sg_blend() #blend.thisown = 0 #blend.on.value(True) #self.m_sep.add(blend) self.m_plots = inlib.sg_plots(self.m_ttf) self.m_plots.thisown = 0 self.m_plots.set_regions(a_cols, a_rows) self.m_sep.add(self.m_plots) self.m_width = a_width self.m_height = a_height base_plots.base_plots.__init__(self, a_out, self.m_plots)
def vis_img(a_img): if a_img.is_empty() == True: return #////////////////////////////////////////////////////////// #/// create scene graph /////////////////////////////////// #////////////////////////////////////////////////////////// all_sep = inlib.sg_separator() #all_sep.thisown = 0 camera = inlib.sg_ortho() camera.thisown = 0 camera.height.value(2) camera.znear.value(0.1) all_sep.add(camera) sep = inlib.sg_separator() #sep.thisown = 0 #decided below. #all_sep.add(sep) #decided below. mat = inlib.sg_rgba() mat.thisown = 0 mat.color.value(inlib.colorf_white()) sep.add(mat) _img = inlib.sg_tex_rect() _img.thisown = 0 #_img.img.value(a_img) _img.img.value().transfer(a_img) sep.add(_img) #////////////////////////////////////////////////////////// #/// visualize //////////////////////////////////////////// #////////////////////////////////////////////////////////// width = 700 height = 500 if args.vis_mode == "offscreen": import exlib_offscreen as exlib all_sep.add(sep) sep.thisown = 0 gl2ps_mgr = exlib.sg_gl2ps_manager() zb_mgr = inlib.sg_zb_manager() factor = 2 # have greater size to have good freetype rendering. _width = factor * width _height = factor * height clear_color = inlib.colorf_white() file = 'out_cfitsio_hst_vis.ps' format = "INZB_PS" exlib.sg_write_paper(inlib.get_cout(),gl2ps_mgr,zb_mgr,\ clear_color.r(),clear_color.g(),clear_color.b(),clear_color.a(),\ all_sep,_width,_height,file,format) file = 'out_cfitsio_hst_vis.png' format = "INZB_PNG" exlib.sg_write_paper(inlib.get_cout(),gl2ps_mgr,zb_mgr,\ clear_color.r(),clear_color.g(),clear_color.b(),clear_color.a(),\ all_sep,_width,_height,file,format) del clear_color del all_sep # before the below mgr. del zb_mgr del gl2ps_mgr elif args.vis_mode == "client": del all_sep host = args.vis_host port = int(args.vis_port) #print("try to connected to "+host+" "+str(port)+" ...") import exlib_offscreen as exlib dc = exlib.net_sg_client( inlib.get_cout(), False, True) #False=quiet, True=warn if receiving unknown protocol. if dc.initialize(host, port) == False: print("can't connect to " + host + " " + str(port)) exit() if dc.send_string(inlib.sg_s_protocol_clear_static_sg()) == False: print("send protocol_clear_static_scene() failed.") exit() opts = inlib.args() opts.add(inlib.sg_s_send_placement(), inlib.sg_s_placement_static()) if dc.send_sg(sep, opts) == False: print("send_sg failed.") exit() if dc.socket().send_string(inlib.sg_s_protocol_disconnect()) == False: print("send protocol_s_disconnect() failed.") exit() dc.socket().disconnect() del dc del sep else: print('exit viewer steering by closing the window with the mouse.') import exlib_window as exlib smgr = exlib.session(inlib.get_cout()) # screen manager if smgr.is_valid() == True: viewer = exlib.sg_viewer(smgr, 0, 0, width, height) if viewer.has_window() == True: all_sep.add(sep) sep.thisown = 0 all_sep.thisown = 0 viewer.sg().add(all_sep) viewer.show() smgr.steer() del viewer del smgr
args = parser.parse_args(None) if args.number_of_points == None : number_of_points = 10000 else: number_of_points = int(args.number_of_points) #//////////////////////////////////////////////////////////// #//////////////////////////////////////////////////////////// #//////////////////////////////////////////////////////////// import inlib all_sep = inlib.sg_separator() #all_sep.thisown = 0 camera = inlib.sg_ortho() camera.thisown = 0 camera.position.value(inlib.vec3f(0,0,5)) camera.focal.value(5) camera.height.value(2) camera.znear.value(0.1) camera.zfar.value(100) all_sep.add(camera) light = inlib.sg_head_light() light.thisown = 0 light.direction.value(inlib.vec3f(1,-1,-10)) #light.on.value(False) all_sep.add(light) m = inlib.sg_matrix()
def polyhedron(): #////////////////////////////////////////////////////////// #/// create scene graph /////////////////////////////////// #////////////////////////////////////////////////////////// all_sep = inlib.sg_separator() #all_sep.thisown = 0 # decided below camera = inlib.sg_ortho() camera.thisown = 0 camera.position.value(inlib.vec3f(0, 0, 5)) camera.focal.value(5) camera.height.value(10) camera.znear.value(0.1) camera.zfar.value(100) all_sep.add(camera) light = inlib.sg_head_light() light.thisown = 0 light.direction.value(inlib.vec3f(1, -1, -10)) #light.on.value(False) all_sep.add(light) sep = inlib.sg_separator() #all_sep.add(sep) # decided below #sep.thisown = 0 # decided below m = inlib.sg_matrix() m.thisown = 0 m.set_rotate(0, 1, 0, inlib.fhalf_pi() / 2) m.mul_rotate(1, 0, 0, inlib.fhalf_pi() / 2) sep.add(m) mat = inlib.sg_rgba() mat.thisown = 0 mat.color.value(inlib.colorf_green()) sep.add(mat) # A Tube with a transvers hole : tubs_1 = inlib.hep_polyhedron_tubs(0.7, 1.5, 2, 0, inlib.two_pi()) tubs_2 = inlib.hep_polyhedron_tubs(0, 0.5, 4, 0, inlib.two_pi()) tubs_2.Transform(inlib.rotd(inlib.vec3d(0, 1, 0), inlib.half_pi()), inlib.vec3d(0, 0, 0)) op = tubs_1.subtract(tubs_2) node = inlib.sg_polyhedron() node.thisown = 0 #node.ph.value(inlib.hep_polyhedron_sphere(0.9,1,0,inlib.two_pi(),0,inlib.pi())) node.ph.value(op) #node.solid.value(False) #node.reduced_wire_frame.value(False) sep.add(node) #////////////////////////////////////////////////////////// #/// viewing : //////////////////////////////////////////// #////////////////////////////////////////////////////////// width = 700 height = 500 if args.vis_mode == "offscreen": import exlib_offscreen as exlib all_sep.add(sep) sep.thisown = 0 gl2ps_mgr = exlib.sg_gl2ps_manager() zb_mgr = inlib.sg_zb_manager() factor = 2 # have greater size to have good freetype rendering. _width = factor * width _height = factor * height clear_color = inlib.colorf_white() file = 'out_polyhedron_vis.ps' format = "INZB_PS" exlib.sg_write_paper(inlib.get_cout(),gl2ps_mgr,zb_mgr,\ clear_color.r(),clear_color.g(),clear_color.b(),clear_color.a(),\ all_sep,_width,_height,file,format) file = 'out_polyhedron_vis.png' format = "INZB_PNG" exlib.sg_write_paper(inlib.get_cout(),gl2ps_mgr,zb_mgr,\ clear_color.r(),clear_color.g(),clear_color.b(),clear_color.a(),\ all_sep,_width,_height,file,format) del clear_color del all_sep # before the below mgr. del zb_mgr del gl2ps_mgr elif args.vis_mode == "client": del all_sep host = args.vis_host port = int(args.vis_port) #print("try to connected to "+host+" "+str(port)+" ...") import exlib_offscreen as exlib dc = exlib.net_sg_client( inlib.get_cout(), False, True) #False=quiet, True=warn if receiving unknown protocol. if dc.initialize(host, port) == False: print("can't connect to " + host + " " + str(port)) exit() if dc.send_string(inlib.sg_s_protocol_clear_static_sg()) == False: print("send protocol_clear_static_scene() failed.") exit() opts = inlib.args() opts.add(inlib.sg_s_send_placement(), inlib.sg_s_placement_static()) if dc.send_sg(sep, opts) == False: print("send_sg failed.") exit() if dc.socket().send_string(inlib.sg_s_protocol_disconnect()) == False: print("send protocol_s_disconnect() failed.") exit() dc.socket().disconnect() del dc del sep else: print('exit viewer steering by closing the window with the mouse.') import exlib_window as exlib all_sep.add(sep) sep.thisown = 0 smgr = exlib.session(inlib.get_cout()) if smgr.is_valid() == True: viewer = exlib.sg_viewer(smgr, 0, 0, width, height) if viewer.has_window() == True: all_sep.thisown = 0 viewer.sg().add( all_sep) # give ownership of sep to the viewer. viewer.show() print('steer...') smgr.steer() #FIXME : it blocks input from the prompt, why ? print('end steer.') del viewer del smgr
def plot3D_col(data, width=700, height=500, col_index=3, pointSize=1, client=False): #provide [0,255] index in heat map #/////////////////////////////////// #/// header /////////////////// #/////////////////////////////////// all_sep = inlib.sg_separator() camera = inlib.sg_ortho() camera.thisown = 0 camera.position.value(inlib.vec3f(0, 0, 5)) camera.height.value(2) camera.znear.value(0.1) camera.zfar.value(100) all_sep.add(camera) light = inlib.sg_head_light() light.thisown = 0 light.direction.value(inlib.vec3f(1, -1, -10)) #light.on.value(False) all_sep.add(light) layout = inlib.sg_matrix() layout.thisown = 0 #layout.set_rotate(0,1,0,0.785) all_sep.add(layout) #///////////////////////////////////////// #/// create the scene graph : //////////// #///////////////////////////////////////// cmap = inlib.SOPI_midas_heat() cmap_size = cmap.size() sep = inlib.sg_separator() m = inlib.sg_matrix() m.thisown = 0 sep.add(m) vtxs = inlib.sg_colored_sized_points() vtxs.thisown = 0 vtxs.mode.value(inlib.points()) sep.add(vtxs) for row in data[1:]: SOPI_color = cmap.get_color( int(row[col_index] )) # with midas_heat : icolor 0 is black, size-1 is white. r = SOPI_color.r() g = SOPI_color.g() b = SOPI_color.b() a = 1 vtxs.add(float(row[0]), float(row[1]), float(row[2]), r, g, b, a, pointSize) vtxs.center() # plotting///////////////////////////////////////////// if not client: import exlib_window as exlib smgr = exlib.session(inlib.get_cout()) # screen manager if smgr.is_valid() == True: viewer = exlib.gui_viewer_window(smgr, 0, 0, width, height) if viewer.has_window() == True: sep.thisown = 0 all_sep.add(sep) all_sep.thisown = 0 viewer.scene().add(all_sep) viewer.set_scene_camera(camera) viewer.set_scene_light(light) viewer.set_plane_viewer(False) viewer.set_scene_light_on(True) viewer.hide_main_menu() viewer.hide_meta_zone() viewer.show_camera_menu() viewer.show() viewer.steer() del viewer del smgr else: # client mode del all_sep host = "127.0.0.1" port = 50800 print("sending data to " + host + ":" + str(port) + " ->...") import exlib_offscreen as exlib dc = exlib.net_sg_client( inlib.get_cout(), False, True) #False=quiet, True=warn if receiving unknown protocol. if dc.initialize(host, port) == False: print("can't connect to " + host + " " + str(port)) exit() if dc.send_string(inlib.sg_s_protocol_clear_static_sg()) == False: print("send protocol_clear_static_scene() failed.") exit() opts = inlib.args() opts.add(inlib.sg_s_send_placement(), inlib.sg_s_placement_static()) if dc.send_sg(sep, opts) == False: print("send_sg failed.") exit() if dc.socket().send_string(inlib.sg_s_protocol_disconnect()) == False: print("send protocol_s_disconnect() failed.") exit() dc.socket().disconnect() del dc del sep
def plot3D_rgb_size(data, iord, bin_size=None, width=700, height=500, rgb_index=(3, 4, 5), client=False): #/////////////////////////////////// #/// header /////////////////// #/////////////////////////////////// all_sep = inlib.sg_separator() camera = inlib.sg_ortho() camera.thisown = 0 camera.position.value(inlib.vec3f(0, 0, 5)) camera.height.value(2) camera.znear.value(0.1) camera.zfar.value(100) all_sep.add(camera) light = inlib.sg_head_light() light.thisown = 0 light.direction.value(inlib.vec3f(1, -1, -10)) #light.on.value(False) all_sep.add(light) layout = inlib.sg_matrix() layout.thisown = 0 #layout.set_rotate(0,1,0,0.785) all_sep.add(layout) #///////////////////////////////////////// #/// create the scene graph : //////////// #///////////////////////////////////////// cmap = inlib.SOPI_midas_heat() cmap_size = cmap.size() sep = inlib.sg_separator() m = inlib.sg_matrix() m.thisown = 0 sep.add(m) vtxs = inlib.sg_colored_sized_points() vtxs.thisown = 0 vtxs.mode.value(inlib.points()) sep.add(vtxs) #loop in size chuncks for isize in range(len(iord)): _size = isize + 1 if not bin_size is None: _size = bin_size[isize] for i in iord[isize]: row = data[i] r = row[rgb_index[0]] g = row[rgb_index[1]] b = row[rgb_index[2]] a = 1 vtxs.add(float(row[0]), float(row[1]), float(row[2]), r, g, b, a, _size) vtxs.center() # plotting///////////////////////////////////////////// if not client: import exlib_window as exlib smgr = exlib.session(inlib.get_cout()) # screen manager if smgr.is_valid() == True: viewer = exlib.gui_viewer_window(smgr, 0, 0, width, height) if viewer.has_window() == True: sep.thisown = 0 all_sep.add(sep) all_sep.thisown = 0 viewer.scene().add(all_sep) viewer.set_scene_camera(camera) viewer.set_scene_light(light) viewer.set_plane_viewer(False) viewer.set_scene_light_on(True) viewer.hide_main_menu() viewer.hide_meta_zone() viewer.show_camera_menu() viewer.show() viewer.steer() del viewer del smgr else: # client mode del all_sep host = "127.0.0.1" port = 50800 print("sending data to " + host + ":" + str(port) + " ->...") import exlib_offscreen as exlib dc = exlib.net_sg_client( inlib.get_cout(), False, True) #False=quiet, True=warn if receiving unknown protocol. if dc.initialize(host, port) == False: print("can't connect to " + host + " " + str(port)) exit() if dc.send_string(inlib.sg_s_protocol_clear_static_sg()) == False: print("send protocol_clear_static_scene() failed.") exit() opts = inlib.args() opts.add(inlib.sg_s_send_placement(), inlib.sg_s_placement_static()) if dc.send_sg(sep, opts) == False: print("send_sg failed.") exit() if dc.socket().send_string(inlib.sg_s_protocol_disconnect()) == False: print("send protocol_s_disconnect() failed.") exit() dc.socket().disconnect() del dc del sep