Beispiel #1
0
def plot_histo(a_h, a_stop):

    import window
    p = window.plotter(inlib.get_cout(), 1, 1, 0, 0, 700, 500)
    p.plot_histo_cp(a_h)
    p.show()

    print('steer...')
    #p.steer() # it blocks input from the prompt (because threading module is not a truely thread system).

    import time
    while True:
        if a_stop() == True: break
        if p.sync() == False: break
        time.sleep(0.01)

    print('end steer.')
    del p

    import offscreen
    p = offscreen.plotter(inlib.get_cout(), 0, 0, 700, 500)
    p.plot_histo_cp(a_h)
    p.out_ps()
    p.out_zb_ps()
    p.out_bsg()
    del p
Beispiel #2
0
    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
Beispiel #3
0
 def out_ps(self, a_file='out.ps'):
     action = exlib.sg_gl2ps_action(self.m_gl2ps_mgr, inlib.get_cout(),
                                    self.m_width, self.m_height)
     action.open(a_file)
     self.m_sep.render(action)
     action.close()
     del action
Beispiel #4
0
 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
Beispiel #5
0
 def __init__(self, a_out, a_cols, a_rows, a_x, a_y, a_width, a_height):
     self.m_gl2ps_mgr = exlib.sg_gl2ps_manager()
     self.m_session = exlib.session(inlib.get_cout())  # screen manager
     if self.m_session.is_valid() == False:
         raise ValueError()
     self.m_plotter = exlib.plotter(self.m_session, a_cols, a_rows, a_x,
                                    a_y, a_width, a_height)
     if self.m_plotter.has_window() == False:
         raise ValueError()
     base_plots.base_plots.__init__(self, a_out, self.m_plotter.plots())
Beispiel #6
0
def main():
    rfile = inlib.rroot_file(
        inlib.get_cout(), file,
        False)  # wroot.root produced by inlib/examples/cpp/wroot.cpp.
    if rfile.is_open() == False:
        print("can't open ../../../data/wroot.root")
        return EXIT_FAILURE

    keys = rfile.dir().keys()
    if keys.size() != 4:
        print('expected 4 keys in file. Found ' + str(keys.size()))
        return EXIT_FAILURE


#  ls = True
#  dump = True
#  inlib.rroot_read(inlib.get_cout(),rfile,keys,True,ls,dump,0)
#  return EXIT_SUCCESS

    dir = inlib.rroot_find_dir(rfile.dir(), 'histo')
    if dir == None:
        print('directory histo not found')
        return EXIT_FAILURE

    key = dir.find_key('rg')
    if key == None:
        print('rg histo not found')
        return EXIT_FAILURE

    h = inlib.rroot_key_to_h1d(rfile, key)
    if h == None:
        print('key rg is not a h1d.')
        return EXIT_FAILURE

    prec = 1e-10
    import math

    h_mean_ref = 0.8893330840610005
    if math.fabs(h.mean() - h_mean_ref) > prec:
        print("h.mean " + str(h.mean()) + ", expected " + str(h_mean_ref))
        return EXIT_FAILURE

    h_rms_ref = 1.8674268448349378
    if math.fabs(h.rms() - h_rms_ref) > prec:
        print("h.rms " + str(h.rms()) + ", expected " + str(h_rms_ref))
        return EXIT_FAILURE

    rfile.close()
    return EXIT_SUCCESS
Beispiel #7
0
def plot3D(data, width=700, height=500, pointSize=1.2, client=False):
    c3 = inlib.histo_c3d('xyz')
    [c3.fill(float(row[0]), float(row[1]), float(row[2]), 1) for row in data]

    #plotter
    if not client:
        plotter = window.gui_plotter(inlib.get_cout(), 1, 1, 0, 0, width,
                                     height)
    else:
        import inexlib_client
        style_file = os.path.join(os.environ['EXLIB_RES_DIR'], "ioda.style")
        plotter = inexlib_client.plotter(inlib.get_cout(), 1, 1, "127.0.0.1",
                                         50800, style_file)

