Ejemplo n.º 1
0
def test_filter_two_points(full_cell_mesh, full_cell_soma_pt, tmp_path):

    pt_down = full_cell_soma_pt + np.array([0, 50000, 0])
    is_large = mesh_filters.filter_largest_component(full_cell_mesh)
    full_cell_mesh = full_cell_mesh.apply_mask(is_large)
    on_ais = mesh_filters.filter_two_point_distance(
        full_cell_mesh, [full_cell_soma_pt, pt_down], 2000)

    ais_mesh = full_cell_mesh.apply_mask(on_ais)
    ais_actor = trimesh_vtk.mesh_actor(ais_mesh)

    fname = 'full_cell_ais.png'
    filepath = os.path.join(tmp_path, fname)

    trimesh_vtk.render_actors([ais_actor],
                              back_color=(1, 1, 1),
                              do_save=True,
                              filename=filepath,
                              scale=1)
    compare_img_to_test_file(filepath)

    pts_end = np.array([full_cell_soma_pt, pt_down])
    ais_sloppy = mesh_filters.filter_close_to_line(full_cell_mesh, pts_end,
                                                   4000)
    assert (np.sum(ais_sloppy) == 12961)
def eval_actor_image(actors,
                     fname,
                     tmp_path,
                     camera=None,
                     scale=2,
                     make_image=False):
    filepath = os.path.join(tmp_path, fname)

    if make_image:
        fpath = fname
    else:
        fpath = filepath
    trimesh_vtk.render_actors(actors,
                              do_save=True,
                              scale=scale,
                              camera=camera,
                              filename=fpath,
                              back_color=(1, 1, 1))
    if make_image:
        return True
    else:
        return compare_img_to_test_file(filepath)
def viz_3d_network(positions, edgelist):
    """
    Makes an interactive, 3d visualization of a spatial network.

    Parameters
    ----------
    positions: n_nodes x 3
        The 3d coordinates of each node in the network.

    edgelist: n_edges x 2
        List of the edges. If edges are labeled by node
        names (as opposed to node indexes) then positions
        must be a pd.DataFrame indexed by the node names.
    """

    # if nodes are named then convert node names to indexes
    if isinstance(positions, pd.DataFrame) and \
            isinstance(edgelist, pd.DataFrame):

        # convert edges to node index format i.e. (idx_0, idx_9) -> (0, 9)
        rootid2index = {idx: i for i, idx in enumerate(positions.index)}
        to_idxer = np.vectorize(lambda x: rootid2index[x])
        edgelist = to_idxer(edgelist)

    positions = np.array(positions)
    edgelist = np.array(edgelist)

    sk = skeleton.Skeleton(positions, edgelist)
    edge_actor = trimesh_vtk.skeleton_actor(sk,
                                            color=(0, 0, 0),
                                            opacity=.7,
                                            line_width=1)

    vert_actor = trimesh_vtk.point_cloud_actor(positions,
                                               size=3000,
                                               color=(1, 0, 0))
    trimesh_vtk.render_actors([edge_actor, vert_actor])
Ejemplo n.º 4
0
print(compare)
numTrue = 0
for i in compare:
    if i == True:
        numTrue += 1
if numTrue > len(compare) / 2:
    print("one head")
else:
    print("two heads")

#print(synapse1_loc)
#print(synapse2_loc)
syn1loc_array = np.array(synapse1_loc)
syn2loc_array = np.array(synapse2_loc)
squared_dist = np.sum((syn1loc_array - syn2loc_array)**2, axis=0)
syn_dist = np.sqrt(squared_dist)
print(syn_dist)

# Visualize the meshes, synapses, skeletons, and lines
renderer1 = trimesh_vtk.render_actors(actors=[
    spinemesh1_actor, spinemesh2_actor, synapse1_actor, synapse2_actor,
    skeleton1_actor, skeleton2_actor, end_actor1, end_actor2, line1, line2
],
                                      do_save=False)

# Visualize the meshes, synapses, and lines (no skeletons)
renderer2 = trimesh_vtk.render_actors(actors=[
    spinemesh1_actor, spinemesh2_actor, synapse1_actor, synapse2_actor, line1,
    line2
],
                                      do_save=False)
Ejemplo n.º 5
0
#from PyQt5.QtWidgets import QShortcut ,  QApplication, QWidget, QPushButton, QVBoxLayout, QLabel, QLineEdit, QGridLayout, QMessageBox
#from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
import csv
import json
import os
import pickle
import pandas as pd
import numpy as np
#import moviepy
import trimesh
import meshparty
from meshparty import trimesh_io, trimesh_vtk

# Create a set of 120 png images vizualizing the full rotation of each mesh
# Change mesh filename manually
spinemesh1 = trimesh.exchange.load.load_mesh(r'data\PSS_meshes\27.off')
spinemesh1_actor = trimesh_vtk.mesh_actor(spinemesh1,
                                          color=(0, 1, 0),
                                          opacity=0.6)
locmesh1 = trimesh.exchange.load.load_mesh(r'data\local_meshes\27.off')
locmesh1_actor = trimesh_vtk.mesh_actor(locmesh1, color=(1, 1, 1), opacity=0.1)
renderer1 = trimesh_vtk.render_actors(
    actors=[spinemesh1_actor, locmesh1_actor], do_save=False)

# When vtk window appears with PSS and local mesh actors, manually rotate meshes to desired orientation
cam = renderer1.GetActiveCamera()
trimesh_vtk.render_actors_360(actors=[spinemesh1_actor, locmesh1_actor],
                              camera_start=cam,
                              directory='pss_images\pt27',
                              nframes=120,
                              do_save=True)
