from vedo import makeLUT, Sphere mesh = Sphere().lineWidth(0.1) # create some data array to be associated to points data = mesh.points()[:, 2] data[10:20] = float('nan') # Build a lookup table of colors: # scalar color alpha lut = makeLUT( [ (-0.80, 'pink'), (-0.33, 'green', 0.8), (0.67, 'red'), ], vmin=-1, vmax=1, aboveColor='grey', belowColor='white', interpolate=False, ) mesh.cmap(lut, data).addScalarBar() mesh.show(axes=1, viewup='z')
"""Build a custom colormap, including out-of-range and NaN colors and labels""" from vedo import buildLUT, Sphere, show, settings # settings.useDepthPeeling = True # might help with transparencies # generate a sphere and stretch it, so it sits between z=-2 and z=+2 mesh = Sphere(quads=True).scale([1,1,2]).lineWidth(0.1) # create some dummy data array to be associated to points data = mesh.points()[:,2] # pick z-coords, use them as scalar data data[10:70] = float('nan') # make some values invalid by setting to NaN data[300:600] = 100 # send some values very far above-scale # build a custom LookUp Table of colors: # value, color, alpha lut = buildLUT([ #(-2, 'pink' ), # up to -2 is pink (0.0, 'pink' ), # up to 0 is pink (0.4, 'green', 0.5), # up to 0.4 is green with alpha=0.5 (0.7, 'darkblue' ), #( 2, 'darkblue' ), ], vmin=-1.2, belowColor='lightblue', vmax= 0.7, aboveColor='grey', nanColor='red', interpolate=False, ) # 3D scalarbar: mesh.cmap(lut, data).addScalarBar3D(title='My 3D scalarbar', c='white') mesh.scalarbar.scale(1.5).rotateX(90).y(1) # make it bigger and place it
print('---------------------------------') print('vtkVersion', vtk.vtkVersion().GetVTKVersion()) print('---------------------------------') ##################################### cone = Cone(res=48) sphere = Sphere(res=24) carr = cone.cellCenters()[:, 2] parr = cone.points()[:, 0] cone.addCellArray(carr, 'carr') cone.addPointArray(parr, 'parr') carr = sphere.cellCenters()[:, 2] parr = sphere.points()[:, 0] sphere.addCellArray(carr, 'carr') sphere.addPointArray(parr, 'parr') sphere.addPointArray(np.sin(sphere.points()), 'pvectors') sphere.addElevationScalars() cone.computeNormals() sphere.computeNormals() ###################################### test clone() c2 = cone.clone() print('clone()', cone.N(), c2.N()) assert cone.N() == c2.N() print('clone()', cone.NCells(), c2.NCells())
print('---------------------------------') print('vtkVersion', vtk.vtkVersion().GetVTKVersion()) print('---------------------------------') ##################################### cone = Cone(res=48) sphere = Sphere(res=24) carr = cone.cellCenters()[:, 2] parr = cone.points()[:, 0] cone.pointdata["parr"] = parr cone.celldata["carr"] = carr carr = sphere.cellCenters()[:, 2] parr = sphere.points()[:, 0] sphere.pointdata["parr"] = parr sphere.celldata["carr"] = carr sphere.pointdata["pvectors"] = np.sin(sphere.points()) sphere.addElevationScalars() cone.computeNormals() sphere.computeNormals() ###################################### test clone() c2 = cone.clone() print('clone()', cone.N(), c2.N()) assert cone.N() == c2.N()