Esempio n. 1
0
 def __init__(self, myscreen):
     self.myscreen = myscreen
     self.generators = []
     self.verts=[]
     self.far=[]
     self.edges =[]
     self.generatorColor = camvtk.green
     self.vertexColor = camvtk.red
     self.edgeColor = camvtk.cyan
     self.vdtext  = camvtk.Text()
     self.vdtext.SetPos( (50, myscreen.height-50) )
     self.Ngen = 0
     self.vdtext_text = ""
     self.setVDText()
     
     myscreen.addActor(self.vdtext)
Esempio n. 2
0
 def __init__(self, myscreen, vd):
     self.myscreen = myscreen
     self.gen_pts=[ocl.Point(0,0,0)]
     self.generators = camvtk.PointCloud(pointlist=self.gen_pts)
     self.verts=[]
     self.far=[]
     self.edges =[]
     self.generatorColor = camvtk.green
     self.vertexColor = camvtk.red
     self.edgeColor = camvtk.cyan
     self.vdtext  = camvtk.Text()
     self.vdtext.SetPos( (50, myscreen.height-50) )
     self.Ngen = 0
     self.vdtext_text = ""
     self.setVDText(vd)
     
     myscreen.addActor(self.vdtext)
def main(filename="frame/f.png",yc=6, n=0):  
    print(ocl.revision())
          
    f=ocl.Ocode()
    f.set_depth(7) # depth and scale set here.
    f.set_scale(1)
    
    myscreen = camvtk.VTKScreen()   
    myscreen.camera.SetPosition(50, 22, 40)
    myscreen.camera.SetFocalPoint(0,0, 0)   
    myscreen.camera.Azimuth( n*0.5 )
    
    # 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)
    
    # screenshot writer
    w2if = vtk.vtkWindowToImageFilter()
    w2if.SetInput(myscreen.renWin)
    lwr = vtk.vtkPNGWriter()
    lwr.SetInput( w2if.GetOutput() )
    
    # X Y Z arrows
    arrowcenter=(1,2,0)
    xar = camvtk.Arrow(color=camvtk.red, center=arrowcenter, rotXYZ=(0,0,0))
    myscreen.addActor(xar)
    yar = camvtk.Arrow(color=camvtk.green, center=arrowcenter, rotXYZ=(0,0,90))
    myscreen.addActor(yar)
    zar = camvtk.Arrow(color=camvtk.blue, center=arrowcenter, rotXYZ=(0,-90,0))
    myscreen.addActor(zar) 
    
    
    t = ocl.LinOCT()
    t2 = ocl.LinOCT()
    t.init(5)
    t2.init(4)
        
    print(" after init() t :", t.str())
    print(" after init() t2 :", t2.str())
    
    c = ocl.CylCutter(1) # cutter
    c.length = 3
    print("cutter length=", c.length)
    p1 = ocl.Point(-0.2,-0.2,0.2) # start of move
    p2 = ocl.Point(1.5,1.5,-1) # end of move
    
    # volume of g1 move 
    g1vol = ocl.CylMoveOCTVolume(c, p1, p2)
    
    
    # sphere
    svol = ocl.SphereOCTVolume()
    svol.radius=1
    svol.center = ocl.Point(0,0,1)
    svol.calcBB()

    # cube
    cube1 = ocl.CubeOCTVolume()
    cube1.side=2.123
    cube1.center = ocl.Point(0,0,0)
    cube1.calcBB()
    
    #cylinder volume at start of move
    cylvol = ocl.CylinderOCTVolume()
    cylvol.p1 = ocl.Point(p1)
    cylvol.p2 = ocl.Point(p1)+ocl.Point(0,0,c.length)
    cylvol.radius= c.radius
    cylvol.calcBB()
    
    # draw exact cylinder
    cp = 0.5*(cylvol.p1 + cylvol.p2)
    height = (cylvol.p2-cylvol.p1).norm()
    cylvolactor = camvtk.Cylinder(center=(cp.x, cp.y, cp.z-float(height)/2), radius = cylvol.radius, height=height, rotXYZ=(90,0,0))
    cylvolactor.SetWireframe()
    myscreen.addActor(cylvolactor)

    # cylinder at start of move
    #drawCylCutter(myscreen, c, p1)
    # cylinder at end of move
    drawCylCutter(myscreen, c, p2)
    
    # green ball at start of move
    startp = camvtk.Sphere(center=(p1.x,p1.y,p1.z), radius=0.1, color=camvtk.green)
    myscreen.addActor(startp)
    # red ball at end of move
    endp = camvtk.Sphere(center=(p2.x,p2.y,p2.z), radius=0.1, color=camvtk.red)
    myscreen.addActor(endp)
    
    
    
    
    # build g1 tree
    t_before = time.time()
    t.build( g1vol )
    t_after = time.time()
    print("g1 build took ", t_after-t_before," s")
    
    # build cube
    t_before = time.time()
    t2.build( cube1 )
    t_after = time.time()
    print("cube build took ", t_after-t_before," s")
    
    #t.sort()
    #t2.sort()
    
    print("calling diff()...",)
    t_before = time.time()
    #dt = t2.operation(1,t)
    t2.diff(t)
    t_after = time.time()
    print("done.")
    print("diff took ", t_after-t_before," s")
    
    print("diff has ", t2.size()," nodes")
    
    # original trees
    print("drawing trees")
    drawTree2(myscreen,t,opacity=1, color=camvtk.green)
    drawTree2(myscreen,t2,opacity=0.2, color=camvtk.cyan)
    drawTree2(myscreen,t2,opacity=1, color=camvtk.cyan, offset=(5,0,0))
        
    # elliptical tube
    pmax = p1 + 1.5* (p2-p1)
    pmin = p1 - 0.5* (p2-p1)
    myscreen.addActor( camvtk.Sphere(center=(pmax.x,pmax.y,pmax.z), radius=0.1, color=camvtk.lgreen) )
    myscreen.addActor( camvtk.Sphere(center=(pmin.x,pmin.y,pmin.z), radius=0.1, color=camvtk.pink) )
    aaxis = pmin + ocl.Point(-0.353553, 0.353553, 0)
    baxis = pmin + ocl.Point(0.0243494, 0.0243494, 0.126617)
    myscreen.addActor( camvtk.Sphere(center=(aaxis.x,aaxis.y,aaxis.z), radius=0.1, color=camvtk.orange) )
    myscreen.addActor( camvtk.Sphere(center=(baxis.x,baxis.y,baxis.z), radius=0.1, color=camvtk.yellow) )
   
    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() 
Esempio n. 4
0
    print(" made ", pf2.dcCalls, " drop-cutter calls")

    #clpoints = pftp.getCLPoints()
    #ccpoints = pftp.getCCPoints()

    clpoints = pf2.getCLPoints()
    ccpoints = pf2.getCCPoints()

    #CLPointGrid(minx,dx,maxx,miny,dy,maxy,z)
    nv = 0
    nn = 0
    ne = 0
    nf = 0
    myscreen.camera.SetPosition(3, 100, 15)
    myscreen.camera.SetFocalPoint(50, 50, 0)
    t = camvtk.Text()
    t.SetPos((myscreen.width - 200, myscreen.height - 30))

    myscreen.addActor(t)

    t2 = camvtk.Text()
    t2.SetPos((myscreen.width - 200, 30))
    myscreen.addActor(t2)
    t3 = camvtk.Text()
    t3.SetPos((30, 30))
    myscreen.addActor(t3)

    t4 = camvtk.Text()
    t4.SetPos((30, myscreen.height - 60))
    myscreen.addActor(t4)
