예제 #1
0
 zvals = generateRange(zmin,zmax,zNmax)
 print(" calculating waterlines at ", len(zvals)," different z-heights")
 #print zvals
 bpc_x = ocl.BatchPushCutter()
 bpc_y = ocl.BatchPushCutter()
 bpc_x.setXDirection()
 bpc_y.setYDirection()
 bpc_x.setSTL(s)
 bpc_y.setSTL(s)
 bpc_x.setCutter(cutter)
 bpc_y.setCutter(cutter)
 # create fibers
 nfibers=0
 for zh in zvals:
     for y in yvals:
         f1 = ocl.Point(xmin,y,zh) # start point of fiber
         f2 = ocl.Point(xmax,y,zh)  # end point of fiber
         f =  ocl.Fiber( f1, f2)
         bpc_x.appendFiber(f)
         
         nfibers=nfibers+1
     for x in xvals:
         f1 = ocl.Point(x,ymin,zh) # start point of fiber
         f2 = ocl.Point(x,ymax,zh)  # end point of fiber
         f =  ocl.Fiber( f1, f2)
         bpc_y.appendFiber(f)
         
         nfibers=nfibers+1
 # run
 #t_before = time.time() 
 #bpc2.pushCutter2()
예제 #2
0
    for p in mpts:
        drawVertex(myscreen, p, camvtk.red, rad=1)

if __name__ == "__main__":  
    print ocl.revision()
    myscreen = camvtk.VTKScreen()
    myscreen.camera.SetPosition(0.01, 0,  1000 ) 
    myscreen.camera.SetFocalPoint(0, 0, 0)
    myscreen.camera.SetClippingRange(-100,3000)
    camvtk.drawOCLtext(myscreen)
    w2if = vtk.vtkWindowToImageFilter()
    w2if.SetInput(myscreen.renWin)
    lwr = vtk.vtkPNGWriter()
    lwr.SetInput( w2if.GetOutput() )

    c1 = Circle(c=ocl.Point(100,30), r=100, cw=1)
    c2 = Circle(c=ocl.Point(20,30), r=60, cw=1)
    
    drawCircle(myscreen, c1, camvtk.cyan)
    drawCircle(myscreen, c2, camvtk.cyan)
    c1c2 = CircleCircle(c1,c2)
    bicc = Bisector( c1c2 )
    drawBisector( myscreen, bicc )
    
    c1a = Circle(c=ocl.Point(100,30), r=100, cw=-1)
    c2a  = Circle(c=ocl.Point(20,30), r=60, cw=1)
    c1c2alt = CircleCircle(c1a,c2a)
    biccalt = Bisector( c1c2alt )
    drawBisector( myscreen, biccalt )

    
예제 #3
0
 def __init__(self,c=ocl.Point(0,0),r=1,cw=1):
     self.c = c
     self.r = r
     self.cw = cw # CW=1, CCW = -1
    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)]
    yfiber(yvals,t,zh,myscreen,cutter, color)
    xfiber(xvals,t,zh,myscreen,cutter, color)

if __name__ == "__main__":  
    print ocl.revision()
    myscreen = camvtk.VTKScreen()
    myscreen.camera.SetPosition(0.5, 3, 2)
    myscreen.camera.SetFocalPoint(0.5, 0.5, 0)
    camvtk.drawArrows(myscreen,center=(-0.5,-0.5,-0.5))
    camvtk.drawOCLtext(myscreen)
    
    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)
예제 #5
0
                              color=camvtk.lgreen))
            myscreen.addActor(
                camvtk.Sphere(center=(cc2.x, cc2.y, cc2.z),
                              radius=0.005,
                              color=camvtk.lgreen))
            # cutter circle
            #c1 = camvtk.Circle(center=(ip1.x,ip1.y,ip1.z), radius = 0.3/2, color=fibercolor)
            #myscreen.addActor(c1)
            #c2 = camvtk.Circle(center=(ip2.x,ip2.y,ip2.z), radius = 0.3/2, color=fibercolor)
            #myscreen.addActor(c2)


if __name__ == "__main__":
    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, 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)
    diameter = 0.2
    length = 5
    angle = math.pi / 4
    cutter = ocl.CylCutter(diameter, length)
    #cutter = ocl.BallCutter(diameter, length)
    #cutter = ocl.BullCutter(diameter, diameter/5, length)
예제 #6
0
    apdc.setSampling(0.4)
    apdc.setMinSampling(0.0008)
    print(" apdc sampling = ", apdc.getSampling())

    ymin = 0
    ymax = 50
    Ny = 40  # number of lines in the y-direction
    dy = float(ymax - ymin) / (Ny - 1)  # the y step-over

    # create a simple "Zig" pattern where we cut only in one direction.
    paths = []
    # create a list of paths
    for n in range(0, Ny):
        path = ocl.Path()
        y = ymin + n * dy  # current y-coordinate
        p1 = ocl.Point(0, y, 0)  # start-point of line
        p2 = ocl.Point(130, 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)

    cl_paths = []

    # we now have a list of paths to run through apdc
    t_before = time.time()
    n_aclp = 0
    for p in paths:
        aclp = adaptive_path_drop_cutter(
            s, cutter, p)  # the output is a list of Cutter-Locations
        n_aclp = n_aclp + len(aclp)
        cl_paths.append(aclp)
