Пример #1
0
def load_all_panels(addon_prefs=None, first_time=False):
    mmvt = sys.modules[__name__]
    # check_empty_subject_version()
    # fix_cortex_labels_material()
    for panel in get_panels(first_time):
        if panel is freeview_panel:
            panel.init(mmvt, addon_prefs)
        else:
            now = time.time()
            panel.init(mmvt)
            print('{} took {:.5f}s to initialize'.format(
                panel.__name__,
                time.time() - now))
    if bpy.data.objects.get('rh'):
        split_view(0)
        split_view(0)
        fix_scale()
    show_activity()
    show_pial()
    # view_all()
    # show_electrodes(False)
    # show_hide_connections(False)
    # show_activity(False)
    mmvt_utils.select_layer(BRAIN_EMPTY_LAYER, False)
    mmvt_utils.unfilter_graph_editor()
    lock_colorbar_values(False)
    for hemi in ['lh', 'rh']:
        if bpy.data.objects.get(hemi):
            bpy.data.objects[hemi].hide = True
            bpy.data.objects[hemi].hide_render = True
    set_colorbar_defaults()
    mmvt_utils.center_view()
    mmvt_utils.select_time_range(0, bpy.context.scene.maximal_time_steps)
Пример #2
0
 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"}
Пример #3
0
def select_all_rois():
    mu.unfilter_graph_editor()
    fmri_parent = bpy.data.objects.get('fMRI')
    if mu.count_fcurves(bpy.data.objects['Brain']) > 0:
        bpy.context.scene.filter_curves_type = 'MEG'
        select_brain_objects('Brain', bpy.data.objects['Cortex-lh'].children + bpy.data.objects['Cortex-rh'].children)
    elif not fmri_parent is None:
        bpy.context.scene.filter_curves_type = 'fMRI'
        select_brain_objects('fMRI')
Пример #4
0
 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"}
Пример #5
0
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)
Пример #6
0
 def invoke(self, context, event=None):
     clear_filtering()
     type_of_filter = bpy.context.scene.filter_curves_type
     if type_of_filter == 'MEG':
         _addon().select_all_rois()
         _addon().clear_contours()
         # _addon().clear_cortex()
     elif type_of_filter == 'MEG_sensors':
         _addon().select_all_meg_sensors()
     elif type_of_filter == 'Electrodes':
         _addon().select_all_electrodes()
     elif type_of_filter == 'EEG':
         _addon().select_all_eeg_sensors()
     bpy.data.scenes['Scene'].frame_preview_end = _addon().get_max_time_steps()
     bpy.data.scenes['Scene'].frame_preview_start = 1
     bpy.types.Scene.closest_curve_str = ''
     bpy.types.Scene.filter_is_on = False
     mu.unfilter_graph_editor()
     return {"FINISHED"}
