Ejemplo n.º 1
0
def init(addon):
    try:
        trans_fname = op.join(mu.get_user_fol(), 'orig_trans.npz')
        volumes = glob.glob(
            op.join(mu.get_user_fol(), 'freeview', '*+aseg.npy'))
        luts = glob.glob(
            op.join(mu.get_user_fol(), 'freeview', '*ColorLUT.npz'))
        if op.isfile(trans_fname):
            WhereAmIPanel.subject_orig_trans = mu.Bag(np.load(trans_fname))
        for atlas_vol_fname, atlas_vol_lut_fname in zip(volumes, luts):
            atlas = mu.namebase(atlas_vol_fname)[:-len('+aseg')]
            WhereAmIPanel.vol_atlas[atlas] = np.load(atlas_vol_fname)
            WhereAmIPanel.vol_atlas_lut[atlas] = np.load(atlas_vol_lut_fname)
        subjects_dir = mu.get_link_dir(mu.get_links_dir(), 'subjects')
        annot_files = glob.glob(
            op.join(subjects_dir, mu.get_user(), 'label', 'rh.*.annot'))
        if len(annot_files) > 0:
            files_names = [mu.namebase(fname)[3:] for fname in annot_files]
            items = [(c, c, '', ind) for ind, c in enumerate(files_names)]
            bpy.types.Scene.subject_annot_files = bpy.props.EnumProperty(
                items=items)
            bpy.context.scene.subject_annot_files = files_names[0]
        else:
            bpy.types.Scene.subject_annot_files = bpy.props.EnumProperty(
                items=[])
            # bpy.context.scene.subject_annot_files = ''

        bpy.context.scene.closest_label_output = ''
        bpy.context.scene.new_label_r = 5

        mri_data_fname = op.join(mu.get_user_fol(), 'freeview',
                                 '{}_data.npz'.format('mri'))
        if op.isfile(mri_data_fname):
            WhereAmIPanel.mri_data = mu.Bag(np.load(mri_data_fname))
        gray_colormap_fname = op.join(mu.file_fol(), 'color_maps', 'gray.npy')
        if op.isfile(gray_colormap_fname):
            WhereAmIPanel.gray_colormap = np.load(gray_colormap_fname)

        WhereAmIPanel.addon = addon
        WhereAmIPanel.init = True
        WhereAmIPanel.run_slices_listener = False
        init_slices()
        if WhereAmIPanel.run_slices_listener:
            start_slicer_server()
        else:
            WhereAmIPanel.slicer_state = slicer.init('mri')
            create_slices('mri', bpy.context.scene.cursor_location)
        save_slices_cursor_pos()
        register()
    except:
        print("Can't init where-am-I panel!")
        print(traceback.format_exc())
Ejemplo n.º 2
0
def init(addon):
    try:
        t1_trans_fname = op.join(mu.get_user_fol(), 't1_trans.npz')
        if not op.isfile(t1_trans_fname):
            # backward compatibility
            t1_trans_fname = op.join(mu.get_user_fol(), 'orig_trans.npz')
        t2_trans_fname = op.join(mu.get_user_fol(), 't2_trans.npz')
        ct_trans_fname = op.join(mu.get_user_fol(), 'ct', 'ct_trans.npz')
        volumes = glob.glob(op.join(mu.get_user_fol(), 'freeview', '*+aseg.npy'))
        luts = glob.glob(op.join(mu.get_user_fol(), 'freeview', '*ColorLUT.npz'))
        if op.isfile(t1_trans_fname):
            WhereAmIPanel.subject_t1_trans = mu.Bag(np.load(t1_trans_fname))
        if op.isfile(t2_trans_fname):
            WhereAmIPanel.subject_t2_trans = mu.Bag(np.load(t2_trans_fname))
        if op.isfile(ct_trans_fname):
            WhereAmIPanel.subject_ct_trans = mu.Bag(np.load(ct_trans_fname))
        for atlas_vol_fname, atlas_vol_lut_fname in zip(volumes, luts):
            atlas = mu.namebase(atlas_vol_fname)[:-len('+aseg')]
            WhereAmIPanel.vol_atlas[atlas] = np.load(atlas_vol_fname)
            WhereAmIPanel.vol_atlas_lut[atlas] = np.load(atlas_vol_lut_fname)
        try:
            subjects_dir = mu.get_link_dir(mu.get_links_dir(), 'subjects')
            annot_files = [mu.namebase(fname)[3:] for fname in glob.glob(
                op.join(subjects_dir, mu.get_user(), 'label', 'rh.*.annot'))]
            annot_files += [mu.namebase(fname)[3:] for fname in glob.glob(
                op.join(mu.get_user_fol(), 'labels', 'rh.*.annot'))]
            WhereAmIPanel.annot_files = annot_files = list(set(annot_files))
            if len(annot_files) > 0:
                items = [(c, c, '', ind) for ind, c in enumerate(annot_files)]
                bpy.types.Scene.subject_annot_files = bpy.props.EnumProperty(
                    items=items, update=subject_annot_files_update, description='List of different atlases.\n\nCurrent atlas')
                ind = mu.index_in_list(bpy.context.scene.atlas, annot_files, 0)
                bpy.context.scene.subject_annot_files = annot_files[ind]
            else:
                bpy.types.Scene.subject_annot_files = bpy.props.EnumProperty(items=[])
                # bpy.context.scene.subject_annot_files = ''
        except:
            bpy.types.Scene.subject_annot_files = bpy.props.EnumProperty(items=[])
        bpy.context.scene.closest_label_output = ''
        bpy.context.scene.new_label_r = 5
        bpy.context.scene.find_closest_label_on_click = False
        bpy.context.scene.plot_closest_label_contour = False

        mri_data_fname = op.join(mu.get_user_fol(), 'freeview', 'mri_data.npz')
        if op.isfile(mri_data_fname):
            WhereAmIPanel.mri_data = mu.Bag(np.load(mri_data_fname))
        gray_colormap_fname = op.join(mu.file_fol(), 'color_maps', 'gray.npy')
        if op.isfile(gray_colormap_fname):
            WhereAmIPanel.gray_colormap = np.load(gray_colormap_fname)

        WhereAmIPanel.addon = addon
        WhereAmIPanel.init = True
        WhereAmIPanel.run_slices_listener = False
        init_slices()
        if WhereAmIPanel.run_slices_listener:
            start_slicer_server()
        else:
            WhereAmIPanel.slicer_state = mu.Bag({})
            WhereAmIPanel.slicer_state['mri'] = slicer.init(_addon(), 'mri')
            create_slices(None, bpy.context.scene.cursor_location)
        save_slices_cursor_pos()
        register()
    except:
        print("Can't init where-am-I panel!")
        print(traceback.format_exc())
Ejemplo n.º 3
0
def set_slicer_state(modality):
    if WhereAmIPanel.slicer_state is None or modality not in WhereAmIPanel.slicer_state:
        WhereAmIPanel.slicer_state[modality] = slicer.init(_addon(), modality)