Ejemplo n.º 6
0
def render_actors_360(actors,
                      directory,
                      nframes,
                      camera_start=None,
                      start_frame=0,
                      video_width=1280,
                      video_height=720,
                      scale=4,
                      do_save=True):
    """
    Function to create a series of png frames which rotates around
    the Azimuth angle of a starting camera

    This will save images as a series of png images in the directory
    specified.

    The movie will start at time 0 and will go to frame nframes,
    completing a 360 degree rotation in that many frames.
    Keep in mind that typical movies are encoded at 15-30
    frames per second and nframes is units of frames.
    
    Parameters
    ----------
    actors :  list of vtkActor's
        list of vtkActors to render
    directory : str
        folder to save images into
    nframes : int
        number of frames to render
    camera_start : vtk.Camera
        camera to start rotation, default=None will fit actors in scene
    start_frame : int
        number to save the first frame number as... (default 0)
        i.e. frames will start_frame = 5, first file would be 005.png
    video_width : int
        size of video in pixels
    video_height : int
        size of the video in pixels
    scale : int
        how much to expand the image
    do_save : bool
        whether to save the images to disk or just play interactively

    Returns
    -------
    vtkRenderer
        the renderer used to render
    endframe
        the last frame written

    Example
    -------
    ::

        from meshparty import trimesh_io, trimesh_vtk
        mm = trimesh_io.MeshMeta(disk_cache_path = 'meshes')
        mesh = mm.mesh(filename='mymesh.obj')
        mesh_actor = trimesh_vtk.mesh_actor(mesh)
        mesh_center = np.mean(mesh.vertices, axis=0)
        camera_start = trimesh_vtk.oriented_camera(mesh_center)
        
        render_actors_360([mesh_actor], 'movie', 360, camera_start=camera_start)
    """
    if camera_start is None:
        frame_0_file = os.path.join(directory, "0000.png")
        ren = trimesh_vtk.render_actors(actors,
                                        do_save=True,
                                        filename=frame_0_file,
                                        VIDEO_WIDTH=video_width,
                                        VIDEO_HEIGHT=video_height,
                                        back_color=(1, 1, 1))
        camera_start = ren.GetActiveCamera()

    cameras = []
    times = []
    for k, angle in enumerate(np.linspace(0, 360, nframes)):
        angle_cam = vtk.vtkCamera()
        angle_cam.ShallowCopy(camera_start)
        angle_cam.Azimuth(angle)
        cameras.append(angle_cam)
        times.append(k)

    return render_movie(actors,
                        directory,
                        times=times,
                        cameras=cameras,
                        video_height=video_height,
                        video_width=video_width,
                        scale=scale,
                        do_save=do_save,
                        start_frame=start_frame)
Ejemplo n.º 7
0
                return True

    spine2broken = trimesh.repair.broken_faces(spinemesh2_mp)
    spine2openings = spinemesh2_mp.submesh([spine2broken], append=True)
    spine2openings = meshparty.trimesh_io.Mesh(
        vertices=spine2openings.vertices, faces=spine2openings.faces)
    print(spine2openings.body_count)
    if spine2openings.body_count == 1:
        pass
    elif spine2openings.body_count > 3:
        return True
    else:
        mask2 = mesh_filters.filter_components_by_size(spine2openings,
                                                       min_size=10)
        if True not in mask2:
            pass
        else:
            spine2openings = spine2openings.apply_mask(mask2)
            print(spine2openings.body_count)
            if spine2openings.body_count == 1:
                pass
            else:
                return True
    return False


# Visualize the meshes, synapses, and lines (no skeletons)
renderer1 = trimesh_vtk.render_actors(actors=[
    spinemesh1_actor, spinemesh2_actor, synapse1_actor, synapse2_actor
],
                                      do_save=False)
Ejemplo n.º 8
0
#trimesh_vtk.render_actors([shaft1_actor])
#shaft1openings_actor = trimesh_vtk.mesh_actor(shaft1openings)
#trimesh_vtk.render_actors([shaft1openings_actor])
print(shaft1openings.body_count)

#shaft 2
shaft2 = trimesh.exchange.load.load_mesh(
    r'data\meshes\EXPT1\137732862037\spine_1676.off')
shaft2broken = trimesh.repair.broken_faces(shaft2)
shaft2openings = shaft2.submesh([shaft2broken], append=True)
#shaft2_actor = trimesh_vtk.mesh_actor(shaft2,color=(0,0,1),opacity=0.2)
#trimesh_vtk.render_actors([shaft2_actor])
shaft2openings_actor = trimesh_vtk.mesh_actor(shaft2openings,
                                              color=(0, 0, 1),
                                              opacity=0.2)
trimesh_vtk.render_actors([shaft2openings_actor])
print(shaft2openings.body_count)

#spine 1
spine1 = trimesh.exchange.load.load_mesh(
    r'data\meshes\EXPT1\134025041739\spine_599.off')
spine1broken = trimesh.repair.broken_faces(spine1)
spine1openings = spine1.submesh([spine1broken], append=True)
#spine1_actor = trimesh_vtk.mesh_actor(spine1)
#trimesh_vtk.render_actors([spine1_actor])
#spine1openings_actor = trimesh_vtk.mesh_actor(spine1openings)
#trimesh_vtk.render_actors([spine1openings_actor])
print(spine1openings.body_count)

#spine 2
spine2 = trimesh.exchange.load.load_mesh(