Exemplo n.º 1
0
def STLSurfaceSource(filename):
    stl = camvtk.STLSurf(filename)
    polydata = stl.src.GetOutput()
    s = ocl.STLSurf()
    camvtk.vtkPolyData2OCLSTL(polydata, s)
    return s
import ocl
import camvtk
import time
import vtk

if __name__ == "__main__":
    print(ocl.version())

    myscreen = camvtk.VTKScreen()
    stl = camvtk.STLSurf("../stl/gnu_tux_mod.stl")
    print("STL surface read")
    myscreen.addActor(stl)
    stl.SetWireframe()
    polydata = stl.src.GetOutput()
    s = ocl.STLSurf()
    camvtk.vtkPolyData2OCLSTL(polydata, s)
    print("STLSurf with ", s.size(), " triangles")

    # define a cutter
    cutter = ocl.CylCutter(0.6, 5)
    print(cutter)

    print("creating PathDropCutter()")
    pdc = ocl.PathDropCutter()  # create a pdc
    print("set STL surface")
    pdc.setSTL(s)
    print("set cutter")
    pdc.setCutter(cutter)  # set the cutter
    print("set minimumZ")
    pdc.minimumZ = -1  # set the minimum Z-coordinate, or "floor" for drop-cutter
    print("set the sampling interval")
Exemplo n.º 3
0
if __name__ == "__main__":
    print ocl.version()
    myscreen = camvtk.VTKScreen()
    #stl = camvtk.STLSurf("../../stl/demo.stl")
    #stl = camvtk.STLSurf("../../stl/gnu_tux_mod.stl")
    #stl = camvtk.STLSurf("../../stl/porche.stl")
    #stl = camvtk.STLSurf("../../stl/ktoolcav.stl")
    #stl = camvtk.STLSurf("../../stl/ktoolcor.stl")
    stl = camvtk.STLSurf("../../stl/sphere_cutout.stl")
    #myscreen.addActor(stl)
    #stl.SetWireframe() # render tux as wireframe
    #stl.SetSurface() # render tux as surface
    #stl.SetColor(camvtk.cyan)
    polydata = stl.src.GetOutput()  # get polydata from vtk-surface
    s = ocl.STLSurf()
    camvtk.vtkPolyData2OCLSTL(polydata, s)  #put triangles on ocl-surface
    #s.rotate(-math.pi/2,math.pi,0)
    stl2 = camvtk.STLSurf(triangleList=s.getTriangles())
    myscreen.addActor(stl2)
    stl2.SetSurface()
    stl2.SetColor(camvtk.cyan)
    print "STL surface read,", s.size(), "triangles"
    zh = -0.5
    zheights = [-0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, -0.05]  # for cavity
    zheights = [-0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7]  # for core
    zheights = [10, 20, 30, 40, 50, 60]  # for waterline1.stl
    diam = 6
    length = 100
    loops = []

    #cutter = ocl.CylCutter( diam , length )
Exemplo n.º 4
0
import ocl
import pyocl
import camvtk

stl = camvtk.STLSurf("./model0.stl")
stl_polydata = stl.src.GetOutput()
stl_surf = ocl.STLSurf()
camvtk.vtkPolyData2OCLSTL(stl_polydata, stl_surf)
csv_file = open("ocl_settings.txt", "r")
op_cutter_type = csv_file.readline().split()[0]
op_cutter_diameter = float(csv_file.readline())
op_minz = float(csv_file.readline())
csv_file.close()

cutter_length = 5
if op_cutter_type == "END":
    cutter = ocl.CylCutter(op_cutter_diameter * 1000, cutter_length)
elif op_cutter_type == "BALL":
    cutter = ocl.BallCutter(op_cutter_diameter * 1000, cutter_length)
elif op_cutter_type == "VCARVE":
    cutter = ocl.ConeCutter(op_cutter_diameter * 1000, 1, cutter_length)
else:
    print "Cutter unsupported: " + op_cutter_type + "\n"
    quit()
# add BullCutter
bdc = ocl.BatchDropCutter()
bdc.setSTL(stl_surf)
bdc.setCutter(cutter)

