예제 #1
0
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)
예제 #2
0
파일: Tool.py 프로젝트: danheeks/PyCAM
 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)
예제 #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
    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
예제 #4
0
    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
예제 #5
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
 #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)
     #drawLoops(myscreen, loops[0], camvtk.pink)
     
예제 #7
0
    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"

    # define a cutter
    #cutter = ocl.CylCutter(0.6, 5)
    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)
    print " apdc sampling = ", apdc.getSampling()
예제 #8
0
def main(ycoord=1.2, filename="test", theta=60, fi=45):
    myscreen = camvtk.VTKScreen()
    focal = cam.Point(2.17, 1, 0)
    r = 14
    theta = (float(theta) / 360) * 2 * math.pi

    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)

    #ycoord = 1.1

    # the two points that define the edge
    a = cam.Point(3, ycoord, 2.999999)
    b = cam.Point(-1, ycoord, 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)))
    #c=cam.Point(0,0,0.3)
    myscreen.addActor(camvtk.Line(p1=(a.x, a.y, a.z), p2=(b.x, b.y, b.z)))
    #t = cam.Triangle(a,b,c)

    cutter_length = 2
    cutter = cam.BullCutter(1, 0.2, cutter_length)

    print cutter
    xar = camvtk.Arrow(color=camvtk.red, rotXYZ=(0, 0, 0))
    myscreen.addActor(xar)
    yar = camvtk.Arrow(color=camvtk.green, rotXYZ=(0, 0, 90))
    myscreen.addActor(yar)
    zar = camvtk.Arrow(color=camvtk.blue, rotXYZ=(0, -90, 0))
    myscreen.addActor(zar)

    cl = cam.Point(2.1748, 1, 0)
    radius1 = 1
    radius2 = 0.25

    #tor.SetWireframe()
    #myscreen.addActor(tor)

    cyl = camvtk.Cylinder(center=(cl.x, cl.y, cl.z),
                          radius=radius1,
                          height=2,
                          color=(0, 1, 1),
                          rotXYZ=(90, 0, 0),
                          resolution=50)
    #myscreen.addActor(cyl)

    cl_line = camvtk.Line(p1=(cl.x, cl.y, -100),
                          p2=(cl.x, cl.y, +100),
                          color=camvtk.red)
    myscreen.addActor(cl_line)

    cl_tube = camvtk.Tube(p1=(cl.x, cl.y, -100),
                          p2=(cl.x, cl.y, +100),
                          radius=radius1,
                          color=camvtk.green)
    cl_tube.SetOpacity(0.1)
    myscreen.addActor(cl_tube)

    a_inf = a + (-100 * (b - a))
    b_inf = a + (+100 * (b - a))

    tube = camvtk.Tube(p1=(a_inf.x, a_inf.y, a_inf.z),
                       p2=(b_inf.x, b_inf.y, b_inf.z),
                       radius=0.05 * radius2,
                       color=camvtk.red)
    tube.SetOpacity(0.3)
    myscreen.addActor(tube)

    # cylindrical-cutter circle at z=0 plane
    #cir= camvtk.Circle(radius=radius1, center=(cl.x,cl.y,cl.z), color=camvtk.yellow)
    #myscreen.addActor(cir)

    #clp = camvtk.Point(center=(cl.x,cl.y,cl.z))
    #myscreen.addActor(clp)

    # short axis of ellipse = radius2
    # long axis of ellipse = radius2/sin(theta)
    # where theta is the slope of the line
    dx = b.x - a.x
    dz = b.z - a.z
    #print "dx=", dx
    #print "dz=", dz
    theta = math.atan(dz /
                      dx)  ## dx==0 is special case!! (i.e. vertical lines)
    print "theta=", theta
    a_axis = abs(radius2 / math.sin(theta))
    print "a=", a_axis
    # ellipse
    #a=2
    b_axis = radius2
    print "b= ", b_axis

    # slice the tube with a plane at z=0 and find the ellipse center
    # line is from Point a to b:
    # a + t*(b-a)
    # find t so that z-component is zero:
    # a.z + t( b.z -a.z) = 0
    # t= a.z / (b.z - a.z)
    # so point
    tparam = -a.z / (b.z - a.z)  # NOTE horizontal lines are a special case!!
    ellcenter = a + tparam * (b - a)
    print "ellcenter (z=0?) =", ellcenter
    # center of the
    # ecen_tmp=cam.Point(ellcenter,a.y,0)

    #drawellipse(myscreen, ellcenter, a_axis, b_axis)

    oe = cam.Ellipse(ellcenter, a_axis, b_axis, radius1)

    #oe2 = cam.Ellipse(ellcenter, a_axis, b_axis, 0.05) # to locate text on the outside of the ellipse

    nmax = 20
    #delta=0.05
    #td = 1

    t = camvtk.Text()
    t.SetPos((myscreen.width - 450, myscreen.height - 30))
    t.SetText("OpenCAMLib " +
              datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
    myscreen.addActor(t)

    t2 = camvtk.Text()
    ytext = "Y: %3.3f" % (ycoord)
    t2.SetText(ytext)
    t2.SetPos((50, myscreen.height - 150))
    myscreen.addActor(t2)

    #w2if = vtk.vtkWindowToImageFilter()
    #w2if.SetInput(myscreen.renWin)
    #lwr = vtk.vtkPNGWriter()
    #lwr.SetInput( w2if.GetOutput() )

    epos = cam.Epos()
    epos.setS(0, 1)

    #p5 = oe.ePoint(epos5)
    #pt = oe2.oePoint(epos5)
    #print "before= ", epos5.s, " , ", epos5.t

    # RUN THE SOLVER!
    nsteps = cam.Ellipse.solver(oe, cl)

    print "solver done. back to python:"
    print "1st (s,t) solution=", oe.epos1
    print "2st (s,t) solution=", oe.epos2

    elc1 = calcEcenter(oe, a, b, cl, 1)
    elc2 = calcEcenter(oe, a, b, cl, 2)
    print "elc1=", elc1
    print "elc2=", elc2
    #exit()

    #elc2 = elc2
    #epos = oe.epos2

    fe1 = cam.Ellipse(elc1, a_axis, b_axis, radius1)
    fe2 = cam.Ellipse(elc2, a_axis, b_axis, radius1)

    # draw ellipse-centers
    myscreen.addActor(
        camvtk.Sphere(center=(elc1.x, elc1.y, elc1.z),
                      radius=0.01,
                      color=camvtk.lgreen))
    myscreen.addActor(
        camvtk.Sphere(center=(elc2.x, elc2.y, elc2.z),
                      radius=0.01,
                      color=camvtk.pink))

    # cc-points on the ellipse
    ccp1 = fe1.ePoint(oe.epos1)
    ccp2 = fe2.ePoint(oe.epos2)
    myscreen.addActor(
        camvtk.Sphere(center=(ccp1.x, ccp1.y, ccp1.z),
                      radius=0.01,
                      color=camvtk.lgreen))
    myscreen.addActor(
        camvtk.Sphere(center=(ccp2.x, ccp2.y, ccp2.z),
                      radius=0.01,
                      color=camvtk.pink))

    cl1 = fe1.oePoint(oe.epos1)
    cl2 = fe2.oePoint(oe.epos2)

    # circles
    myscreen.addActor(
        camvtk.Circle(radius=radius1,
                      center=(cl1.x, cl1.y, cl1.z),
                      color=camvtk.green))
    myscreen.addActor(
        camvtk.Circle(radius=radius1,
                      center=(cl2.x, cl2.y, cl2.z),
                      color=camvtk.pink))

    # torus
    tor = camvtk.Toroid(r1=radius1,
                        r2=radius2,
                        center=(cl1.x, cl1.y, cl1.z),
                        rotXYZ=(0, 0, 0),
                        color=camvtk.green)
    tor.SetOpacity(0.4)
    myscreen.addActor(tor)
    tor = camvtk.Toroid(r1=radius1,
                        r2=radius2,
                        center=(cl2.x, cl2.y, cl2.z),
                        rotXYZ=(0, 0, 0),
                        color=camvtk.pink)
    tor.SetOpacity(0.4)
    myscreen.addActor(tor)

    # line: ellipse-center to cc-point
    myscreen.addActor(
        camvtk.Line(p1=(elc1.x, elc1.y, elc1.z),
                    p2=(ccp1.x, ccp1.y, ccp1.z),
                    color=camvtk.cyan))
    myscreen.addActor(
        camvtk.Line(p1=(elc2.x, elc2.y, elc2.z),
                    p2=(ccp2.x, ccp2.y, ccp2.z),
                    color=camvtk.cyan))

    # line: cc-point to cl-point
    myscreen.addActor(
        camvtk.Line(p1=(cl1.x, cl1.y, cl1.z),
                    p2=(ccp1.x, ccp1.y, ccp1.z),
                    color=camvtk.yellow))
    myscreen.addActor(
        camvtk.Line(p1=(cl2.x, cl2.y, cl2.z),
                    p2=(ccp2.x, ccp2.y, ccp2.z),
                    color=camvtk.yellow))

    # true cl
    #clt = cc1.

    #fclpoint = camvtk.Sphere(center=(fclp.x,fclp.y,fclp.z), radius=0.01, color=camvtk.blue)
    #myscreen.addActor(fclpoint)

    # line from ellipse center to fcc
    # the offset normal
    #myscreen.addActor(camvtk.Line( p1=(fclp.x,fclp.y,fclp.z),p2=(fccp.x,fccp.y,fccp.z), color=camvtk.yellow ))

    drawellipse(myscreen, elc1, a_axis, b_axis)
    drawellipse(myscreen, elc2, a_axis, b_axis)

    #convtext = "%i" % (nsteps)
    #print (pt.x, pt.y, pt.z)
    #center=(pt.x, pt.y, pt.z)
    #tst = camvtk.Text3D( color=(1,1,1), center=(pt.x, pt.y, 0)  ,
    #text=convtext, scale=0.02)
    #tst.SetCamera(myscreen.camera)
    #myscreen.addActor(tst)

    #colmax=11
    #colmin=4
    #nsteps = nsteps - colmin
    #colmax = colmax - colmin
    #convcolor=( float(nsteps*nsteps)/(colmax), float((colmax-nsteps))/colmax, 0 )
    #esphere = camvtk.Sphere(center=(p5.x,p5.y,0), radius=0.01, color=convcolor)
    #cce = oe.ePoint(epos)
    #cle = oe.oePoint(epos)
    #end_sphere = camvtk.Sphere(center=(cce.x,cce.y,0), radius=0.01, color=camvtk.green)
    #cl_sphere = camvtk.Sphere(center=(cle.x,cle.y,0), radius=0.01, color=camvtk.pink)
    #cl_sphere.SetOpacity(0.4)

    #clcir= camvtk.Circle(radius=radius1, center=(cle.x,cle.y,cle.z), color=camvtk.pink)
    #myscreen.addActor(clcir)

    #myscreen.addActor(esphere)
    #myscreen.addActor(end_sphere)
    #myscreen.addActor(cl_sphere)
    #myscreen.render()

    print "done."
    myscreen.render()
    lwr.SetFileName(filename)

    #raw_input("Press Enter to terminate")
    time.sleep(0.5)
    #lwr.Write()
    myscreen.iren.Start()
예제 #9
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)
예제 #10
0
def main(ycoord=0.970, filename="test"):
    myscreen = camvtk.VTKScreen()

    myscreen.camera.SetPosition(2, 5, 5)
    myscreen.camera.SetFocalPoint(1.38, 1, 0)

    #ycoord = 1.1

    a = cam.Point(3, ycoord, -2)
    b = cam.Point(-1, ycoord, 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)))
    #c=cam.Point(0,0,0.3)
    myscreen.addActor(camvtk.Line(p1=(a.x, a.y, a.z), p2=(b.x, b.y, b.z)))
    #t = cam.Triangle(a,b,c)

    cutter = cam.BullCutter(1, 0.2, 20)

    print(cutter)
    xar = camvtk.Arrow(color=camvtk.red, rotXYZ=(0, 0, 0))
    myscreen.addActor(xar)
    yar = camvtk.Arrow(color=camvtk.green, rotXYZ=(0, 0, 90))
    myscreen.addActor(yar)
    zar = camvtk.Arrow(color=camvtk.blue, rotXYZ=(0, -90, 0))
    myscreen.addActor(zar)

    cl = cam.Point(2.1748, 1, 0)
    radius1 = 1
    radius2 = 0.25

    tor = camvtk.Toroid(r1=radius1,
                        r2=radius2,
                        center=(cl.x, cl.y, cl.z),
                        rotXYZ=(0, 0, 0))
    #tor.SetWireframe()
    #myscreen.addActor(tor)

    cyl = camvtk.Cylinder(center=(cl.x, cl.y, cl.z),
                          radius=radius1,
                          height=2,
                          color=(0, 1, 1),
                          rotXYZ=(90, 0, 0),
                          resolution=50)
    #myscreen.addActor(cyl)

    cl_line = camvtk.Line(p1=(cl.x, cl.y, -100),
                          p2=(cl.x, cl.y, +100),
                          color=camvtk.red)
    myscreen.addActor(cl_line)

    tube = camvtk.Tube(p1=(a.x, a.y, a.z), p2=(b.x, b.y, b.z), color=(1, 1, 0))
    tube.SetOpacity(0.2)
    myscreen.addActor(tube)

    # cylindrical-cutter circle at z=0 plane
    #cir= camvtk.Circle(radius=radius1, center=(cl.x,cl.y,cl.z), color=camvtk.yellow)
    #myscreen.addActor(cir)

    #clp = camvtk.Point(center=(cl.x,cl.y,cl.z))
    #myscreen.addActor(clp)

    # short axis of ellipse = radius2
    # long axis of ellipse = radius2/sin(theta)
    # where theta is the slope of the line
    dx = b.x - a.x
    dz = b.z - a.z
    #print "dx=", dx
    #print "dz=", dz
    theta = math.atan(dz /
                      dx)  ## dx==0 is special case!! (i.e. vertical lines)
    print("theta=", theta)
    a_axis = abs(radius2 / math.sin(theta))
    print("a=", a_axis)
    # ellipse
    #a=2
    b_axis = radius2
    print("b= ", b_axis)

    # slice the tube with a plane at z=0 and find the ellipse center
    # line is from Point a to b:
    # a + t*(b-a)
    # find t so that z-component is zero:
    # a.z + t( b.z -a.z) = 0
    # t= a.z / (b.z - a.z)
    # so point
    tparam = -a.z / (b.z - a.z)  # NOTE horizontal lines are a special case!!
    ellcenter = a + tparam * (b - a)
    print("ellcenter (z=0?) =", ellcenter)
    # center of the
    # ecen_tmp=cam.Point(ellcenter,a.y,0)

    #drawellipse(myscreen, ellcenter, a_axis, b_axis)

    oe = cam.Ellipse(ellcenter, a_axis, b_axis, radius1)

    #oe2 = cam.Ellipse(ellcenter, a_axis, b_axis, 0.05) # to locate text on the outside of the ellipse

    nmax = 20
    #delta=0.05
    #td = 1

    t = camvtk.Text()
    t.SetPos((myscreen.width - 450, myscreen.height - 30))

    myscreen.addActor(t)
    t2 = camvtk.Text()
    ytext = "Y: %3.3f" % (ycoord)
    t2.SetText(ytext)
    t2.SetPos((50, myscreen.height - 150))
    myscreen.addActor(t2)

    #w2if = vtk.vtkWindowToImageFilter()
    #w2if.SetInput(myscreen.renWin)
    #lwr = vtk.vtkPNGWriter()
    #lwr.SetInput( w2if.GetOutput() )

    epos = cam.Epos()
    epos.setS(0, 1)
    #epos1.setS(0,1)

    t.SetText("OpenCAMLib 10.03-beta, " +
              datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))

    #p5 = oe.ePoint(epos5)
    #pt = oe2.oePoint(epos5)
    #print "before= ", epos5.s, " , ", epos5.t
    nsteps = cam.Ellipse.solver(oe, cl)
    epos = oe.epos1
    cce = oe.ePoint(epos)
    cle = oe.oePoint(epos)
    #epos2 = cam.Epos()
    #epos.s = epos.s
    #epos.t = epos.t
    #print nsteps
    print("solution1 at: ", epos.s, " , ", epos.t)
    #print "solution2 at: ", epos2.s , " , ", epos2.t
    print(" cl =", cl)
    print(" cle=", cle)

    xoffset = cl.x - cle.x
    print("xoffset= ", xoffset)
    # we slide xoffset along the x-axis from ellcenter
    # to find the correct z-plane
    # line is: a + t*(b-a)
    # find t so that x-component is ellcenter.x + xoffset
    # a.x + t(b.x-a.x) = ellcenter.x + xoffset
    # t= (ellcenter.x + xoffset - a.x) / (b.x - a.x)
    tparam2 = (ellcenter.x + xoffset - a.x) / (b.x - a.x)
    slide = tparam2 * (b - a)
    print("sliding z-delta: ", slide.z)
    elc2 = a + tparam2 * (b - a)
    print("ellcenter2=", elc2)
    #convlist.append(nsteps)
    fe = cam.Ellipse(elc2, a_axis, b_axis, radius1)
    fecen = camvtk.Sphere(center=(elc2.x, elc2.y, elc2.z),
                          radius=0.01,
                          color=camvtk.pink)
    myscreen.addActor(fecen)
    fccp = fe.ePoint(epos)
    fclp = fe.oePoint(epos)
    print("solver cl=", fclp, " == ", cl, " ??")

    fcir = camvtk.Circle(radius=radius1,
                         center=(cl.x, cl.y, elc2.z),
                         color=camvtk.yellow)
    myscreen.addActor(fcir)

    fccpoint = camvtk.Sphere(center=(fccp.x, fccp.y, fccp.z),
                             radius=0.01,
                             color=camvtk.green)
    myscreen.addActor(fccpoint)

    fclpoint = camvtk.Sphere(center=(fclp.x, fclp.y, fclp.z),
                             radius=0.01,
                             color=camvtk.blue)
    myscreen.addActor(fclpoint)

    # line from ellipse center to fcc
    myscreen.addActor(
        camvtk.Line(p1=(elc2.x, elc2.y, elc2.z),
                    p2=(fccp.x, fccp.y, fccp.z),
                    color=camvtk.cyan))
    # the offset normal
    myscreen.addActor(
        camvtk.Line(p1=(fclp.x, fclp.y, fclp.z),
                    p2=(fccp.x, fccp.y, fccp.z),
                    color=camvtk.yellow))

    drawellipse(myscreen, elc2, a_axis, b_axis)
    #convtext = "%i" % (nsteps)
    #print (pt.x, pt.y, pt.z)
    #center=(pt.x, pt.y, pt.z)
    #tst = camvtk.Text3D( color=(1,1,1), center=(pt.x, pt.y, 0)  ,
    #text=convtext, scale=0.02)
    #tst.SetCamera(myscreen.camera)
    #myscreen.addActor(tst)

    colmax = 11
    colmin = 4
    nsteps = nsteps - colmin
    colmax = colmax - colmin
    convcolor = (float(nsteps * nsteps) / (colmax), float(
        (colmax - nsteps)) / colmax, 0)
    #esphere = camvtk.Sphere(center=(p5.x,p5.y,0), radius=0.01, color=convcolor)
    end_sphere = camvtk.Sphere(center=(cce.x, cce.y, 0),
                               radius=0.01,
                               color=camvtk.green)
    cl_sphere = camvtk.Sphere(center=(cle.x, cle.y, 0),
                              radius=0.01,
                              color=camvtk.pink)
    cl_sphere.SetOpacity(0.4)

    clcir = camvtk.Circle(radius=radius1,
                          center=(cle.x, cle.y, cle.z),
                          color=camvtk.pink)
    myscreen.addActor(clcir)

    #myscreen.addActor(esphere)
    myscreen.addActor(end_sphere)
    myscreen.addActor(cl_sphere)
    #myscreen.render()

    print("done.")
    myscreen.render()
    lwr.SetFileName(filename)
    #lwr.Write()
    #raw_input("Press Enter to terminate")
    #time.sleep(0.5)
    myscreen.iren.Start()