예제 #7
0
def main(filename="frame/f.png", yc=6, n=0):
    f = ocl.Ocode()
    f.set_depth(9)
    f.set_scale(5)

    myscreen = camvtk.VTKScreen()
    myscreen.camera.SetPosition(50, 22, 40)
    myscreen.camera.SetFocalPoint(0, 0, 0)
    myscreen.camera.Azimuth(n * 0.5)

    # 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)

    # screenshot writer
    w2if = vtk.vtkWindowToImageFilter()
    w2if.SetInput(myscreen.renWin)
    lwr = vtk.vtkPNGWriter()
    lwr.SetInput(w2if.GetOutput())
    arrowcenter = (1, 2, 0)
    xar = camvtk.Arrow(color=camvtk.red, center=arrowcenter, rotXYZ=(0, 0, 0))
    myscreen.addActor(xar)
    yar = camvtk.Arrow(color=camvtk.green,
                       center=arrowcenter,
                       rotXYZ=(0, 0, 90))
    myscreen.addActor(yar)
    zar = camvtk.Arrow(color=camvtk.blue,
                       center=arrowcenter,
                       rotXYZ=(0, -90, 0))
    myscreen.addActor(zar)
    """
    dl = myscreen.GetLights()
    print "original default light:"
    print dl
    print "nextitem()"
    l1 = dl.GetNextItem()
    print " light:"
    print l1
    #print myscreen.GetLights()
    
    lights = vtk.vtkLightCollection()
    l = myscreen.MakeLight()
    l2 = myscreen.MakeLight()
    #myscreen.RemoveAllLights()
    l.SetAmbientColor(0.5, 0.5, 0.5)
    l.SetPosition(0,0,20)  
    l.SetConeAngle(360)  
    l2.SetPosition(0,0,-20)  
    l2.SetConeAngle(360)
    l2.SetIntensity(0.5) 
    myscreen.AddLight(l)
    myscreen.AddLight(l2)
    #myscreen.SetLightCollection(lights)
    llist = myscreen.GetLights()
    li = llist.GetNextItem()
    print " new list of lights:"
    print li
    #for li in llist:
    #    print li
    print " newly created light:"
    print l
    
    dl = myscreen.GetLights()
    print "NEW light:"
    print dl
    """

    t = ocl.LinOCT()
    t2 = ocl.LinOCT()
    t.init(0)
    t2.init(1)

    #drawTree2(myscreen, t, opacity=0.2)
    #myscreen.render()
    #myscreen.iren.Start()
    #exit()

    print " after init() t :", t.str()
    print " after init() t2 :", t2.str()

    # sphere
    svol = ocl.SphereOCTVolume()
    svol.radius = 3.2
    svol.center = ocl.Point(1, 0, 3)
    svol.calcBB()

    # cube
    cube1 = ocl.CubeOCTVolume()
    cube1.side = 2.123
    cube1.center = ocl.Point(0, 0, 0)
    cube1.calcBB()

    #cylinder
    cylvol = ocl.CylinderOCTVolume()
    cylvol.p2 = ocl.Point(3, 4, -5)
    cylvol.radius = 2
    cylvol.calcBB()

    # draw exact cylinder
    cp = 0.5 * (cylvol.p1 + cylvol.p2)
    height = (cylvol.p2 - cylvol.p1).norm()
    cylvolactor = camvtk.Cylinder(center=(cp.x, cp.y,
                                          cp.z - float(height) / 2),
                                  radius=cylvol.radius,
                                  height=height,
                                  rotXYZ=(90, 0, 0))
    cylvolactor.SetWireframe()
    #myscreen.addActor(cylvolactor)

    c = ocl.CylCutter(2)
    c.length = 3
    print "cutter length=", c.length
    p1 = ocl.Point(-1, -2, 0)
    p2 = ocl.Point(1, 2.0, 0)
    g1vol = ocl.CylMoveOCTVolume(c, p1, p2)

    cyl1 = camvtk.Cylinder(center=(p1.x, p1.y, p1.z),
                           radius=c.radius,
                           height=c.length,
                           rotXYZ=(90, 0, 0),
                           color=camvtk.grey)
    cyl1.SetWireframe()
    myscreen.addActor(cyl1)
    cyl2 = camvtk.Cylinder(center=(p2.x, p2.y, p2.z),
                           radius=c.radius,
                           height=c.length,
                           rotXYZ=(90, 0, 0),
                           color=camvtk.grey)
    cyl2.SetWireframe()
    myscreen.addActor(cyl2)

    startp = camvtk.Sphere(center=(p1.x, p1.y, p1.z),
                           radius=0.1,
                           color=camvtk.green)
    myscreen.addActor(startp)

    endp = camvtk.Sphere(center=(p2.x, p2.y, p2.z),
                         radius=0.1,
                         color=camvtk.red)
    myscreen.addActor(endp)

    t.build(g1vol)
    t2.build(cube1)
    print "calling diff()...",
    dt = t2.operation(1, t)
    print "done."

    # set Cylinde bounding-box
    """
    cylvol.bb.maxx = 1.23
    cylvol.bb.minx = -0.2
    cylvol.bb.maxy = 1.23
    cylvol.bb.miny = -0.2
    cylvol.bb.maxz = 1.23
    cylvol.bb.minz = -0.2
    """
    drawBB(myscreen, g1vol)

    #print cylvol.bb.maxx

    #print "t2 build()"
    #t2.build(cube1)
    #print " t2 after build() ", t2.size()
    #t2.condense()
    #print " t2 after condense() ", t2.size()

    # original trees
    drawTree2(myscreen, t, opacity=1, color=camvtk.green)
    drawTree2(myscreen, t2, opacity=1, color=camvtk.cyan)
    drawTree2(myscreen, dt, opacity=1, color=camvtk.cyan, offset=(5, 0, 0))
    """
    for n in xrange(0,30):
        tp = ocl.Point(2.5,2.5,2-n*0.3)
        tpc = camvtk.black
        if (cylvol.isInside(tp)):
            tpc = camvtk.red
        else:
            tpc = camvtk.cyan
        tp_sphere = camvtk.Sphere(center=(tp.x,tp.y,tp.z), radius=0.1, color= tpc)
        myscreen.addActor(tp_sphere)
    """

    #drawTree(myscreen,t2,opacity=1, color=camvtk.red)

    #print " diff12()...",
    #t3 = t2.operation(1,t)
    #print "done."

    #print " diff21()...",
    #t4 = t2.operation(2,t)
    #print "done."

    #print " intersection()...",
    #t5 = t2.operation(3,t)
    #print "done."

    #print " sum()...",
    #t6 = t2.operation(4,t)
    #print "done."

    #print "  difference 1-2  t3 (blue) =", t3.size()
    #print " difference 2-1  t4 (yellow)=", t4.size()
    #print "     intersection t5 (pink) =", t5.size()
    #print "            union t6 (grey) =", t6.size()

    #drawTree(myscreen,t3,opacity=1, color=camvtk.blue, offset=(0,15,0))
    #drawTree(myscreen,t4,opacity=1, color=camvtk.yellow,offset=(0,-15,0))
    #drawTree(myscreen,t5,opacity=1, color=camvtk.pink,offset=(-15,0,0))
    #drawTree(myscreen,t6,opacity=1, color=camvtk.grey,offset=(-15,-15,0))

    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)

    #st2 = camvtk.Text()
    #ytext = "Linear OCTree set operations: difference, intersection, union"
    #st2.SetText(ytext)
    #st2.SetPos( (50, myscreen.height-30) )
    #myscreen.addActor( st2)

    #st3 = camvtk.Text()
    #text = "Original OCTrees\n  Ball:%d nodes\n  Cube: %d nodes" % ( t.size(), t2.size() )
    #st3.SetText(text)
    #st3.SetPos( (50, 200) )
    #myscreen.addActor( st3)

    #st4 = camvtk.Text()
    #un = " Union (grey): %d nodes\n" % (t6.size())
    #int = " Intersection (pink): %d nodes\n"  % (t5.size())
    #diff1 = " difference Cube-Ball (blue): %d nodes\n"  % (t3.size())
    #diff2 = " difference Ball-Cube (yellow): %d nodes\n"  % (t4.size())
    #text= un+int+diff1+diff2
    #st4.SetText(text)
    #st4.SetPos( (50, 100) )
    #myscreen.addActor( st4)

    print " render()...",
    myscreen.render()
    print "done."
    lwr.SetFileName(filename)
    time.sleep(0.2)
    #lwr.Write()

    myscreen.iren.Start()