Esempio n. 5
0
def main(ycoord=1.2, filename="test", theta=60, fi=45):
    myscreen = camvtk.VTKScreen()
    focal = cam.Point(2.17, 1, 0)
    r = 14
    theta = (float(theta) / 360) * 2 * math.pi

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

    #ycoord = 1.1

    # the two points that define the edge
    a = cam.Point(3, ycoord, 2.999999)
    b = cam.Point(-1, ycoord, 3)

    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)))
    #c=cam.Point(0,0,0.3)
    myscreen.addActor(camvtk.Line(p1=(a.x, a.y, a.z), p2=(b.x, b.y, b.z)))
    #t = cam.Triangle(a,b,c)

    cutter_length = 2
    cutter = cam.BullCutter(1, 0.2, cutter_length)

    print cutter
    xar = camvtk.Arrow(color=camvtk.red, rotXYZ=(0, 0, 0))
    myscreen.addActor(xar)
    yar = camvtk.Arrow(color=camvtk.green, rotXYZ=(0, 0, 90))
    myscreen.addActor(yar)
    zar = camvtk.Arrow(color=camvtk.blue, rotXYZ=(0, -90, 0))
    myscreen.addActor(zar)

    cl = cam.Point(2.1748, 1, 0)
    radius1 = 1
    radius2 = 0.25

    #tor.SetWireframe()
    #myscreen.addActor(tor)

    cyl = camvtk.Cylinder(center=(cl.x, cl.y, cl.z),
                          radius=radius1,
                          height=2,
                          color=(0, 1, 1),
                          rotXYZ=(90, 0, 0),
                          resolution=50)
    #myscreen.addActor(cyl)

    cl_line = camvtk.Line(p1=(cl.x, cl.y, -100),
                          p2=(cl.x, cl.y, +100),
                          color=camvtk.red)
    myscreen.addActor(cl_line)

    cl_tube = camvtk.Tube(p1=(cl.x, cl.y, -100),
                          p2=(cl.x, cl.y, +100),
                          radius=radius1,
                          color=camvtk.green)
    cl_tube.SetOpacity(0.1)
    myscreen.addActor(cl_tube)

    a_inf = a + (-100 * (b - a))
    b_inf = a + (+100 * (b - a))

    tube = camvtk.Tube(p1=(a_inf.x, a_inf.y, a_inf.z),
                       p2=(b_inf.x, b_inf.y, b_inf.z),
                       radius=0.05 * radius2,
                       color=camvtk.red)
    tube.SetOpacity(0.3)
    myscreen.addActor(tube)

    # cylindrical-cutter circle at z=0 plane
    #cir= camvtk.Circle(radius=radius1, center=(cl.x,cl.y,cl.z), color=camvtk.yellow)
    #myscreen.addActor(cir)

    #clp = camvtk.Point(center=(cl.x,cl.y,cl.z))
    #myscreen.addActor(clp)

    # short axis of ellipse = radius2
    # long axis of ellipse = radius2/sin(theta)
    # where theta is the slope of the line
    dx = b.x - a.x
    dz = b.z - a.z
    #print "dx=", dx
    #print "dz=", dz
    theta = math.atan(dz /
                      dx)  ## dx==0 is special case!! (i.e. vertical lines)
    print "theta=", theta
    a_axis = abs(radius2 / math.sin(theta))
    print "a=", a_axis
    # ellipse
    #a=2
    b_axis = radius2
    print "b= ", b_axis

    # slice the tube with a plane at z=0 and find the ellipse center
    # line is from Point a to b:
    # a + t*(b-a)
    # find t so that z-component is zero:
    # a.z + t( b.z -a.z) = 0
    # t= a.z / (b.z - a.z)
    # so point
    tparam = -a.z / (b.z - a.z)  # NOTE horizontal lines are a special case!!
    ellcenter = a + tparam * (b - a)
    print "ellcenter (z=0?) =", ellcenter
    # center of the
    # ecen_tmp=cam.Point(ellcenter,a.y,0)

    #drawellipse(myscreen, ellcenter, a_axis, b_axis)

    oe = cam.Ellipse(ellcenter, a_axis, b_axis, radius1)

    #oe2 = cam.Ellipse(ellcenter, a_axis, b_axis, 0.05) # to locate text on the outside of the ellipse

    nmax = 20
    #delta=0.05
    #td = 1

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

    t2 = camvtk.Text()
    ytext = "Y: %3.3f" % (ycoord)
    t2.SetText(ytext)
    t2.SetPos((50, myscreen.height - 150))
    myscreen.addActor(t2)

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

    epos = cam.Epos()
    epos.setS(0, 1)

    #p5 = oe.ePoint(epos5)
    #pt = oe2.oePoint(epos5)
    #print "before= ", epos5.s, " , ", epos5.t

    # RUN THE SOLVER!
    nsteps = cam.Ellipse.solver(oe, cl)

    print "solver done. back to python:"
    print "1st (s,t) solution=", oe.epos1
    print "2st (s,t) solution=", oe.epos2

    elc1 = calcEcenter(oe, a, b, cl, 1)
    elc2 = calcEcenter(oe, a, b, cl, 2)
    print "elc1=", elc1
    print "elc2=", elc2
    #exit()

    #elc2 = elc2
    #epos = oe.epos2

    fe1 = cam.Ellipse(elc1, a_axis, b_axis, radius1)
    fe2 = cam.Ellipse(elc2, a_axis, b_axis, radius1)

    # draw ellipse-centers
    myscreen.addActor(
        camvtk.Sphere(center=(elc1.x, elc1.y, elc1.z),
                      radius=0.01,
                      color=camvtk.lgreen))
    myscreen.addActor(
        camvtk.Sphere(center=(elc2.x, elc2.y, elc2.z),
                      radius=0.01,
                      color=camvtk.pink))

    # cc-points on the ellipse
    ccp1 = fe1.ePoint(oe.epos1)
    ccp2 = fe2.ePoint(oe.epos2)
    myscreen.addActor(
        camvtk.Sphere(center=(ccp1.x, ccp1.y, ccp1.z),
                      radius=0.01,
                      color=camvtk.lgreen))
    myscreen.addActor(
        camvtk.Sphere(center=(ccp2.x, ccp2.y, ccp2.z),
                      radius=0.01,
                      color=camvtk.pink))

    cl1 = fe1.oePoint(oe.epos1)
    cl2 = fe2.oePoint(oe.epos2)

    # circles
    myscreen.addActor(
        camvtk.Circle(radius=radius1,
                      center=(cl1.x, cl1.y, cl1.z),
                      color=camvtk.green))
    myscreen.addActor(
        camvtk.Circle(radius=radius1,
                      center=(cl2.x, cl2.y, cl2.z),
                      color=camvtk.pink))

    # torus
    tor = camvtk.Toroid(r1=radius1,
                        r2=radius2,
                        center=(cl1.x, cl1.y, cl1.z),
                        rotXYZ=(0, 0, 0),
                        color=camvtk.green)
    tor.SetOpacity(0.4)
    myscreen.addActor(tor)
    tor = camvtk.Toroid(r1=radius1,
                        r2=radius2,
                        center=(cl2.x, cl2.y, cl2.z),
                        rotXYZ=(0, 0, 0),
                        color=camvtk.pink)
    tor.SetOpacity(0.4)
    myscreen.addActor(tor)

    # line: ellipse-center to cc-point
    myscreen.addActor(
        camvtk.Line(p1=(elc1.x, elc1.y, elc1.z),
                    p2=(ccp1.x, ccp1.y, ccp1.z),
                    color=camvtk.cyan))
    myscreen.addActor(
        camvtk.Line(p1=(elc2.x, elc2.y, elc2.z),
                    p2=(ccp2.x, ccp2.y, ccp2.z),
                    color=camvtk.cyan))

    # line: cc-point to cl-point
    myscreen.addActor(
        camvtk.Line(p1=(cl1.x, cl1.y, cl1.z),
                    p2=(ccp1.x, ccp1.y, ccp1.z),
                    color=camvtk.yellow))
    myscreen.addActor(
        camvtk.Line(p1=(cl2.x, cl2.y, cl2.z),
                    p2=(ccp2.x, ccp2.y, ccp2.z),
                    color=camvtk.yellow))

    # true cl
    #clt = cc1.

    #fclpoint = camvtk.Sphere(center=(fclp.x,fclp.y,fclp.z), radius=0.01, color=camvtk.blue)
    #myscreen.addActor(fclpoint)

    # line from ellipse center to fcc
    # the offset normal
    #myscreen.addActor(camvtk.Line( p1=(fclp.x,fclp.y,fclp.z),p2=(fccp.x,fccp.y,fccp.z), color=camvtk.yellow ))

    drawellipse(myscreen, elc1, a_axis, b_axis)
    drawellipse(myscreen, elc2, a_axis, b_axis)

    #convtext = "%i" % (nsteps)
    #print (pt.x, pt.y, pt.z)
    #center=(pt.x, pt.y, pt.z)
    #tst = camvtk.Text3D( color=(1,1,1), center=(pt.x, pt.y, 0)  ,
    #text=convtext, scale=0.02)
    #tst.SetCamera(myscreen.camera)
    #myscreen.addActor(tst)

    #colmax=11
    #colmin=4
    #nsteps = nsteps - colmin
    #colmax = colmax - colmin
    #convcolor=( float(nsteps*nsteps)/(colmax), float((colmax-nsteps))/colmax, 0 )
    #esphere = camvtk.Sphere(center=(p5.x,p5.y,0), radius=0.01, color=convcolor)
    #cce = oe.ePoint(epos)
    #cle = oe.oePoint(epos)
    #end_sphere = camvtk.Sphere(center=(cce.x,cce.y,0), radius=0.01, color=camvtk.green)
    #cl_sphere = camvtk.Sphere(center=(cle.x,cle.y,0), radius=0.01, color=camvtk.pink)
    #cl_sphere.SetOpacity(0.4)

    #clcir= camvtk.Circle(radius=radius1, center=(cle.x,cle.y,cle.z), color=camvtk.pink)
    #myscreen.addActor(clcir)

    #myscreen.addActor(esphere)
    #myscreen.addActor(end_sphere)
    #myscreen.addActor(cl_sphere)
    #myscreen.render()

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

    #raw_input("Press Enter to terminate")
    time.sleep(0.5)
    #lwr.Write()
    myscreen.iren.Start()