예제 #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.
예제 #12
0
    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, 0, 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)
    s = ocl.STLSurf()
    s.addTriangle(t)  # a one-triangle STLSurf

    #cutter = ocl.CylCutter(0.31, 5)
    #cutter = ocl.BallCutter(0.4, 5)
    cutter = ocl.BullCutter(0.4, 0.1, 5)

    print "fiber..."

    zh = 0.23

    aloops = []
    awl = ocl.AdaptiveWaterline()
    #awl = ocl.Waterline()
    awl.setSTL(s)
    awl.setCutter(cutter)
    awl.setZ(zh)
    sampling = 0.1
    awl.setSampling(sampling)
    awl.setMinSampling(0.0001)
    t_before = time.time()
예제 #13
0
    myscreen = camvtk.VTKScreen()

    myscreen.camera.SetPosition(5, 3, 2)
    myscreen.camera.SetFocalPoint(1.38, 1, 0)

    a = cam.Point(3, 2, -2)
    b = cam.Point(-1, 2, 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)))
    #c=cam.Point(0,0,0.3)
    myscreen.addActor(camvtk.Line(p1=(a.x, a.y, a.z), p2=(b.x, b.y, b.z)))
    #t = cam.Triangle(a,b,c)

    cutter_length = 2
    cutter = cam.BullCutter(1, 0.2, cutter_length)

    print cutter

    xar = camvtk.Arrow(color=red, rotXYZ=(0, 0, 0))
    myscreen.addActor(xar)
    yar = camvtk.Arrow(color=green, rotXYZ=(0, 0, 90))
    myscreen.addActor(yar)
    zar = camvtk.Arrow(color=blue, rotXYZ=(0, -90, 0))
    myscreen.addActor(zar)

    cl = cam.Point(2.193, 1, 0)
    radius1 = 1
    radius2 = 0.25

    tor = camvtk.Toroid(r1=radius1,
    #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 / 2

    maxx = 10
    miny = -1
    dy = 1 / float(2)
    maxy = 13
    z = -1
    # this generates a list of CL-points in a grid
    clpoints = pyocl.CLPointGrid(minx, dx, maxx, miny, dy, maxy, z)
예제 #15
0
if __name__ == "__main__":
    myscreen = camvtk.VTKScreen()

    myscreen.camera.SetPosition(5, 3, 2)
    myscreen.camera.SetFocalPoint(1.38, 1, 0)

    a = cam.Point(3, 2, -2)
    b = cam.Point(-1, 2, 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)))
    #c=cam.Point(0,0,0.3)
    myscreen.addActor(camvtk.Line(p1=(a.x, a.y, a.z), p2=(b.x, b.y, b.z)))
    #t = cam.Triangle(a,b,c)

    cutter = cam.BullCutter(1, 0.2)

    print cutter.str()

    xar = camvtk.Arrow(color=red, rotXYZ=(0, 0, 0))
    myscreen.addActor(xar)
    yar = camvtk.Arrow(color=green, rotXYZ=(0, 0, 90))
    myscreen.addActor(yar)
    zar = camvtk.Arrow(color=blue, rotXYZ=(0, -90, 0))
    myscreen.addActor(zar)

    cl = cam.Point(2.193, 1, 0)
    radius1 = 1
    radius2 = 0.25

    tor = camvtk.Toroid(r1=radius1,
 a = ocl.Point(0,1,0.2)
 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)
예제 #17
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)
예제 #18
0
if __name__ == "__main__":
    myscreen = camvtk.VTKScreen()

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

    cutter = ocl.BullCutter(1, 0.2)
    #cutter = ocl.CylCutter(0.5)
    #cutter = ocl.BallCutter(1.5)

    print(ocl.revision())
    print(cutter)

    print("rendering...", )

    # insert code here to actually do something...

    print("done.")

    myscreen.camera.SetPosition(0.5, 3, 2)
    myscreen.camera.SetFocalPoint(0.5, 0.5, 0)
    myscreen.render()