コード例 #1
0
ファイル: fourier_epicycles.py プロジェクト: marcomusy/vedo
def epicycles(time, rotation, fourier, order):
    global objs
    plt.remove(objs)
    x, y = [0, 0]
    objs, path = [], []
    for i in range(len(fourier[:order])):
        re, im, freq, amp, phase = fourier[i]
        if amp > 0.2:
            c = vedo.Circle([x, y], amp).wireframe().lw(0.1)
            objs.append(c)
        x += amp * np.cos(freq * time + phase + rotation)
        y += amp * np.sin(freq * time + phase + rotation)
        path.append([x, y])

    if len(points):
        hline = vedo.Line([x, y], points[-1], c='red5', lw=0.1)
        pline = vedo.Line(path, c='green5', lw=2)
        oline = vedo.Line(points, c='red4', lw=5)
        objs += [hline, pline, oline]
        plt.add(objs, resetcam=False)
    return [x, y]
コード例 #2
0
def build_manifold(w, q, c_range, n, t3, tlim, out_file):
    ADAPT_MAXLEVEL = 2
    ADAPT_TOL = 0.2

    # Hidden-Nonseizing-Seizing boundary
    # c = np.linspace(c_range[0], c_range[1], n)
    c = np.linspace(c_range[0], c_range[1], n * 2**ADAPT_MAXLEVEL)
    boundary_hns = get_c_hss(w, q, c, tlim, t3)

    # Hidden-Hidden-Seizing manifold
    verts_hhs, triangs_hhs = get_c_hhs_adaptive(w,
                                                q,
                                                c_range,
                                                n,
                                                c_range,
                                                n,
                                                t3,
                                                tol=ADAPT_TOL,
                                                maxlevel=ADAPT_MAXLEVEL)

    # Cutting mesh
    cut_line = np.copy(boundary_hns)
    cut_line[:, 2] = c_range[0]
    cut_line = vp.Line(cut_line)
    cut_mesh = cut_line.extrude(zshift=c_range[1] - c_range[0])

    # Hidden-Nonseizing-Seizing manifold
    vmesh_hhs = vp.Mesh([verts_hhs, triangs_hhs])
    vmesh_hns = vmesh_hhs.cutWithMesh(cut_mesh, invert=False)
    verts_hns = vmesh_hns.points()
    triangs_hns = vmesh_hns.faces()

    # Hidden-Nonseizing-Seizing inverted manifold
    vmesh_hhs = vp.Mesh([verts_hhs, triangs_hhs])
    vmesh_hnsi = vmesh_hhs.cutWithMesh(cut_mesh, invert=True)
    verts_hnsi = vmesh_hnsi.points()
    triangs_hnsi = vmesh_hnsi.faces()

    assert all([len(f) == 3 for f in triangs_hns])
    assert all([len(f) == 3 for f in triangs_hnsi])

    np.savez(out_file,
             boundary_hns=boundary_hns,
             verts_hns=verts_hns,
             triangs_hns=triangs_hns,
             verts_hnsi=verts_hnsi,
             triangs_hnsi=triangs_hnsi,
             verts_hhs=verts_hhs,
             triangs_hhs=triangs_hhs)
コード例 #3
0
ファイル: plot3d.py プロジェクト: ins-amu/ddmisp
def viz_structure(regpos, w, surfaces, w_perc=3):
    # Connections
    wmax = np.max(w)
    vlines = []
    for reg1, reg2 in zip(*np.where(
            w > np.percentile(w.flat, (100 - w_perc)))):
        vlines.append(
            vp.Line(regpos[reg1],
                    regpos[reg2],
                    c='k',
                    lw=5 * w[reg1, reg2] / wmax))

    # Brain surfaces
    vmeshes = [
        vp.Mesh([verts, triangs], 'grey', alpha=0.05)
        for verts, triangs in surfaces
    ]

    return vlines, vmeshes
