def rotate_brain_via_lookup(elc_name, loc): cortical_probs_max, subcortical_probs_max = 0, 0 cortical_probs_rois = \ [(p, r) for p, r in zip(loc['cortical_probs'], loc['cortical_rois']) if 'white' not in r.lower()] subcortical_probs_rois = \ [(p, r) for p, r in zip(loc['subcortical_probs'], loc['subcortical_rois']) if 'white' not in r.lower()] if len(cortical_probs_rois) > 0: cortical_probs_ind = np.argmax(cortical_probs_rois, 0)[0] cortical_probs_max = cortical_probs_rois[cortical_probs_ind][0] if len(subcortical_probs_rois) > 0: subcortical_probs_ind = np.argmax(subcortical_probs_rois, 0)[0] subcortical_probs_max = subcortical_probs_rois[subcortical_probs_ind][0] if cortical_probs_max > subcortical_probs_max: max_roi = cortical_probs_rois[cortical_probs_ind][1] max_roi_is_cortical = True else: max_roi = subcortical_probs_rois[subcortical_probs_ind][1] max_roi_is_cortical = False if max_roi_is_cortical: atlas = bpy.context.scene.electrodes_labeling_files.split('_')[1] hemi = mu.get_obj_hemi(max_roi) annot_fname = mu.get_annot_fname(hemi, atlas) max_roi_vertices_indices = mu.read_label_vertices_from_annot(annot_fname, max_roi) if max_roi_vertices_indices is None: print('Can\'t find {} vertices in {}!'.format(max_roi, annot_fname)) return elc_pos = bpy.data.objects[elc_name].location mesh = 'inflated_{}'.format(hemi) vert_ind, vert_pos = _addon().vertex_data.find_closest_vertices( elc_pos, max_roi_vertices_indices, mesh, False) vert_pos *= 0.1 mu.rotate_view_to_vertice(vert_ind, mesh)
def plot_labels_probs(elc): _addon().init_activity_map_coloring('FMRI') if bpy.context.scene.electrodes_what_to_color == 'probs': if len(elc['cortical_rois']) > 0: hemi = mu.get_obj_hemi(elc['cortical_rois'][0]) if not hemi is None: labels_data = dict(data=elc['cortical_probs'], names=elc['cortical_rois']) if not _addon().colorbar_values_are_locked(): _addon().set_colorbar_title('Electrodes probabilities') _addon().set_colormap('YlOrRd') atlas = bpy.context.scene.electrodes_labeling_files.split( '_')[1:-6][0] _addon().labels_coloring_hemi(labels_data, ElecsPanel.faces_verts, hemi, 0, colors_min=0, colors_max=1, atlas=atlas) colors = mu.get_distinct_colors(len(elc['cortical_rois'])) if bpy.context.scene.electrodes_label_contours: _addon().color_contours(elc['cortical_rois'], specific_colors=colors) else: print("Can't get the rois hemi!") else: _addon().clear_cortex() _addon().clear_subcortical_regions() if len(elc['subcortical_rois']) > 0: cm = _addon().get_cm() colors = mu.calc_colors_from_cm(elc['subcortical_probs'], 0, 256, cm) for region, color in zip(elc['subcortical_rois'], colors): _addon().color_subcortical_region(region, color) elif bpy.context.scene.electrodes_what_to_color == 'verts': if len(elc['cortical_indices']) > 0: hemi = bpy.data.objects[elc['hemi']] if not hemi is None: _addon().init_activity_map_coloring('FMRI', subcorticals=True) vertices_num = np.max(elc['cortical_indices']) + 1 activity = np.ones((vertices_num, 4)) activity[:, 0] = 0 activity[elc['cortical_indices'], 0] = 1 activity[elc['cortical_indices'], 1:] = np.tile(cu.name_to_rgb('blue'), (len(elc['cortical_indices']), 1)) print('Plot {} vertices with blue'.format( len(elc['cortical_indices']))) _addon().activity_map_obj_coloring( hemi, activity, ElecsPanel.faces_verts[elc['hemi']], 0, True) else: print("Can't get the elec's hemi!") else: _addon().clear_cortex() print('No cortical vertices for {}'.format(elc['name']))
def plot_labels_probs(elc): _addon().init_activity_map_coloring('FMRI') if bpy.context.scene.electrodes_what_to_color == 'probs': if len(elc['cortical_rois']) > 0: hemi = mu.get_obj_hemi(elc['cortical_rois'][0]) if not hemi is None: labels_data = dict(data=elc['cortical_probs'], names=elc['cortical_rois']) _addon().set_colorbar_title('Electrodes probabilities') _addon().set_colormap('YlOrRd') _addon().labels_coloring_hemi(labels_data, ElecsPanel.faces_verts, hemi, 0, colors_min=0, colors_max=1) else: print("Can't get the rois hemi!") else: _addon().clear_cortex() _addon().clear_subcortical_regions() if len(elc['subcortical_rois']) > 0: for region, color in zip(elc['subcortical_rois'], elc['subcortical_colors'][:, :3]): _addon().color_subcortical_region(region, color) elif bpy.context.scene.electrodes_what_to_color == 'verts': if len(elc['cortical_indices']) > 0: hemi = bpy.data.objects[elc['hemi']] if not hemi is None: _addon().init_activity_map_coloring('FMRI', subcorticals=True) vertices_num = np.max(elc['cortical_indices']) + 1 activity = np.ones((vertices_num, 4)) activity[:, 0] = 0 activity[elc['cortical_indices'], 0] = 1 activity[elc['cortical_indices'], 1:] = np.tile(cu.name_to_rgb('blue'), (len(elc['cortical_indices']), 1)) print('Plot {} vertices with blue'.format( len(elc['cortical_indices']))) _addon().activity_map_obj_coloring( hemi, activity, ElecsPanel.faces_verts[elc['hemi']], 0, True) else: print("Can't get the elec's hemi!") else: _addon().clear_cortex() print('No cortical vertices for {}'.format(elc['name']))
def plot_labels_probs(elc): ElecsPanel.addon.init_activity_map_coloring('FMRI') if bpy.context.scene.electrodes_what_to_color == 'probs': if len(elc['cortical_rois']) > 0: hemi = mu.get_obj_hemi(elc['cortical_rois'][0]) if not hemi is None: # if no matplotlib should calculate the colors offline :( labels_data = dict(data=elc['cortical_probs'], colors=elc['cortical_colors'][:, :3], names=elc['cortical_rois']) ElecsPanel.addon.meg_labels_coloring_hemi( labels_data, ElecsPanel.faces_verts, hemi, 0) else: print("Can't get the rois hemi!") else: ElecsPanel.addon.clear_cortex() ElecsPanel.addon.clear_subcortical_regions() if len(elc['subcortical_rois']) > 0: for region, color in zip(elc['subcortical_rois'], elc['subcortical_colors'][:, :3]): ElecsPanel.addon.color_subcortical_region(region, color) elif bpy.context.scene.electrodes_what_to_color == 'verts': if len(elc['cortical_indices']) > 0: hemi = bpy.data.objects[elc['hemi']] if not hemi is None: ElecsPanel.addon.init_activity_map_coloring('FMRI', subcorticals=True) vertices_num = np.max(elc['cortical_indices']) + 1 activity = np.ones((vertices_num, 4)) activity[:, 0] = 0 activity[elc['cortical_indices'], 0] = 1 activity[elc['cortical_indices'], 1:] = np.tile(cu.name_to_rgb('blue'), (len(elc['cortical_indices']), 1)) print('Plot {} vertices with blue'.format( len(elc['cortical_indices']))) ElecsPanel.addon.activity_map_obj_coloring( hemi, activity, ElecsPanel.faces_verts[elc['hemi']], 0, True) else: print("Can't get the elec's hemi!") else: ElecsPanel.addon.clear_cortex() print('No cortical vertices for {}'.format(elc['name']))
def invoke(self, context, event=None): label_name = context.scene.labels_regex SearchMark.marked_objects_select = {} objects = mu.get_non_functional_objects() SearchPanel.marked_objects = [] for obj in objects: SearchFilter.marked_objects_select[obj.name] = obj.select obj.select = label_name in obj.name try: import fnmatch if fnmatch.fnmatch(obj.name, '*{}*'.format(label_name)): SearchPanel.marked_objects.append(obj.name) except: if label_name in obj.name: SearchPanel.marked_objects.append(obj.name) if len(SearchPanel.marked_objects) == 0: print('No objects found for "{}"'.format( context.scene.labels_regex)) return # todo: show rois only if the object is an ROI. Also, move the cursor selected_obj = bpy.data.objects[SearchPanel.marked_objects[0]] verts = np.array([vert.co for vert in selected_obj.data.vertices]) center = np.mean(verts, axis=0) if any([mu.obj_is_cortex(o) for o in SearchPanel.marked_objects]): selected_roi = [ o for o in SearchPanel.marked_objects if mu.obj_is_cortex(o) ][0] hemi = mu.get_obj_hemi(selected_roi) center = _addon().where_am_i.pos_to_current_inflation(center, hemis=[hemi]) else: center = mathutils.Vector(center) * mu.get_matrix_world() # if bpy.context.scene.search_plot_contour: # _addon().where_am_i.plot_closest_label_contour(selected_roi, hemi) # bpy.context.scene.cursor_location = tuple(center) _addon().where_am_i.set_cursor_location(center) # _addon().set_cursor_pos() # _addon().set_tkreg_ras(bpy.context.scene.cursor_location * 10, False) if bpy.context.scene.slices_rotate_view_on_click: mu.rotate_view_to_vertice() # if any([mu.obj_is_cortex(o.name) for o in SearchPanel.marked_objects]): # SearchPanel.addon.show_rois() return {"FINISHED"}
def plot_labels_probs(elc): ElecsPanel.addon.init_activity_map_coloring('FMRI') if bpy.context.scene.electrodes_what_to_color == 'probs': if len(elc['cortical_rois']) > 0: hemi = mu.get_obj_hemi(elc['cortical_rois'][0]) if not hemi is None: # if no matplotlib should calculate the colors offline :( labels_data = dict(data=elc['cortical_probs'], colors=elc['cortical_colors'][:, :3], names=elc['cortical_rois']) ElecsPanel.addon.meg_labels_coloring_hemi(labels_data, ElecsPanel.faces_verts, hemi, 0) else: print("Can't get the rois hemi!") else: ElecsPanel.addon.clear_cortex() ElecsPanel.addon.clear_subcortical_regions() if len(elc['subcortical_rois']) > 0: for region, color in zip(elc['subcortical_rois'], elc['subcortical_colors'][:, :3]): ElecsPanel.addon.color_subcortical_region(region, color) elif bpy.context.scene.electrodes_what_to_color == 'verts': if len(elc['cortical_indices']) > 0: hemi = bpy.data.objects[elc['hemi']] if not hemi is None: ElecsPanel.addon.init_activity_map_coloring('FMRI', subcorticals=True) vertices_num = np.max(elc['cortical_indices']) + 1 activity = np.ones((vertices_num, 4)) activity[:, 0] = 0 activity[elc['cortical_indices'], 0] = 1 activity[elc['cortical_indices'], 1:] = np.tile( cu.name_to_rgb('blue'), (len(elc['cortical_indices']), 1)) print('Plot {} vertices with blue'.format(len(elc['cortical_indices']))) ElecsPanel.addon.activity_map_obj_coloring(hemi, activity, ElecsPanel.faces_verts[elc['hemi']], 0, True) else: print("Can't get the elec's hemi!") else: ElecsPanel.addon.clear_cortex() print('No cortical vertices for {}'.format(elc['name']))