Пример #7
0
    def modal(self, context, event):
        if self.left_clicked:
            self.left_clicked = False
            active_image, pos = click_inside_images_view(event)
            if active_image is not None:
                xyz = _addon().slices_were_clicked(active_image, pos)
                bpy.context.scene.cursor_location = tuple(xyz)
                set_cursor_pos()
                if bpy.context.scene.cursor_is_snapped:  # and is_view_3d():
                    _addon().set_tkreg_ras(
                        bpy.context.scene.cursor_location * 10, False)
                    snap_cursor(True)
                    if bpy.context.scene.slices_rotate_view_on_click:
                        mu.rotate_view_to_vertice()
                # if bpy.context.scene.slices_zoom > 1:
                #     ohad(pos/bpy.context.scene.slices_zoom)
                return {'PASS_THROUGH'}
            if not click_inside_3d_view(event):
                return {'PASS_THROUGH'}
            if _addon().meg.change_cursor_on_selection():
                cluster = _addon().select_meg_cluster(
                    event, context, bpy.context.scene.cursor_location)
                if cluster is not None:
                    return {'PASS_THROUGH'}
            cursor_moved = np.linalg.norm(
                SelectionListener.cursor_pos -
                bpy.context.scene.cursor_location) > 1e-3
            if cursor_moved and bpy.data.objects.get('inner_skull',
                                                     None) is not None:
                _addon().find_point_thickness()
                return {'PASS_THROUGH'}
            if bpy.context.scene.cursor_is_snapped:  # and is_view_3d():
                snap_cursor(True)
            if _addon().fMRI_clusters_files_exist(
            ) and bpy.context.scene.plot_fmri_cluster_per_click:
                _addon().find_closest_cluster(only_within=True)

            tkreg_ras = _addon().calc_tkreg_ras_from_cursor()
            if tkreg_ras is not None:
                _addon().set_tkreg_ras(tkreg_ras, move_cursor=False)
            # if _addon().is_pial():
            #     tkreg_ras = bpy.context.scene.cursor_location * 10
            #     _addon().set_tkreg_ras(tkreg_ras)
            # elif bpy.context.scene.cursor_is_snapped:
            #     tkreg_ras = _addon().calc_tkreg_ras_from_snapped_cursor()
            #     _addon().set_tkreg_ras(tkreg_ras)

            if cursor_moved:
                set_cursor_pos()
                # print('cursor position was changed by the user!')
                _addon().create_slices(pos=tkreg_ras)
                _addon().freeview.save_cursor_position()
                clear_slice()
            if bpy.context.scene.find_closest_label_on_click:  # coloring_panel.WIC_CONTOURS in _addon().what_is_colored():
                _addon().find_closest_label(
                    plot_contour=bpy.context.scene.plot_closest_label_contour)

        if self.right_clicked:
            self.right_clicked = False
            if not click_inside_3d_view(event):
                return {'PASS_THROUGH'}
            # print(bpy.context.selected_objects)
            # cluster = _addon().select_meg_cluster(event, context)
            # if cluster is not None:
            #     return {'PASS_THROUGH'}
            if len(bpy.context.selected_objects):
                mu.unfilter_graph_editor()
                if bpy.context.scene.fit_graph_on_selection:
                    mu.view_all_in_graph_editor()
                selected_obj = bpy.context.active_object  # bpy.context.selected_objects[-1]
                selected_obj_name = selected_obj.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
                ]:
                    _addon().select_roi(selected_obj_name)
                elif 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
                        _addon().select_roi(pial_obj_name)
                        # mu.change_selected_fcurves_colors(pial_obj)
                        # mu.change_selected_fcurves_colors()
                elif selected_obj_type == mu.OBJ_TYPE_CON:
                    _addon().select_connection(selected_obj_name)
                elif selected_obj_type == mu.OBJ_TYPE_CON_VERTICE:
                    _addon().vertices_selected(selected_obj_name)
                elif selected_obj_type == mu.OBJ_TYPE_ELECTRODE:
                    bpy.context.scene.cursor_is_snapped = False
                    _addon().electode_was_manually_selected(selected_obj_name)
                    try:
                        _addon().dell.dell_ct_electrode_was_selected(
                            selected_obj_name)
                    except:
                        pass
                if bpy.context.scene.find_curves_sep_auto:
                    _addon().calc_best_curves_sep()
                elif bpy.context.scene.curves_sep > 0:
                    _addon().curves_sep_update()
            else:
                _addon().clear_electrodes_selection()
                #todo: should call to _addon().clear_rois_selection()
                # if is_activity():
                #     bpy.context.scene.cursor_location = mouse_coo_to_3d_loc(event, context)
                #     snap_cursor(True)
                #     _addon().find_closest_label()

        if time.time() - self.press_time > 1 and event.value == 'PRESS':
            if event.type == 'RIGHTMOUSE':
                self.press_time = time.time()
                self.right_clicked = True
            if event.type == 'LEFTMOUSE':
                self.press_time = time.time()
                self.left_clicked = True

        if time.time() - self.press_time > 0.1:
            if event.type == 'TIMER':
                if bpy.context.scene.rotate_brain:
                    if _addon().render.is_camera_view():
                        _addon().render.camera_mode('ORTHO')
                        _addon().show_hide.rotate_brain()
                        _addon().render.camera_mode('CAMERA')
                    else:
                        _addon().show_hide.rotate_brain()

        if _addon() and _addon().render_in_queue():
            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'}
