Example #1
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())
Example #2
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()
Example #3
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
Example #4
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
Example #5
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" :
Example #6
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
Example #7
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
Example #8
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
Example #9
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