Exemplo n.º 1
0
a2 = a1.subdivide(method=0)  # Increasing the number of points of the mesh
coords2 = a2.coordinates()
pts2 = vp.points(coords2, r=1, legend='#points = ' + str(len(coords2)))
vp.show([a2, pts2], at=1, interactive=True)

########################################################################################
# Draw a bunch of simple objects on separate parts of the rendering window:
# split window to best accomodate 9 renderers
vp = Plotter(N=9, title='basic shapes')
vp.sharecam = False  # each object can be moved independently
vp.show(at=0, actors=vp.arrow([0, 0, 0], [1, 1, 1]), legend='arrow')
vp.show(at=1, actors=vp.line([0, 0, 0], [1, 1, 1]), legend='line')
vp.show(at=2, actors=vp.points([[0, 0, 0], [1, 1, 1]]), legend='points')
vp.show(at=3, actors=vp.text('Hello!'))
vp.show(at=4, actors=vp.sphere())
vp.show(at=5, actors=vp.cube(), legend='cube')
vp.show(at=6, actors=vp.ring(), legend='ring')
vp.show(at=7, actors=vp.helix(), legend='helix')
vp.show(at=8, actors=vp.cylinder(), legend='cylinder', interactive=1)

########################################################################################
# Draw a bunch of objects from various mesh formats. Loading is automatic.
vp = Plotter(shape=(3, 3),
             title='mesh formats')  # split window in 3 rows and 3 columns
vp.sharecam = False  # each object can be moved independently
vp.show('data/beethoven.ply', at=0, c=0, axes=0,
        ruler=1)  # dont show axes, add a ruler
vp.show('data/cow.g', at=1, c=1, zoom=1.15)  # make it 15% bigger
vp.show('data/limb.pcd', at=2, c=2)
vp.show('data/ring.gmsh', at=3, c=3, wire=1)
vp.show('data/images/dog.jpg', at=4)  # 2d images can be loaded the same way
Exemplo n.º 2
0
x0 = 0.85  # initial x-coordinate of the block
k = 25  # spring constant
m = 20  # block mass
b = 0.5  # viscosity friction (proportional to velocity)
dt = 0.1  # time step

#initial conditions
v = vector(0, 0, 0.2)
x = vector(x0, 0, 0)
xr = vector(l_rest, 0, 0)
sx0 = vector(-0.8, 0, 0)
offx = vector(0, 0.3, 0)

vp.box(pos=(0, -0.1, 0), length=2.0, width=0.02, height=0.5)  #surface
vp.box(pos=(-.82, .15, 0), length=.04, width=0.50, height=0.3)  #wall
block = vp.cube(pos=x, length=0.2, c='t')
spring = vp.helix(sx0, x, r=.06, thickness=.01, texture='metal1')

pb = ProgressBar(0, 500, c='r')
for i in pb.range():
    F = -k * (x - xr) - b * v  # Force and friction
    a = F / m  # acceleration
    v = v + a * dt  # velocity
    x = x + v * dt + 1 / 2 * a * dt**2  # position

    block.pos(x)  # update block position
    spring.stretch(sx0, x)  # stretch helix accordingly
    trace = vp.point(x + offx, c='r/0.5', r=3)  # leave a red trace

    vp.camera.Azimuth(.1)
    vp.camera.Elevation(.1)
Exemplo n.º 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.cube(wire=True, c='white')  # 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,
Exemplo n.º 4
0
# Show a cube for each available texture name
# any jpg file can be used as texture.
#
from vtkplotter import Plotter
from vtkplotter.utils import textures, textures_path

print(textures_path)
print(textures)

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

for i, txt in enumerate(textures):
    cube = vp.cube(texture=txt)
    tname = vp.text(txt, pos=3)
    vp.show([cube, tname], at=i)

vp.camera.Elevation(70)
vp.camera.Azimuth(10)
vp.show(interactive=1)
Exemplo n.º 5
0
# Show a cube for each available color name
#
from vtkplotter import Plotter
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)
    cube = vp.cube(c=rgb)
    tname = vp.text(cname, pos=3)
    vp.show([cube, tname], at=i)

print('click on any cube and press i')
vp.show(zoom=1.1, interactive=1)
Exemplo n.º 6
0
x0 = 0.85 # initial x-coordinate of the block
k = 25    # spring constant
m = 20    # block mass
b = 0.5   # viscosity friction (proportional to velocity)
dt= 0.15  # time step

#initial conditions
v = vector(0, 0, 0.2)
x = vector(x0, 0, 0)
xr = vector(L, 0, 0)
sx0 = vector(-0.8, 0, 0)
offx= vector(0, 0.3, 0)

vp.box(pos=(0, -0.1, 0), length=2.0, width=0.02, height=0.5) #surface
vp.box(pos=(-.82,.15,0), length=.04, width=0.50, height=0.3) #wall
block = vp.cube(pos=x, length=0.2, c='tomato')
block.addTrail(offset=[0,0.2,0], alpha=0.6, lw=2, n=500) 
spring= vp.helix(sx0, x, r=.06, thickness=.01, texture='metal1')

pb = ProgressBar(0,300, c='r')
for i in pb.range(): 
    F = -k*(x-xr) - b*v             # Force and friction
    a = F/m                         # acceleration
    v = v + a * dt                  # velocity
    x = x + v*dt + 1/2 * a * dt**2  # position
    
    block.pos(x)                    # update block position and trail
    spring.stretch(sx0, x)          # stretch helix accordingly
    
    vp.camera.Azimuth(0.1)
    vp.camera.Elevation(0.1)
Exemplo n.º 7
0
# Example use of addTrail() and updateTrail()
#
from vtkplotter import Plotter, sin

vp = Plotter(axes=1, interactive=0)

c = vp.cube()
vp.cutPlane(c, [-0.4, 0, 0])  #cut away the left face

s = vp.sphere([1, 1, 1], r=.03, c='db')

# add a trail to last created actor with max 50 segments
vp.addTrail(c='k', lw=3, maxlength=.5, n=50)

for i in range(200):
    s.pos([-2. + i / 100., sin(i / 5.) / 10., 0]).updateTrail()
    vp.render()
    vp.camera.Azimuth(-.3)

vp.show(interactive=1)