Пример #1
0
def vtk_visualize_parallel_finish_zig(stlfile, toolpaths):
	myscreen = camvtk.VTKScreen()
	stl = camvtk.STLSurf(stlfile)
	myscreen.addActor(stl)
	stl.SetSurface() # try also SetWireframe()
	stl.SetColor(camvtk.cyan)
	myscreen.camera.SetPosition(15, 13, 7)
	myscreen.camera.SetFocalPoint(5, 5, 0)
	
	rapid_height= 5 # XY rapids at this height
	feed_height = 3 
	rapidColor = camvtk.pink
	XYrapidColor = camvtk.green
	plungeColor = camvtk.red
	feedColor = camvtk.yellow
	# zig path algorithm:
	# 1) lift to clearance height
	# 2) XY rapid to start of path
	# 3) plunge to correct z-depth
	# 4) feed along path until end
	pos = ocl.Point(0,0,0) # keep track of the current position of the tool
	first = True 
	for path in toolpaths:
		first_pt = path[0]
		if (first == True): # green sphere at path start
			myscreen.addActor( camvtk.Sphere(center=(first_pt.x,first_pt.y,rapid_height) , radius=0.1, color=camvtk.green) ) 
			pos = ocl.Point(first_pt.x,first_pt.y,first_pt.z) # at start of program, assume we have already a rapid move here
			first = False
		else: # not the very first move
			# retract up to rapid_height
			myscreen.addActor( camvtk.Line(p1=( pos.x,pos.y,pos.z),p2=(pos.x,pos.y,feed_height),color=plungeColor) )
			myscreen.addActor( camvtk.Line(p1=( pos.x,pos.y,feed_height),p2=(pos.x,pos.y,rapid_height),color=rapidColor) )
			# XY rapid into position
			myscreen.addActor( camvtk.Line(p1=( pos.x,pos.y,rapid_height),p2=( first_pt.x,first_pt.y,rapid_height),color=XYrapidColor) )
			pos = ocl.Point(first_pt.x,first_pt.y,first_pt.z)
		
		# rapid down to the feed_height
		myscreen.addActor( camvtk.Line(p1=( pos.x,pos.y,rapid_height),p2=(pos.x,pos.y,feed_height),color=rapidColor) )
		# feed down to CL
		myscreen.addActor( camvtk.Line(p1=( pos.x,pos.y,feed_height),p2=(pos.x,pos.y,pos.z),color=plungeColor) )
		
		# feed along the path
		for p in path[1:]:
			myscreen.addActor( camvtk.Line(p1=( pos.x,pos.y,pos.z),p2=(p.x,p.y,p.z),color=feedColor) )
			pos = ocl.Point(p.x,p.y,p.z)
		
	# END retract up to rapid_height
	myscreen.addActor( camvtk.Line(p1=( pos.x,pos.y,pos.z),p2=(pos.x,pos.y,feed_height),color=plungeColor) )
	myscreen.addActor( camvtk.Line(p1=( pos.x,pos.y,feed_height),p2=(pos.x,pos.y,rapid_height),color=rapidColor) )
	myscreen.addActor( camvtk.Sphere(center=(pos.x,pos.y,rapid_height) , radius=0.1, color=camvtk.red) ) 

	camvtk.drawArrows(myscreen,center=(-0.5,-0.5,-0.5)) # XYZ coordinate arrows
	camvtk.drawOCLtext(myscreen)
	myscreen.render()    
	myscreen.iren.Start()
Пример #2
0
def vtk_visualize_waterlines(stlfile, waterlines):
    myscreen = camvtk.VTKScreen()
    stl = camvtk.STLSurf(stlfile)
    myscreen.addActor(stl)
    stl.SetSurface()  # try also SetWireframe()
    stl.SetColor(camvtk.cyan)
    myscreen.camera.SetPosition(15, 13, 7)
    myscreen.camera.SetFocalPoint(5, 5, 0)
    print "Rendering waterlines at ", len(waterlines), " different z-heights"
    n = 0
    for loops in waterlines:  # at each z-height, we may get many loops
        print "  %d/%d:" % (n, len(waterlines))
        drawLoops(myscreen, loops, camvtk.yellow)
        n = n + 1
    camvtk.drawArrows(myscreen, center=(-0.5, -0.5, -0.5))  # XYZ coordinate arrows
    camvtk.drawOCLtext(myscreen)
    myscreen.render()
    myscreen.iren.Start()
Пример #3
0
def vtk_visualize_waterlines(stlfile, waterlines):
    myscreen = camvtk.VTKScreen()
    stl = camvtk.STLSurf(stlfile)
    myscreen.addActor(stl)
    stl.SetSurface()  # try also SetWireframe()
    stl.SetColor(camvtk.cyan)
    myscreen.camera.SetPosition(15, 13, 7)
    myscreen.camera.SetFocalPoint(5, 5, 0)
    print "Rendering waterlines at ", len(waterlines), " different z-heights"
    n = 0
    for loops in waterlines:  # at each z-height, we may get many loops
        print "  %d/%d:" % (n, len(waterlines))
        drawLoops(myscreen, loops, camvtk.yellow)
        n = n + 1
    camvtk.drawArrows(myscreen,
                      center=(-0.5, -0.5, -0.5))  # XYZ coordinate arrows
    camvtk.drawOCLtext(myscreen)
    myscreen.render()
    myscreen.iren.Start()
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=(0, 0, 0))

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

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

    cp = ocl.Point(0, 0, 0)
    max_depth = 9
    root_scale = 3
    t = ocl.Octree(root_scale, max_depth, cp)
    print(t)

    nodes = t.get_leaf_nodes()
    t.init(1)
    #nodes=[]
    s = ocl.SphereOCTVolume()
    s.center = ocl.Point(0, 0, 0)
    s.radius = 2.6345
    print("build...", )
    t.build(s)
    print("done.")
    print(t)

    sphere = camvtk.Sphere(center=(s.center.x, s.center.y, s.center.z),
                           radius=s.radius,
                           color=camvtk.cyan)
    sphere.SetOpacity(0.1)
    myscreen.addActor(sphere)

    nodes = t.get_surface_nodes()
    print("got ", len(nodes), " surface nodes")

    points = []
    for n in nodes:
        #n=nodes[0]
        verts = n.vertices()
        #c = n.center
        #print " node at depth=", n.depth," center=",c
        #myscreen.addActor( camvtk.Sphere( center=(c.x,c.y,c.z), radius=0.1, color=camvtk.yellow ))
        for v in verts:
            #print v
            #myscreen.addActor( camvtk.Sphere( center=(v.x,v.y,v.z), radius=0.1 ))
            #
            points.append(v)

    #myscreen.addActor( camvtk.PointCloud( pointlist= points))

    tris = t.mc_triangles()
    mc_surf = camvtk.STLSurf(triangleList=tris, color=camvtk.red)
    #mc_surf.SetWireframe()
    myscreen.addActor(mc_surf)
    print(" render()...", )
    myscreen.render()
    print("done.")

    #time.sleep(0.2)

    myscreen.iren.Start()
