v0.14.0
make_mesh_png.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 import argparse
5 import pyvista as pv
6 import matplotlib.pyplot as plt
7 from matplotlib.colors import ListedColormap
8 import matplotlib.image as mpimg
9 
10 debug=True
11 
12 def make_png(file, args):
13  my_cmap = plt.cm.get_cmap("turbo", 124)
14  mesh = pv.read(file)
15 
16  if args.wrap_vector:
17  mesh = mesh.warp_by_vector(args.wrap_vector, factor=1)
18 
19  p = pv.Plotter(notebook=False, off_screen=True)
20  if args.field:
21  p.add_mesh(
22  mesh,
23  scalars=args.field,
24  show_edges=False,
25  smooth_shading=False, cmap=my_cmap)
26  else:
27  p.add_mesh(
28  mesh,
29  show_edges=True, edge_color='white', color='white')
30  if args.d2:
31  p.camera_position = args.d2
32  p.camera.zoom(args.zoom)
33  p.camera.roll += args.roll
34  p.camera.azimuth += args.azimuth
35  image = p.screenshot('%spng' % file[:-3])
36 
37 def is_not_vtk(files):
38  return not files.endswith('vtk')
39 
40 if __name__ == '__main__':
41  parser = argparse.ArgumentParser(
42  description="Convert multiple vtk files to png files using the pyvista.")
43  parser.add_argument(
44  "files", help="list of vtk files or a regexp mask", nargs='+')
45  parser.add_argument('-d2', '--d2', dest='d2', default='')
46  parser.add_argument('-f', '--field', dest='field', default='', type=str)
47  parser.add_argument('-wv', '--wrap_vector', dest='wrap_vector', default='', type=str)
48  parser.add_argument('--zoom', dest='zoom', default=1.2, type=float)
49  parser.add_argument('--roll', dest='roll', default=0, type=float)
50  parser.add_argument('--azimuth', dest='azimuth', default=0, type=float)
51  args = parser.parse_args()
52 
53  if debug:
54  print(args)
55 
56  from pyvirtualdisplay import Display
57  display = Display(backend="xvfb", visible=False, size=(800, 800))
58  display.start()
59 
60  for f in args.files:
61  make_png(f, args)
62 
make_mesh_png.make_png
def make_png(file, args)
Definition: make_mesh_png.py:12
make_mesh_png.is_not_vtk
def is_not_vtk(files)
Definition: make_mesh_png.py:37