#scen graph plotter
    sgp = plotter.plot_cloud3D(c3)
    sgp.shape.value(inlib.sg_plotter.xyz)
    sgp.shape_automated.value(False)
    sgp.infos_style().visible.value(False)
    sgp.points_style(0).color.value(inlib.colorf_black())
    #sgp.points_style(0).color.value(inlib.colorf_yellow())
    #sgp.points_style(0).modeling.value(inlib.modeling_points())
    sgp.points_style(0).marker_style.value(inlib.marker_dot)
    sgp.points_style(0).point_size.value(pointSize)

    if not client:
        plotter.show()
        plotter.steer()
    else:
        print("clearing scene")
        plotter.send_clear_static_scene()
        print("sending data to 127.0.0.1:50800 ...")
        plotter.send_plots()

    del plotter
    del c3
Beispiel #8
0
    def __init__(self, a_out, a_cols, a_rows, a_x, a_y, a_width, a_height):
        self.m_gl2ps_mgr = exlib.sg_gl2ps_manager()
        self.m_session = exlib.session(inlib.get_cout())  # screen manager
        if self.m_session.is_valid() == False:
            raise ValueError()
        self.m_plotter = exlib.gui_plotter(self.m_session, a_cols, a_rows, a_x,
                                           a_y, a_width, a_height)
        if self.m_plotter.has_window() == False:
            raise ValueError()
        base_plots.base_plots.__init__(self, a_out, self.m_plotter.plots())

        self.m_plotter.set_plane_viewer(False)
        self.m_plotter.set_scene_light_on(False)
        self.m_plotter.hide_main_menu()
        self.m_plotter.hide_meta_zone()
        self.m_plotter.show_camera_menu()
Beispiel #9
0
 def out_bsg(self, a_file='out.bsg'):
     action = inlib.sg_write_bsg(inlib.get_cout())
     if action.open_buffer() == False:
         print(
             "offscreen.plotter.render : inlib::sg::write_bsg.open_buffer : failed."
         )
     elif self.m_sep.write(action) == False:
         print("offscreen.plotter.render : group.write() failed.")
     elif action.close_buffer() == False:
         print(
             "offscreen.plotter.render : inlib::sg::write_bsg.close_buffer : failed."
         )
     elif action.write_file(a_file) == False:
         print(
             "offscreen.plotter.render : inlib::sg::write_bsg.write_file : failed."
         )
     del action
Beispiel #10
0
def rroot_main():
    rfile = inlib.rroot_file(inlib.get_cout(), path, False)
    if rfile.is_open() == False:
        print "can't open out.root"
        return EXIT_FAILURE

    keys = rfile.dir().keys()
    #print 'number of keys = ',keys.size()

    dir = inlib.rroot_find_dir(rfile.dir(), 'CHARM')
    if dir == None:
        print 'directory not found'
        return EXIT_FAILURE

    key = dir.find_key('h7103')
    if key == None:
        print 'histo not found'
        return EXIT_FAILURE

    h = inlib.rroot_key_to_h1d(rfile, key)
    if h == None:
        print 'key is not a h1d.'
        return EXIT_FAILURE

    #print h.mean(),h.rms()

    rfile.close()

    #//////////////////////////////////////////////////
    #// plot : ////////////////////////////////////////
    #//////////////////////////////////////////////////

    plots = inlib.get_sg_plots(gv)
    if plots == None:
        print 'sg::plots not found.'
        return EXIT_FAILURE

    plots.set_current_plotter(0)

    plotter = plots.current_plotter()
    plotter.clear()
    plotter.plot_cp(h)

    gv.hide_main_menu()
Beispiel #11
0
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
Beispiel #12
0
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
Beispiel #13
0
if verbose == True :
  print("inlib::histo::c3d entries : "+str(c3.entries()))
  print("  mean x = "+str(c3.mean_x())+", rms x = "+str(c3.rms_x()))
  print("  mean y = "+str(c3.mean_y())+", rms y = "+str(c3.rms_y()))
  print("  mean z = "+str(c3.mean_z())+", rms z = "+str(c3.rms_z()))
  
