예제 #1
0
def showSolution3D(S, start, goal):
    from vtkplotter import Text, Cube, Line, Grid, mergeActors, 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 = mergeActors(cubes).clean().texture('metal2')

    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.wireframe(False).cellColors(gradient, cmap='gist_earth_r')
    grd.addScalarBar(title='Gradient', horizontal=True)

    txts.append(Text(__doc__, c='k'))
    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, bg='white', axes=0, zoom=1.2)
예제 #2
0
    def __init__(self, parent=None):

        Qt.QMainWindow.__init__(self, parent)
        self.frame = Qt.QFrame()
        self.vl = Qt.QVBoxLayout()
        self.vtkWidget = QVTKRenderWindowInteractor(self.frame)
        self.vl.addWidget(self.vtkWidget)

        vp = Plotter(offscreen=1, interactive=0, axes=2, N=2)

        cn = Cone()
        cc = Cube().pos(1, 1, 1).color("pink")
        ss = Torus()
        vp.show(cn, cc, at=0)
        vp.show(ss, at=1, viewup="z")

        self.start(vp)
예제 #3
0

#####################################################################################################
if __name__ == "__main__":

    # An example simulation of N particles scattering on a charged target.
    # See e.g. https://en.wikipedia.org/wiki/Rutherford_scattering

    vp = Plotter(title="Particle Simulator",
                 bg="black",
                 axes=0,
                 interactive=False)
    vp.camera.Elevation(20)  # Initial camera position
    vp.camera.Azimuth(40)

    vp.add(Cube(c="white").wire(1))  # a wireframe cube

    sim = ParticleSim(dt=5e-6, iterations=200)
    sim.add_particle((-0.4, 0, 0),
                     color="w",
                     charge=3e-6,
                     radius=0.01,
                     fixed=True)  # the target

    positions = np.random.randn(500,
                                3) / 60  # generate a beam of 500 particles
    for p in positions:
        p[0] = -0.5  # Fix x position. Their charge are small/negligible compared to target:
        sim.add_particle(p,
                         charge=0.01e-6,
                         mass=0.1e-6,
예제 #4
0
            # Add a trail behind the particle
            self.vtk_actor.addTrail(alpha=0.4, maxlength=1, n=50)


#####################################################################################################
if __name__ == "__main__":

    # An example simulation of N particles scattering on a charged target.
    # See e.g. https://en.wikipedia.org/wiki/Rutherford_scattering

    vp = Plotter(title="Particle Simulator",
                 bg="black",
                 axes=0,
                 interactive=False)

    vp += Cube(c="white").wireframe(1)  # a wireframe cube

    sim = ParticleSim(dt=5e-6, iterations=200)
    sim.add_particle((-0.4, 0, 0),
                     color="w",
                     charge=3e-6,
                     radius=0.01,
                     fixed=True)  # the target

    positions = np.random.randn(500,
                                3) / 60  # generate a beam of 500 particles
    for p in positions:
        p[0] = -0.5  # Fix x position. Their charge are small/negligible compared to target:
        sim.add_particle(p,
                         charge=0.01e-6,
                         mass=0.1e-6,
예제 #5
0
"""
Show a cube for each available texture name
any jpg file can be used as texture.
"""
from vtkplotter import Plotter, Cube, Text
from vtkplotter.settings import textures, textures_path

print(__doc__)
print(textures_path)
print(textures)

vp = Plotter(N=len(textures), axes=0)

for i, txt in enumerate(textures):
    cb = Cube(texture=txt)
    tname = Text(txt, pos=3)
    vp.show(cb, tname, at=i)

vp.camera.Elevation(70)
vp.camera.Azimuth(10)
vp.show(interactive=1)
예제 #6
0
"""
Computes the (signed) distance 
from one mesh to another.
"""
from vtkplotter import Sphere, Cube, show, Text

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.scalars("Distance"))

show(s1, s2, Text(__doc__))
예제 #7
0
'''
Show a cube for each available color name
'''
print(__doc__)
from vtkplotter import Plotter, Cube, Text
from vtkplotter.colors import colors, getColor
from operator import itemgetter

# sorting by hex color code:
sorted_colors = sorted(colors.items(), key=itemgetter(1))
# or by name:
# sorted_colors = sorted(colors.items(), key=itemgetter(0))

vp = Plotter(N=len(sorted_colors), axes=0, size='fullscreen')

for i, sc in enumerate(sorted_colors):
    cname = sc[0]
    rgb = getColor(cname)
    cb = Cube(c=rgb)
    tname = Text(cname, pos=3)
    vp.show([cb, tname], at=i)

print('click on any cube and press i')
vp.show(zoom=1.1, interactive=1)
예제 #8
0
"""
Show a cube for each available texture name.
Any jpg file can be used as texture.
"""
from vtkplotter import Plotter, Cube, Text2D
from vtkplotter.settings import textures, textures_path

print(__doc__)
print('textures_path:', textures_path)
print('textures:', textures)

vp = Plotter(N=len(textures), axes=0)

for i, name in enumerate(textures):
    if i>30: break
    cb = Cube().texture(name)
    tname = Text2D(name, pos=3)
    vp.show(cb, tname, at=i)

vp.show(interactive=1)
예제 #9
0
"""
Show some text as a corner annotation.
Fonts: arial, courier, times.
"""
from vtkplotter import show, Text, Cube

with open("annotations.py") as fname:
    t = fname.read()

actor2d = Text(t, pos=3, s=1.2, c='k', bg="lb", font="courier")

show(actor2d, Cube(), verbose=0, axes=0)
예제 #10
0
"""Show some text as a corner annotation.
Fonts: arial, courier, times.
"""
from vtkplotter import show, Text2D, Cube

with open("annotations.py") as fname:
    t = fname.read()

txt2d = Text2D(t, pos=3, s=1.2, c='k', bg="lb", font="courier")

show(txt2d, Cube(), verbose=0, axes=0)
예제 #11
0
from vtkplotter import Latex, Cube, Point, show

# https://matplotlib.org/tutorials/text/mathtext.html

latex1 = r'x= \frac{ - b \pm \sqrt {b^2 - 4ac} }{2a}'
latex2 = r'$\mathcal{A}\mathrm{sin}(2 \omega t)$'
latex3 = r'I(Y | X)=\sum_{x \in \mathcal{X}, y \in \mathcal{Y}} p(x, y) \log \left(\frac{p(x)}{p(x, y)}\right)'
latex4 = r'\Gamma_{\epsilon}(x)=\left[1-e^{-2 \pi \epsilon}\right]^{1-x} \prod_{n=0}^{\infty} \frac{1-\exp (-2 \pi \epsilon(n+1))}{1-\exp (-2 \pi \epsilon(x+n))}'
latex5 = r'\left( \begin{array}{l}{c t^{\prime}} \\ {x^{\prime}} \\ {y^{\prime}} \\ {z^{\prime}}\end{array}\right)=\left( \begin{array}{cccc}{\gamma} & {-\gamma \beta} & {0} & {0} \\ {-\gamma \beta} & {\gamma} & {0} & {0} \\ {0} & {0} & {1} & {0} \\ {0} & {0} & {0} & {1}\end{array}\right) \left( \begin{array}{l}{c t} \\ {x} \\ {y} \\ {z}\end{array}\right)'
latex6 = r'\mathrm{CO}_{2}+6 \mathrm{H}_{2} \mathrm{O} \rightarrow \mathrm{C}_{6} \mathrm{H}_{12} \mathrm{O}_{6}+6 \mathrm{O}_{2}'
latex7 = r'x~\mathrm{(arb. units)}'

p = Point()
c = Cube().wire()

l = Latex(latex5, s=1, c='white', bg='', alpha=0.9,
          fromweb=False).addPos(4, 0, -1)

show(p, c, l, axes=8)
예제 #12
0
"""
Show a cube for each available texture name
any jpg file can be used as texture.
"""
from vtkplotter import Plotter, Cube, Text
from vtkplotter.settings import textures, textures_path

print(__doc__)
print(textures_path)
print(textures)

vp = Plotter(N=len(textures), axes=0)

for i, txt in enumerate(textures):
    cb = Cube().texture(txt)
    tname = Text(txt, pos=3)
    vp.show(cb, tname, at=i)

vp.show(interactive=1)
예제 #13
0
파일: fonts.py 프로젝트: zlinzju/vtkplotter
from vtkplotter import Cube, Text, show, collection
from vtkplotter.settings import fonts

Text("List of available fonts:")

Cube().c('white').rotateX(20).rotateZ(20)

for i, f in enumerate(fonts):
    Text(f + ':  The quick fox jumps over the lazy dog.',
         pos=(5, i * 40 + 20),
         font=f,
         c=i % 3)

show(collection(), axes=False)

#####################################################################################################
if __name__ == '__main__':

    # An example simulation of N particles scattering on a charged target.
    # See e.g. https://en.wikipedia.org/wiki/Rutherford_scattering

    vp = Plotter(title='Particle Simulator',
                 bg='black',
                 axes=0,
                 interactive=False)
    vp.camera.Elevation(20)  # Initial camera position
    vp.camera.Azimuth(40)

    vp.add(Cube(c='white').wire(1))  # a wireframe cube

    sim = ParticleSim(dt=5e-6, iterations=200)
    sim.add_particle((-0.4, 0, 0),
                     color='w',
                     charge=3e-6,
                     radius=0.01,
                     fixed=True)  # the target

    positions = np.random.randn(500,
                                3) / 60  # generate a beam of 500 particles
    for p in positions:
        p[0] = -0.5  # Fix x position. Their charge are small/negligible compared to target:
        sim.add_particle(p,
                         charge=.01e-6,
                         mass=0.1e-6,