Пример #5
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() 
def drawScreen(a,b,c,filename,write_flag):  
    print(ocl.version())
    myscreen = camvtk.VTKScreen()
    #a = ocl.Point(0,1,0.3)
    myscreen.addActor(camvtk.Point(center=(a.x,a.y,a.z), color=(1,0,1)))
    #b = ocl.Point(1,0.5,0.3)    
    myscreen.addActor(camvtk.Point(center=(b.x,b.y,b.z), color=(1,0,1)))
    #c = ocl.Point(-0.1,0.3,0.0)
    myscreen.addActor(camvtk.Point(center=(c.x,c.y,c.z), color=(1,0,1)))
    myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(c.x,c.y,c.z)) )
    myscreen.addActor( camvtk.Line(p1=(c.x,c.y,c.z),p2=(b.x,b.y,b.z)) )
    myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(b.x,b.y,b.z)) )
    t = ocl.Triangle(b,c,a)
    s = ocl.STLSurf()
    s.addTriangle(t) # a one-triangle STLSurf
    zheights=[-0.3, -0.2, -0.1, -0.05, 0.0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.26, 0.27, 0.28, 0.29 ]  # the z-coordinates for the waterlines
    zheights=[-0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, -0.05, 0.0, 0.05, 0.1, 0.15, 0.2,  0.28 ]
    zheights=[ -0.35, -0.3, -0.25, -0.2, -0.15, -0.1, -0.05, 0.0, 0.05, 0.1, 0.15, 0.2,  0.25, 0.28]
    
    zheights=[]
    Nmax=20
    zmin=-0.5
    zmax= -0.05
    dz = (zmax-zmin)/float(Nmax-1)
    z = zmin
    for n in range(Nmax):
        zheights.append(z)
        z=z+dz
        
    zheights=[]
    zheights.append(-0.25)
    #zheights=[ -0.35,  -0.25,  -0.15,  -0.05, 0.05,  0.15,   0.25]
    #zheights=[ 0.1]
    
    length = 10
    diam = 0.6
    cutter1 = ocl.CylCutter( diam , length )
    cutter2 = ocl.BallCutter( diam , length )
    cutter3 = ocl.BullCutter( diam , diam/5, length )
    cutter4 = ocl.ConeCutter( diam , math.pi/5, length )
    
    for zh in zheights:
        #loops = calcWaterline(zh, cutter1, s)
        #drawLoops(myscreen, loops[0], camvtk.yellow)
        
        #loops = calcWaterline(zh, cutter2, s)
        #drawLoops(myscreen, loops[0], camvtk.green)
        #loops = calcWaterline(zh, cutter3, s)
        #drawLoops(myscreen, loops[0], camvtk.yellow)
        
        loops = calcWaterline(zh, cutter4, s)
        drawLoops(myscreen, loops[0], camvtk.pink)
        
        #for f in loops[1]:
        #    drawFiber(myscreen, f, camvtk.red)
        #for f in loops[2]:
        #    drawFiber(myscreen, f, camvtk.lblue)
        
        
        

    print("done.")
    myscreen.camera.SetPosition(1, -1, 3)
    myscreen.camera.SetFocalPoint(0.5, 0.5, 0)
    camvtk.drawArrows(myscreen,center=(-0.5,-0.5,-0.5))
    camvtk.drawOCLtext(myscreen)
    myscreen.render()    
    
    """
    w2if = vtk.vtkWindowToImageFilter()
    w2if.SetInput(myscreen.renWin)
    lwr = vtk.vtkPNGWriter()
    lwr.SetInput( w2if.GetOutput() )
    w2if.Modified()
    lwr.SetFileName(filename)
    if write_flag:
        lwr.Write()
        print("wrote ",filename)
    """
    
    time.sleep(1)
Пример #7
0
def drawScreen(a,b,c,filename,write_flag):  
    print ocl.revision()
    myscreen = camvtk.VTKScreen()
    z_hi = a.z
    if b.z > z_hi:
        z_hi = b.z
    if c.z > z_hi:
        z_hi = c.z

    z_lo = a.z
    if b.z < z_lo:
        z_lo = b.z
    if c.z < z_lo:
        z_lo = c.z
    #z_hi = 0.3 # this is the shallow case
    #ztri = 0.8 # this produces the steep case where we hit the circular rim
    
    #z_lo = 0.1
    #a = ocl.Point(0,1,ztri)
    #b = ocl.Point(1,0.5,ztri)    
    #c = ocl.Point(0.2,0.2,ztri_lo)
    
    myscreen.addActor(camvtk.Point(center=(a.x,a.y,a.z), color=(1,0,1)))
    myscreen.addActor(camvtk.Point(center=(b.x,b.y,b.z), color=(1,0,1)))
    myscreen.addActor(camvtk.Point(center=(c.x,c.y,c.z), color=(1,0,1)))
    myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(c.x,c.y,c.z)) )
    myscreen.addActor( camvtk.Line(p1=(c.x,c.y,c.z),p2=(b.x,b.y,b.z)) )
    myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(b.x,b.y,b.z)) )
    t = ocl.Triangle(b,c,a)
    angle = math.pi/5
    diameter=0.3
    length=5
    #cutter = ocl.BallCutter(diameter, length)
    #cutter = ocl.CylCutter(diameter, length)
    #cutter = ocl.BullCutter(diameter, diameter/4, length)
    cutter = ocl.ConeCutter(diameter, angle, length)
    #cutter = cutter.offsetCutter( 0.1 )
    
    print "cutter= ", cutter
    print "length=", cutter.getLength()
    print "fiber..."
    range=2
    Nmax = 100
    yvals = [float(n-float(Nmax)/2)/Nmax*range for n in xrange(0,Nmax+1)]
    xvals = [float(n-float(Nmax)/2)/Nmax*range for n in xrange(0,Nmax+1)]
    zmin = z_lo - 0.3
    zmax = z_hi
    zNmax = 20
    dz = (zmax-zmin)/(zNmax-1)
    zvals=[]
    for n in xrange(0,zNmax):
        zvals.append(zmin+n*dz)
    for zh in zvals:
        yfiber(cutter,yvals,t,zh,myscreen)
        xfiber(cutter,xvals,t,zh,myscreen)
    print "done."
    myscreen.camera.SetPosition(-2, -1, 3)
    myscreen.camera.SetFocalPoint(1.0, 0.0, -0.5)
    camvtk.drawArrows(myscreen,center=(-0.5,-0.5,-0.5))
    camvtk.drawOCLtext(myscreen)
    myscreen.render()    
    w2if = vtk.vtkWindowToImageFilter()
    w2if.SetInput(myscreen.renWin)
    lwr = vtk.vtkPNGWriter()
    lwr.SetInput( w2if.GetOutput() )
    w2if.Modified()
    lwr.SetFileName(filename)
    if write_flag:
        lwr.Write()
        print "wrote ",filename
Пример #8
0
    #    print p.x," ",p.y," ",p.z
    #exit()

    loops = []
    for z in zh:

        z_loops = getWaterline(s, cutter, z, sampling)
        for l in z_loops:
            loops.append(l)

    #for l in line:

    #drawLoops(myscreen, line, camvtk.cyan)
    #for l in cutter_loops:
    #    loops.append(l)

    print "All waterlines done. Got", len(loops), " loops in total."
    # draw the loops
    drawLoops(myscreen, loops, camvtk.yellow)
    drawLoops(myscreen, ptsy_all, camvtk.red)
    drawLoops(myscreen, ptsx_all, camvtk.green)

    print "done."
    myscreen.camera.SetPosition(15, 13, 7)
    myscreen.camera.SetFocalPoint(5, 5, 0)
    camvtk.drawArrows(myscreen, center=(0, 0, 3))
    camvtk.drawOCLtext(myscreen)
    myscreen.render()
    myscreen.iren.Start()
    #raw_input("Press Enter to terminate")