csv_file = open("ocl_chunks.txt", "r")
for text_line in csv_file:
Exemplo n.º 5
0
def main():
    myscreen = camvtk.VTKScreen()
    focal = cam.Point(5, 5, 0)
    r = 30
    theta = (float(45)/360)*2*math.pi
    fi=45
    
    campos = cam.Point( r*math.sin(theta)*math.cos(fi), r*math.sin(theta)*math.sin(fi), r*math.cos(theta) ) 
    myscreen.camera.SetPosition(campos.x, campos.y, campos.z)
    myscreen.camera.SetFocalPoint(focal.x,focal.y, focal.z)
    
    t = camvtk.Text()
    t.SetPos( (myscreen.width-450, myscreen.height-30) )

    
    myscreen.addActor( t)
    t2 = camvtk.Text()
    ytext = "kd-tree debug" #"Y: %3.3f" % (ycoord)
    t2.SetText(ytext)
    t2.SetPos( (50, myscreen.height-50) )   
    myscreen.addActor( t2)
        
    #w2if = vtk.vtkWindowToImageFilter()
    #w2if.SetInput(myscreen.renWin)
    #lwr = vtk.vtkPNGWriter()
    #lwr.SetInput( w2if.GetOutput() )
  
    
    t.SetText("OpenCAMLib 10.03-beta, " + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
    
    
    #ycoord = 1.1
    
    stl = camvtk.STLSurf(filename="../stl/demo.stl")
    #stl = camvtk.STLSurf(filename="../stl/demo2.stl")
    print("STL surface read")
    #myscreen.addActor(stl)
    #stl.SetWireframe()
    #stl.SetColor((0.5,0.5,0.5))
    polydata = stl.src.GetOutput()
    s= cam.STLSurf()
    camvtk.vtkPolyData2OCLSTL(polydata, s)
    print("STLSurf with ", s.size(), " triangles")
    
    
    myscreen.addActor( camvtk.Sphere( center=(0,0,0), radius=0.2, color = camvtk.yellow ) )
  
    s.build_kdtree()
    print("built kd-tree")
    s.jump_kd_reset()
    
    tlist = s.get_kd_triangles()
    
    print("got", len(tlist), " triangles")
    
    while (s.jump_kd_hi()):
        lotris = s.get_kd_triangles()
        s.jump_kd_up()
        cut = s.get_kd_cut()
        s.jump_kd_lo()
        hitris = s.get_kd_triangles()
        lev = s.get_kd_level()
        
        print("l=", lev, " hi=", len(hitris), " lo=", len(lotris), " cut=", cut)
        
        if ( cut[0] < 2 ):
            print("x cut ",)
            if ( cut[0] == 0):
                print("max" )
                myscreen.addActor( camvtk.Line( p1=(cut[1],100,0), p2=(cut[1],-100,0), color = camvtk.green ) )
            else:
                print("min" )
                myscreen.addActor( camvtk.Line( p1=(cut[1],100,0), p2=(cut[1],-100,0), color = camvtk.lgreen ) )
            #myscreen.addActor( camvtk.Line( p1=(100,cut[1],0), p2=(-100,cut[1],0), color = camvtk.red ) )
        else:
            print("y cut ",)
            if ( cut[0] == 2):
                print("max" )
                myscreen.addActor( camvtk.Line( p1=(100,cut[1],0), p2=(-100,cut[1],0), color = camvtk.red ) )
            else:
                print("min")
                myscreen.addActor( camvtk.Line( p1=(100,cut[1],0), p2=(-100,cut[1],0), color = camvtk.pink ) )
            
        
        slo = camvtk.STLSurf(triangleList=lotris)
        slo.SetColor(camvtk.pink)
        slo.SetWireframe()
        shi = camvtk.STLSurf(triangleList=hitris)
        shi.SetColor(camvtk.lgreen)
        shi.SetWireframe()
        myscreen.addActor(slo)
        myscreen.addActor(shi)
        myscreen.render()
        myscreen.iren.Start()
        raw_input("Press Enter to terminate")   
        time.sleep(1)
        myscreen.removeActor(slo)
        myscreen.removeActor(shi)
    

  
    print("done.")
    myscreen.render()
    #lwr.SetFileName(filename)
    
    #raw_input("Press Enter to terminate")         
    time.sleep(0.2)
    #lwr.Write()
    myscreen.iren.Start()
def getWeaveRAM(Nmax,weave2_flag):
    #stl = camvtk.STLSurf("../stl/demo.stl")
    stl = camvtk.STLSurf("../stl/gnu_tux_mod.stl")
    polydata = stl.src.GetOutput()
    s = ocl.STLSurf()
    camvtk.vtkPolyData2OCLSTL(polydata, s)
    cutter = ocl.CylCutter(0.3, 5)
    fiber_range=30
    #Nmax = 400
    yvals = [float(n-float(Nmax)/2)/Nmax*float(fiber_range) for n in xrange(0,Nmax+1)]
    xvals = [float(n-float(Nmax)/2)/Nmax*float(fiber_range) for n in xrange(0,Nmax+1)]
    zvals=[ 1.6523]
    bpc_x = ocl.BatchPushCutter()
    bpc_y = ocl.BatchPushCutter()
    bpc_x.setXDirection()
    bpc_y.setYDirection()
    bpc_x.setSTL(s)
    bpc_y.setSTL(s)
    bpc_x.setCutter(cutter)
    bpc_y.setCutter(cutter)
    # create fibers
    for zh in zvals:
        for y in yvals:
            f1 = ocl.Point(-15.5,y,zh) # start point of fiber
            f2 = ocl.Point(15.5,y,zh)  # end point of fiber
            f =  ocl.Fiber( f1, f2)
            bpc_x.appendFiber(f)
        for x in xvals:
            f1 = ocl.Point(x,-15.5,zh) # start point of fiber
            f2 = ocl.Point(x,15.5,zh)  # end point of fiber
            f =  ocl.Fiber( f1, f2)
            bpc_y.appendFiber(f)
            
    # run
    bpc_x.run()
    bpc_y.run()
    xfibers = bpc_x.getFibers()
    yfibers = bpc_y.getFibers()
    fibers = xfibers+yfibers
    print " got ",len(xfibers)," xfibers"
    print " got ",len(yfibers)," yfibers"
    fibercount = len(xfibers) + len(yfibers)
    print "rendering fibers and CL-points."
    w = ocl.Weave()
    print "push fibers to Weave...",
    for f in fibers:
        w.addFiber(f)
    print "done."
    print "Weave build()...",
    mem1 = procmemory.memory()
    if weave2_flag==1:
        w.build2()
    else:
        w.build()
    mem2 = procmemory.memory()
    #print "after ", float(mem2)/float(1024*1024), " MB"
    megabytes = float(mem2-mem1)/float(1024*1024)
    megabytes2 = float(mem2)/float(1024*1024)
    verts = w.numVertices()
    print " before: ", float(mem1)/float(1024*1024)
    print "  after: ", float(mem2)/float(1024*1024)
    print " build() memory: ",megabytes," MB"
    print "done"
    print "face_traverse..."
    w.face_traverse()
    print "done."
    w_clpts = w.getCLVertices()
    w_ipts = w.getINTVertices()
    w_edges = w.getEdges()
    w_loop = w.getLoops()


    print " got: ", len(w_edges), " edges"
    print " got: ", len(w_loop), " loops"
    out=[]
    out.append(fibercount)
    out.append(verts)
    return out
Exemplo n.º 7
0
if __name__ == "__main__":  
    print(ocl.version())
    myscreen = camvtk.VTKScreen()
    #stl = camvtk.STLSurf("../../stl/demo.stl")
    #stl = camvtk.STLSurf("../../stl/gnu_tux_mod.stl")
    #stl = camvtk.STLSurf("../../stl/porche.stl")
    #stl = camvtk.STLSurf("../../stl/ktoolcav.stl")
    #stl = camvtk.STLSurf("../../stl/ktoolcor.stl")
    stl = camvtk.STLSurf("../../stl/sphere_cutout.stl")
    #myscreen.addActor(stl)
    #stl.SetWireframe() # render tux as wireframe
    #stl.SetSurface() # render tux as surface
    #stl.SetColor(camvtk.cyan)
    polydata = stl.src.GetOutput() # get polydata from vtk-surface
    s = ocl.STLSurf()
    camvtk.vtkPolyData2OCLSTL(polydata, s) #put triangles on ocl-surface
    #s.rotate(-math.pi/2,math.pi,0)
    stl2 = camvtk.STLSurf(triangleList= s.getTriangles() )
    myscreen.addActor(stl2) 
    stl2.SetSurface()
    stl2.SetColor(camvtk.cyan)
    print("STL surface read,", s.size(), "triangles")
    zh=-0.5
    zheights=[ -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, -0.05] # for cavity
    zheights=[ -0.1, 0.0, 0.1, 0.2, 0.3, 0.4 , 0.5, 0.6, 0.7] # for core
    zheights=[ 10, 20, 30, 40, 50, 60] # for waterline1.stl
    diam = 6
    length = 100
    loops = []

    #cutter = ocl.CylCutter( diam , length )
Exemplo n.º 8
0
import datetime

if __name__ == "__main__":  
    myscreen = camvtk.VTKScreen()
    myscreen.setAmbient(20,20,20)
    
    #stl = camvtk.STLSurf(filename="demo.stl")
    stl = camvtk.STLSurf(filename="demo2.stl")
    print("STL surface read")
    myscreen.addActor(stl)
    stl.SetWireframe()
    stl.SetColor((0.5,0.5,0.5))
    #stl.SetFlat()
    polydata = stl.src.GetOutput()
    s= cam.STLSurf()
    camvtk.vtkPolyData2OCLSTL(polydata, s)
    print("STLSurf with ", s.size(), " triangles")
    cutterDiameter=0.6
    cutter = cam.CylCutter(cutterDiameter)
    #print cutter.str()
    #print cc.type
    minx=-20
    dx=1
    maxx=20
    
    miny=-20
    dy=01
    maxy=20
    z=-0.2
    
    bucketSize = 20
Exemplo n.º 9
0
def STLSurfaceSource(filename):
    stl = camvtk.STLSurf(filename)
    polydata = stl.src.GetOutput()
    s = ocl.STLSurf()
    camvtk.vtkPolyData2OCLSTL(polydata, s)
    return s
Exemplo n.º 10
0
def main(filename="frame/f.png"):  
    print ocl.revision()
          
    myscreen = camvtk.VTKScreen()   
    myscreen.camera.SetPosition(-15, -8, 15)
    myscreen.camera.SetFocalPoint(5,5, 0)   
    # axis arrows
    camvtk.drawArrows(myscreen,center=(-1,-1,0))

    
    # screenshot writer
    w2if = vtk.vtkWindowToImageFilter()
    w2if.SetInput(myscreen.renWin)
    lwr = vtk.vtkPNGWriter()
    lwr.SetInput( w2if.GetOutput() )
        

    
    c = ocl.CylCutter(2) # cutter
    c.length = 3
    print "cutter length=", c.length
    
    # generate CL-points
    stl = camvtk.STLSurf("../stl/demo.stl")
    polydata = stl.src.GetOutput()
    s = ocl.STLSurf()
    camvtk.vtkPolyData2OCLSTL(polydata, s)
    print "STL surface read,", s.size(), "triangles"
    print s.getBounds()
    #exit()
    minx=0
    dx=0.1/6
    maxx=10
    miny=0
    dy=1
    maxy=10
    z=-17
    # this generates a list of CL-points in a grid
    clpoints = pyocl.CLPointGridZigZag(minx,dx,maxx,miny,dy,maxy,z)
    print "generated grid with", len(clpoints)," CL-points"
    # batchdropcutter    
    bdc = ocl.BatchDropCutter()
    bdc.setSTL(s,1)
    bdc.setCutter(c)
    for p in clpoints:
        bdc.appendPoint(p)
    t_before = time.time()    
    print "threads=",bdc.nthreads
    bdc.dropCutter4()
    t_after = time.time()
    calctime = t_after-t_before
    print " done in ", calctime," s"
    clpoints = bdc.getCLPoints()
    
    # filter
    print "filtering. before filter we have", len(clpoints),"cl-points"
    f = ocl.LineCLFilter()
    f.setTolerance(0.001)
    for p in clpoints:
        f.addCLPoint(p)
    f.run()
    clpts = f.getCLPoints()
    print "after filtering we have", len(clpts),"cl-points"
    
    #exit()
        
    # stupid init code
    f=ocl.Ocode()
    tree_maxdepth=8
    f.set_depth(tree_maxdepth) # depth and scale set here.
    f.set_scale(10)
    
    # cube
    stockvol = ocl.BoxOCTVolume()
    stockvol.corner = ocl.Point(0,0,-0.5)
    stockvol.v1 = ocl.Point(10,0,0)
    stockvol.v2 = ocl.Point(0,10,0)
    stockvol.v3 = ocl.Point(0,0,3)
    stockvol.calcBB()
    #cube1.side=10.0
    #cube1.center = ocl.Point(0,0,0)
    #cube1.calcBB()
    
    t_before = time.time()
    stock = ocl.LinOCT()
    stock.init(3)
    stock.build( stockvol )
    calctime = time.time()-t_before
    print " stock built in ", calctime," s, stock.size()=",stock.size()
        
    # draw initial octree 
    #tlist = pyocl.octree2trilist(stock)
    #surf = camvtk.STLSurf(triangleList=tlist)
    #myscreen.addActor(surf)
    
    # draw initial cutter
    #startp = ocl.Point(0,0,0)
    #cyl = camvtk.Cylinder(center=(startp.x,startp.y,startp.z), radius=c.radius,
    #                        height=c.length,
    #                        rotXYZ=(90,0,0), color=camvtk.grey)
    #cyl.SetWireframe()
    #myscreen.addActor(cyl)
    
    timetext = camvtk.Text()
    timetext.SetPos( (myscreen.width-300, myscreen.height-30) )
    myscreen.addActor( timetext)
    
    ocltext = camvtk.Text()
    ocltext.SetPos( (myscreen.width-300, myscreen.height-60) )
    myscreen.addActor( ocltext)
    ocltext.SetText("OpenCAMLib")
    
    octtext = camvtk.Text()
    octtext.SetPos( (myscreen.width-300, myscreen.height-90) )
    myscreen.addActor( octtext)
    octtext.SetText("Octree cutting-simulation")
    
    infotext = camvtk.Text()
    infotext.SetPos( (myscreen.width-300, myscreen.height-180) )
    myscreen.addActor( infotext)
    
    
    Nmoves = len(clpts)
    print Nmoves,"CL-points to process"
    for n in xrange(0,Nmoves-1):
        timetext.SetText(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
        
        #if n<Nmoves-1:
        print n," to ",n+1
        startp = clpts[n]  # start of move
        endp   = clpts[n+1] # end of move
        
        t_before = time.time()
        sweep = ocl.LinOCT()
        sweep.init(0)
        calctime = time.time()-t_before
        print " sweep-init done in ", calctime," s, sweep.size()=",sweep.size()
        
        g1vol = ocl.CylMoveOCTVolume(c, ocl.Point(startp.x,startp.y,startp.z), ocl.Point(endp.x,endp.y,endp.z))
        
        t_before = time.time()
        sweep.build( g1vol )
        calctime = time.time()-t_before
        print " sweep-build done in ", calctime," s, sweep.size()=",sweep.size()
        
        # draw cutter
        cyl1 = camvtk.Cylinder(center=(startp.x,startp.y,startp.z), radius=c.radius,
                            height=c.length,
                            rotXYZ=(90,0,0), color=camvtk.lgreen)
        cyl1.SetWireframe()
        #myscreen.addActor(cyl1)
        cyl2 = camvtk.Cylinder(center=(endp.x,endp.y,endp.z), radius=c.radius,
                            height=c.length,
                            rotXYZ=(90,0,0), color=camvtk.pink)
        cyl2.SetWireframe()
        #myscreen.addActor(cyl2)
        
    
        #camvtk.drawCylCutter(myscreen, c, startp)
        #camvtk.drawCylCutter(myscreen, c, endp)
        myscreen.addActor( camvtk.Line( p1=(startp.x,startp.y,startp.z), p2=(endp.x,endp.y,endp.z), color=camvtk.red))
        #camvtk.drawTree2(myscreen,sweep,color=camvtk.red,opacity=0.5)
        

            
        t_before = time.time()
        stock.diff(sweep)
        calctime = time.time()-t_before
        print " diff done in ", calctime," s, stock.size()", stock.size()
        
        info = "tree-depth:%i \nmove: %i \nstock-nodes: %i \nsweep-nodes: %i" % (tree_maxdepth, n, stock.size(), sweep.size() )
        infotext.SetText(info)
        
        
        if (n%1==0 or n==Nmoves-2): # draw only every m:th frame
            # sweep surface 
            t_before = time.time()
            #sweep_tlist = pyocl.octree2trilist(sweep)
            sweep_tlist = sweep.get_triangles()
            sweepsurf = camvtk.STLSurf(triangleList=sweep_tlist)
            sweepsurf.SetColor(camvtk.red)
            sweepsurf.SetOpacity(0.1)
            myscreen.addActor(sweepsurf)
            calctime = time.time()-t_before
            print " sweepsurf-render  ", calctime," s"
                   
            # stock surface 
            t_before = time.time()
            #tlist = pyocl.octree2trilist(stock)
            tlist = stock.get_triangles()
            stocksurf = camvtk.STLSurf(triangleList=tlist)
            stocksurf.SetColor(camvtk.cyan)
            stocksurf.SetOpacity(1.0)
            myscreen.addActor(stocksurf)
            calctime = time.time()-t_before
            print " stocksurf-render  ", calctime," s"
            
            #time.sleep(1.1)
            # write screenshot to disk
            lwr.SetFileName("frames/cutsim_frame"+ ('%03d' % n)+".png")
            #lwr.SetFileName(filename)
            
            t_before = time.time() # time the render process
            myscreen.render()
            w2if.Modified() 
            lwr.Write()
            
            calctime = time.time()-t_before
            print " render  ", calctime," s"
            
            #myscreen.render()
            #time.sleep(0.1)
            
            myscreen.removeActor(sweepsurf)
            if n != (Nmoves-2):
                myscreen.removeActor(stocksurf)
                
        

        
        #myscreen.removeActor(cyl1)
        #myscreen.removeActor(cyl2)
        #myscreen.render()
        #time.sleep(0.1)

    print " render()...",
    myscreen.render()
    print "done."
    
    
    #time.sleep(0.2)
    
    
    
    myscreen.iren.Start() 
Exemplo n.º 11
0
def main(filename="frame/f.png"):
    print(ocl.version())

    myscreen = camvtk.VTKScreen()
    myscreen.camera.SetPosition(-15, -8, 15)
    myscreen.camera.SetFocalPoint(5, 5, 0)
    # axis arrows
    camvtk.drawArrows(myscreen, center=(-1, -1, 0))

    # screenshot writer
    w2if = vtk.vtkWindowToImageFilter()
    w2if.SetInput(myscreen.renWin)
    lwr = vtk.vtkPNGWriter()
    lwr.SetInput(w2if.GetOutput())

    c = ocl.CylCutter(1, 4)  # cutter
    c.length = 3
    print("cutter length=", c.length)

    # generate CL-points
    stl = camvtk.STLSurf("../stl/gnu_tux_mod.stl")
    polydata = stl.src.GetOutput()
    s = ocl.STLSurf()
    camvtk.vtkPolyData2OCLSTL(polydata, s)
    print("STL surface read,", s.size(), "triangles")
    print(s.getBounds())
    #exit()
    minx = 0
    dx = 0.1
    maxx = 9
    miny = 0
    dy = 0.4
    maxy = 12
    z = -17
    # this generates a list of CL-points in a grid
    clpoints = pyocl.CLPointGridZigZag(minx, dx, maxx, miny, dy, maxy, z)
    print("generated grid with", len(clpoints), " CL-points")
    # batchdropcutter
    bdc = ocl.BatchDropCutter()
    bdc.setSTL(s)
    bdc.setCutter(c)
    for p in clpoints:
        bdc.appendPoint(p)
    t_before = time.time()
    print("threads=", bdc.getThreads())
    bdc.run()
    t_after = time.time()
    calctime = t_after - t_before
    print(" done in ", calctime, " s")
    clpoints = bdc.getCLPoints()

    # filter
    print("filtering. before filter we have", len(clpoints), "cl-points")
    t_before = time.time()
    f = ocl.LineCLFilter()
    f.setTolerance(0.001)
    for p in clpoints:
        f.addCLPoint(p)
    f.run()
    clpts = f.getCLPoints()
    calctime = time.time() - t_before
    print("after filtering we have", len(clpts), "cl-points")
    print(" done in ", calctime, " s")

    #exit()

    # stupid init code
    ocode = ocl.Ocode()
    tree_maxdepth = 10
    ocode.set_depth(tree_maxdepth)  # depth and scale set here.
    ocode.set_scale(10)

    # cube
    stockvol = ocl.BoxOCTVolume()
    stockvol.corner = ocl.Point(0, 0, -0.5)
    stockvol.v1 = ocl.Point(9, 0, 0)
    stockvol.v2 = ocl.Point(0, 12, 0)
    stockvol.v3 = ocl.Point(0, 0, 3.5)
    stockvol.calcBB()

    t_before = time.time()
    stock = ocl.LinOCT()
    stock.init(0)
    stock.build(stockvol)
    calctime = time.time() - t_before
    print(" stock built in ", calctime, " s, stock.size()=", stock.size())

    # draw initial octree
    #tlist = pyocl.octree2trilist(stock)
    #surf = camvtk.STLSurf(triangleList=tlist)
    #myscreen.addActor(surf)

    # draw initial cutter
    #startp = ocl.Point(0,0,0)
    #cyl = camvtk.Cylinder(center=(startp.x,startp.y,startp.z), radius=c.radius,
    #                        height=c.length,
    #                        rotXYZ=(90,0,0), color=camvtk.grey)
    #cyl.SetWireframe()
    #myscreen.addActor(cyl)

    timetext = camvtk.Text()
    timetext.SetPos((myscreen.width - 300, myscreen.height - 30))
    myscreen.addActor(timetext)

    ocltext = camvtk.Text()
    ocltext.SetPos((myscreen.width - 300, myscreen.height - 60))
    myscreen.addActor(ocltext)
    ocltext.SetText("OpenCAMLib")

    octtext = camvtk.Text()
    octtext.SetPos((myscreen.width - 300, myscreen.height - 90))
    myscreen.addActor(octtext)
    octtext.SetText("Octree cutting-simulation")

    infotext = camvtk.Text()
    infotext.SetPos((myscreen.width - 300, myscreen.height - 180))
    myscreen.addActor(infotext)

    Nmoves = len(clpts)
    print(Nmoves, "CL-points to process")
    for n in range(0, Nmoves - 1):
        timetext.SetText(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))

        #if n<Nmoves-1:
        print(n, " to ", n + 1, " of ", Nmoves)
        startp = clpts[n]  # start of move
        endp = clpts[n + 1]  # end of move

        #t_before = time.time()
        sweep = ocl.LinOCT()
        sweep.init(0)
        #calctime = time.time()-t_before
        #print " sweep-init done in ", calctime," s, sweep.size()=",sweep.size()

        g1vol = ocl.CylMoveOCTVolume(c, ocl.Point(startp.x, startp.y,
                                                  startp.z),
                                     ocl.Point(endp.x, endp.y, endp.z))

        t_before = time.time()
        sweep.build(g1vol)
        calctime = time.time() - t_before
        print(" sweep-build done in ", calctime, " s, sweep.size()=",
              sweep.size())

        # draw cutter
        cyl1 = camvtk.Cylinder(center=(startp.x, startp.y, startp.z),
                               radius=c.radius,
                               height=c.length,
                               rotXYZ=(90, 0, 0),
                               color=camvtk.lgreen)
        cyl1.SetWireframe()
        #myscreen.addActor(cyl1)
        cyl2 = camvtk.Cylinder(center=(endp.x, endp.y, endp.z),
                               radius=c.radius,
                               height=c.length,
                               rotXYZ=(90, 0, 0),
                               color=camvtk.pink)
        cyl2.SetWireframe()
        #myscreen.addActor(cyl2)

        #camvtk.drawCylCutter(myscreen, c, startp)
        #camvtk.drawCylCutter(myscreen, c, endp)
        myscreen.addActor(
            camvtk.Line(p1=(startp.x, startp.y, startp.z),
                        p2=(endp.x, endp.y, endp.z),
                        color=camvtk.red))
        #camvtk.drawTree2(myscreen,sweep,color=camvtk.red,opacity=0.5)

        t_before = time.time()
        stock.diff(sweep)
        calctime = time.time() - t_before
        print(" diff done in ", calctime, " s, stock.size()", stock.size())

        info = "tree-depth:%i \nmove: %i \nstock-nodes: %i \nsweep-nodes: %i" % (
            tree_maxdepth, n, stock.size(), sweep.size())
        infotext.SetText(info)

        if ((n != 0 and n % 10 == 0)
                or n == Nmoves - 2):  # draw only every m:th frame
            # sweep surface
            t_before = time.time()
            #sweep_tlist = pyocl.octree2trilist(sweep)
            sweep_tlist = sweep.get_triangles()
            sweepsurf = camvtk.STLSurf(triangleList=sweep_tlist)
            sweepsurf.SetColor(camvtk.red)
            sweepsurf.SetOpacity(0.1)
            myscreen.addActor(sweepsurf)
            calctime = time.time() - t_before
            print(" sweepsurf-render  ", calctime, " s")

            # stock surface
            t_before = time.time()
            #tlist = pyocl.octree2trilist(stock)
            tlist = stock.get_triangles()
            stocksurf = camvtk.STLSurf(triangleList=tlist)
            stocksurf.SetColor(camvtk.cyan)
            stocksurf.SetOpacity(1.0)
            myscreen.addActor(stocksurf)
            calctime = time.time() - t_before
            print(" stocksurf-render  ", calctime, " s")

            #time.sleep(1.1)
            # write screenshot to disk
            lwr.SetFileName("frames/tux_frame" + ('%06d' % n) + ".png")
            #lwr.SetFileName(filename)

            t_before = time.time()  # time the render process
            myscreen.render()
            w2if.Modified()
            lwr.Write()

            calctime = time.time() - t_before
            print(" render  ", calctime, " s")

            #myscreen.render()
            #time.sleep(0.1)

            myscreen.removeActor(sweepsurf)
            if n != (Nmoves - 2):
                myscreen.removeActor(stocksurf)

        #myscreen.removeActor(cyl1)
        #myscreen.removeActor(cyl2)
        #myscreen.render()
        #time.sleep(0.1)

    print(" render()...", )
    myscreen.render()
    print("done.")

    #time.sleep(0.2)

    myscreen.iren.Start()
def getWeaveRAM(Nmax,weave2_flag):
    #stl = camvtk.STLSurf("../stl/demo.stl")
    stl = camvtk.STLSurf("../../stl/gnu_tux_mod.stl")
    polydata = stl.src.GetOutput()
    s = ocl.STLSurf()
    camvtk.vtkPolyData2OCLSTL(polydata, s)
    cutter = ocl.CylCutter(0.3, 5)
    fiber_range=30
    #Nmax = 400
    yvals = [float(n-float(Nmax)/2)/Nmax*float(fiber_range) for n in range(0,Nmax+1)]
    xvals = [float(n-float(Nmax)/2)/Nmax*float(fiber_range) for n in range(0,Nmax+1)]
    zvals=[ 1.6523]
    bpc_x = ocl.BatchPushCutter()
    bpc_y = ocl.BatchPushCutter()
    bpc_x.setXDirection()
    bpc_y.setYDirection()
    bpc_x.setSTL(s)
    bpc_y.setSTL(s)
    bpc_x.setCutter(cutter)
    bpc_y.setCutter(cutter)
    # create fibers
    for zh in zvals:
        for y in yvals:
            f1 = ocl.Point(-15.5,y,zh) # start point of fiber
            f2 = ocl.Point(15.5,y,zh)  # end point of fiber
            f =  ocl.Fiber( f1, f2)
            bpc_x.appendFiber(f)
        for x in xvals:
            f1 = ocl.Point(x,-15.5,zh) # start point of fiber
            f2 = ocl.Point(x,15.5,zh)  # end point of fiber
            f =  ocl.Fiber( f1, f2)
            bpc_y.appendFiber(f)
            
    # run
    bpc_x.run()
    bpc_y.run()
    xfibers = bpc_x.getFibers()
    yfibers = bpc_y.getFibers()
    fibers = xfibers+yfibers
    print(" got ",len(xfibers)," xfibers")
    print(" got ",len(yfibers)," yfibers")
    fibercount = len(xfibers) + len(yfibers)
    print("rendering fibers and CL-points.")
    w = ocl.Weave()
    print("push fibers to Weave...",)
    for f in fibers:
        w.addFiber(f)
    print("done.")
    print("Weave build()...",)
    mem1 = procmemory.memory()
    if weave2_flag==1:
        w.build2()
    else:
        w.build()
    mem2 = procmemory.memory()
    #print "after ", float(mem2)/float(1024*1024), " MB"
    megabytes = float(mem2-mem1)/float(1024*1024)
    megabytes2 = float(mem2)/float(1024*1024)
    verts = w.numVertices()
    print(" before: ", float(mem1)/float(1024*1024))
    print("  after: ", float(mem2)/float(1024*1024))
    print(" build() memory: ",megabytes," MB")
    print("done")
    print("face_traverse...")
    w.face_traverse()
    print("done.")
    w_clpts = w.getCLVertices()
    w_ipts = w.getINTVertices()
    w_edges = w.getEdges()
    w_loop = w.getLoops()


    print(" got: ", len(w_edges), " edges")
    print(" got: ", len(w_loop), " loops")
    out=[]
    out.append(fibercount)
    out.append(verts)
    return out
Exemplo n.º 13
0
def main():
    print(ocl.revision())
    myscreen = camvtk.VTKScreen()
    myscreen.camera.SetPosition(-8, -4, 25)
    myscreen.camera.SetFocalPoint(4.5, 6, 0)
    # axis arrows
    camvtk.drawArrows(myscreen, center=(-1, -1, 0))
    camvtk.drawOCLtext(myscreen)

    octtext = camvtk.Text()
    octtext.SetPos((70, myscreen.height - 600))
    myscreen.addActor(octtext)

    cltext = camvtk.Text()
    cltext.SetPos((70, myscreen.height - 100))
    myscreen.addActor(cltext)

    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")

    #angle = math.pi/4
    radius = 0.4
    length = 5
    cutter = ocl.BallCutter(2 * radius, length)
    #cutter = ocl.CylCutter(2*radius, length)

    # generate CL-points
    minx = 0
    dx = 0.1 / 0.4
    maxx = 9
    miny = 0
    dy = cutter.getRadius() / 1.5
    maxy = 12
    z = -1
    # this generates a list of CL-points in a grid
    clpoints = pyocl.CLPointGrid(minx, dx, maxx, miny, dy, maxy, z)
    # batchdropcutter
    bdc = ocl.BatchDropCutter()
    bdc.bucketSize = 7
    bdc.setSTL(s)
    bdc.setCutter(cutter)
    #bdc.setThreads(1)  # explicitly setting one thread is better for debugging
    for p in clpoints:
        bdc.appendPoint(p)

    t_before = time.time()
    bdc.run()
    t_after = time.time()
    calctime = t_after - t_before
    print(" BDC4 done in ", calctime, " s")
    dropcutter_time = calctime
    clpoints = bdc.getCLPoints()

    #camvtk.drawCLPointCloud(myscreen, clpoints)
    print(" clpts= ", len(clpoints))
    myscreen.render()
    #myscreen.iren.Start()
    #exit()

    s = ocl.BallCutterVolume()
    #s = ocl.CylCutterVolume()
    #s.center = ocl.Point(-2.50,-0.6,0)
    s.radius = cutter.getRadius()
    s.length = cutter.getLength()

    # screenshot writer
    w2if = vtk.vtkWindowToImageFilter()
    w2if.SetInput(myscreen.renWin)
    lwr = vtk.vtkPNGWriter()
    lwr.SetInput(w2if.GetOutput())

    cp = ocl.Point(5, 5, -3)  # center of octree
    #depths = [3, 4, 5, 6, 7, 8]
    max_depth = 7
    root_scale = 7
    t = ocl.Octree(root_scale, max_depth, cp)
    t.init(5)
    n = 0  # the frame number

    stockbox = ocl.PlaneVolume(1, 0, 0.1)
    t.diff_negative(stockbox)
    stockbox = ocl.PlaneVolume(0, 0, 8.9)
    t.diff_negative(stockbox)

    stockbox = ocl.PlaneVolume(1, 1, 0.1)
    t.diff_negative(stockbox)
    stockbox = ocl.PlaneVolume(0, 1, 11.9)
    t.diff_negative(stockbox)

    stockbox = ocl.PlaneVolume(1, 2, -0.5)
    t.diff_negative(stockbox)
    stockbox = ocl.PlaneVolume(0, 2, 3)
    t.diff_negative(stockbox)

    mc = ocl.MarchingCubes()

    print("mc()...", )
    tris = mc.mc_tree(t)  #.mc_triangles()
    print(" mc() got ", len(tris), " triangles")
    mc_surf = camvtk.STLSurf(triangleList=tris, color=camvtk.red)
    mc_surf.SetColor(camvtk.cyan)
    print(" STLSurf()...", )
    myscreen.addActor(mc_surf)
    print("done.")
    cl = ocl.Point(0, 0, 5)
    cactors = camvtk.drawBallCutter(myscreen, cutter, cl)
    myscreen.render()
    #myscreen.iren.Start()
    #exit()
    myscreen.removeActor(mc_surf)
    renderinterleave = len(clpoints) / 100
    step_time = 0
    #render_time = 0
    while (n < len(clpoints)):
        cl = ocl.Point(clpoints[n].x, clpoints[n].y, clpoints[n].z)
        s.setPos(cl)  # move the cutter
        t_before = time.time()
        t.diff_negative(s)  # subtract cutter from stock
        t_after = time.time()
        build_time = t_after - t_before
        step_time = step_time + build_time

        n = n + 1
        if n < (len(clpoints) - renderinterleave):
            myscreen.removeActor(mc_surf)
            for c in cactors:
                myscreen.removeActor(c)
        if ((n % renderinterleave) == 0):

            cactors = camvtk.drawBallCutter(myscreen, cutter, cl)
            t_before = time.time()
            print("mc()...", )
            tris = mc.mc_tree(t)  #.mc_triangles()
            mc_time = time.time() - t_before
            print("done in ", mc_time, " s")
            print(" mc() got ", len(tris), " triangles")
            print(" STLSurf()...", )

            t_before = time.time()
            mc_surf = camvtk.STLSurf(triangleList=tris, color=camvtk.red)
            #mc_surf.SetWireframe()
            mc_surf.SetColor(camvtk.cyan)
            myscreen.addActor(mc_surf)
            print("done.")
            print(" render()...", )
            myscreen.render()
            render_time = time.time() - t_before
            myscreen.camera.Azimuth(0.1)
            lwr.SetFileName("frames/cutsim_d10_frame" + ('%06d' % n) + ".png")
            w2if.Modified()

            call_ms = step_time / renderinterleave
            print(renderinterleave, " diff() calls in", step_time, " = ",
                  call_ms, " ms/call")
            infotext = "Octree max_depth=%i \nCL-point %i of %i \n%i CL-pts/frame\ndiff()-time:  %1.3f s/CL-point\nmc()-time:  %1.3f s/frame\nrender()-time:  %1.3f s/frame\n%i Triangles" % (
                max_depth, n, len(clpoints), renderinterleave, call_ms,
                mc_time, render_time, len(tris))
            octtext.SetText(infotext)
            postext = "X: %f\nY: %f\nZ: %f" % (cl.x, cl.y, cl.z)
            cltext.SetText(postext)

            #lwr.Write() # uncomment to actually write files to disk

            print("done.")

            step_time = 0

        #lwr.SetFileName("frames/mc8_frame"+ ('%06d' % n)+".png")
        #myscreen.camera.Azimuth( 2 )
        #myscreen.render()
        #w2if.Modified()
        #lwr.Write()

        #mc_surf.SetWireframe()
        #print "sleep...",
        #time.sleep(1.02)
        #print "done."

    print(" clpts= ", len(clpoints))
    print("All done.")
    myscreen.iren.Start()
Exemplo n.º 14
0
import ocl
import tempfile
import pyocl
import camvtk

stl = camvtk.STLSurf(tempfile.gettempdir() + "/model0.stl")
stl_polydata = stl.src.GetOutput()
stl_surf = ocl.STLSurf()
camvtk.vtkPolyData2OCLSTL(stl_polydata, stl_surf)
csv_file = open(tempfile.gettempdir() + '/ocl_settings.txt', 'r')
op_cutter_type = csv_file.readline().split()[0]
op_cutter_diameter = float(csv_file.readline())
op_minz = float(csv_file.readline())
csv_file.close()

cutter_length = 5
if op_cutter_type == 'END':
    cutter = ocl.CylCutter(op_cutter_diameter * 1000, cutter_length)
elif op_cutter_type == 'BALL':
    cutter = ocl.BallCutter(op_cutter_diameter * 1000, cutter_length)
elif op_cutter_type == 'VCARVE':
    cutter = ocl.ConeCutter(op_cutter_diameter * 1000, 1, cutter_length)
else:
    print "Cutter unsupported: " + op_cutter_type + '\n'
    quit()
#add BullCutter
bdc = ocl.BatchDropCutter()
bdc.setSTL(stl_surf)
bdc.setCutter(cutter)

csv_file = open(tempfile.gettempdir() + '/ocl_chunks.txt', 'r')
Exemplo n.º 15
0
def main():
    myscreen = camvtk.VTKScreen()
    focal = cam.Point(5, 5, 0)
    r = 30
    theta = (float(45) / 360) * 2 * math.pi
    fi = 45

    campos = cam.Point(r * math.sin(theta) * math.cos(fi),
                       r * math.sin(theta) * math.sin(fi), r * math.cos(theta))
    myscreen.camera.SetPosition(campos.x, campos.y, campos.z)
    myscreen.camera.SetFocalPoint(focal.x, focal.y, focal.z)

    t = camvtk.Text()
    t.SetPos((myscreen.width - 450, myscreen.height - 30))

    myscreen.addActor(t)
    t2 = camvtk.Text()
    ytext = "kd-tree debug"  #"Y: %3.3f" % (ycoord)
    t2.SetText(ytext)
    t2.SetPos((50, myscreen.height - 50))
    myscreen.addActor(t2)

    #w2if = vtk.vtkWindowToImageFilter()
    #w2if.SetInput(myscreen.renWin)
    #lwr = vtk.vtkPNGWriter()
    #lwr.SetInput( w2if.GetOutput() )

    t.SetText("OpenCAMLib 10.03-beta, " +
              datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))

    #ycoord = 1.1

    stl = camvtk.STLSurf(filename="../stl/demo.stl")
    #stl = camvtk.STLSurf(filename="../stl/demo2.stl")
    print "STL surface read"
    #myscreen.addActor(stl)
    #stl.SetWireframe()
    #stl.SetColor((0.5,0.5,0.5))
    polydata = stl.src.GetOutput()
    s = cam.STLSurf()
    camvtk.vtkPolyData2OCLSTL(polydata, s)
    print "STLSurf with ", s.size(), " triangles"

    myscreen.addActor(
        camvtk.Sphere(center=(0, 0, 0), radius=0.2, color=camvtk.yellow))

    s.build_kdtree()
    print "built kd-tree"
    s.jump_kd_reset()

    tlist = s.get_kd_triangles()

    print "got", len(tlist), " triangles"

    while (s.jump_kd_hi()):
        lotris = s.get_kd_triangles()
        s.jump_kd_up()
        cut = s.get_kd_cut()
        s.jump_kd_lo()
        hitris = s.get_kd_triangles()
        lev = s.get_kd_level()

        print "l=", lev, " hi=", len(hitris), " lo=", len(lotris), " cut=", cut

        if (cut[0] < 2):
            print "x cut ",
            if (cut[0] == 0):
                print "max"
                myscreen.addActor(
                    camvtk.Line(p1=(cut[1], 100, 0),
                                p2=(cut[1], -100, 0),
                                color=camvtk.green))
            else:
                print "min"
                myscreen.addActor(
                    camvtk.Line(p1=(cut[1], 100, 0),
                                p2=(cut[1], -100, 0),
                                color=camvtk.lgreen))
            #myscreen.addActor( camvtk.Line( p1=(100,cut[1],0), p2=(-100,cut[1],0), color = camvtk.red ) )
        else:
            print "y cut ",
            if (cut[0] == 2):
                print "max"
                myscreen.addActor(
                    camvtk.Line(p1=(100, cut[1], 0),
                                p2=(-100, cut[1], 0),
                                color=camvtk.red))
            else:
                print "min"
                myscreen.addActor(
                    camvtk.Line(p1=(100, cut[1], 0),
                                p2=(-100, cut[1], 0),
                                color=camvtk.pink))

        slo = camvtk.STLSurf(triangleList=lotris)
        slo.SetColor(camvtk.pink)
        slo.SetWireframe()
        shi = camvtk.STLSurf(triangleList=hitris)
        shi.SetColor(camvtk.lgreen)
        shi.SetWireframe()
        myscreen.addActor(slo)
        myscreen.addActor(shi)
        myscreen.render()
        myscreen.iren.Start()
        raw_input("Press Enter to terminate")
        time.sleep(1)
        myscreen.removeActor(slo)
        myscreen.removeActor(shi)

    print "done."
    myscreen.render()
    #lwr.SetFileName(filename)

    #raw_input("Press Enter to terminate")
    time.sleep(0.2)
    #lwr.Write()
    myscreen.iren.Start()
