File: drop_cutter_tst_5.py

package info (click to toggle)
opencamlib 2023.01.11-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,800 kB
  • sloc: cpp: 8,722; python: 5,530; sh: 604; javascript: 310; makefile: 209
file content (70 lines) | stat: -rw-r--r-- 2,150 bytes parent folder | download | duplicates (2)
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
from opencamlib import ocl, pyocl, camvtk
import time
import datetime

if __name__ == "__main__":  
    print(ocl.version())
    myscreen = camvtk.VTKScreen()
    stl = camvtk.STLSurf("../../../stl/gnu_tux_mod.stl")
    
    myscreen.addActor(stl)
    stl.SetWireframe()
    stl.SetColor((0.5,0.5,0.5))

    polydata = stl.src.GetOutput()
    s= ocl.STLSurf()
    camvtk.vtkPolyData2OCLSTL(polydata, s)
    print("STL surface read,", s.size(), "triangles" )
    
    cutter = ocl.CylCutter(0.6, 6)
    print(cutter)

    minx=-0.2
    dx=1
    maxx=10.2
    miny=-0.2
    dy=1
    maxy=12.2
    z=-0.2
    clpoints = pyocl.CLPointGrid(minx,dx,maxx,miny,dy,maxy,z)
    print(len(clpoints),"CL-points to evaluate...")
    tris = s.getTriangles()
    # very naive approach to drop-cutter (and doing loops in python is slow)
    # this is so slow in practice it is not usable with the tux-model STL-file (22k triangles)
    for cl in clpoints: # loop through all the cl-points
        for t in tris: # for each cl-point loop through all triangles
            cutter.vertexDrop(cl,t) # vertex test
            cutter.edgeDrop(cl,t)  # edge test
            cutter.facetDrop(cl,t) # facet test
    print("done.")

    camvtk.drawCLPointCloud(myscreen, clpoints)

    print(len(clpoints), " cl points evaluated")
    myscreen.camera.SetPosition(3, 23, 15)
    myscreen.camera.SetFocalPoint(4, 5, 0)
    myscreen.render()
    
    #w2if = vtk.vtkWindowToImageFilter()
    #w2if.SetInput(myscreen.renWin)
    #lwr = vtk.vtkPNGWriter()
    #lwr.SetInput( w2if.GetOutput() )
    #w2if.Modified()
    #lwr.SetFileName("tux1.png")
    #lwr.Write()
    
    t = camvtk.Text()
    t.SetPos( (myscreen.width-200, myscreen.height-30) )
    myscreen.addActor( t)
     
    for n in range(1,36):
        t.SetText(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
        myscreen.camera.Azimuth( 1 )
        time.sleep(0.01)
        myscreen.render()
        #lwr.SetFileName("frame"+ ('%03d' % n)+".png")
        #w2if.Modified() 
        #lwr.Write() #uncomment to write screenshots to disk

    myscreen.iren.Start()
    raw_input("Press Enter to terminate")