Пример #8
0
def select_all_connections():
    mu.unfilter_graph_editor()
    connection_parent_name = _addon().get_connections_parent_name()
    select_brain_objects(connection_parent_name)
Пример #9
0
def select_all_eeg_sensors():
    mu.unfilter_graph_editor()
    bpy.context.scene.filter_curves_type = 'EEG'
    select_brain_objects('EEG_sensors')
Пример #10
0
def select_only_subcorticals():
    mu.unfilter_graph_editor()
    bpy.context.scene.filter_curves_type = 'MEG'
    select_brain_objects('Subcortical_structures')
Пример #11
0
    def modal(self, context, event):
        # def show_fcurves(obj):
        #     mu.change_fcurves_colors(obj)
        # mu.view_all_in_graph_editor()
        if self.left_clicked:
            self.left_clicked = False
            if bpy.context.scene.cursor_is_snapped:
                snap_cursor(True)
            if _addon().fMRI_clusters_files_exist(
            ) and bpy.context.scene.plot_fmri_cluster_per_click:
                _addon().find_closest_cluster(only_within=True)
            if _addon().is_pial():
                _addon().set_tkreg_ras_coo(bpy.context.scene.cursor_location *
                                           10)
            if self.cursor_pos != tuple(bpy.context.scene.cursor_location):
                self.cursor_pos = tuple(bpy.context.scene.cursor_location)
                _addon().create_slices()
                _addon().save_cursor_position()
                if bpy.context.scene.is_sliced_ind > -1:
                    tmp_new = bpy.context.scene.cursor_location[
                        bpy.context.scene.is_sliced_ind]
                    tmp_old = bpy.context.scene.last_cursor_location[
                        bpy.context.scene.is_sliced_ind]
                    if abs(tmp_new - tmp_old) > 0.005:
                        _addon().clear_slice()
                if bpy.data.objects.get('inner_skull', None) is not None:
                    _addon().find_point_thickness()
            _addon().slices_were_clicked()

        if self.right_clicked:
            self.right_clicked = False
            # print(bpy.context.selected_objects)
            if len(bpy.context.selected_objects):
                mu.unfilter_graph_editor()
                if bpy.context.scene.fit_graph_on_selection:
                    mu.view_all_in_graph_editor()
                selected_obj = bpy.context.active_object  # bpy.context.selected_objects[-1]
                selected_obj_name = selected_obj.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
                ]:
                    _addon().select_roi(selected_obj_name)
                elif 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
                        _addon().select_roi(pial_obj_name)
                        # mu.change_selected_fcurves_colors(pial_obj)
                        # mu.change_selected_fcurves_colors()
                elif selected_obj_type == mu.OBJ_TYPE_CON:
                    _addon().select_connection(selected_obj_name)
                elif selected_obj_type == mu.OBJ_TYPE_CON_VERTICE:
                    _addon().vertices_selected(selected_obj_name)
                elif selected_obj_type == mu.OBJ_TYPE_ELECTRODE:
                    _addon().electode_was_manually_selected(selected_obj_name)
                if bpy.context.scene.find_curves_sep_auto:
                    _addon().calc_best_curves_sep()
                elif bpy.context.scene.curves_sep > 0:
                    _addon().curves_sep_update()
            else:
                _addon().clear_electrodes_selection()
        if time.time() - self.press_time > 1:
            if event.type == 'RIGHTMOUSE':
                self.press_time = time.time()
                self.right_clicked = True
            if event.type == 'LEFTMOUSE':
                self.press_time = time.time()
                self.left_clicked = True

        if time.time() - self.press_time > 0.1:
            if event.type == 'TIMER':
                if bpy.context.scene.rotate_brain:
                    _addon().rotate_brain()

        if _addon() and _addon().render_in_queue():
            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'}