コード例 #4
0
ファイル: optics_base.py プロジェクト: sariths/vtkPlotter
 def asLine(self,
            min_hits=1,
            max_hits=1000,
            c=None,
            cmap_amplitudes="",
            vmin=0):
     """Return a vedo.Line object if it has at least min_hits and less than max_hits"""
     if min_hits < len(self.path) < max_hits:
         ln = vedo.Line(self.path).lw(1)
         if cmap_amplitudes:
             ln.cmap(cmap_amplitudes, self._amplitudes, vmin=vmin)
         elif c is None:
             c = vedo.colors.colorMap(self.wave_length, "jet", 450e-09,
                                      750e-09) / 1.5
             ln.color(c)
         else:
             ln.color(c)
         return ln
     return None
コード例 #5
0
ファイル: viz3d.py プロジェクト: ins-amu/ddmisp
def viz_structure(regpos, w, surfaces, contacts):
    # Connections
    wmax = np.max(w)
    vlines = []
    for reg1, reg2 in zip(*np.where(w > np.percentile(w.flat, 97))):
        vlines.append(
            vp.Line(regpos[reg1],
                    regpos[reg2],
                    c='k',
                    lw=15 * w[reg1, reg2] / wmax))

    # Brain surfaces
    vmeshes = [
        vp.Mesh([verts, triangs], 'grey', alpha=0.05)
        for verts, triangs in surfaces
    ]

    # Electrodes
    ncontacts = contacts.shape[0]
    vcontacts = []
    for i in range(ncontacts):
        vcontacts.append(vp.Sphere(contacts[i], r=0.8, c='green'))

    return vlines, vmeshes, vcontacts
コード例 #6
0
"""Elliptic Fourier Descriptors
parametrizing a closed countour (in red)"""
import vedo, pyefd

shapes = vedo.load(vedo.dataurl+'timecourse1d.npy')

sh = shapes[55]
sr = vedo.Line(sh).mirror('x').reverse()
sm = vedo.merge(sh, sr).c('red5').lw(3)
pts = sm.points()[:,(0,1)]

rlines = []
for order in range(5,30, 5):
    coeffs = pyefd.elliptic_fourier_descriptors(pts, order=order, normalize=False)
    a0, c0 = pyefd.calculate_dc_coefficients(pts)
    rpts = pyefd.reconstruct_contour(coeffs, locus=(a0,c0), num_points=400)
    color = vedo.colorMap(order, "Blues", 5,30)
    rline = vedo.Line(rpts).lw(3).c(color)
    rlines.append(rline)

sm.z(0.1) # move it on top so it's visible
vedo.show(sm, *rlines, __doc__, axes=1, bg='k', size=(1190, 630), zoom=1.8)
コード例 #7
0
    vedo.dolfin.plot(mesh, arrow, txt, c='grey5', at=i, N=N,
                     zoom=1.1)  #PRESS q

dmesh_i = meshes[0]  # initial mesh
dmesh_f = meshes[-1]  # final mesh

vmesh_i = vedo.Mesh([dmesh_i.coordinates(), dmesh_i.cells()], c='grey5').z(-1)
vmesh_f = vedo.Mesh(
    [dmesh_f.coordinates(), dmesh_f.cells()], c='grey3').wireframe()

plt = vedo.Plotter()

# move a few points along the deformation of the circle
seeds = vedo.Circle(r=50,
                    res=res).points()[:,
                                      (0, 1)]  # make points 2d with [:,(0,1)]
endpoints = []
for i, p in enumerate(seeds):
    line = [p]
    for u in displacements:
        p = p + u(p)
        line.append(p)
    plt += vedo.Line(line, c=i, lw=4).z(1)
    endpoints.append(p)

plt += [vmesh_i, vmesh_f, __doc__]
plt.show(axes=1)

