This repository has been archived by the owner on Jun 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pocimg
executable file
·83 lines (67 loc) · 2.27 KB
/
pocimg
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
81
82
83
#!/usr/bin/python2
# -*- coding: utf-8 -*-
# auto-updating viewer of 'poc' modeling program
# Copyright © 2017 Jeff Epler <jepler@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from occmodelviewer import Viewer
import os
import poctools
import sys
import time
import traceback
import vtk
filename = sys.argv[1]
with poctools.TemporaryDirectory() as d:
stlfile = os.path.join(d, "out.stl")
ns = poctools.execpoc(sys.argv[1:])
poctools.output(stlfile)
reader = vtk.vtkSTLReader()
reader.SetFileName(stlfile)
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(reader.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetBounds() # forces STL file to be read now
b = poctools.Bbox(poctools.Object())
diag = ((b[3] - b[0]) ** 2 + (b[4] - b[1]) ** 2 + (b[5] - b[2]) ** 2) ** .5
center = ((b[0] + b[3]) / 2, (b[4] + b[1]) / 2, (b[5]+ b[2]) / 2)
ren = vtk.vtkRenderer()
ren.AddActor(actor)
ren.SetBackground(0,0,.5)
ren.SetBackground2(.1,.1,.2)
ren.SetGradientBackground(True)
camera = vtk.vtkCamera()
camera.SetFocalPoint(center)
camera.SetViewUp((0,0,1))
camera.ParallelProjectionOff()
camera.Azimuth(-37.5)
camera.Elevation(30)
camera.SetPosition(1.4*diag, diag, diag)
ren.SetActiveCamera(camera)
ren.ResetCamera()
renWin = vtk.vtkRenderWindow()
renWin.OffScreenRenderingOn()
renWin.AddRenderer(ren)
writer = vtk.vtkPNGWriter()
renWin.Render()
w2if = vtk.vtkWindowToImageFilter()
w2if.SetInput(renWin)
w2if.ReadFrontBufferOff()
w2if.SetMagnification(3)
w2if.Update()
writer = vtk.vtkPNGWriter()
writer.SetFileName(os.path.splitext(filename)[0] + ".png")
writer.SetInputConnection(w2if.GetOutputPort())
writer.Write()