def main(): # Make some data first: n = 3600 s = 50 m = -0.97 # try various m: 0.4, 2.48, -1.383, -2.03, ... m = math.exp(m) k = 1 xyz = [np.array([0, s * (math.e - 2), 0])] t = 0 while t < n: rad = math.pi * t / 180 f = s * (math.exp(math.cos(rad)) - 2 * math.cos(4 * rad) - math.pow(math.sin(rad/m), 5)) xyz.append(np.array([f * math.sin(rad), f * math.cos(rad), f * math.sin(2*rad)])) t += k r = np.linalg.norm(xyz, axis=1) r = 5 - (5 / r.max()) * r + 0.02 # Create the plots: optix = TkOptiX() # create and configure, show the window later optix.set_background(0.99) # white background optix.set_ambient(0.2) # dim ambient light # add plot, BezierChain geometry makes a smooth line interpolating data points optix.set_data("curve", pos=xyz, r=r, c=0.9, geom="BezierChain") # 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 auto-configured to fit the plot optix.camera_fit() # 2 spherical light sources, warm and cool, fit positions with respect to # the current camera plane: 45 deg right/left and 25 deg up; # do not include lights in geometry, so they do not appear in the image optix.setup_light("light1", color=15*np.array([0.99, 0.9, 0.7]), radius=250, in_geometry=False) optix.light_fit("light1", horizontal_rot=45, vertical_rot=25, dist_scale=1.1) optix.setup_light("light2", color=20*np.array([0.7, 0.9, 0.99]), radius=200, in_geometry=False) optix.light_fit("light2", horizontal_rot=-45, vertical_rot=25, dist_scale=1.1) # accumulate up to 30 frames (override default of 4 frames) optix.set_param(max_accumulation_frames=200) print("done")
def main(): rt = TkOptiX() n = 1000000 # 1M data points xyz = 3 * (np.random.random((n, 3)) - 0.5) r = 0.02 * np.random.random(n) + 0.002 rt.set_data("plot", xyz, r=r) rt.set_ambient(0.9) # set ambient light, brighter than default rt.show() # note: non-blocking in the interactive shell print("done")
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")
def main(): # Make some data first (arbitrary scles): data = np.random.normal(2, 0.8, 1000) h, x = np.histogram(data, bins=15, range=(0, 4)) s = np.cumsum(h) / np.sum(h) e = 6 * np.sqrt(h) / np.sum(h) h = 3 * h / np.sum(h) bin_size = x[1] - x[0] # Create the plot: optix = TkOptiX() # create and configure, show the window later # accumulate more frames (override default of step=1 and max=4 frames) optix.set_param(min_accumulation_step=2, max_accumulation_frames=100) # Add data: # - pos argument is used for bar positions # - u and w vectors are used to set base x and z sizes # - v is used to set bar heights. ps = np.zeros((h.shape[0], 3)) ps[:, 0] = x[:-1] vs = np.zeros((h.shape[0], 3)) vs[:, 1] = s optix.set_data("cumulative", pos=ps, u=[0.9 * bin_size, 0, 0], v=vs, w=[0, 0, 0.8 * bin_size], c=[0.6, 0, 0], geom="Parallelepipeds") ph = np.zeros((h.shape[0], 3)) ph[:, 0] = x[:-1] ph[:, 2] = bin_size vh = np.zeros((h.shape[0], 3)) vh[:, 1] = h optix.set_data("density", pos=ph, u=[0.9 * bin_size, 0, 0], v=vh, w=[0, 0, 0.8 * bin_size], c=0.95, geom="Parallelepipeds") pe = np.zeros((e.shape[0], 3)) pe[:, 0] = x[:-1] pe[:, 1] = h pe[:, 2] = bin_size ve = np.zeros((e.shape[0], 3)) ve[:, 1] = e optix.set_data("error", pos=pe, u=[0.9 * bin_size, 0, 0], v=ve, w=[0, 0, 0.8 * bin_size], c=map_to_colors(e, "Blues"), geom="Parallelepipeds") # Setup camera and light: optix.setup_camera("cam", eye=[x[0], 1.5 * np.amax((h, s + e)), x[-1] - x[0]], target=[(x[0] + x[-1]) / 2, 0, 0]) optix.setup_light("l1", color=10) # show the UI window optix.show() print("done")
def main(): b = 7000 # number of curves n = 60 # number pf nodes per curve dt = 0.08 # nodes distance ofs = 50 * np.random.rand(3) inp = 5 * np.random.rand(b, 3, 4) - 2.5 for c in range(b): inp[c, 1:, :3] = inp[c, 0, :3] inp[c, :, 0] *= 1.75 # more spread in X inp[c, :, 3] = ofs # sync the 4'th dim of the noise #print(inp) pos = np.zeros((b, n, 3), dtype=np.float32) r = np.zeros((b, n), dtype=np.float32) rnd = simplex(inp) #print(rnd) for t in range(n): rt = 2.0 * (t + 1) / (n + 2) - 1 rt = 1 - rt * rt r[:, t] = 0.07 * rt * rt for c in range(b): mag = np.linalg.norm(rnd[c]) r[c, t] *= 0.2 + 0.8 * mag # modulate thickness rnd[c] = (dt / mag) * rnd[c] # normalize and scale the step size inp[c, :, :3] += rnd[c] # step in the field direction pos[c, t] = inp[c, 0, :3] rnd = simplex(inp, rnd) # calculate noise at the next pos rt = TkOptiX(start_now=False) rt.set_param( min_accumulation_step=1, max_accumulation_frames=200, rt_timeout=100000 # accept lower fps ) exposure = 1.2 gamma = 1.8 rt.set_float("tonemap_exposure", exposure) rt.set_float("tonemap_gamma", gamma) rt.set_float("denoiser_blend", 0.25) rt.add_postproc("Denoiser") rt.setup_material("plastic", m_plastic) for c in range(b): if np.random.uniform() < 0.05: rt.set_data("c" + str(c), pos=pos[c], r=1.1 * r[c], c=[0.4, 0, 0], geom="BezierChain") else: rt.set_data("c" + str(c), pos=pos[c], r=r[c], c=0.94, geom="BezierChain", mat="plastic") rt.setup_camera("dof_cam", eye=[0, 0, 12], target=[0, 0, 0], fov=57, focal_scale=0.7, cam_type="DoF") rt.setup_light("l1", pos=[8, -3, 13], color=1.5 * np.array([0.99, 0.97, 0.93]), radius=5) rt.setup_light("l2", pos=[-17, -7, 5], u=[0, 0, -10], v=[0, 14, 0], color=1 * np.array([0.25, 0.28, 0.35]), light_type="Parallelogram") rt.set_ambient([0.05, 0.07, 0.09]) rt.set_background(0) rt.show() print("done")
# plot.setup_light("l1", color=1*np.array([0.99, 0.95, 0.9]), radius=3) plot.set_background(fname) plot.set_ambient(0.1) # for i in range(1,6): # points = np.load(input_path+str(i)+".npz","r+")["arr_0"] points = generate_snowflake().T Fullpoints = np.zeros([points.shape[1], 3]) Fullpoints[:, 0] = points[0, :] #+10*i Fullpoints[:, 1] = points[1, :] # Fullpoints[:,2] = 2*i plot.set_data("flake" + str(1), Fullpoints, rad, c=[0.85, 0.85, 1], mat="ice", rnd=False, geom=Geometry(8)) # n = 100000 # 1M points, better not try this with matplotlib # xyz = 3 * (np.random.random((n, 3)) - 0.5) # random 3D positions # r = 0.02 * np.random.random(n) + 0.002 # random radii # plot = TkOptiX() # plot.set_data("my plot", xyz, r=r) # plot.get_rt_size() plot.show()