Exemplo n.º 1
0
def importWindow(fileinput):
    """Import a whole scene from a Numpy file."""
    import numpy as np
    from vtkplotter import Plotter

    data = np.load(fileinput, allow_pickle=True)[0]

    settings.renderPointsAsSpheres = data['renderPointsAsSpheres']
    settings.renderLinesAsTubes = data['renderLinesAsTubes']
    settings.hiddenLineRemoval = data['hiddenLineRemoval']
    settings.visibleGridEdges = data['visibleGridEdges']
    settings.interactorStyle = data['interactorStyle']

    vp = Plotter(pos=data['position'],
                 size=data['size'],
                 axes=data['axes'],
                 title=data['title'],
                 bg=data['backgrcol'],
                 infinity=data['infinity'],
                 depthpeeling=data['depthpeeling'],
    )
    vp.xtitle = data['xtitle']
    vp.ytitle = data['ytitle']
    vp.ztitle = data['ztitle']
    vp.actors = loadNumpy(data['objects'])
    return vp
Exemplo n.º 2
0
def importWindow(fileinput):
    """Import a whole scene from a Numpy file.
    Return ``Plotter`` instance."""
    from vtkplotter import Plotter

    data = np.load(fileinput, allow_pickle=True,
                   encoding="latin1").flatten()[0]

    if 'renderPointsAsSpheres' in data.keys():
        settings.renderPointsAsSpheres = data['renderPointsAsSpheres']
    if 'renderLinesAsTubes' in data.keys():
        settings.renderLinesAsTubes = data['renderLinesAsTubes']
    if 'hiddenLineRemoval' in data.keys():
        settings.hiddenLineRemoval = data['hiddenLineRemoval']
    if 'visibleGridEdges' in data.keys():
        settings.visibleGridEdges = data['visibleGridEdges']
    if 'interactorStyle' in data.keys():
        settings.interactorStyle = data['interactorStyle']
    if 'useParallelProjection' in data.keys():
        settings.useParallelProjection = data['useParallelProjection']

    axes = data.pop('axes', 4)
    title = data.pop('title', '')
    backgrcol = data.pop('backgrcol', "blackboard")

    vp = Plotter(  #size=data['size'], # not necessarily a good idea to set it
        #shape=data['shape'],
        axes=axes,
        title=title,
        bg=backgrcol,
    )
    vp.xtitle = data.pop('xtitle', 'x')
    vp.ytitle = data.pop('ytitle', 'y')
    vp.ztitle = data.pop('ztitle', 'z')

    if 'objects' in data.keys():
        objs = loadNumpy(data['objects'])
        if not utils.isSequence(objs):
            objs = [objs]
    else:
        colors.printc("Trying to import a that was not exported.", c=1)
        colors.printc(" -> try to load a single object with load().", c=1)
        return loadNumpy(fileinput)
    vp.actors = objs

    #    if vp.shape==(1,1):
    #        vp.actors = loadNumpy(data['objects'])
    #    else:
    #        print(objs, )
    #        for a in objs:
    #            for ar in a.renderedAt:
    #                print(vp.shape, [a], ar )
    #                vp.show(a, at=ar)
    return vp
Exemplo n.º 3
0
def importWindow(fileinput):
    """Import a whole scene from a Numpy file.
    Return ``Plotter`` instance."""
    import numpy as np
    from vtkplotter import Plotter

    data = np.load(fileinput, allow_pickle=True)[0]

    if 'renderPointsAsSpheres' in data.keys():
        settings.renderPointsAsSpheres = data['renderPointsAsSpheres']
    if 'renderLinesAsTubes' in data.keys():
        settings.renderLinesAsTubes = data['renderLinesAsTubes']
    if 'hiddenLineRemoval' in data.keys():
        settings.hiddenLineRemoval = data['hiddenLineRemoval']
    if 'visibleGridEdges' in data.keys():
        settings.visibleGridEdges = data['visibleGridEdges']
    if 'interactorStyle' in data.keys():
        settings.interactorStyle = data['interactorStyle']
    if 'useParallelProjection' in data.keys():
        settings.useParallelProjection = data['useParallelProjection']

    pos = data.pop('position', (0, 0))
    axes = data.pop('axes', 4)
    title = data.pop('title', '')
    backgrcol = data.pop('backgrcol', "blackboard")

    vp = Plotter(
        pos=pos,
        #size=data['size'], # not necessarily a good idea to set it
        #shape=data['shape'],
        axes=axes,
        title=title,
        bg=backgrcol,
    )
    vp.xtitle = data.pop('xtitle', 'x')
    vp.ytitle = data.pop('ytitle', 'y')
    vp.ztitle = data.pop('ztitle', 'z')

    objs = loadNumpy(data['objects'])
    if not utils.isSequence(objs):
        objs = [objs]
    vp.actors = objs

    #    if vp.shape==(1,1):
    #        vp.actors = loadNumpy(data['objects'])
    #    else:
    #        print(objs, )
    #        for a in objs:
    #            for ar in a.renderedAt:
    #                print(vp.shape, [a], ar )
    #                vp.show(a, at=ar)
    return vp
