Exemple #1
0
def find_closest_label(atlas=None, plot_contour=True):
    subjects_dir = mu.get_link_dir(mu.get_links_dir(), 'subjects')
    if bpy.context.scene.cursor_is_snapped:
        vertex_ind, hemi = _addon().get_closest_vertex_and_mesh_to_cursor()
    else:
        closest_mesh_name, vertex_ind, _ = \
            _addon().find_closest_vertex_index_and_mesh(use_shape_keys=True)
        hemi = closest_mesh_name[len('infalted_'):] if _addon().is_inflated() else closest_mesh_name
    if vertex_ind == -1:
        print("find_closest_label: Can't find the closest vertex")
        return
    hemi = 'rh' if 'rh' in hemi else 'lh'
    if atlas is None:
        atlas = bpy.context.scene.subject_annot_files
    annot_fname = op.join(subjects_dir, mu.get_user(), 'label', '{}.{}.annot'.format(hemi, atlas))
    if not op.isfile(annot_fname):
        annot_fname = op.join(mu.get_user_fol(), 'labels', '{}.{}.annot'.format(hemi, atlas))
    if op.isfile(annot_fname):
        labels = mu.read_labels_from_annot(annot_fname)
        vert_labels = [l for l in labels if vertex_ind in l.vertices]
        if len(vert_labels) > 0:
            label = vert_labels[0]
            bpy.context.scene.closest_label_output = label.name
            if plot_contour:
                plot_closest_label_contour(label, hemi)
        return label.name
    else:
        print("Can't find the annotation file for atlas {}!".format(atlas))
Exemple #2
0
def find_closest_label():
    subjects_dir = mu.get_link_dir(mu.get_links_dir(), 'subjects')
    closest_mesh_name, vertex_ind, vertex_co, _ = \
        _addon().find_vertex_index_and_mesh_closest_to_cursor(use_shape_keys=True)
    hemi = closest_mesh_name[len('infalted_'):] if _addon().is_inflated(
    ) else closest_mesh_name
    annot_fname = op.join(
        subjects_dir, mu.get_user(), 'label',
        '{}.{}.annot'.format(hemi, bpy.context.scene.subject_annot_files))
    labels = mu.read_labels_from_annot(annot_fname)
    vert_labels = [l for l in labels if vertex_ind in l.vertices]
    if len(vert_labels) > 0:
        label = vert_labels[0]
        bpy.context.scene.closest_label_output = label.name
        return label.name, hemi
    else:
        return 'unknown', hemi