def _clusters_update(): MEGPanel.current_cluster = cluster = MEGPanel.clusters_lookup[ bpy.context.scene.meg_clusters] # set_cluster_time_series(cluster) cluster_name = get_cluster_name(cluster) cluster_max_vert_co = mu.get_vert_co(cluster.max_vert, cluster.hemi) bpy.context.scene.cursor_location = cluster_max_vert_co _addon().set_cursor_pos() _addon().set_closest_vertex_and_mesh_to_cursor( cluster.max_vert, 'inflated_{}'.format(cluster.hemi)) _addon().save_cursor_position() _addon().create_slices() if bpy.context.scene.plot_current_meg_cluster: _addon().color_contours([cluster_name], cluster.hemi, MEGPanel.contours, bpy.context.scene.cumulate_meg_cluster, False) bpy.data.objects[PARENT_OBJ_NAME].select = True # mu.view_all_in_graph_editor() fcurves = mu.get_fcurves(PARENT_OBJ_NAME) cluster_fcurve_name = get_cluster_fcurve_name(cluster) if bpy.context.scene.cumulate_meg_cluster: fcurve_ind = [mu.get_fcurve_name(f) for f in fcurves].index(cluster_fcurve_name) fcurves[fcurve_ind].hide = False else: for fcurve in fcurves: fcurve_name = mu.get_fcurve_name(fcurve) fcurve.hide = fcurve_name != cluster_fcurve_name MEGPanel.prev_cluster = bpy.context.scene.meg_clusters
def flip_meg_clusters_ts(): fcurves = mu.get_fcurves(PARENT_OBJ_NAME, only_not_hiden=True) for fcurve, cluster in zip(fcurves, MEGPanel.clusters_labels_filtered): if cluster.ts_max < 0: for t in range(len(cluster.label_data)): fcurve.keyframe_points[t].co[ 1] = -fcurve.keyframe_points[t].co[1] MEGPanel.data_is_flipped = not MEGPanel.data_is_flipped
def select_all_clusters(): parent_obj = bpy.data.objects.get(PARENT_OBJ_NAME, None) if parent_obj is not None: parent_obj.select = True fcurves = mu.get_fcurves(PARENT_OBJ_NAME) filtered_fcurves_names = [ get_cluster_fcurve_name(c) for c in MEGPanel.clusters_labels_filtered ] for fcurve in fcurves: fcurve_name = mu.get_fcurve_name(fcurve) fcurve.hide = fcurve_name not in filtered_fcurves_names plot_all_clusters() mu.view_all_in_graph_editor()
def filter_electrode_or_sensor(elec_name, val=0.3): elec_obj = bpy.data.objects[elec_name] if bpy.context.scene.mark_filter_items: FilteringMakerPanel.electrodes_colors[elec_name] = _addon().get_obj_color(elec_obj) _addon().object_coloring(elec_obj, cu.name_to_rgb('green')) else: elec_obj.active_material.node_tree.nodes["Layer Weight"].inputs[0].default_value = val # todo: selecting the electrode will show both of their conditions time series # We don't want it to happen if selection_type == 'conds'... if bpy.context.scene.selection_type == 'conds' or bpy.context.scene.filter_items_one_by_one: bpy.data.objects[elec_name].select = True fcurves = mu.get_fcurves(bpy.data.objects[elec_name]) for fcurve in fcurves: fcurve.hide = False fcurve.select = True bpy.context.scene.objects.active = bpy.data.objects[elec_name] bpy.types.Scene.filter_is_on = True
def get_selected_clusters_data(): names = [] data = None fcurves = mu.get_fcurves(PARENT_OBJ_NAME) filtered_fcurves_names = [ get_cluster_fcurve_name(c) for c in MEGPanel.clusters_labels_filtered ] filtered_clusters = { fcurve_name: cluster for fcurve_name, cluster in zip(filtered_fcurves_names, MEGPanel.clusters_labels_filtered) } data_ind = 0 for fcurve in fcurves: fcurve_name = mu.get_fcurve_name(fcurve) if fcurve_name in filtered_fcurves_names: x = filtered_clusters[fcurve_name].label_data if data is None: data = np.zeros((len(filtered_fcurves_names), len(x))) data[data_ind] = x names.append(fcurve_name) data_ind += 1 return data, names, ['all']
def select_roi(roi_name, change_selected_fcurves_colors=True): roi = bpy.data.objects.get(roi_name) if roi is None: return # check if MEG data is loaded and attahced to the obj if mu.count_fcurves(roi) > 0: roi.select = True labels_selection_coloring(roi_name) # mu.change_fcurves_colors(roi) else: # Check if dynamic fMRI data is loaded fmri_parent_obj = bpy.data.objects.get('fMRI') fcurves = mu.get_fcurves(fmri_parent_obj) for fcurve in fcurves: if mu.get_fcurve_name(fcurve) == roi_name: fcurve.hide = False fmri_parent_obj.select = True else: fcurve.hide = True if change_selected_fcurves_colors: mu.change_selected_fcurves_colors(mu.OBJ_TYPES_ROIS) mu.view_all_in_graph_editor()
def select_connection(connection_name): fcurves = mu.get_fcurves(connection_name) for fcurve in fcurves: fcurve.hide = False fcurve.select = True mu.view_all_in_graph_editor()
def deselect_all_clusters(): for fcurve in mu.get_fcurves(PARENT_OBJ_NAME): fcurve.hide = True clear_all_clusters()
def get_rois_fcruves(): return mu.get_fcurves('Brain', recursive=False, only_selected=True) + \ mu.get_fcurves('Cortex-lh', recursive=True, only_selected=True) + \ mu.get_fcurves('Cortex-rh', recursive=True, only_selected=True)