| 1 |
from opencamlib import ocl, camvtk |
| 2 |
import time |
| 3 |
|
| 4 |
if __name__ == "__main__": |
| 5 |
print(ocl.version()) |
| 6 |
myscreen = camvtk.VTKScreen() |
| 7 |
#stl = camvtk.STLSurf("../../../stl/demo.stl") |
| 8 |
stl = camvtk.STLSurf("../../../stl/gnu_tux_mod.stl") |
| 9 |
myscreen.addActor(stl) |
| 10 |
stl.SetWireframe() # render tux as wireframe |
| 11 |
#stl.SetSurface() # render tux as surface |
| 12 |
stl.SetColor(camvtk.cyan) |
| 13 |
polydata = stl.src.GetOutput() |
| 14 |
s = ocl.STLSurf() |
| 15 |
camvtk.vtkPolyData2OCLSTL(polydata, s) |
| 16 |
print("STL surface read,", s.size(), "triangles") |
| 17 |
zh=1.75145 |
| 18 |
cutter_diams = [1.4] |
| 19 |
length = 5 |
| 20 |
loops = [] |
| 21 |
for diam in cutter_diams: |
| 22 |
#cutter = ocl.CylCutter( diam , length ) |
| 23 |
cutter = ocl.BallCutter( diam , length ) |
| 24 |
#cutter = ocl.BullCutter( diam , diam/5, length ) |
| 25 |
wl = ocl.Waterline() |
| 26 |
wl.setSTL(s) |
| 27 |
wl.setCutter(cutter) |
| 28 |
wl.setZ(zh) |
| 29 |
wl.setSampling(0.1) |
| 30 |
#wl.setThreads(5) |
| 31 |
t_before = time.time() |
| 32 |
wl.run() |
| 33 |
t_after = time.time() |
| 34 |
calctime = t_after-t_before |
| 35 |
print(" Waterline done in ", calctime," s") |
| 36 |
cutter_loops = wl.getLoops() |
| 37 |
for l in cutter_loops: |
| 38 |
loops.append(l) |
| 39 |
|
| 40 |
print("All waterlines done. Got", len(loops)," loops in total.") |
| 41 |
# draw the loops |
| 42 |
nloop = 0 |
| 43 |
for lop in loops: |
| 44 |
n = 0 |
| 45 |
N = len(lop) |
| 46 |
first_point=ocl.Point(-1,-1,5) |
| 47 |
previous=ocl.Point(-1,-1,5) |
| 48 |
for p in lop: |
| 49 |
if n==0: # don't draw anything on the first iteration |
| 50 |
previous=p |
| 51 |
first_point = p |
| 52 |
elif n== (N-1): # the last point |
| 53 |
myscreen.addActor( camvtk.Line(p1=(previous.x,previous.y,previous.z),p2=(p.x,p.y,p.z),color=camvtk.yellow) ) # the normal line |
| 54 |
# and a line from p to the first point |
| 55 |
myscreen.addActor( camvtk.Line(p1=(p.x,p.y,p.z),p2=(first_point.x,first_point.y,first_point.z),color=camvtk.yellow) ) |
| 56 |
else: |
| 57 |
myscreen.addActor( camvtk.Line(p1=(previous.x,previous.y,previous.z),p2=(p.x,p.y,p.z),color=camvtk.yellow) ) |
| 58 |
previous=p |
| 59 |
n=n+1 |
| 60 |
print("rendered loop ",nloop, " with ", len(lop), " points") |
| 61 |
nloop = nloop+1 |
| 62 |
|
| 63 |
print("done.") |
| 64 |
myscreen.camera.SetPosition(15, 13, 7) |
| 65 |
myscreen.camera.SetFocalPoint(5, 5, 0) |
| 66 |
camvtk.drawArrows(myscreen,center=(-0.5,-0.5,-0.5)) |
| 67 |
camvtk.drawOCLtext(myscreen) |
| 68 |
myscreen.render() |
| 69 |
myscreen.iren.Start() |
| 70 |
#raw_input("Press Enter to terminate") |