def out_zb_ps(self, a_file='out_zb.ps'): factor = 2 # have greater size to have good freetype rendering. _width = factor * self.m_width _height = factor * self.m_height action = inlib.sg_zb_action(self.m_zb_mgr, inlib.get_cout(), _width, _height) clear_color = inlib.colorf_white() action.zbuffer().clear_color_buffer(0) action.add_color(clear_color.r(), clear_color.g(), clear_color.b()) action.zbuffer().clear_depth_buffer() self.m_sep.render(action) wps = inlib.wps(inlib.get_cout()) if wps.open_file(a_file) == False: print( "offscreen.plotter.render : inlib::sg::wps.open_file : failed." ) else: wps.PS_BEGIN_PAGE() wps.PS_PAGE_SCALE(_width, _height) wps.PS_IMAGE(action) wps.PS_END_PAGE() wps.close_file() del clear_color del wps del action
def write_paper(self, a_file, a_format): factor = 2 # have greater size to have good freetype rendering. _width = factor * self.m_width _height = factor * self.m_height clear_color = inlib.colorf_white() exlib.sg_write_paper(inlib.get_cout(),self.m_gl2ps_mgr,self.m_zb_mgr,\ clear_color.r(),clear_color.g(),clear_color.b(),clear_color.a(),\ self.m_sep,_width,_height,a_file,a_format) del clear_color
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
p.write_paper('out_csv_c3d_vis.png','INZB_PNG') del p elif args.vis_mode == "client" : if verbose == True : print("plot (client) ...") import inexlib_client style_file = "./res/ioda.style" p = inexlib_client.plotter(inlib.get_cout(),1,1,args.vis_host,int(args.vis_port),style_file) #p.m_blend.on.value(True) sgp = p.plot_cloud3D(c3) color = inlib.colorf_blue() if args.vis_host == "134.158.76.71": #LAL/wallino. color = inlib.colorf_white() #color = inlib.colorf_white() # on black background, it is nice #color.set_a(0.5) sgp.points_style(0).color.value(color) sgp.theta.value(0) sgp.phi.value(0) sgp.tau.value(0) #sgp.x_axis_automated.value(False) #sgp.x_axis_min.value(60.4) #sgp.x_axis_max.value(71) #sgp.y_axis_automated.value(False) #sgp.y_axis_min.value(-46.5) #sgp.y_axis_max.value(-32.9)
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
a_sep.thisown = 0 all_sep.add(a_sep) return all_sep #/////////////////////////////////////////////////// #/////////////////////////////////////////////////// #/////////////////////////////////////////////////// sep = inlib.sg_separator() #sep.thisown = 0 _color = inlib.colorf_blue() if args.vis_host == "134.158.76.71": #LAL/wallino. _color = inlib.colorf_white() _color.set_a(0.5) #/////////////////////////////////////////////////// #/// two cubes blended : /////////////////////////// #/////////////////////////////////////////////////// _sep = inlib.sg_separator() _sep.thisown = 0 sep.add(_sep) blend = inlib.sg_blend() blend.thisown = 0 blend.on.value(True) _sep.add(blend) 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