#///////////////////////////////////////////////////////////////////////////////////////
#/// plotting : /////////////////////////////////////////////////////////////////////////
#///////////////////////////////////////////////////////////////////////////////////////

if verbose == True : print("plot ...")

import exlib_window as exlib

smgr = exlib.session(inlib.get_cout()) # screen manager
if smgr.is_valid() == True :
  plotter = exlib.plotter(smgr,2,2,0,0,700,500)
  if plotter.has_window() == True :

    sgp = plotter.plots().current_plotter()
    sgp.bins_style(0).color.value(inlib.colorf_blue())
    sgp.infos_style().font.value(inlib.font_arialbd_ttf())
    sgp.infos_x_margin.value(0.01) #percent of plotter width.
    sgp.infos_y_margin.value(0.01) #percent of plotter height.
    sgp.plot(h)
    
    plotter.plots().next()
    sgp = plotter.plots().current_plotter()
    sgp.points_style(0).color.value(inlib.colorf_blue())
    sgp.points_style(0).modeling.value(inlib.modeling_points())
Beispiel #14
0
      print('file hst-img-2010x1890.fits not found.')
      exit()
    
import inlib

cmap = inlib.SOPI_colrj32()

lut = inlib.lut_double(-0.04,0.4,cmap.size())

import exlib_window as exlib

slice = 0
ihdu = 1
img = inlib.img_byte()
yswap = False
if exlib.fits_image_read_slice_to_img(inlib.get_cout(),file,ihdu,slice,yswap,lut,cmap,img) == False :
  print('read_slice failed.')
else:
  print ('size ');print(img.size())

del cmap
del lut
  
#//////////////////////////////////////////////////////////
#//////////////////////////////////////////////////////////
#//////////////////////////////////////////////////////////
stop_thread = False

def vis_img(a_img,a_stop):
  if a_img.is_empty() == True : return
  #//////////////////////////////////////////////////////////
Beispiel #15
0
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
Beispiel #16
0
if verbose == True:
    print("inlib::histo::c3d entries : " + str(c3.entries()))
    print("  mean x = " + str(c3.mean_x()) + ", rms x = " + str(c3.rms_x()))
    print("  mean y = " + str(c3.mean_y()) + ", rms y = " + str(c3.rms_y()))
    print("  mean z = " + str(c3.mean_z()) + ", rms z = " + str(c3.rms_z()))

#///////////////////////////////////////////////////////////////////////////////////////
#/// plotting : /////////////////////////////////////////////////////////////////////////
#///////////////////////////////////////////////////////////////////////////////////////
width = 700
height = 500

if args.vis_mode == "window":
    if verbose == True: print("plot (window) ...")
    import window
    p = window.plotter(inlib.get_cout(), 2, 2, 0, 0, width, height)

    sgp = p.plot_histo(h1_0)
    sgp.y_axis_automated.value(False)
    sgp.y_axis_min.value(0)
    sgp.y_axis_max.value(y_max)
    p.next()
    sgp = p.plot_histo(h1_1)
    sgp.y_axis_automated.value(False)
    sgp.y_axis_min.value(0)
    sgp.y_axis_max.value(y_max)
    p.next()
    sgp = p.plot_histo(h1_2)
    sgp.y_axis_automated.value(False)
    sgp.y_axis_min.value(0)
    sgp.y_axis_max.value(y_max)
Beispiel #17
0
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
Beispiel #18
0
  vtxs.add(rgd.shoot(),rgd.shoot(),rgd.shoot())

[fill() for i in range(0,number_of_points)]

vtxs.center()

#////////////////////////////////////////////////////////////
#////////////////////////////////////////////////////////////
#////////////////////////////////////////////////////////////
width = 700
height = 500

