scale = 10 / 170.258 # New legnth [um] / old length [px] folder = 'res/pipe00' # iframes_raw = list(range(1, 18, 2)) + [18] + list(range(21, 42, 2)) shapes = [] for iframe_raw in iframes_raw: xname = os.path.join(folder, 'x-{}.dat'.format(iframe_raw)) yname = os.path.join(folder, 'y-{}.dat'.format(iframe_raw)) zname = os.path.join(folder, 'z-{}.dat'.format(iframe_raw)) xx = scale * np.loadtxt(xname) yy = scale * np.loadtxt(yname) zz = scale * np.loadtxt(zname) cc = colors[iframe_raw] # shapes are starting from 1 c = tuple(cc[:3]) # discard opacity shape = vedo.Tube(list(zip(zz, xx, yy)), r=0.125, c=c) shapes += [shape] # ===== final ===== # + shift folder = 'res/pipe_final' # iframes_raw = list(range(20)) x = np.loadtxt(os.path.join(folder, 'x-data')) y = np.loadtxt(os.path.join(folder, 'y-data')) z = np.loadtxt(os.path.join(folder, 'z-data')) # Add shapes # Shift them and rescale for easier comparison x0, y0 = 20, 0 for iframe_raw, xx, yy, zz in zip(iframes_raw, x, y, z):
def viz_observation_manifold(t3, tlim, size): tmin = 0 tmax = 2 * tlim # tlim line vline1 = vp.Tube([[tmin, tlim, t3], [tmax, tlim, t3]], r=2.0) vline1.color('g') # t = 0 line vline2 = vp.Tube([[tmin, tlim, t3], [tmin, tmax, t3]], r=2.0) vline2.color((1, 1, 1)) # Manifold verts = [[tmin, tlim, t3], [tmax, tlim, t3], [tmin, tmax, t3], [tmax, tmax, t3]] triangs = [[0, 1, 3], [0, 3, 2]] vmesh1 = vp.Mesh([verts, triangs]) vmesh1.color((1, 1, 1)) # Inverse manifold verts = [[tmin, tmin, t3], [tmax, tmin, t3], [tmin, tlim, t3], [tmax, tlim, t3]] triangs = [[0, 1, 3], [0, 3, 2]] vmesh2 = vp.Mesh([verts, triangs]) vmesh2.color((0.9, 0.9, 0.9)).alpha(0.0) # Invisible points to set the extent vpoints = vp.Points([(tmin - 0.1, tmin - 0.1, tmin - 0.1), (1.01 * tmax, 1.01 * tmax, 1.01 * tmax)]).alpha(0.0) lpos = [(p, str(p)) for p in [0, 50, 100, 150]] vplotter = vp.Plotter(offscreen=True, size=size, axes=dict(xyGrid=True, yzGrid=True, zxGrid=True, xTitleSize=0, yTitleSize=0, zTitleSize=0, xPositionsAndLabels=lpos, yPositionsAndLabels=lpos, zPositionsAndLabels=lpos[1:], axesLineWidth=5, tipSize=0.02, gridLineWidth=2, xLabelSize=0.05, yLabelSize=0.05, zLabelSize=0.05, xLabelOffset=0.05, yLabelOffset=0.05, zLabelOffset=0.0, zTitleRotation=225)) vlabels = [ vp.Text2D("H", (0.09 * size[0], 0.10 * size[1]), s=3, font='Arial'), vp.Text2D("N", (0.87 * size[0], 0.16 * size[1]), s=3, font='Arial'), vp.Text2D("S", (0.49 * size[0], 0.90 * size[1]), s=3, font='Arial') ] vp.show([vline1, vline2, vmesh1, vpoints] + vlabels, camera=dict(pos=(378, 324, 450), focalPoint=(tlim, tlim, tlim + 27), viewup=(0, 0, 1))) img = vp.screenshot(None, scale=1, returnNumpy=True) vp.clear() vp.closePlotter() return img
def viz_param_manifold(filename, size): data = np.load(filename) vline = vp.Tube(data['boundary_hns'], r=0.08) vline.color('g') # HNS manifold vmesh_hns = vp.Mesh([data['verts_hns'], data['triangs_hns']]) k = 3 prior = (2 * np.pi)**(-k / 2) * (np.exp( -0.5 * np.sum(vmesh_hns.points()**2, axis=1))) vmesh_hns.pointColors(prior, cmap='Reds', vmin=0) vmesh_hns.addScalarBar(horizontal=True, nlabels=6, c='k', pos=(0.74, 0.01), titleFontSize=44) vmesh_hns.scalarbar.SetLabelFormat("%.2g") vmesh_hns.scalarbar.SetBarRatio(1.0) # Inverted HNS manifold vmesh_hnsi = vp.Mesh([data['verts_hnsi'], data['triangs_hnsi']]) # vmesh_hnsi.color([0.68, 0.68, 0.68]) vmesh_hnsi.color([0.9, 0.9, 0.9]).alpha(0.0) # Invisible points to set the extent vpoints = vp.Points([(-5.01, -5.01, -5.01), (5.01, 5.01, 5.01)]).alpha(0.0) vplotter = vp.Plotter(offscreen=True, size=size, axes=dict(xyGrid=True, yzGrid=True, zxGrid=True, xTitleSize=0, yTitleSize=0, zTitleSize=0, xHighlightZero=True, yHighlightZero=True, zHighlightZero=True, xHighlightZeroColor='b', yHighlightZeroColor='b', zHighlightZeroColor='b', numberOfDivisions=10, axesLineWidth=5, tipSize=0.02, gridLineWidth=2, xLabelSize=0.05, yLabelSize=0.05, zLabelSize=0.05, xLabelOffset=0.05, yLabelOffset=0.05, zLabelOffset=0.0, zTitleRotation=225)) vlabels = [ vp.Text2D("H", (0.09 * size[0], 0.10 * size[1]), s=3, font='Arial'), vp.Text2D("N", (0.87 * size[0], 0.16 * size[1]), s=3, font='Arial'), vp.Text2D("S", (0.49 * size[0], 0.90 * size[1]), s=3, font='Arial') ] k = 2 vecs = np.array([[[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]], [[k, -k, 0, 0, 0, 0], [0, 0, k, -k, 0, 0], [0, 0, 0, 0, k, -k]]]) varrows = vp.Arrows(vecs[0].T, vecs[1].T, s=1.2, c='k') vp.show([vline, vmesh_hns, vmesh_hnsi, vpoints, varrows] + vlabels, camera=dict(pos=(16, 13, 20), focalPoint=(0, 0, 1.5), viewup=(0, 0, 1))) img = vp.screenshot(None, scale=1, returnNumpy=True) vp.clear() vp.closePlotter() return img
''' if isinstance(cmap, str): cmap = plt.get_cmap(cmap) # return cmap(np.linspace(minval, maxval, num, endpoint=endpoint)) x = np.loadtxt(os.path.join(folder, 'x-data')) y = np.loadtxt(os.path.join(folder, 'y-data')) z = np.loadtxt(os.path.join(folder, 'z-data')) colors = get_colors(len(iframes_raw), 'hsv') shapes = [] for iframe_raw, xx, yy, zz in zip(iframes_raw, x, y, z): cc = colors[iframe_raw] # shapes are starting from 1 c = tuple(cc[:3]) # discard opacity shape = vedo.Tube(list(zip(xx, yy, zz)), r=0.125, c=c) shapes += [shape] size = 256 * np.array([4, 3]) # window size # 256 offscreen = False # Hide interactive = False # should be false to execute the whole script plotter = vedo.plotter.Plotter(pos=(100, 0), interactive=interactive, size=size, offscreen=offscreen) plane = vedo.Plane(pos=(0, 0, 0), normal=(0, 0, 1), sx=10).alpha(0.5) shapes += [plane] plotter.add(shapes, render=False) plotter.show(interactive=True).close()
cmap = plt.get_cmap(cmap) # return cmap(np.linspace(minval, maxval, num, endpoint=endpoint)) colors = get_colors(42, 'hsv') shapes = [] for iframe_raw in iframes_raw: xname = os.path.join(folder, 'x-{}.dat'.format(iframe_raw)) yname = os.path.join(folder, 'y-{}.dat'.format(iframe_raw)) zname = os.path.join(folder, 'z-{}.dat'.format(iframe_raw)) xx = np.loadtxt(xname) yy = np.loadtxt(yname) zz = np.loadtxt(zname) cc = colors[iframe_raw] # shapes are starting from 1 c = tuple(cc[:3]) # discard opacity shape = vedo.Tube(list(zip(zz, xx, yy)), r=1, c=c) # NB: Swapped axes!! shapes += [shape] size = 256 * np.array([4, 3]) # window size # 256 offscreen = False # Hide interactive = False # should be false to execute the whole script plotter = vedo.plotter.Plotter(pos=(100, 0), interactive=interactive, size=size, offscreen=offscreen) plane = vedo.Plane(pos=(0, 0, 0), normal=(0, 0, 1), sx=100).alpha(0.5) shapes += [plane] plotter.add(shapes, render=False) plotter.show(interactive=True).close()
# Git repo at : https://morphomatics.github.io/tutorial_ssm/ # Install with: # pip install git+https://github.com/morphomatics/morphomatics.git#egg=morphomatics # from morphomatics.geom import Surface from morphomatics.stats import StatisticalShapeModel from morphomatics.manifold import FundamentalCoords import numpy as np import vedo ln1 = [[1, 1, x / 2] for x in np.arange(0, 15, 0.15)] ln2 = [[np.sin(x), np.cos(x), x / 2] for x in np.arange(0, 15, 0.15)] rads = [0.4 * (np.cos(6 * ir / len(ln2)))**2 + 0.1 for ir in range(len(ln2))] vmesh1 = vedo.Tube(ln1, r=0.08, c="tomato").triangulate().clean() vmesh2 = vedo.Tube(ln2, r=rads, c="tomato").triangulate().clean() verts1 = vmesh1.points() verts2 = vmesh2.points() faces = np.array(vmesh1.faces()) # construct model SSM = StatisticalShapeModel(lambda ref: FundamentalCoords(ref)) surfaces = [Surface(v, faces) for v in [verts1, verts2]] SSM.construct(surfaces) # sample trajectory along the main mode of variation shapes = [vmesh1] std = np.sqrt(SSM.variances[0]) for t in np.linspace(-1.0, 1.0, 20): e = SSM.space.exp(SSM.mean_coords, t * std * SSM.modes[0])