예제 #1
0
def add_surface_point_to_points(scene,
                                points,
                                point_radius,
                                color="n",
                                verbose=True):
    """
    Adds the closest part of the brain surface to the list of points. Returns
    the brainrender scene with the point added, and the point added to the
    list of points
    :param scene: brainrender scene object
    :param points: List of points
    :param point_radius: Radius of the point when displayed
    :param bool verbose: Whether to print the progress
    :return:
        scene: brainrender scene with the surface point added.
        points: list of points with the surface point added.
    """
    if verbose:
        print(
            "Finding the closest point on the brain surface to the first point"
        )
    root_mesh = mesh.Mesh(scene.root)
    surface_intersection = np.expand_dims(root_mesh.closestPoint(points[0]),
                                          axis=0)
    points = np.concatenate([surface_intersection, points], axis=0)
    scene.add_vtkactor(
        Spheres(surface_intersection, r=point_radius).color(color))
    return scene, points
예제 #2
0
def analyse_track(
    scene,
    points_file,
    add_surface_to_points=True,
    spline_points=100,
    fit_degree=3,
    spline_smoothing=0.05,
    point_radius=30,
    spline_radius=10,
    verbose=True,
):
    """
    Given a file of points, fit a spline function, and add to a brainrender
     scene.
    :param scene: brainrender scene object
    :param points_file:
    :param bool add_surface_to_points: Add the closest part of the brain
    surface to the list of points
    :param spline_points: How many points define the spline
    :param fit_degree: spline fit degree
    :param spline_smoothing: spline fit smoothing
    :param point_radius: size of the points in the brainrender scene
    :param spline_radius: size of the rendered spline in the brainrender
    scene
    :param bool verbose: Whether to print the progress
    :return:
        scene: brainrender scene with the surface point added.
        spline: vedo spline object
    """
    points = pd.read_hdf(points_file)
    scene.add_cells(
        points,
        color_by_region=True,
        res=12,
        radius=point_radius,
        verbose=False,
    )
    points = np.array(points)

    if add_surface_to_points:
        scene, points = add_surface_point_to_points(scene,
                                                    points,
                                                    point_radius,
                                                    verbose=verbose)

    far_point = np.expand_dims(points[-1], axis=0)
    scene.add_vtkactor(Spheres(far_point, r=point_radius).color("n"))

    spline = (Spline(
        points,
        smooth=spline_smoothing,
        degree=fit_degree,
        res=spline_points,
    ).pointSize(spline_radius).color("n"))

    return scene, spline
예제 #3
0
    def _from_numpy(self, data):
        """
            Creates the mesh
        """
        N = len(data)
        if not isinstance(self.colors, str):
            if not N == len(self.colors):  # pragma: no cover
                raise ValueError(  # pragma: no cover
                    "When passing a list of colors, the number of colors shou  # pragma: no coverld match the number of cells"  # pragma: no cover
                )  # pragma: no cover

        self.name = self.name or "Points"
        mesh = Spheres(data,
                       r=self.radius,
                       c=self.colors,
                       alpha=self.alpha,
                       res=8)
        return mesh
for t_interval in range(int(T / output_int)):
    for it in range(output_int):
        t = t_interval * output_int + it
        #print('\r', "t=", t, end='')
        #print("t=", t)
        take_step(d_X, N)

    print('\r', "t=", t, end='')
    out_X = d_X.copy_to_host()

    pol = arr_pol_to_float3(out_X[:, 3:5])
    coords_t.append(out_X[:, :3])
    pol_t.append(pol)

#print('\r', "DONE", t, end='')

#######################################################################
from vedo import Box, Spheres, Arrows, show, interactive

world = Box(pos=(1, 1, 0), size=(10, 10, 4), alpha=1).wireframe()

for t in range(len(coords_t)):
    cells = Spheres(coords_t[t], c='b', r=0.4)
    polarities = Arrows(startPoints=coords_t[t],
                        endPoints=coords_t[t] + pol_t[t],
                        c='tomato')
    show(world, cells, polarities, interactive=0, viewup='z')

interactive()
예제 #5
0
        idx_new = N + it

        theta = acos(2. * np.random.uniform(0,1) - 1);
        phi = np.random.uniform(0,1) * 2.0 * pi;
        X[idx_new,0] = X[idx,0] + mean_dist / 4 * sin(theta) * cos(phi);
        X[idx_new,1] = X[idx,1] + mean_dist / 4 * sin(theta) * sin(phi);
        X[idx_new,2] = X[idx,2] + mean_dist / 4 * cos(theta);

    return N + marked_for_div_idx.size

# Initialise cells
ini_x = np.random.uniform(low=-1.0, high=1.0, size=n_max)
ini_y = np.random.uniform(low=-1.0, high=1.0, size=n_max)
ini_z = np.random.uniform(low=-1.0, high=1.0, size=n_max)

X = np.column_stack((ini_x, ini_y, ini_z))

########################################################
from vedo import ProgressBar, Spheres,show, interactive

pb = ProgressBar(0, T, c='red')
for t in pb.range():

    take_euler_step(X, N, dt, relu_force, r_max, r_eq)
    N = proliferation(X, N, prolif_rate, r_eq)

    cells = Spheres(X[:N,:], c='b', r=0.4)
    show(cells, interactive=0, viewup='z')
    pb.print("N= " + str(N))