if args.vis_mode == "window" :
  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 :
      sep.thisown = 0
      all_sep.add(sep)
      all_sep.thisown = 0
      viewer.sg().add(all_sep)
      viewer.show()
      print('steer...')
      smgr.steer()
      print('end steer.')
    del viewer
  del smgr
    
elif args.vis_mode == "offscreen" :
Beispiel #19
0
                    required=True,
                    help='port to display on')
args = parser.parse_args(None)

host = args.vis_host
port = int(args.vis_port)

#//////////////////////////////////////////////////////////
#/// inexlib client : /////////////////////////////////////
#//////////////////////////////////////////////////////////
import inlib

import exlib_offscreen as exlib

dc = exlib.net_sg_client(
    inlib.get_cout(), False,
    True)  #False=quiet, True=warn if receiving unknown protocol.

#print("try to connected to "+host+" "+str(port)+" ...")

if dc.initialize(host, port) == False:
    print("can't connect to " + host + " " + str(port))
    exit()

#print("connected to "+host+" "+str(port))

#//////////////////////////////////////////////////////////
#/// scene graph : ////////////////////////////////////////
#//////////////////////////////////////////////////////////
sep = inlib.sg_separator()
sep.thisown = 0
Beispiel #20
0
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
Beispiel #21
0
height = 500

if args.vis_mode == "offscreen":
    import exlib_offscreen as exlib

    all_sep = create_all_sep(sep)

    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_two_cubes.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_two_cubes.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 zb_mgr
    del gl2ps_mgr
    del all_sep

elif args.vis_mode == "client":

    host = args.vis_host
Beispiel #22
0
    c3 = inlib.histo_c3d('xyz')
    [
        c3.fill(ntuple[0][0], ntuple[0][1], ntuple[0][2], 1) for ntuple in data
        if ntuple[0] is not None
    ]

    #print("inlib::histo::c3d entries : "+str(c3.entries()))
    #print("  mean x = "+str(c3.mean_x())+", rms x = "+str(c3.rms_x()))
    #print("  mean y = "+str(c3.mean_y())+", rms y = "+str(c3.rms_y()))
    #print("  mean z = "+str(c3.mean_z())+", rms z = "+str(c3.rms_z()))

    if args.vis_mode == "window":
        #print("plot (window) ...")
        import window
        p = window.plotter(inlib.get_cout(), 1, 1, 0, 0, 700, 500)
        p.plot_cloud3D(c3)
        p.show()
        p.steer()
        del p

    elif args.vis_mode == "offscreen":
        #print("plot (offscreen) ...")
        import offscreen
        p = offscreen.plotter(inlib.get_cout(), 1, 1, 400, 400)
        p.plot_cloud3D(c3)
        if args.vis_format == "bsg":
            p.out_bsg('out_spark_fits_vis.bsg')
        else:
            p.write_paper('out_spark_fits_vis.ps', 'INZB_PS')
            p.write_paper('out_spark_fits_vis.png', 'INZB_PNG')
Beispiel #23
0
#//////////////////////////////////////////////////////////
#//////////////////////////////////////////////////////////
file = '../../data/pawdemo.root'
if os.path.isfile(file) == False:
    file = '../data/pawdemo.root'
    if os.path.isfile(file) == False:
        file = './data/pawdemo.root'
        if os.path.isfile(file) == False:
            file = './pawdemo.root'
            if os.path.isfile(file) == False:
                print('file pawdemo.root not found.')
                exit()

import inlib

out = inlib.get_cout()

EXIT_FAILURE = 1
EXIT_SUCCESS = 0

#//////////////////////////////////////////////////
#// open the file and get an histo : //////////////
#//////////////////////////////////////////////////


def tree_main():
    rfile = inlib.rroot_file(inlib.get_cout(), file, False)
    if rfile.is_open() == False:
        print("can't open file")
        return EXIT_FAILURE
Beispiel #24
0
            print('file hst-img-2010x1890.fits not found.')
            exit()

import inlib

cmap = inlib.SOPI_colrj32()

lut = inlib.lut_double(-0.04, 0.4, cmap.size())

import exlib_window as exlib