Пример #9
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()
Пример #10
0
def main():  
    print ocl.revision()
    myscreen = camvtk.VTKScreen()   
    myscreen.camera.SetPosition(-8, -4, 25)
    myscreen.camera.SetFocalPoint(0,0, 0)   
    arpos=-1.5
    camvtk.drawArrows(myscreen,center=(arpos,arpos,arpos))
    camvtk.drawOCLtext(myscreen)
    octtext = camvtk.Text()
    octtext.SetPos( (70, myscreen.height-600) )
    myscreen.addActor( octtext)
    octtext.SetText("Octree")
    vertex = [       ocl.Point( 1, 1,-1),   #// 0
                     ocl.Point(-1, 1,-1),   #// 1
                     ocl.Point(-1,-1,-1),   #// 2
                     ocl.Point( 1,-1,-1),   #// 3
                     ocl.Point( 1, 1, 1),   #// 4
                     ocl.Point(-1, 1, 1),   #// 5
                     ocl.Point(-1,-1, 1),   #// 6
                     ocl.Point( 1,-1, 1)    #// 7
                    ]
    
    n=0
    for v in vertex:
        myscreen.addActor( camvtk.Sphere(center=(v.x,v.y,v.z), radius=0.1,color=camvtk.red))
        v=v
        t = camvtk.Text3D(color=camvtk.red, center=(v.x+0.1,v.y+0.1,v.z), text=str(n), scale=0.2, camera=myscreen.camera)
        myscreen.addActor(t)
        n=n+1
    
    edgeTable = [ [0,1] ,
                  [1,2] ,
                  [2,3] ,
                  [3,0] ,
                  [4,5] ,
                  [5,6] ,
                  [6,7] ,
                  [7,4] ,
                  [0,4] ,
                  [1,5] ,
                  [2,6] ,
                  [3,7] ,  
                ]
    
    # draw the edges as tubes
    ne = 0
    for e in edgeTable:

        ep1 = vertex[ e[0] ] 
        ep2 = vertex[ e[1] ]
        tu = camvtk.Tube( p1=(ep1.x,ep1.y,ep1.z), p2=(ep2.x,ep2.y,ep2.z), radius=0.051, color=camvtk.green )
        myscreen.addActor(tu)
        mid = 0.5*(ep1 + ep2)
        t = camvtk.Text3D(color=camvtk.green, center=(mid.x+0.1,mid.y+0.1,mid.z), text=str(ne), scale=0.2, camera=myscreen.camera)
        myscreen.addActor(t)
        ne=ne+1
        
    # number the faces
    face = [ [2,3,6,7] , 
             [0,3,4,7] , 
             [0,1,4,5] ,
             [1,2,5,6] ,
             [0,1,2,3] ,
             [4,5,6,7] ,
            ]
    nf=0
    for f in face:
        mid = ocl.Point()
        for v in f:
            mid = mid+vertex[v]
        mid=0.25*mid
        t = camvtk.Text3D(color=camvtk.blue, center=(mid.x,mid.y,mid.z), text=str(nf), scale=0.2, camera=myscreen.camera)
        myscreen.addActor(t)
        nf=nf+1
    myscreen.render() 
    print "All done."
    myscreen.iren.Start() 
Пример #11
0
    minSampling=0.1
    
    aloops = []
    for zh in zheights:
        awl = ocl.AdaptiveWaterline()
        awl.setSTL(s)
        awl.setCutter(cutter)
        awl.setZ(zh)
        awl.setSampling(sampling)
        awl.setMinSampling(minSampling)
        #wl.setThreads(5)
        t_before = time.time() 
        awl.run()
        t_after = time.time()
        calctime = t_after-t_before
        print(" AdaptiveWaterline done in ", calctime," s")
        acutter_loops = awl.getLoops()
        for l in acutter_loops:
            aloops.append(l)
    
    drawLoops(myscreen, aloops, camvtk.red)
    
    print("done.")
    myscreen.camera.SetPosition(185, 153, 167)
    myscreen.camera.SetFocalPoint(5, 5, 0)
    camvtk.drawArrows(myscreen,center=(0,-4,0))
    camvtk.drawOCLtext(myscreen)
    myscreen.render()    
    myscreen.iren.Start()
    #raw_input("Press Enter to terminate") 
Пример #12
0
def main():  
    print(ocl.revision())
    myscreen = camvtk.VTKScreen()   
    myscreen.camera.SetPosition(2, 2, 5)
    myscreen.camera.SetFocalPoint(0.5,0, 1)   
    # axis arrows
    camvtk.drawArrows(myscreen,center=(-2,-2,0))
    camvtk.drawOCLtext(myscreen)
    
    
    s = ocl.BallCutterVolume()
    #s = ocl.CylCutterVolume()
    #s = ocl.BullCutterVolume()
    #s.center = ocl.Point(-2.50,-0.6,0)
    s.r1=0.3
    s.r2=0.1
    s.radius = 0.4
    s.length = 2
    startpoint = ocl.Point(0.46,1.0,0.4)
    s.setPos( startpoint )

    # screenshot writer
    w2if = vtk.vtkWindowToImageFilter()
    w2if.SetInput(myscreen.renWin)
    lwr = vtk.vtkPNGWriter()
    lwr.SetInput( w2if.GetOutput() )
    
    cp= ocl.Point(0,0,0) # center of octree
    max_depth = 6
    root_scale = 1
    t = ocl.Octree(root_scale, max_depth, cp)
    
    t.init(2)
    n = 0 # the frame number
    
    print("root_scale = ", t.root_scale())
    print(" max_depth = ", t.max_depth())
    print(" leaf_scale=", t.leaf_scale())
    
    # X
    #stockbox = ocl.PlaneVolume( 1, 0, -0.9)
    #t.diff_negative(stockbox)
    #stockbox = ocl.PlaneVolume( 0, 0, 0.9  )
    #t.diff_negative(stockbox)
    
    # Y
    #stockbox = ocl.PlaneVolume( 1, 1, -0.9)
    #t.diff_negative(stockbox)
    #stockbox = ocl.PlaneVolume( 0, 1, 0.9  )
    #t.diff_negative(stockbox)
    
    # Z
    #stockbox = ocl.PlaneVolume( 1, 2, 0.1  )
    #t.diff_negative(stockbox)
    #stockbox = ocl.PlaneVolume( 0, 2, 0.8)
    #t.diff_negative(stockbox)
    
    
    #t.diff_negative(s)
    
    mc = ocl.MarchingCubes()
    
    print("mc()...",)
    tris = mc.mc_tree(t) # t.mc_triangles()
    print(" mc() got ", len(tris), " triangles")
    #tris2 = t.side_triangles()
    #print "appending"
    #for tr in tris2:
    #    tris.append(tr)
    #print " side_triangles() got ", len(tris2), " triangles"
    mc_surf = camvtk.STLSurf( triangleList=tris )
    mc_surf.SetColor(camvtk.cyan)
    #s_surf = camvtk.STLSurf( triangleList=tris2 )
    #s_surf.SetColor(camvtk.yellow)
    
    #mc_surf.SetWireframe()
    #mc_surf.SetOpacity(0.3)
    
    print(" STLSurf()...",)
    myscreen.addActor( mc_surf )
    #myscreen.addActor( s_surf )
    print("done.")
    myscreen.render()
    
    
    myscreen.render()
    #myscreen.iren.Start() 
    #exit()
    myscreen.removeActor( mc_surf )
    #myscreen.removeActor( s_surf )
    #renderinterleave=900
    #step_time = 0
    Nmax=10
    #dy = float(-2)/float(Nmax)
    dy = - 2* t.leaf_scale()
    cl = startpoint
    while (n<Nmax):
        cl = cl + ocl.Point(0.0,dy,0)
        #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
        #print n," diff() took ",build_time," s"
        #step_time=step_time+build_time
        if n<Nmax:
            myscreen.removeActor( mc_surf )
            #myscreen.removeActor( s_surf )
            #for c in cactors:
            #    myscreen.removeActor( c )
        
        #call_ms = 1e3*step_time/renderinterleave
        #print renderinterleave," diff() calls in", step_time, " = ", call_ms," ms/call"
        #infotext= "Octree max_depth=%i \nCL-point %i of %i \ndiff() CPU-time: %f ms/CL-point" % (max_depth,n, 
        #                                                                                          len(clpoints), call_ms )
        #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)
        #t_before = time.time() 
        #print "mc()...",
        tris = mc.mc_tree(t) #t.mc_triangles()
        #tris2 = t.side_triangles()
        #print "appending"
        #for tr in tris2:
        #    tris.append(tr)
        #mc_time = time.time()-t_before
        #print "done in ", mc_time," s"
        #print " mc() got ", len(tris), " triangles"
        #print " STLSurf()...",
        mc_surf = camvtk.STLSurf( triangleList=tris )
        mc_surf.SetWireframe()
        mc_surf.SetColor(camvtk.cyan)
        myscreen.addActor( mc_surf )
        #s_surf = camvtk.STLSurf( triangleList=tris2 )
        #s_surf.SetWireframe()
        #s_surf.SetColor(camvtk.yellow)
        #myscreen.addActor( s_surf )
        
        #print "done."
        #print " render()...",
        myscreen.render()
        #myscreen.camera.Azimuth( 0.1 )
        #lwr.SetFileName("frames/wireframe3_d8_frame"+ ('%06d' % n)+".png")
        #w2if.Modified() 
        #lwr.Write()
        
        #print "done."   
        #time.sleep(0.4)
        print(n, " mc_tris=",len(tris))
        #," side_tris=",len(tris2)
        n=n+1
        #myscreen.camera.SetPosition(3*math.cos( 7*float(n)/(float(Nmax)) ), 3*math.sin( 7*float(n)/(float(Nmax)) ), 5)
        #myscreen.camera.Azimuth( math.sin( 5*float(n)/(float(Nmax)) ) )
    print("all done.")
    myscreen.iren.Start() 
    exit()