예제 #8
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 = []
        f2 = ocl.Point(x, 1.5, zh)  # end point of fiber
        f = ocl.Fiber(f1, f2)
        i = ocl.Interval()
        cutter.pushCutter(f, i, t)
        f.addInterval(i)
        drawFiber_clpts(myscreen, f, camvtk.lblue)


if __name__ == "__main__":
    print ocl.revision()
    myscreen = camvtk.VTKScreen()
    #a = ocl.Point(0,1,0.3)
    #b = ocl.Point(1,0.5,0.0)
    #c = ocl.Point(0.1,0.1,-2.0)

    a = ocl.Point(0, 1, 0.3)
    b = ocl.Point(1, 0.5, 0.3)
    c = ocl.Point(0.2, 0.2, 0.1)

    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
    #cutter = ocl.BallCutter(diameter, length)
    #cutter = ocl.CylCutter(diameter, length)
예제 #10
0

def drawVertices(myscreen, weave, vertexType, vertexRadius, vertexColor):
    pts = weave.getVertices(vertexType)
    print(" got ", len(pts), " of type ", vertexType)
    for p in pts:
        myscreen.addActor(
            camvtk.Sphere(center=(p.x, p.y, p.z),
                          radius=vertexRadius,
                          color=vertexColor))


if __name__ == "__main__":
    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, 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)) )

    # a second triangle
    offset = ocl.Point(0.51, 0.51, 0)
    a2 = a + offset
    b2 = b + offset
    c2 = c + offset
    t2 = ocl.Triangle(b2, c2, a2)
예제 #11
0
    def execute(self, obj):
        import MeshPart
        FreeCAD.Console.PrintWarning(
            translate("PathSurface", "Hold on.  This might take a minute.\n"))
        output = ""
        if obj.Comment != "":
            output += '(' + str(obj.Comment) + ')\n'

        toolLoad = PathUtils.getLastToolLoad(obj)
        if toolLoad is None or toolLoad.ToolNumber == 0:
            self.vertFeed = 100
            self.horizFeed = 100
            self.vertRapid = 100
            self.horizRapid = 100
            self.radius = 0.25
            obj.ToolNumber = 0
            obj.ToolDescription = "UNDEFINED"
        else:
            self.vertFeed = toolLoad.VertFeed.Value
            self.horizFeed = toolLoad.HorizFeed.Value
            self.vertRapid = toolLoad.VertRapid.Value
            self.horizRapid = toolLoad.HorizRapid.Value
            tool = PathUtils.getTool(obj, toolLoad.ToolNumber)
            if tool.Diameter == 0:
                self.radius = 0.25
            else:
                self.radius = tool.Diameter / 2
            obj.ToolNumber = toolLoad.ToolNumber
            obj.ToolDescription = toolLoad.Name

        if obj.UserLabel == "":
            obj.Label = obj.Name + " :" + obj.ToolDescription
        else:
            obj.Label = obj.UserLabel + " :" + obj.ToolDescription

        output += "(" + obj.Label + ")"
        output += "(Compensated Tool Path. Diameter: " + str(
            self.radius * 2) + ")"

        # if obj.Base:
        #     for b in obj.Base:

        parentJob = PathUtils.findParentJob(obj)
        if parentJob is None:
            return
        mesh = parentJob.Base
        if mesh is None:
            return
        print "base object: " + mesh.Name

        if obj.Algorithm in ['OCL Dropcutter', 'OCL Waterline']:
            try:
                import ocl
            except:
                FreeCAD.Console.PrintError(
                    translate(
                        "PathSurface",
                        "This operation requires OpenCamLib to be installed.\n"
                    ))
                return

        #mesh = b[0]
        if mesh.TypeId.startswith('Mesh'):
            mesh = mesh.Mesh
            bb = mesh.BoundBox
        else:
            bb = mesh.Shape.BoundBox
            mesh = MeshPart.meshFromShape(mesh.Shape, MaxLength=2)

        s = ocl.STLSurf()
        for f in mesh.Facets:
            p = f.Points[0]
            q = f.Points[1]
            r = f.Points[2]
            t = ocl.Triangle(ocl.Point(p[0], p[1], p[2]),
                             ocl.Point(q[0], q[1], q[2]),
                             ocl.Point(r[0], r[1], r[2]))
            s.addTriangle(t)

        if obj.Algorithm == 'OCL Dropcutter':
            output = self._dropcutter(obj, s, bb)
        elif obj.Algorithm == 'OCL Waterline':
            output = self._waterline(obj, s, bb)

        if obj.Active:
            path = Path.Path(output)
            obj.Path = path
            obj.ViewObject.Visibility = True

        else:
            path = Path.Path("(inactive operation)")
            obj.Path = path
            obj.ViewObject.Visibility = False