slice = 0
ihdu = 1
img = inlib.img_byte()
yswap = False
if exlib.fits_image_read_slice_to_img(inlib.get_cout(), file, ihdu, slice,
                                      yswap, lut, cmap, img) == False:
    print('read_slice failed.')
    exit()

#print ('size ');print(img.size())

del cmap
del lut

#//////////////////////////////////////////////////////////
#//////////////////////////////////////////////////////////
#//////////////////////////////////////////////////////////
stop_thread = False

Beispiel #25
0
def tree_main():
    rfile = inlib.rroot_file(inlib.get_cout(), file, False)
    if rfile.is_open() == False:
        print("can't open file")
        return EXIT_FAILURE

    keys = rfile.dir().keys()
    #print('number of keys = ');print(keys.size())

    dir = inlib.rroot_find_dir(rfile.dir(), 'STAFF')
    if dir == None:
        print('directory not found')
        return EXIT_FAILURE

    key = dir.find_key('h10')
    if key == None:
        print('tree not found')
        return EXIT_FAILURE

    fac = inlib.rroot_fac(out)
    tree = inlib.rroot_key_to_tree(rfile, fac, key)
    if tree == None:
        print('key is not a tree.')
        return EXIT_FAILURE

    #tree.show(gv.out(),1)
    #print(tree.entries())

    leaf = tree.find_leaf("Age")
    if leaf == None:
        print('leaf not found.')
        return EXIT_FAILURE

    #print('leaf type : ');print(leaf.s_cls())

    li = inlib.rroot_cast_leaf_int(leaf)
    if leaf == None:
        print('leaf not a leaf<int>.')
        return EXIT_FAILURE

    branch = tree.find_leaf_branch(leaf)
    if branch == None:
        print('branch of leaf not found.')
        return EXIT_FAILURE

    h_age = inlib.histo_h1d('CERN/Age', 100, 0, 100)

    for i in range(0, tree.entries()):
        if branch.find_entry(rfile, i) == False:
            print('branch.find_entry failed.')
            return EXIT_FAILURE
        v = li.value(0)
        h_age.fill(v, 1)

    rfile.close()

    print(h_age.entries())
    print(h_age.mean())
    print(h_age.rms())

    #//////////////////////////////////////////////////
    #// plot : ////////////////////////////////////////
    #//////////////////////////////////////////////////

    if args.vis_mode == "offscreen":
        import offscreen
        p = offscreen.plotter(inlib.get_cout(), 1, 1, 700, 500)
        p.plot_histo(h_age)
        if args.vis_format == "bsg":
            p.out_bsg('out_tree.bsg')
        else:
            p.write_paper('out_tree.ps', 'INZB_PS')
            p.write_paper('out_tree.png', 'INZB_PNG')
        del p

    elif args.vis_mode == "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.plot_histo(h_age)

        #p.set_plotters_style("ROOT_default")
        if args.vis_host == "134.158.76.71":  #LAL/wallino.
            p.set_plotters_style("wall_ROOT_default")
        p.send_clear_static_scene()
        p.send_plots()
        del p

    else:
        import exlib_window as exlib
        gl2ps_mgr = exlib.sg_gl2ps_manager()
        smgr = exlib.session(inlib.get_cout())  # screen manager
        if smgr.is_valid() == True:
            plotter = exlib.plotter(smgr, 1, 1, 0, 0, 700, 500)
            if plotter.has_window() == True:
                sgp = plotter.plots().current_plotter()
                sgp.bins_style(0).color.value(inlib.colorf_blue())

                sgp.infos_style().font.value(inlib.font_arialbd_ttf())

                sgp.infos_x_margin.value(0.01)  #percent of plotter width.
                sgp.infos_y_margin.value(0.01)  #percent of plotter height.

                plotter.plot(h_age)

                plotter.plots().view_border.value(False)

                waction = exlib.sg_gl2ps_action(gl2ps_mgr, inlib.get_cout(),
                                                plotter.width(),
                                                plotter.height())
                waction.open('out.ps')
                plotter.sg().render(waction)
                waction.close()
                del waction

                plotter.show()

                plotter.steer()

            del plotter

        del smgr
