コード例 #1
0
def make_trajectory_sequence(args):
    # Make a small circle (1 / 10 of the pixel size), so that the composite body only rotates and
    # does not translate. Put this circle in the middle of the image.
    circle = args.n / 2 * args.ps + make_circle(
        n=1024).magnitude * args.ps / 10
    traj = Trajectory(circle, velocity=args.ps / q.s, pixel_size=args.ps)
    metaballs = _make_metaballs(args)
    composite = CompositeBody(traj, bodies=metaballs)

    im = None
    d_angle = 10 * q.deg
    fmt = 'Projection at rotation {:>9}'
    # Rotate around 360 deg
    for i, t in enumerate(
            np.linspace(0, traj.time.simplified.magnitude, 37) * q.s):
        # Reset transformation matrices
        composite.clear_transformation()
        # Move to the desired position, i.e. around the circle and then each metaball moves relative
        # to the composite body.
        composite.move(t)
        p = composite.project(args.shape, args.ps).get()
        if im is None:
            im = show(p, title=fmt.format(i * d_angle))
        else:
            im.axes.set_title(fmt.format(i * d_angle))
            im.set_data(p)
        plt.draw()

    plt.show()
コード例 #2
0
ファイル: composite_body.py プロジェクト: ufo-kit/syris
def make_trajectory_sequence(args):
    # Make a small circle (1 / 10 of the pixel size), so that the composite body only rotates and
    # does not translate. Put this circle in the middle of the image.
    circle = args.n / 2 * args.ps + make_circle(n=1024).magnitude * args.ps / 10
    traj = Trajectory(circle, velocity=args.ps / q.s, pixel_size=args.ps)
    metaballs = _make_metaballs(args)
    composite = CompositeBody(traj, bodies=metaballs)

    im = None
    d_angle = 10 * q.deg
    fmt = 'Projection at rotation {:>9}'
    # Rotate around 360 deg
    for i, t in enumerate(np.linspace(0, traj.time.simplified.magnitude, 37) * q.s):
        # Reset transformation matrices
        composite.clear_transformation()
        # Move to the desired position, i.e. around the circle and then each metaball moves relative
        # to the composite body.
        composite.move(t)
        p = composite.project(args.shape, args.ps).get()
        if im is None:
            im = show(p, title=fmt.format(i * d_angle))
        else:
            im.axes.set_title(fmt.format(i * d_angle))
            im.set_data(p)
        plt.draw()

    plt.show()
コード例 #3
0
ファイル: composite_body.py プロジェクト: ufo-kit/syris
def make_complex_trajectory_sequence(args):
    edge = 20
    x = np.linspace(0, args.n / 2 - args.n / 4 - edge - 5, num=10)
    y = z = np.zeros(x.shape)
    # Move along x axis
    traj_x = Trajectory(zip(x, y, z) * args.ps, velocity=args.ps / q.s, pixel_size=args.ps)
    # Move along y axis
    traj_y = Trajectory(zip(y, x, z) * args.ps, velocity=args.ps / q.s, pixel_size=args.ps)
    # Move along both x and y axes
    traj_xy = Trajectory(zip(x, x, z) * args.ps, velocity=args.ps / q.s, pixel_size=args.ps)
    # Circular trajectory of the composite body rotates around the image center and with radius
    # n / 4 pixels.
    circle = args.n / 2 * args.ps + make_circle().magnitude * args.n / 4 * args.ps
    traj_circle = Trajectory(circle, velocity=args.ps / q.s, pixel_size=args.ps)
    # Make the trajectory of the circle the same duration as the simple linear one.
    traj_circle = Trajectory(circle, velocity=traj_circle.length / traj_xy.length * args.ps / q.s)
    # three cubes in the same height and depth, shifted only along the x axis.
    traj_stationary = Trajectory([(0, 0, 0)] * args.ps)
    traj_stationary_1 = Trajectory([(-2 * edge, 0, 0)] * args.ps)
    traj_stationary_2 = Trajectory([(2 * edge, 0, 0)] * args.ps)

    cube = make_cube() / q.m * edge * args.ps
    # The cubes are elongated along y axis.
    cube[::2, :] /= 3

    mesh = Mesh(cube, traj_x, orientation=geom.Y_AX)
    mesh_2 = Mesh(cube, traj_y, orientation=geom.Y_AX)
    mesh_3 = Mesh(cube, traj_xy, orientation=geom.Y_AX)
    mesh_stationary = Mesh(cube, traj_stationary, orientation=geom.Y_AX)
    mesh_stationary_1 = Mesh(cube, traj_stationary_1, orientation=geom.Y_AX)
    mesh_stationary_2 = Mesh(cube, traj_stationary_2, orientation=geom.Y_AX)
    bodies = [mesh, mesh_2, mesh_3, mesh_stationary, mesh_stationary_1, mesh_stationary_2]
    composite = CompositeBody(traj_circle, bodies=bodies, orientation=geom.Y_AX)
    composite.bind_trajectory(args.ps)

    total_time = composite.time
    if args.t is None:
        times = np.linspace(0, 1, 100)
    else:
        if args.t < 0 or args.t > 1:
            raise ValueError('--t must be in the range [0, 1]')
        times = [args.t]

    im = None
    for index, i in enumerate(times):
        t = i * total_time
        composite.clear_transformation()
        composite.move(t)
        p = composite.project(args.shape, args.ps).get()
        if im is None:
            im = show(p, title='Projection')
        else:
            im.set_data(p)
            plt.draw()

    plt.show()