예제 #12
0
def main():  
    print ocl.revision()
    myscreen = camvtk.VTKScreen()   
    myscreen.camera.SetPosition(-15, -8, 15)
    myscreen.camera.SetFocalPoint(0,0, 0)   
    # axis arrows
    camvtk.drawArrows(myscreen,center=(0,0,0))

    s = ocl.SphereOCTVolume()
    s.center = ocl.Point(-2.50,-0.6,0)
    s.radius = 0.6345
    
    #sphere = camvtk.Sphere( center=(s.center.x,s.center.y,s.center.z), radius=s.radius, color=camvtk.cyan)
    #sphere.SetOpacity(0.1)
    #myscreen.addActor( sphere );
    
    
    # screenshot writer
    w2if = vtk.vtkWindowToImageFilter()
    w2if.SetInput(myscreen.renWin)
    lwr = vtk.vtkPNGWriter()
    lwr.SetInput( w2if.GetOutput() )
    
    # text
    #camvtk.drawOCLtext(myscreen)
    #octtext = camvtk.Text()
    #octtext.SetPos( (myscreen.width-400, myscreen.height-290) )
    #myscreen.addActor( octtext)

    
    
    cp= ocl.Point(0,0,-3)
    #depths = [3, 4, 5, 6, 7, 8]
    max_depth = 7
    root_scale = 3
    t = ocl.Octree(root_scale, max_depth, cp)
    t.init(4)
    n = 0 # the frame number
    nmax=200
    theta=0
    dtheta=0.1
    
    s.center =  ocl.Point( 2*math.cos(theta),1*math.sin(theta),0.01*theta)  
    
    mc = ocl.MarchingCubes()
   
    
    while (n<=nmax):
        print "diff...",
        t_before = time.time() 
        t.diff_negative(s)
        t_after = time.time() 
        build_time = t_after-t_before
        print "done in ", build_time," s"
        #infotext= "Octree + Marching-Cubes test\nmax octree-depth:%i \ntriangles: %i \nbuild() time: %f ms" % (max_depth, 
        #                                                  len(tris), build_time*1e3 )
        #octtext.SetText(infotext)
        
        if n==nmax:
            t_before = time.time() 
            print "mc()...",
            tris = mc.mc_tree(t) 
            t_after = time.time() 
            mc_time = t_after-t_before
            print "done in ", mc_time," s"
            print " mc() got ", len(tris), " triangles"
            mc_surf = camvtk.STLSurf( triangleList=tris, color=camvtk.red )
            mc_surf.SetWireframe()
            mc_surf.SetColor(camvtk.cyan)
            print " STLSurf()...",
            myscreen.addActor( mc_surf )
            print "done."
            print " render()...",
            myscreen.render()

            print "done."

            #lwr.SetFileName("frames/mc8_frame"+ ('%06d' % n)+".png")
            #myscreen.camera.Azimuth( 2 )
            #myscreen.render()
            #w2if.Modified() 
            #lwr.Write()
                
            #mc_surf.SetWireframe()
            #print "sleep...",
            #time.sleep(1.02)
            #print "done."
                
            
            if n is not nmax:
                myscreen.removeActor( mc_surf )
                #myscreen.removeActor( oct_points )
        
        # move forward
        theta = n*dtheta
        s.center =  ocl.Point( 2*math.cos(theta),1*math.sin(theta),-0.1*theta)  
        print "center moved to", s.center
        n=n+1
    print "All done."
    myscreen.iren.Start() 
예제 #13
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
예제 #14
0
        f = ocl.Fiber(f1, f2)
        i = ocl.Interval()
        cutter.pushCutter(f, i, t)
        f.addInterval(i)
        drawFiber_clpts(myscreen, f, camvtk.lblue)


