Beispiel #1
0
    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
Beispiel #2
0
    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
Beispiel #3
0
        def _order(p):
            if inter.coords[0][0] < inter.coords[1][0]:
                these = list(p)
            else:
                these = list(reversed(p))

            if forward:
                these.reverse()

            path = ocl.Path()
            path.append(ocl.Line(ocl.Point(*these[0]), ocl.Point(*these[1])))
            return path
Beispiel #4
0
 def feed(self, x=None, y=None, z=None, a=None, b=None, c=None):
     px = self.x
     py = self.y
     pz = self.z
     recreator.Redirector.feed(self, x, y, z, a, b, c)
     if self.x == None or self.y == None or self.z == None:
         return
     if px == self.x and py == self.y:
         return
         
     # add a line to the path
     if self.path == None: self.path = ocl.Path()
     self.path.append(ocl.Line(ocl.Point(px, py, pz), ocl.Point(self.x, self.y, self.z)))
Beispiel #5
0
 def z2(self, z):
     path = ocl.Path()
     # use a line with no length
     path.append(ocl.Line(ocl.Point(self.x, self.y, self.z), ocl.Point(self.x, self.y, self.z)))
     self.setPdcfIfNotSet()
     if (self.z>self.minz):
         self.pdcf.setZ(self.z)  # Adjust Z if we have gotten a higher limit (Fix pocketing losing steps when using attach?)
     else:
         self.pdcf.setZ(self.minz/units) # Else use minz
     self.pdcf.setPath(path)
     self.pdcf.run()
     plist = self.pdcf.getCLPoints()
     p = plist[0]
     return p.z + self.material_allowance/units
Beispiel #6
0
def YdirectionZigPath(xmin, xmax, ymin, ymax, Ny):
    paths = []
    dy = float(ymax - ymin) / (Ny - 1)  # the y step-over
    for n in xrange(0, Ny):
        path = ocl.Path()
        y = ymin + n * dy  # current y-coordinate
        if (n == Ny - 1):
            assert (y == ymax)
        elif (n == 0):
            assert (y == ymin)
        p1 = ocl.Point(xmin, y, 0)  # start-point of line
        p2 = ocl.Point(xmax, y, 0)  # end-point of line
        l = ocl.Line(p1, p2)  # line-object
        path.append(l)  # add the line to the path
        paths.append(path)
    return paths
Beispiel #7
0
def getPathsX(s, cutter, sampling, x):
    #apdc = ocl.PathDropCutter()
    apdc = ocl.AdaptivePathDropCutter()
    apdc.setSTL(s)
    apdc.setCutter(cutter)
    apdc.setZ(-20)
    apdc.setSampling(sampling)
    apdc.setMinSampling(sampling / 700)
    path = ocl.Path()
    p1 = ocl.Point(x, -1.52 * cutter.getDiameter(),
                   -111)  # start-point of line
    p2 = ocl.Point(x, +1.52 * cutter.getDiameter(), -111)  # end-point of line
    l = ocl.Line(p1, p2)  # line-object
    path.append(l)
    apdc.setPath(path)
    apdc.run()
    return apdc.getCLPoints()
Beispiel #8
0
 def feed(self, x=None, y=None, z=None):
     px = self.x
     py = self.y
     pz = self.z
     if x != None: self.x = x * units
     if y != None: self.y = y * units
     if z != None: self.z = z * units
     if self.x == None or self.y == None or self.z == None:
         self.cut_path()
         self.original.feed(x, y, z)
         return
     if px == self.x and py == self.y:
         # z move only
         self.cut_path()
         self.original.feed(self.x/units, self.y/units, self.z2(self.z)/units)
         return
         
     # add a line to the path
     if self.path == None: self.path = ocl.Path()
     self.path.append(ocl.Line(ocl.Point(px, py, pz), ocl.Point(self.x, self.y, self.z)))
Beispiel #9
0
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)
Beispiel #10
0
import sys
import ocl