def main(filename="frame/f.png",yc=6, n=0):        
    f=ocl.Ocode()
    f.set_depth(9)
    f.set_scale(5)
    
    myscreen = camvtk.VTKScreen()   
    myscreen.camera.SetPosition(50, 22, 40)
    myscreen.camera.SetFocalPoint(0,0, 0)   
    myscreen.camera.Azimuth( n*0.5 )
    
    # 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)
    
    # screenshot writer
    w2if = vtk.vtkWindowToImageFilter()
    w2if.SetInput(myscreen.renWin)
    lwr = vtk.vtkPNGWriter()
    lwr.SetInput( w2if.GetOutput() )
    arrowcenter=(1,2,0)
    xar = camvtk.Arrow(color=camvtk.red, center=arrowcenter, rotXYZ=(0,0,0))
    myscreen.addActor(xar)
    yar = camvtk.Arrow(color=camvtk.green, center=arrowcenter, rotXYZ=(0,0,90))
    myscreen.addActor(yar)
    zar = camvtk.Arrow(color=camvtk.blue, center=arrowcenter, rotXYZ=(0,-90,0))
    myscreen.addActor(zar) 
    
    """
    dl = myscreen.GetLights()
    print("original default light:")
    print(dl)
    print("nextitem()")
    l1 = dl.GetNextItem()
    print(" light:")
    print(l1)
    #print myscreen.GetLights()
    
    lights = vtk.vtkLightCollection()
    l = myscreen.MakeLight()
    l2 = myscreen.MakeLight()
    #myscreen.RemoveAllLights()
    l.SetAmbientColor(0.5, 0.5, 0.5)
    l.SetPosition(0,0,20)  
    l.SetConeAngle(360)  
    l2.SetPosition(0,0,-20)  
    l2.SetConeAngle(360)
    l2.SetIntensity(0.5) 
    myscreen.AddLight(l)
    myscreen.AddLight(l2)
    #myscreen.SetLightCollection(lights)
    llist = myscreen.GetLights()
    li = llist.GetNextItem()
    print(" new list of lights:")
    print(li)
    #for li in llist:
    #    print(li)
    print(" newly created light:")
    print(l)
    
    dl = myscreen.GetLights()
    print("NEW light:")
    print(dl)
    """
    
    t = ocl.LinOCT()
    t2 = ocl.LinOCT()
    t.init(0)
    t2.init(1)
    
    #drawTree2(myscreen, t, opacity=0.2)
    #myscreen.render()
    #myscreen.iren.Start() 
    #exit()
    
    print(" after init() t :", t.str())
    print(" after init() t2 :", t2.str())
    
    # sphere
    svol = ocl.SphereOCTVolume()
    svol.radius=3.2
    svol.center = ocl.Point(1,0,3)
    svol.calcBB()

    # cube
    cube1 = ocl.CubeOCTVolume()
    cube1.side=2.123
    cube1.center = ocl.Point(0,0,0)
    cube1.calcBB()
    
    #cylinder
    cylvol = ocl.CylinderOCTVolume()
    cylvol.p2 = ocl.Point(3,4,-5)
    cylvol.radius= 2
    cylvol.calcBB()
    
    # draw exact cylinder
    cp = 0.5*(cylvol.p1 + cylvol.p2)
    height = (cylvol.p2-cylvol.p1).norm()
    cylvolactor = camvtk.Cylinder(center=(cp.x, cp.y, cp.z-float(height)/2), radius = cylvol.radius, height=height, rotXYZ=(90,0,0))
    cylvolactor.SetWireframe()
    #myscreen.addActor(cylvolactor)

    
    c = ocl.CylCutter(2)
    c.length = 3
    print("cutter length=", c.length)
    p1 = ocl.Point(-1,-2,0)
    p2 = ocl.Point(1,2.0,0)
    g1vol = ocl.CylMoveOCTVolume(c, p1, p2)
   
    
    cyl1 = camvtk.Cylinder(center=(p1.x,p1.y,p1.z), radius=c.radius,
                            height=c.length,
                            rotXYZ=(90,0,0), color=camvtk.grey)
    cyl1.SetWireframe()
    myscreen.addActor(cyl1) 
    cyl2 = camvtk.Cylinder(center=(p2.x,p2.y,p2.z), radius=c.radius,
                            height=c.length,
                            rotXYZ=(90,0,0), color=camvtk.grey)
    cyl2.SetWireframe()
    myscreen.addActor(cyl2) 
    
    startp = camvtk.Sphere(center=(p1.x,p1.y,p1.z), radius=0.1, color=camvtk.green)
    myscreen.addActor(startp)
    
    endp = camvtk.Sphere(center=(p2.x,p2.y,p2.z), radius=0.1, color=camvtk.red)
    myscreen.addActor(endp)
    
    
       
    t.build( g1vol )
    t2.build( cube1)
    print("calling diff()...",)
    dt = t2.operation(1,t)
    print("done.")
    
    # set Cylinde bounding-box
    """
    cylvol.bb.maxx = 1.23
    cylvol.bb.minx = -0.2
    cylvol.bb.maxy = 1.23
    cylvol.bb.miny = -0.2
    cylvol.bb.maxz = 1.23
    cylvol.bb.minz = -0.2
    """
    drawBB( myscreen, g1vol)
    
    
    #print cylvol.bb.maxx
    
    #print "t2 build()" 
    #t2.build(cube1)
    #print " t2 after build() ", t2.size()
    #t2.condense()
    #print " t2 after condense() ", t2.size()   
    
    # original trees
    drawTree2(myscreen,t,opacity=1, color=camvtk.green)
    drawTree2(myscreen,t2,opacity=1, color=camvtk.cyan)
    drawTree2(myscreen,dt,opacity=1, color=camvtk.cyan, offset=(5,0,0))
    
    """
    for n in range(0,30):
        tp = ocl.Point(2.5,2.5,2-n*0.3)
        tpc = camvtk.black
        if (cylvol.isInside(tp)):
            tpc = camvtk.red
        else:
            tpc = camvtk.cyan
        tp_sphere = camvtk.Sphere(center=(tp.x,tp.y,tp.z), radius=0.1, color= tpc)
        myscreen.addActor(tp_sphere)
    """
    
    #drawTree(myscreen,t2,opacity=1, color=camvtk.red)

    #print " diff12()...",
    #t3 = t2.operation(1,t)
    #print "done."


    #print " diff21()...",
    #t4 = t2.operation(2,t)
    #print "done."


    #print " intersection()...",
    #t5 = t2.operation(3,t)
    #print "done."
    
    #print " sum()...",
    #t6 = t2.operation(4,t)
    #print "done."
    
    #print "  difference 1-2  t3 (blue) =", t3.size()
    #print " difference 2-1  t4 (yellow)=", t4.size()
    #print "     intersection t5 (pink) =", t5.size()
    #print "            union t6 (grey) =", t6.size()

    #drawTree(myscreen,t3,opacity=1, color=camvtk.blue, offset=(0,15,0))
    #drawTree(myscreen,t4,opacity=1, color=camvtk.yellow,offset=(0,-15,0))
    #drawTree(myscreen,t5,opacity=1, color=camvtk.pink,offset=(-15,0,0))
    #drawTree(myscreen,t6,opacity=1, color=camvtk.grey,offset=(-15,-15,0))
    
    
    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)
    
    #st2 = camvtk.Text()
    #ytext = "Linear OCTree set operations: difference, intersection, union"
    #st2.SetText(ytext)
    #st2.SetPos( (50, myscreen.height-30) )   
    #myscreen.addActor( st2)
    
    #st3 = camvtk.Text()
    #text = "Original OCTrees\n  Ball:%d nodes\n  Cube: %d nodes" % ( t.size(), t2.size() )
    #st3.SetText(text)
    #st3.SetPos( (50, 200) )   
    #myscreen.addActor( st3)
    
    #st4 = camvtk.Text()
    #un = " Union (grey): %d nodes\n" % (t6.size())
    #int = " Intersection (pink): %d nodes\n"  % (t5.size())
    #diff1 = " difference Cube-Ball (blue): %d nodes\n"  % (t3.size())
    #diff2 = " difference Ball-Cube (yellow): %d nodes\n"  % (t4.size())
    #text= un+int+diff1+diff2
    #st4.SetText(text)
    #st4.SetPos( (50, 100) )   
    #myscreen.addActor( st4)
    
    print(" render()...",)
    myscreen.render()
    print("done.")
    lwr.SetFileName(filename)
    time.sleep(0.2)
    #lwr.Write()
    
    
    myscreen.iren.Start() 