if __name__ == "__main__":
    print(ocl.version())
    myscreen = camvtk.VTKScreen()

    ztri = 0.3  # this is the shallow case
    #ztri = 0.8 # this produces the steep case where we hit the circular rim

    ztri_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)

    a = ocl.Point(0, 1, 0.3)
    b = ocl.Point(1, 0.5, 0.3)
    c = ocl.Point(0, 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 / 5
예제 #15
0
 def eTang(self, epos):
     p = cam.Point(-self.a * epos.t, self.b * epos.s, 0)
     p.normalize()
     return p
예제 #16
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()
예제 #17
0
def main(filename="frame/f.png", yc=6, n=0):
    print(ocl.revision())

    f = ocl.Ocode()
    f.set_depth(7)
    f.set_scale(1)

    myscreen = camvtk.VTKScreen()
    myscreen.camera.SetPosition(50, 22, 40)
    myscreen.camera.SetFocalPoint(0, 0, 0)
    myscreen.camera.Azimuth(n * 0.5)

    # 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)

    # screenshot writer
    w2if = vtk.vtkWindowToImageFilter()
    w2if.SetInput(myscreen.renWin)
    lwr = vtk.vtkPNGWriter()
    lwr.SetInput(w2if.GetOutput())
    arrowcenter = (1, 2, 0)
    xar = camvtk.Arrow(color=camvtk.red, center=arrowcenter, rotXYZ=(0, 0, 0))
    myscreen.addActor(xar)
    yar = camvtk.Arrow(color=camvtk.green,
                       center=arrowcenter,
                       rotXYZ=(0, 0, 90))
    myscreen.addActor(yar)
    zar = camvtk.Arrow(color=camvtk.blue,
                       center=arrowcenter,
                       rotXYZ=(0, -90, 0))
    myscreen.addActor(zar)

    t = ocl.LinOCT()
    t2 = ocl.LinOCT()
    t.init(0)
    #exit()
    t2.init(2)

    #drawTree2(myscreen, t, opacity=0.2)
    #myscreen.render()
    #myscreen.iren.Start()
    #exit()

    print(" after init() t :", t.str())
    #print " after init() t2 :", t2.str()

    # sphere
    svol = ocl.SphereOCTVolume()
    svol.radius = 1
    svol.center = ocl.Point(0, 0, 1)
    svol.calcBB()

    # cube
    cube1 = ocl.CubeOCTVolume()
    cube1.side = 2.123
    cube1.center = ocl.Point(0, 0, 0)
    cube1.calcBB()

    #cylinder
    cylvol = ocl.CylinderOCTVolume()
    cylvol.p2 = ocl.Point(1, 5, -2)
    cylvol.radius = 0.4
    cylvol.calcBB()

    # draw exact cylinder
    cp = 0.5 * (cylvol.p1 + cylvol.p2)
    height = (cylvol.p2 - cylvol.p1).norm()
    cylvolactor = camvtk.Cylinder(center=(cp.x, cp.y,
                                          cp.z - float(height) / 2),
                                  radius=cylvol.radius,
                                  height=height,
                                  rotXYZ=(90, 0, 0))
    cylvolactor.SetWireframe()
    #myscreen.addActor(cylvolactor)

    c = ocl.CylCutter(1)
    c.length = 3
    print("cutter length=", c.length)
    p1 = ocl.Point(0.2, 0.2, 0)
    p2 = ocl.Point(1.5, 1.5, -1)
    g1vol = ocl.CylMoveOCTVolume(c, p1, p2)

    cyl1 = camvtk.Cylinder(center=(p1.x, p1.y, p1.z),
                           radius=c.radius,
                           height=c.length,
                           rotXYZ=(90, 0, 0),
                           color=camvtk.grey)
    cyl1.SetWireframe()
    myscreen.addActor(cyl1)
    cyl2 = camvtk.Cylinder(center=(p2.x, p2.y, p2.z),
                           radius=c.radius,
                           height=c.length,
                           rotXYZ=(90, 0, 0),
                           color=camvtk.grey)
    cyl2.SetWireframe()
    myscreen.addActor(cyl2)

    startp = camvtk.Sphere(center=(p1.x, p1.y, p1.z),
                           radius=0.1,
                           color=camvtk.green)
    myscreen.addActor(startp)

    endp = camvtk.Sphere(center=(p2.x, p2.y, p2.z),
                         radius=0.1,
                         color=camvtk.red)
    myscreen.addActor(endp)

    #t.build( g1vol )
    t_before = time.time()
    #t.build( g1vol )
    t.build(svol)
    t_after = time.time()
    print("build took ", t_after - t_before, " s")

    t_before = time.time()
    t2.build(cube1)
    t_after = time.time()
    print("build took ", t_after - t_before, " s")

    #t.sort()
    #t2.sort()

    print("calling diff()...", )
    t_before = time.time()
    #dt = t2.operation(1,t)
    t2.diff(t)
    t_after = time.time()
    print("done.")
    print("diff took ", t_after - t_before, " s")

    print("diff has ", t2.size(), " nodes")

    #drawBB( myscreen, g1vol)
    #print "drawBB() done"

    # original trees
    print("drawing trees")
    drawTree2(myscreen, t, opacity=1, color=camvtk.green)
    drawTree2(myscreen, t2, opacity=0.2, color=camvtk.cyan)
    drawTree2(myscreen, t2, opacity=1, color=camvtk.cyan, offset=(5, 0, 0))

    # box-volume
    #cor = g1vol.box.corner
    #v1 = g1vol.box.v1 + cor
    #v2 = g1vol.box.v2 + cor
    #v3 = g1vol.box.v3 + cor
    #myscreen.addActor( camvtk.Sphere(center=(cor.x,cor.y,cor.z), radius=0.1, color=camvtk.red) )
    #myscreen.addActor( camvtk.Sphere(center=(v1.x,v1.y,v1.z), radius=0.1, color=camvtk.blue) )
    #myscreen.addActor( camvtk.Sphere(center=(v2.x,v2.y,v2.z), radius=0.1, color=camvtk.cyan) )
    #myscreen.addActor( camvtk.Sphere(center=(v3.x,v3.y,v3.z), radius=0.1, color=camvtk.pink) )

    # elliptical tube
    pmax = p1 + 1.5 * (p2 - p1)
    pmin = p1 - 0.5 * (p2 - p1)
    myscreen.addActor(
        camvtk.Sphere(center=(pmax.x, pmax.y, pmax.z),
                      radius=0.1,
                      color=camvtk.lgreen))
    myscreen.addActor(
        camvtk.Sphere(center=(pmin.x, pmin.y, pmin.z),
                      radius=0.1,
                      color=camvtk.pink))
    aaxis = pmin + ocl.Point(-0.353553, 0.353553, 0)
    baxis = pmin + ocl.Point(0.0243494, 0.0243494, 0.126617)
    myscreen.addActor(
        camvtk.Sphere(center=(aaxis.x, aaxis.y, aaxis.z),
                      radius=0.1,
                      color=camvtk.orange))
    myscreen.addActor(
        camvtk.Sphere(center=(baxis.x, baxis.y, baxis.z),
                      radius=0.1,
                      color=camvtk.yellow))

    ##camvtk.Cylinder(center=(pmin.x,pmin.y,pmin.z), radius=0.1, color=camvtk.pink)
    """
    for n in range(0,30):
        tp = ocl.Point(2.5,2.5,2-n*0.3)
        tpc = camvtk.black
        if (cylvol.isInside(tp)):
            tpc = camvtk.red
        else:
            tpc = camvtk.cyan
        tp_sphere = camvtk.Sphere(center=(tp.x,tp.y,tp.z), radius=0.1, color= tpc)
        myscreen.addActor(tp_sphere)
    """

    #drawTree(myscreen,t2,opacity=1, color=camvtk.red)

    #print " diff12()...",
    #t3 = t2.operation(1,t)
    #print "done."

    #print " diff21()...",
    #t4 = t2.operation(2,t)
    #print "done."

    #print " intersection()...",
    #t5 = t2.operation(3,t)
    #print "done."

    #print " sum()...",
    #t6 = t2.operation(4,t)
    #print "done."

    #print "  difference 1-2  t3 (blue) =", t3.size()
    #print " difference 2-1  t4 (yellow)=", t4.size()
    #print "     intersection t5 (pink) =", t5.size()
    #print "            union t6 (grey) =", t6.size()

    #drawTree(myscreen,t3,opacity=1, color=camvtk.blue, offset=(0,15,0))
    #drawTree(myscreen,t4,opacity=1, color=camvtk.yellow,offset=(0,-15,0))
    #drawTree(myscreen,t5,opacity=1, color=camvtk.pink,offset=(-15,0,0))
    #drawTree(myscreen,t6,opacity=1, color=camvtk.grey,offset=(-15,-15,0))

    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)

    #st2 = camvtk.Text()
    #ytext = "Linear OCTree set operations: difference, intersection, union"
    #st2.SetText(ytext)
    #st2.SetPos( (50, myscreen.height-30) )
    #myscreen.addActor( st2)

    #st3 = camvtk.Text()
    #text = "Original OCTrees\n  Ball:%d nodes\n  Cube: %d nodes" % ( t.size(), t2.size() )
    #st3.SetText(text)
    #st3.SetPos( (50, 200) )
    #myscreen.addActor( st3)

    #st4 = camvtk.Text()
    #un = " Union (grey): %d nodes\n" % (t6.size())
    #int = " Intersection (pink): %d nodes\n"  % (t5.size())
    #diff1 = " difference Cube-Ball (blue): %d nodes\n"  % (t3.size())
    #diff2 = " difference Ball-Cube (yellow): %d nodes\n"  % (t4.size())
    #text= un+int+diff1+diff2
    #st4.SetText(text)
    #st4.SetPos( (50, 100) )
    #myscreen.addActor( st4)

    print(" render()...", )
    myscreen.render()
    print("done.")
    lwr.SetFileName(filename)
    time.sleep(0.2)
    #lwr.Write()

    myscreen.iren.Start()