Exemplo n.º 4
0
def importWindow(fileinput, mtlFile=None, texturePath=None):
    """Import a whole scene from a Numpy or OBJ wavefront file.
    Return ``Plotter`` instance.

    :param str mtlFile: MTL file for OBJ wavefront files.
    :param str texturePath: path of the texture files directory.
    """
    from vtkplotter import Plotter

    if '.npy' in fileinput:
        data = np.load(fileinput, allow_pickle=True, encoding="latin1").flatten()[0]

        if 'renderPointsAsSpheres' in data.keys():
            settings.renderPointsAsSpheres = data['renderPointsAsSpheres']
        if 'renderLinesAsTubes' in data.keys():
            settings.renderLinesAsTubes = data['renderLinesAsTubes']
        if 'hiddenLineRemoval' in data.keys():
            settings.hiddenLineRemoval = data['hiddenLineRemoval']
        if 'visibleGridEdges' in data.keys():
            settings.visibleGridEdges = data['visibleGridEdges']
        if 'interactorStyle' in data.keys():
            settings.interactorStyle = data['interactorStyle']
        if 'useParallelProjection' in data.keys():
            settings.useParallelProjection = data['useParallelProjection']

        axes = data.pop('axes', 4)
        title = data.pop('title', '')
        backgrcol = data.pop('backgrcol', "blackboard")

        vp = Plotter(size=data['size'], # not necessarily a good idea to set it
                     #shape=data['shape'],
                     axes=axes,
                     title=title,
                     bg=backgrcol,
        )
        vp.xtitle = data.pop('xtitle', 'x')
        vp.ytitle = data.pop('ytitle', 'y')
        vp.ztitle = data.pop('ztitle', 'z')

        #print(data.keys())
#        print(data['objects'])
#        exit()

        if 'objects' in data.keys():
            objs = loadNumpy(data['objects'])
            if not utils.isSequence(objs):
               objs = [objs]
        else:
            colors.printc("Trying to import a that was not exported.", c=1)
            colors.printc(" -> try to load a single object with load().", c=1)
            return loadNumpy(fileinput)
        vp.actors = objs

        #    if vp.shape==(1,1):
        #        vp.actors = loadNumpy(data['objects'])
        #    else:
        #        print(objs, )
        #        for a in objs:
        #            for ar in a.renderedAt:
        #                print(vp.shape, [a], ar )
        #                vp.show(a, at=ar)
        return vp

    elif '.obj' in fileinput.lower():

        vp = Plotter()

        importer = vtk.vtkOBJImporter()
        importer.SetFileName(fileinput)
        if mtlFile is not False:
            if mtlFile is None:
                mtlFile = fileinput.replace('.obj', '.mtl').replace('.OBJ', '.MTL')
            importer.SetFileNameMTL(mtlFile)
        if texturePath is not False:
            if texturePath is None:
                texturePath = fileinput.replace('.obj', '.txt').replace('.OBJ', '.TXT')
            importer.SetTexturePath(texturePath)
        importer.SetRenderWindow(vp.window)
        importer.Update()

        actors = vp.renderer.GetActors()
        actors.InitTraversal()
        for i in range(actors.GetNumberOfItems()):
            vactor = actors.GetNextActor()
            act = Mesh(vactor)
            act_tu = vactor.GetTexture()
            if act_tu:
                act_tu.InterpolateOn()
                act.texture(act_tu)
            vp.actors.append( act )
        return vp
Exemplo n.º 5
0
"""
2D histogram with hexagonal binning.
"""
print(__doc__)
from vtkplotter import Plotter, histogram2D, Points, Latex
import numpy as np

