Hi all,
I'm replying to my own email because I worked out a solution and wanted
to share but also because I believe what I'm doing is FAR from optimal
and hope that someone
Would it be possible with python scripting to create an animation by
"rotating" the look up table in a way that would look like this:
https://www.youtube.com/watch?v=qA_vInXwdKM#t=3m25s ? It is a
pseudo-animation created by changing the "range" of the LUT.
So I made this python script (see attachment) that generates different
meshes with scalar values "rotated" (I don't find a better term to
describe what I'm doing).
It works and make it easy to play the animation by opening the produced
vtk files as a sequence in paraview.
However, every vtk file contains both the mesh geometry and the scalar
values, but only the latter change. What would be the right way to
animate only the scalar values and not the mesh geometry? What data
format should I use? How could I import it into an animation in paraview?
Thanks for your guidance
--
Nicolas
#!/usr/bin/env python
from sys import argv
import numpy as np
import pyvtk
def open_binary(file_name):
reader = vtk.vtkUnstructuredGridReader()
reader.SetFileName(file_name)
reader.Update()
unstr_grid = reader.GetOutput()
triangles = vtk_to_numpy(unstr_grid.GetCells().GetData())
triangles = triangles.reshape((int(len(triangles) / 4), 4))[:, 1:]
points = vtk_to_numpy(unstr_grid.GetPoints().GetData())
scalars = pyvtk.Scalars(
vtk_to_numpy(unstr_grid.GetPointData().GetArray(0)))
points_data = pyvtk.PointData(scalars)
grid = pyvtk.UnstructuredGrid(points, triangle=triangles)
mesh = pyvtk.VtkData(grid, points_data)
return mesh
file_name = argv[1]
output_prefix = argv[2]
n = int(argv[3])
try:
mesh = pyvtk.VtkData(file_name)
except NotImplementedError:
mesh = open_binary(file_name)
t0 = np.copy(mesh.point_data.data[0].scalars)
scalars_range = np.nanmax(t0) - np.nanmin(t0)
step = scalars_range / n
for i in range(1, n):
mesh.tofile(file_name, format='binary')
vals = t0 + i * step
above = np.nan
vals[vals > np.nanmax(t0)] = vals[vals > np.nanmax(t0)] - scalars_range
mesh.point_data.data[0].scalars = vals
file_name = "{}{:04d}.vtk".format(output_prefix, i)
print(file_name)
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Please keep messages on-topic and check the ParaView Wiki at:
http://paraview.org/Wiki/ParaView
Search the list archives at: http://markmail.org/search/?q=ParaView
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/paraview