예제 #1
0
def create_keyframes(d, threshold, threshold_type, radius=.1, stat=STAT_DIFF, verts_color='pink'):
    layers_rods = [False] * 20
    rods_layer = _addon().CONNECTIONS_LAYER
    layers_rods[rods_layer] = True
    mu.delete_hierarchy(get_connections_parent_name())
    mu.create_empty_if_doesnt_exists(get_connections_parent_name(), _addon().BRAIN_EMPTY_LAYER, None, 'Functional maps')
    if d.con_values.ndim >= 2:
        windows_num = d.con_values.shape[1]
    else:
        windows_num = 1
    T = ConnectionsPanel.addon.get_max_time_steps()
    if T == 0:
        T = windows_num
    norm_fac = T / windows_num
    if d.con_values.ndim > 2:
        stat_data = calc_stat_data(d.con_values, stat)
    else:
        stat_data = d.con_values
    mask = calc_mask(stat_data, threshold, threshold_type, windows_num)
    indices = np.where(mask)[0]
    parent_obj = bpy.data.objects[get_connections_parent_name()]
    parent_obj.animation_data_clear()
    N = len(indices)
    print('{} connections are above the threshold'.format(N))
    create_vertices(d, mask, verts_color)
    create_conncection_per_condition(d, layers_rods, indices, mask, windows_num, norm_fac, T, radius)
    print('Create connections for the conditions {}'.format('difference' if stat == STAT_DIFF else 'mean'))
    create_keyframes_for_parent_obj(d, indices, mask, windows_num, norm_fac, T, stat)
    print('finish keyframing!')
예제 #2
0
파일: dti_panel.py 프로젝트: dorianps/mmvt
def init(addon):
    if not check_for_dti_files():
        unregister()
    else:
        register()
        DTIPanel.addon = addon
        mu.create_empty_if_doesnt_exists(PARENT_OBJ, addon.BRAIN_EMPTY_LAYER, None, 'Brain')
예제 #3
0
def show_electrodes_groups_leads_update(self, context):
    parent_name = 'leads'
    leads_obj = bpy.data.objects.get(parent_name, None)
    show_leads = bpy.context.scene.show_electrodes_groups_leads
    if show_leads and leads_obj is None:
        leads_obj = mu.create_empty_if_doesnt_exists(parent_name, _addon().BRAIN_EMPTY_LAYER, None)
    elif not show_leads and leads_obj is None:
        return

    if len(leads_obj.children) == 0:
        for group, electrodes in ElecsPanel.groups_electrodes.items():
            points = [get_elc_pos(e) for e in electrodes]
            # points_inside_cylinder, _, dists = mu.points_in_cylinder(
            #     get_elc_pos(electrodes[0]), get_elc_pos(electrodes[-1]), points, 0.1)
            # if len(points_inside_cylinder) == len(electrodes):
            if bpy.context.scene.electrodes_create_curved_leads:
                for ind, (p1, p2) in enumerate(zip(points[:-1], points[1:])):
                    create_lead(p1, p2, '{}_lead_{}'.format(group, ind))
            else:
                create_lead(get_elc_pos(electrodes[0]), get_elc_pos(electrodes[-1]), '{}_lead'.format(group))
            # group_new_pos = mu.move_electrodes_to_line(get_elc_pos(electrodes[0]), get_elc_pos(electrodes[-1]), points)
            # for elc_name, elc_new_pos in zip(electrodes, group_new_pos):
            #     bpy.data.objects[elc_name].location = elc_new_pos


    for group_lead_obj in leads_obj.children:
        group_lead_obj.hide = not show_leads
예제 #4
0
파일: dti_panel.py 프로젝트: dorianps/mmvt
def plot_pathway(self, context, layers_dti, pathway_name, pathway_type):
    if pathway_type == TRACULA:
        pkl_fname = op.join(SUBJECT_DTI_FOL, TRACULA, '{}{}.pkl'.format(pathway_name, TRACULA_POSTFIX))
        mu.create_empty_if_doesnt_exists(pathway_name, DTIPanel.addon.CONNECTIONS_LAYER, None, PARENT_OBJ)
        parent_obj = bpy.data.objects[pathway_name]
        tracks = mu.load(pkl_fname)
        N = len(tracks)
        now = time.time()
        for ind, track in enumerate(tracks[:1000]):
            mu.time_to_go(now, ind, N, 100)
            track = track * 0.1
            # pprint(track)
            cur_obj = mu.create_spline(track, layers_dti, bevel_depth=0.01)
            # cur_obj.scale = [0.1] * 3
            cur_obj.name = '{}_{}'.format(pathway_name, ind)
            cur_obj.parent = parent_obj
