slice_plane1.py 1.1 KB

1234567891011121314151617181920212223242526272829
  1. """Slice a Volume with an arbitrary plane
  2. hover the plane to get the scalar values"""
  3. from vedo import dataurl, precision, Sphere, Volume, Plotter
  4. def func(evt):
  5. if not evt.object:
  6. return
  7. pid = evt.object.closest_point(evt.picked3d, return_point_id=True)
  8. txt = f"Probing:\n{precision(evt.object.picked3d, 3)}\nvalue = {arr[pid]}"
  9. pts = evt.object.points
  10. sph = Sphere(pts[pid]).c('orange7').pickable(False)
  11. fp = sph.flagpole(txt, s=7, offset=(-150,15), font=2).follow_camera()
  12. # remove old and add the two new objects
  13. plt.remove('Sphere', 'FlagPole').add(sph, fp).render()
  14. vol = Volume(dataurl+'embryo.slc')
  15. vol.cmap('white').alpha([0,0,0.8]).pickable(False)
  16. vslice = vol.slice_plane(vol.center(), [0,1,1])
  17. vslice.cmap('Purples_r').add_scalarbar('Slice', c='w')
  18. arr = vslice.pointdata[0] # retrieve vertex array data
  19. print("slice shape :", vslice.metadata["shape"])
  20. print("slice bounds:", vslice.metadata["original_bounds"])
  21. plt = Plotter(axes=9, bg='k', bg2='bb')
  22. plt.add_callback('as my mouse moves please call', func) # be kind to vedo ;)
  23. plt.show(vol, vslice, __doc__)
  24. plt.close()