Esempio n. 7
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()
Esempio n. 8
0
def main():
    myscreen = camvtk.VTKScreen()
    focal = cam.Point(50, 0, 0)
    r = 300
    theta = (float(45)/360)*2*math.pi
    fi=45
    
    campos = cam.Point( r*math.sin(theta)*math.cos(fi), r*math.sin(theta)*math.sin(fi), r*math.cos(theta) ) 
    myscreen.camera.SetPosition(campos.x, campos.y, campos.z)
    myscreen.camera.SetFocalPoint(focal.x,focal.y, focal.z)
    
    t = camvtk.Text()
    t.SetPos( (myscreen.width-450, myscreen.height-30) )

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

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

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

  
    print "done."
    myscreen.render()
    #lwr.SetFileName(filename)
    
    #raw_input("Press Enter to terminate")         
    time.sleep(0.2)
    lwr.Write()
    myscreen.iren.Start()
Esempio n. 9
0
def main(filename="frame/f.png", yc=6, n=0):
    f = ocl.Ocode()
    f.set_depth(10)

    myscreen = camvtk.VTKScreen()
    myscreen.camera.SetPosition(50, 22, 40)
    myscreen.camera.SetFocalPoint(0, 0, 0)
    myscreen.camera.Azimuth(n * 0.5)

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

    # screenshot writer
    w2if = vtk.vtkWindowToImageFilter()
    w2if.SetInput(myscreen.renWin)
    lwr = vtk.vtkPNGWriter()
    lwr.SetInput(w2if.GetOutput())
    arrowcenter = (1, 2, 0)
    xar = camvtk.Arrow(color=camvtk.red, center=arrowcenter, rotXYZ=(0, 0, 0))
    myscreen.addActor(xar)
    yar = camvtk.Arrow(color=camvtk.green,
                       center=arrowcenter,
                       rotXYZ=(0, 0, 90))
    myscreen.addActor(yar)
    zar = camvtk.Arrow(color=camvtk.blue,
                       center=arrowcenter,
                       rotXYZ=(0, -90, 0))
    myscreen.addActor(zar)

    t = ocl.LinOCT()
    #t2 = ocl.LinOCT()
    t.init(3)
    #t2.init(3)

    print " after init() t :", t.str()
    #print " after init() t2 :", t2.str()

    # sphere
    svol = ocl.SphereOCTVolume()
    svol.radius = 3.2
    svol.center = ocl.Point(1, 0, 3)

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

    #cylinder
    cylvol = ocl.CylinderOCTVolume()
    cylvol.p2 = ocl.Point(0, 0, 4)
    cylvol.radius = 4

    c = ocl.CylCutter(1)
    c.length = 3
    print "cutter length=", c.length
    p1 = ocl.Point(0, 0, 0)
    p2 = ocl.Point(1, 1.4, 0)
    g1vol = ocl.CylMoveOCTVolume(c, p1, p2)

    cyl1 = camvtk.Cylinder(center=(p1.x, p1.y, p1.z),
                           radius=c.radius,
                           height=c.length,
                           rotXYZ=(90, 0, 0),
                           color=camvtk.grey)
    cyl1.SetWireframe()
    myscreen.addActor(cyl1)
    cyl2 = camvtk.Cylinder(center=(p2.x, p2.y, p2.z),
                           radius=c.radius,
                           height=c.length,
                           rotXYZ=(90, 0, 0),
                           color=camvtk.grey)
    cyl2.SetWireframe()
    myscreen.addActor(cyl2)

    startp = camvtk.Sphere(center=(p1.x, p1.y, p1.z),
                           radius=0.1,
                           color=camvtk.green)
    myscreen.addActor(startp)

    endp = camvtk.Sphere(center=(p2.x, p2.y, p2.z),
                         radius=0.1,
                         color=camvtk.red)
    myscreen.addActor(endp)

    t.build(g1vol)

    #print "t2 build()"
    #t2.build(cube1)
    #print " t2 after build() ", t2.size()
    #t2.condense()
    #print " t2 after condense() ", t2.size()

    # original trees
    drawTree(myscreen, t, opacity=1, color=camvtk.green)
    #drawTree(myscreen,t2,opacity=1, color=camvtk.red)

    #print " diff12()...",
    #t3 = t2.operation(1,t)
    #print "done."

    #print " diff21()...",
    #t4 = t2.operation(2,t)
    #print "done."

    #print " intersection()...",
    #t5 = t2.operation(3,t)
    #print "done."

    #print " sum()...",
    #t6 = t2.operation(4,t)
    #print "done."

    #print "  difference 1-2  t3 (blue) =", t3.size()
    #print " difference 2-1  t4 (yellow)=", t4.size()
    #print "     intersection t5 (pink) =", t5.size()
    #print "            union t6 (grey) =", t6.size()

    #drawTree(myscreen,t3,opacity=1, color=camvtk.blue, offset=(0,15,0))
    #drawTree(myscreen,t4,opacity=1, color=camvtk.yellow,offset=(0,-15,0))
    #drawTree(myscreen,t5,opacity=1, color=camvtk.pink,offset=(-15,0,0))
    #drawTree(myscreen,t6,opacity=1, color=camvtk.grey,offset=(-15,-15,0))

    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)

    #st2 = camvtk.Text()
    #ytext = "Linear OCTree set operations: difference, intersection, union"
    #st2.SetText(ytext)
    #st2.SetPos( (50, myscreen.height-30) )
    #myscreen.addActor( st2)

    #st3 = camvtk.Text()
    #text = "Original OCTrees\n  Ball:%d nodes\n  Cube: %d nodes" % ( t.size(), t2.size() )
    #st3.SetText(text)
    #st3.SetPos( (50, 200) )
    #myscreen.addActor( st3)

    #st4 = camvtk.Text()
    #un = " Union (grey): %d nodes\n" % (t6.size())
    #int = " Intersection (pink): %d nodes\n"  % (t5.size())
    #diff1 = " difference Cube-Ball (blue): %d nodes\n"  % (t3.size())
    #diff2 = " difference Ball-Cube (yellow): %d nodes\n"  % (t4.size())
    #text= un+int+diff1+diff2
    #st4.SetText(text)
    #st4.SetPos( (50, 100) )
    #myscreen.addActor( st4)

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

    myscreen.iren.Start()