def main():  
    print ocl.revision()
    myscreen = camvtk.VTKScreen()   
    myscreen.camera.SetPosition(-15, -8, 15)
    myscreen.camera.SetFocalPoint(0,0, 0)   
    # axis arrows
    camvtk.drawArrows(myscreen,center=(0,0,0))

    s = ocl.SphereOCTVolume()
    s.center = ocl.Point(0,0,0)
    s.radius = 2.6345
    
    sphere = camvtk.Sphere( center=(s.center.x,s.center.y,s.center.z), radius=s.radius, color=camvtk.cyan)
    sphere.SetOpacity(0.1)
    myscreen.addActor( sphere );
    
    
    # screenshot writer
    w2if = vtk.vtkWindowToImageFilter()
    w2if.SetInput(myscreen.renWin)
    lwr = vtk.vtkPNGWriter()
    lwr.SetInput( w2if.GetOutput() )
    
    # text
    camvtk.drawOCLtext(myscreen)
    octtext = camvtk.Text()
    octtext.SetPos( (myscreen.width-400, myscreen.height-290) )
    myscreen.addActor( octtext)

    
    
    cp= ocl.Point(0,0,0)
    #depths = [3, 4, 5, 6, 7, 8]
    depths = [4, 5 ]
    root_scale = 3
    n = 0 # the frame number
    for max_depth in depths:
        t = ocl.Octree(root_scale, max_depth, cp)
        t.init(1)
        print "build...",
        t_before = time.time() 
        t.diff_positive(s)    
        t_after = time.time() 
        build_time = t_after-t_before
        print "done."
        tris = t.mc_triangles()
        infotext= "Octree + Marching-Cubes test\nmax octree-depth:%i \ntriangles: %i \nbuild() time: %f ms" % (max_depth, 
                                                          len(tris), build_time*1e3 )
        octtext.SetText(infotext)
        
        mc_surf = camvtk.STLSurf( triangleList=tris, color=camvtk.red )
        #
        myscreen.addActor( mc_surf )
        print " render()...",
        myscreen.render()
        print "done."
        for m in xrange(0,180):
            # do a rotating animation
            lwr.SetFileName("frames/mc8_frame"+ ('%06d' % n)+".png")
            myscreen.camera.Azimuth( 2 )
            myscreen.render()
            w2if.Modified() 
            #lwr.Write()
            
            if m > 90:
                mc_surf.SetWireframe()
            time.sleep(0.02)
            
            n=n+1
        myscreen.removeActor( mc_surf )
        
    myscreen.iren.Start() 
Пример #14
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()
import camvtk
import time
import vtk
import datetime
import math

def drawEdge(myscreen, a, b):
    myscreen.addActor(camvtk.Sphere(center=(a.x,a.y,a.z), radius=0.0351, color=camvtk.green));
    myscreen.addActor(camvtk.Sphere(center=(b.x,b.y,b.z), radius=0.0351, color=camvtk.red));
    myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(b.x,b.y,b.z)) )

if __name__ == "__main__":  
    print ocl.revision()
    myscreen = camvtk.VTKScreen()
    camvtk.drawOCLtext(myscreen)
    camvtk.drawArrows(myscreen,center=(-1,-2,0))
    a=ocl.Point(0,1.7,-0.6)
    b=ocl.Point(0,0.11,0.3)    

    drawEdge(myscreen, a, b)
    diameter=0.4
    length=1
    # spherical cutter and cylinder
    s1 = camvtk.Sphere(center=(a.x,a.y,a.z), radius=diameter/2, color=camvtk.lgreen)
    s2 = camvtk.Sphere(center=(b.x,b.y,b.z), radius=diameter/2, color=camvtk.pink)
    s1.SetOpacity(1)
    s2.SetOpacity(1)
    myscreen.addActor(s1)
    myscreen.addActor(s2)
    # tube
    cyltube = camvtk.Tube( p1=(a.x,a.y,a.z) , p2=(b.x,b.y,b.z), radius=diameter/2, color=camvtk.yellow )
Пример #16
0
def main():
    print(ocl.revision())
    myscreen = camvtk.VTKScreen()
    myscreen.camera.SetPosition(-15, -8, 15)
    myscreen.camera.SetFocalPoint(0, 0, 0)
    # axis arrows
    camvtk.drawArrows(myscreen, center=(0, 0, 0))

    s = ocl.SphereOCTVolume()
    s.center = ocl.Point(0, 0, 0)
    s.radius = 2.6345

    sphere = camvtk.Sphere(center=(s.center.x, s.center.y, s.center.z),
                           radius=s.radius,
                           color=camvtk.cyan)
    sphere.SetOpacity(0.1)
    myscreen.addActor(sphere)

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

    # text
    camvtk.drawOCLtext(myscreen)
    octtext = camvtk.Text()
    octtext.SetPos((myscreen.width - 400, myscreen.height - 290))
    myscreen.addActor(octtext)

    cp = ocl.Point(0, 0, 0)
    #depths = [3, 4, 5, 6, 7, 8]
    depths = [4, 5]
    root_scale = 3
    n = 0  # the frame number
    for max_depth in depths:
        t = ocl.Octree(root_scale, max_depth, cp)
        t.init(1)
        print("build...", )
        t_before = time.time()
        t.diff_positive(s)
        t_after = time.time()
        build_time = t_after - t_before
        print("done.")
        tris = t.mc_triangles()
        infotext = "Octree + Marching-Cubes test\nmax octree-depth:%i \ntriangles: %i \nbuild() time: %f ms" % (
            max_depth, len(tris), build_time * 1e3)
        octtext.SetText(infotext)

        mc_surf = camvtk.STLSurf(triangleList=tris, color=camvtk.red)
        #
        myscreen.addActor(mc_surf)
        print(" render()...", )
        myscreen.render()
        print("done.")
        for m in range(0, 180):
            # do a rotating animation
            lwr.SetFileName("frames/mc8_frame" + ('%06d' % n) + ".png")
            myscreen.camera.Azimuth(2)
            myscreen.render()
            w2if.Modified()
            #lwr.Write()

            if m > 90:
                mc_surf.SetWireframe()
            time.sleep(0.02)

            n = n + 1
        myscreen.removeActor(mc_surf)

    myscreen.iren.Start()
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=(0,0,0))

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

    
    c = ocl.CylCutter(3,10) # cutter
    c.length = 3
    print "cutter length=", c.length
    
    cp= ocl.Point(0,0,0)
    max_depth = 9
    root_scale = 3
    t = ocl.Octree(root_scale, max_depth, cp)
    print t
    
    nodes = t.get_leaf_nodes()
    t.init(1)
    #nodes=[]
    s = ocl.SphereOCTVolume()
    s.center = ocl.Point(0,0,0)
    s.radius = 2.6345
    print "build...",
    t.build(s)
    print "done."
    print t
    
    sphere = camvtk.Sphere( center=(s.center.x,s.center.y,s.center.z), radius=s.radius, color=camvtk.cyan)
    sphere.SetOpacity(0.1)
    myscreen.addActor( sphere );
    
    
    nodes = t.get_surface_nodes()
    print "got ", len(nodes)," surface nodes"
   
    points=[]
    for n in nodes:
        #n=nodes[0]
        verts = n.vertices()
        #c = n.center
        #print " node at depth=", n.depth," center=",c
        #myscreen.addActor( camvtk.Sphere( center=(c.x,c.y,c.z), radius=0.1, color=camvtk.yellow ))
        for v in verts:
            #print v
            #myscreen.addActor( camvtk.Sphere( center=(v.x,v.y,v.z), radius=0.1 ))
            #
            points.append(v)
            
    #myscreen.addActor( camvtk.PointCloud( pointlist= points))
    
    tris = t.mc_triangles()
    mc_surf = camvtk.STLSurf( triangleList=tris, color=camvtk.red )
    #mc_surf.SetWireframe()
    myscreen.addActor( mc_surf )
    print " render()...",
    myscreen.render()
    print "done."
    
    
    #time.sleep(0.2)
    
    
    
    myscreen.iren.Start() 
