示例#1
0
def axes_scene(rotation=[1, 0, 0, 0]):
    x = np.array([[6, 0, 0], [6, -1, -1], [6, -1, 1], [6, 1, -1], [6, 1, 1],
                  [6, -0.5, -0.5], [6, -0.5, 0.5], [6, 0.5, -0.5],
                  [6, 0.5, 0.5]])
    x_lines_prim = draw.Lines(start_points=np.array([[0, 0, 0], *x[1:5]]),
                              end_points=np.array([x[0]] * 5),
                              widths=0.5 * np.ones(5),
                              colors=[[1, 0, 0, 1]] * 5,
                              cap_mode=1)
    y = np.array([[0, 6, 0], [1, 6, 1], [-1, 6, 1], [0, 6, -1], [0.5, 6, 0.5],
                  [-0.5, 6, 0.5], [0, 6, -0.5]])
    y_lines_prim = draw.Lines(start_points=np.array([[0, 0, 0], *y[1:4]]),
                              end_points=np.array([y[0]] * 4),
                              widths=0.5 * np.ones(4),
                              colors=[[0, 1, 0, 1]] * 4,
                              cap_mode=1)
    z = np.array([[0, 0, 6], [-1, 1, 6], [1, 1, 6], [-1, -1, 6], [1, -1, 6],
                  [-0.5, -1, 6], [0, -1, 6], [0.5, -1, 6], [-0.5, 1, 6],
                  [0, 1, 6], [0.5, 1, 6], [-0.5, -0.5, 6], [0.5, 0.5, 6]])
    z_lines_prim = draw.Lines(start_points=np.array([[0, 0, 0], *z[1:4]]),
                              end_points=np.array([z[0], *z[2:5]]),
                              widths=0.5 * np.ones(4),
                              colors=[[0, 0, 1, 1]] * 4,
                              cap_mode=1)
    scene = draw.Scene([x_lines_prim, y_lines_prim, z_lines_prim],
                       rotation=rotation)
    return scene
示例#2
0
def axes_scene(rotation=[1, 0, 0, 0]):
    x = np.array([[6, 0, 0],
                  [6, -1, -1],
                  [6, -1, 1],
                  [6, 1, -1],
                  [6, 1, 1],
                  [6, -0.5, -0.5],
                  [6, -0.5, 0.5],
                  [6, 0.5, -0.5],
                  [6, 0.5, 0.5]])
    x_sphere_prim = draw.Spheres(positions=x,
                                 radii=0.25*np.ones(len(x)),
                                 colors=[[1, 0, 0, 1]]*len(x))
    x_lines_prim = draw.Lines(start_points=np.array([[0, 0, 0], *x[1:5]]),
                              end_points=np.array([x[0]]*5),
                              widths=0.5*np.ones(5),
                              colors=[[1, 0, 0, 1]]*5)
    y = np.array([[0, 6, 0],
                  [1, 6, 1],
                  [-1, 6, 1],
                  [0, 6, -1],
                  [0.5, 6, 0.5],
                  [-0.5, 6, 0.5],
                  [0, 6, -0.5]])
    y_sphere_prim = draw.Spheres(positions=y,
                                 radii=0.25*np.ones(len(y)),
                                 colors=[[0, 1, 0, 1]]*len(y))
    y_lines_prim = draw.Lines(start_points=np.array([[0, 0, 0], *y[1:4]]),
                              end_points=np.array([y[0]]*4),
                              widths=0.5*np.ones(4),
                              colors=[[0, 1, 0, 1]]*4)
    z = np.array([[0, 0, 6],
                  [-1, 1, 6],
                  [1, 1, 6],
                  [-1, -1, 6],
                  [1, -1, 6],
                  [-0.5, -1, 6],
                  [0, -1, 6],
                  [0.5, -1, 6],
                  [-0.5, 1, 6],
                  [0, 1, 6],
                  [0.5, 1, 6],
                  [-0.5, -0.5, 6],
                  [0.5, 0.5, 6]])
    z_sphere_prim = draw.Spheres(positions=z,
                                 radii=0.25*np.ones(len(z)),
                                 colors=[[0, 0, 1, 1]]*len(z))
    z_lines_prim = draw.Lines(start_points=np.array([[0, 0, 0], *z[1:4]]),
                              end_points=np.array([z[0], *z[2:5]]),
                              widths=0.5*np.ones(4),
                              colors=[[0, 0, 1, 1]]*4)
    scene = draw.Scene([x_sphere_prim, x_lines_prim,
                        y_sphere_prim, y_lines_prim,
                        z_sphere_prim, z_lines_prim],
                       rotation=rotation)
    return scene