# to invert everything and move the end points back in place, check out discussion:
#https://fenicsproject.discourse.group/t/precision-in-hyperelastic-model/6824/3
コード例 #8
0
ファイル: vonNeumann_elephant.py プロジェクト: zhDai/vedo
def elephant(t, p):
    Cx = np.zeros((6, ), dtype='complex')
    Cy = np.zeros((6, ), dtype='complex')
    Cx[1], Cy[1] = p[0].real * 1j, p[3].imag + p[0].imag * 1j
    Cx[2], Cy[2] = p[1].real * 1j, p[1].imag * 1j
    Cx[3], Cy[3] = p[2].real, p[2].imag * 1j
    Cx[5] = p[3].real
    x = np.append(fourier(t, Cy), [p[4].imag])
    y = -np.append(fourier(t, Cx), [-p[4].imag])
    return np.array([x, y])


# draw the body of the elephant
ele = elephant(np.linspace(0.4 + 1.3 * np.pi, 2 * np.pi + 0.9 * np.pi, 100), p)
body = vedo.Line(ele.T).tomesh().lw(0).c('r4')
plt = vedo.show(body, __doc__ + str(p), zoom=0.8, axes=1, interactive=False)
ltrunk = None

# wiggle trunk
#vd = vedo.Video()
for i in range(50):
    trunk = elephant(
        np.linspace(2 * np.pi + 0.9 * np.pi, 0.4 + 3.3 * np.pi, 500), p)
    x, y = trunk
    for ii in range(len(y) - 1):
        y[ii] -= np.sin(
            ((x[ii] - x[0]) * np.pi / len(y))) * np.sin(float(i)) * p[4].real
    plt.remove(ltrunk)  # remove old trunk before drawing at new position
    ltrunk = vedo.Line(trunk.T).lw(6).c('r3')
    plt.add(ltrunk)
コード例 #9
0
ファイル: drag_catenary.py プロジェクト: marcomusy/vedo
        left = r * A
        right = np.sinh(A)
        A = A + dA
    A = A - dA

    a = dx / (2 * A)
    b = xb - a * 1 / 2 * np.log((1 + dy / L) / (1 - dy / L))
    c = y0 - a * np.cosh((x0 - b) / a)
    x = x0
    ddx = 0.001
    pts = []
    while x < x1:
        y = a * np.cosh((x - b) / a) + c
        x = x + ddx
        pts.append([x, y])
    pts.append([x1, y1])

    coords = vedo.Spline(pts, res=n).points()
    line.points(coords)  # update coords
    nodes.points(coords).z(.01)
    plt.render()


surf = vedo.Plane(sx=1, sy=1).shift(0.51, 0, 0)
line = vedo.Line(P1, P2, res=n, lw=10)
nodes = line.clone().c('red3').pointSize(8).z(.01)

plt = vedo.Plotter()
plt.addCallback("hover", move)
plt.show(__doc__, surf, line, nodes, axes=1, mode='image')
コード例 #10
0
ファイル: fourier_epicycles.py プロジェクト: marcomusy/vedo
        x += amp * np.cos(freq * time + phase + rotation)
        y += amp * np.sin(freq * time + phase + rotation)
        path.append([x, y])

    if len(points):
        hline = vedo.Line([x, y], points[-1], c='red5', lw=0.1)
        pline = vedo.Line(path, c='green5', lw=2)
        oline = vedo.Line(points, c='red4', lw=5)
        objs += [hline, pline, oline]
        plt.add(objs, resetcam=False)
    return [x, y]


# Load some 2D shape and make it symmetric
shape = vedo.load(vedo.dataurl + 'timecourse1d.npy')[55]
shaper = vedo.Line(shape).mirror('x').reverse()
shape = vedo.merge(shape, shaper)
x, y, _ = shape.points().T

# Compute Fourier Discrete Transform in x and y separately:
fourierX = DFT(x)
fourierY = DFT(y)

vedo.settings.defaultFont = 'Glasgo'
plt = vedo.Plotter(size=(1500, 750), bg='black', axes=1, interactive=False)
txt = vedo.Text2D(f"{__doc__} (order={order})",
                  c='red9',
                  bg='white',
                  pos='bottom-center')
plt.show(shape, txt, mode='image', zoom=1.9)