예제 #5
0
def create_lead(p1, p2, lead_name, radius=0.03):
    if bpy.data.objects.get(lead_name) is not None:
        return bpy.data.objects.get(lead_name)
    layers = [False] * 20
    lead_layer = _addon().ELECTRODES_LAYER
    layers[lead_layer] = True
    parent_name = 'leads'
    mu.create_empty_if_doesnt_exists(parent_name, _addon().BRAIN_EMPTY_LAYER, None, parent_name)

    mu.cylinder_between(p1, p2, radius, layers)
    color = tuple(np.concatenate((bpy.context.scene.electrodes_leads_color, [1])))
    mu.create_material('{}_mat'.format(lead_name), color, 1)
    cur_obj = bpy.context.active_object
    cur_obj.name = lead_name
    cur_obj.parent = bpy.data.objects[parent_name]
    bpy.data.objects[lead_name].select = False
    return bpy.data.objects[lead_name]
예제 #6
0
def create_new_electrode(elc_name):
    electrode_size = bpy.context.scene.electrodes_radius
    parent_name = _addon().electrodes_panel_parent
    mu.create_empty_if_doesnt_exists(parent_name, _addon().BRAIN_EMPTY_LAYER, root_fol=parent_name)
    layers_array = [False] * 20
    layers_array[_addon().ELECTRODES_LAYER] = True
    x, y, z = bpy.context.scene.cursor_location
    if not bpy.data.objects.get(elc_name) is None:
        elc_obj = bpy.data.objects[elc_name]
        elc_obj.location = [x, y, z]
    else:
        print('creating {}: {}'.format(elc_name, (x, y, z)))
        mu.create_sphere((x, y, z), electrode_size, layers_array, elc_name)
        cur_obj = bpy.data.objects[elc_name]
        cur_obj.select = True
        cur_obj.parent = bpy.data.objects[parent_name]
        mu.create_and_set_material(cur_obj)
    _addon().show_hide_electrodes(True)
예제 #7
0
def create_keyframes(d, threshold, threshold_type, radius=.1, stat=STAT_DIFF):
    layers_rods = [False] * 20
    rods_layer = CONNECTIONS_LAYER
    layers_rods[rods_layer] = True
    mu.delete_hierarchy(PARENT_OBJ)
    mu.create_empty_if_doesnt_exists(PARENT_OBJ, BRAIN_EMPTY_LAYER, None,
                                     'Functional maps')
    # cond_id = [i for i, cond in enumerate(d.conditions) if cond == condition][0]
    if d.con_colors.ndim == 3:
        windows_num = d.con_colors.shape[1]
    else:
        windows_num = 1
    T = ConnectionsPanel.addon.get_max_time_steps()
    if T == 0:
        T = windows_num
    norm_fac = T / windows_num
    # todo: Check if we really want to let the user create connection according to the first option
    # if bpy.context.scene.selection_type == 'conds':
    #     # Takes all the connections that at least one condition pass the threshold
    #     # Ex: np.array([True, False, False]) | np.array([False, True, False]) = array([ True,  True, False], dtype=bool)
    #     mask1 = np.max(d.con_values[:, :, 0], axis=1) > threshold
    #     mask2 = np.max(d.con_values[:, :, 1], axis=1) > threshold
    #     mask = mask1 | mask2
    # else:
    if d.con_values.ndim > 2:
        stat_data = calc_stat_data(d.con_values, stat)
    else:
        stat_data = d.con_values
    mask = calc_mask(stat_data, threshold, threshold_type, windows_num)
    indices = np.where(mask)[0]
    parent_obj = bpy.data.objects[PARENT_OBJ]
    parent_obj.animation_data_clear()
    N = len(indices)
    print('{} connections are above the threshold'.format(N))
    create_conncection_for_both_conditions(d, layers_rods, indices, mask,
                                           windows_num, norm_fac, T, radius)
    print('Create connections for the conditions {}'.format(
        'difference' if stat == STAT_DIFF else 'mean'))
    create_keyframes_for_parent_obj(d, indices, mask, windows_num, norm_fac, T,
                                    stat)
    print('finish keyframing!')
