def cutting_tool(diameter, corner_radius, length): cutter = ocl.CylCutter(1.0, length) # dummy cutter if corner_radius == 0.0: cutter = ocl.CylCutter(diameter, length) elif corner_radius > diameter / 2 - 0.000000001: cutter = ocl.BallCutter(diameter, length) else: cutter = ocl.BullCutter(diameter, corner_radius, length) return (cutter)
def _dropcutter(self, obj, s, bb): import ocl import time cutter = ocl.CylCutter(self.radius * 2, 5) pdc = ocl.PathDropCutter() # create a pdc pdc.setSTL(s) pdc.setCutter(cutter) pdc.minimumZ = 0.25 pdc.setSampling(obj.SampleInterval) # some parameters for this "zigzig" pattern xmin = bb.XMin - cutter.getDiameter() xmax = bb.XMax + cutter.getDiameter() ymin = bb.YMin - cutter.getDiameter() ymax = bb.YMax + cutter.getDiameter() # number of lines in the y-direction Ny = int(bb.YLength / cutter.getDiameter()) dy = float(ymax - ymin) / Ny # the y step-over path = ocl.Path() # create an empty path object # add Line objects to the path in this loop for n in xrange(0, Ny): y = ymin + n * dy p1 = ocl.Point(xmin, y, 0) # start-point of line p2 = ocl.Point(xmax, y, 0) # end-point of line if (n % 2 == 0): # even l = ocl.Line(p1, p2) # line-object else: # odd l = ocl.Line(p2, p1) # line-object path.append(l) # add the line to the path pdc.setPath(path) # run drop-cutter on the path t_before = time.time() pdc.run() t_after = time.time() print "calculation took ", t_after - t_before, " s" # retrieve the points clp = pdc.getCLPoints() print "points received: " + str(len(clp)) # generate the path commands output = "" output += "G0 Z" + str(obj.ClearanceHeight.Value) + "\n" output += "G0 X" + str(clp[0].x) + " Y" + str(clp[0].y) + "\n" output += "G1 Z" + str(clp[0].z) + " F" + str(self.vertFeed) + "\n" for c in clp: output += "G1 X" + str(c.x) + " Y" + \ str(c.y) + " Z" + str(c.z) + "\n" return output
def _dropcutter(self, obj, s, bb): import ocl import time cutter = ocl.CylCutter(obj.ToolController.Tool.Diameter, 5) pdc = ocl.PathDropCutter() # create a pdc pdc.setSTL(s) pdc.setCutter(cutter) pdc.minimumZ = 0.25 pdc.setSampling(obj.SampleInterval) # some parameters for this "zigzig" pattern xmin = bb.XMin - cutter.getDiameter() xmax = bb.XMax + cutter.getDiameter() ymin = bb.YMin - cutter.getDiameter() ymax = bb.YMax + cutter.getDiameter() # number of lines in the y-direction Ny = int(bb.YLength / cutter.getDiameter()) dy = float(ymax - ymin) / Ny # the y step-over path = ocl.Path() # create an empty path object # add Line objects to the path in this loop for n in xrange(0, Ny): y = ymin + n * dy p1 = ocl.Point(xmin, y, 0) # start-point of line p2 = ocl.Point(xmax, y, 0) # end-point of line if (n % 2 == 0): # even l = ocl.Line(p1, p2) # line-object else: # odd l = ocl.Line(p2, p1) # line-object path.append(l) # add the line to the path pdc.setPath(path) # run drop-cutter on the path t_before = time.time() pdc.run() t_after = time.time() print("calculation took ", t_after - t_before, " s") # retrieve the points clp = pdc.getCLPoints() print("points received: " + str(len(clp))) # generate the path commands output = [] output.append(Path.Command('G0', {'Z': obj.ClearanceHeight.Value, 'F': self.vertRapid})) output.append(Path.Command('G0', {'X': clp[0].x, "Y": clp[0].y, 'F': self.horizRapid})) output.append(Path.Command('G1', {'Z': clp[0].z, 'F': self.vertFeed})) for c in clp: output.append(Path.Command('G1', {'X': c.x, "Y": c.y, "Z": c.z, 'F': self.horizFeed})) return output
def OCLDefinition(self, surface): import ocl if self.type == TOOL_TYPE_BALLENDMILL: return ocl.BallCutter(self.diameter + surface.material_allowance * 2, 1000) elif self.type == TOOL_TYPE_CHAMFER or self.type == TOOL_TYPE_ENGRAVER: return ocl.CylConeCutter(self.flat_radius * 2 + surface.material_allowance, self.diameter + surface.material_allowance * 2, self.cutting_edge_angle * math.pi/360) else: if self.corner_radius > 0.000000001: return ocl.BullCutter(self.diameter + surface.material_allowance * 2, self.corner_radius, 1000) else: return ocl.CylCutter(self.diameter + surface.material_allowance * 2, 1000)
def ocl_sample(operation, chunks): oclSTL = get_oclSTL(operation) op_cutter_type = operation.cutter_type op_cutter_diameter = operation.cutter_diameter op_minz = operation.minz if op_cutter_type == "VCARVE": op_cutter_tip_angle = operation['cutter_tip_angle'] cutter = None cutter_length = 5 if op_cutter_type == 'END': cutter = ocl.CylCutter( (op_cutter_diameter + operation.skin * 2) * 1000, cutter_length) elif op_cutter_type == 'BALLNOSE': cutter = ocl.BallCutter( (op_cutter_diameter + operation.skin * 2) * 1000, cutter_length) elif op_cutter_type == 'VCARVE': cutter = ocl.ConeCutter( (op_cutter_diameter + operation.skin * 2) * 1000, op_cutter_tip_angle, cutter_length) elif op_cutter_type == 'BALLCONE': angle = math.degrees( math.atan((op_cutter_diameter / 2) - operation.ball_radius) / (operation.ball_cone_flute - operation.ball_radius)) print("BallCone angle:" + str(angle)) cutter = ocl.BallConeCutter( (operation.ball_radius + operation.skin) * 2000, (op_cutter_diameter + operation.skin * 2) * 1000, math.radians(angle)) elif op_cutter_type == 'BULLNOSE': cutter = ocl.BullCutter( (op_cutter_diameter + operation.skin * 2) * 1000, operaton.bull_corner_radius * 1000, cutter_length) else: print("Cutter unsupported: {0}\n".format(op_cutter_type)) quit() bdc = ocl.BatchDropCutter() bdc.setSTL(oclSTL) bdc.setCutter(cutter) for chunk in chunks: for coord in chunk.points: bdc.appendPoint( ocl.CLPoint(coord[0] * 1000, coord[1] * 1000, op_minz * 1000)) bdc.run() cl_points = bdc.getCLPoints() return cl_points
def oclGetWaterline(operation, chunks): layers = oclWaterlineLayerHeights(operation) oclSTL = get_oclSTL(operation) cutter_props = operation.getOpCuttingTool() op_cutter_type = cutter_props.cutter_type op_cutter_diameter = cutter_props.cutter_diameter op_minz = operation.minz if op_cutter_type == "VCARVE": op_cutter_tip_angle = cutter_props.cutter_tip_angle cutter = None cutter_length = 150 #TODO: automatically determine necessary cutter length depending on object size if op_cutter_type == 'END': cutter = ocl.CylCutter( (op_cutter_diameter + operation.skin * 2) * 1000, cutter_length) elif op_cutter_type == 'BALLNOSE': cutter = ocl.BallCutter( (op_cutter_diameter + operation.skin * 2) * 1000, cutter_length) elif op_cutter_type == 'VCARVE': cutter = ocl.ConeCutter( (op_cutter_diameter + operation.skin * 2) * 1000, op_cutter_tip_angle, cutter_length) else: print("Cutter unsupported: {0}\n".format(op_cutter_type)) quit() waterline = ocl.Waterline() waterline.setSTL(oclSTL) waterline.setCutter(cutter) waterline.setSampling(0.1) #TODO: add sampling setting to UI for height in layers: print(str(height) + '\n') waterline.reset() waterline.setZ(height * OCL_SCALE) waterline.run2() wl_loops = waterline.getLoops() for l in wl_loops: chunks.append(camPathChunk(inpoints=[])) for p in l: chunks[-1].points.append( (p.x / OCL_SCALE, p.y / OCL_SCALE, p.z / OCL_SCALE)) chunks[-1].append(chunks[-1].points[0]) chunks[-1].closed = True chunks[-1].poly = sgeometry.Polygon(chunks[-1].points)
def ocl_cutter(self): # choose a cutter for the operation: # http://www.anderswallin.net/2011/08/opencamlib-cutter-shapes/ diameter = self.tool.diameter length = 5 # cutter = ocl.BallCutter(diameter, length) if isinstance(self.tool, StraightRouterBit): cutter = ocl.CylCutter(self.tool.diameter, self.tool.cutting_length) elif isinstance(self.tool, BallRouterBit): cutter = ocl.BullCutter(diameter, self.tool.diameter / 2.0, self.tool.cutting_length) # cutter = ocl.ConeCutter(diameter, angle, length) # cutter = cutter.offsetCutter( 0.4 ) return cutter
def ocl_sample(operation, chunks): oclSTL = get_oclSTL(operation) op_cutter_type = operation.cutter_type op_cutter_diameter = operation.cutter_diameter op_minz = operation.minz op_cutter_tip_angle = math.radians(operation.cutter_tip_angle)/2 if op_cutter_type == "VCARVE": cutter_length = (op_cutter_diameter/math.tan(op_cutter_tip_angle))/2 else: cutter_length = 10 cutter = None if op_cutter_type == 'END': cutter = ocl.CylCutter((op_cutter_diameter + operation.skin * 2) * 1000, cutter_length) elif op_cutter_type == 'BALLNOSE': cutter = ocl.BallCutter((op_cutter_diameter + operation.skin * 2) * 1000, cutter_length) elif op_cutter_type == 'VCARVE': cutter = ocl.ConeCutter((op_cutter_diameter + operation.skin * 2) * 1000, op_cutter_tip_angle, cutter_length) elif op_cutter_type =='CYLCONE': cutter = ocl.CylConeCutter((operation.cylcone_diameter/2+operation.skin)*2000,(op_cutter_diameter + operation.skin * 2) * 1000, op_cutter_tip_angle) elif op_cutter_type == 'BALLCONE': cutter = ocl.BallConeCutter((operation.ball_radius + operation.skin) * 2000, (op_cutter_diameter + operation.skin * 2) * 1000, op_cutter_tip_angle) elif op_cutter_type =='BULLNOSE': cutter = ocl.BullCutter((op_cutter_diameter + operation.skin * 2) * 1000,operation.bull_corner_radius*1000, cutter_length) else: print("Cutter unsupported: {0}\n".format(op_cutter_type)) quit() bdc = ocl.BatchDropCutter() bdc.setSTL(oclSTL) bdc.setCutter(cutter) for chunk in chunks: for coord in chunk.points: bdc.appendPoint(ocl.CLPoint(coord[0] * 1000, coord[1] * 1000, op_minz * 1000)) bdc.run() cl_points = bdc.getCLPoints() return cl_points
def ocl_sample(operation, chunks): oclSTL = get_oclSTL(operation) cutter_props = operation.getOpCuttingTool() op_cutter_type = cutter_props.cutter_type op_cutter_diameter = cutter_props.cutter_diameter op_minz = operation.minz if op_cutter_type == "VCARVE": op_cutter_tip_angle = cutter_props.cutter_tip_angle cutter = None cutter_length = 5 if op_cutter_type == 'END': cutter = ocl.CylCutter( (op_cutter_diameter + operation.skin * 2) * 1000, cutter_length) elif op_cutter_type == 'BALLNOSE': cutter = ocl.BallCutter( (op_cutter_diameter + operation.skin * 2) * 1000, cutter_length) elif op_cutter_type == 'VCARVE': cutter = ocl.ConeCutter( (op_cutter_diameter + operation.skin * 2) * 1000, op_cutter_tip_angle, cutter_length) else: print("Cutter unsupported: {0}\n".format(op_cutter_type)) quit() # add BullCutter bdc = ocl.BatchDropCutter() bdc.setSTL(oclSTL) bdc.setCutter(cutter) for chunk in chunks: for coord in chunk.points: bdc.appendPoint( ocl.CLPoint(coord[0] * 1000, coord[1] * 1000, op_minz * 1000)) bdc.run() cl_points = bdc.getCLPoints() return cl_points
import ocl import camvtk import issue20data if __name__ == "__main__": s = ocl.STLSurf() triangles = issue20data.trilist for t in triangles: s.addTriangle(t) print(ocl.version()) # define a cutter length = 10 cutter = ocl.CylCutter(3, length) #cutter = ocl.BallCutter(3, length) #cutter = ocl.BullCutter(3,0.5, length) pdf = ocl.PathDropCutter() # create a pdf-object for the surface s pdf.setSTL(s) pdf.setCutter(cutter) # set the cutter pdf.minimumZ = -1 # set the minimum Z-coordinate, or # "floor" for drop-cutter path = ocl.Path() # create an empty path object # add a line to the path path.append(ocl.Line(ocl.Point(0, 0.098, 0), ocl.Point(4, 0.098, 0))) # set the path for pdf pdf.setPath(path)
def _waterline(self, obj, s, bb): import time import ocl def drawLoops(loops): nloop = 0 pp = [] pp.append(Path.Command("(waterline begin)" )) for loop in loops: p = loop[0] pp.append(Path.Command("(loop begin)" )) pp.append(Path.Command('G0', {"Z": obj.SafeHeight.Value, 'F': self.vertRapid})) pp.append(Path.Command('G0', {'X': p.x, "Y": p.y, 'F': self.horizRapid})) pp.append(Path.Command('G1', {"Z": p.z, 'F': self.vertFeed})) for p in loop[1:]: pp.append(Path.Command('G1', {'X': p.x, "Y": p.y, "Z": p.z, 'F': self.horizFeed})) # zheight = p.z p = loop[0] pp.append(Path.Command('G1', {'X': p.x, "Y": p.y, "Z": p.z, 'F': self.horizFeed})) pp.append(Path.Command("(loop end)" )) print(" loop ", nloop, " with ", len(loop), " points") nloop = nloop + 1 pp.append(Path.Command("(waterline end)" )) return pp depthparams = PathUtils.depth_params(obj.ClearanceHeight.Value, obj.SafeHeight.Value, obj.StartDepth.Value, obj.StepDown, obj.FinishDepth.Value, obj.FinalDepth.Value) t_before = time.time() zheights = [i for i in depthparams] wl = ocl.Waterline() wl.setSTL(s) cutter = ocl.CylCutter(obj.ToolController.Tool.Diameter, 5) wl.setCutter(cutter) # this should be smaller than the smallest details in the STL file wl.setSampling(obj.SampleInterval) # AdaptiveWaterline() also has settings for minimum sampling interval # (see c++ code) all_loops = [] print ("zheights: {}".format(zheights)) for zh in zheights: print("calculating Waterline at z= ", zh) wl.reset() wl.setZ(zh) # height for this waterline wl.run() all_loops.append(wl.getLoops()) t_after = time.time() calctime = t_after - t_before n = 0 output = [] for loops in all_loops: # at each z-height, we may get many loops print(" %d/%d:" % (n, len(all_loops))) output.extend(drawLoops(loops)) n = n + 1 print("(" + str(calctime) + ")") return output
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()
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 ] cutter_diams = [0.6] # run the thing for all these cutter diameters length = 5 loops = [] cutter = ocl.CylCutter(1, 1) t_total = time.time() for zh in zheights: for diam in cutter_diams: cutter = ocl.CylCutter(diam, length) cutter = ocl.BallCutter(diam, length) #cutter = ocl.BullCutter( diam , diam/5, length ) #cutter = ocl.ConeCutter( diam , math.pi/5, length ) wl = ocl.Waterline() #wl.setThreads(1) wl.setSTL(s) wl.setCutter(cutter) wl.setZ(zh) wl.setSampling(0.02) wl.setThreads(1)
stl = camvtk.STLSurf("../stl/gnu_tux_mod.stl") #stl = camvtk.STLSurf("../stl/demo.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 diameter = 1.77321 length = 5 #cutter = ocl.BallCutter(diameter, length) cutter = ocl.CylCutter(diameter, length) #cutter = ocl.BullCutter(diameter, 0.2, length) #cutter = ocl.ConeCutter(diameter, angle, length) #cutter = cutter.offsetCutter( 0.4 ) print cutter minx = -1 dx = 0.1 / 5 maxx = 10 miny = -1 dy = 1 / float(2) maxy = 13 z = -1 # this generates a list of CL-points in a grid
if __name__ == "__main__": print ocl.version() myscreen = camvtk.VTKScreen() #stl = camvtk.STLSurf("../stl/demo.stl") stl = camvtk.STLSurf("../stl/pycam-textbox.stl") print "STL surface read" myscreen.addActor(stl) stl.SetWireframe() polydata = stl.src.GetOutput() s= ocl.STLSurf() camvtk.vtkPolyData2OCLSTL(polydata, s) print "STLSurf with ", s.size(), " triangles" print s.getBounds() # define a cutter cutter = ocl.CylCutter(10, 50) # diameter, length #cutter = ocl.BullCutter(0.6, 0.01, 5) print cutter #pdc = ocl.PathDropCutter() # create a pdc apdc = ocl.AdaptivePathDropCutter() #pdc.setSTL(s) apdc.setSTL(s) #pdc.setCutter(cutter) # set the cutter apdc.setCutter(cutter) #print "set minimumZ" #pdc.minimumZ = -1 # set the minimum Z-coordinate, or "floor" for drop-cutter #apdc.minimumZ = -1 #print "set the sampling interval" #pdc.setSampling(0.4) apdc.setSampling(0.4) apdc.setMinSampling(0.0008)
myscreen.addActor(camvtk.Point(center=(b.x, b.y, b.z), color=(1, 0, 1))) c = ocl.Point(0, 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))) f1 = ocl.Point(-2, 0.5, -0.2) f2 = ocl.Point(2, 0.5, -0.2) t = ocl.Triangle(b, c, a) #radius1=1 #angle = math.pi/4 #cutter = ocl.ConeCutter(0.37, angle) #cutter = ocl.BallCutter(0.532,5) cutter = ocl.CylCutter(0.3, 5) #cutter = ocl.CylConeCutter(0.2,0.5,math.pi/9) #cutter = ocl.BallConeCutter(0.4,0.6,math.pi/9) #cutter = ocl.BullConeCutter(0.4,0.1,0.7,math.pi/6) #cutter = ocl.ConeConeCutter(0.4,math.pi/3,0.7,math.pi/6) #cutter = ocl.ConeCutter(0.4, math.pi/3) print "fiber..." f = ocl.Fiber(f1, f2) i = ocl.Interval() f.printInts() print "vertexPush" cc = ocl.CCPoint() cutter.pushCutter(f, i, t)
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()
import ocl # this illustrates issue 8 if __name__ == "__main__": print ocl.version() cutter = ocl.CylCutter(3.0, 6) path = ocl.Path() path.append(ocl.Line(ocl.Point(-6.51, 0, 0), ocl.Point(6.51, 1.2, 0))) s=ocl.STLSurf() ocl.STLReader("../../stl/sphere2.stl",s) pdc = ocl.PathDropCutter() pdc.setSTL(s) pdc.setCutter(cutter) pdc.setPath(path) pdc.run() clpts = pdc.getCLPoints() for p in clpts: print p
import ocl import math print ocl.revision() # cylinder c = ocl.CylCutter(2.345, 5) d = c.offsetCutter(0.1) print c print "offset: ",d print # ball c = ocl.BallCutter(2.345, 6) d = c.offsetCutter(0.1) print c print "offset: ",d print # bull c = ocl.BullCutter(2.345, 0.123, 6) d = c.offsetCutter(0.1) print c print "offset: ",d print # cone c = ocl.ConeCutter(2.345, math.pi/6) d = c.offsetCutter(0.1) print c print "offset: ",d
z=z+dz #zheights=[] """ zheights.append(0.29) zheights.append(0.28) zheights.append(0.27) zheights.append(0.26) zheights.append(0.25) """ #zheights=[ -0.35, -0.25, -0.15, -0.05, 0.05, 0.15, 0.25] #zheights=[ 0.1] length = 10 diam = 0.6 cutter1 = ocl.CylCutter( diam , length ) cutter2 = ocl.BallCutter( diam , length ) cutter3 = ocl.BullCutter( diam , diam/5, length ) cutter4 = ocl.ConeCutter( diam , math.pi/5, length ) cutter5 = ocl.CylConeCutter(diam/float(3),diam,math.pi/float(9)) for zh in zheights: loops = calcWaterline(zh, cutter5, s) drawLoops(myscreen, loops[0], camvtk.red) #loops = calcWaterline(zh, cutter2, s) #drawLoops(myscreen, loops[0], camvtk.green) #loops = calcWaterline(zh, cutter3, s) #drawLoops(myscreen, loops[0], camvtk.yellow) #loops = calcWaterline(zh, cutter4, s)
if __name__ == "__main__": print(ocl.version()) myscreen = camvtk.VTKScreen() stl = camvtk.STLSurf("../stl/gnu_tux_mod.stl") print("STL surface read") myscreen.addActor(stl) stl.SetWireframe() polydata = stl.src.GetOutput() s = ocl.STLSurf() camvtk.vtkPolyData2OCLSTL(polydata, s) print("STLSurf with ", s.size(), " triangles") # define a cutter cutter = ocl.CylCutter(0.6, 5) print(cutter) print("creating PathDropCutter()") pdc = ocl.PathDropCutter() # create a pdc print("set STL surface") pdc.setSTL(s) print("set cutter") pdc.setCutter(cutter) # set the cutter print("set minimumZ") pdc.minimumZ = -1 # set the minimum Z-coordinate, or "floor" for drop-cutter print("set the sampling interval") pdc.setSampling(0.0123) # some parameters for this "zigzig" pattern ymin = 0
t = ocl.Triangle(b, c, a) s = ocl.STLSurf() s.addTriangle(t) # a one-triangle STLSurf # alternatively, run on the tux model stl = camvtk.STLSurf("../../stl/gnu_tux_mod.stl") #myscreen.addActor(stl) #stl.SetWireframe() # render tux as wireframe #stl.SetSurface() # render tux as surface #stl.SetColor(camvtk.cyan) polydata = stl.src.GetOutput() s = ocl.STLSurf() camvtk.vtkPolyData2OCLSTL(polydata, s) 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.05, 0.0, 0.05, 0.1, 0.15, 0.2, 0.28] zheights = [1.75145] diam = 0.6 # run the thing for all these cutter diameters length = 5 loops = [] cutter = ocl.CylCutter(1, 1) sampling = 0.005 waterline_time(zheights, diam, length, s, sampling)
def drawScreen(a, b, c, filename, write_flag): print(ocl.version()) myscreen = camvtk.VTKScreen() #a = ocl.Point(0,1,0.3) myscreen.addActor(camvtk.Point(center=(a.x, a.y, a.z), color=(1, 0, 1))) #b = ocl.Point(1,0.5,0.3) myscreen.addActor(camvtk.Point(center=(b.x, b.y, b.z), color=(1, 0, 1))) #c = ocl.Point(-0.1,0.3,0.0) myscreen.addActor(camvtk.Point(center=(c.x, c.y, c.z), color=(1, 0, 1))) myscreen.addActor(camvtk.Line(p1=(a.x, a.y, a.z), p2=(c.x, c.y, c.z))) myscreen.addActor(camvtk.Line(p1=(c.x, c.y, c.z), p2=(b.x, b.y, b.z))) myscreen.addActor(camvtk.Line(p1=(a.x, a.y, a.z), p2=(b.x, b.y, b.z))) t = ocl.Triangle(b, c, a) s = ocl.STLSurf() s.addTriangle(t) # a one-triangle STLSurf zheights = [ -0.3, -0.2, -0.1, -0.05, 0.0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.26, 0.27, 0.28, 0.29 ] # the z-coordinates for the waterlines zheights = [ -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, -0.05, 0.0, 0.05, 0.1, 0.15, 0.2, 0.28 ] zheights = [ -0.35, -0.3, -0.25, -0.2, -0.15, -0.1, -0.05, 0.0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.28 ] zheights = [] Nmax = 20 zmin = -0.5 zmax = -0.05 dz = (zmax - zmin) / float(Nmax - 1) z = zmin for n in range(Nmax): zheights.append(z) z = z + dz zheights = [] zheights.append(-0.25) #zheights=[ -0.35, -0.25, -0.15, -0.05, 0.05, 0.15, 0.25] #zheights=[ 0.1] length = 10 diam = 0.6 cutter1 = ocl.CylCutter(diam, length) cutter2 = ocl.BallCutter(diam, length) cutter3 = ocl.BullCutter(diam, diam / 5, length) cutter4 = ocl.ConeCutter(diam, math.pi / 5, length) for zh in zheights: #loops = calcWaterline(zh, cutter1, s) #drawLoops(myscreen, loops[0], camvtk.yellow) #loops = calcWaterline(zh, cutter2, s) #drawLoops(myscreen, loops[0], camvtk.green) #loops = calcWaterline(zh, cutter3, s) #drawLoops(myscreen, loops[0], camvtk.yellow) loops = calcWaterline(zh, cutter4, s) drawLoops(myscreen, loops[0], camvtk.pink) #for f in loops[1]: # drawFiber(myscreen, f, camvtk.red) #for f in loops[2]: # drawFiber(myscreen, f, camvtk.lblue) print("done.") myscreen.camera.SetPosition(1, -1, 3) myscreen.camera.SetFocalPoint(0.5, 0.5, 0) camvtk.drawArrows(myscreen, center=(-0.5, -0.5, -0.5)) camvtk.drawOCLtext(myscreen) myscreen.render() """ w2if = vtk.vtkWindowToImageFilter() w2if.SetInput(myscreen.renWin) lwr = vtk.vtkPNGWriter() lwr.SetInput( w2if.GetOutput() ) w2if.Modified() lwr.SetFileName(filename) if write_flag: lwr.Write() print("wrote ",filename) """ time.sleep(1)
def _dropcutter(self, obj, s, bb): import ocl import time if obj.ToolController.Tool.ToolType == 'BallEndMill': cutter = ocl.BallCutter(obj.ToolController.Tool.Diameter, 5) # TODO: 5 represents cutting edge height. Should be replaced with the data from toolcontroller? else: cutter = ocl.CylCutter(obj.ToolController.Tool.Diameter, 5) pdc = ocl.PathDropCutter() # create a pdc pdc.setSTL(s) pdc.setCutter(cutter) pdc.setZ(obj.FinalDepth.Value + obj.DepthOffset.Value) # set minimumZ pdc.setSampling(obj.SampleInterval) # the max and min XY area of the operation xmin = bb.XMin - obj.DropCutterExtraOffset.x xmax = bb.XMax + obj.DropCutterExtraOffset.x ymin = bb.YMin - obj.DropCutterExtraOffset.y ymax = bb.YMax + obj.DropCutterExtraOffset.y path = ocl.Path() # create an empty path object if obj.DropCutterDir == 'Y': Ny = int(bb.YLength / (cutter.getDiameter() * (obj.StepOver / 100.0))) dy = float(ymax - ymin) / Ny # the y step-over # add Line objects to the path in this loop for n in xrange(0, Ny): y = ymin + n * dy p1 = ocl.Point(xmin, y, 0) # start-point of line p2 = ocl.Point(xmax, y, 0) # end-point of line if (n % 2 == 0): # even l = ocl.Line(p1, p2) # line-object else: # odd l = ocl.Line(p2, p1) # line-object path.append(l) # add the line to the path else: Nx = int(bb.XLength / (cutter.getDiameter() * (obj.StepOver / 100.0))) dx = float(xmax - xmin) / Nx # the y step-over # add Line objects to the path in this loop for n in xrange(0, Nx): x = xmin + n * dx p1 = ocl.Point(x, ymin, 0) # start-point of line p2 = ocl.Point(x, ymax, 0) # end-point of line if (n % 2 == 0): # even l = ocl.Line(p1, p2) # line-object else: # odd l = ocl.Line(p2, p1) # line-object path.append(l) # add the line to the path pdc.setPath(path) # run drop-cutter on the path t_before = time.time() pdc.run() t_after = time.time() print("calculation took ", t_after - t_before, " s") # retrieve the points clp = pdc.getCLPoints() print("points received: " + str(len(clp))) # generate the path commands output = [] output.append(Path.Command('G0', {'Z': obj.ClearanceHeight.Value, 'F': self.vertRapid})) output.append(Path.Command('G0', {'X': clp[0].x, "Y": clp[0].y, 'F': self.horizRapid})) output.append(Path.Command('G1', {'Z': clp[0].z, 'F': self.vertFeed})) for c in clp: output.append(Path.Command('G1', {'X': c.x, "Y": c.y, "Z": c.z, 'F': self.horizFeed})) return output
import pyocl import camvtk stl = camvtk.STLSurf(tempfile.gettempdir() + "/model0.stl") stl_polydata = stl.src.GetOutput() stl_surf = ocl.STLSurf() camvtk.vtkPolyData2OCLSTL(stl_polydata, stl_surf) csv_file = open(tempfile.gettempdir() + '/ocl_settings.txt', 'r') op_cutter_type = csv_file.readline().split()[0] op_cutter_diameter = float(csv_file.readline()) op_minz = float(csv_file.readline()) csv_file.close() cutter_length = 5 if op_cutter_type == 'END': cutter = ocl.CylCutter(op_cutter_diameter * 1000, cutter_length) elif op_cutter_type == 'BALL': cutter = ocl.BallCutter(op_cutter_diameter * 1000, cutter_length) elif op_cutter_type == 'VCARVE': cutter = ocl.ConeCutter(op_cutter_diameter * 1000, 1, cutter_length) else: print "Cutter unsupported: " + op_cutter_type + '\n' quit() #add BullCutter bdc = ocl.BatchDropCutter() bdc.setSTL(stl_surf) bdc.setCutter(cutter) csv_file = open(tempfile.gettempdir() + '/ocl_chunks.txt', 'r') for text_line in csv_file: sample_point = [float(coord) for coord in text_line.split()]
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()
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()
myscreen = camvtk.VTKScreen() myscreen.setAmbient(20, 20, 20) #stl = camvtk.STLSurf(filename="demo.stl") stl = camvtk.STLSurf(filename="demo2.stl") print("STL surface read") myscreen.addActor(stl) stl.SetWireframe() stl.SetColor((0.5, 0.5, 0.5)) #stl.SetFlat() polydata = stl.src.GetOutput() s = cam.STLSurf() camvtk.vtkPolyData2OCLSTL(polydata, s) print("STLSurf with ", s.size(), " triangles") cutterDiameter = 0.6 cutter = cam.CylCutter(cutterDiameter) #print cutter.str() #print cc.type minx = -20 dx = 1 maxx = 20 miny = -20 dy = 01 maxy = 20 z = -0.2 bucketSize = 20 #pftp = cam.ParallelFinish() #pftp.initCLPoints(minx,dx,maxx,miny,dy,maxy,z)
def zigzag(filepath, tool_diameter=3.0, corner_radius=0.0, step_over=1.0, x0=-10.0, x1=10.0, y0=-10.0, y1=10.0, direction='X', mat_allowance=0.0, style=0, clearance=5.0, rapid_safety_space=2.0, start_depth=0.0, step_down=2.0, final_depth=-10.0, units=1.0): mm = True if math.fabs(units) > 0.000000001: # ocl works in mm, so convert all values to mm mm = False tool_diameter *= units corner_radius *= units step_over *= units x0 *= units x1 *= units y0 *= units y1 *= units mat_allowance *= units clearance *= units rapid_safety_space *= units start_depth *= units step_down *= units final_depth *= units # read the stl file, we know it is an ascii file because HeeksCNC made it s = STLSurfFromFile(filepath) cutter = ocl.CylCutter(1.0, 1.0) # a dummy-cutter for now if corner_radius == 0.0: cutter = ocl.CylCutter(tool_diameter + mat_allowance, 100.0) elif corner_radius > tool_diameter / 2 - 0.000000001: cutter = ocl.BallCutter(tool_diameter + mat_allowance, 100.0) else: cutter = ocl.BullCutter(tool_diameter + mat_allowance, corner_radius, 100.0) if final_depth > start_depth: raise 'final_depth > start_depth' height = start_depth - final_depth zsteps = int(height / math.fabs(step_down) + 0.999999) zstep_down = height / zsteps incremental_rapid_to = rapid_safety_space - start_depth if incremental_rapid_to < 0: incremental_rapid_to = 0.1 dcf = ocl.PathDropCutter() dcf.setSTL(s) dcf.setCutter(cutter) for k in range(0, zsteps): z1 = start_depth - k * zstep_down z0 = start_depth - (k + 1) * zstep_down dcf.setZ(z0) steps = int((y1 - y0) / step_over) + 1 if direction == 'Y': steps = int((x1 - x0) / step_over) + 1 sub_step_over = (y1 - y0) / steps if direction == 'Y': sub_step_over = (x1 - x0) / steps rapid_to = z1 + incremental_rapid_to path = ocl.Path() for i in range(0, steps + 1): odd_numbered_pass = (i % 2 == 1) u = y0 + float(i) * sub_step_over if direction == 'Y': u = x0 + float(i) * sub_step_over if style == 0: # one way if direction == 'Y': path.append( ocl.Line(ocl.Point(u, y0, 0), ocl.Point(u, y1, 0))) else: path.append( ocl.Line(ocl.Point(x0, u, 0), ocl.Point(x1, u, 0))) cut_path(path, dcf, z1, mat_allowance, mm, units, rapid_to, incremental_rapid_to) path = ocl.Path() if mm: rapid(z=clearance) else: rapid(z=clearance / units) else: # back and forth if direction == 'Y': if odd_numbered_pass: path.append( ocl.Line(ocl.Point(u, y1, 0), ocl.Point(u, y0, 0))) if i < steps: path.append( ocl.Line( ocl.Point(u, y0, 0), ocl.Point(u + sub_step_over, y0, 0))) # feed across to next pass else: path.append( ocl.Line(ocl.Point(u, y0, 0), ocl.Point(u, y1, 0))) if i < steps: path.append( ocl.Line( ocl.Point(u, y1, 0), ocl.Point(u + sub_step_over, y1, 0))) # feed across to next pass else: # 'X' if odd_numbered_pass: path.append( ocl.Line(ocl.Point(x1, u, 0), ocl.Point(x0, u, 0))) if i < steps: path.append( ocl.Line( ocl.Point(x0, u, 0), ocl.Point(x0, u + sub_step_over, 0))) # feed across to next pass else: path.append( ocl.Line(ocl.Point(x0, u, 0), ocl.Point(x1, u, 0))) if i < steps: path.append( ocl.Line( ocl.Point(x1, u, 0), ocl.Point(x1, u + sub_step_over, 0))) # feed across to next pass if style != 0: # back and forth cut_path(path, dcf, z1, mat_allowance, mm, units, rapid_to, incremental_rapid_to) if mm: rapid(z=clearance) else: rapid(z=clearance / units)
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()