def _electrodes_update(): if ElecsPanel.addon is None or not ElecsPanel.init: return # ElecsPanel.addon.show_electrodes() # show_elecs_hemi_update() # _show_only_current_lead_update() prev_electrode = ElecsPanel.current_electrode ElecsPanel.current_electrode = current_electrode = bpy.context.scene.electrodes bpy.context.scene.current_lead = ElecsPanel.groups[current_electrode] update_cursor() color_electrodes(current_electrode, prev_electrode) if prev_electrode != '': unselect_prev_electrode(prev_electrode) # if ElecsPanel.groups[prev_electrode] != bpy.context.scene.current_lead: # _show_only_current_lead_update() if not ElecsPanel.lookup is None: loc = ElecsPanel.lookup.get(current_electrode, None) if loc is None: print("Can't find {} in ElecsPanel.lookup!".format(current_electrode)) else: print_electrode_loc(loc) if bpy.context.scene.color_lables: plot_labels_probs(loc) else: print('lookup table is None!') select_electrode(current_electrode) mu.change_fcurves_colors(bpy.data.objects[current_electrode])
def _electrodes_update(): if ElecsPanel.addon is None or not ElecsPanel.init: return # ElecsPanel.addon.show_electrodes() # show_elecs_hemi_update() # _show_only_current_lead_update() prev_electrode = ElecsPanel.current_electrode ElecsPanel.current_electrode = current_electrode = bpy.context.scene.electrodes bpy.context.scene.current_lead = ElecsPanel.groups[current_electrode] update_cursor() color_electrodes(current_electrode, prev_electrode) if prev_electrode != '': unselect_prev_electrode(prev_electrode) # if ElecsPanel.groups[prev_electrode] != bpy.context.scene.current_lead: # _show_only_current_lead_update() if not ElecsPanel.lookup is None: loc = ElecsPanel.lookup.get(current_electrode, None) if loc is None: print("Can't find {} in ElecsPanel.lookup!".format( current_electrode)) else: print_electrode_loc(loc) if bpy.context.scene.color_lables: plot_labels_probs(loc) else: print('lookup table is None!') select_electrode(current_electrode) mu.change_fcurves_colors(bpy.data.objects[current_electrode])
def modal(self, context, event): # def show_fcurves(obj): # mu.change_fcurves_colors(obj) # mu.view_all_in_graph_editor() if self.right_clicked: if len(bpy.context.selected_objects): selected_obj_name = bpy.context.selected_objects[0].name selected_obj_type = mu.check_obj_type(selected_obj_name) if selected_obj_type in [ mu.OBJ_TYPE_CORTEX_LH, mu.OBJ_TYPE_CORTEX_RH, mu.OBJ_TYPE_ELECTRODE, mu.OBJ_TYPE_EEG ]: obj = bpy.data.objects.get(selected_obj_name) if obj: mu.change_fcurves_colors(obj) if selected_obj_type in [ mu.OBJ_TYPE_CORTEX_INFLATED_LH, mu.OBJ_TYPE_CORTEX_INFLATED_RH ]: pial_obj_name = selected_obj_name[len('inflated_'):] pial_obj = bpy.data.objects.get(pial_obj_name) if not pial_obj is None: pial_obj.select = True mu.change_fcurves_colors(pial_obj) self.right_clicked = False if time.time() - self.press_time > 1 and event.type == 'RIGHTMOUSE': self.press_time = time.time() self.right_clicked = True return {'PASS_THROUGH'}
def create_conncection_per_condition(d, layers_rods, indices, mask, windows_num, norm_fac, T, radius): N = len(indices) parent_obj = bpy.data.objects[get_connections_parent_name()] print('Create connections for both conditions') con_color = (1, 1, 1, 1) now = time.time() for run, (ind, conn_name, (i, j)) in enumerate(zip(indices, d.con_names[mask], d.con_indices[mask])): mu.time_to_go(now, run, N, runs_num_to_print=10) p1, p2 = d.locations[i, :] * 0.1, d.locations[j, :] * 0.1 mu.cylinder_between(p1, p2, radius, layers_rods) mu.create_material('{}_mat'.format(conn_name), con_color, 1) cur_obj = bpy.context.active_object cur_obj.name = conn_name cur_obj.parent = parent_obj # cur_obj.animation_data_clear() if windows_num == 1: continue for cond_id, cond in enumerate(d.conditions): # insert_frame_keyframes(cur_obj, '{}-{}'.format(conn_name, cond), d.con_values[ind, -1, cond_id], T) for t in range(windows_num): extra_time_points = 0 if norm_fac == 1 else 2 timepoint = t * norm_fac + extra_time_points mu.insert_keyframe_to_custom_prop(cur_obj, '{}-{}'.format(conn_name, cond), d.con_values[ind, t, cond_id], timepoint) fcurve = cur_obj.animation_data.action.fcurves[cond_id] fcurve.keyframe_points[0].co[1] = 0 fcurve.keyframe_points[-1].co[1] = 0 finalize_fcurves(cur_obj) mu.change_fcurves_colors(parent_obj.children)
def invoke(self, context, event=None): select_all_meg_sensors() SelectionMakerPanel.selection.append(SEL_MEG_SENSORS) mu.unfilter_graph_editor() mu.change_fcurves_colors(bpy.data.objects['MEG_sensors'].children) mu.view_all_in_graph_editor(context) return {"FINISHED"}
def finalize_fcurves(parent_obj, interpolation=''): for fcurve in parent_obj.animation_data.action.fcurves: fcurve.modifiers.new(type='LIMITS') if interpolation == '': interpolation = 'BEZIER' if len(fcurve.keyframe_points) > 10 else 'LINEAR' for kf in fcurve.keyframe_points: kf.interpolation = interpolation mu.change_fcurves_colors([parent_obj])
def invoke(self, context, event=None): evoked_name = '{}_{}'.format(bpy.context.scene.meg_evoked_files, bpy.context.scene.evoked_objects) evoked_obj = bpy.data.objects.get(evoked_name) if not evoked_obj is None: evoked_obj.select = not evoked_obj.select mu.view_all_in_graph_editor(context) selected_objects = mu.get_selected_objects() mu.change_fcurves_colors(selected_objects) return {"FINISHED"}
def invoke(self, context, event=None): select_only_subcorticals() SelectionMakerPanel.selection.append(SEL_SUBS) mu.view_all_in_graph_editor(context) if bpy.context.scene.selection_type == 'diff': mu.change_fcurves_colors([bpy.data.objects['Subcortical_structures']]) else: mu.change_fcurves_colors(bpy.data.objects['Subcortical_structures'].children) return {"FINISHED"}
def invoke(self, context, event=None): select_all_rois() mu.view_all_in_graph_editor(context) if bpy.context.scene.selection_type == 'diff': mu.change_fcurves_colors([bpy.data.objects['Brain']]) else: corticals_labels = mu.get_corticals_labels() mu.change_fcurves_colors(corticals_labels) return {"FINISHED"}
def finalize_fcurves(parent_obj, interpolation=''): for fcurve in parent_obj.animation_data.action.fcurves: fcurve.modifiers.new(type='LIMITS') if interpolation == '': interpolation = 'BEZIER' if len( fcurve.keyframe_points) > 10 else 'LINEAR' for kf in fcurve.keyframe_points: kf.interpolation = interpolation mu.change_fcurves_colors([parent_obj])
def invoke(self, context, event=None): select_all_eeg() mu.unfilter_graph_editor() # if bpy.context.scene.selection_type == 'diff': # mu.change_fcurves_colors([bpy.data.objects['Deep_electrodes']]) # elif bpy.context.scene.selection_type == 'spec_cond': # mu.filter_graph_editor(bpy.context.scene.conditions_selection) # else: mu.change_fcurves_colors(bpy.data.objects['EEG_electrodes'].children) mu.view_all_in_graph_editor(context) return {"FINISHED"}
def select_all_electrodes(): parent_obj = bpy.data.objects['Deep_electrodes'] mu.unfilter_graph_editor() bpy.context.scene.filter_curves_type = 'Electrodes' if 'ELECTRODES' in _addon().settings.sections(): config = _addon().settings['ELECTRODES'] bad = mu.get_args_list(config.get('bad', '')) else: bad = [] select_brain_objects('Deep_electrodes', exclude=bad) mu.unfilter_graph_editor() if bpy.context.scene.selection_type == 'diff': mu.change_fcurves_colors([parent_obj], bad) elif bpy.context.scene.selection_type == 'spec_cond': mu.filter_graph_editor(bpy.context.scene.conditions_selection) else: mu.change_fcurves_colors(parent_obj.children, bad)
def vertices_selected(vertice_name): label_name = vertice_name[:-len('_vertice')] if _addon().both_conditions(): for conn_name in ConnectionsPanel.vertices_lookup[label_name]: conn_obj = bpy.data.objects.get(conn_name, None) if conn_obj and not conn_obj.hide: conn_obj.select = True elif _addon().conditions_diff(): parent_obj = bpy.context.scene.objects[get_connections_parent_name()] if parent_obj.animation_data is None: return parent_obj.select = True for fcurve in parent_obj.animation_data.action.fcurves: con_name = mu.get_fcurve_name(fcurve) fcurve.select = con_name in ConnectionsPanel.vertices_lookup[label_name] fcurve.hide = not con_name in ConnectionsPanel.vertices_lookup[label_name] mu.change_fcurves_colors(bpy.data.objects[get_connections_parent_name()].children) _addon().fit_selection()
def modal(self, context, event): # def show_fcurves(obj): # mu.change_fcurves_colors(obj) # mu.view_all_in_graph_editor() if self.right_clicked: if len(bpy.context.selected_objects): selected_obj_name = bpy.context.selected_objects[0].name selected_obj_type = mu.check_obj_type(selected_obj_name) if selected_obj_type in [mu.OBJ_TYPE_CORTEX_LH, mu.OBJ_TYPE_CORTEX_RH, mu.OBJ_TYPE_ELECTRODE, mu.OBJ_TYPE_EEG]: obj = bpy.data.objects.get(selected_obj_name) if obj: mu.change_fcurves_colors(obj) if selected_obj_type in [mu.OBJ_TYPE_CORTEX_INFLATED_LH, mu.OBJ_TYPE_CORTEX_INFLATED_RH]: pial_obj_name = selected_obj_name[len('inflated_'):] pial_obj = bpy.data.objects.get(pial_obj_name) if not pial_obj is None: pial_obj.select = True mu.change_fcurves_colors(pial_obj) self.right_clicked = False if time.time() - self.press_time > 1: if event.type == 'RIGHTMOUSE': self.press_time = time.time() self.right_clicked = True if event.type == 'LEFTMOUSE': if _addon().fMRI_clusters_files_exist() and bpy.context.scene.plot_fmri_cluster_per_click: _addon().find_closest_cluster(only_within=True) if not _addon().render_in_queue() is None: rendering_data = mu.queue_get(_addon().render_in_queue()) if not rendering_data is None: try: rendering_data = rendering_data.decode(sys.getfilesystemencoding(), 'ignore') if '*** finish rendering! ***' in rendering_data.lower(): print('Finish rendering!') _addon().finish_rendering() except: print("Can't read the stdout from the rendering") return {'PASS_THROUGH'}
def show_electrodes_fcurves(): bpy.context.scene.selection_type = 'diff' _addon().select_all_electrodes() mu.change_fcurves_colors([bpy.data.objects['Deep_electrodes']])