示例#3
0
def field_scene(N=10, use='ellipsoids'):
    features = dict(ambient_light=.4)
    (positions, units) = example_vector_field(5)

    normalized_z = positions[:, 2].copy()
    normalized_z -= np.min(normalized_z)
    normalized_z /= np.max(normalized_z)

    colors = plato.cmap.cubehelix(normalized_z, h=1.4)
    colors[:, :3] = .5 * (colors[:, :3] + plato.cmap.cubeellipse(
        np.arctan2(positions[:, 1], positions[:, 0])))

    if use == 'ellipsoids':
        orientations = rowan.vector_vector_rotation([(1, 0, 0)], units)
        prim = draw.Ellipsoids(positions=positions,
                               orientations=orientations,
                               colors=colors,
                               a=.5,
                               b=.125,
                               c=.125)
    elif use == 'lines':
        features['ambient_light'] = 1
        starts = positions - units / 2
        ends = positions + units / 2

        prim = draw.Lines(start_points=starts,
                          end_points=ends,
                          colors=colors,
                          widths=np.ones(len(positions)) * .25)
    else:
        raise NotImplementedError('Unknown primitive {}'.format(use))

    rotation = [0.8126942, 0.35465172, -0.43531808, 0.15571932]
    scene = draw.Scene(prim, zoom=4, features=features, rotation=rotation)
    return scene
示例#4
0
def lines_cube():
    vertices = np.array(list(itertools.product(*(3*[[-1, 1]]))), dtype=np.float32)
    edge_indices = np.array([0, 1, 1, 3, 3, 2, 2, 0, 0, 4, 1, 5, 3, 7, 2, 6, 4,
                             5, 5, 7, 7, 6, 6, 4], dtype=np.uint32).reshape((12, 2))
    widths = np.ones((12,))*.1
    colors = plato.cmap.cubehelix(edge_indices[:, 0].astype(np.float32)/8)

    prim = draw.Lines(start_points=vertices[edge_indices[:, 0]],
                      end_points=vertices[edge_indices[:, 1]],
                      widths=widths, colors=colors)

    features = dict(ambient_light=.25, directional_light=dict(lights=(-.1, -.15, -1)))
    rotation = [ 9.9774611e-01,  2.3801494e-02, -6.2734932e-02,  5.5756618e-04]
    return draw.Scene(prim, features=features, rotation=rotation, zoom=11)
示例#5
0
def many_3d_primitives(seed=15, num_particles=3):
    np.random.seed(seed)
    positions = np.random.uniform(0, 3, (num_particles, 3))
    colors = np.random.uniform(.75, .9, (num_particles, 4))**1.5
    orientations = np.random.rand(num_particles, 4)
    orientations /= np.linalg.norm(orientations, axis=-1, keepdims=True)

    vertices = np.random.rand(12, 3)
    vertices -= np.mean(vertices, axis=0, keepdims=True)
    diameters = np.random.rand(num_particles)

    prim = draw.ConvexSpheropolyhedra(positions=positions,
                                      colors=colors,
                                      orientations=orientations,
                                      vertices=vertices,
                                      radius=.1)

    prim2 = draw.ConvexPolyhedra.copy(prim)
    prim2.positions = (-1, -1, -1) - prim2.positions

    prim3 = draw.Spheres.copy(prim)
    prim3.diameters = diameters
    prim3.positions = (1, -1, 1) - prim.positions

    prim4 = draw.Lines(start_points=prim.positions,
                       end_points=prim2.positions,
                       colors=np.random.rand(num_particles, 4),
                       widths=np.ones((num_particles, )) * .1)

    (vertices, faces) = plato.geometry.convexHull(vertices)
    vertices -= (-1, 1, -1)
    indices = list(plato.geometry.fanTriangleIndices(faces))
    colors = np.random.rand(len(vertices), 4)
    colors[:] = .5
    prim5 = draw.Mesh(vertices=vertices, indices=indices, colors=colors)

    prim6 = draw.Ellipsoids.copy(prim)
    prim6.b = 1.05
    prim6.c = 0.8
    prim6.positions = (-1, 1, -1) - prim6.positions

    prims = [prim, prim2, prim3, prim4, prim5, prim6]
    features = dict(ambient_light=.25,
                    directional_light=(-.1, -.15, -1),
                    translucency=True)
    scene = draw.Scene(prims, zoom=5, clip_scale=10, features=features)
    return scene
示例#6
0
def disks_and_lines():
    thetas = np.linspace(0, 2*np.pi, 6, endpoint=False)
    extra_positions = np.array([np.cos(thetas), np.sin(thetas)]).T*1.1
    positions = np.array([[0, 0]] + extra_positions.tolist())
    colors = np.tile([[.25, .25, .8, 1]], (len(positions), 1))
    diameters = np.ones((len(positions),))

    prim1 = draw.Disks(positions=positions, colors=colors, diameters=diameters)

    positions_3d = np.pad(positions, ((0, 0), (0, 1)), 'constant')

    colors = np.tile([[.1, .1, .1, 1]], (6, 1))
    prim2 = draw.Lines(start_points=np.tile(positions_3d[:1], (6, 1)),
                       end_points=positions_3d[1:],
                       widths=np.ones((6,))*.25, colors=colors)

    return draw.Scene([prim2, prim1], zoom=10)