| 1 |
from opencamlib import ocl, pyocl, camvtk |
| 2 |
import time |
| 3 |
import datetime |
| 4 |
|
| 5 |
if __name__ == "__main__": |
| 6 |
print(ocl.version()) |
| 7 |
myscreen = camvtk.VTKScreen() |
| 8 |
stl = camvtk.STLSurf("../../../stl/gnu_tux_mod.stl") |
| 9 |
|
| 10 |
myscreen.addActor(stl) |
| 11 |
stl.SetWireframe() |
| 12 |
stl.SetColor((0.5,0.5,0.5)) |
| 13 |
|
| 14 |
polydata = stl.src.GetOutput() |
| 15 |
s= ocl.STLSurf() |
| 16 |
camvtk.vtkPolyData2OCLSTL(polydata, s) |
| 17 |
print("STL surface read,", s.size(), "triangles" ) |
| 18 |
|
| 19 |
cutter = ocl.CylCutter(0.6, 6) |
| 20 |
print(cutter) |
| 21 |
|
| 22 |
minx=-0.2 |
| 23 |
dx=1 |
| 24 |
maxx=10.2 |
| 25 |
miny=-0.2 |
| 26 |
dy=1 |
| 27 |
maxy=12.2 |
| 28 |
z=-0.2 |
| 29 |
clpoints = pyocl.CLPointGrid(minx,dx,maxx,miny,dy,maxy,z) |
| 30 |
print(len(clpoints),"CL-points to evaluate...") |
| 31 |
tris = s.getTriangles() |
| 32 |
# very naive approach to drop-cutter (and doing loops in python is slow) |
| 33 |
# this is so slow in practice it is not usable with the tux-model STL-file (22k triangles) |
| 34 |
for cl in clpoints: # loop through all the cl-points |
| 35 |
for t in tris: # for each cl-point loop through all triangles |
| 36 |
cutter.vertexDrop(cl,t) # vertex test |
| 37 |
cutter.edgeDrop(cl,t) # edge test |
| 38 |
cutter.facetDrop(cl,t) # facet test |
| 39 |
print("done.") |
| 40 |
|
| 41 |
camvtk.drawCLPointCloud(myscreen, clpoints) |
| 42 |
|
| 43 |
print(len(clpoints), " cl points evaluated") |
| 44 |
myscreen.camera.SetPosition(3, 23, 15) |
| 45 |
myscreen.camera.SetFocalPoint(4, 5, 0) |
| 46 |
myscreen.render() |
| 47 |
|
| 48 |
#w2if = vtk.vtkWindowToImageFilter() |
| 49 |
#w2if.SetInput(myscreen.renWin) |
| 50 |
#lwr = vtk.vtkPNGWriter() |
| 51 |
#lwr.SetInput( w2if.GetOutput() ) |
| 52 |
#w2if.Modified() |
| 53 |
#lwr.SetFileName("tux1.png") |
| 54 |
#lwr.Write() |
| 55 |
|
| 56 |
t = camvtk.Text() |
| 57 |
t.SetPos( (myscreen.width-200, myscreen.height-30) ) |
| 58 |
myscreen.addActor( t) |
| 59 |
|
| 60 |
for n in range(1,36): |
| 61 |
t.SetText(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) |
| 62 |
myscreen.camera.Azimuth( 1 ) |
| 63 |
time.sleep(0.01) |
| 64 |
myscreen.render() |
| 65 |
#lwr.SetFileName("frame"+ ('%03d' % n)+".png") |
| 66 |
#w2if.Modified() |
| 67 |
#lwr.Write() #uncomment to write screenshots to disk |
| 68 |
|
| 69 |
myscreen.iren.Start() |
| 70 |
raw_input("Press Enter to terminate") |