# This example shows how to aggregate lines and arcs into path objects and then
# how to retrieve such data.
print ocl.version()

paths = []

# use Point(x,y) which sets z=0
path_id_1 = ocl.Path()
path_id_1.append(ocl.Line(ocl.Point(6, -9), ocl.Point(10.79422863,
                                                      0.69615242)))
path_id_1.append(
    ocl.Line(ocl.Point(10.79422863, 0.69615242),
             ocl.Point(4.79422863, 9.69615242)))
path_id_1.append(ocl.Line(ocl.Point(4.79422863, 9.69615242), ocl.Point(-6, 9)))
path_id_1.append(
    ocl.Line(ocl.Point(-6, 9), ocl.Point(-10.7942286, -0.69615242)))
path_id_1.append(
    ocl.Line(ocl.Point(-10.7942286, -0.69615242),
             ocl.Point(-4.79422863, -9.69615242)))
path_id_1.append(
    ocl.Line(ocl.Point(-4.79422863, -9.69615242), ocl.Point(6, -9)))
paths.append(path_id_1)

path_id_2 = ocl.Path()
path_id_2.append(
    ocl.Line(ocl.Point(15, -14, 0), ocl.Point(19.62435565, 5.99038106, 0)))
path_id_2.append(
    ocl.Line(ocl.Point(19.62435565, 5.99038106, 0),
    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

    path = ocl.Path()  # create an empty path object
    # add Line objects to the path in this loop
    for n in range(0, Ny):
        y = ymin + n * dy
        p1 = ocl.Point(0, y, 0)  # start-point of line
        p2 = ocl.Point(9, y, 0)  # end-point of line
        l = ocl.Line(p1, p2)  # line-object
        path.append(l)  # add the line to the path

    print(" set the path for pdf ")
    pdc.setPath(path)

    print(" run the calculation ")
    t_before = time.time()
    pdc.run()  # run drop-cutter on the path
    t_after = time.time()
    print("run took ", t_after - t_before, " s")

    print("get the results ")
    clp = pdc.getCLPoints()  # get the cl-points from pdf

    print(" render the CL-points")
Beispiel #12
0
    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

    print('first point ', clp[0], '   ( z should be at z5 )')

    # visualize things with VTK
    myscreen = camvtk.VTKScreen()
    myscreen.addActor(camvtk.PointCloud(pointlist=clp))
    #myscreen.addActor( camvtk.PointCloud( pointlist=ccp, collist=ccp ) )
    su = camvtk.STLSurf(filename=None, triangleList=triangles)
Beispiel #13
0
    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
Beispiel #14
0
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
Beispiel #15
0
import ocl
import camvtk
import time

if __name__ == "__main__":

    myscreen = camvtk.VTKScreen()

    myscreen.camera.SetPosition(3, 60, 15)
    myscreen.camera.SetFocalPoint(1, 1, 10)

    cutter = ocl.CylCutter(3.0)
    path = ocl.Path()

    path.append(ocl.Line(ocl.Point(1.0, 1.4, 0), ocl.Point(2.0, 1.4, 0)))
    cl = ocl.Point(1.4, 1.4, 0)
    s = ocl.STLSurf("cone_on_side.stl")

    stl = camvtk.STLSurf("cone_on_side.stl")
    myscreen.addActor(stl)
    stl.SetWireframe()

    #dcf = ocl.PathDropCutterFinish(s)
    #dcf.setCutter(cutter)
    #dcf.setPath(path)
    #dcf.run()
    #plist = dcf.getCLPoints()
    pf = ocl.ParallelFinish()
    pf.initSTLSurf(s, 1)

    plist = []
Beispiel #16
0
    def points_to_ocl_path(self, pts):
        path = ocl.Path()
        for p1, p2 in zip(pts[:-1], pts[1:]):
            path.append(ocl.Line(ocl.Point(*p1), ocl.Point(*p2)))

        return path