def pos_to_current_inflation(pos, hemis=mu.HEMIS, subject_tkreg_ras=False): if not subject_tkreg_ras: pos = mathutils.Vector(pos) * mu.get_matrix_world() closest_mesh_name, vertex_ind, vertex_co = _addon().find_closest_vertex_index_and_mesh(pos, hemis) obj = bpy.data.objects['inflated_{}'.format(closest_mesh_name)] me = obj.to_mesh(bpy.context.scene, True, 'PREVIEW') try: new_pos = me.vertices[vertex_ind].co * mu.get_matrix_world() # Bug in windows, Blender crashses here # todo: Figure out why... if not mu.IS_WINDOWS: bpy.data.meshes.remove(me) return new_pos except: print('pos_to_current_inflation: Error! ({})'.format(pos)) return np.array([0, 0, 0])
def mni305_ras_to_subject_tkreg_ras(mni305_ras): matrix_world = mu.get_matrix_world() if mu.get_user() == 'fsaverage': ras_tkr = mathutils.Vector(mni305_ras) * matrix_world else: vox = mu.apply_trans(np.linalg.inv(t1_trans().vox2ras), mni305_ras) ras_tkr = mathutils.Vector(mu.apply_trans(np.linalg.inv(t1_trans().ras_tkr2vox), vox)) * matrix_world return ras_tkr
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_tracks(): tracks_name = bpy.context.scene.dti_tracks tracks_fname = op.join(SUBJECT_DTI_FOL, '{}_tracks.npy'.format(tracks_name)) tracks_header = op.join(SUBJECT_DTI_FOL, '{}_header.pkl'.format(tracks_name)) world_matrix = mu.get_matrix_world() tracks = np.load(tracks_fname) * 0.1 header = mu.load(tracks_header) layers_dti = [False] * 20 dti_layer = DTIPanel.addon.CONNECTIONS_LAYER layers_dti[dti_layer] = True mu.create_empty_if_doesnt_exists(tracks_name, DTIPanel.addon.CONNECTIONS_LAYER, None, PARENT_OBJ) parent_obj = bpy.data.objects[tracks_name] # N = len(tracks) # now = time.time() # for ind, track in enumerate(tracks): # mu.time_to_go(now, ind, N, 100) cur_obj = mu.create_spline(tracks, layers_dti, bevel_depth=0.01) cur_obj.name = tracks_name cur_obj.parent = parent_obj