""" trimesh to vedo interoperability """ # Install trimesh with: # sudo apt install python3-rtree # pip install rtree shapely # conda install trimesh import trimesh import vedo from vedo import trimesh2vtk, vtk2trimesh url = 'https://raw.githubusercontent.com/mikedh/trimesh/master/models/' filename = vedo.download(url + 'machinist.XAML') mesh = trimesh.load(filename) vedo.show(mesh) # vedo visualizer (conversion is on the fly) # explicit conversion vmesh = trimesh2vtk(mesh) # returns a vedo.Mesh(vtkActor) object trimsh_reconverted = vtk2trimesh(vmesh) trimsh_reconverted.show() # this is the trimesh built-in visualizer
#g = Graph(layout='2d', zrange=7) g = DirectedGraph(layout='cone') #g = DirectedGraph(layout='circular3d', height=1, radius=1.5) #g = DirectedGraph(layout='force') # Vertex generation is automatic, # add a child to vertex0, so that now vertex1 exists g.addChild(0, edgeLabel="Mother giving birth\nto her little baby cell") g.addChild(1) g.addChild(1) g.addChild(2) g.addChild(2) g.addChild(2) g.addChild(3) g.addChild(3, edgeLabel="It's a male!") g.addChild(4) g.addChild(4) for i in range(7): g.addChild(5, nodeLabel="cell5_" + str(i)) g.addChild(7) g.addChild(7) g.addChild(7) g.build() # optimize layout g.unpack(0).color('dg').lineWidth( 3) #0=graph, 1=vertexLabels, 2=edgeLabels, 3=arrows g.unpack(2).color('dr') show(g, __doc__, axes=9, elevation=-40)
"""Share the same color map across different meshes """ from vedo import load, show, datadir ##################################### man1 = load(datadir+"man.vtk") scals = man1.points()[:, 2] * 5 + 27 # pick z coordinates [18->34] man1.cmap("rainbow", scals, vmin=18, vmax=44) ##################################### man2 = load(datadir+"man.vtk") scals = man2.points()[:, 2] * 5 + 37 # pick z coordinates [28->44] man2.cmap("rainbow", scals, vmin=18, vmax=44).addScalarBar() show([(man1, __doc__), man2], N=2, elevation=-40, axes=11)
# test on a sphere mesh mesh = trimesh.creation.icosphere() # create some rays ray_origins = np.array([[0, 0, -3], [1, 2, -3]]) ray_directions = np.array([[0, 0, 1], [0, -1, 1]]) # run the mesh-ray query locations, index_ray, index_tri = mesh.ray.intersects_location( ray_origins=ray_origins, ray_directions=ray_directions) locs = trimesh.points.PointCloud(locations) # stack rays into line segments for visualization as Path3D ray_visualize = trimesh.load_path( np.hstack((ray_origins, ray_origins + ray_directions)).reshape(-1, 2, 3)) print("The rays hit the mesh at coordinates:\n", locations) print("The rays with index: {} hit triangles stored at mesh.faces[{}]".format( index_ray, index_tri)) # stack rays into line segments for visualization as Path3D ray_visualize = trimesh.load_path( np.hstack( (ray_origins, ray_origins + ray_directions * 5.0)).reshape(-1, 2, 3)) # make mesh white-ish mesh.visual.face_colors = [200, 200, 250, 100] mesh.visual.face_colors[index_tri] = [255, 0, 0, 255] show(mesh, ray_visualize, locs, axes=1)
"""A simple scatter plot""" from vedo import show from vedo.pyplot import plot import numpy as np x = np.random.randn(100) + 10 y = np.random.randn(100) * 20 plt = plot( x, y, lw=0, xtitle="variable x", ytitle="variable y", aspect=4 / 3, # aspect ratio marker="*", # marker style mc="dr", # marker color axes=True, ) # show Assembly object and lock interaction to 2d: # (can zoom in a region w/ mouse, press r to reset) show(plt, __doc__, zoom=1.2, viewup='2d').close()
sin(state[2]) * cosa + M2 * L2 * state[3] * state[3] * sina - (M1 + M2) * G * sin(state[0])) / den1 dydx[2] = state[3] den2 = (L2 / L1) * den1 dydx[3] = (-M2 * L2 * state[3] * state[3] * sina * cosa + (M1 + M2) * G * sin(state[0]) * cosa - (M1 + M2) * L1 * state[1] * state[1] * sina - (M1 + M2) * G * sin(state[2])) / den2 return dydx t = np.arange(0.0, 10.0, dt) state = np.radians([th1, w1, th2, w2]) y = integrate.odeint(derivs, state, t) P1 = np.dstack([L1 * sin(y[:, 0]), -L1 * cos(y[:, 0])]).squeeze() P2 = P1 + np.dstack([L2 * sin(y[:, 2]), -L2 * cos(y[:, 2])]).squeeze() ax = Axes(xrange=(-2, 2), yrange=(-2, 1), htitle=__doc__) pb = ProgressBar(0, len(t), c="b") for i in pb.range(): j = max(i - 5, 0) k = max(i - 10, 0) l1 = Line([[0, 0], P1[i], P2[i]]).lw(7).c("blue2") l2 = Line([[0, 0], P1[j], P2[j]]).lw(6).c("blue2", 0.3) l3 = Line([[0, 0], P1[k], P2[k]]).lw(5).c("blue2", 0.1) pt = Points([P1[i], P2[i], P1[j], P2[j], P1[k], P2[k]], r=8).c("blue2", 0.2) show(l1, l2, l3, pt, ax, interactive=False, size=(900, 700), zoom=1.4) pb.print()
# load the mesh from filename, file objects are also supported f = download( 'https://github.com/mikedh/trimesh/raw/master/models/featuretype.STL') mesh = trimesh.load_mesh(f) # get a single cross section of the mesh txt = 'cross section of the mesh' mslice = mesh.section(plane_origin=mesh.centroid, plane_normal=[0, 0, 1]) pl = Plane(mesh.centroid, normal=[0, 0, 1], sx=6, sy=4, c='green', alpha=0.3) slice_2D, to_3D = mslice.to_planar() # show objects on N=2 non-synced renderers: show([(mesh, pl), (slice_2D, txt)], N=2, sharecam=False, axes=7) # if we wanted to take a bunch of parallel slices, like for a 3D printer # we can do that easily with the section_multiplane method # we're going to slice the mesh into evenly spaced chunks along z # this takes the (2,3) bounding box and slices it into [minz, maxz] z_extents = mesh.bounds[:, 2] # slice every .125 model units (eg, inches) z_levels = np.arange(*z_extents, step=0.125) # find a bunch of parallel cross sections sections = mesh.section_multiplane(plane_origin=mesh.bounds[0], plane_normal=[0, 0, 1], heights=z_levels) N = len(sections) printc("nr. of sections:", N, c='green')
ws.append(w) # print(i, 'whisker:\n', w.info) # build some theoretical expectation to be shown as a grey band x = np.linspace(-1, 9, 100) y = x / 5 + 0.2 * np.sin(x) ye = y**2 / 5 + 0.1 # error on y line = Line(np.c_[x, y]) band = Ribbon(np.c_[x, y - ye], np.c_[x, y + ye]).c('black', 0.1) # build braces to inndicate stats significance and dosage bra1 = Brace([0, 3], [2, 3], comment='*~*', s=0.7, style='[') bra2 = Brace([4, -1], [8, -1], comment='dose > 3~\mug/kg', s=0.7) # build custom axes axes = Axes( xrange=[-1, 9], yrange=[-3, 5], htitle='\beta_c -expression: change in time', xtitle=' ', ytitle='Level of \beta_c protein in \muM/l', xValuesAndLabels=[ (0, 'Experiment^A\nat t=1h'), (4, 'Experiment^B\nat t=2h'), (8, 'Experiment^C\nat t=4h'), ], xLabelSize=0.02, ) show(ws, bra1, bra2, line, band, __doc__, axes, zoom=1.1)
# np.random.seed(0) # Generate some noisy data points along a line x = np.linspace(0, 15, 25) a, b = (np.random.rand(2) - 0.5) * 10 # choose a and b y = a * x + b noise = np.random.randn(len(x)) * 5 # create gaussian noise # Plot the points and the "true" line without noise plt = plot(x, y + noise, '*k', title=__doc__) plt += DashedLine(x, y) # Fit points and evaluate, with a boostrap and Monte-Carlo technique, # the correct error coeffs and error bands. Return a Line object: pfit = fit( [x, y + noise], deg=1, # degree of the polynomial niter=500, # nr. of MC iterations to compute error bands nstd=2, # nr. of std deviations to display ) plt += [pfit, pfit.errorBand, *pfit.errorLines] # add these objects to Plot msg = f"Generated a, b : {np.array([a,b])}"\ f"\nFitted a, b : {pfit.coefficients}"\ f"\nerrors on a, b : {pfit.coefficientErrors}"\ f"\nave point spread: \sigma \approx {pfit.dataSigma:.3f} in y units" msg = Text2D(msg, font='VictorMono', pos='bottom-left', c='red3') show(plt, msg, interactorStyle="Image").close()
"""Identify and fill holes of an input mesh. Holes are identified by locating boundary edges, linking them together into loops, and then triangulating the resulting loops. """ from vedo import load, show, datadir a = load(datadir + "bunny.obj").lw(0.1).bc('red') # size = approximate limit to the size of the hole to be filled. b = a.clone().pos(.2, 0, 0).fillHoles(size=0.1) b.color("lb").bc('green').legend("filled mesh") show(a, b, __doc__, elevation=-70)
shape = load(datadir+"lamp.vtk") ms = [] cmaps = ("jet", "PuOr", "viridis") for i in range(3): s = shape.clone().pos(0, i*2.2, 0) # colorize mesh scals = s.points()[:,2] s.cmap(cmaps[i], scals) ms.append(s) # add 2D scalar bar to first mesh ms[0].addScalarBar(title="my scalarbar\nnumber #0") #2D # add 3D scalar bars ms[1].addScalarBar3D(c="k", title="scalarbar #1", sy=3) sc = ms[2].addScalarBar3D(pos=(1,0,-5), c="k", sy=2.8, # change y-size title="A viridis 3D\nscalarbar to play with", titleFont='Quikhand', titleXOffset=-2, # offset of labels titleSize=1.5) sc.rotateX(90) # make it vertical show(ms, __doc__, axes=1, viewup='z')
"""Interactively cut a set of meshes""" from vedo import dataurl, show, Volume # generate an isosurface the volume for each thresholds thresholds = [0.1, 0.25, 0.4, 0.6, 0.75, 0.9] # isos is of type Mesh isos = Volume(dataurl + 'quadric.vti').isosurface(thresholds) show(isos, __doc__, axes=1, interactive=False).addCutterTool(isos)
"""Share the same color and trasparency mapping across different volumes""" from vedo import Volume, Line, show import numpy as np arr = np.zeros(shape=(50, 50, 50)) for i in range(50): for j in range(50): for k in range(50): arr[i, j, k] = j vol1 = Volume(arr).mode(1).cmap('jet', alpha=[0, 1], vmin=0, vmax=80).addScalarBar("vol1") vol2 = Volume(arr + 30).mode(1).cmap('jet', alpha=[0, 1], vmin=0, vmax=80).addScalarBar("vol2") # or equivalently, to set transparency: # vol1.alpha([0,1], vmin=0, vmax=70) # can also manually build a scalarbar object to span the whole range: sb = Line([50, 0, 0], [50, 50, 0]).cmap('jet', [0, 70]).addScalarBar3D("vol2", c='black').scalarbar show([(vol1, __doc__), (vol2, sb)], N=2, axes=1)
#vedo.show(ms, axes=True) # this already works! pt = [0.0234, 0.0484, 0.0400] ms.colorize_by_geodesic_distance_from_a_given_point(startpoint=pt) mlab_mesh = ms.current_mesh() vedo_mesh = vedo.Mesh(mlab_mesh).cmap('Paired').addScalarBar("distance") print("Can convert back to pymeshlab.MeshSet:", type(vedo_mesh.to_meshlab())) vedo.show( __doc__, vedo_mesh, vedo.Point(pt), axes=True, bg='green9', bg2='blue9', title="vedo + pymeshlab", ) ################################################################################ # Full list of filters, https://pymeshlab.readthedocs.io/en/latest/filter_list.html # # MeshLab offers plenty of useful filters, among which: # # ambient_occlusion # compute_curvature_principal_directions # colorize_by_geodesic_distance_from_a_given_point # compute_normals_for_point_sets # compute_planar_section
"""Create a set of transparencies which can be passed to method pointColors() """ from vedo import load, show, datadir mesh = load(datadir + "beethoven.ply") # pick y coordinates of vertices and use them as scalars scals = mesh.points()[:, 1] # define opacities in the range of the scalar, # at min(scals) alpha is 0.1, # at max(scals) alpha is 0.9: alphas = [0.1, 0.1, 0.3, 0.4, 0.9] mesh.pointColors(scals, alpha=alphas, cmap="copper") # print(mesh.getPointArray('pointColors_copper')) # retrieve scalars show(mesh, __doc__, axes=9)
"""Set custom lights to a 3D scene""" from vedo import Plotter, load, dataurl, Point, Light, show man = load(dataurl + 'man.vtk').c('white').lighting('glossy') p1 = Point([1, 0, 1], c='y') p2 = Point([0, 0, 2], c='r') p3 = Point([-1, -0.5, -1], c='b') p4 = Point([0, 1, 0], c='k') # Add light sources at the given positions l1 = Light(p1, c='y') # p1 can simply be [1,0,1] l2 = Light(p2, c='r') l3 = Light(p3, c='b') l4 = Light(p4, c='w', intensity=0.5) show(man, l1, l2, l3, l4, p1, p2, p3, p4, __doc__, axes=1, viewup='z') ##################################################### ##### Equivalent code using a Plotter instance: ##### ##################################################### # plt = Plotter(axes=1) # plt += [man, p1, p2, p3, p4, l1, l2, l3, l4] # plt.show(viewup='z') #####################################################
g.addChild(i) for i in range(3): g.addChild(i) for i in range(7, 9): g.addChild(i) for i in range(3): g.addChild(12) # add 3 children to node 12 g.addEdge(1, 16) ##################### build and draw graph = g.build().unpack(0).lineWidth(4) # get the vedo 3d graph lines nodes = graph.points() # get the 3d points of the nodes pts = Points(nodes, r=10).lighting('off') v1 = ['node' + str(n) for n in range(len(nodes))] v2 = [sin(x) for x in range(len(nodes))] labs1 = pts.labels(v1, scale=.02, italic=True).shift(.05, 0.02, 0).c('green') labs2 = pts.labels(v2, scale=.02, precision=3).shift(.05, -.02, 0).c('red') # Interpolate the node value to color the edges: graph.cmap('viridis', v2).addScalarBar3D(c='k') graph.scalarbar.shift(.3, 0, 0) pts.cmap('viridis', v2) # This would colorize the edges directly with solid color based on a v3 array: # v3 = [sin(x) for x in range(graph.NCells())] # graph.cmap('jet', v3).addScalarBar() show(pts, graph, labs1, labs2, __doc__, axes=9)
##################################################################################### ##################################################################################### # THE FOLLOWING CODE DOES THE SAME AND IT IS MEANT TO ILLUSTRATE # HOW THE slicer() METHOD WORKS INTERNALLY: from vedo import * ################################ prepare the scene #vol = Volume(10*np.random.randn(300,250,200)+100) # test vol = load(filename) #.printInfo() box = vol.box().wireframe().alpha(0) # make an invisible box vp = show(box, axes=1, bg='white', bg2='lightblue', size=(850, 700), title=filename, interactive=False, newPlotter=True) vp.showInset(vol, pos=(1, 1), size=0.3, draggable=False) ################# inits visibles = [None, None, None] cmaps = ["gist_ncar_r", "jet", "Spectral_r", "hot_r", "gist_earth_r", "bone_r"] cmap = cmaps[0] dims = vol.dimensions() i_init = int(dims[2] / 2) msh = vol.zSlice(i_init).pointColors(cmap=cmap).lighting('plastic') msh.addScalarBar(pos=(0.04, 0.0), horizontal=True, titleFontSize=0) vp.renderer.AddActor(msh) visibles[2] = msh
np.random.seed(1) data = np.random.uniform(0, 1, (25, 100)) X = np.linspace(-1, 1, data.shape[-1]) G = 0.15 * np.exp(-4 * X**2) # use a gaussian as a weight # Generate line plots lines = [] for i in range(len(data)): pts = np.c_[X, np.zeros_like(X) + i / 10, G * data[i]] lines.append(Line(pts, lw=3)) # Set up the first frame axes = dict(xtitle='\Deltat /\mus', ytitle="source", ztitle="") plt = show(lines, __doc__, axes=axes, elevation=-30, interactive=False, bg='k8') # vd = Video("anim_lines.mp4") for i in range(50): data[:, 1:] = data[:, :-1] # Shift data to the right data[:, 0] = np.random.uniform(0, 1, len(data)) # Fill-in new values for i in range(len(data)): # Update data newpts = lines[i].points() newpts[:, 2] = G * data[i] lines[i].points(newpts).cmap('gist_heat_r', newpts[:, 2]) plt.show() if plt.escaped: break # if ESC is hit during the loop # vd.addFrame() # vd.close()
"""Custom color and transparency maps for Volumes""" from vedo import load, datadir, show from vedo.pyplot import cornerHistogram # Build a Volume object. # A set of color/transparency values - of any length - can be passed # to define the transfer function in the range of the scalar. # E.g.: setting alpha=[0, 0, 0, 1, 0, 0, 0] would make visible # only voxels with value close to center of the range (see histogram). vol = load(datadir + 'embryo.slc') # returns a Volume vol.color([ (0, "green"), (49, "green"), (50, "blue"), (109, "blue"), (110, "red"), (180, "red"), ]) # vol.mode('max-projection') vol.alpha([0., 1.]) vol.alphaUnit(8) # absorption unit, higher factors = higher transparency vol.addScalarBar3D(title='color~\dot~alpha transfer function', c='k') ch = cornerHistogram(vol, logscale=True, pos='bottom-left') # show both Volume and Mesh show(vol, ch, __doc__, axes=1, zoom=1.2)
import numpy as np ################################################################################## 2D for i, f in enumerate(fonts): Text2D( f + ': The quick fox jumps over the lazy dog. 1234567890 αβγδεθλμνπστφψω', pos=(.015, 1 - (i + 3) * .06), font=f, s=1.3, c='k') Text2D("List of Available Fonts", pos='top-center', bg='k', s=1.1) show(..., bg2='cornsilk', axes=False, zoom=1.2, size=(1200, 700), interactive=False) ################################################################################## 3D # Symbols ~ ^ _ are reserved modifiers: # use ~ to add a short space, 1/4 of the default size, # use ^ and _ to start up/sub scripting, a space terminates them. txt = """The quick fox jumps over the lazy dog. Symbols: !@#$%&*()+=-{}[]:;|<>?/\euro1234567890\~ Units: \delta=0.25E-03 ~μm, T_sea ~=~5.3~±0.7~\circC LaTeX: \nabla\dotE=~4\pi~\rho, \nabla\timesE=~-1/c~~\partialB/\partialt ih~\partial/\partialt~\Psi = [-h^2 /2m\nabla^2 + V(r,t)]~\Psi(r,t) \DeltaE~=~h\nu, y = \Sigma_n ~A_n cos(\omega_n t+\delta_n ) sin(k_n x) \intx\dot~dx = \onehalf x\^2 + const. d^2 x^\mu + \Gamma^\mu_\alpha\beta ~dx^\alpha ~dx^\beta = 0
v_cyclic=True, function=one_sheet_hyperboloid, adaptor_class=VtkAdaptor, ) poly_data = DodecaTessagon(**options).create_mesh() dodeca = Mesh(poly_data).x(5).computeNormals() dodeca.lineWidth(1).backColor('tomato') # --------------------------------------------------------- def chubby_torus(u, v): return general_torus(5, 1.5, v, warp_var(u, 0.2)) options = dict( u_range=[0.0, 1.0], v_range=[0.0, 1.0], u_num=2, v_num=12, color_pattern=1, function=chubby_torus, adaptor_class=VtkAdaptor, ) poly_data = FloretTessagon(**options).create_mesh() poly_data.GetCellData().GetScalars().SetName("color_pattern") floret = Mesh(poly_data).reverse().y(-9).scale(0.7) floret.cmap('Greens_r', input_array="color_pattern", mode='cells').lineWidth(0.1) # --------------------------------------------------------- show(rhombus, dodeca, floret, __doc__, axes=1)
"""Koch snowflake fractal""" from vedo import sqrt, Line, show levels = 7 def koch(level): # Compute Koch fractal contour points k = sqrt(3)/2 if level: points = koch(level-1) + [(0, 0)] # recursion! kpts = [] for i in range(len(points)-1): p1, p2 = points[i], points[i+1] dx, dy = (p2[0]-p1[0])/3, (p2[1]-p1[1])/3 pa = (p1[0] + dx , p1[1] + dy ) pb = (p1[0] + dx*2, p1[1] + dy*2) z = complex(pb[0]-pa[0], pb[1]-pa[1]) * (0.5-k*1j) p3 = (pa[0]+z.real, pa[1]+z.imag) kpts += [p1, pa, p3, pb] return kpts else: return [(0, 0), (1, 0), (0.5, k)] kochs = [] for i in range(levels): # Create a Line from the points and mesh the inside with minimum resolution kmsh = Line(koch(i)).tomesh(resMesh=1).lw(0).color(-i).z(-i/1000) kochs.append(kmsh) show(kochs, __doc__+ f"\nlevels: {levels}\npoints: {kmsh.N()}", axes=10).close()
u[...] = 1.0 U[n // 2 - r:n // 2 + r, n // 2 - r:n // 2 + r] = 0.50 V[n // 2 - r:n // 2 + r, n // 2 - r:n // 2 + r] = 0.25 u += 0.05 * np.random.uniform(-1, 1, (n, n)) v += 0.05 * np.random.uniform(-1, 1, (n, n)) sy, sx = V.shape grd = Grid(sx=sx, sy=sy, resx=sx, resy=sy) grd.lineWidth(0).wireframe(False).lighting(ambient=0.5) formula = r'(u,v)=(D_u\cdot\Delta u -u v v+F(1-u), D_v\cdot\Delta v +u v v -(F+k)v)' ltx = Latex(formula, s=15, pos=(0, -sy / 1.9, 0)) print('Du, Dv, F, k, name =', Du, Dv, F, k, name) for step in range(Nsteps): for i in range(25): Lu = (U[0:-2, 1:-1] + U[1:-1, 0:-2] - 4 * U[1:-1, 1:-1] + U[1:-1, 2:] + U[2:, 1:-1]) Lv = (V[0:-2, 1:-1] + V[1:-1, 0:-2] - 4 * V[1:-1, 1:-1] + V[1:-1, 2:] + V[2:, 1:-1]) uvv = u * v * v u += Du * Lu - uvv + F * (1 - u) v += Dv * Lv + uvv - (F + k) * v grd.cmap('ocean_r', V.ravel(), on='cells', arrayName="escals") grd.mapCellsToPoints() newpts = grd.points() newpts[:, 2] = grd.getPointArray('escals') * 25 # assign z grd.points(newpts) # set the new points show(ltx, grd, zoom=1.25, elevation=-.15, bg='linen', interactive=False) interactive()
"""Read and show meshio objects""" import meshio from vedo import datadir, show, Mesh mesh = meshio.read(datadir+'shuttle.obj') # vedo understands meshio format for polygonal data: #show(mesh, __doc__) # explicitly convert it to a vedo.Mesh object: m = Mesh(mesh).lineWidth(1).color('tomato').printInfo() show(m, __doc__)
y2 = 3 * np.exp(-x) * np.cos(2 * x)**2 axes_opts = dict(numberOfDivisions=3, xyPlaneColor='lavender', xyAlpha=1) # Build first plot and its axes: plt1 = plot( x, y1, title=__doc__, xtitle='time in seconds', ytitle='some function [a.u.]', ) # Build second plot and its axes: plt2 = plot( x, y2, title='my second plot', xtitle='time in seconds', ytitle='some other function', lc='red', pad=0, # no margins axes=axes_opts, ) # Scale the plot2 to make it small # and position it anywhere in the scene: plt2.scale(0.5).pos(2, 1.4, 0.01) show(plt1, plt2, zoom=1.1)
"""Computes the signed distance of one mesh from another """ from vedo import Sphere, Cube, show s1 = Sphere() s2 = Cube(pos=[1, 0, 0], c='white', alpha=0.4) s1.distanceToMesh(s2, signed=True, negate=False) s1.addScalarBar(title='Signed\nDistance') #print(s1.getPointArray("Distance")) show(s1, s2, __doc__, axes=11).close()
import pyshtools from scipy.interpolate import griddata from vedo import Points, load, mag, show, spher2cart, datadir print(__doc__) ############################################################# lmax = 10 # maximum degree of the spherical harm. expansion N = 50 # number of grid intervals on the unit sphere rmax = 1.5 # line length x0 = [0, 0, 0] # set object at this position ############################################################# shape = load(datadir + 'apple.ply').normalize().pos(x0).lineWidth(0.1) show(shape, at=0, N=2, axes=dict(zxGrid=False)) ############################################################ # cast rays from the center and find intersections agrid, pts = [], [] for th in np.linspace(0, np.pi, N, endpoint=0): lats = [] for ph in np.linspace(0, 2 * np.pi, N, endpoint=0): p = spher2cart(rmax, th, ph) intersections = shape.intersectWithLine([0, 0, 0], p) if len(intersections): value = mag(intersections[0]) lats.append(value) pts.append(intersections[0]) else: lats.append(rmax)
from vedo import Mesh, dataurl, show shape = Mesh(dataurl + "lamp.vtk") ms = [] cmaps = ("jet", "PuOr", "viridis") for i in range(3): s = shape.clone(deep=False).pos(0, i * 2.2, 0) # colorize mesh scals = s.points()[:, 2] s.cmap(cmaps[i], scals) ms.append(s) # add 2D scalar bar to first mesh ms[0].addScalarBar(title="my scalarbar\nnumber #0") #2D # add 3D scalar bars ms[1].addScalarBar3D(c="k", title="scalarbar #1", sy=3) sc = ms[2].addScalarBar3D( pos=(1, 0, -5), c="k", sy=2.8, # change y-size title="A viridis 3D\nscalarbar to play with", titleFont='Quikhand', titleXOffset=-2, # offset of labels titleSize=1.5) sc.scalarbar.rotateX(90) # make it vertical show(ms, __doc__, axes=1, viewup='z').close()