Esempio n. 10
0
def main(ycoord=0.970, filename="test"):
    myscreen = camvtk.VTKScreen()

    myscreen.camera.SetPosition(2, 5, 5)
    myscreen.camera.SetFocalPoint(1.38, 1, 0)

    #ycoord = 1.1

    a = cam.Point(3, ycoord, -2)
    b = cam.Point(-1, ycoord, 3)

    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)))
    #c=cam.Point(0,0,0.3)
    myscreen.addActor(camvtk.Line(p1=(a.x, a.y, a.z), p2=(b.x, b.y, b.z)))
    #t = cam.Triangle(a,b,c)

    cutter = cam.BullCutter(1, 0.2, 20)

    print(cutter)
    xar = camvtk.Arrow(color=camvtk.red, rotXYZ=(0, 0, 0))
    myscreen.addActor(xar)
    yar = camvtk.Arrow(color=camvtk.green, rotXYZ=(0, 0, 90))
    myscreen.addActor(yar)
    zar = camvtk.Arrow(color=camvtk.blue, rotXYZ=(0, -90, 0))
    myscreen.addActor(zar)

    cl = cam.Point(2.1748, 1, 0)
    radius1 = 1
    radius2 = 0.25

    tor = camvtk.Toroid(r1=radius1,
                        r2=radius2,
                        center=(cl.x, cl.y, cl.z),
                        rotXYZ=(0, 0, 0))
    #tor.SetWireframe()
    #myscreen.addActor(tor)

    cyl = camvtk.Cylinder(center=(cl.x, cl.y, cl.z),
                          radius=radius1,
                          height=2,
                          color=(0, 1, 1),
                          rotXYZ=(90, 0, 0),
                          resolution=50)
    #myscreen.addActor(cyl)

    cl_line = camvtk.Line(p1=(cl.x, cl.y, -100),
                          p2=(cl.x, cl.y, +100),
                          color=camvtk.red)
    myscreen.addActor(cl_line)

    tube = camvtk.Tube(p1=(a.x, a.y, a.z), p2=(b.x, b.y, b.z), color=(1, 1, 0))
    tube.SetOpacity(0.2)
    myscreen.addActor(tube)

    # cylindrical-cutter circle at z=0 plane
    #cir= camvtk.Circle(radius=radius1, center=(cl.x,cl.y,cl.z), color=camvtk.yellow)
    #myscreen.addActor(cir)

    #clp = camvtk.Point(center=(cl.x,cl.y,cl.z))
    #myscreen.addActor(clp)

    # short axis of ellipse = radius2
    # long axis of ellipse = radius2/sin(theta)
    # where theta is the slope of the line
    dx = b.x - a.x
    dz = b.z - a.z
    #print "dx=", dx
    #print "dz=", dz
    theta = math.atan(dz /
                      dx)  ## dx==0 is special case!! (i.e. vertical lines)
    print("theta=", theta)
    a_axis = abs(radius2 / math.sin(theta))
    print("a=", a_axis)
    # ellipse
    #a=2
    b_axis = radius2
    print("b= ", b_axis)

    # slice the tube with a plane at z=0 and find the ellipse center
    # line is from Point a to b:
    # a + t*(b-a)
    # find t so that z-component is zero:
    # a.z + t( b.z -a.z) = 0
    # t= a.z / (b.z - a.z)
    # so point
    tparam = -a.z / (b.z - a.z)  # NOTE horizontal lines are a special case!!
    ellcenter = a + tparam * (b - a)
    print("ellcenter (z=0?) =", ellcenter)
    # center of the
    # ecen_tmp=cam.Point(ellcenter,a.y,0)

    #drawellipse(myscreen, ellcenter, a_axis, b_axis)

    oe = cam.Ellipse(ellcenter, a_axis, b_axis, radius1)

    #oe2 = cam.Ellipse(ellcenter, a_axis, b_axis, 0.05) # to locate text on the outside of the ellipse

    nmax = 20
    #delta=0.05
    #td = 1

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

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

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

    epos = cam.Epos()
    epos.setS(0, 1)
    #epos1.setS(0,1)

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

    #p5 = oe.ePoint(epos5)
    #pt = oe2.oePoint(epos5)
    #print "before= ", epos5.s, " , ", epos5.t
    nsteps = cam.Ellipse.solver(oe, cl)
    epos = oe.epos1
    cce = oe.ePoint(epos)
    cle = oe.oePoint(epos)
    #epos2 = cam.Epos()
    #epos.s = epos.s
    #epos.t = epos.t
    #print nsteps
    print("solution1 at: ", epos.s, " , ", epos.t)
    #print "solution2 at: ", epos2.s , " , ", epos2.t
    print(" cl =", cl)
    print(" cle=", cle)

    xoffset = cl.x - cle.x
    print("xoffset= ", xoffset)
    # we slide xoffset along the x-axis from ellcenter
    # to find the correct z-plane
    # line is: a + t*(b-a)
    # find t so that x-component is ellcenter.x + xoffset
    # a.x + t(b.x-a.x) = ellcenter.x + xoffset
    # t= (ellcenter.x + xoffset - a.x) / (b.x - a.x)
    tparam2 = (ellcenter.x + xoffset - a.x) / (b.x - a.x)
    slide = tparam2 * (b - a)
    print("sliding z-delta: ", slide.z)
    elc2 = a + tparam2 * (b - a)
    print("ellcenter2=", elc2)
    #convlist.append(nsteps)
    fe = cam.Ellipse(elc2, a_axis, b_axis, radius1)
    fecen = camvtk.Sphere(center=(elc2.x, elc2.y, elc2.z),
                          radius=0.01,
                          color=camvtk.pink)
    myscreen.addActor(fecen)
    fccp = fe.ePoint(epos)
    fclp = fe.oePoint(epos)
    print("solver cl=", fclp, " == ", cl, " ??")

    fcir = camvtk.Circle(radius=radius1,
                         center=(cl.x, cl.y, elc2.z),
                         color=camvtk.yellow)
    myscreen.addActor(fcir)

    fccpoint = camvtk.Sphere(center=(fccp.x, fccp.y, fccp.z),
                             radius=0.01,
                             color=camvtk.green)
    myscreen.addActor(fccpoint)

    fclpoint = camvtk.Sphere(center=(fclp.x, fclp.y, fclp.z),
                             radius=0.01,
                             color=camvtk.blue)
    myscreen.addActor(fclpoint)

    # line from ellipse center to fcc
    myscreen.addActor(
        camvtk.Line(p1=(elc2.x, elc2.y, elc2.z),
                    p2=(fccp.x, fccp.y, fccp.z),
                    color=camvtk.cyan))
    # the offset normal
    myscreen.addActor(
        camvtk.Line(p1=(fclp.x, fclp.y, fclp.z),
                    p2=(fccp.x, fccp.y, fccp.z),
                    color=camvtk.yellow))

    drawellipse(myscreen, elc2, a_axis, b_axis)
    #convtext = "%i" % (nsteps)
    #print (pt.x, pt.y, pt.z)
    #center=(pt.x, pt.y, pt.z)
    #tst = camvtk.Text3D( color=(1,1,1), center=(pt.x, pt.y, 0)  ,
    #text=convtext, scale=0.02)
    #tst.SetCamera(myscreen.camera)
    #myscreen.addActor(tst)

    colmax = 11
    colmin = 4
    nsteps = nsteps - colmin
    colmax = colmax - colmin
    convcolor = (float(nsteps * nsteps) / (colmax), float(
        (colmax - nsteps)) / colmax, 0)
    #esphere = camvtk.Sphere(center=(p5.x,p5.y,0), radius=0.01, color=convcolor)
    end_sphere = camvtk.Sphere(center=(cce.x, cce.y, 0),
                               radius=0.01,
                               color=camvtk.green)
    cl_sphere = camvtk.Sphere(center=(cle.x, cle.y, 0),
                              radius=0.01,
                              color=camvtk.pink)
    cl_sphere.SetOpacity(0.4)

    clcir = camvtk.Circle(radius=radius1,
                          center=(cle.x, cle.y, cle.z),
                          color=camvtk.pink)
    myscreen.addActor(clcir)

    #myscreen.addActor(esphere)
    myscreen.addActor(end_sphere)
    myscreen.addActor(cl_sphere)
    #myscreen.render()

    print("done.")
    myscreen.render()
    lwr.SetFileName(filename)
    #lwr.Write()
    #raw_input("Press Enter to terminate")
    #time.sleep(0.5)
    myscreen.iren.Start()
