Discussion:
[MayaVi-users] animate PolyData with point_data
David Froger
2016-07-07 23:43:49 UTC
Permalink
Hello,

I'm trying to animate a PolyData.

The script bellow works (the triangular mesh move up and down), but if I try
to set point_data (uncomment the 3 lines), the triangular mesh do not move
anymore.

There is no error message.

What's wrong?

Thanks a lot,
David


import numpy as np
from mayavi import mlab
from tvtk.api import tvtk

# 3-----4-----5 y=1
# | \ 1 \ 3 |
# | 0 \ | 2 \ |
# 0-----1-----2 y=0
# x=0 x=1 x=2

npoints = 6

def generate_points(z):
return np.array([(0,0,z), (1,0,z), (2,0,z),
(0,1,z), (1,1,z), (2,1,z)], 'd')

@mlab.show
@mlab.animate(delay=250)
def anim():
z = z0
velocity = 0.5
while True:
z += velocity
if z > 1 or z < -1:
velocity *= -1
points = generate_points(z)
poly_data.points = points
#poly_data.point_data.scalars = points[:,2]
yield
z0 = 0.

triangles = np.array([(0,1,3), (1,4,3), (1,2,4), (2,5,4)], 'int32')
points = generate_points(z0)

fig = mlab.figure()

poly_data = tvtk.PolyData(points=generate_points(0), polys=triangles)
#poly_data.point_data.scalars = points[:,2]
#poly_data.point_data.scalars.name = "z"
surf = mlab.pipeline.surface(poly_data)

anim()
Prabhu Ramachandran
2016-07-08 13:55:16 UTC
Permalink
Post by David Froger
Hello,
I'm trying to animate a PolyData.
The script bellow works (the triangular mesh move up and down), but if I try
to set point_data (uncomment the 3 lines), the triangular mesh do not move
anymore.
Yes, because point_data represents attributes associated with the points. The
scalars/vectors/tensors are therefore independent of the points. You can of
course achieve this by using the scalars to modify the points using a warp
filter. For example you could setup the points to be planar on the x-y plane
and set the scalar values but instead you'd have to do:

src = mlab.pipeline.add_dataset(poly_data)
surf = mlab.pipeline.surface(mlab.pipeline.warp_scalar(src))

Then your approach may work.

cheers,
Prabhu

Loading...