def build_new_label_name(): closest_label_output = bpy.context.scene.closest_label_output if closest_label_output == '': new_label_name = 'Unknown' else: delim, pos, label, label_hemi = mu.get_hemi_delim_and_pos(closest_label_output) label = '{}-{}mm'.format(label, bpy.context.scene.new_label_r) new_label_name = mu.build_label_name(delim, pos, label, label_hemi) bpy.context.scene.new_label_name = new_label_name
def plot_labels(labels_names, colors, atlas, atlas_labels_rh=[], atlas_labels_lh=[], do_plot=True): if len(atlas_labels_rh) == 0 and len( atlas_labels_lh) == 0: # or atlas == bpy.context.scene.atlas: atlas_labels_rh = mu.read_labels_from_annots(atlas, hemi='rh') atlas_labels_lh = mu.read_labels_from_annots(atlas, hemi='lh') atlas_labels = atlas_labels_rh + atlas_labels_lh if len(atlas_labels) == 0: print("Couldn't find the atlas! ({})".format(atlas)) return annot_verts_ok = check_annot_verts(atlas_labels_lh, atlas_labels_rh, atlas) if not annot_verts_ok: return org_delim, org_pos, label, label_hemi = mu.get_hemi_delim_and_pos( atlas_labels[0].name) labels_names_fix = [] for label_name in labels_names: delim, pos, label, label_hemi = mu.get_hemi_delim_and_pos(label_name) label = mu.get_label_hemi_invariant_name(label_name) label_fix = mu.build_label_name(org_delim, org_pos, label, label_hemi) labels_names_fix.append(label_fix) labels = [l for l in atlas_labels if l.name in labels_names_fix] if len(labels) < len(labels_names): dump_fname = op.join(mu.get_user_fol(), 'logs', '{}_labels.txt'.format(atlas)) print("Can't find all the labels ({}) in the {} atlas!".format( labels_names, atlas)) print("Take a look here for the {} labels names: {}".format( atlas, dump_fname)) with open(dump_fname, 'w') as output_file: output_file.write( "Can't find all the labels ({}) in the {} atlas!\n".format( labels_names, atlas)) output_file.write( "Take a look here for the {} labels names:\n".format(atlas)) for label in atlas_labels: output_file.write('{}\n'.format(label.name)) import webbrowser webbrowser.open_new(dump_fname) return labels.sort(key=lambda x: labels_names_fix.index(x.name)) # todo: check if bpy.context.scene.color_rois_homogeneously for label, color in zip(labels, colors): print('color {}: {}'.format(label, color)) # plot_label(label, color) LabelsPanel.labels_plotted.append((label, color)) if do_plot: _plot_labels()