Exemplo n.º 1
0
def main():
    """Main function."""
    args = parse_args()
    syris.init(loglevel=logging.INFO, double_precision=args.double_precision)
    units = q.Quantity(1, args.units)
    triangles = make_cube(
    ).magnitude if args.input is None else read_blender_obj(args.input)
    triangles = triangles * units
    tr = geom.Trajectory([(0, 0, 0)] * units)
    mesh = Mesh(triangles,
                tr,
                center=args.center,
                iterations=args.supersampling)
    LOG.info('Number of triangles: {}'.format(mesh.num_triangles))

    shape = (args.n, args.n)
    if args.pixel_size is None:
        if args.input is None:
            fov = 4. * units
        else:
            # Maximum sample size in x and y direction
            max_diff = np.max(mesh.extrema[:-1, 1] - mesh.extrema[:-1, 0])
            fov = max_diff
        fov *= args.margin
        args.pixel_size = fov / args.n
    else:
        fov = args.n * args.pixel_size

    if args.translate is None:
        translate = (fov.simplified.magnitude / 2.,
                     fov.simplified.magnitude / 2., 0) * q.m
    else:
        translate = (args.translate[0].simplified.magnitude,
                     args.translate[1].simplified.magnitude, 0) * q.m
    LOG.info('Translation: {}'.format(translate.rescale(q.um)))

    mesh.translate(translate)
    mesh.rotate(args.y_rotate, geom.Y_AX)
    mesh.rotate(args.x_rotate, geom.X_AX)
    fmt = 'n: {}, pixel size: {}, FOV: {}'
    LOG.info(
        fmt.format(args.n, args.pixel_size.rescale(q.um), fov.rescale(q.um)))

    st = time.time()
    proj = mesh.project(shape, args.pixel_size, t=None).get()
    LOG.info('Duration: {} s'.format(time.time() - st))
    offset = (0, translate[1].simplified, -(fov / 2.).simplified) * q.m

    if args.projection_filename is not None:
        save_image(args.projection_filename, proj)

    if args.compute_slice:
        sl = mesh.compute_slices((1, ) + shape, args.pixel_size,
                                 offset=offset).get()[0]
        if args.slice_filename is not None:
            save_image(args.slice_filename, sl)
        show(sl, title='Slice at y = {}'.format(args.n / 2))

    show(proj, title='Projection')
    plt.show()
Exemplo n.º 2
0
def main():
    syris.init()
    n = 256
    shape = (n, n)
    ps = 1 * q.um
    fov = n * ps
    triangles = make_cube().magnitude * n / 8. * ps
    # Rotation around the vertical axis
    points = make_circle(axis='y').magnitude * fov / 30000 + fov / 2
    trajectory = geom.Trajectory(points, pixel_size=ps, velocity=10 * q.um / q.s)
    # *orientation* aligns the object with the trajectory derivative
    mesh = Mesh(triangles, trajectory, orientation=geom.Z_AX)
    # Compute projection at the angle Pi/4
    projection = mesh.project(shape, ps, t=trajectory.time / 8).get()

    show(projection)
    plt.show()
Exemplo n.º 3
0
def main():
    syris.init()
    n = 256
    shape = (n, n)
    ps = 1 * q.um
    fov = n * ps
    triangles = make_cube().magnitude * n / 8. * ps
    # Rotation around the vertical axis
    points = make_circle(axis='y').magnitude * fov / 30000 + fov / 2
    trajectory = geom.Trajectory(points,
                                 pixel_size=ps,
                                 velocity=10 * q.um / q.s)
    # *orientation* aligns the object with the trajectory derivative
    mesh = Mesh(triangles, trajectory, orientation=geom.Z_AX)
    # Compute projection at the angle Pi/4
    projection = mesh.project(shape, ps, t=trajectory.time / 8).get()

    show(projection)
    plt.show()
Exemplo n.º 4
0
    def test_project_composite(self):
        n = 64
        shape = (n, n)
        ps = 1 * q.um
        x = np.linspace(0, n, num=10)
        y = z = np.zeros(x.shape)
        traj_x = Trajectory(zip(x, y, z) * ps, velocity=ps / q.s)
        traj_y = Trajectory(zip(y, x, z) * ps, velocity=ps / q.s)
        traj_xy = Trajectory(zip(n - x, x, z) * ps, velocity=ps / q.s)
        mb = MetaBall(traj_x, n * ps / 16)
        cube = make_cube() / q.m * 16 * ps / 4
        mesh = Mesh(cube, traj_xy)
        composite = CompositeBody(traj_y, bodies=[mb, mesh])
        composite.bind_trajectory(ps)

        composite.move(n / 2 * q.s)
        p = composite.project(shape, ps).get()
        composite.clear_transformation()

        # Compute
        composite.move(n / 2 * q.s)
        p_separate = (mb.project(shape, ps) + mesh.project(shape, ps)).get()

        np.testing.assert_almost_equal(p, p_separate)