def create_conncection_for_both_conditions(d, layers_rods, indices, mask, windows_num, norm_fac, T, radius):
    N = len(indices)
    parent_obj = bpy.data.objects[PARENT_OBJ]
    print('Create connections for both conditions')
    now = time.time()
    for run, (ind, conn_name, (i, j)) in enumerate(zip(indices, d.con_names[mask], d.con_indices[mask])):
        mu.time_to_go(now, run, N, runs_num_to_print=10)
        if d.con_colors.ndim == 3:
            con_color = np.hstack((d.con_colors[ind, 0, :], [0.]))
        else:
            con_color = np.hstack((d.con_colors[ind, :], [0.]))
        p1, p2 = d.locations[i, :] * 0.1, d.locations[j, :] * 0.1
        mu.cylinder_between(p1, p2, radius, layers_rods)
        # mu.create_material('{}_mat'.format(conn_name), (0, 0, 1, 1), 1)
        mu.create_material('{}_mat'.format(conn_name), con_color, 1)
        cur_obj = bpy.context.active_object
        cur_obj.name = conn_name
        cur_obj.parent = parent_obj
        # cur_obj.animation_data_clear()
        if windows_num == 1:
            continue
        for cond_id, cond in enumerate(d.conditions):
            # insert_frame_keyframes(cur_obj, '{}-{}'.format(conn_name, cond), d.con_values[ind, -1, cond_id], T)
            for t in range(windows_num):
                extra_time_points = 0 if norm_fac ==1 else 2
                timepoint = t * norm_fac + extra_time_points
                mu.insert_keyframe_to_custom_prop(cur_obj, '{}-{}'.format(conn_name, cond),
                                                  d.con_values[ind, t, cond_id], timepoint)
        finalize_fcurves(cur_obj)
Beispiel #2
0
def create_conncection_for_both_conditions(d, layers_rods, indices, mask,
                                           windows_num, norm_fac, T, radius):
    N = len(indices)
    parent_obj = bpy.data.objects[PARENT_OBJ]
    print('Create connections for both conditions')
    now = time.time()
    for run, (ind, conn_name, (i, j)) in enumerate(
            zip(indices, d.con_names[mask], d.con_indices[mask])):
        mu.time_to_go(now, run, N, runs_num_to_print=10)
        if d.con_colors.ndim == 3:
            con_color = np.hstack((d.con_colors[ind, 0, :], [0.]))
        else:
            con_color = np.hstack((d.con_colors[ind, :], [0.]))
        p1, p2 = d.locations[i, :] * 0.1, d.locations[j, :] * 0.1
        mu.cylinder_between(p1, p2, radius, layers_rods)
        # mu.create_material('{}_mat'.format(conn_name), (0, 0, 1, 1), 1)
        mu.create_material('{}_mat'.format(conn_name), con_color, 1)
        cur_obj = bpy.context.active_object
        cur_obj.name = conn_name
        cur_obj.parent = parent_obj
        # cur_obj.animation_data_clear()
        if windows_num == 1:
            continue
        for cond_id, cond in enumerate(d.conditions):
            # insert_frame_keyframes(cur_obj, '{}-{}'.format(conn_name, cond), d.con_values[ind, -1, cond_id], T)
            for t in range(windows_num):
                extra_time_points = 0 if norm_fac == 1 else 2
                timepoint = t * norm_fac + extra_time_points
                mu.insert_keyframe_to_custom_prop(
                    cur_obj, '{}-{}'.format(conn_name, cond),
                    d.con_values[ind, t, cond_id], timepoint)
        finalize_fcurves(cur_obj)
Beispiel #3
0
def create_conncection_per_condition(d, layers_rods, indices, mask, windows_num, norm_fac, T, radius):
    N = len(indices)
    parent_obj = bpy.data.objects[get_connections_parent_name()]
    print('Create connections for both conditions')
    con_color = (1, 1, 1, 1)
    now = time.time()
    for run, (ind, conn_name, (i, j)) in enumerate(zip(indices, d.con_names[mask], d.con_indices[mask])):
        mu.time_to_go(now, run, N, runs_num_to_print=10)
        p1, p2 = d.locations[i, :] * 0.1, d.locations[j, :] * 0.1
        mu.cylinder_between(p1, p2, radius, layers_rods)
        mu.create_material('{}_mat'.format(conn_name), con_color, 1)
        cur_obj = bpy.context.active_object
        cur_obj.name = conn_name
        cur_obj.parent = parent_obj
        # cur_obj.animation_data_clear()
        if windows_num == 1:
            continue
        for cond_id, cond in enumerate(d.conditions):
            # insert_frame_keyframes(cur_obj, '{}-{}'.format(conn_name, cond), d.con_values[ind, -1, cond_id], T)
            for t in range(windows_num):
                extra_time_points = 0 if norm_fac == 1 else 2
                timepoint = t * norm_fac + extra_time_points
                mu.insert_keyframe_to_custom_prop(cur_obj, '{}-{}'.format(conn_name, cond),
                                                  d.con_values[ind, t, cond_id], timepoint)
            fcurve = cur_obj.animation_data.action.fcurves[cond_id]
            fcurve.keyframe_points[0].co[1] = 0
            fcurve.keyframe_points[-1].co[1] = 0
        finalize_fcurves(cur_obj)
    mu.change_fcurves_colors(parent_obj.children)
Beispiel #4
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]