コード例 #4
0
ファイル: test_bodies.py プロジェクト: flmiot/syris-1
    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)
コード例 #5
0
def make_complex_trajectory_sequence(args):
    edge = 20
    x = np.linspace(0, args.n / 2 - args.n / 4 - edge - 5, num=10)
    y = z = np.zeros(x.shape)
    # Move along x axis
    traj_x = Trajectory(zip(x, y, z) * args.ps,
                        velocity=args.ps / q.s,
                        pixel_size=args.ps)
    # Move along y axis
    traj_y = Trajectory(zip(y, x, z) * args.ps,
                        velocity=args.ps / q.s,
                        pixel_size=args.ps)
    # Move along both x and y axes
    traj_xy = Trajectory(zip(x, x, z) * args.ps,
                         velocity=args.ps / q.s,
                         pixel_size=args.ps)
    # Circular trajectory of the composite body rotates around the image center and with radius
    # n / 4 pixels.
    circle = args.n / 2 * args.ps + make_circle(
    ).magnitude * args.n / 4 * args.ps
    traj_circle = Trajectory(circle,
                             velocity=args.ps / q.s,
                             pixel_size=args.ps)
    # Make the trajectory of the circle the same duration as the simple linear one.
    traj_circle = Trajectory(circle,
                             velocity=traj_circle.length / traj_xy.length *
                             args.ps / q.s)
    # three cubes in the same height and depth, shifted only along the x axis.
    traj_stationary = Trajectory([(0, 0, 0)] * args.ps)
    traj_stationary_1 = Trajectory([(-2 * edge, 0, 0)] * args.ps)
    traj_stationary_2 = Trajectory([(2 * edge, 0, 0)] * args.ps)

    cube = make_cube() / q.m * edge * args.ps
    # The cubes are elongated along y axis.
    cube[::2, :] /= 3

    mesh = Mesh(cube, traj_x, orientation=geom.Y_AX)
    mesh_2 = Mesh(cube, traj_y, orientation=geom.Y_AX)
    mesh_3 = Mesh(cube, traj_xy, orientation=geom.Y_AX)
    mesh_stationary = Mesh(cube, traj_stationary, orientation=geom.Y_AX)
    mesh_stationary_1 = Mesh(cube, traj_stationary_1, orientation=geom.Y_AX)
    mesh_stationary_2 = Mesh(cube, traj_stationary_2, orientation=geom.Y_AX)
    bodies = [
        mesh, mesh_2, mesh_3, mesh_stationary, mesh_stationary_1,
        mesh_stationary_2
    ]
    composite = CompositeBody(traj_circle,
                              bodies=bodies,
                              orientation=geom.Y_AX)
    composite.bind_trajectory(args.ps)

    total_time = composite.time
    if args.t is None:
        times = np.linspace(0, 1, 100)
    else:
        if args.t < 0 or args.t > 1:
            raise ValueError('--t must be in the range [0, 1]')
        times = [args.t]

    im = None
    for index, i in enumerate(times):
        t = i * total_time
        composite.clear_transformation()
        composite.move(t)
        p = composite.project(args.shape, args.ps).get()
        if im is None:
            im = show(p, title='Projection')
        else:
            im.set_data(p)
            plt.draw()

    plt.show()