Exemplo n.º 1
0
def _electrodes_update():
    if _addon() is None or not ElecsPanel.init:
        return
    # mu.print_traceback()
    ElecsPanel.prev_elect = prev_elect = 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_elect)
    # todo: fix electrodes_selection_coloring!
    electrodes_selection_coloring()
    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)
            if bpy.context.scene.electrode_rotate:
                rotate_brain_via_lookup(current_electrode, loc)
    else:
        pass
        # print('lookup table is None!')
    # mu.change_fcurves_colors(bpy.data.objects[current_electrode])
    # select_electrode(current_electrode)
    bpy.data.objects[current_electrode].select = True
    mu.change_selected_fcurves_colors(mu.OBJ_TYPE_ELECTRODE)
    _addon().show_electrodes()
Exemplo n.º 2
0
def _electrodes_update():
    if _addon() is None or not ElecsPanel.init:
        return
    # mu.print_traceback()
    prev_elect = 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_elect)
    # bpy.context.scene.objects.active = bpy.data.objects[current_electrode]
    selected_electrodes = [
        obj.name for obj in bpy.context.selected_objects
        if mu.check_obj_type(obj.name) == mu.OBJ_TYPE_ELECTRODE
    ]
    # Check if it's a new selection:
    # print(len(selected_electrodes), current_electrode, ElecsPanel.prev_electrodes)
    if len(selected_electrodes
           ) == 1 and current_electrode not in ElecsPanel.prev_electrodes:
        # Clear and init prev_electrodes
        unselect_prev_electrode(ElecsPanel.prev_electrodes)
        ElecsPanel.prev_electrodes = set([current_electrode])
    # Check if this is a new electrodes where the shift is pressed
    elif len(selected_electrodes
             ) > 1 and current_electrode not in ElecsPanel.prev_electrodes:
        # Add current electrode to prev_electrodes
        ElecsPanel.prev_electrodes.add(current_electrode)
    # Check if the user unselect one of the selected electrodes
    elif len(selected_electrodes
             ) > 1 and current_electrode in ElecsPanel.prev_electrodes:
        bpy.data.objects[current_electrode].select = False
        unselect_prev_electrode([current_electrode])
        ElecsPanel.prev_electrodes.remove(current_electrode)
    else:
        clear_electrodes_selection()

    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!')
    # mu.change_fcurves_colors(bpy.data.objects[current_electrode])
    mu.change_selected_fcurves_colors(mu.OBJ_TYPE_ELECTRODE)
Exemplo n.º 3
0
    def filter_rois(self, current_file_to_upload):
        print('filter_ROIs')
        source_files = [
            op.join(self.current_activity_path,
                    current_file_to_upload.format(hemi=hemi))
            for hemi in mu.HEMIS
        ]
        objects_indices, names, Filtering.filter_values = self.get_object_to_filter(
            source_files)
        Filtering.objects_indices, Filtering.filter_objects = objects_indices, names
        deselect_all_objects()

        filter_obj_names = [names[ind] for ind in objects_indices]
        if bpy.context.scene.selection_type == 'diff':
            brain_obj = bpy.data.objects['Brain']
            self.objs_colors = []
            for fcurve in brain_obj.animation_data.action.fcurves:
                con_name = mu.get_fcurve_name(fcurve)
                fcurve.hide = con_name not in filter_obj_names
                fcurve.select = not fcurve.hide
                if fcurve.select:
                    self.objs_colors.append(fcurve.color)
            brain_obj.select = True
            _addon().color_contours(filter_obj_names,
                                    specific_colors=self.objs_colors,
                                    move_cursor=False)
        else:
            for roi_name in filter_obj_names:
                bpy.data.objects[roi_name].select = True
            self.objs_colors = mu.change_selected_fcurves_colors(
                mu.OBJ_TYPES_ROIS)
            _addon().color_contours(filter_obj_names,
                                    specific_colors=self.objs_colors,
                                    move_cursor=False)
Exemplo n.º 4
0
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()