Пример #18
0
def main():  
    print(ocl.revision())
    myscreen = camvtk.VTKScreen()   
    myscreen.camera.SetPosition(-15, -8, 15)
    myscreen.camera.SetFocalPoint(0,0, 0)   
    # axis arrows
    camvtk.drawArrows(myscreen,center=(0,0,0))

    s = ocl.SphereOCTVolume()
    s.center = ocl.Point(-2.50,-0.6,0)
    s.radius = 0.6345
    
    #sphere = camvtk.Sphere( center=(s.center.x,s.center.y,s.center.z), radius=s.radius, color=camvtk.cyan)
    #sphere.SetOpacity(0.1)
    #myscreen.addActor( sphere );
    
    
    # screenshot writer
    w2if = vtk.vtkWindowToImageFilter()
    w2if.SetInput(myscreen.renWin)
    lwr = vtk.vtkPNGWriter()
    lwr.SetInput( w2if.GetOutput() )
    
    # text
    camvtk.drawOCLtext(myscreen)
    octtext = camvtk.Text()
    octtext.SetPos( (myscreen.width-400, myscreen.height-290) )
    myscreen.addActor( octtext)

    
    
    cp= ocl.Point(0,0,-3)
    #depths = [3, 4, 5, 6, 7, 8]
    max_depth = 7
    root_scale = 3
    t = ocl.Octree(root_scale, max_depth, cp)
    t.init(4)
    n = 0 # the frame number
    nmax=30
    theta=0
    dtheta=0.05
    s.center =  ocl.Point( 1.5*math.cos(theta),0.3*math.sin(theta),theta)  
    mc = ocl.MarchingCubes()
    tris=[]
    while (n<=nmax):
        print("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")
        infotext= "Octree + Marching-Cubes test\nmax octree-depth:%i \ntriangles: %i \nbuild() time: %f ms" % (max_depth, 
                                                len(tris), build_time*1e3 )
        octtext.SetText(infotext)
        
        if n==nmax:
            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.")
            #nodes = t.get_leaf_nodes()
            #allpoints=[]
            #for no in nodes:
            #    verts = no.vertices()
            #    for v in verts:
            #        allpoints.append(v)
            #oct_points = camvtk.PointCloud( allpoints )
            #print " PointCloud()...",
            #myscreen.addActor( oct_points )
            #print "done."
            print(" render()...",)
            myscreen.render()

            print("done.")

            #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."
                
            
            if n is not nmax:
                myscreen.removeActor( mc_surf )
                #myscreen.removeActor( oct_points )
        
        # move forward
        theta = n*dtheta
        s.center =  ocl.Point( 1.5*math.cos(theta),0.3*math.sin(theta),0.01*theta)  
        print("center moved to", s.center)
        n=n+1
    print("All done.")
    myscreen.iren.Start() 
Пример #19
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()
Пример #20
0
def drawScreen(a, b, c, filename, write_flag):
    print(ocl.version())
    myscreen = camvtk.VTKScreen()
    #a = ocl.Point(0,1,0.3)
    myscreen.addActor(camvtk.Point(center=(a.x, a.y, a.z), color=(1, 0, 1)))
    #b = ocl.Point(1,0.5,0.3)
    myscreen.addActor(camvtk.Point(center=(b.x, b.y, b.z), color=(1, 0, 1)))
    #c = ocl.Point(-0.1,0.3,0.0)
    myscreen.addActor(camvtk.Point(center=(c.x, c.y, c.z), color=(1, 0, 1)))
    myscreen.addActor(camvtk.Line(p1=(a.x, a.y, a.z), p2=(c.x, c.y, c.z)))
    myscreen.addActor(camvtk.Line(p1=(c.x, c.y, c.z), p2=(b.x, b.y, b.z)))
    myscreen.addActor(camvtk.Line(p1=(a.x, a.y, a.z), p2=(b.x, b.y, b.z)))
    t = ocl.Triangle(b, c, a)
    s = ocl.STLSurf()
    s.addTriangle(t)  # a one-triangle STLSurf
    zheights = [
        -0.3, -0.2, -0.1, -0.05, 0.0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.26, 0.27,
        0.28, 0.29
    ]  # the z-coordinates for the waterlines
    zheights = [
        -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, -0.05, 0.0, 0.05, 0.1,
        0.15, 0.2, 0.28
    ]
    zheights = [
        -0.35, -0.3, -0.25, -0.2, -0.15, -0.1, -0.05, 0.0, 0.05, 0.1, 0.15,
        0.2, 0.25, 0.28
    ]

    zheights = []
    Nmax = 20
    zmin = -0.5
    zmax = -0.05
    dz = (zmax - zmin) / float(Nmax - 1)
    z = zmin
    for n in range(Nmax):
        zheights.append(z)
        z = z + dz

    zheights = []
    zheights.append(-0.25)
    #zheights=[ -0.35,  -0.25,  -0.15,  -0.05, 0.05,  0.15,   0.25]
    #zheights=[ 0.1]

    length = 10
    diam = 0.6
    cutter1 = ocl.CylCutter(diam, length)
    cutter2 = ocl.BallCutter(diam, length)
    cutter3 = ocl.BullCutter(diam, diam / 5, length)
    cutter4 = ocl.ConeCutter(diam, math.pi / 5, length)

    for zh in zheights:
        #loops = calcWaterline(zh, cutter1, s)
        #drawLoops(myscreen, loops[0], camvtk.yellow)

        #loops = calcWaterline(zh, cutter2, s)
        #drawLoops(myscreen, loops[0], camvtk.green)
        #loops = calcWaterline(zh, cutter3, s)
        #drawLoops(myscreen, loops[0], camvtk.yellow)

        loops = calcWaterline(zh, cutter4, s)
        drawLoops(myscreen, loops[0], camvtk.pink)

        #for f in loops[1]:
        #    drawFiber(myscreen, f, camvtk.red)
        #for f in loops[2]:
        #    drawFiber(myscreen, f, camvtk.lblue)

    print("done.")
    myscreen.camera.SetPosition(1, -1, 3)
    myscreen.camera.SetFocalPoint(0.5, 0.5, 0)
    camvtk.drawArrows(myscreen, center=(-0.5, -0.5, -0.5))
    camvtk.drawOCLtext(myscreen)
    myscreen.render()
    """
    w2if = vtk.vtkWindowToImageFilter()
    w2if.SetInput(myscreen.renWin)
    lwr = vtk.vtkPNGWriter()
    lwr.SetInput( w2if.GetOutput() )
    w2if.Modified()
    lwr.SetFileName(filename)
    if write_flag:
        lwr.Write()
        print("wrote ",filename)
    """

    time.sleep(1)
