| 1 |
from opencamlib import ocl, camvtk |
| 2 |
import time |
| 3 |
|
| 4 |
def drawLoops(myscreen,loops,loopColor): |
| 5 |
# draw the loops |
| 6 |
nloop = 0 |
| 7 |
for lop in loops: |
| 8 |
n = 0 |
| 9 |
N = len(lop) |
| 10 |
first_point=ocl.Point(-1,-1,5) |
| 11 |
previous=ocl.Point(-1,-1,5) |
| 12 |
for p in lop: |
| 13 |
if n==0: # don't draw anything on the first iteration |
| 14 |
previous=p |
| 15 |
first_point = p |
| 16 |
elif n== (N-1): # the last point |
| 17 |
myscreen.addActor( camvtk.Line(p1=(previous.x,previous.y,previous.z),p2=(p.x,p.y,p.z),color=loopColor) ) # the normal line |
| 18 |
# and a line from p to the first point |
| 19 |
myscreen.addActor( camvtk.Line(p1=(p.x,p.y,p.z),p2=(first_point.x,first_point.y,first_point.z),color=loopColor) ) |
| 20 |
else: |
| 21 |
myscreen.addActor( camvtk.Line(p1=(previous.x,previous.y,previous.z),p2=(p.x,p.y,p.z),color=loopColor) ) |
| 22 |
previous=p |
| 23 |
n=n+1 |
| 24 |
print("rendered loop ",nloop, " with ", len(lop), " points") |
| 25 |
nloop = nloop+1 |
| 26 |
|
| 27 |
def getLoops(wl,zh,diam): |
| 28 |
t_before = time.time() |
| 29 |
wl.reset() |
| 30 |
wl.setZ(zh) |
| 31 |
wl.run() |
| 32 |
t_after = time.time() |
| 33 |
calctime = t_after-t_before |
| 34 |
print(" Waterline done in ", calctime," s") |
| 35 |
return wl.getLoops() |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
if __name__ == "__main__": |
| 40 |
print(ocl.version()) |
| 41 |
myscreen = camvtk.VTKScreen() |
| 42 |
#stl = camvtk.STLSurf("../../../stl/demo.stl") |
| 43 |
stl = camvtk.STLSurf("../../../stl/gnu_tux_mod.stl") |
| 44 |
myscreen.addActor(stl) |
| 45 |
#stl.SetWireframe() # render tux as wireframe |
| 46 |
stl.SetSurface() # render tux as surface |
| 47 |
stl.SetColor(camvtk.cyan) |
| 48 |
polydata = stl.src.GetOutput() |
| 49 |
s = ocl.STLSurf() |
| 50 |
camvtk.vtkPolyData2OCLSTL(polydata, s) |
| 51 |
print("STL surface read,", s.size(), "triangles") |
| 52 |
|
| 53 |
#zh = 1.0 |
| 54 |
t_before = time.time() |
| 55 |
diam = 0.5 |
| 56 |
zheights=[0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4, 2.6] |
| 57 |
zheights=[float(1.0)] |
| 58 |
wl = ocl.Waterline() |
| 59 |
#wl = ocl.AdaptiveWaterline() |
| 60 |
wl.setSTL(s) |
| 61 |
length= 10 |
| 62 |
cutter = ocl.BallCutter( diam , length ) |
| 63 |
wl.setCutter(cutter) |
| 64 |
wl.setSampling(0.0314) |
| 65 |
|
| 66 |
for zh in zheights: |
| 67 |
print("calculating Waterline at z= ", zh) |
| 68 |
cutter_loops = getLoops(wl,zh,diam) |
| 69 |
drawLoops(myscreen,cutter_loops,camvtk.red) |
| 70 |
t_after = time.time() |
| 71 |
calctime = t_after-t_before |
| 72 |
print(" TOTAL Waterline time is: ", calctime," s") |
| 73 |
|
| 74 |
print("done.") |
| 75 |
myscreen.camera.SetPosition(15, 13, 7) |
| 76 |
myscreen.camera.SetFocalPoint(5, 5, 0) |
| 77 |
camvtk.drawArrows(myscreen,center=(-0.5,-0.5,-0.5)) |
| 78 |
camvtk.drawOCLtext(myscreen) |
| 79 |
myscreen.render() |
| 80 |
myscreen.iren.Start() |
| 81 |
#raw_input("Press Enter to terminate") |