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
#blend = inlib.sg_blend() #blend.thisown = 0 #blend.on.value(True) #sep.add(blend) m = inlib.sg_matrix() m.thisown = 0 sep.add(m) vtxs = inlib.sg_atb_vertices() vtxs.thisown = 0 vtxs.mode.value(inlib.points()) sep.add(vtxs) #cmap = inlib.SOPI_midas_idl14() cmap = inlib.SOPI_midas_heat() cmap_size = cmap.size() redshift_delta = redshift_max - redshift_min # mag_u : ultraviolet # mag_g : green # mag_r : red # mag_i : near infrared # mag_z : infrared i_pos_x = 0 i_pos_y = 1 i_pos_z = 2 i_redshift = 3 i_mag_g = 4
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