Пример #21
0
def vtk_visualize_parallel_finish_zig(stlfile, toolpaths):
    myscreen = camvtk.VTKScreen()
    stl = camvtk.STLSurf(stlfile)
    myscreen.addActor(stl)
    stl.SetSurface()  # try also SetWireframe()
    stl.SetColor(camvtk.cyan)
    myscreen.camera.SetPosition(15, 13, 7)
    myscreen.camera.SetFocalPoint(5, 5, 0)

    rapid_height = 5  # XY rapids at this height
    feed_height = 3
    rapidColor = camvtk.pink
    XYrapidColor = camvtk.green
    plungeColor = camvtk.red
    feedColor = camvtk.yellow
    # zig path algorithm:
    # 1) lift to clearance height
    # 2) XY rapid to start of path
    # 3) plunge to correct z-depth
    # 4) feed along path until end
    pos = ocl.Point(0, 0, 0)  # keep track of the current position of the tool
    first = True
    for path in toolpaths:
        first_pt = path[0]
        if (first == True):  # green sphere at path start
            myscreen.addActor(
                camvtk.Sphere(center=(first_pt.x, first_pt.y, rapid_height),
                              radius=0.1,
                              color=camvtk.green))
            pos = ocl.Point(
                first_pt.x, first_pt.y, first_pt.z
            )  # at start of program, assume we have already a rapid move here
            first = False
        else:  # not the very first move
            # retract up to rapid_height
            myscreen.addActor(
                camvtk.Line(p1=(pos.x, pos.y, pos.z),
                            p2=(pos.x, pos.y, feed_height),
                            color=plungeColor))
            myscreen.addActor(
                camvtk.Line(p1=(pos.x, pos.y, feed_height),
                            p2=(pos.x, pos.y, rapid_height),
                            color=rapidColor))
            # XY rapid into position
            myscreen.addActor(
                camvtk.Line(p1=(pos.x, pos.y, rapid_height),
                            p2=(first_pt.x, first_pt.y, rapid_height),
                            color=XYrapidColor))
            pos = ocl.Point(first_pt.x, first_pt.y, first_pt.z)

        # rapid down to the feed_height
        myscreen.addActor(
            camvtk.Line(p1=(pos.x, pos.y, rapid_height),
                        p2=(pos.x, pos.y, feed_height),
                        color=rapidColor))
        # feed down to CL
        myscreen.addActor(
            camvtk.Line(p1=(pos.x, pos.y, feed_height),
                        p2=(pos.x, pos.y, pos.z),
                        color=plungeColor))

        # feed along the path
        for p in path[1:]:
            myscreen.addActor(
                camvtk.Line(p1=(pos.x, pos.y, pos.z),
                            p2=(p.x, p.y, p.z),
                            color=feedColor))
            pos = ocl.Point(p.x, p.y, p.z)

    # END retract up to rapid_height
    myscreen.addActor(
        camvtk.Line(p1=(pos.x, pos.y, pos.z),
                    p2=(pos.x, pos.y, feed_height),
                    color=plungeColor))
    myscreen.addActor(
        camvtk.Line(p1=(pos.x, pos.y, feed_height),
                    p2=(pos.x, pos.y, rapid_height),
                    color=rapidColor))
    myscreen.addActor(
        camvtk.Sphere(center=(pos.x, pos.y, rapid_height),
                      radius=0.1,
                      color=camvtk.red))

    camvtk.drawArrows(myscreen,
                      center=(-0.5, -0.5, -0.5))  # XYZ coordinate arrows
    camvtk.drawOCLtext(myscreen)
    myscreen.render()
    myscreen.iren.Start()
Пример #22
0
def main():  
    print(ocl.version())
    myscreen = camvtk.VTKScreen()   
    myscreen.camera.SetPosition(-8, -4, 25)
    myscreen.camera.SetFocalPoint(0,0, 0)   
    arpos=-1.5
    camvtk.drawArrows(myscreen,center=(arpos,arpos,arpos))
    camvtk.drawOCLtext(myscreen)
    octtext = camvtk.Text()
    octtext.SetPos( (70, myscreen.height-600) )
    myscreen.addActor( octtext)
    octtext.SetText("Octree")
    vertex = [       ocl.Point( 1, 1,-1),   #// 0
                     ocl.Point(-1, 1,-1),   #// 1
                     ocl.Point(-1,-1,-1),   #// 2
                     ocl.Point( 1,-1,-1),   #// 3
                     ocl.Point( 1, 1, 1),   #// 4
                     ocl.Point(-1, 1, 1),   #// 5
                     ocl.Point(-1,-1, 1),   #// 6
                     ocl.Point( 1,-1, 1)    #// 7
                    ]
    
    n=0
    for v in vertex:
        myscreen.addActor( camvtk.Sphere(center=(v.x,v.y,v.z), radius=0.1,color=camvtk.red))
        v=v
        t = camvtk.Text3D(color=camvtk.red, center=(v.x+0.1,v.y+0.1,v.z), text=str(n), scale=0.2, camera=myscreen.camera)
        myscreen.addActor(t)
        n=n+1
    
    edgeTable = [ [0,1] ,
                  [1,2] ,
                  [2,3] ,
                  [3,0] ,
                  [4,5] ,
                  [5,6] ,
                  [6,7] ,
                  [7,4] ,
                  [0,4] ,
                  [1,5] ,
                  [2,6] ,
                  [3,7] ,  
                ]
    
    # draw the edges as tubes
    ne = 0
    for e in edgeTable:

        ep1 = vertex[ e[0] ] 
        ep2 = vertex[ e[1] ]
        tu = camvtk.Tube( p1=(ep1.x,ep1.y,ep1.z), p2=(ep2.x,ep2.y,ep2.z), radius=0.051, color=camvtk.green )
        myscreen.addActor(tu)
        mid = 0.5*(ep1 + ep2)
        t = camvtk.Text3D(color=camvtk.green, center=(mid.x+0.1,mid.y+0.1,mid.z), text=str(ne), scale=0.2, camera=myscreen.camera)
        myscreen.addActor(t)
        ne=ne+1
        
    # number the faces
    face = [ [2,3,6,7] , 
             [0,3,4,7] , 
             [0,1,4,5] ,
             [1,2,5,6] ,
             [0,1,2,3] ,
             [4,5,6,7] ,
            ]
    nf=0
    for f in face:
        mid = ocl.Point()
        for v in f:
            mid = mid+vertex[v]
        mid=0.25*mid
        t = camvtk.Text3D(color=camvtk.blue, center=(mid.x,mid.y,mid.z), text=str(nf), scale=0.2, camera=myscreen.camera)
        myscreen.addActor(t)
        nf=nf+1
    myscreen.render() 
    print("All done.")
    myscreen.iren.Start() 
Пример #23
0
def main():
    print ocl.revision()
    myscreen = camvtk.VTKScreen()
    myscreen.camera.SetPosition(2, 2, 5)
    myscreen.camera.SetFocalPoint(0.5, 0, 1)
    camvtk.drawArrows(myscreen, center=(-2, -2, 0))  # axis arrows
    camvtk.drawOCLtext(myscreen)

    #s = ocl.BallCutterVolume()
    #s = ocl.CylCutterVolume()
    s = ocl.BullCutterVolume()
    s.r1 = 0.3
    s.r2 = 0.1
    s.radius = 0.4
    s.length = 2
    startpoint = ocl.Point(0.46, 0.2, 0.4)
    s.setPos(startpoint)
    cp = ocl.Point(0, 0, 0)  # center of octree
    max_depth = 6
    root_scale = 1
    t = ocl.Octree(root_scale, max_depth, cp)
    t.init(2)
    n = 0  # the frame number
    print "root_scale = ", t.root_scale()
    print " max_depth = ", t.max_depth()
    print " leaf_scale=", t.leaf_scale()

    print "mc()...",
    mc = ocl.MarchingCubes()
    tris = mc.mc_tree(t)

    mc_surf = camvtk.STLSurf(triangleList=tris)
    mc_surf.SetColor(camvtk.cyan)

    print " STLSurf()...",
    myscreen.addActor(mc_surf)

    print "done."
    myscreen.render()
    myscreen.removeActor(mc_surf)

    Nmax = 20
    dy = -1 * t.leaf_scale()
    cl = startpoint
    renderinterleave = 1
    while (n < Nmax):

        cl = cl + ocl.Point(0.0, dy, 0)
        s.setPos(cl)  # move the cutter
        t_before = time.time()
        t.diff_negative(s)  # subtract cutter from stock
        t_after = time.time()
        diff_time = t_after - t_before
        if n < Nmax:
            myscreen.removeActor(
                mc_surf)  # leave the surface on the very last iteration

        # marching cubes
        t_before = time.time()
        tris = mc.mc_tree(t)
        t_after = time.time()
        mc_time = t_after - t_before

        # render
        t_before = time.time()
        mc_surf = camvtk.STLSurf(triangleList=tris)
        mc_surf.SetColor(camvtk.cyan)
        myscreen.addActor(mc_surf)
        myscreen.render()

        t_after = time.time()
        render_time = t_after - t_before
        print "%i: mc_tris=%i\t diff=%1.3f \t mc=%1.3f \t ren=%1.3f" % (
            n, len(tris), diff_time, mc_time, render_time)
        n = n + 1

    print "all done."
    myscreen.iren.Start()
    exit()
