Exemple #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)
def _save_all_views(views=None,
                    inflated_ratio_in_file_name=False,
                    rot_lh_axial=True,
                    render_images=False,
                    quality=0,
                    img_name_prefix='',
                    add_colorbar=False,
                    cb_ticks_num=None,
                    cb_ticks_font_size=None,
                    overwrite=True):
    def get_image_name(view_name):
        return '{}{}{}_{}'.format(
            '{}_'.format(hemi) if hemi != '' else '',
            '{}_'.format(img_name_prefix) if img_name_prefix != '' else '',
            surf_name, view_name)

    def should_save_image(img_name):
        return overwrite or not op.isfile(get_full_output_fname(img_name))

    def save_medial_views():
        if _addon().ROT_MEDIAL_LEFT in views:
            image_name = '{}_left_medial'.format(surf_name)
            if should_save_image(image_name):
                _addon().hide_hemi('rh')
                _addon().show_hemi('lh')
                _addon().rotate_view(_addon().ROT_SAGITTAL_RIGHT)
                image_fname = save_render_image(image_name, quality,
                                                render_images, add_colorbar,
                                                cb_ticks_num,
                                                cb_ticks_font_size)
                images_names.append(image_fname)
        if _addon().ROT_MEDIAL_RIGHT in views:
            image_name = '{}_right_medial'.format(surf_name)
            if should_save_image(image_name):
                _addon().show_hemi('rh')
                _addon().hide_hemi('lh')
                _addon().rotate_view(_addon().ROT_SAGITTAL_LEFT)
                image_fname = save_render_image(
                    '{}_right_medial'.format(surf_name), quality,
                    render_images, add_colorbar, cb_ticks_num,
                    cb_ticks_font_size)
                images_names.append(image_fname)
        _addon().show_hemi('rh')
        _addon().show_hemi('lh')

    if views is None:
        views = list(_addon().ANGLES_DICT.keys(
        ))  # + [_addon().ROT_MEDIAL_LEFT, _addon().ROT_MEDIAL_RIGHT]
    else:
        views = list(map(int, views))
    inf_r = bpy.context.scene.inflating
    if inflated_ratio_in_file_name:
        surf_name_dict = {-1: 'pial', 0: 'inflated', 1: 'flat'}
        surf_name = surf_name_dict.get(inf_r, '')
        if surf_name == '':
            if -1 < inf_r < 0:
                surf_name = '{:.1f}_inflated'.format(1 - inf_r)
            else:
                surf_name = '{:.1f}_flat'.format(inf_r)
    else:
        surf_name = 'pial' if inf_r == -1 else 'inflated' if -1 < inf_r <= 0 else 'flat'
    if mu.get_hemi_obj('rh').hide and not mu.get_hemi_obj('lh').hide:
        hemi = 'lh'
    elif not mu.get_hemi_obj('rh').hide and mu.get_hemi_obj('lh').hide:
        hemi = 'rh'
    elif not mu.get_hemi_obj('rh').hide and not mu.get_hemi_obj('lh').hide:
        hemi = ''
    else:
        mu.write_to_stderr('You need to show at least one hemi')
    org_view_ang = tuple(mu.get_view3d_region().view_rotation)
    images_names = []
    for view in views:
        view_name = _addon().view_name(view)
        img_name = get_image_name(view_name)
        if not should_save_image(img_name):
            continue
        _addon().rotate_view(view)
        if hemi == 'lh' and rot_lh_axial and view in (
                _addon().ROT_AXIAL_SUPERIOR, _addon().ROT_AXIAL_INFERIOR):
            _addon().rotate_brain(dz=180)
        mu.center_view()
        image_fname = save_render_image(img_name, quality, render_images,
                                        add_colorbar, cb_ticks_num,
                                        cb_ticks_font_size)
        print(image_fname, view, hemi)
        images_names.append(image_fname)
    # if not mu.get_hemi_obj('rh').hide and not mu.get_hemi_obj('lh').hide:
    if views is None:
        save_medial_views()
    # todo: doesn't work
    mu.rotate_view3d(org_view_ang)
    mu.center_view()
    return images_names
Exemple #3
0
 def invoke(self, context, event=None):
     mu.center_view()
     return {"FINISHED"}