-
Notifications
You must be signed in to change notification settings - Fork 2
/
ply2png.py
81 lines (62 loc) · 1.52 KB
/
ply2png.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#! vtkpython
import sys, getopt
xsize = 500
ysize = 500
def usage():
print ""
print "ply2png.py [options] input_ply output_png"
print ""
print " -x int Window X size"
print " -y int Window Y size"
print ""
try:
opts, args = getopt.getopt( sys.argv[1:], "vhx:y:",
[ "verbose", "help" ] )
except getopt.GetoptErr, err:
print (str(err))
usage()
sys.exit(1)
for o, a in opts:
if o in ("-v", "--verbose"):
verbose = verbose + 1
elif o in ("-h", "--help"):
usage()
sys.exit()
elif o in ("-x"):
xsize = int(a)
elif o in ("-y"):
ysize = int(a)
else:
assert False, "unhandled options"
if len(args) < 2:
usage()
sys.exit(2)
inname = args[0]
outname = args[1]
from vtk import *
reader = vtkPLYReader()
reader.SetFileName(inname)
gf = vtkGraphicsFactory
gf.SetOffScreenOnlyMode(1)
gf.SetUseMesaClasses(1)
if_ = vtkImagingFactory
if_.SetUseMesaClasses(1)
mapper = vtkPolyDataMapper()
mapper.SetInputConnection(reader.GetOutputPort())
actor = vtkActor()
actor.SetMapper(mapper)
renderer = vtkRenderer()
renderWindow = vtkRenderWindow()
renderWindow.SetSize(xsize, ysize)
renderWindow.SetOffScreenRendering(1)
renderWindow.AddRenderer(renderer)
renderer.AddActor(actor)
renderer.SetBackground(1, 1, 1)
renderWindow.Render()
wif = vtkWindowToImageFilter()
wif.SetInput(renderWindow)
wif.Update()
writer = vtkPNGWriter()
writer.SetFileName(outname)
writer.SetInput(wif.GetOutput())
writer.Write()