Пример #24
0
    minSampling = 0.1

    aloops = []
    for zh in zheights:
        awl = ocl.AdaptiveWaterline()
        awl.setSTL(s)
        awl.setCutter(cutter)
        awl.setZ(zh)
        awl.setSampling(sampling)
        awl.setMinSampling(minSampling)
        #wl.setThreads(5)
        t_before = time.time()
        awl.run()
        t_after = time.time()
        calctime = t_after - t_before
        print " AdaptiveWaterline done in ", calctime, " s"
        acutter_loops = awl.getLoops()
        for l in acutter_loops:
            aloops.append(l)

    drawLoops(myscreen, aloops, camvtk.red)

    print "done."
    myscreen.camera.SetPosition(185, 153, 167)
    myscreen.camera.SetFocalPoint(5, 5, 0)
    camvtk.drawArrows(myscreen, center=(0, -4, 0))
    camvtk.drawOCLtext(myscreen)
    myscreen.render()
    myscreen.iren.Start()
    #raw_input("Press Enter to terminate")
Пример #25
0
def main():
    print ocl.revision()
    myscreen = camvtk.VTKScreen()
    myscreen.camera.SetPosition(-15, -8, 15)
    myscreen.camera.SetFocalPoint(0, 0, 0)
    # axis arrows
    camvtk.drawArrows(myscreen, center=(0, 0, 0))

    s = ocl.SphereOCTVolume()
    s.center = ocl.Point(-2.50, -0.6, 0)
    s.radius = 0.6345

    #sphere = camvtk.Sphere( center=(s.center.x,s.center.y,s.center.z), radius=s.radius, color=camvtk.cyan)
    #sphere.SetOpacity(0.1)
    #myscreen.addActor( sphere );

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

    # text
    camvtk.drawOCLtext(myscreen)
    octtext = camvtk.Text()
    octtext.SetPos((myscreen.width - 400, myscreen.height - 290))
    myscreen.addActor(octtext)

    cp = ocl.Point(0, 0, -3)
    #depths = [3, 4, 5, 6, 7, 8]
    max_depth = 7
    root_scale = 3
    t = ocl.Octree(root_scale, max_depth, cp)
    t.init(4)
    n = 0  # the frame number
    nmax = 30
    theta = 0
    dtheta = 0.05
    s.center = ocl.Point(1.5 * math.cos(theta), 0.3 * math.sin(theta), theta)
    mc = ocl.MarchingCubes()
    tris = []
    while (n <= nmax):
        print "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"
        infotext = "Octree + Marching-Cubes test\nmax octree-depth:%i \ntriangles: %i \nbuild() time: %f ms" % (
            max_depth, len(tris), build_time * 1e3)
        octtext.SetText(infotext)

        if n == nmax:
            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."
            #nodes = t.get_leaf_nodes()
            #allpoints=[]
            #for no in nodes:
            #    verts = no.vertices()
            #    for v in verts:
            #        allpoints.append(v)
            #oct_points = camvtk.PointCloud( allpoints )
            #print " PointCloud()...",
            #myscreen.addActor( oct_points )
            #print "done."
            print " render()...",
            myscreen.render()

            print "done."

            #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."

            if n is not nmax:
                myscreen.removeActor(mc_surf)
                #myscreen.removeActor( oct_points )

        # move forward
        theta = n * dtheta
        s.center = ocl.Point(1.5 * math.cos(theta), 0.3 * math.sin(theta),
                             0.01 * theta)
        print "center moved to", s.center
        n = n + 1
    print "All done."
    myscreen.iren.Start()
Пример #26
0
    #exit()
    
    loops = []
    for z in zh:
        
        z_loops = getWaterline(s, cutter, z, sampling)
        for l in z_loops:
            loops.append(l)
    
    
    #for l in line:
        
    #drawLoops(myscreen, line, camvtk.cyan)
    #for l in cutter_loops:
    #    loops.append(l)
    
    print "All waterlines done. Got", len(loops)," loops in total."
    # draw the loops
    drawLoops(myscreen, loops, camvtk.cyan)
    drawLoops(myscreen, ptsy_all, camvtk.pink)
    drawLoops(myscreen, ptsx_all, camvtk.lblue)
    
    print "done."
    myscreen.camera.SetPosition(15, 13, 7)
    myscreen.camera.SetFocalPoint(5, 5, 0)
    camvtk.drawArrows(myscreen,center=(0,0,3))
    camvtk.drawOCLtext(myscreen)
    myscreen.render()    
    myscreen.iren.Start()
    #raw_input("Press Enter to terminate") 
Пример #27
0
def drawEdge(myscreen, a, b):
    myscreen.addActor(
        camvtk.Sphere(center=(a.x, a.y, a.z),
                      radius=0.0351,
                      color=camvtk.green))
    myscreen.addActor(
        camvtk.Sphere(center=(b.x, b.y, b.z), radius=0.0351, color=camvtk.red))
    myscreen.addActor(camvtk.Line(p1=(a.x, a.y, a.z), p2=(b.x, b.y, b.z)))


if __name__ == "__main__":
    print ocl.revision()
    myscreen = camvtk.VTKScreen()
    camvtk.drawOCLtext(myscreen)
    camvtk.drawArrows(myscreen, center=(-1, -2, 0))
    a = ocl.Point(0, 1.7, -0.6)
    b = ocl.Point(0, 0.11, 0.3)

    drawEdge(myscreen, a, b)
    diameter = 0.4
    length = 1
    # spherical cutter and cylinder
    s1 = camvtk.Sphere(center=(a.x, a.y, a.z),
                       radius=diameter / 2,
                       color=camvtk.lgreen)
    s2 = camvtk.Sphere(center=(b.x, b.y, b.z),
                       radius=diameter / 2,
                       color=camvtk.pink)
    s1.SetOpacity(1)
    s2.SetOpacity(1)
