def DrawLoops(myscreen, loops): # draw the loops nloop = 0 for lop in loops: n = 0 N = len(lop) first_point = ocl.Point(-1, -1, 5) previous = ocl.Point(-1, -1, 5) for p in lop: if n == 0: # don't draw anything on the first iteration previous = p first_point = p elif n == (N - 1): # the last point myscreen.addActor( camvtk.Line(p1=(previous.x, previous.y, previous.z), p2=(p.x, p.y, p.z), color=camvtk.yellow)) # the normal line # and a line from p to the first point myscreen.addActor( camvtk.Line(p1=(p.x, p.y, p.z), p2=(first_point.x, first_point.y, first_point.z), color=camvtk.yellow)) else: myscreen.addActor( camvtk.Line(p1=(previous.x, previous.y, previous.z), p2=(p.x, p.y, p.z), color=camvtk.yellow)) previous = p n = n + 1 print("rendered loop ", nloop, " with ", len(lop), " points") nloop = nloop + 1
def drawcuts(myscreen, s): cut = s.get_kd_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 ) ) if (s.jump_kd_hi()): drawcuts(myscreen, s) s.jump_kd_up() if (s.jump_kd_lo()): drawcuts(myscreen, s) s.jump_kd_up() return
def drawLoops(myscreen, loops, loopColor=camvtk.yellow): nloop=0 zofz = 0.00 for lop in loops: n = 0 N = len(lop) first_point=ocl.Point(-1,-1,5) previous=ocl.Point(-1,-1,5) for p in lop: if n==0: # don't draw anything on the first iteration previous=p first_point = p elif n== (N-1): # the last point myscreen.addActor( camvtk.Line(p1=(previous.x,previous.y,previous.z+zofz),p2=(p.x,p.y,p.z+zofz),color=loopColor) ) # the normal line # and a line from p to the first point myscreen.addActor( camvtk.Line(p1=(p.x,p.y,p.z+zofz),p2=(first_point.x,first_point.y,first_point.z+zofz),color=loopColor) ) else: myscreen.addActor( camvtk.Line(p1=(previous.x,previous.y,previous.z+zofz),p2=(p.x,p.y,p.z+zofz),color=loopColor) ) previous=p n=n+1 zofz = zofz +0.00 print "rendered loop ",nloop, " with ", len(lop), " points at zofz=",zofz if len(lop)==2: for p in lop: print p myscreen.addActor( camvtk.Sphere(center=(p.x,p.y,p.z+zofz),radius=0.0005, color=camvtk.pink ) ) nloop = nloop+1
def drawFiber(myscreen, f, fibercolor=camvtk.red): inter = f.getInts() for i in inter: if not i.empty(): ip1 = f.point(i.lower) ip2 = f.point(i.upper) myscreen.addActor( camvtk.Line(p1=(ip1.x, ip1.y, ip1.z), p2=(ip2.x, ip2.y, ip2.z), color=fibercolor)) myscreen.addActor( camvtk.Sphere(center=(ip1.x, ip1.y, ip1.z), radius=0.005, color=camvtk.clColor(i.lower_cc))) myscreen.addActor( camvtk.Sphere(center=(ip2.x, ip2.y, ip2.z), radius=0.005, color=camvtk.clColor(i.upper_cc))) cc1 = i.lower_cc cc2 = i.upper_cc myscreen.addActor( camvtk.Sphere(center=(cc1.x, cc1.y, cc1.z), radius=0.005, color=camvtk.lgreen)) myscreen.addActor( camvtk.Sphere(center=(cc2.x, cc2.y, cc2.z), radius=0.005, color=camvtk.lgreen))
def drawEdge(myscreen, e, edgeColor=camvtk.yellow): p1 = e[0] p2 = e[1] myscreen.addActor( camvtk.Line(p1=(p1.x, p1.y, p1.z), p2=(p2.x, p2.y, p2.z), color=edgeColor))
def drawTour(myscreen, pts, tour, tourColor = camvtk.red): for n in range(0,len(tour)-1): idx0 = n idx1 = n+1 ip1 = pts[ tour[idx0] ] ip2 = pts[ tour[idx1] ] myscreen.addActor( camvtk.Line(p1=(ip1.x,ip1.y,ip1.z),p2=(ip2.x,ip2.y,ip2.z), color=tourColor) )
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)))
def drawFiber(myscreen, f): #myscreen.addActor( camvtk.Line(p1=(f.p1.x,f.p1.y,f.p1.z),p2=(f.p2.x,f.p2.y,f.p2.z), color=camvtk.orange) ) #myscreen.addActor( camvtk.Sphere(center=(f.p1.x,f.p1.y,f.p1.z),radius=0.05, color=camvtk.lgreen) ) #myscreen.addActor( camvtk.Sphere(center=(f.p2.x,f.p2.y,f.p2.z),radius=0.05, color=camvtk.pink) ) inter = f.getInts() for i in inter: ip1 = f.point( i.lower ) ip2 = f.point( i.upper ) myscreen.addActor( camvtk.Line(p1=(ip1.x,ip1.y,ip1.z),p2=(ip2.x,ip2.y,ip2.z), color=camvtk.red) )
def drawLoop(myscreen, w_loop): # draw the loop as a yellow line previous = 0 for loop in w_loop: np = 0 for p in loop: if np is not 0: myscreen.addActor( camvtk.Line( p1=(previous.x,previous.y, previous.z), p2=(p.x,p.y,p.z), color=camvtk.yellow) ) np=np+1 previous = p
def drawFiber(myscreen, f, fibercolor): inter = f.getInts() print "fiber has ", len(inter) , " intervals" for i in inter: if not i.empty(): ip1 = f.point( i.lower ) ip2 = f.point( i.upper ) myscreen.addActor( camvtk.Line(p1=(ip1.x,ip1.y,ip1.z),p2=(ip2.x,ip2.y,ip2.z), color=fibercolor) ) myscreen.addActor( camvtk.Sphere(center=(ip1.x,ip1.y,ip1.z),radius=0.005, color=camvtk.clColor( i.lower_cc) ) ) myscreen.addActor( camvtk.Sphere(center=(ip2.x,ip2.y,ip2.z),radius=0.005, color=camvtk.clColor( i.upper_cc) ) )
def setEdges(self, vd): for e in self.edges: myscreen.removeActor(e) self.edges = [] for e in vd.getEdgesGenerators(): p1 = self.scale*e[0] p2 = self.scale*e[1] actor = camvtk.Line( p1=( p1.x,p1.y,p1.z), p2=(p2.x,p2.y,p2.z), color=self.edgeColor ) myscreen.addActor(actor) self.edges.append(actor) myscreen.render()
def drawellipse(myscreen, ellcenter, a_axis, b_axis): resolution=50 for n in xrange(0,resolution): angle1= (float(n)/float(resolution))*2*math.pi angle2= (float(n+1)/float(resolution))*2*math.pi x=ellcenter.x + a_axis*math.cos(angle1) y=ellcenter.y + b_axis*math.sin(angle1) z=ellcenter.z x2=ellcenter.x + a_axis*math.cos(angle2) y2=ellcenter.y + b_axis*math.sin(angle2) myscreen.addActor( camvtk.Line(p1=(x,y,z),p2=(x2,y2,z), color=camvtk.grey) )
def drawFibers(myscreen, fibs, fibcolor): for f in fibs: #print f for i in f.getInts(): #print i p1 = f.point(i.lower) p2 = f.point(i.upper) #print p1 #print p2 myscreen.addActor( camvtk.Line(p1=(p1.x, p1.y, p1.z), p2=(p2.x, p2.y, p2.z), color=fibcolor))
def setDT(self,vd): for e in self.DTedges: myscreen.removeActor(e) self.DTedges = [] #gc.collect() #print "dt-edges: ",vd.getDelaunayEdges() for e in vd.getDelaunayEdges(): p1 = e[0] p2 = e[1] actor = camvtk.Line( p1=( p1.x,p1.y,p1.z), p2=(p2.x,p2.y,p2.z), color=camvtk.red ) myscreen.addActor(actor) self.DTedges.append(actor) myscreen.render()
def setEdges(self, vd): for e in self.edges: myscreen.removeActor(e) #e.Delete() self.edges = [] #gc.collect() for e in vd.getEdgesGenerators(): ofset = 0 p1 = e[0] p2 = e[1] actor = camvtk.Line( p1=( p1.x,p1.y,p1.z), p2=(p2.x,p2.y,p2.z), color=self.edgeColor ) myscreen.addActor(actor) self.edges.append(actor) myscreen.render()
def setEdges(self, vd): for e in self.edges: myscreen.removeActor(e) #e.Delete() self.edges = [] for e in vd.getEdgesGenerators(): ofset = 0 p1 = e[0] p2 = e[1] actor = camvtk.Line( p1=( p1.x,p1.y,p1.z), p2=(p2.x,p2.y,p2.z), color=self.edgeColor ) myscreen.addActor(actor) self.edges.append(actor) #actor1 = camvtk.Sphere( center=(p1.x,p1.y,p1.z), radius=2, color=camvtk.pink ) #actor2 = camvtk.Sphere( center=(p2.x,p2.y,p2.z), radius=2, color=camvtk.lgreen ) #myscreen.addActor(actor1) #self.edges.append(actor1) #myscreen.addActor(actor2) #self.edges.append(actor2) myscreen.render()
import camvtk import time import vtk import datetime import math if __name__ == "__main__": 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,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) print t zcut=0.1 print "zslice at z=",zcut t2 = t.zslice(zcut) for tri in t2: print tri pts = tri.getPoints() myscreen.addActor( camvtk.Line(p1=(pts[0].x,pts[0].y,pts[0].z),p2=(pts[2].x,pts[2].y,pts[2].z)) ) myscreen.addActor( camvtk.Line(p1=(pts[2].x,pts[2].y,pts[2].z),p2=(pts[1].x,pts[1].y,pts[1].z)) ) myscreen.addActor( camvtk.Line(p1=(pts[0].x,pts[0].y,pts[0].z),p2=(pts[1].x,pts[1].y,pts[1].z)) ) for p in pts:
if len(lop)==2: for p in lop: print p myscreen.addActor( camvtk.Sphere(center=(p.x,p.y,p.z+zofz),radius=0.0005, color=camvtk.pink ) ) nloop = nloop+1 if __name__ == "__main__": 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=10 zmin=-0.5 zmax= 0.30 dz = (zmax-zmin)/float(Nmax-1) z = zmin
print "All waterlines done. Got", len(loops), " loops in total." # draw the loops for lop in loops: n = 0 N = len(lop) first_point = ocl.Point(-1, -1, 5) previous = ocl.Point(-1, -1, 5) for p in lop: if n == 0: # don't draw anything on the first iteration previous = p first_point = p elif n == (N - 1): # the last point myscreen.addActor( camvtk.Line(p1=(previous.x, previous.y, previous.z), p2=(p.x, p.y, p.z), color=camvtk.yellow)) # the normal line # and a line from p to the first point myscreen.addActor( camvtk.Line(p1=(p.x, p.y, p.z), p2=(first_point.x, first_point.y, first_point.z), color=camvtk.yellow)) else: myscreen.addActor( camvtk.Line(p1=(previous.x, previous.y, previous.z), p2=(p.x, p.y, p.z), color=camvtk.yellow)) previous = p n = n + 1
print(" got: ", len(w_loop), " loops") # draw the loops nloop = 0 for lop in w_loop: n = 0 N = len(lop) first_point=ocl.Point(-1,-1,5) previous=ocl.Point(-1,-1,5) for p in lop: if n==0: # don't draw anything on the first iteration previous=p first_point = p elif n== (N-1): # the last point myscreen.addActor( camvtk.Line(p1=(previous.x,previous.y,previous.z),p2=(p.x,p.y,p.z),color=camvtk.yellow) ) # the normal line # and a line from p to the first point myscreen.addActor( camvtk.Line(p1=(p.x,p.y,p.z),p2=(first_point.x,first_point.y,first_point.z),color=camvtk.yellow) ) else: myscreen.addActor( camvtk.Line(p1=(previous.x,previous.y,previous.z),p2=(p.x,p.y,p.z),color=camvtk.yellow) ) previous=p n=n+1 print("rendered loop ",nloop, " with ", len(lop), " points") nloop = nloop+1 # draw edges of weave ne = 0 zoffset=0.0 # 1 dzoffset = 0.000 # 5 for e in w_edges:
drawVertices(myscreen, w, ocl.WeaveVertexType.FULLINT, vertexRadius, camvtk.yellow) drawVertices(myscreen, w, ocl.WeaveVertexType.ADJ, vertexRadius, camvtk.green) drawVertices(myscreen, w, ocl.WeaveVertexType.TWOADJ, vertexRadius, camvtk.lblue) print " got: ", len(w_edges), " edges" print " got: ", len(w_loop), " loop points" previous = 0 # draw the loop as a yellow line for loop in w_loop: np = 0 for p in loop: #myscreen.addActor( camvtk.Sphere(center=(p.x,p.y,p.z+zoffset2), radius=0.006, color=camvtk.pink ) ) if np is not 0: myscreen.addActor( camvtk.Line( p1=(previous.x,previous.y, previous.z), p2=(p.x,p.y,p.z), color=camvtk.yellow) ) np=np+1 previous = p # draw edges of weave ne = 0 zoffset=0.0 # 1 dzoffset = 0.000 # 5 for e in w_edges: p1 = e[0] p2 = e[1] myscreen.addActor( camvtk.Line( p1=( p1.x,p1.y,p1.z+zoffset+ne*dzoffset), p2=(p2.x,p2.y,p2.z+zoffset+ne*dzoffset) ) ) ne = ne+1 print "done." myscreen.camera.SetPosition(0.8051, 0.8051, 3.5)
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()
def drawNode(myscreen, node): if node.type == cam.OCType.BLACK: return # don't draw intermediate nodes if node.type == cam.OCType.GREY: return # don't draw intermediate nodes p = [] for n in xrange(1, 9): p1 = node.nodePoint(n) p.append(p1) lines = [] lines.append( camvtk.Line(p1=(p[0].x, p[0].y, p[0].z), p2=(p[1].x, p[1].y, p[1].z))) lines.append( camvtk.Line(p1=(p[0].x, p[0].y, p[0].z), p2=(p[2].x, p[2].y, p[2].z))) lines.append( camvtk.Line(p1=(p[0].x, p[0].y, p[0].z), p2=(p[3].x, p[3].y, p[3].z))) lines.append( camvtk.Line(p1=(p[2].x, p[2].y, p[2].z), p2=(p[4].x, p[4].y, p[4].z))) lines.append( camvtk.Line(p1=(p[1].x, p[1].y, p[1].z), p2=(p[5].x, p[5].y, p[5].z))) lines.append( camvtk.Line(p1=(p[1].x, p[1].y, p[1].z), p2=(p[6].x, p[6].y, p[6].z))) lines.append( camvtk.Line(p1=(p[2].x, p[2].y, p[2].z), p2=(p[6].x, p[6].y, p[6].z))) lines.append( camvtk.Line(p1=(p[6].x, p[6].y, p[6].z), p2=(p[7].x, p[7].y, p[7].z))) lines.append( camvtk.Line(p1=(p[4].x, p[4].y, p[4].z), p2=(p[7].x, p[7].y, p[7].z))) lines.append( camvtk.Line(p1=(p[4].x, p[4].y, p[4].z), p2=(p[3].x, p[3].y, p[3].z))) lines.append( camvtk.Line(p1=(p[5].x, p[5].y, p[5].z), p2=(p[3].x, p[3].y, p[3].z))) lines.append( camvtk.Line(p1=(p[5].x, p[5].y, p[5].z), p2=(p[7].x, p[7].y, p[7].z))) if node.type == cam.OCType.WHITE: color = nodeColor(node) if node.type == cam.OCType.GREY: color = camvtk.white if node.type == cam.OCType.BLACK: color = camvtk.grey for li in lines: li.SetColor(color) if node.type == cam.OCType.BLACK: li.SetOpacity(0.1) if node.type == cam.OCType.GREY: li.SetOpacity(0.2) myscreen.addActor(li)
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()
writeFrame(w2if, lwr, nf) nf = nf + 1 #""" #DELETE-EDGES #""" delEdges = vd.getDeleteEdges(p) modEdges = vd.getModEdges(p) #print " seed vertex is ",sv edge_actors = [] if n in ren: for e in delEdges: p1 = scale * e[0] p2 = scale * e[1] e_actor = camvtk.Line(p1=(p1.x, p1.y, p1.z), p2=(p2.x, p2.y, p2.z), color=camvtk.red) edge_actors.append(e_actor) for e in modEdges: p1 = scale * e[0] p2 = scale * e[1] e_actor = camvtk.Line(p1=(p1.x, p1.y, p1.z), p2=(p2.x, p2.y, p2.z), color=camvtk.green) edge_actors.append(e_actor) for a in edge_actors: myscreen.addActor(a) myscreen.render() time.sleep(delay) writeFrame(w2if, lwr, nf) nf = nf + 1
def kdtreesearch(myscreen, tlist, s, cutter, cl, depth): #print "surface=", s.str() #print "cutter=", cutter.str() #print "cl=", cl.str() myscreen.render() #raw_input("Press Enter to terminate") #time.sleep(1) if (depth==1): # stop jumping and return all triangles tris = s.get_kd_triangles() for t in tris: tlist.append(t) return # jump high or low depending on search cut = s.get_kd_cut() print "cutvalues: ", cut dim = cut[0] cval = cut[1] if dim == 0: # cut along xmax print cval, " < ", cl.x - cutter.radius, " ??" if ( cval < ( cl.x - cutter.radius) ): myscreen.addActor( camvtk.Line( p1=(cval,100,0), p2=(cval,-100,0), color = camvtk.green ) ) s.jump_kd_lo() trilist = s.get_kd_triangles() drawtriangles(myscreen, trilist, camvtk.blue) s.jump_kd_up() print "xmax: jump ONLY hi" s.jump_kd_hi() print "search hi at level=", s.get_kd_level() kdtreesearch(myscreen, tlist, s, cutter, cl, depth-1) print "len tlist=", len(tlist), " now level=", s.get_kd_level() else: #print "xmax: jump both hi and lo" s.jump_kd_hi() #print "search hi at level=", s.get_kd_level() kdtreesearch(myscreen, tlist, s, cutter, cl, depth-1) #print "len tlist=", len(tlist), " now level=", s.get_kd_level() s.jump_kd_up() s.jump_kd_lo() #print "search lo at level=", s.get_kd_level() kdtreesearch(myscreen, tlist, s, cutter, cl, depth-1) #print "len tlist=", len(tlist), " now level=", s.get_kd_level() if dim == 1: print cval, " > ", cl.x + cutter.radius, " ??" if ( cval > ( cl.x + cutter.radius) ): myscreen.addActor( camvtk.Line( p1=(cval,100,0), p2=(cval,-100,0), color = camvtk.lgreen ) ) s.jump_kd_hi() trilist = s.get_kd_triangles() drawtriangles(myscreen, trilist, camvtk.blue) s.jump_kd_up() print "xmin: jump only lo" s.jump_kd_lo() kdtreesearch(myscreen, tlist, s, cutter, cl, depth-1) else: #print "xmin: jump both hi and lo" s.jump_kd_lo() kdtreesearch(tlist, s, cutter, cl, depth-1) s.jump_kd_up() s.jump_kd_hi() kdtreesearch(myscreen, tlist, s, cutter, cl, depth-1) if dim == 2: print cval, " < ", cl.y - cutter.radius, " ??" if ( cval < ( cl.y - cutter.radius) ): myscreen.addActor( camvtk.Line( p1=(100,cval,0), p2=(-100,cval,0), color = camvtk.red ) ) s.jump_kd_lo() trilist = s.get_kd_triangles() drawtriangles(myscreen, trilist, camvtk.yellow) s.jump_kd_up() s.jump_kd_hi() kdtreesearch(myscreen, tlist, s, cutter, cl, depth-1) else: #print "ymax: jump both hi and lo" s.jump_kd_lo() kdtreesearch(myscreen, tlist, s, cutter, cl, depth-1) s.jump_kd_up() s.jump_kd_hi() kdtreesearch(myscreen, tlist, s, cutter, cl, depth-1) if dim == 3: # cut along ymin print cval, " > ", cl.y + cutter.radius, " ??" if ( cval > ( cl.y + cutter.radius) ): myscreen.addActor( camvtk.Line( p1=(100,cval,0), p2=(-100,cval,0), color = camvtk.pink ) ) s.jump_kd_hi() trilist = s.get_kd_triangles() drawtriangles(myscreen, trilist, camvtk.yellow) s.jump_kd_up() print "ymin: jump ONLY lo" s.jump_kd_lo() kdtreesearch(myscreen, tlist, s, cutter, cl, depth-1) else: #print "ymin: jump both hi and lo" s.jump_kd_hi() #print "search hi at level=", s.get_kd_level() kdtreesearch(myscreen, tlist, s, cutter, cl, depth-1) #print "len tlist=", len(tlist), " now level=", s.get_kd_level() s.jump_kd_up() s.jump_kd_lo() #print "search lo at level=", s.get_kd_level() kdtreesearch(myscreen, tlist, s, cutter, cl, depth-1) return
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()
cutactor = camvtk.Cylinder(center=(cl.x, cl.y, cl.z), radius=cutterDiameter / 2, height=2, color=(0.7, 1, 1)) myscreen.addActor(cutactor) #myscreen.addActor( camvtk.Point(center=(cl.x,cl.y,cl.z) , color=col) ) if n == 0: precl = cl else: d = cl - precl if (d.norm() < 9): myscreen.addActor( camvtk.Line(p1=(precl.x, precl.y, precl.z), p2=(cl.x, cl.y, cl.z), color=(0, 1, 1))) precl = cl n = n + 1 #myscreen.addActor( camvtk.Point(center=(cl2.x,cl2.y,cl2.z+0.2) , color=(0.6,0.2,0.9)) ) #myscreen.addActor( camvtk.Point(center=(cc.x,cc.y,cc.z), color=col) ) #print cc.type myscreen.camera.Azimuth(0.2) #time.sleep(0.01) myscreen.render() w2if.Modified() lwr.SetFileName("kdmov" + ('%05d' % n) + ".png") #lwr.Write() #raw_input("Press Enter to continue") myscreen.removeActor(stl2)
def addNodes(myscreen, oct): if oct.type == 1: return # don't draw intermediate nodes p = [] for n in xrange(1,9): p1 = oct.nodePoint(n) p.append(p1) lines = [] lines.append ( camvtk.Line(p1=(p[0].x,p[0].y,p[0].z),p2=(p[1].x,p[1].y,p[1].z)) ) lines.append ( camvtk.Line(p1=(p[0].x,p[0].y,p[0].z),p2=(p[2].x,p[2].y,p[2].z)) ) lines.append ( camvtk.Line(p1=(p[0].x,p[0].y,p[0].z),p2=(p[3].x,p[3].y,p[3].z)) ) lines.append ( camvtk.Line(p1=(p[2].x,p[2].y,p[2].z),p2=(p[4].x,p[4].y,p[4].z)) ) lines.append ( camvtk.Line(p1=(p[1].x,p[1].y,p[1].z),p2=(p[5].x,p[5].y,p[5].z)) ) lines.append ( camvtk.Line(p1=(p[1].x,p[1].y,p[1].z),p2=(p[6].x,p[6].y,p[6].z)) ) lines.append ( camvtk.Line(p1=(p[2].x,p[2].y,p[2].z),p2=(p[6].x,p[6].y,p[6].z)) ) lines.append ( camvtk.Line(p1=(p[6].x,p[6].y,p[6].z),p2=(p[7].x,p[7].y,p[7].z)) ) lines.append ( camvtk.Line(p1=(p[4].x,p[4].y,p[4].z),p2=(p[7].x,p[7].y,p[7].z)) ) lines.append ( camvtk.Line(p1=(p[4].x,p[4].y,p[4].z),p2=(p[3].x,p[3].y,p[3].z)) ) lines.append ( camvtk.Line(p1=(p[5].x,p[5].y,p[5].z),p2=(p[3].x,p[3].y,p[3].z)) ) lines.append ( camvtk.Line(p1=(p[5].x,p[5].y,p[5].z),p2=(p[7].x,p[7].y,p[7].z)) ) if oct.type == 0: color = camvtk.grey if oct.type == 1: color = camvtk.green if oct.type == 2: color = nodeColor(oct) for li in lines: li.SetColor( color ) if oct.type==0: li.SetOpacity(0.2) myscreen.addActor(li)
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