예제 #8
0
파일: dti_panel.py 프로젝트: keshava/mmvt
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
예제 #9
0
def create_keyframes(d, threshold, threshold_type, radius=.1, stat=STAT_DIFF, verts_color='pink'):
    layers_rods = [False] * 20
    rods_layer = _addon().CONNECTIONS_LAYER
    layers_rods[rods_layer] = True
    mu.delete_hierarchy(PARENT_OBJ)
    mu.create_empty_if_doesnt_exists(PARENT_OBJ, _addon().BRAIN_EMPTY_LAYER, None, 'Functional maps')
    # cond_id = [i for i, cond in enumerate(d.conditions) if cond == condition][0]
    if d.con_colors.ndim == 3:
        windows_num = d.con_colors.shape[1]
    else:
        windows_num = 1
    T = ConnectionsPanel.addon.get_max_time_steps()
    if T == 0:
        T = windows_num
    norm_fac = T / windows_num
    # todo: Check if we really want to let the user create connection according to the first option
    # if bpy.context.scene.selection_type == 'conds':
    #     # Takes all the connections that at least one condition pass the threshold
    #     # Ex: np.array([True, False, False]) | np.array([False, True, False]) = array([ True,  True, False], dtype=bool)
    #     mask1 = np.max(d.con_values[:, :, 0], axis=1) > threshold
    #     mask2 = np.max(d.con_values[:, :, 1], axis=1) > threshold
    #     mask = mask1 | mask2
    # else:
    if d.con_values.ndim > 2:
        stat_data = calc_stat_data(d.con_values, stat)
    else:
        stat_data = d.con_values
    mask = calc_mask(stat_data, threshold, threshold_type, windows_num)
    indices = np.where(mask)[0]
    parent_obj = bpy.data.objects[PARENT_OBJ]
    parent_obj.animation_data_clear()
    N = len(indices)
    print('{} connections are above the threshold'.format(N))
    create_conncection_for_both_conditions(d, layers_rods, indices, mask, windows_num, norm_fac, T, radius)
    create_vertices(d, mask, verts_color)
    print('Create connections for the conditions {}'.format('difference' if stat == STAT_DIFF else 'mean'))
    create_keyframes_for_parent_obj(d, indices, mask, windows_num, norm_fac, T, stat)
    print('finish keyframing!')
예제 #10
0
def create_vertices(d, mask, verts_color='pink'):
    layers = [False] * 20
    layers[_addon().CONNECTIONS_LAYER] = True
    vert_color = np.hstack((cu.name_to_rgb(verts_color), [0.]))
    parent_name = 'connections_vertices'
    parent_obj = mu.create_empty_if_doesnt_exists(parent_name, _addon().BRAIN_EMPTY_LAYER, None, get_connections_parent_name())
    for vertice in ConnectionsPanel.vertices:
    # for ind in range(len(d.names[mask])):
    # for indice in indices:
        p1 = d.locations[vertice, :] * 0.1
        vert_name = '{}_vertice'.format(d.labels[vertice])
        mu.create_ico_sphere(p1, layers, vert_name)
        mu.create_material('{}_mat'.format(vert_name), vert_color, 1)
        cur_obj = bpy.context.active_object
        cur_obj.name = vert_name
        cur_obj.parent = parent_obj
예제 #11
0
def create_vertices(d, mask, verts_color='pink'):
    indices = set()
    layers = [False] * 20
    layers[_addon().CONNECTIONS_LAYER] = True
    vert_color = np.hstack((cu.name_to_rgb(verts_color), [0.]))
    parent_name = 'connections_vertices'
    parent_obj = mu.create_empty_if_doesnt_exists(parent_name, _addon().BRAIN_EMPTY_LAYER, None, PARENT_OBJ)
    for (i, j) in d.con_indices[mask]:
        indices.add(i)
        indices.add(j)
    for indice in indices:
        p1 = d.locations[indice, :] * 0.1
        vert_name = 'connection_{}'.format(indice)
        mu.create_ico_sphere(p1, layers, vert_name)
        mu.create_material('{}_mat'.format(vert_name), vert_color, 1)
        cur_obj = bpy.context.active_object
        cur_obj.name = vert_name
        cur_obj.parent = parent_obj
예제 #12
0
def show_electrodes_groups_leads_update(self, context):
    parent_name = 'leads'
    leads_obj = bpy.data.objects.get(parent_name, None)
    show_leads = bpy.context.scene.show_electrodes_groups_leads
    if show_leads and leads_obj is None:
        leads_obj = mu.create_empty_if_doesnt_exists(
            parent_name,
            _addon().BRAIN_EMPTY_LAYER, None)
    if len(leads_obj.children) == 0:
        for group, electrodes in ElecsPanel.groups_electrodes.items():
            points = [get_elc_pos(e) for e in electrodes]
            points_inside_cylinder, _, dists = mu.points_in_cylinder(
                get_elc_pos(electrodes[0]), get_elc_pos(electrodes[-1]),
                points, 0.1)
            if len(points_inside_cylinder) == len(electrodes):
                create_lead(get_elc_pos(electrodes[0]),
                            get_elc_pos(electrodes[-1]),
                            '{}_lead'.format(group))
            else:
                for ind, (p1, p2) in enumerate(zip(points[:-1], points[1:])):
                    create_lead(p1, p2, '{}_lead_{}'.format(group, ind))

    for group_lead_obj in leads_obj.children:
        group_lead_obj.hide = not show_leads