Exemplo n.º 16
0
def main():  
    print(ocl.revision())
    myscreen = camvtk.VTKScreen()   
    myscreen.camera.SetPosition(-8, -4, 25)
    myscreen.camera.SetFocalPoint(4.5,6, 0)   
    # axis arrows
    camvtk.drawArrows(myscreen,center=(-1,-1,0))
    camvtk.drawOCLtext(myscreen)
    
    octtext = camvtk.Text()
    octtext.SetPos( (70, myscreen.height-600) )
    myscreen.addActor( octtext)
    
    cltext = camvtk.Text()
    cltext.SetPos( (70, myscreen.height-100) )
    myscreen.addActor( cltext)
    
    
    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")
    
    #angle = math.pi/4
    radius  = 0.4
    length=10
    cutter = ocl.BallCutter(2*radius, length)
    #cutter = ocl.CylCutter(2*radius, length)
    
    # generate CL-points
    minx=0
    dx=0.1/0.2
    maxx=9
    miny=0
    dy=cutter.getRadius()/1.5
    maxy=12
    z=-1
    # this generates a list of CL-points in a grid
    clpoints = pyocl.CLPointGrid(minx,dx,maxx,miny,dy,maxy,z)
    # batchdropcutter    
    bdc = ocl.BatchDropCutter()
    bdc.bucketSize = 10
    bdc.setSTL(s)
    bdc.setCutter(cutter)
    #bdc.setThreads(1)  # explicitly setting one thread is better for debugging
    for p in clpoints:
        bdc.appendPoint(p)
    
    t_before = time.time()    
    bdc.run()
    
    t_after = time.time()
    calctime = t_after-t_before
    print(" BDC4 done in ", calctime," s")
    dropcutter_time = calctime
    clpoints = bdc.getCLPoints()
    
    #camvtk.drawCLPointCloud(myscreen, clpoints)
    print(" clpts= ", len(clpoints))
    myscreen.render()
    #myscreen.iren.Start() 
    #exit()
    
    s = ocl.BallCutterVolume()
    #s = ocl.CylCutterVolume()
    #s.center = ocl.Point(-2.50,-0.6,0)
    s.radius = cutter.getRadius()
    s.length = cutter.getLength()

    # screenshot writer
    w2if = vtk.vtkWindowToImageFilter()
    w2if.SetInput(myscreen.renWin)
    lwr = vtk.vtkPNGWriter()
    lwr.SetInput( w2if.GetOutput() )
    
    cp= ocl.Point(5,5,-6) # center of octree
    #depths = [3, 4, 5, 6, 7, 8]
    max_depth = 7
    root_scale = 10
    t = ocl.Octree(root_scale, max_depth, cp)
    t.init(5)
    n = 0 # the frame number
    
    stockbox = ocl.PlaneVolume( 1, 0, 0.1)
    t.diff_negative(stockbox)
    stockbox = ocl.PlaneVolume( 0, 0, 8.9  )
    t.diff_negative(stockbox)
    
    stockbox = ocl.PlaneVolume( 1, 1, 0.1)
    t.diff_negative(stockbox)
    stockbox = ocl.PlaneVolume( 0, 1, 11.9  )
    t.diff_negative(stockbox)
    
    stockbox = ocl.PlaneVolume( 1, 2, -0.5  )
    t.diff_negative(stockbox)
    stockbox = ocl.PlaneVolume( 0, 2, 3)
    t.diff_negative(stockbox)
    
    mc = ocl.MarchingCubes()
    
    print("stock mc()...",)
    tris = mc.mc_tree(t) # t.mc_triangles()
    print(" mc() got ", len(tris), " triangles")
    mc_surf = camvtk.STLSurf( triangleList=tris, color=camvtk.red )
    mc_surf.SetColor(camvtk.cyan)
    print("stock STLSurf()...",)
    myscreen.addActor( mc_surf )
    print("done.")
            
    myscreen.render()
    #myscreen.iren.Start() 
    #exit()
    myscreen.removeActor( mc_surf )
    renderinterleave=10
    step_time = 0
    while (n<len(clpoints)):
        cl = ocl.Point( clpoints[n].x, clpoints[n].y, clpoints[n].z )
        s.setPos( cl )
        #myscreen.addActor( camvtk.Point( center=(cl.x,cl.y,cl.z), color=camvtk.yellow))
        print(n,": diff...",)
        t_before = time.time() 
        t.diff_negative(s)
        t_after = time.time() 
        build_time = t_after-t_before
        #print "done in ", build_time," s"
        step_time=step_time+build_time
        n=n+1
        if ( (n%renderinterleave)==0):
            infotext= "Octree max_depth=%i \nCL-point %i of %i \ndiff()-time: %f ms/CL-point" % (max_depth,n, 
                                                                                                      len(clpoints), 1e3*step_time/renderinterleave )
            octtext.SetText(infotext)
            postext= "X: %f\nY: %f\nZ: %f" % (cl.x,cl.y,cl.z )
            cltext.SetText(postext)
            
            cactors = camvtk.drawBallCutter(myscreen, cutter, cl)
            print(cactors)
            t_before = time.time() 
            print("mc()...",)
            tris = mc.mc_tree(t) #.mc_triangles()
            t_after = time.time() 
            mc_time = t_after-t_before
            print("done in ", mc_time," s")
            print(" mc() got ", len(tris), " triangles")
            mc_surf = camvtk.STLSurf( triangleList=tris, color=camvtk.red )
            #mc_surf.SetWireframe()
            mc_surf.SetColor(camvtk.cyan)
            print(" STLSurf()...",)
            myscreen.addActor( mc_surf )
            print("done.")

            print(" render()...",)
            myscreen.render()
            myscreen.camera.Azimuth( 0.5 )
            lwr.SetFileName("frames/cutsim_d9_frame"+ ('%06d' % n)+".png")
            w2if.Modified() 
            lwr.Write()
            
            print("done.")
            myscreen.removeActor( mc_surf )
            for c in cactors:
                myscreen.removeActor( c )
            step_time = 0
        
        
        
        #lwr.SetFileName("frames/mc8_frame"+ ('%06d' % n)+".png")
        #myscreen.camera.Azimuth( 2 )
        #myscreen.render()
        #w2if.Modified() 
        #lwr.Write()
            
        #mc_surf.SetWireframe()
        #print "sleep...",
        #time.sleep(1.02)
        #print "done."
                
        

        # move forward
        #theta = n*dtheta
        #sp1 = ocl.Point(s.center)
        #s.center =  ocl.Point( 1.7*math.cos(theta),1.3*math.sin(theta),thetalift*theta)  
        #sp2 = ocl.Point(s.center)
        #print "line from ",sp1," to ",sp2
        #if n is not nmax:
        #    myscreen.addActor( camvtk.Line( p1=(sp1.x,sp1.y,sp1.z),p2=(sp2.x,sp2.y,sp2.z), color=camvtk.red ) )
        #print "center moved to", s.center
    
    print(" clpts= ", len(clpoints))
    print("All done.")
    myscreen.iren.Start() 