예제 #18
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) + "F " + PathUtils.fmt(
                self.vertRapid) + "\n"
        output += "G0 X" + str(clp[0].x) + " Y" + str(
            clp[0].y) + "F " + PathUtils.fmt(self.horizRapid) + "\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
import ocl
import pyocl  # pyocl.CLPointGrid()
import camvtk
import vtk
import math

if __name__ == "__main__":
    print(ocl.version())
    myscreen = camvtk.VTKScreen()

    a = ocl.Point(1, 0.6, 0.1)
    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.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)
    radius1 = 1
    angle = math.pi / 4
    #cutter = ocl.ConeCutter(0.37, angle)
    #cutter = ocl.BallCutter(0.532)
    #cutter = ocl.CylCutter(0.3)
    #cutter = ocl.BullCutter(1,0.2)

    #cutter = ocl.CylConeCutter(0.2,0.5,math.pi/9)
    #cutter =  ocl.BallConeCutter(0.4,0.6,math.pi/9)
예제 #20
0
    def execute(self, obj):
        import MeshPart
        FreeCAD.Console.PrintWarning(
            translate("Path_Surface", "Hold on.  This might take a minute.\n"))
        output = ""
        if obj.Comment != "":
            output += '(' + str(obj.Comment) + ')\n'

        toolLoad = obj.ToolController
        if toolLoad is None or toolLoad.ToolNumber == 0:
            FreeCAD.Console.PrintError(
                "No Tool Controller is selected. We need a tool to build a Path."
            )
        else:
            self.vertFeed = toolLoad.VertFeed.Value
            self.horizFeed = toolLoad.HorizFeed.Value
            self.vertRapid = toolLoad.VertRapid.Value
            self.horizRapid = toolLoad.HorizRapid.Value
            tool = toolLoad.Proxy.getTool(toolLoad)
            if not tool or tool.Diameter == 0:
                FreeCAD.Console.PrintError(
                    "No Tool found or diameter is zero. We need a tool to build a Path."
                )
                return
            else:
                self.radius = tool.Diameter / 2

        output += "(" + obj.Label + ")"
        output += "(Compensated Tool Path. Diameter: " + str(
            self.radius * 2) + ")"

        # if obj.Base:
        #     for b in obj.Base:

        parentJob = PathUtils.findParentJob(obj)
        if parentJob is None:
            return
        mesh = parentJob.Base
        if mesh is None:
            return
        print("base object: " + mesh.Name)

        if obj.Algorithm in ['OCL Dropcutter', 'OCL Waterline']:
            try:
                import ocl
            except:
                FreeCAD.Console.PrintError(
                    translate(
                        "Path_Surface",
                        "This operation requires OpenCamLib to be installed.\n"
                    ))
                return

        if mesh.TypeId.startswith('Mesh'):
            mesh = mesh.Mesh
        else:
            # try/except is for Path Jobs created before GeometryTolerance
            try:
                deflection = parentJob.GeometryTolerance
            except AttributeError:
                from PathScripts.PathPreferences import PathPreferences
                deflection = PathPreferences.defaultGeometryTolerance()

            mesh = MeshPart.meshFromShape(mesh.Shape, Deflection=deflection)

        bb = mesh.BoundBox

        s = ocl.STLSurf()
        for f in mesh.Facets:
            p = f.Points[0]
            q = f.Points[1]
            r = f.Points[2]
            t = ocl.Triangle(ocl.Point(p[0], p[1], p[2]),
                             ocl.Point(q[0], q[1], q[2]),
                             ocl.Point(r[0], r[1], r[2]))
            s.addTriangle(t)

        if obj.Algorithm == 'OCL Dropcutter':
            output = self._dropcutter(obj, s, bb)
        elif obj.Algorithm == 'OCL Waterline':
            output = self._waterline(obj, s, bb)

        if obj.Active:
            path = Path.Path(output)
            obj.Path = path
            obj.ViewObject.Visibility = True

        else:
            path = Path.Path("(inactive operation)")
            obj.Path = path
            obj.ViewObject.Visibility = False