def main(filename="frame/f.png", yc=6, n=0):
    print ocl.revision()

    f = ocl.Ocode()
    f.set_depth(7)
    f.set_scale(1)

    myscreen = camvtk.VTKScreen()
    myscreen.camera.SetPosition(50, 22, 40)
    myscreen.camera.SetFocalPoint(0, 0, 0)
    myscreen.camera.Azimuth(n * 0.5)

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

    # screenshot writer
    w2if = vtk.vtkWindowToImageFilter()
    w2if.SetInput(myscreen.renWin)
    lwr = vtk.vtkPNGWriter()
    lwr.SetInput(w2if.GetOutput())
    arrowcenter = (1, 2, 0)
    xar = camvtk.Arrow(color=camvtk.red, center=arrowcenter, rotXYZ=(0, 0, 0))
    myscreen.addActor(xar)
    yar = camvtk.Arrow(color=camvtk.green,
                       center=arrowcenter,
                       rotXYZ=(0, 0, 90))
    myscreen.addActor(yar)
    zar = camvtk.Arrow(color=camvtk.blue,
                       center=arrowcenter,
                       rotXYZ=(0, -90, 0))
    myscreen.addActor(zar)

    t = ocl.LinOCT()
    t2 = ocl.LinOCT()
    t.init(0)
    #exit()
    t2.init(2)

    #drawTree2(myscreen, t, opacity=0.2)
    #myscreen.render()
    #myscreen.iren.Start()
    #exit()

    print " after init() t :", t.str()
    #print " after init() t2 :", t2.str()

    # sphere
    svol = ocl.SphereOCTVolume()
    svol.radius = 1
    svol.center = ocl.Point(0, 0, 1)
    svol.calcBB()

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

    #cylinder
    cylvol = ocl.CylinderOCTVolume()
    cylvol.p2 = ocl.Point(1, 5, -2)
    cylvol.radius = 0.4
    cylvol.calcBB()

    # draw exact cylinder
    cp = 0.5 * (cylvol.p1 + cylvol.p2)
    height = (cylvol.p2 - cylvol.p1).norm()
    cylvolactor = camvtk.Cylinder(center=(cp.x, cp.y,
                                          cp.z - float(height) / 2),
                                  radius=cylvol.radius,
                                  height=height,
                                  rotXYZ=(90, 0, 0))
    cylvolactor.SetWireframe()
    #myscreen.addActor(cylvolactor)

    c = ocl.CylCutter(1)
    c.length = 3
    print "cutter length=", c.length
    p1 = ocl.Point(0.2, 0.2, 0)
    p2 = ocl.Point(1.5, 1.5, -1)
    g1vol = ocl.CylMoveOCTVolume(c, p1, p2)

    cyl1 = camvtk.Cylinder(center=(p1.x, p1.y, p1.z),
                           radius=c.radius,
                           height=c.length,
                           rotXYZ=(90, 0, 0),
                           color=camvtk.grey)
    cyl1.SetWireframe()
    myscreen.addActor(cyl1)
    cyl2 = camvtk.Cylinder(center=(p2.x, p2.y, p2.z),
                           radius=c.radius,
                           height=c.length,
                           rotXYZ=(90, 0, 0),
                           color=camvtk.grey)
    cyl2.SetWireframe()
    myscreen.addActor(cyl2)

    startp = camvtk.Sphere(center=(p1.x, p1.y, p1.z),
                           radius=0.1,
                           color=camvtk.green)
    myscreen.addActor(startp)

    endp = camvtk.Sphere(center=(p2.x, p2.y, p2.z),
                         radius=0.1,
                         color=camvtk.red)
    myscreen.addActor(endp)

    #t.build( g1vol )
    t_before = time.time()
    #t.build( g1vol )
    t.build(svol)
    t_after = time.time()
    print "build took ", t_after - t_before, " s"

    t_before = time.time()
    t2.build(cube1)
    t_after = time.time()
    print "build took ", t_after - t_before, " s"

    #t.sort()
    #t2.sort()

    print "calling diff()...",
    t_before = time.time()
    #dt = t2.operation(1,t)
    t2.diff(t)
    t_after = time.time()
    print "done."
    print "diff took ", t_after - t_before, " s"

    print "diff has ", t2.size(), " nodes"

    #drawBB( myscreen, g1vol)
    #print "drawBB() done"

    # original trees
    print "drawing trees"
    drawTree2(myscreen, t, opacity=1, color=camvtk.green)
    drawTree2(myscreen, t2, opacity=0.2, color=camvtk.cyan)
    drawTree2(myscreen, t2, opacity=1, color=camvtk.cyan, offset=(5, 0, 0))

    # box-volume
    #cor = g1vol.box.corner
    #v1 = g1vol.box.v1 + cor
    #v2 = g1vol.box.v2 + cor
    #v3 = g1vol.box.v3 + cor
    #myscreen.addActor( camvtk.Sphere(center=(cor.x,cor.y,cor.z), radius=0.1, color=camvtk.red) )
    #myscreen.addActor( camvtk.Sphere(center=(v1.x,v1.y,v1.z), radius=0.1, color=camvtk.blue) )
    #myscreen.addActor( camvtk.Sphere(center=(v2.x,v2.y,v2.z), radius=0.1, color=camvtk.cyan) )
    #myscreen.addActor( camvtk.Sphere(center=(v3.x,v3.y,v3.z), radius=0.1, color=camvtk.pink) )

    # elliptical tube
    pmax = p1 + 1.5 * (p2 - p1)
    pmin = p1 - 0.5 * (p2 - p1)
    myscreen.addActor(
        camvtk.Sphere(center=(pmax.x, pmax.y, pmax.z),
                      radius=0.1,
                      color=camvtk.lgreen))
    myscreen.addActor(
        camvtk.Sphere(center=(pmin.x, pmin.y, pmin.z),
                      radius=0.1,
                      color=camvtk.pink))
    aaxis = pmin + ocl.Point(-0.353553, 0.353553, 0)
    baxis = pmin + ocl.Point(0.0243494, 0.0243494, 0.126617)
    myscreen.addActor(
        camvtk.Sphere(center=(aaxis.x, aaxis.y, aaxis.z),
                      radius=0.1,
                      color=camvtk.orange))
    myscreen.addActor(
        camvtk.Sphere(center=(baxis.x, baxis.y, baxis.z),
                      radius=0.1,
                      color=camvtk.yellow))

    ##camvtk.Cylinder(center=(pmin.x,pmin.y,pmin.z), radius=0.1, color=camvtk.pink)
    """
    for n in xrange(0,30):
        tp = ocl.Point(2.5,2.5,2-n*0.3)
        tpc = camvtk.black
        if (cylvol.isInside(tp)):
            tpc = camvtk.red
        else:
            tpc = camvtk.cyan
        tp_sphere = camvtk.Sphere(center=(tp.x,tp.y,tp.z), radius=0.1, color= tpc)
        myscreen.addActor(tp_sphere)
    """

    #drawTree(myscreen,t2,opacity=1, color=camvtk.red)

    #print " diff12()...",
    #t3 = t2.operation(1,t)
    #print "done."

    #print " diff21()...",
    #t4 = t2.operation(2,t)
    #print "done."

    #print " intersection()...",
    #t5 = t2.operation(3,t)
    #print "done."

    #print " sum()...",
    #t6 = t2.operation(4,t)
    #print "done."

    #print "  difference 1-2  t3 (blue) =", t3.size()
    #print " difference 2-1  t4 (yellow)=", t4.size()
    #print "     intersection t5 (pink) =", t5.size()
    #print "            union t6 (grey) =", t6.size()

    #drawTree(myscreen,t3,opacity=1, color=camvtk.blue, offset=(0,15,0))
    #drawTree(myscreen,t4,opacity=1, color=camvtk.yellow,offset=(0,-15,0))
    #drawTree(myscreen,t5,opacity=1, color=camvtk.pink,offset=(-15,0,0))
    #drawTree(myscreen,t6,opacity=1, color=camvtk.grey,offset=(-15,-15,0))

    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)

    #st2 = camvtk.Text()
    #ytext = "Linear OCTree set operations: difference, intersection, union"
    #st2.SetText(ytext)
    #st2.SetPos( (50, myscreen.height-30) )
    #myscreen.addActor( st2)

    #st3 = camvtk.Text()
    #text = "Original OCTrees\n  Ball:%d nodes\n  Cube: %d nodes" % ( t.size(), t2.size() )
    #st3.SetText(text)
    #st3.SetPos( (50, 200) )
    #myscreen.addActor( st3)

    #st4 = camvtk.Text()
    #un = " Union (grey): %d nodes\n" % (t6.size())
    #int = " Intersection (pink): %d nodes\n"  % (t5.size())
    #diff1 = " difference Cube-Ball (blue): %d nodes\n"  % (t3.size())
    #diff2 = " difference Ball-Cube (yellow): %d nodes\n"  % (t4.size())
    #text= un+int+diff1+diff2
    #st4.SetText(text)
    #st4.SetPos( (50, 100) )
    #myscreen.addActor( st4)

    print " render()...",
    myscreen.render()
    print "done."
    lwr.SetFileName(filename)
    time.sleep(0.2)
    #lwr.Write()

    myscreen.iren.Start()