vp = Plotter(axes=1, verbose=0, bg="w")
vp.xtitle = "x gaussian, s=1.0"
vp.ytitle = "y gaussian, s=1.5"
vp.ztitle = "dN/dx/dy"

N = 20000
x = np.random.randn(N) * 1.0
y = np.random.randn(N) * 1.5

histo = histogram2D(x, y, c="dr", bins=15, fill=False)

pts = Points([x, y, np.zeros(N)], c="black", alpha=0.1)

f = r'f(x, y)=A \exp \left(-\left(\frac{\left(x-x_{o}\right)^{2}}{2 \sigma_{x}^{2}}+\frac{\left(y-y_{o}\right)^{2}}{2 \sigma_{y}^{2}}\right)\right)'

formula = Latex(f, c='k', s=2).rotateZ(90).pos(5, -2, 1)

vp.show(histo, pts, formula, viewup="z")
Exemplo n.º 6
0
def f(psi):
    # a smart numpy way to calculate the second derivative in x:
    nabla2psi[1 : N + 1] = (psi[0:N] + psi[2 : N + 2] - 2 * psi[1 : N + 1]) / dx2
    return 1j * (nabla2psi - V * psi)  # this is the RH of Schroedinger equation!


def d_dt(psi):  # find Psi(t+dt)-Psi(t) /dt with 4th order Runge-Kutta method
    k1 = f(psi)
    k2 = f(psi + dt / 2 * k1)
    k3 = f(psi + dt / 2 * k2)
    k4 = f(psi + dt * k3)
    return (k1 + 2 * k2 + 2 * k3 + k4) / 6


vp = Plotter(interactive=0, axes=2, bg=(0.95, 0.95, 1))
vp.xtitle = ""
vp.ytitle = "Psi^2(x,t)"
vp.ztitle = ""

bck = vp.load(datadir+"images/schrod.png", alpha=0.3).scale(0.0255).pos([0, -5, -0.1])
barrier = Line(list(zip(x, V * 15, [0] * len(x))), c="black", lw=2)

lines = []
for i in range(0, Nsteps):
    for j in range(500):
        Psi += d_dt(Psi) * dt  # integrate for a while before showing things
    A = np.real(Psi * np.conj(Psi)) * 1.5  # psi squared, probability(x)
    coords = list(zip(x, A, [0] * len(x)))
    Aline = Line(coords, c="db", lw=3)
    vp.show([Aline, barrier, bck])
    lines.append([Aline, A])  # store objects
Exemplo n.º 7
0
    # a smart numpy way to calculate the second derivative in x:
    nabla2psi[1:N + 1] = (psi[0:N] + psi[2:N + 2] - 2 * psi[1:N + 1]) / dx2
    return 1j * (nabla2psi - V * psi
                 )  # this is the RH of Schroedinger equation!


def d_dt(psi):  # find Psi(t+dt)-Psi(t) /dt with 4th order Runge-Kutta method
    k1 = f(psi)
    k2 = f(psi + dt / 2 * k1)
    k3 = f(psi + dt / 2 * k2)
    k4 = f(psi + dt * k3)
    return (k1 + 2 * k2 + 2 * k3 + k4) / 6


vp = Plotter(interactive=0, axes=2, verbose=0)
vp.xtitle = ''
vp.ytitle = 'Psi^2(x,t)'
vp.ztitle = ''

bck = vp.load('data/images/schrod.png').scale(0.012).pos([0, 0, -.5])
barrier = vp.line(list(zip(x, V * 15)), c='dr', lw=3)

lines = []
for j in range(200):
    for i in range(500):
        Psi += d_dt(Psi) * dt  # integrate for a while

    A = np.real(Psi * np.conj(Psi)) * 1.5  # psi squared, probability(x)
    coords = list(zip(x, A))
    Aline = vp.line(coords, c='db', tube=True, lw=.08)
    vp.show([Aline, barrier, bck])
Exemplo n.º 8
0
# histogram2D example
#
from vtkplotter import Plotter, histogram2D
import numpy as np

vp = Plotter(axes=1, verbose=0)
vp.xtitle = 'x gaussian, s=1.0'
vp.ytitle = 'y gaussian, s=1.5'
vp.ztitle = 'dN/dx/dy'

N = 20000
x = np.random.randn(N) * 1.0
y = np.random.randn(N) * 1.5

vp.add(histogram2D(x, y, c='dr', bins=15, fill=False))

vp.points([x, y, np.zeros(N)], c='black', alpha=0.1)

vp.show(viewup='z')