import math

if __name__ == "__main__":
    print ocl.version()  # print out git version tag

    # set up VTK visualization
    myscreen = camvtk.VTKScreen()
    myscreen.setAmbient(20, 20, 20)
    myscreen.camera.SetPosition(4, 4, 3)
    myscreen.camera.SetFocalPoint(0.6, 0.6, 0)
    myscreen.setAmbient(1, 1, 1)

    #camvtk.drawArrows(myscreen)

    # three corners of a triangle
    a = ocl.Point(1, 0, -0.000010)
    b = ocl.Point(0, 1, +0.0)
    c = ocl.Point(0.001, 0, +0.3001)
    #c = ocl.Point(0,0,0.3)
    t = ocl.Triangle(a, b, c)

    # draw the triangle with VTK
    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)))

    # Define a cutter
    angle = math.pi / 8
예제 #22
0
    zh = 1.9
    cutter_diams = generateRange(0.1, 6, 5)
    loops = []
    length = 20  # cutter length
    for diam in cutter_diams:
        cutter = ocl.CylCutter(diam, length)
        cutter_loops = waterline(cutter, s, zh, 0.05)
        for l in cutter_loops:
            loops.append(l)

    print "All waterlines done. Got", len(loops), " loops in total."
    # draw the loops
    for lop in loops:
        n = 0
        N = len(lop)
        first_point = ocl.Point(-1, -1, 5)
        previous = ocl.Point(-1, -1, 5)
        for p in lop:
            if n == 0:  # don't draw anything on the first iteration
                previous = p
                first_point = p
            elif n == (N - 1):  # the last point
                myscreen.addActor(
                    camvtk.Line(p1=(previous.x, previous.y, previous.z),
                                p2=(p.x, p.y, p.z),
                                color=camvtk.yellow))  # the normal line
                # and a line from p to the first point
                myscreen.addActor(
                    camvtk.Line(p1=(p.x, p.y, p.z),
                                p2=(first_point.x, first_point.y,
                                    first_point.z),
예제 #23
0
def main(filename="frame/f.png"):
    print(ocl.revision())

    myscreen = camvtk.VTKScreen()
    myscreen.camera.SetPosition(-15, -8, 15)
    myscreen.camera.SetFocalPoint(5, 5, 0)
    # axis arrows
    camvtk.drawArrows(myscreen, center=(0, 0, 0))

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

    c = ocl.CylCutter(3, 10)  # cutter
    c.length = 3
    print("cutter length=", c.length)

    cp = ocl.Point(0, 0, 0)
    max_depth = 9
    root_scale = 3
    t = ocl.Octree(root_scale, max_depth, cp)
    print(t)

    nodes = t.get_leaf_nodes()
    t.init(1)
    #nodes=[]
    s = ocl.SphereOCTVolume()
    s.center = ocl.Point(0, 0, 0)
    s.radius = 2.6345
    print("build...", )
    t.build(s)
    print("done.")
    print(t)

    sphere = camvtk.Sphere(center=(s.center.x, s.center.y, s.center.z),
                           radius=s.radius,
                           color=camvtk.cyan)
    sphere.SetOpacity(0.1)
    myscreen.addActor(sphere)

    nodes = t.get_surface_nodes()
    print("got ", len(nodes), " surface nodes")

    points = []
    for n in nodes:
        #n=nodes[0]
        verts = n.vertices()
        #c = n.center
        #print " node at depth=", n.depth," center=",c
        #myscreen.addActor( camvtk.Sphere( center=(c.x,c.y,c.z), radius=0.1, color=camvtk.yellow ))
        for v in verts:
            #print v
            #myscreen.addActor( camvtk.Sphere( center=(v.x,v.y,v.z), radius=0.1 ))
            #
            points.append(v)

    #myscreen.addActor( camvtk.PointCloud( pointlist= points))

    tris = t.mc_triangles()
    mc_surf = camvtk.STLSurf(triangleList=tris, color=camvtk.red)
    #mc_surf.SetWireframe()
    myscreen.addActor(mc_surf)
    print(" render()...", )
    myscreen.render()
    print("done.")

    #time.sleep(0.2)

    myscreen.iren.Start()
예제 #24
0
        # check endcondition
        if abs(current_error) < 1e-8:
            endcondition = 1
        if n > 125:
            endcondition = 1
        n = n + 1
    return n


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_length = 2
    cutter = cam.BullCutter(1, 0.2, cutter_length)

    print(cutter)

    xar = camvtk.Arrow(color=red, rotXYZ=(0, 0, 0))
    #xar.SetFlat()
예제 #25
0
import ocl
import camvtk
import time
import vtk
import datetime
import math

if __name__ == "__main__":  
    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,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]
    cutter_diams = [0.6] # run the thing for all these cutter diameters
    length = 5
    loops = []
    cutter = ocl.CylCutter( 1 , 1 )   
    
    t_total = time.time() 
예제 #26
0
 def ePoint(self, epos):
     # return a point on the ellipse
     p = cam.Point()
     p.x = self.ecen.x + self.a * epos.s
     p.y = self.ecen.y + self.b * epos.t
     return p
예제 #27
0
def drawLine(myscreen, l, lineColor):
    # a x + b y + c = 0
    # x = -c/a
    p1 = 100*ocl.Point( -l.c/l.a , 0 )
    p2 = 100*ocl.Point( 0, -l.c/l.b )
    myscreen.addActor( camvtk.Line( p1=( p1.x,p1.y,p1.z), p2=(p2.x,p2.y,p2.z), color=lineColor ) )
예제 #28
0
 def eNorm(self, epos):
     normal = cam.Point(self.b * epos.s, self.a * epos.t, 0)
     normal.normalize()
     return normal
예제 #29
0
def main():
    myscreen = camvtk.VTKScreen()
    focal = cam.Point(50, 0, 0)
    r = 300
    theta = (float(45) / 360) * 2 * math.pi
    fi = 45

    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)

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

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

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

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

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

    #ycoord = 1.1

    stl = camvtk.STLSurf(filename="../stl/demo.stl")
    #stl = camvtk.STLSurf(filename="../stl/demo2.stl")
    print("STL surface read")
    #myscreen.addActor(stl)
    #stl.SetWireframe()
    #stl.SetColor((0.5,0.5,0.5))
    polydata = stl.src.GetOutput()
    s = cam.STLSurf()
    camvtk.vtkPolyData2OCLSTL(polydata, s)
    print("STLSurf with ", s.size(), " triangles")

    myscreen.addActor(
        camvtk.Sphere(center=(0, 0, 0), radius=0.2, color=camvtk.yellow))

    s.build_kdtree()
    print("built kd-tree")
    s.jump_kd_reset()

    tlist = s.get_kd_triangles()

    print("got", len(tlist), " triangles")

    while (s.jump_kd_hi()):
        lotris = s.get_kd_triangles()
        s.jump_kd_up()
        cut = s.get_kd_cut()
        s.jump_kd_lo()
        hitris = s.get_kd_triangles()
        lev = s.get_kd_level()

        print("l=", lev, " hi=", len(hitris), " lo=", len(lotris), " cut=",
              cut)

        if (cut[0] < 2):
            print("x cut ", )
            if (cut[0] == 0):
                print("max")
                myscreen.addActor(
                    camvtk.Line(p1=(cut[1], 100, 0),
                                p2=(cut[1], -100, 0),
                                color=camvtk.green))
            else:
                print("min")
                myscreen.addActor(
                    camvtk.Line(p1=(cut[1], 100, 0),
                                p2=(cut[1], -100, 0),
                                color=camvtk.lgreen))
            #myscreen.addActor( camvtk.Line( p1=(100,cut[1],0), p2=(-100,cut[1],0), color = camvtk.red ) )
        else:
            print("y cut ", )
            if (cut[0] == 2):
                print("max")
                myscreen.addActor(
                    camvtk.Line(p1=(100, cut[1], 0),
                                p2=(-100, cut[1], 0),
                                color=camvtk.red))
            else:
                print("min")
                myscreen.addActor(
                    camvtk.Line(p1=(100, cut[1], 0),
                                p2=(-100, cut[1], 0),
                                color=camvtk.pink))

        slo = camvtk.STLSurf(triangleList=lotris)
        slo.SetColor(camvtk.pink)
        slo.SetWireframe()
        shi = camvtk.STLSurf(triangleList=hitris)
        shi.SetColor(camvtk.lgreen)
        shi.SetWireframe()
        myscreen.addActor(slo)
        myscreen.addActor(shi)
        myscreen.render()
        myscreen.iren.Start()
        raw_input("Press Enter to terminate")
        time.sleep(1)
        myscreen.removeActor(slo)
        myscreen.removeActor(shi)

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

    #raw_input("Press Enter to terminate")
    time.sleep(0.2)
    lwr.Write()
    myscreen.iren.Start()
