txt = Text2D('..' + data.filename[-30:], font='MonospaceTypewriter') plt.show(vol, msh, sb, box, txt, at=index, interactorStyle=6) def func(widget, event): i = int(widget.GetRepresentation().GetValue()) plt.renderer = widget.GetCurrentRenderer() plt.resetcam = False msh = vol.zSlice(i).lighting('off') msh.pointColors(cmap=cmaps[index], vmin=vmin, vmax=vmax) plt.remove(visibles[0], render=False) if 0 < i < dims[2]: zlev = zb[1] / (zb[1] - zb[0]) * i + zb[0] plt.add([msh, sb.z(zlev)]) visibles[0] = msh return func ###################################################################### plt = Plotter(shape=(1, 3), sharecam=False, bg2='lightcyan') for index, data in enumerate(volumes): plt.addSlider2D(slicerfunc(index, data), 0, data.dimensions()[2], value=0, pos=(sliderstart, sliderstop)) printc("Right click to rotate, use slider to slice along z.", box='-') plt.show(interactive=True)
def slider1(widget, event): value = widget.GetRepresentation().GetValue() mesh.color(value) def slider2(widget, event): value = widget.GetRepresentation().GetValue() mesh.alpha(value) vp = Plotter(axes=0) mesh = vp.load(dataurl + "magnolia.vtk").flat().lw(0.1) vp.addSlider2D(slider1, -9, 9, value=0, pos="bottom-right", title="color number") vp.addSlider2D(slider2, xmin=0.01, xmax=0.99, value=0.5, c="blue", pos="bottom-right-vertical", title="alpha value (opacity)") vp += __doc__ vp.show()
pts = grid.points().tolist() + grid.cellCenters().tolist() # Create the mirror by merging many (y-scaled) cylinders into a single mesh object cyls = [ Cylinder(p, r=0.065, height=0.2, res=720).scale([1, 1.5, 1]) for p in pts ] mirror = Mirror(merge(cyls)).color("silver") # Create a detector surface as a thin cylinder surrounding the mirror sd = Cylinder(r=1, height=0.3, cap=False).cutWithPlane([0, -0.95, 0], normal='y') detector = Detector(sd) def slider(widget, event): ### callback to shift the beam along x dx = widget.GetRepresentation().GetValue() ray = Ray([dx, -1.2, -0.1], direction=(0, 1, 0.02)) ray.maxiterations = 1000 # max nr. of reflections ray.trace([mirror, detector]) # cumpute trajectory detector.count().cmap("Reds", on='cells', vmax=10) line = ray.asLine().lineWidth(4).c('green5') if plt.actors[-1].name == "Line": plt.pop() # remove the last Line plt.add(line) # add the new one plt = Plotter(axes=1, bg='peachpuff', bg2='blue9') plt.addSlider2D(slider, -0.07, 0.07, value=0, pos=5, title="beam shift") plt.show(mirror, detector, __doc__, elevation=-30) plt.close()
""" from vedo import Plotter, datadir def slider1(widget, event): value = widget.GetRepresentation().GetValue() mesh.color(value) def slider2(widget, event): value = widget.GetRepresentation().GetValue() mesh.alpha(value) vp = Plotter(axes=0) mesh = vp.load(datadir + "magnolia.vtk").flat().lw(0.1) # pos = position corner number: horizontal [1-4] or vertical [11-14] vp.addSlider2D(slider1, -9, 9, value=0, pos=4, title="color number") vp.addSlider2D(slider2, xmin=0.01, xmax=0.99, value=0.5, pos=14, c="blue", title="alpha value (opacity)") vp += __doc__ vp.show()
centers = [] pb = ProgressBar(0, len(data)) for i, d in data.iterrows(): pb.print("Parsing USGS data..") M = d['mag'] # earthquake estimated magnitude E = np.sqrt(np.exp(5.24+1.44*M) * scale[0])/10000 # empirical formula for sqrt(energy_release(M)) rgb = colorMap(E, name='Reds', vmin=0, vmax=7) # map energy to color lat, lon = np.deg2rad(d['latitude']), np.deg2rad(d['longitude']) ce = GeoCircle(lat, lon, E/50).scale(scale).z(num/M).c(rgb).lw(0.1).useBounds(False) ce.time = i ce.info = '\n'.join(str(d).split('\n')[:-1]) # remove of the last line in string d #if M > 6.5: ce.alpha(0.8) # make the big ones slightly transparent if i < len(data)-num: ce.off() # switch off older ones: make circles invisible centers.append(ce) def sliderfunc(widget, event): value = widget.GetRepresentation().GetValue() # get the slider current value widget.GetRepresentation().SetTitleText(f"{data['time'][int(value)][:10]}") for ce in centers: isinside = abs(value-ce.time) < num # switch on if inside of time window ce.on() if isinside else ce.off() plt.render() plt = Plotter(size=(2200,1100), title="Earthquake Browser") plt.addSlider2D(sliderfunc, 0, len(centers)-1, value=len(centers)-1, showValue=False, title="today") plt.addHoverLegend(useInfo=True, alpha=1, c='white', bg='red2', s=1) comment = Text2D(__doc__, bg='green9', alpha=0.7) plt.show(pic, centers, comment, zoom=2.27, mode='image').close()
def set_time(widget, event): new_time = int(floor(widget.GetRepresentation().GetValue())) for t in range(0, max_time): if t == new_time: coord_acts[t].on() pol_acts[t].on() else: coord_acts[t].off() pol_acts[t].off() vp.addSlider2D(set_time, xmin=0, xmax=max_time - 1, value=0, pos=5, title="time") # set one time point and clone by default coord_acts[0].on() pol_acts[0].on() vp += buildAxes(xrange=(-4, 4), yrange=(-4, 4), zrange=(-2, 2)) vp += __doc__ vp.show(interactive=True, resetcam=False, viewup='z') # View as a non interactive time sequence # vp = Plotter(interactive=0) # vp.camera.SetPosition([20, 20, 10]) # vp.camera.SetFocalPoint([2.5, 2.5, 0]) # vp.camera.SetViewUp([0,0,1])