def loop_waterline(zh, cutter,s): range=2 Nmax = 200 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)] bpc = ocl.BatchPushCutter() bpc.setXDirection() bpc.setSTL(s) bpc.setCutter(cutter) for y in yvals: f1 = ocl.Point(-range,y,zh) # start point of fiber f2 = ocl.Point(+range,y,zh) # end point of fiber f = ocl.Fiber( f1, f2) bpc.appendFiber(f) for x in xvals: f1 = ocl.Point(x,-range,zh) # start point of fiber f2 = ocl.Point(x,+range,zh) # end point of fiber f = ocl.Fiber( f1, f2) bpc.appendFiber(f) bpc.run() clpoints = bpc.getCLPoints() fibers = bpc.getFibers() w = ocl.Weave() print "Weave...", for f in fibers: w.addFiber(f) print "build()...", w.build() print "face_traverse()...", w.face_traverse() print "done." return w.getLoops()
def waterline(cutter, s, zh, tol=0.1): bpc = ocl.BatchPushCutter() bpc.setSTL(s) bpc.setCutter(cutter) bounds = s.getBounds() xmin = bounds[0] - 2 * cutter.getRadius() xmax = bounds[1] + 2 * cutter.getRadius() ymin = bounds[2] - 2 * cutter.getRadius() ymax = bounds[3] + 2 * cutter.getRadius() Nx = int((xmax - xmin) / tol) Ny = int((ymax - ymin) / tol) xvals = generateRange(xmin, xmax, Nx) yvals = generateRange(ymin, ymax, Ny) for y in yvals: f1 = ocl.Point(xmin, y, zh) # start point of fiber f2 = ocl.Point(xmax, y, zh) # end point of fiber f = ocl.Fiber(f1, f2) bpc.appendFiber(f) for x in xvals: f1 = ocl.Point(x, ymin, zh) # start point of fiber f2 = ocl.Point(x, ymax, zh) # end point of fiber f = ocl.Fiber(f1, f2) bpc.appendFiber(f) bpc.run() fibers = bpc.getFibers() # get fibers w = ocl.Weave() for f in fibers: w.addFiber(f) print " build()...", w.build() print "done" print " split()...", subw = w.get_components() print "done. graph has", len(subw), "sub-weaves" m = 0 loops = [] for sw in subw: print m, " face_traverse...", t_before = time.time() sw.face_traverse() t_after = time.time() calctime = t_after - t_before print "done in ", calctime, " s." sw_loops = sw.getLoops() for lop in sw_loops: loops.append(lop) m = m + 1 return loops
f1 = ocl.Point(x,-15.5,zh) # start point of fiber f2 = ocl.Point(x,15.5,zh) # end point of fiber f = ocl.Fiber( f1, f2) bpc_y.appendFiber(f) # run bpc_x.run() bpc_y.run() xfibers = bpc_x.getFibers() yfibers = bpc_y.getFibers() fibers = xfibers+yfibers print(" got ",len(xfibers)," xfibers") print(" got ",len(yfibers)," yfibers") print("rendering fibers and CL-points.") w = ocl.Weave() print("push fibers to Weave...",) for f in fibers: w.addFiber(f) print("done.") print("Weave build()...",) mem1 = procmemory.resident() print("before ", mem1) w.build() #w.build2() mem2 = procmemory.resident() print("after ", float(mem2)/float(1024*1024), " MB") print(" build() memory: ",float(mem2-mem1)/float(1024*1024)," MB") print("done") print("face_traverse...") w.face_traverse()
def getWeaveRAM(Nmax,weave2_flag): #stl = camvtk.STLSurf("../stl/demo.stl") stl = camvtk.STLSurf("../../stl/gnu_tux_mod.stl") polydata = stl.src.GetOutput() s = ocl.STLSurf() camvtk.vtkPolyData2OCLSTL(polydata, s) cutter = ocl.CylCutter(0.3, 5) fiber_range=30 #Nmax = 400 yvals = [float(n-float(Nmax)/2)/Nmax*float(fiber_range) for n in range(0,Nmax+1)] xvals = [float(n-float(Nmax)/2)/Nmax*float(fiber_range) for n in range(0,Nmax+1)] zvals=[ 1.6523] bpc_x = ocl.BatchPushCutter() bpc_y = ocl.BatchPushCutter() bpc_x.setXDirection() bpc_y.setYDirection() bpc_x.setSTL(s) bpc_y.setSTL(s) bpc_x.setCutter(cutter) bpc_y.setCutter(cutter) # create fibers for zh in zvals: for y in yvals: f1 = ocl.Point(-15.5,y,zh) # start point of fiber f2 = ocl.Point(15.5,y,zh) # end point of fiber f = ocl.Fiber( f1, f2) bpc_x.appendFiber(f) for x in xvals: f1 = ocl.Point(x,-15.5,zh) # start point of fiber f2 = ocl.Point(x,15.5,zh) # end point of fiber f = ocl.Fiber( f1, f2) bpc_y.appendFiber(f) # run bpc_x.run() bpc_y.run() xfibers = bpc_x.getFibers() yfibers = bpc_y.getFibers() fibers = xfibers+yfibers print(" got ",len(xfibers)," xfibers") print(" got ",len(yfibers)," yfibers") fibercount = len(xfibers) + len(yfibers) print("rendering fibers and CL-points.") w = ocl.Weave() print("push fibers to Weave...",) for f in fibers: w.addFiber(f) print("done.") print("Weave build()...",) mem1 = procmemory.memory() if weave2_flag==1: w.build2() else: w.build() mem2 = procmemory.memory() #print "after ", float(mem2)/float(1024*1024), " MB" megabytes = float(mem2-mem1)/float(1024*1024) megabytes2 = float(mem2)/float(1024*1024) verts = w.numVertices() print(" before: ", float(mem1)/float(1024*1024)) print(" after: ", float(mem2)/float(1024*1024)) print(" build() memory: ",megabytes," MB") print("done") print("face_traverse...") w.face_traverse() print("done.") w_clpts = w.getCLVertices() w_ipts = w.getINTVertices() w_edges = w.getEdges() w_loop = w.getLoops() print(" got: ", len(w_edges), " edges") print(" got: ", len(w_loop), " loops") out=[] out.append(fibercount) out.append(verts) return out