예제 #30
0
import time
import vtk
import datetime
import math

def drawEdge(myscreen, a, b):
    myscreen.addActor(camvtk.Sphere(center=(a.x,a.y,a.z), radius=0.0351, color=camvtk.green));
    myscreen.addActor(camvtk.Sphere(center=(b.x,b.y,b.z), radius=0.0351, color=camvtk.red));
    myscreen.addActor( camvtk.Line(p1=(a.x,a.y,a.z),p2=(b.x,b.y,b.z)) )

if __name__ == "__main__":  
    print(ocl.version())
    myscreen = camvtk.VTKScreen()
    camvtk.drawOCLtext(myscreen)
    camvtk.drawArrows(myscreen,center=(-1,-2,0))
    a=ocl.Point(0,1.7,-0.6)
    b=ocl.Point(0,0.11,0.3)    

    drawEdge(myscreen, a, b)
    diameter=0.4
    length=1
    # spherical cutter and cylinder
    s1 = camvtk.Sphere(center=(a.x,a.y,a.z), radius=diameter/2, color=camvtk.lgreen)
    s2 = camvtk.Sphere(center=(b.x,b.y,b.z), radius=diameter/2, color=camvtk.pink)
    s1.SetOpacity(1)
    s2.SetOpacity(1)
    myscreen.addActor(s1)
    myscreen.addActor(s2)
    # tube
    cyltube = camvtk.Tube( p1=(a.x,a.y,a.z) , p2=(b.x,b.y,b.z), radius=diameter/2, color=camvtk.yellow )
    cyltube.SetOpacity(0.2)