def setPdcfIfNotSet(self): if self.pdcf == None: self.pdcf = ocl.PathDropCutter() self.pdcf.setSTL(self.stl) self.pdcf.setCutter(self.cutter) self.pdcf.setSampling(0.1) self.pdcf.setZ(self.minz)
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 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)
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 ymax = 12 Ny = 40 # number of lines in the y-direction dy = float(ymax - ymin) / Ny # the y step-over
camvtk.vtkPolyData2OCLSTL(polydata, s) print "STLSurf with ", s.size(), " triangles" cutter = ocl.CylCutter(0.6) #print cutter.str() minx=-1 dx=0.1 maxx=11 miny=-1 dy=1 maxy=11 z=-0.2 pdf = ocl.PathDropCutter(s) pdf.SetCutter(cutter) path = ocl.Path() exit() pftp = cam.ParallelFinish() pftp.initCLPoints(minx,dx,maxx,miny,dy,maxy,z) pftp.dropCutterSTL1(cutter, s) print " made ", pftp.dcCalls, " drop-cutter calls" pf2 = cam.ParallelFinish() pf2.initCLPoints(minx,dx,maxx,miny,dy,maxy,z) pf2.dropCutterSTL2(cutter, s) print " made ", pf2.dcCalls, " drop-cutter calls"
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) pdf.run() # run drop-cutter on the path clp = pdf.getCLPoints() # get the cl-points from pdf
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 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