Esempio n. 12
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()
Esempio n. 13
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()
Esempio n. 14
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()
Esempio n. 15
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() 
Esempio n. 16
0
def main(filename="frame/f.png", yc=6, n=0):
    f = ocl.Ocode()
    f.set_depth(8)

    myscreen = camvtk.VTKScreen()
    myscreen.camera.SetPosition(50, 22, 40)
    myscreen.camera.SetFocalPoint(0, 0, 0)
    myscreen.camera.Azimuth(n * 0.5)

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

    xar = camvtk.Arrow(color=camvtk.red, center=(10, 20, 0), rotXYZ=(0, 0, 0))
    myscreen.addActor(xar)
    yar = camvtk.Arrow(color=camvtk.green,
                       center=(10, 20, 0),
                       rotXYZ=(0, 0, 90))
    myscreen.addActor(yar)
    zar = camvtk.Arrow(color=camvtk.blue,
                       center=(10, 20, 0),
                       rotXYZ=(0, -90, 0))
    myscreen.addActor(zar)

    t = ocl.LinOCT()
    t2 = ocl.LinOCT()
    t.init(3)
    t2.init(3)

    print " after init() t :", t.str()
    print " after init() t2 :", t2.str()

    svol = ocl.SphereOCTVolume()
    svol.radius = 3
    svol.center = ocl.Point(1, 0, 3)

    cube1 = ocl.CubeOCTVolume()
    cube1.side = 6
    cube1.center = ocl.Point(0, 0, 0)

    cube2 = ocl.CubeOCTVolume()
    cube2.center = ocl.Point(1, 2, 0)
    cube2.side = 30

    print "t build()"
    t.build(svol)
    print " t after build() ", t.size()
    t.condense()
    print " t after condense() ", t.size()

    print "t2 build()"
    t2.build(cube1)
    print " t2 after build() ", t2.size()
    t2.condense()
    print " t2 after condense() ", t2.size()

    # original trees
    drawTree(myscreen, t, opacity=1, color=camvtk.green)
    drawTree(myscreen, t2, opacity=1, color=camvtk.red)

    print " diff12()...",
    t3 = t2.operation(1, t)
    print "done."

    print " diff21()...",
    t4 = t2.operation(2, t)
    print "done."

    print " intersection()...",
    t5 = t2.operation(3, t)
    print "done."

    print " sum()...",
    t6 = t2.operation(4, t)
    print "done."

    print "  difference 1-2  t3 (blue) =", t3.size()
    print " difference 2-1  t4 (yellow)=", t4.size()
    print "     intersection t5 (pink) =", t5.size()
    print "            union t6 (grey) =", t6.size()

    drawTree(myscreen, t3, opacity=1, color=camvtk.blue, offset=(0, 15, 0))
    drawTree(myscreen, t4, opacity=1, color=camvtk.yellow, offset=(0, -15, 0))
    drawTree(myscreen, t5, opacity=1, color=camvtk.pink, offset=(-15, 0, 0))
    drawTree(myscreen, t6, opacity=1, color=camvtk.grey, offset=(-15, -15, 0))

    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)

    st2 = camvtk.Text()
    ytext = "Linear OCTree set operations: difference, intersection, union"
    st2.SetText(ytext)
    st2.SetPos((50, myscreen.height - 30))
    myscreen.addActor(st2)

    st3 = camvtk.Text()
    text = "Original OCTrees\n  Ball:%d nodes\n  Cube: %d nodes" % (t.size(),
                                                                    t2.size())
    st3.SetText(text)
    st3.SetPos((50, 200))
    myscreen.addActor(st3)

    st4 = camvtk.Text()
    un = " Union (grey): %d nodes\n" % (t6.size())
    int = " Intersection (pink): %d nodes\n" % (t5.size())
    diff1 = " difference Cube-Ball (blue): %d nodes\n" % (t3.size())
    diff2 = " difference Ball-Cube (yellow): %d nodes\n" % (t4.size())
    text = un + int + diff1 + diff2
    st4.SetText(text)
    st4.SetPos((50, 100))
    myscreen.addActor(st4)

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

    myscreen.iren.Start()
