コード例 #1
0
ファイル: data_panel.py プロジェクト: pelednoam/mmvt
def import_electrodes(input_file, electrodes_layer, bipolar='', electrode_size=None, parnet_name='Deep_electrodes'):
    if not electrode_size is None:
        bpy.context.scene.electrodes_radius = electrode_size
    if bipolar != '':
        bpy.context.scene.bipolar = bool(bipolar)
    mu.delete_hierarchy(parnet_name)
    f = np.load(input_file)

    electrode_size = bpy.context.scene.electrodes_radius
    layers_array = [False] * 20
    create_empty_if_doesnt_exists(parnet_name, _addon().BRAIN_EMPTY_LAYER, layers_array, parnet_name)

    layers_array = [False] * 20
    layers_array[electrodes_layer] = True

    for (x, y, z), name in zip(f['pos'], f['names']):
        elc_name = name.astype(str)
        if not bpy.data.objects.get(elc_name) is None:
            continue
        print('creating {}: {}'.format(elc_name, (x, y, z)))
        mu.create_sphere((x * 0.1, y * 0.1, z * 0.1), electrode_size, layers_array, elc_name)
        cur_obj = bpy.data.objects[elc_name]
        cur_obj.select = True
        cur_obj.parent = bpy.data.objects[parnet_name]
        mu.create_and_set_material(cur_obj)
コード例 #2
0
ファイル: data_panel.py プロジェクト: dorianps/mmvt
def import_electrodes(input_file,
                      electrodes_layer,
                      bipolar='',
                      electrode_size=None,
                      parnet_name='Deep_electrodes'):
    if not electrode_size is None:
        bpy.context.scene.electrodes_radius = electrode_size
    if bipolar != '':
        bpy.context.scene.bipolar = bool(bipolar)
    mu.delete_hierarchy(parnet_name)
    f = np.load(input_file)

    electrode_size = bpy.context.scene.electrodes_radius
    layers_array = [False] * 20
    create_empty_if_doesnt_exists(parnet_name,
                                  _addon().BRAIN_EMPTY_LAYER, layers_array,
                                  parnet_name)

    layers_array = [False] * 20
    layers_array[electrodes_layer] = True

    for (x, y, z), name in zip(f['pos'], f['names']):
        elc_name = name.astype(str)
        if not bpy.data.objects.get(elc_name) is None:
            continue
        print('creating {}: {}'.format(elc_name, (x, y, z)))
        mu.create_sphere((x * 0.1, y * 0.1, z * 0.1), electrode_size,
                         layers_array, elc_name)
        cur_obj = bpy.data.objects[elc_name]
        cur_obj.select = True
        cur_obj.parent = bpy.data.objects[parnet_name]
        mu.create_and_set_material(cur_obj)
コード例 #3
0
ファイル: data_panel.py プロジェクト: ofek-schechner/mmvt
def import_electrodes(input_file, bipolar='', electrode_size=None):
    if not electrode_size is None:
        bpy.context.scene.electrodes_radius = electrode_size
    if bipolar != '':
        bpy.context.scene.bipolar = bool(bipolar)
    mu.delete_hierarchy('Deep_electrodes')
    print('Adding deep electrodes')
    f = np.load(input_file)

    deep_electrodes_layer = 1
    electrode_size = bpy.context.scene.electrodes_radius
    layers_array = [False] * 20
    create_empty_if_doesnt_exists('Deep_electrodes', DataMakerPanel.addon.BRAIN_EMPTY_LAYER, layers_array, 'Deep_electrodes')

    # if bpy.data.objects.get("Deep_electrodes") is None:
    #     layers_array[BRAIN_EMPTY_LAYER] = True
    #     bpy.ops.object.empty_add(type='PLAIN_AXES', radius=1, view_align=False, location=(0, 0, 0), layers=layers_array)
    #     bpy.data.objects['Empty'].name = 'Deep_electrodes'

    layers_array = [False] * 20
    layers_array[deep_electrodes_layer] = True

    for (x, y, z), name in zip(f['pos'], f['names']):
        elc_name = name.astype(str)
        if not bpy.data.objects.get(elc_name) is None:
            continue
        print('creating {}: {}'.format(elc_name, (x, y, z)))
        mu.create_sphere((x * 0.1, y * 0.1, z * 0.1), electrode_size, layers_array, elc_name)
        cur_obj = bpy.data.objects[elc_name]
        cur_obj.select = True
        cur_obj.parent = bpy.data.objects['Deep_electrodes']
        # cur_obj.active_material = bpy.data.materials['Deep_electrode_mat']
        mu.create_and_set_material(cur_obj)
コード例 #4
0
ファイル: filter_panel.py プロジェクト: ofek-schechner/mmvt
def de_select_electrode(obj, call_create_and_set_material=True):
    obj.active_material.node_tree.nodes["Layer Weight"].inputs[0].default_value = 1
    # safety check, if something happened to the electrode's material
    if call_create_and_set_material:
        mu.create_and_set_material(obj)
    # Sholdn't change to color here. If user plot the electrodes, we don't want to change it back to white.
    if obj.name in FilteringMakerPanel.electrodes_colors:
        FilteringMakerPanel.addon.object_coloring(obj, FilteringMakerPanel.electrodes_colors[obj.name])
コード例 #5
0
ファイル: filter_panel.py プロジェクト: dorianps/mmvt
def de_select_electrode(obj, call_create_and_set_material=True):
    obj.active_material.node_tree.nodes["Layer Weight"].inputs[
        0].default_value = 1
    # safety check, if something happened to the electrode's material
    if call_create_and_set_material:
        mu.create_and_set_material(obj)
    # Sholdn't change to color here. If user plot the electrodes, we don't want to change it back to white.
    if obj.name in FilteringMakerPanel.electrodes_colors:
        _addon().object_coloring(
            obj, FilteringMakerPanel.electrodes_colors[obj.name])
        obj.active_material.diffuse_color = FilteringMakerPanel.electrodes_colors[
            obj.name][:3]
    else:
        obj.active_material.node_tree.nodes["RGB"].outputs[0].default_value = (
            1, 1, 1, 1)
        obj.active_material.diffuse_color = (1, 1, 1)
コード例 #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_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)

        node1_obj, node2_obj = [
            bpy.data.objects['{}_vertice'.format(d.labels[k])] for k in [i, j]
        ]
        mu.create_bezier_curve(node1_obj, node2_obj, layers_rods)
        # p1, p2 = d.locations[i, :] * 0.01, d.locations[j, :] * 0.01
        # mu.hook_curves(node1_obj, node2_obj, p1, p2)
        cur_obj = bpy.context.active_object
        cur_obj.name = conn_name
        cur_obj.parent = parent_obj

        # mu.create_material('{}_mat'.format(conn_name), con_color, 1)
        mu.create_and_set_material(cur_obj)
        # cur_mat = bpy.data.materials['{}_mat'.format(conn_name)]
        # cur_obj.active_material = cur_mat
        # 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)