fix pocimg so it actually works
This commit is contained in:
parent
a54a3f6c52
commit
541cdf2220
2 changed files with 25 additions and 10 deletions
25
pocimg
25
pocimg
|
|
@ -26,14 +26,25 @@ import vtk
|
|||
|
||||
filename = sys.argv[1]
|
||||
|
||||
ns = poctools.execpoc(sys.argv[1:],
|
||||
__output__= os.path.splitext(filename)[0] + ".stl")
|
||||
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)
|
||||
|
||||
actor = vtk.vtkActor()
|
||||
ren = vtk.vtkRenderer()
|
||||
ren.AddActor(actor)
|
||||
ren.SetBackground(0,0,.5)
|
||||
|
|
@ -55,12 +66,6 @@ renWin = vtk.vtkRenderWindow()
|
|||
renWin.OffScreenRenderingOn()
|
||||
renWin.AddRenderer(ren)
|
||||
|
||||
reader = vtk.vtkSTLReader()
|
||||
reader.SetFileName(ns['__output__'])
|
||||
|
||||
mapper = vtk.vtkPolyDataMapper()
|
||||
mapper.SetInputConnection(reader.GetOutputPort())
|
||||
actor.SetMapper(mapper)
|
||||
|
||||
writer = vtk.vtkPNGWriter()
|
||||
|
||||
|
|
@ -73,6 +78,6 @@ w2if.SetMagnification(3)
|
|||
w2if.Update()
|
||||
|
||||
writer = vtk.vtkPNGWriter()
|
||||
writer.SetFileName(os.path.splitext(ns['__output__'])[0] + ".png")
|
||||
writer.SetFileName(os.path.splitext(filename)[0] + ".png")
|
||||
writer.SetInputConnection(w2if.GetOutputPort())
|
||||
writer.Write()
|
||||
|
|
|
|||
10
poctools.py
10
poctools.py
|
|
@ -22,8 +22,10 @@ import itertools
|
|||
import math
|
||||
import os
|
||||
import six
|
||||
import shutil
|
||||
import struct
|
||||
import sys
|
||||
import tempfile
|
||||
import traceback
|
||||
|
||||
import OCC.BRepAlgo
|
||||
|
|
@ -192,6 +194,14 @@ def withhelper(newop, newobj=None, finalop=None):
|
|||
op = holdop
|
||||
do_op(newobj)
|
||||
|
||||
@contextlib.contextmanager
|
||||
def TemporaryDirectory(*args):
|
||||
d = tempfile.mkdtemp(*args)
|
||||
try:
|
||||
yield d
|
||||
finally:
|
||||
shutil.rmtree(d)
|
||||
|
||||
### Primitives
|
||||
|
||||
def Box(p1, p2):
|
||||
|
|
|
|||
Loading…
Reference in a new issue