multiscalars.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. """A Volume can have multiple
  2. scalars associated to each voxel"""
  3. from vedo import dataurl, Volume, printc, show
  4. import numpy as np
  5. vol = Volume(dataurl+'vase.vti')
  6. nx, ny, nz = vol.dimensions()
  7. r0,r1 = vol.scalar_range()
  8. vol.add_scalarbar3d('original voxel scalars')
  9. # create a set of scalars and add it to the Volume
  10. vol.pointdata["myscalars1"] = np.linspace(r0,r1, num=nx*ny*nz)
  11. # create another set of scalars and add it to the Volume
  12. vol.pointdata["myscalars2"] = np.random.randint(-100,+100, nx*ny*nz)
  13. # make SLCImage scalars the active array (can set 0, to pick the first):
  14. printc('Arrays in Volume are:', vol.pointdata.keys(), invert=True)
  15. vol.pointdata.select("SLCImage") # select the first data array as the active one
  16. # Build the isosurface of the active scalars,
  17. # but use testscals1 to colorize this isosurface, and then smooth it
  18. iso1 = vol.isosurface().cmap('rainbow', 'myscalars1').smooth()
  19. iso1.add_scalarbar3d('myscalars1')
  20. iso2 = vol.isosurface().cmap('viridis', 'myscalars2')
  21. iso2.add_scalarbar3d('myscalars2')
  22. show([(vol, __doc__),
  23. (iso1,"Colorize isosurface using\nmyscalars1"),
  24. (iso2,"Colorize isosurface using\nmyscalars2"),
  25. ], N=3, axes=1
  26. ).close()