Пример #28
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() 
Пример #29
0
def main(filename="frame/f.png"):  
    print ocl.revision()
          
    myscreen = camvtk.VTKScreen()   
    myscreen.camera.SetPosition(20, 12, 20)
    myscreen.camera.SetFocalPoint(0,0, 0)   
    # axis arrows
    camvtk.drawArrows(myscreen,center=(2,2,2))

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

    
    c = ocl.CylCutter(1) # cutter
    c.length = 3
    print "cutter length=", c.length
    p1 = ocl.CLPoint(-0.2,-0.2,0.2) # start of move
    p2 = ocl.CLPoint(-0.2,0.2,0.0) # end of move
    p3 = ocl.CLPoint(0.5,0.0,-0.5)
    clpoints=[]
    clpoints.append(p1)
    clpoints.append(p2)
    clpoints.append(p3)
    
    f=ocl.Ocode()
    f.set_depth(6) # depth and scale set here.
    f.set_scale(1)
    
    # cube
    cube1 = ocl.CubeOCTVolume()
    cube1.side=2.123
    cube1.center = ocl.Point(0,0,0)
    cube1.calcBB()
    
    stock = ocl.LinOCT()
    stock.init(3)
    stock.build( cube1 )
    
    # draw initial octree 
    tlist = pyocl.octree2trilist(stock)
    surf = camvtk.STLSurf(triangleList=tlist)
    myscreen.addActor(surf)
    
    Nmoves = len(clpoints)
    print Nmoves,"CL-points to process"
    for n in xrange(0,Nmoves-1):
        #if n<Nmoves-1:
        print n," to ",n+1
        startp = clpoints[n]
        endp   = clpoints[n+1]
        sweep = ocl.LinOCT()
        sweep.init(3)
        g1vol = ocl.CylMoveOCTVolume(c, ocl.Point(startp.x,startp.y,startp.z), ocl.Point(endp.x,endp.y,endp.z))
        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))
        sweep.build( g1vol )
        stock.diff(sweep)
        myscreen.removeActor(surf)
        tlist = pyocl.octree2trilist(stock)
        surf = camvtk.STLSurf(triangleList=tlist)
        surf.SetColor(camvtk.cyan)
        surf.SetOpacity(1.0)
        myscreen.addActor(surf)
        myscreen.render()
        time.sleep(0.2)
            
    #exit()
    
    # draw trees
    #print "drawing trees"
    #camvtk.drawTree2(myscreen,  stock, opacity=1,   color=camvtk.cyan)        

    # box around octree 
    oct_cube = camvtk.Cube(center=(0,0,0), length=4*f.get_scale(), color=camvtk.white)
    oct_cube.SetWireframe()
    myscreen.addActor(oct_cube)
    
    # OCL text
    title = camvtk.Text()
    title.SetPos( (myscreen.width-350, myscreen.height-30) )
    title.SetText("OpenCAMLib " + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
    myscreen.addActor(title)
        
    print " render()...",
    myscreen.render()
    print "done."
    
    lwr.SetFileName(filename)
    time.sleep(0.2)
    #lwr.Write()
    
    
    myscreen.iren.Start() 
Пример #30
0
def main(filename="frame/f.png"):
    print(ocl.revision())

    myscreen = camvtk.VTKScreen()
    myscreen.camera.SetPosition(20, 12, 20)
    myscreen.camera.SetFocalPoint(0, 0, 0)
    # axis arrows
    camvtk.drawArrows(myscreen, center=(2, 2, 2))

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

    c = ocl.CylCutter(1)  # cutter
    c.length = 3
    print("cutter length=", c.length)
    p1 = ocl.CLPoint(-0.2, -0.2, 0.2)  # start of move
    p2 = ocl.CLPoint(-0.2, 0.2, 0.0)  # end of move
    p3 = ocl.CLPoint(0.5, 0.0, -0.5)
    clpoints = []
    clpoints.append(p1)
    clpoints.append(p2)
    clpoints.append(p3)

    f = ocl.Ocode()
    f.set_depth(6)  # depth and scale set here.
    f.set_scale(1)

    # cube
    cube1 = ocl.CubeOCTVolume()
    cube1.side = 2.123
    cube1.center = ocl.Point(0, 0, 0)
    cube1.calcBB()

    stock = ocl.LinOCT()
    stock.init(3)
    stock.build(cube1)

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

    Nmoves = len(clpoints)
    print(Nmoves, "CL-points to process")
    for n in range(0, Nmoves - 1):
        #if n<Nmoves-1:
        print(n, " to ", n + 1)
        startp = clpoints[n]
        endp = clpoints[n + 1]
        sweep = ocl.LinOCT()
        sweep.init(3)
        g1vol = ocl.CylMoveOCTVolume(c, ocl.Point(startp.x, startp.y,
                                                  startp.z),
                                     ocl.Point(endp.x, endp.y, endp.z))
        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))
        sweep.build(g1vol)
        stock.diff(sweep)
        myscreen.removeActor(surf)
        tlist = pyocl.octree2trilist(stock)
        surf = camvtk.STLSurf(triangleList=tlist)
        surf.SetColor(camvtk.cyan)
        surf.SetOpacity(1.0)
        myscreen.addActor(surf)
        myscreen.render()
        time.sleep(0.2)

    #exit()

    # draw trees
    #print "drawing trees"
    #camvtk.drawTree2(myscreen,  stock, opacity=1,   color=camvtk.cyan)

    # box around octree
    oct_cube = camvtk.Cube(center=(0, 0, 0),
                           length=4 * f.get_scale(),
                           color=camvtk.white)
    oct_cube.SetWireframe()
    myscreen.addActor(oct_cube)

    # OCL text
    title = camvtk.Text()
    title.SetPos((myscreen.width - 350, myscreen.height - 30))
    title.SetText("OpenCAMLib " +
                  datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
    myscreen.addActor(title)

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

    lwr.SetFileName(filename)
    time.sleep(0.2)
    #lwr.Write()

    myscreen.iren.Start()
Пример #31
0
def main():  
    print ocl.revision()
    myscreen = camvtk.VTKScreen()   
    myscreen.camera.SetPosition(2, 2, 5)
    myscreen.camera.SetFocalPoint(0.5,0, 1)   
    camvtk.drawArrows(myscreen,center=(-2,-2,0)) # axis arrows
    camvtk.drawOCLtext(myscreen)
    
    #s = ocl.BallCutterVolume()
    #s = ocl.CylCutterVolume()
    s = ocl.BullCutterVolume()
    s.r1=0.3
    s.r2=0.1
    s.radius = 0.4
    s.length = 2
    startpoint = ocl.Point(0.46,0.2,0.4)
    s.setPos( startpoint )
    cp= ocl.Point(0,0,0) # center of octree
    max_depth = 6
    root_scale = 1
    t = ocl.Octree(root_scale, max_depth, cp)
    t.init(2)
    n = 0 # the frame number
    print "root_scale = ", t.root_scale()
    print " max_depth = ", t.max_depth()
    print " leaf_scale=", t.leaf_scale()

    print "mc()...",
    mc = ocl.MarchingCubes()
    tris = mc.mc_tree(t) 

    mc_surf = camvtk.STLSurf( triangleList=tris )
    mc_surf.SetColor(camvtk.cyan)

    print " STLSurf()...",
    myscreen.addActor( mc_surf )

    print "done."
    myscreen.render()
    myscreen.removeActor( mc_surf )

    Nmax=20
    dy = - 1* t.leaf_scale()
    cl = startpoint
    renderinterleave=1
    while (n<Nmax):
        
        cl = cl + ocl.Point(0.0,dy,0)
        s.setPos( cl ) # move the cutter
        t_before = time.time() 
        t.diff_negative(s) # subtract cutter from stock
        t_after = time.time() 
        diff_time = t_after-t_before
        if n<Nmax:
            myscreen.removeActor( mc_surf ) # leave the surface on the very last iteration
            
        # marching cubes
        t_before = time.time() 
        tris = mc.mc_tree(t) 
        t_after = time.time()
        mc_time = t_after-t_before
        
        # render
        t_before = time.time()
        mc_surf = camvtk.STLSurf( triangleList=tris )
        mc_surf.SetColor(camvtk.cyan)
        myscreen.addActor( mc_surf )
        myscreen.render()
        
        t_after = time.time()
        render_time = t_after-t_before
        print "%i: mc_tris=%i\t diff=%1.3f \t mc=%1.3f \t ren=%1.3f" % (n, len(tris), diff_time, mc_time, render_time)
        n=n+1

    print "all done."
    myscreen.iren.Start() 
    exit()
    cutter5 =  ocl.CylConeCutter(diam/float(3),diam,math.pi/float(9))
    
    for zh in zheights:
        loops = calcWaterline(zh, cutter5, s)
        drawLoops(myscreen, loops[0], camvtk.red)
        
        #loops = calcWaterline(zh, cutter2, s)
        #drawLoops(myscreen, loops[0], camvtk.green)
        #loops = calcWaterline(zh, cutter3, s)
        #drawLoops(myscreen, loops[0], camvtk.yellow)
        
        #loops = calcWaterline(zh, cutter4, s)
        #drawLoops(myscreen, loops[0], camvtk.pink)
        
        #for f in loops[1]:
        #    drawFiber(myscreen, f, camvtk.red)
        #for f in loops[2]:
        #    drawFiber(myscreen, f, camvtk.lblue)
        
        
        

    print "done."
    myscreen.camera.SetPosition(1, -1, 3)
    myscreen.camera.SetFocalPoint(0.5, 0.5, 0)
    camvtk.drawArrows(myscreen,center=(-0.5,-0.5,-0.5))
    camvtk.drawOCLtext(myscreen)
    myscreen.render()    
    myscreen.iren.Start()
    #raw_input("Press Enter to terminate") 
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()