コード例 #1
0
ファイル: 5_surface_plot.py プロジェクト: vn-os/plotoptix
def main():

    # make some data first:
    rx = (-15, 5)
    rz = (-10, 10)
    n = 50

    x = np.linspace(rx[0], rx[1], n)
    z = np.linspace(rz[0], rz[1], n)

    X, Z = np.meshgrid(x, z)
    Y = f(X, Z)

    rt = TkOptiX()  # create and configure, show the window later

    rt.set_param(max_accumulation_frames=50)  # accumulate up to 50 frames
    rt.set_background(0)  # black background
    rt.set_ambient(0.25)  # some ambient light

    # try commenting out optional arguments
    rt.set_data_2d("surface",
                   Y,
                   range_x=rx,
                   range_z=rz,
                   c=map_to_colors(Y, "OrRd"),
                   floor_c=[0.05, 0.12, 0.38],
                   floor_y=-1.75,
                   make_normals=True)

    # add wireframe above the surface
    rt.set_data_2d("wireframe",
                   Y + 3,
                   range_x=rx,
                   range_z=rz,
                   r=0.06 * np.abs(Y),
                   geom="Graph",
                   c=0.92)

    # set camera and light position to fit the scene
    rt.setup_camera("cam1")
    eye = rt.get_camera_eye()
    eye[1] = 0.5 * eye[2]
    rt.update_camera("cam1", eye=eye)

    d = np.linalg.norm(rt.get_camera_target() - eye)
    rt.setup_light("light1", color=8, radius=0.3 * d)

    rt.start()

    print("done")
コード例 #2
0
def update_scene(rt: TkOptiX) -> None:
    rt.update_camera(eye=params.eye)
コード例 #3
0
ファイル: 1_scatter_plot_3d.py プロジェクト: vn-os/plotoptix
def main():

    # Make some data first:

    n = 50000

    xyz = 3 * (np.random.random((n, 3)) - 0.5)
    r = 0.1 * (1 - (xyz[:, 0] / 3 + 0.5)) + 0.02
    s = np.sum(xyz, axis=1)

    particles = xyz[s > 0.2]
    rp = r[s > 0.2]
    # Use xyz positions to calculate RGB color components:
    cp = particles / 3 + 0.5

    cubes = xyz[s < -0.2]
    rc = r[s < -0.2]
    # Map Y-coordinate to matplotlib's color map RdYlBu: map_to_colors()
    # function is automatically scaling the data to fit <0; 1> range.
    # Any other mapping is OK, just keep the result in shape
    # (n-data-points, 3), where 3 stands for RGB color
    # components.
    cc = map_to_colors(cubes[:, 1], "RdYlBu")

    # Create plots:

    optix = TkOptiX()  # create and configure, show the window later

    # accumulate up to 30 frames (override default of 4 frames)
    optix.set_param(max_accumulation_frames=30)

    # white background
    optix.set_background(0.99)

    # add plots, ParticleSet geometry is default
    optix.set_data("particles", pos=particles, r=rp, c=cp)
    # and use geom parameter to specify cubes geometry;
    # Parallelepipeds can be described precisely with U, V, W vectors,
    # but here we only provide the r parameter - this results with
    # randomly rotated cubes of U, V, W lenghts equal to r
    optix.set_data("cubes", pos=cubes, r=rc, c=cc, geom="Parallelepipeds")

    # tetrahedrons look good as well, and they are really fast on RTX devices:
    #optix.set_data("tetras", pos=cubes, r=rc, c=cc, geom="Tetrahedrons")

    # if you prefer cubes aligned with xyz:
    #optix.set_data("cubes", pos=cubes, r=rc, c=cc, geom="Parallelepipeds", rnd=False)

    # or if you'd like some edges fixed:
    #v = np.zeros((rc.shape[0], 3)); v[:,1] = rc[:]
    #optix.set_data("cubes", pos=cubes, u=[0.05,0,0], v=v, w=[0,0,0.05], c=cc, geom="Parallelepipeds")

    # show coordinates box
    optix.set_coordinates()

    # show the UI window here - this method is calling some default
    # initialization for us, e.g. creates camera, so any modification
    # of these defaults should come below (or we provide on_initialization
    # callback)
    optix.show()

    # camera and lighting configured by hand
    optix.update_camera(eye=[5, 0, -8])
    optix.setup_light("light1",
                      color=10 * np.array([0.99, 0.9, 0.7]),
                      radius=2)

    print("done")