interactive()
예제 #6
0
def visualize_log_data():
    parser = config_parser()
    args = parser.parse_args()
    if args.run_dir == "newest":
        run_folders = os.listdir('../runs')
        if len(run_folders) == 0:
            raise ValueError('There is no run in the runs directory')
        newest = 0
        run_dir = ""
        for run_folder in run_folders:
            timestamp = os.path.getmtime(os.path.join('../runs', run_folder))
            if timestamp > newest:
                newest = timestamp
                run_dir = os.path.join('../runs', run_folder)
    else:
        run_dir = args.run_dir

    if args.epoch == 0:
        try:
            filenames = os.listdir(os.path.join(run_dir, 'vedo_data'))
        except:
            raise ValueError("There seems to be no vedo data generated for the specified run since the path ",
                             os.path.join(run_dir, 'vedo_data'), '  was not found')

        if len(filenames) == 0:
            raise ValueError('No epoch in the vedo_data folder')
        epoch = 0

        for filename in filenames:
            file_epoch = int(re.findall(r'\d+', filename)[0])
            if file_epoch > epoch:
                epoch = file_epoch
    else:
        epoch = args.epoch

    ats = []
    images = []

    print('Using run ' + run_dir + ' and epoch ' + str(epoch))

    for image_index in range(args.number_images):
        try:
            densities_samples_warps = np.load(
                os.path.join(run_dir, 'vedo_data',
                             "densities_samples_warps_epoch_" + str(epoch) + '_image_' + str(image_index) + '.npz'))
            densities, densities_samples, warps, warps_samples = densities_samples_warps['densities'], \
                                                                 densities_samples_warps['samples_density'], \
                                                                 densities_samples_warps['warps'], \
                                                                 densities_samples_warps['samples_warp']

            if args.mode == "density":
                max_density = np.max(densities)
                if max_density == 0:
                    print('Every density for image ', image_index,
                          ' is 0 so your images are probably white and this visualization has spheres of radius 0')
                normalized_densities = densities / max_density

                radii = normalized_densities * 0.05
                ats.append(image_index)
                images.append(Spheres(densities_samples, r=radii, c="lb", res=8))
            elif args.mode == "warp":
                ats.append(image_index)
                images.append([Arrows(warps_samples, warps_samples + warps, s=0.3),
                               Spheres(warps_samples, r=0.01, res=8)])

        except FileNotFoundError as err:
            print('Skipping the iteration with image index ', image_index, ' because the file for that image '
                                                                           'was not found: ', err)

    show(images, at=ats, axes=2)
예제 #7
0
import numpy as np
from Forces.forces import relu_force
from Solvers.solvers import take_euler_step

# Params
N = 200
T = 100
r_max = 1.0
r_eq = 0.8
dt = 0.1

# Initialise cells
ini_x = np.random.uniform(low=-1.0, high=1.0, size=N)
ini_y = np.random.uniform(low=-1.0, high=1.0, size=N)
ini_z = np.random.uniform(low=-1.0, high=1.0, size=N)

X = np.column_stack((ini_x, ini_y, ini_z))

from vedo import ProgressBar, Spheres, interactive

pb = ProgressBar(0, T, c='red')
for t in pb.range():

    take_euler_step(X, N, dt, relu_force, r_max, r_eq)

    Spheres(X, c='b', r=0.3).show(axes=1, interactive=0)
    pb.print()

interactive()
예제 #8
0
"""Example that shows how to draw very large number
of spheres (same for Points, Lines) with different
colors or different radii, N="""
from vedo import show, Spheres
from random import gauss

N = 50000

cols = range(N)  # color numbers
pts = [(gauss(0, 1), gauss(0, 2), gauss(0, 1)) for i in cols]
rads = [abs(pts[i][1]) / 10 for i in cols]  # radius=0 for y=0

# all have same radius but different colors:
s0 = Spheres(pts, c=cols, r=0.1, res=5)  # res= theta-phi resolution
show(s0, __doc__ + str(N), at=0, N=2, axes=1, viewup=(-0.7, 0.7, 0))

# all have same color but different radius along y:
s1 = Spheres(pts, r=rads, c="lb", res=8)
show(s1, at=1, axes=2, interactive=True)
예제 #9
0
    if t % output_int == 0:
        out_X = np.copy(X)
        pol = arr_pol_to_float3(out_X[:, 3:5])
        coords_t.append(out_X[:, :3])
        pol_t.append(pol)

###############################################################################
# View as an interactive time sequence with a slider
max_time = len(coords_t)
vp = Plotter(interactive=False)

coord_acts = []
pol_acts = []
for t in range(len(coords_t)):
    coords = Spheres(coords_t[t], c='b', r=0.4).off()
    polarities = Arrows(startPoints=coords_t[t],
                        endPoints=coords_t[t] + pol_t[t],
                        c='t').off()
    vp += [coords, polarities]
    coord_acts.append(coords)
    pol_acts.append(polarities)


def set_time(widget, event):
    new_time = int(floor(widget.GetRepresentation().GetValue()))
    for t in range(0, max_time):
        if t == new_time:
            coord_acts[t].on()
            pol_acts[t].on()
        else: