Exemplo n.º 1
0
# Generate a time sequence of 3D shapes (from a sphere to a tetrahedron)
# as noisy cloud points, and smooth it with Moving Least Squares (smoothMLS3D).
# This make a simultaneus fit in 4D (space+time).
# smoothMLS3D method returns a vtkActor where points are color coded
# in bins of fitted time.
# Data itself can suggest a meaningful time separation based on the spatial
# distribution of points.
# The nr neighbours in the local 4D fitting must be specified.
#
import numpy as np
from vtkplotter import Plotter, sphere, smoothMLS3D

vp = Plotter(N=2, axes=0)

# generate uniform points on sphere (tol separates points by 2% of actor size)
cc = sphere(res=200).clean(tol=0.02).coordinates()

a, b, noise = .2, .4, .1  # some random warping paramenters, and noise factor
for i in range(5):  # generate a time sequence of 5 shapes
    cs = cc + a * i * cc**2 + b * i * cc**3  # warp sphere in weird ways
    # set absolute time of points actor, and add 1% noise on positions
    vp.points(cs, c=i, alpha=0.5).gaussNoise(1.0).time(0.2 * i)
    vp.show(at=0, zoom=1.4)  # show input clouds as func(time)

asse = smoothMLS3D(vp.actors, neighbours=50)

vp.addScalarBar3D(asse, at=1, pos=(-2, 0, -1))  # color indicates fitted time
vp.show(asse, at=1, zoom=1.4, axes=4, interactive=1)
Exemplo n.º 2
0
man1.addPointScalars(scals, 'mypointscalars')  # add a vtkArray to actor
#print(man1.scalars('mypointscalars')) # info can be retrieved this way
vp.show(man1, at=0, elevation=-60)
vp.addScalarBar()  # add a scalarbar to last drawn actor

##################################### pointColors
man2 = vp.load('data/shapes/man.vtk')
scals = man2.coordinates()[:, 1] + 37  # pick y coordinates of vertices

man2.pointColors(scals, cmap='bone', vmin=36.2, vmax=36.7)  # right dark arm
vp.show(man2, at=1, axes=0, legend='pointColors')
vp.addScalarBar(horizontal=True)

##################################### cellColors
man3 = vp.load('data/shapes/man.vtk')
scals = man3.cellCenters()[:, 2] + 37  # pick z coordinates of cells
man3.cellColors(scals, cmap='afmhot')
#print(man3.scalars('cellColors_afmhot')) # info can be retrieved this way

# add some oriented 3D text
txt = vp.text('Floor temperature is 35C', s=.1).rotateZ(90).pos([1, -.9, -1.7])
vp.show([man3, txt], at=2, legend='cellColors')

# add a fancier 3D scalar bar embedded in the scene
vp.addScalarBar3D(man3, at=2, pos=(-1, 0, -1.7))

vp.show(interactive=1)

# N.B. in the above example one can also do:
# import matplotlib.cm as cm
# man2.pointColors(scals, cmap=cm.bone)
Exemplo n.º 3
0
man1 = vp.load('data/shapes/man.vtk')
Np = man1.N()  # nr. of vertices
pscals = arange(0, 1, 1. / Np)  # coloring will be by index nr of the vertex
man1.pointScalars(pscals, 'mypointscalars')  # add a vtkArray to actor
#print(man1.scalars('mypointscalars')) # info can be retrieved this way
vp.show(man1, at=0, axes=1)
vp.addScalarBar()  # add a scalarbar to last drawn actor

#####################################
man2 = vp.load('data/shapes/man.vtk')
pscals = man2.coordinates()[:, 1] + 37  # pick y coordinates of vertices
man2.pointColors(pscals, cmap='bone')  # use a colormap to associate a color
#print(man2.scalars('pointColors_bone')) # info can be retrieved this way
vp.show(man2, at=1, axes=0, legend='pointColors')
vp.addScalarBar(horizontal=True)

#####################################
man3 = vp.load('data/shapes/man.vtk')
cscals = man3.cellCenters()[:, 2] + 37  # pick z coordinates of cells
man3.cellColors(cscals, cmap='afmhot')

# add some oriented 3D text
txt = vp.text('floor temperature is 35C', s=.1).rotateZ(90).pos([1, -.9, -1.7])

vp.show([txt, man3], at=2, legend=['', 'cellColors'], axes=0)

# add a fancier 3D scalar bar
vp.addScalarBar3D(man3, at=2, pos=(-1, 0, -1.7), cmap='afmhot')

vp.show(interactive=1, zoom=1.4)