Esempio n. 1
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
Esempio n. 2
0
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)
Esempio n. 3
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
Esempio n. 4
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
 """
 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)
     #drawLoops(myscreen, loops[0], camvtk.pink)
     
     #for f in loops[1]:
Esempio n. 6
0
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()]
    bdc.appendPoint(
        ocl.CLPoint(sample_point[0] * 1000, sample_point[1] * 1000,
                    op_minz * 1000))
csv_file.close()
Esempio n. 7
0
          'r') as csv_file:
    op_cutter_type = csv_file.readline().split()[0]
    op_cutter_diameter = float(csv_file.readline())
    if op_cutter_type == "VCARVE":
        op_cutter_tip_angle = float(csv_file.readline())
    op_minz = float(csv_file.readline())

cutter = None
cutter_length = 5

if op_cutter_type == 'END':
    cutter = ocl.CylCutter(op_cutter_diameter * 1000, cutter_length)
elif op_cutter_type == 'BALLNOSE':
    cutter = ocl.BallCutter(op_cutter_diameter * 1000, cutter_length)
elif op_cutter_type == 'VCARVE':
    cutter = ocl.ConeCutter(op_cutter_diameter * 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(stl_surf)
bdc.setCutter(cutter)

with open(os.path.join(tempfile.gettempdir(), 'ocl_chunks.txt'),
          'r') as csv_file:
    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,
Esempio n. 8
0
def drawScreen(a,b,c,filename,write_flag):  
    print ocl.revision()
    myscreen = camvtk.VTKScreen()
    z_hi = a.z
    if b.z > z_hi:
        z_hi = b.z
    if c.z > z_hi:
        z_hi = c.z

    z_lo = a.z
    if b.z < z_lo:
        z_lo = b.z
    if c.z < z_lo:
        z_lo = c.z
    #z_hi = 0.3 # this is the shallow case
    #ztri = 0.8 # this produces the steep case where we hit the circular rim
    
    #z_lo = 0.1
    #a = ocl.Point(0,1,ztri)
    #b = ocl.Point(1,0.5,ztri)    
    #c = ocl.Point(0.2,0.2,ztri_lo)
    
    myscreen.addActor(camvtk.Point(center=(a.x,a.y,a.z), color=(1,0,1)))
    myscreen.addActor(camvtk.Point(center=(b.x,b.y,b.z), color=(1,0,1)))
    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)
    angle = math.pi/5
    diameter=0.3
    length=5
    #cutter = ocl.BallCutter(diameter, length)
    #cutter = ocl.CylCutter(diameter, length)
    #cutter = ocl.BullCutter(diameter, diameter/4, length)
    cutter = ocl.ConeCutter(diameter, angle, length)
    #cutter = cutter.offsetCutter( 0.1 )
    
    print "cutter= ", cutter
    print "length=", cutter.getLength()
    print "fiber..."
    range=2
    Nmax = 100
    yvals = [float(n-float(Nmax)/2)/Nmax*range for n in xrange(0,Nmax+1)]
    xvals = [float(n-float(Nmax)/2)/Nmax*range for n in xrange(0,Nmax+1)]
    zmin = z_lo - 0.3
    zmax = z_hi
    zNmax = 20
    dz = (zmax-zmin)/(zNmax-1)
    zvals=[]
    for n in xrange(0,zNmax):
        zvals.append(zmin+n*dz)
    for zh in zvals:
        yfiber(cutter,yvals,t,zh,myscreen)
        xfiber(cutter,xvals,t,zh,myscreen)
    print "done."
    myscreen.camera.SetPosition(-2, -1, 3)
    myscreen.camera.SetFocalPoint(1.0, 0.0, -0.5)
    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
    #c = ocl.Point(0,0,0.3)

    myscreen.addActor(camvtk.Point(center=(a.x, a.y, a.z), color=(1, 0, 1)))
    myscreen.addActor(camvtk.Point(center=(b.x, b.y, b.z), color=(1, 0, 1)))
    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(a, b, c)

    angle = math.pi / 8
    length = 5.0
    #c1 = ocl.BullCutter(0.5,0.1, length)
    #c1 = ocl.CylCutter(0.5, length)
    #c1 = ocl.BallCutter(0.5, length)
    c1 = ocl.ConeCutter(0.5, angle, length)
    cutter = c1
    cutter = c1.offsetCutter(0.1)

    print cutter

    # grid parameters

    minx = -0.7
    dx = 0.03
    maxx = 1.7
    miny = -0.7
    dy = 0.03
    maxy = 1.7
    z = -0.5
    # generate list of CL-poins at height z
Esempio n. 10
0
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)
Esempio n. 11
0
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

# TODO: add compound-cutters here below.
Esempio n. 12
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
    zh = 0.25  # the z-coordinates for the waterlines
    diam = 0.31  # run the thing for all these cutter diameters
    length = 5
    loops = []

    #cutter = ocl.CylCutter( diam , length )
    #cutter = ocl.BallCutter( diam , length )
    #cutter = ocl.BullCutter( diam , diam/5, length )
    cutter = ocl.ConeCutter(diam, math.pi / 4, length)

    wl = ocl.Waterline()
    #wl.setThreads(1)
    wl.setSTL(s)
    wl.setCutter(cutter)
    wl.setZ(zh)
    wl.setSampling(0.05)
    t_before = time.time()
    wl.run()
    t_after = time.time()
    calctime = t_after - t_before
    print " Waterline done in ", calctime, " s"
    cutter_loops = wl.getLoops()
    for l in cutter_loops:
        loops.append(l)
    b = ocl.Point(1,0.5,0.0)    
    c = ocl.Point(0.1,0.1,0.0)
    myscreen.addActor(camvtk.Point(center=(a.x,a.y,a.z), color=(1,0,1)))
    myscreen.addActor(camvtk.Point(center=(b.x,b.y,b.z), color=(1,0,1)))
    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)
    angle = math.pi/4
    diameter=0.3
    length=5
    cutter1 = ocl.BallCutter(diameter, length)
    cutter2 = ocl.CylCutter(diameter, length)
    cutter3 = ocl.BullCutter(diameter, diameter/4, length)
    cutter4 = ocl.ConeCutter(diameter, angle, length)
    #cutter = cutter.offsetCutter( 0.1 )
    
    
    range=2
    Nmax = 50
    yvals = [float(n-float(Nmax)/2)/Nmax*range for n in xrange(0,Nmax+1)]
    xvals = [float(n-float(Nmax)/2)/Nmax*range for n in xrange(0,Nmax+1)]
    zmin = -0.1
    zmax = 0.25
    zNmax =5
    dz = (zmax-zmin)/(zNmax-1)
    zvals=[]
    for n in xrange(0,zNmax):
        zvals.append(zmin+n*dz)