Exemplo n.º 17
0
def main():
    print ocl.revision()
    myscreen = camvtk.VTKScreen()
    myscreen.camera.SetPosition(-8, -4, 25)
    myscreen.camera.SetFocalPoint(4.5, 6, 0)
    # axis arrows
    camvtk.drawArrows(myscreen, center=(-1, -1, 0))
    camvtk.drawOCLtext(myscreen)

    octtext = camvtk.Text()
    octtext.SetPos((70, myscreen.height - 600))
    myscreen.addActor(octtext)

    cltext = camvtk.Text()
    cltext.SetPos((70, myscreen.height - 100))
    myscreen.addActor(cltext)

    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"

    #angle = math.pi/4
    radius = 0.4
    length = 10
    cutter = ocl.BallCutter(2 * radius, length)
    #cutter = ocl.CylCutter(2*radius, length)

    # generate CL-points
    minx = 0
    dx = 0.1 / 0.2
    maxx = 9
    miny = 0
    dy = cutter.getRadius() / 1.5
    maxy = 12
    z = -1
    # this generates a list of CL-points in a grid
    clpoints = pyocl.CLPointGrid(minx, dx, maxx, miny, dy, maxy, z)
    # batchdropcutter
    bdc = ocl.BatchDropCutter()
    bdc.bucketSize = 10
    bdc.setSTL(s)
    bdc.setCutter(cutter)
    #bdc.setThreads(1)  # explicitly setting one thread is better for debugging
    for p in clpoints:
        bdc.appendPoint(p)

    t_before = time.time()
    bdc.run()

    t_after = time.time()
    calctime = t_after - t_before
    print " BDC4 done in ", calctime, " s"
    dropcutter_time = calctime
    clpoints = bdc.getCLPoints()

    #camvtk.drawCLPointCloud(myscreen, clpoints)
    print " clpts= ", len(clpoints)
    myscreen.render()
    #myscreen.iren.Start()
    #exit()

    s = ocl.BallCutterVolume()
    #s = ocl.CylCutterVolume()
    #s.center = ocl.Point(-2.50,-0.6,0)
    s.radius = cutter.getRadius()
    s.length = cutter.getLength()

    # screenshot writer
    w2if = vtk.vtkWindowToImageFilter()
    w2if.SetInput(myscreen.renWin)
    lwr = vtk.vtkPNGWriter()
    lwr.SetInput(w2if.GetOutput())

    cp = ocl.Point(5, 5, -6)  # center of octree
    #depths = [3, 4, 5, 6, 7, 8]
    max_depth = 7
    root_scale = 10
    t = ocl.Octree(root_scale, max_depth, cp)
    t.init(5)
    n = 0  # the frame number

    stockbox = ocl.PlaneVolume(1, 0, 0.1)
    t.diff_negative(stockbox)
    stockbox = ocl.PlaneVolume(0, 0, 8.9)
    t.diff_negative(stockbox)

    stockbox = ocl.PlaneVolume(1, 1, 0.1)
    t.diff_negative(stockbox)
    stockbox = ocl.PlaneVolume(0, 1, 11.9)
    t.diff_negative(stockbox)

    stockbox = ocl.PlaneVolume(1, 2, -0.5)
    t.diff_negative(stockbox)
    stockbox = ocl.PlaneVolume(0, 2, 3)
    t.diff_negative(stockbox)

    mc = ocl.MarchingCubes()

    print "stock mc()...",
    tris = mc.mc_tree(t)  # t.mc_triangles()
    print " mc() got ", len(tris), " triangles"
    mc_surf = camvtk.STLSurf(triangleList=tris, color=camvtk.red)
    mc_surf.SetColor(camvtk.cyan)
    print "stock STLSurf()...",
    myscreen.addActor(mc_surf)
    print "done."

    myscreen.render()
    #myscreen.iren.Start()
    #exit()
    myscreen.removeActor(mc_surf)
    renderinterleave = 10
    step_time = 0
    while (n < len(clpoints)):
        cl = ocl.Point(clpoints[n].x, clpoints[n].y, clpoints[n].z)
        s.setPos(cl)
        #myscreen.addActor( camvtk.Point( center=(cl.x,cl.y,cl.z), color=camvtk.yellow))
        print n, ": diff...",
        t_before = time.time()
        t.diff_negative(s)
        t_after = time.time()
        build_time = t_after - t_before
        #print "done in ", build_time," s"
        step_time = step_time + build_time
        n = n + 1
        if ((n % renderinterleave) == 0):
            infotext = "Octree max_depth=%i \nCL-point %i of %i \ndiff()-time: %f ms/CL-point" % (
                max_depth, n, len(clpoints),
                1e3 * step_time / renderinterleave)
            octtext.SetText(infotext)
            postext = "X: %f\nY: %f\nZ: %f" % (cl.x, cl.y, cl.z)
            cltext.SetText(postext)

            cactors = camvtk.drawBallCutter(myscreen, cutter, cl)
            print cactors
            t_before = time.time()
            print "mc()...",
            tris = mc.mc_tree(t)  #.mc_triangles()
            t_after = time.time()
            mc_time = t_after - t_before
            print "done in ", mc_time, " s"
            print " mc() got ", len(tris), " triangles"
            mc_surf = camvtk.STLSurf(triangleList=tris, color=camvtk.red)
            #mc_surf.SetWireframe()
            mc_surf.SetColor(camvtk.cyan)
            print " STLSurf()...",
            myscreen.addActor(mc_surf)
            print "done."

            print " render()...",
            myscreen.render()
            myscreen.camera.Azimuth(0.5)
            lwr.SetFileName("frames/cutsim_d9_frame" + ('%06d' % n) + ".png")
            w2if.Modified()
            lwr.Write()

            print "done."
            myscreen.removeActor(mc_surf)
            for c in cactors:
                myscreen.removeActor(c)
            step_time = 0

        #lwr.SetFileName("frames/mc8_frame"+ ('%06d' % n)+".png")
        #myscreen.camera.Azimuth( 2 )
        #myscreen.render()
        #w2if.Modified()
        #lwr.Write()

        #mc_surf.SetWireframe()
        #print "sleep...",
        #time.sleep(1.02)
        #print "done."

        # move forward
        #theta = n*dtheta
        #sp1 = ocl.Point(s.center)
        #s.center =  ocl.Point( 1.7*math.cos(theta),1.3*math.sin(theta),thetalift*theta)
        #sp2 = ocl.Point(s.center)
        #print "line from ",sp1," to ",sp2
        #if n is not nmax:
        #    myscreen.addActor( camvtk.Line( p1=(sp1.x,sp1.y,sp1.z),p2=(sp2.x,sp2.y,sp2.z), color=camvtk.red ) )
        #print "center moved to", s.center

    print " clpts= ", len(clpoints)
    print "All done."
    myscreen.iren.Start()
