Exemple #1
0
def _clusters_update():
    MEGPanel.current_cluster = cluster = MEGPanel.clusters_lookup[
        bpy.context.scene.meg_clusters]
    # set_cluster_time_series(cluster)
    cluster_name = get_cluster_name(cluster)
    cluster_max_vert_co = mu.get_vert_co(cluster.max_vert, cluster.hemi)
    bpy.context.scene.cursor_location = cluster_max_vert_co
    _addon().set_cursor_pos()
    _addon().set_closest_vertex_and_mesh_to_cursor(
        cluster.max_vert, 'inflated_{}'.format(cluster.hemi))
    _addon().save_cursor_position()
    _addon().create_slices()
    if bpy.context.scene.plot_current_meg_cluster:
        _addon().color_contours([cluster_name], cluster.hemi,
                                MEGPanel.contours,
                                bpy.context.scene.cumulate_meg_cluster, False)
    bpy.data.objects[PARENT_OBJ_NAME].select = True
    # mu.view_all_in_graph_editor()
    fcurves = mu.get_fcurves(PARENT_OBJ_NAME)
    cluster_fcurve_name = get_cluster_fcurve_name(cluster)
    if bpy.context.scene.cumulate_meg_cluster:
        fcurve_ind = [mu.get_fcurve_name(f)
                      for f in fcurves].index(cluster_fcurve_name)
        fcurves[fcurve_ind].hide = False
    else:
        for fcurve in fcurves:
            fcurve_name = mu.get_fcurve_name(fcurve)
            fcurve.hide = fcurve_name != cluster_fcurve_name

    MEGPanel.prev_cluster = bpy.context.scene.meg_clusters
Exemple #2
0
def _clusters_update():
    if fMRIPanel.addon is None or not fMRIPanel.init:
        return
    clusters_labels_file = bpy.context.scene.fmri_clusters_labels_files
    # key = '{}_{}'.format(clusters_labels_file, bpy.context.scene.fmri_clusters_labels_parcs)
    key = clusters_labels_file
    fMRIPanel.cluster_labels = cluster = fMRIPanel.lookup[key][bpy.context.scene.fmri_clusters]
    cluster_centroid = np.mean(cluster['coordinates'], 0) / 10.0
    _addon().clear_closet_vertex_and_mesh_to_cursor()
    _addon().set_vertex_data(cluster['max'])
    if 'max_vert' in cluster:
        bpy.context.scene.cursor_location = mu.get_vert_co(cluster.max_vert, cluster.hemi)
        _addon().set_closest_vertex_and_mesh_to_cursor(cluster.max_vert, 'inflated_{}'.format(cluster.hemi))
    else:
        if _addon().is_pial():
            bpy.context.scene.cursor_location = cluster_centroid
            closest_mesh_name, vertex_ind, vertex_co = _addon().find_vertex_index_and_mesh_closest_to_cursor(
                cluster_centroid, mu.HEMIS, False)
            _addon().set_closest_vertex_and_mesh_to_cursor(vertex_ind, closest_mesh_name)
        else:
            closest_mesh_name, vertex_ind, vertex_co = _addon().find_vertex_index_and_mesh_closest_to_cursor(
                cluster_centroid, mu.HEMIS, False)
            inflated_mesh = 'inflated_{}'.format(closest_mesh_name)
            me = bpy.data.objects[inflated_mesh].to_mesh(bpy.context.scene, True, 'PREVIEW')
            bpy.context.scene.cursor_location = me.vertices[vertex_ind].co / 10.0
            bpy.data.meshes.remove(me)
            _addon().set_closest_vertex_and_mesh_to_cursor(vertex_ind, closest_mesh_name)

    tkreg_ras = _addon().calc_tkreg_ras_from_cursor()
    if tkreg_ras is not None:
        _addon().set_tkreg_ras(tkreg_ras, move_cursor=False)

    if bpy.context.scene.plot_current_cluster and not fMRIPanel.blobs_plotted:
        faces_verts = fMRIPanel.addon.get_faces_verts()
        if bpy.context.scene.fmri_what_to_plot == 'blob':
            plot_blob(cluster, faces_verts, True)
    if bpy.context.scene.plot_fmri_cluster_contours:
        inter_labels = [inter_label['name'] for inter_label in cluster['intersects']]
        atlas = fMRIPanel.clusters_labels[bpy.context.scene.fmri_clusters_labels_files].atlas
        _addon().color_contours(
            inter_labels, cluster.hemi, None, False, False,
            specific_colors=bpy.context.scene.fmri_cluster_contours_color, atlas=atlas)

    _addon().save_cursor_position()
    _addon().create_slices(pos=tkreg_ras)
    find_electrodes_in_cluster()
    if bpy.context.scene.fmri_rotate_view_to_vertice:
        mu.rotate_view_to_vertice()