Пример #1
0
def CLPointGridZigZag(minx, dx, maxx, miny, dy, maxy, z):
    """ generate and return a zigzag grid of points """
    plist = []
    xvalues = [
        round(minx + n * dx, 2)
        for n in range(int(round((maxx - minx) / dx)) + 1)
    ]
    yvalues = [
        round(miny + n * dy, 2)
        for n in range(int(round((maxy - miny) / dy)) + 1)
    ]

    #yrow = 0
    #x=minx
    #dir = 0
    xlist = xvalues
    for y in yvalues:
        #xlist = xvalues
        #if dir == 1:
        #    xlist.reverse()
        #    dir = 0
        #else:
        #    dir = 1

        for x in xlist:
            plist.append(ocl.CLPoint(x, y, z))
        xlist.reverse()
        #yrow=yrow+1
    return plist
Пример #2
0
def filter_path(path,tol):
    f = ocl.LineCLFilter()
    f.setTolerance(tol)
    for p in path:
        p2 = ocl.CLPoint(p.x,p.y,p.z)
        f.addCLPoint(p2)
    f.run()
    return  f.getCLPoints()
Пример #3
0
def CLPointGrid(minx,dx,maxx,miny,dy,maxy,z):
    """ generate and return a rectangular grid of points """
    plist = []
    xvalues = [round(minx+n*dx,2) for n in xrange(int(round((maxx-minx)/dx))+1) ]
    yvalues = [round(miny+n*dy,2) for n in xrange(int(round((maxy-miny)/dy))+1) ]
    for y in yvalues:
        for x in xvalues:
            plist.append( ocl.CLPoint(x,y,z) )
    return plist
Пример #4
0
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
Пример #5
0
def CLPointGrid(minx, dx, maxx, miny, dy, maxy, z):
    plist = []
    xvalues = [
        round(minx + n * dx, 2)
        for n in xrange(int(round((maxx - minx) / dx)) + 1)
    ]
    yvalues = [
        round(miny + n * dy, 2)
        for n in xrange(int(round((maxy - miny) / dy)) + 1)
    ]
    for y in yvalues:
        for x in xvalues:
            plist.append(ocl.CLPoint(x, y, z))
    return plist
Пример #6
0
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
Пример #7
0
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
Пример #8
0
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()]
    bdc.appendPoint(
        ocl.CLPoint(sample_point[0] * 1000, sample_point[1] * 1000,
                    op_minz * 1000))
csv_file.close()

bdc.run()

cl_points = bdc.getCLPoints()

csv_file = open(tempfile.gettempdir() + '/ocl_chunk_samples.txt', 'w')
for point in cl_points:
    csv_file.write(str(point.z) + '\n')
csv_file.close()
Пример #9
0
import ocl

print ocl.version()

p0 = ocl.CLPoint(0, 0, 0)
p1 = ocl.CLPoint(1, 2, 3)
p2 = ocl.CLPoint(1.1, 2.2, 3.3)
clp = []
clp.append(p0)
clp.append(p1)
clp.append(p2)

f = ocl.LineCLFilter()
f.setTolerance(0.01)
for p in clp:
    f.addCLPoint(p)

f.run()
p2 = f.getCLPoints()
for p in p2:
    print p
Пример #10
0
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()
Пример #11
0
    aclp = apdc.getCLPoints()
    print "got ", len(aclp), " adaptive points"

    aclp_lifted = []
    for p in aclp:
        p2 = ocl.Point(p.x, p.y, p.z) + ocl.Point(0, 0, 1)
        aclp_lifted.append(p2)

    # filter the adaptively sampled toolpaths

    print "filtering. before filter we have", len(aclp_lifted), "cl-points"
    t_before = time.time()
    f = ocl.LineCLFilter()
    f.setTolerance(0.001)
    for p in aclp_lifted:
        p2 = ocl.CLPoint(p.x, p.y, p.z)
        f.addCLPoint(p2)

    f.run()
    t_after = time.time()
    calctime = t_after - t_before
    print " done in ", calctime, " s"

    cl_filtered = f.getCLPoints()
    aclp_lifted2 = []
    for p in cl_filtered:
        p2 = ocl.Point(p.x, p.y, p.z) + ocl.Point(0, 0, 1)
        aclp_lifted2.append(p2)

    print " render the CL-points"
    camvtk.drawCLPointCloud(myscreen, clp)
Пример #12
0
import ocl

print ocl.revision()

p = ocl.Point(1,2,3)
print p
cc = ocl.CCPoint(4,5,6)
print cc
cl = ocl.CLPoint()
print cl
cl2 = ocl.CLPoint(7,8,9)
print cl2
cl3 = ocl.CLPoint(10,11,12,cc)
print cl3
cc.x=77
print cl3
Пример #13
0
    print c2

    minx = -0.5
    dx = 0.0051
    maxx = 1.5
    miny = -0.7
    dy = dx
    maxy = 1.5
    z = -1.8
    clpoints = CLPointGrid(minx, dx, maxx, miny, dy, maxy, z)
    print len(clpoints), "cl-points to evaluate"
    n = 0
    ccpoints = []
    cl2pts = []
    for p in clpoints:
        cl2pts.append(ocl.CLPoint(p.x, p.y, p.z))

    for (cl, cl2) in zip(clpoints, cl2pts):

        #cutter.vertexDrop(cl,t)
        #cutter.edgeDrop(cl,t)
        #cutter.facetDrop(cl,t)
        #c2.vertexDrop(cl2,t)
        cutter.dropCutter(cl, t)
        c2.dropCutter(cl2, t)
        n = n + 1
        if (n % int(len(clpoints) / 10)) == 0:
            print n / int(len(clpoints) / 10), " ",

    print "done."
Пример #14
0
import ocl
import camvtk
import time

if __name__ == "__main__":
    cutter = ocl.CylCutter(.1, 5)
    print(cutter)
    a = ocl.Point(1, 0, 0)
    b = ocl.Point(0, 1, 0)
    c = ocl.Point(0, 0, 1)
    t = ocl.Triangle(a, b, c)
    print("triangle created  t=", t)
    cl = ocl.CLPoint(0.2, 0.2, 0)

    cutter.dropCutter(cl, t)
    print("CL= ", cl)