def showSolution3D(S, start, goal): from vedo import Text, Cube, Line, Grid, merge, show pts, cubes, txts = [], [], [] pts = [(x, -y) for y, x in S[0]] for y, line in enumerate(Z): for x, c in enumerate(line): if c: cubes.append(Cube([x, -y, 0])) path = Line(pts).lw(6).c('tomato') walls = merge(cubes).clean().flat().texture('wood1') sy, sx = S[1].shape gradient = np.flip(S[1], axis=0).ravel() grd = Grid(pos=((sx - 1) / 2, -(sy - 1) / 2, -0.49), sx=sx, sy=sy, resx=sx, resy=sy) grd.lw(0).wireframe(False).cmap('gist_earth_r', gradient, mode='cells') grd.addScalarBar(title='Gradient', horizontal=True, c='k', nlabels=2) txts.append(__doc__) txts.append(Text('Start', pos=[start[1] - 1, -start[0] + 1.5, 1], c='k')) txts.append(Text('Goal!', pos=[goal[1] - 2, -goal[0] - 2.7, 1], c='k')) show(path, walls, grd, txts, axes=0, zoom=1.2)
def test_text_3d(scene): # Text to add s = "BRAINRENDER" # Specify a color for each letter colors = makePalette(len(s), "salmon", "powderblue") x = 0 # use to specify the position of each letter # Add letters one at the time to color them individually for n, letter in enumerate("BRAINRENDER"): if "I" == letter or "N" == letter and n < 5: # make the spacing right x += 0.6 else: x += 1 # Add letter and silhouette to the scne act = Text(letter, depth=0.5, c=colors[n], pos=(x, 0, 0), justify="centered") sil = act.silhouette().lw(3).color("k") scene.add_actor(act, sil) scene.render(interactive=False) scene.close()
def make_actor_label( atlas, actors, labels, size=300, color=None, radius=100, xoffset=0, yoffset=-500, zoffset=0, ): """ Adds a 2D text ancored to a point on the actor's mesh to label what the actor is :param kwargs: key word arguments can be passed to determine text appearance and location: - size: int, text size. Default 300 - color: str, text color. A list of colors can be passed if None the actor's color is used. Default None. - xoffset, yoffset, zoffset: integers that shift the label position - radius: radius of sphere used to denote label anchor. Set to 0 or None to hide. """ offset = [-yoffset, -zoffset, xoffset] default_offset = np.array([0, -200, 100]) new_actors = [] for n, (actor, label) in enumerate(zip(listify(actors), listify(labels))): # Get label color if color is None: color = actor.c() # Get mesh's highest point points = actor.points().copy() point = points[np.argmin(points[:, 1]), :] point += np.array(offset) + default_offset try: if atlas.hemisphere_from_coords(point, as_string=True) == "left": point = atlas.mirror_point_across_hemispheres(point) except IndexError: pass # Create label txt = Text(label, point, s=size, c=color) txt._kwargs = dict( size=size, color=color, radius=radius, xoffset=xoffset, yoffset=yoffset, zoffset=zoffset, ) new_actors.append(txt) # Mark a point on Mesh that corresponds to the label location if radius is not None: pt = actor.closestPoint(point) sphere = Sphere(pt, r=radius, c=color) sphere.ancor = pt new_actors.append(sphere) return new_actors
def build_keyboard(self): nts = ("C", "D", "E", "F", "G", "A", "B") tol = 0.12 keybsize = 16.5 # in cm, span of one octave wb = keybsize / 7 nr_octaves = 7 span = nr_octaves * wb * 7 self.vp = Plotter(title='PianoPlayer ' + __version__, axes=0, size=(1400, 700), bg='cornsilk', bg2='lb') #wooden top and base self.vp += Box(pos=(span / 2 + keybsize, 6, 1), length=span + 1, height=3, width=5).texture('wood1') self.vp += Box(pos=(span / 2 + keybsize, 0, -1), length=span + 1, height=1, width=17).texture('wood1') self.vp += Text('PianoPlayer ^' + __version__ + " ", pos=(18, 5., 2.3), depth=.5, c='silver', italic=0.8) leggio = Box(pos=(span / 1.55, 8, 10), length=span / 2, height=span / 8, width=0.08, c=(1, 1, 0.9)).rotateX(-20) self.vp += leggio.texture('paper1') self.vp += Text('Playing:\n' + self.songname[-30:].replace('_', "\\_"), font="Theemim", vspacing=3, depth=0.04, s=1.35, c='k', italic=0.5).rotateX(70).pos([55, 10, 6]) for ioct in range(nr_octaves): for ik in range(7): #white keys x = ik * wb + (ioct + 1) * keybsize + wb / 2 tb = Box(pos=(x, -2, 0), length=wb - tol, height=1, width=12, c='white') self.KB.update({nts[ik] + str(ioct + 1): tb}) self.vp += tb if not nts[ik] in ("E", "B"): #black keys tn = Box(pos=(x + wb / 2, 0, 1), length=wb * .6, height=1, width=8, c='black') self.KB.update({nts[ik] + "#" + str(ioct + 1): tn}) self.vp += tn cam = dict(pos=(110, -51.1, 89.1), focalPoint=(81.5, 0.531, 2.82), viewup=(-0.163, 0.822, 0.546), distance=105, clippingRange=(41.4, 179)) self.vp.show(interactive=0, camera=cam, resetcam=0)
\intx\dot~dx = \onehalf x\^2 + const. d^2 x^\mu + \Gamma^\mu_\alpha\beta ~dx^\alpha ~dx^\beta = 0 -∇\^2u(x) = f(x) in Ω, u(x)~=~u_D (x) in \partial\Omega Protect underscore \\\_ and \\\^ with a backslash. """ plt = Plotter(N=4, pos=(300, 0), size=(1600, 950)) cam = dict(pos=(3.99e+5, 8.51e+3, 6.47e+5), focalPoint=(2.46e+5, 1.16e+5, -9.24e+3), viewup=(-0.0591, 0.983, 0.175), distance=6.82e+5, clippingRange=(5.26e+5, 8.92e+5)) for i, fnt in enumerate(["Kanopus", "Normografo", "Theemim", "VictorMono"]): t = Text(txt, font=fnt, italic=0).c('darkblue').scale(12300) plt.show( t, Text2D("3D font: " + fnt, font=fnt, bg='r'), axes=dict( xtitle='my units for L_x (\mum)', ytitle='my Y-axis with\na long description', titleFont=fnt, labelFont=fnt, digits=2, yTitleOffset=-.015, xLabelSize=0.015, yLabelSize=0.015, zLabelSize=0.015, ), at=i,
) # Text to add s = "BRAINRENDER" # Specify a color for each letter colors = makePalette(len(s), "salmon", "powderblue") x = 0 # use to specify the position of each letter # Add letters one at the time to color them individually for n, letter in enumerate("BRAINRENDER"): if "I" == letter or "N" == letter and n < 5: # make the spacing right x += 0.6 else: x += 1 # Add letter and silhouette to the scene act = Text( letter, depth=0.5, c=colors[n], pos=(x, 0, 0), justify="centered", alpha=1, ) scene.add_silhouette(act, lw=3) scene.render()
def make_actor_label( atlas, actors, labels, size=300, color=None, radius=100, xoffset=0, yoffset=0, zoffset=0, ): """ Adds a 2D text ancored to a point on the actor's mesh to label what the actor is :param kwargs: key word arguments can be passed to determine text appearance and location: - size: int, text size. Default 300 - color: str, text color. A list of colors can be passed if None the actor's color is used. Default None. - xoffset, yoffset, zoffset: integers that shift the label position - radius: radius of sphere used to denote label anchor. Set to 0 or None to hide. """ # Check args if not isinstance(actors, (tuple, list)): actors = [actors] if not isinstance(labels, (tuple, list)): labels = [labels] if atlas.atlas_name == "ABA": offset = [-yoffset, -zoffset, xoffset] default_offset = np.array([0, -200, 100]) else: offset = [xoffset, yoffset, zoffset] default_offset = np.array([100, 0, -200]) new_actors = [] for n, (actor, label) in enumerate(zip(actors, labels)): if not isinstance(actor, Mesh): raise ValueError( f"Mesh must be an instance of Mesh, not {type(actor)}") if not isinstance(label, str): raise ValueError(f"Label must be a string, not {type(label)}") # Get label color if color is None: color = actor.c() elif isinstance(color, (list, tuple)): color = color[n] # Get mesh's highest point points = actor.points().copy() point = points[np.argmin(points[:, 1]), :] point += np.array(offset) + default_offset try: if atlas.hemisphere_from_coords(point, as_string=True) == "left": point = atlas.mirror_point_across_hemispheres(point) except IndexError: pass # Create label txt = Text(label, point, s=size, c=color) txt._original_actor = actor txt._label = label txt._kwargs = dict( size=size, color=color, radius=radius, xoffset=xoffset, yoffset=yoffset, zoffset=zoffset, ) new_actors.append(txt) # Mark a point on Mesh that corresponds to the label location if radius is not None: pt = actor.closestPoint(point) sphere = Sphere(pt, r=radius, c=color) sphere.ancor = pt new_actors.append(sphere) return new_actors
from vedo import settings, Volume, Text, show, datadir settings.fontIsMono = False settings.fontLSpacing = 0.2 settings.fontHSpacing = 0.5 vol = Volume(datadir + "embryo.slc") vol.mode(1).c('b2') # vol.mode(1).c(['dr','dr','dr','dr', 'dg', 'dg', 'db', 'db', 'db']) # vol.mode(0).c('b2') t = Text("Sharpe\n~~~Lab", s=40, font="./Spears.npz", vspacing=1.4, depth=.04) t.c('k1').rotateX(90).pos(200, 150, 70) cam = dict(pos=(363, -247, 121), focalPoint=(240, 137, 116), viewup=(4.45e-3, 0.0135, 1.00), distance=403, clippingRange=(36.0, 874)) show( vol, t, size=(700, 400), camera=cam, # elevation=-89, zoom=2, )
# Fit points and evaluate, with a boostrap and Monte-Carlo technique, # the correct errors and error bands. Return a Line object: pfit = fit( [x, y + noise], deg=deg, # degree of the polynomial niter=500, # nr. of MC iterations to compute error bands nstd=2, # nr. of std deviations to display xerrors=xerrs, # optional array of errors on x yerrors=yerrs, # optional array of errors on y vrange=(-3, 15), # specify the domain of fit ) plt += [pfit, pfit.errorBand, *pfit.errorLines] # add these objects to Plot txt = "fit coefficients:\n " + precision(pfit.coefficients, 2) \ + "\n\pm" + precision(pfit.coefficientErrors, 2) \ + "\n\Chi^2_\nu = " + precision(pfit.reducedChi2, 3) plt += Text(txt, s=0.42, font='VictorMono').pos(2, -2).c('k') # Create an histo to show the correlation of fit parameters h = histogram(pfit.MonteCarloCoefficients[:, 0], pfit.MonteCarloCoefficients[:, 1], title="parameters correlation", xtitle='coeff_0', ytitle='coeff_1', cmap='bone_r', scalarbar=True) h.scale(150).shift(-1, 11) # make it a lot bigger and move it show(plt, h, zoom=1.2)