Exemplo n.º 18
0
def main():
    myscreen = camvtk.VTKScreen()
    focal = cam.Point(50, 0, 0)
    r = 300
    theta = (float(45)/360)*2*math.pi
    fi=45
    
    campos = cam.Point( r*math.sin(theta)*math.cos(fi), r*math.sin(theta)*math.sin(fi), r*math.cos(theta) ) 
    myscreen.camera.SetPosition(campos.x, campos.y, campos.z)
    myscreen.camera.SetFocalPoint(focal.x,focal.y, focal.z)
    
    t = camvtk.Text()
    t.SetPos( (myscreen.width-450, myscreen.height-30) )

    
    myscreen.addActor( t)
    t2 = camvtk.Text()
    ytext = "kd-tree debug" #"Y: %3.3f" % (ycoord)
    t2.SetText(ytext)
    t2.SetPos( (50, myscreen.height-50) )   
    myscreen.addActor( t2)
        
    w2if = vtk.vtkWindowToImageFilter()
    w2if.SetInput(myscreen.renWin)
    lwr = vtk.vtkPNGWriter()
    lwr.SetInput( w2if.GetOutput() )
  
    epos = cam.Epos()
    epos.setS(0,1)

    t.SetText("OpenCAMLib 10.04-beta, " + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
    
    
    #ycoord = 1.1
    
    stl = camvtk.STLSurf(filename="../stl/carpet2.stl")
    #stl = camvtk.STLSurf(filename="demo2.stl")
    print "STL surface read"
    myscreen.addActor(stl)
    stl.SetWireframe()
    stl.SetColor((0.5,0.5,0.5))
    polydata = stl.src.GetOutput()
    s= cam.STLSurf()
    camvtk.vtkPolyData2OCLSTL(polydata, s)
    print "STLSurf with ", s.size(), " triangles"
    
    cutterDiameter=7
    cutter = cam.CylCutter(cutterDiameter)
    
    cl = cam.Point(31, 42, 3)
    
    cutactor = camvtk.Cylinder(center=(cl.x,cl.y,cl.z), 
                                   radius=cutterDiameter/2, 
                                   height=2, 
                                   rotXYZ=(90,0,0),
                                   color=camvtk.green)
    myscreen.addActor( cutactor )
    
    # sphere to see (0,0)
    myscreen.addActor( camvtk.Sphere( center=(0,0,0), radius=0.2, color = camvtk.yellow ) )
  
    s.build_kdtree()
    print "built kd-tree"
    s.jump_kd_reset()
    

    cpp_tlist = s.getTrianglesUnderCutter(cl, cutter)
    
    py_tlist = []
    depth = 6
    kdtreesearch(myscreen, py_tlist, s, cutter, cl, depth)
    
    print "len(cpp_list) after search=", len(cpp_tlist)
    print "len(py_list) after search=", len(py_tlist)
    
    cpp = camvtk.STLSurf(triangleList=cpp_tlist)
    cpp.SetColor(camvtk.lgreen)
    cpp.SetWireframe()
    myscreen.addActor(cpp)
    
    py = camvtk.STLSurf(triangleList=py_tlist)
    py.SetColor(camvtk.pink)
    py.SetWireframe()
    myscreen.addActor(py)
    
    
    
    #drawcuts(myscreen, s)
    
    myscreen.render()
    myscreen.iren.Start()
    time.sleep(2)
    exit()
    
    tlist = s.get_kd_triangles()
    
    print "got", len(tlist), " triangles"
    
    while (s.jump_kd_hi()):
        lotris = s.get_kd_triangles()
        s.jump_kd_up()
        cut = s.get_kd_cut()
        s.jump_kd_lo()
        hitris = s.get_kd_triangles()
        lev = s.get_kd_level()
        
        print "l=", lev, " hi=", len(hitris), " lo=", len(lotris), " cut=", cut
        
        if ( cut[0] < 2 ):
            print "x cut ",
            if ( cut[0] == 0):
                print "max" 
                myscreen.addActor( camvtk.Line( p1=(cut[1],100,0), p2=(cut[1],-100,0), color = camvtk.green ) )
            else:
                print "min" 
                myscreen.addActor( camvtk.Line( p1=(cut[1],100,0), p2=(cut[1],-100,0), color = camvtk.lgreen ) )
        else:
            print "y cut ",
            if ( cut[0] == 2):
                print "max" 
                myscreen.addActor( camvtk.Line( p1=(100,cut[1],0), p2=(-100,cut[1],0), color = camvtk.red ) )
            else:
                print "min"
                myscreen.addActor( camvtk.Line( p1=(100,cut[1],0), p2=(-100,cut[1],0), color = camvtk.pink ) )
            
        
        slo = camvtk.STLSurf(triangleList=lotris)
        slo.SetColor(camvtk.pink)
        slo.SetWireframe()
        shi = camvtk.STLSurf(triangleList=hitris)
        shi.SetColor(camvtk.lgreen)
        shi.SetWireframe()
        myscreen.addActor(slo)
        myscreen.addActor(shi)
        myscreen.render()
        #myscreen.iren.Start()
        #raw_input("Press Enter to terminate")   
        time.sleep(1)
        myscreen.removeActor(slo)
        myscreen.removeActor(shi)
    

  
    print "done."
    myscreen.render()
    #lwr.SetFileName(filename)
    
    #raw_input("Press Enter to terminate")         
    time.sleep(0.2)
    lwr.Write()
    myscreen.iren.Start()
Exemplo n.º 19
0
def main():  
    print ocl.revision()
    myscreen = camvtk.VTKScreen()   
    myscreen.camera.SetPosition(-8, -4, 25)
    myscreen.camera.SetFocalPoint(4.5,6, 0)   
    # axis arrows
    camvtk.drawArrows(myscreen,center=(-1,-1,0))
    camvtk.drawOCLtext(myscreen)
    
    octtext = camvtk.Text()
    octtext.SetPos( (70, myscreen.height-600) )
    myscreen.addActor( octtext)
    
    cltext = camvtk.Text()
    cltext.SetPos( (70, myscreen.height-100) )
    myscreen.addActor( cltext)
    
    
    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"
    
    #angle = math.pi/4
    radius  = 0.4
    length=5
    cutter = ocl.BallCutter(2*radius, length)
    #cutter = ocl.CylCutter(2*radius, length)
    
    
    
    # generate CL-points
    minx=0
    dx=0.1/0.4
    maxx=9
    miny=0
    dy=cutter.getRadius()/1.5
    maxy=12
    z=-1
    # this generates a list of CL-points in a grid
    clpoints = pyocl.CLPointGrid(minx,dx,maxx,miny,dy,maxy,z)
    # batchdropcutter    
    bdc = ocl.BatchDropCutter()
    bdc.bucketSize = 7
    bdc.setSTL(s)
    bdc.setCutter(cutter)
    #bdc.setThreads(1)  # explicitly setting one thread is better for debugging
    for p in clpoints:
        bdc.appendPoint(p)
    
    t_before = time.time()    
    bdc.run()
    t_after = time.time()
    calctime = t_after-t_before
    print " BDC4 done in ", calctime," s"
    dropcutter_time = calctime
    clpoints = bdc.getCLPoints()
    
    #camvtk.drawCLPointCloud(myscreen, clpoints)
    print " clpts= ", len(clpoints)
    myscreen.render()
    #myscreen.iren.Start() 
    #exit()
    
    s = ocl.BallCutterVolume()
    #s = ocl.CylCutterVolume()
    #s.center = ocl.Point(-2.50,-0.6,0)
    s.radius = cutter.getRadius()
    s.length = cutter.getLength()

    # screenshot writer
    w2if = vtk.vtkWindowToImageFilter()
    w2if.SetInput(myscreen.renWin)
    lwr = vtk.vtkPNGWriter()
    lwr.SetInput( w2if.GetOutput() )
    
    cp= ocl.Point(5,5,-3) # center of octree
    #depths = [3, 4, 5, 6, 7, 8]
    max_depth = 7
    root_scale = 7
    t = ocl.Octree(root_scale, max_depth, cp)
    t.init(5)
    n = 0 # the frame number
    
    stockbox = ocl.PlaneVolume( 1, 0, 0.1)
    t.diff_negative(stockbox)
    stockbox = ocl.PlaneVolume( 0, 0, 8.9  )
    t.diff_negative(stockbox)
    
    stockbox = ocl.PlaneVolume( 1, 1, 0.1)
    t.diff_negative(stockbox)
    stockbox = ocl.PlaneVolume( 0, 1, 11.9  )
    t.diff_negative(stockbox)
    
    stockbox = ocl.PlaneVolume( 1, 2, -0.5  )
    t.diff_negative(stockbox)
    stockbox = ocl.PlaneVolume( 0, 2, 3)
    t.diff_negative(stockbox)
    
    mc = ocl.MarchingCubes()
    
    print "mc()...",
    tris = mc.mc_tree(t) #.mc_triangles()
    print " mc() got ", len(tris), " triangles"
    mc_surf = camvtk.STLSurf( triangleList=tris, color=camvtk.red )
    mc_surf.SetColor(camvtk.cyan)
    print " STLSurf()...",
    myscreen.addActor( mc_surf )
    print "done."
    cl = ocl.Point(0,0,5)
    cactors = camvtk.drawBallCutter(myscreen, cutter, cl)
    myscreen.render()
    #myscreen.iren.Start() 
    #exit()
    myscreen.removeActor( mc_surf )
    renderinterleave=len(clpoints)/100
    step_time = 0
    #render_time = 0
    while (n<len(clpoints)):
        cl = ocl.Point( clpoints[n].x, clpoints[n].y, clpoints[n].z )
        s.setPos( cl ) # move the cutter
        t_before = time.time() 
        t.diff_negative(s) # subtract cutter from stock
        t_after = time.time() 
        build_time = t_after-t_before
        step_time=step_time+build_time
        
        n=n+1
        if n<(len(clpoints)-renderinterleave):
            myscreen.removeActor( mc_surf )
            for c in cactors:
                myscreen.removeActor( c )
        if ( (n%renderinterleave)==0):

            
            cactors = camvtk.drawBallCutter(myscreen, cutter, cl)
            t_before = time.time() 
            print "mc()...",
            tris = mc.mc_tree(t) #.mc_triangles()
            mc_time = time.time()-t_before
            print "done in ", mc_time," s"
            print " mc() got ", len(tris), " triangles"
            print " STLSurf()...",
            
            
            t_before = time.time() 
            mc_surf = camvtk.STLSurf( triangleList=tris, color=camvtk.red )
            #mc_surf.SetWireframe()
            mc_surf.SetColor(camvtk.cyan)
            myscreen.addActor( mc_surf )
            print "done."
            print " render()...",
            myscreen.render()
            render_time = time.time()-t_before
            myscreen.camera.Azimuth( 0.1 )
            lwr.SetFileName("frames/cutsim_d10_frame"+ ('%06d' % n)+".png")
            w2if.Modified() 
            
            call_ms = step_time/renderinterleave
            print renderinterleave," diff() calls in", step_time, " = ", call_ms," ms/call"
            infotext= "Octree max_depth=%i \nCL-point %i of %i \n%i CL-pts/frame\ndiff()-time:  %1.3f s/CL-point\nmc()-time:  %1.3f s/frame\nrender()-time:  %1.3f s/frame\n%i Triangles" % (max_depth,n, 
                                                                                                      len(clpoints), renderinterleave, call_ms, mc_time, render_time, len(tris))
            octtext.SetText(infotext)
            postext= "X: %f\nY: %f\nZ: %f" % (cl.x,cl.y,cl.z )
            cltext.SetText(postext)
            
            #lwr.Write() # uncomment to actually write files to disk
            
            print "done."

            step_time = 0
        
        #lwr.SetFileName("frames/mc8_frame"+ ('%06d' % n)+".png")
        #myscreen.camera.Azimuth( 2 )
        #myscreen.render()
        #w2if.Modified() 
        #lwr.Write()
            
        #mc_surf.SetWireframe()
        #print "sleep...",
        #time.sleep(1.02)
        #print "done."

    
    print " clpts= ", len(clpoints)
    print "All done."
    myscreen.iren.Start()