Esempio n. 17
0
def main():
    myscreen = camvtk.VTKScreen()
    focal = cam.Point(5, 5, 0)
    r = 30
    theta = (float(45) / 360) * 2 * math.pi
    fi = 45

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

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

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

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

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

    #ycoord = 1.1

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

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

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

    tlist = s.get_kd_triangles()

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

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

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

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

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

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

    #raw_input("Press Enter to terminate")
    time.sleep(0.2)
    #lwr.Write()
    myscreen.iren.Start()
Esempio n. 18
0
        
    print "none=",nn," vertex=",nv, " edge=",ne, " facet=",nf, " sum=", nn+nv+ne+nf
    print len(clpoints), " cl points evaluated"
    myscreen.camera.SetPosition(3, 23, 15)
    myscreen.camera.SetFocalPoint(5, 5, 0)
    myscreen.render()
    
    w2if = vtk.vtkWindowToImageFilter()
    w2if.SetInput(myscreen.renWin)
    lwr = vtk.vtkPNGWriter()
    lwr.SetInput( w2if.GetOutput() )
    w2if.Modified()
    lwr.SetFileName("tux1.png")
    #lwr.Write()
    
    t = camvtk.Text()
    t.SetPos( (myscreen.width-200, myscreen.height-30) )
    myscreen.addActor( t)
     
    for n in range(1,36):
        t.SetText(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
        myscreen.camera.Azimuth( 1 )
        time.sleep(0.01)
        myscreen.render()
        lwr.SetFileName("kd_frame"+ ('%03d' % n)+".png")
        w2if.Modified() 
        #lwr.Write()

        

Esempio n. 19
0
def main():
    print ocl.revision()
    myscreen = camvtk.VTKScreen()
    myscreen.camera.SetPosition(-8, -4, 25)
    myscreen.camera.SetFocalPoint(4.5, 6, 0)
    # axis arrows
    camvtk.drawArrows(myscreen, center=(-1, -1, 0))
    camvtk.drawOCLtext(myscreen)

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

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

    stl = camvtk.STLSurf("../../stl/gnu_tux_mod.stl")
    #myscreen.addActor(stl)
    #stl.SetWireframe()
    stl.SetColor((0.5, 0.5, 0.5))

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

    #angle = math.pi/4
    radius = 0.4
    length = 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()
Esempio n. 20
0
    tree = buildOCTree(testvol)
    print "done."
    print tree
    
    list =[]
    searchOCTree(tree, list)
    print len(list), " nodes in tree"
    
    w2if = vtk.vtkWindowToImageFilter()
    w2if.SetInput(myscreen.renWin)
    lwr = vtk.vtkPNGWriter()
    lwr.SetInput( w2if.GetOutput() )
    w2if.Modified()

    
    t = camvtk.Text()
    t.SetPos( (myscreen.width-200, myscreen.height-30) )
    myscreen.addActor( t)
    
    t2 = camvtk.Text()
    t2.SetPos( (myscreen.width-200, 30) )
    myscreen.addActor( t2)
    
    n = 0
    for node in list:
        addNodes(myscreen, node)
        if (n%50) == 0:
            nodetext = "Nodes: %5i" % (n)
            t2.SetText(nodetext)
            t.SetText("OpenCAMLib 10.03-beta " + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
            myscreen.render()
Esempio n. 21
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()