Beispiel #26
0
  print("inlib::histo::c3d entries : "+str(c3.entries()))
  print("  mean x = "+str(c3.mean_x())+", rms x = "+str(c3.rms_x()))
  print("  mean y = "+str(c3.mean_y())+", rms y = "+str(c3.rms_y()))
  print("  mean z = "+str(c3.mean_z())+", rms z = "+str(c3.rms_z()))
  print("  low x = "+str(c3.lower_edge_x())+", up x = "+str(c3.upper_edge_x()))
  print("  low y = "+str(c3.lower_edge_y())+", up y = "+str(c3.upper_edge_y()))
  print("  low z = "+str(c3.lower_edge_z())+", up z = "+str(c3.upper_edge_z()))
  
#///////////////////////////////////////////////////////////////////////////////////////
#/// plotting : /////////////////////////////////////////////////////////////////////////
#///////////////////////////////////////////////////////////////////////////////////////

if args.vis_mode == "window" :
  if verbose == True : print("plot (window) ...")
  import window
  p = window.plotter(inlib.get_cout(),1,1,0,0,700,500)
  p.plot_cloud3D(c3)
  p.show()
  p.steer()
  del p
    
elif args.vis_mode == "offscreen" :
  if verbose == True : print("plot (offscreen) ...")
  import offscreen
  p = offscreen.plotter(inlib.get_cout(),1,1,400,400)
  p.plot_cloud3D(c3)
  if args.vis_format == "bsg":
    p.out_bsg('out_csv_c3d_vis.bsg')
  else:
    p.write_paper('out_csv_c3d_vis.ps','INZB_PS')
    p.write_paper('out_csv_c3d_vis.png','INZB_PNG')
Beispiel #27
0
def tree_main():
    rfile = inlib.rroot_file(inlib.get_cout(), path, False)
    if rfile.is_open() == False:
        print "can't open out.root"
        return EXIT_FAILURE

    keys = rfile.dir().keys()
    #print 'number of keys = ',keys.size()

    dir = inlib.rroot_find_dir(rfile.dir(), 'STAFF')
    if dir == None:
        print 'directory not found'
        return EXIT_FAILURE

    key = dir.find_key('h10')
    if key == None:
        print 'tree not found'
        return EXIT_FAILURE

    fac = inlib.rroot_fac(gv.out())
    tree = inlib.rroot_key_to_tree(rfile, fac, key)
    if tree == None:
        print 'key is not a tree.'
        return EXIT_FAILURE

    #tree.show(gv.out(),1)
    #print tree.entries()

    leaf = tree.find_leaf("Age")
    if leaf == None:
        print 'leaf not found.'
        return EXIT_FAILURE

    #print 'leaf type : ',leaf.s_cls()

    li = inlib.rroot_cast_leaf_int(leaf)
    if leaf == None:
        print 'leaf not a leaf<int>.'
        return EXIT_FAILURE

    branch = tree.find_leaf_branch(leaf)
    if branch == None:
        print 'branch of leaf not found.'
        return EXIT_FAILURE

    h_age = inlib.histo_h1d('CERN/Age', 100, 0, 100)

    for i in range(0, tree.entries()):
        if branch.find_entry(rfile, i) == False:
            print 'branch.find_entry failed.'
            return EXIT_FAILURE
        v = li.value(0)
        #print 'li ',i,' ',v
        h_age.fill(v, 1)

    rfile.close()

    #//////////////////////////////////////////////////
    #// plot : ////////////////////////////////////////
    #//////////////////////////////////////////////////

    plots = inlib.get_sg_plots(gv)
    if plots == None:
        print 'sg::plots not found.'
        return EXIT_FAILURE

    plots.set_current_plotter(0)

    plotter = plots.current_plotter()
    plotter.clear()
    plotter.plot_cp(h_age)

    gv.hide_main_menu()