def insert_offset_loop(vd, ofs):
    polygon_ids = []
    # create segs from ofs
    segs = []
    previous = ovd.Point()
    for ofloop in ofs:
        loop = []
        first = True
        for of in ofloop:
            #print of
            if first:
                #loop.append( of[0] )
                previous = of[0]
                first = False
            else:
                cw = of[3]  # cw/ccw flag
                cen = of[2]  # center
                r = of[1]  # radius
                p = of[0]  # target point
                if r == -1:  # r=-1 means line-segment
                    loop.append(
                        p
                    )  #points.extend( [previous,p] ) #drawLine(myscreen, previous, p, lineColor)
                else:  # otherwise we have an arc
                    loop.extend(arc_pts2(previous, p, r, cen, cw))
                    #points.extend( arc_pts( previous, p, r,cen,cw) )
                previous = p
                #loop.append(p)

        segs.append(loop)

    #print segs
    t_before = time.time()
    for poly in segs:
        poly_id = insert_polygon_points(vd, poly)
        polygon_ids.append(poly_id)
    t_after = time.time()
    pt_time = t_after - t_before

    t_before = time.time()
    for ids in polygon_ids:
        insert_polygon_segments(vd, ids)

    t_after = time.time()
    seg_time = t_after - t_before

    return [pt_time, seg_time]
Beispiel #2
0
    def __init__(self, myscreen, vd, scale=1, textscale=0.06, vertexradius=0.04):
        self.myscreen = myscreen
        self.vd = vd
        self.scale = scale

        self.gen_pts = [ovd.Point(0, 0)]
        self.generators = PointCloud(pointlist=self.gen_pts)
        self.verts = []
        self.far = []
        self.edges = []
        self.gens = []
        self.actors = []
        self.pointsiteColor = yellow
        self.generatorColor = yellow
        self.vertexColor = blue
        self.seedColor = pink
        self.edgeColor = cyan
        self.vertexRadius = vertexradius

        self.vdtext = Text()
        self.vdtext.SetPos((50, myscreen.height - 70))
        myscreen.addActor(self.vdtext)
        self.actors.append(self.vdtext)

        self.vdtext2 = Text()
        self.vdtext2.SetPos((myscreen.width - 500, 50))
        self.vdtext2.SetText("--")
        myscreen.addActor(self.vdtext2)
        self.actors.append(self.vdtext2)

        self.gittext = Text()
        self.gittext.SetPos((50, 50))
        self.gittext_text = "github.com/aewallin"
        self.gittext.SetText(self.gittext_text)
        myscreen.addActor(self.gittext)

        self.N_pointgen = 0
        self.N_linegen = 0
        self.vdtext_text = "CPU Time:"
        self.setVDText()
        self.drawClearanceDisk = 0
        self.textScale = textscale
        self.drawVertexIndex = 1
        self.drawVertices = 1
        self.drawGenerators = 1
        self.offsetEdges = 0
        self.drawNullEdges = 1
def circleGenerators(far, Nmax):
    # POINTS ON A CIRCLE
    #"""
    #cpos=[50,50]
    #npts = 100
    dalfa= float(2*math.pi)/float(Nmax-1)
    #dgamma= 10*2*math.pi/npts
    #alfa=0
    #ofs=10
    plist=[]
    radius=0.81234*float(far)
    for n in range(Nmax):
        x=float(radius)*math.cos(float(n)*float(dalfa))
        y=float(radius)*math.sin(float(n)*float(dalfa))
        plist.append( ovd.Point(x,y) )
    #random.shuffle(plist)
    return plist
def insert_polygon_points(vd, polygon):
    """ insert PointSites into VD
        return list of vertex-indexes
    """
    pts = []
    for p in polygon:
        pts.append(ovd.Point(p[0], p[1]))
    id_list = []
    print "inserting ", len(pts), " point-sites:"
    m = 0
    for p in pts:
        id_list.append(vd.addVertexSite(p))
        print " ", m, " added vertex ", id_list[len(id_list) -
                                                1], " ({0}, {1})".format(
                                                    p.x, p.y)
        m = m + 1
    print vd.numFaces(), " faces after all points inserted"
    return id_list
def regularGridGenerators(far, Nmax):
    # REGULAR GRID
    rows = int(math.sqrt(Nmax))
    print "rows= ",rows
    gpos=[-0.7*far ,  1.4*far/float(rows-1) ]  # start, stride
    plist = []
    for n in range(rows):
        for m in range(rows):
            x=gpos[0]+gpos[1]*n
            y=gpos[0]+gpos[1]*m
            # rotation
            #alfa = 0
            #xt=x
            #yt=y
            #x = xt*math.cos(alfa)-yt*math.sin(alfa)
            #y = xt*math.sin(alfa)+yt*math.cos(alfa)
            plist.append( ovd.Point(x,y) )
    random.shuffle(plist)
    return plist
Beispiel #6
0
def arc_pts(pt1, pt2, r, cen, cw):  # (start, end, radius, center, cw )
    # draw arc as many line-segments
    start = pt1 - cen
    end = pt2 - cen
    theta1 = math.atan2(start.x, start.y)
    theta2 = math.atan2(end.x, end.y)
    alfa = []  # the list of angles
    da = 0.1
    CIRCLE_FUZZ = 1e-9
    # idea from emc2 / cutsim g-code interp G2/G3
    if (cw == False):
        while ((theta2 - theta1) > -CIRCLE_FUZZ):
            theta2 -= 2 * math.pi
    else:
        while ((theta2 - theta1) < CIRCLE_FUZZ):
            theta2 += 2 * math.pi

    dtheta = theta2 - theta1
    arclength = r * dtheta
    dlength = min(0.001, arclength / 10)
    steps = int(float(arclength) / float(dlength))
    rsteps = float(1) / float(steps)
    dc = math.cos(-dtheta * rsteps)  # delta-cos
    ds = math.sin(-dtheta * rsteps)  # delta-sin

    previous = pt1
    tr = [start.x, start.y]
    pts = []
    for i in range(steps):
        #f = (i+1) * rsteps #; // varies from 1/rsteps..1 (?)
        #theta = theta1 + i* dtheta
        tr = rotate(tr[0], tr[1], dc,
                    ds)  #; // rotate center-start vector by a small amount
        x = cen.x + tr[0]
        y = cen.y + tr[1]

        current = ovd.Point(x, y)
        #myscreen.addActor( ovdvtk.Line(p1=(previous.x,previous.y,0),p2=(current.x,current.y,0),color=arcColor) )
        pts.extend([previous, current])
        previous = current
    return pts
Beispiel #7
0
def drawArc(myscreen, pt1, pt2, r, cen, cw, arcColor):
    # draw arc as many line-segments
    start = pt1 - cen
    end = pt2 - cen
    theta1 = math.atan2(start.x, start.y)
    theta2 = math.atan2(end.x, end.y)
    alfa = []  # the list of angles
    da = 0.1
    CIRCLE_FUZZ = 1e-9
    # idea from emc2 / cutsim g-code interp G2/G3
    if (cw == False):
        while ((theta2 - theta1) > -CIRCLE_FUZZ):
            theta2 -= 2 * math.pi
    else:
        while ((theta2 - theta1) < CIRCLE_FUZZ):
            theta2 += 2 * math.pi

    dtheta = theta2 - theta1
    arclength = r * dtheta
    dlength = max(0.001, arclength / 10)
    steps = int(float(arclength) / float(dlength))
    if steps == 0: steps = 1
    rsteps = float(1) / float(steps)
    dc = math.cos(-dtheta * rsteps)  # delta-cos
    ds = math.sin(-dtheta * rsteps)  # delta-sin

    previous = pt1
    tr = [start.x, start.y]
    for i in range(steps):
        tr = rotate(tr[0], tr[1], dc,
                    ds)  # ; // rotate center-start vector by a small amount
        x = cen.x + tr[0]
        y = cen.y + tr[1]
        current = ovd.Point(x, y)
        myscreen.addActor(
            ovdvtk.Line(p1=(previous.x, previous.y, 0),
                        p2=(current.x, current.y, 0),
                        color=arcColor))
        ngc_writer.xy_line_to(current.x, current.y)
        previous = current
Beispiel #8
0
def drawLineArcTest():
    myscreen = ovdvtk.VTKScreen()
    myscreen.camera.SetPosition(0.01, 0, 1000)
    myscreen.camera.SetFocalPoint(0, 0, 0)
    myscreen.camera.SetClippingRange(-100, 3000)

    l1 = Line(math.cos(1), math.sin(1), -50, +1)  # first line-site
    drawLine(myscreen, l1, ovdvtk.yellow)

    c2 = Circle(c=ovd.Point(30, 50), r=20, cw=+1)  # first site
    drawVertex(myscreen, c2.c, ovdvtk.orange)
    drawCircle(myscreen, c2.c, c2.r, ovdvtk.orange)
    #myscreen.addActor( ovdvtk.Circle( center=(c.c.x,c.c.y,c.c.z), radius=c.r, color=circleColor ) )

    c1c2 = CircleLine(c2, l1)  # bisectors
    #CircleLine
    b1 = Bisector(c1c2)
    #b2= Bisector( l2l1 )
    drawBisector(myscreen, b1)
    #drawBisector( myscreen, b2 )
    myscreen.render()
    myscreen.iren.Start()
Beispiel #9
0
def insert_polygon_segments(vd, id_list):
    j = 0
    print "inserting ", len(id_list), " line-segments:"
    for n in range(len(id_list)):
        n_nxt = n + 1
        if n == (len(id_list) - 1):
            n_nxt = 0
        print " ", j, "inserting segement ", id_list[n], " - ", id_list[n_nxt]

        if id_list[n] == 47124:  # 47013:
            vd.debug_on()
            vd.addLineSite(id_list[n], id_list[n_nxt], 5)  # fails: 47124/6
            vod.setVDText2([1, 1])
            vod.setAll()
            #verts=[id_list[n], id_list[n_nxt], 117443,117445,117460,117454]
            #for v in verts:
            #    print "drawing ",v
            #print vod
            #print dir(vod)
            #    vod.drawVertexIdx(v)
            vod.drawIncidentVertexIds()
            # f4792   f4795
            for v in vd.getFaceVertices(4792):
                vod.drawVertexIdx(v)
            print "PYTHON All DONE."
            f = ovd.Point(0.055, -0.2437)
            myscreen.camera.SetPosition(f.x, f.y - float(1) / float(1000), 0.3)
            #myscreen.camera.SetClippingRange(-(zmult+1)*camPos,(zmult+1)*camPos)
            myscreen.camera.SetFocalPoint(f.x, f.y, 0)
            myscreen.render()
            myscreen.iren.Start()
        elif id_list[n] in [47113]:
            vd.addLineSite(id_list[n], id_list[n_nxt])
        else:
            pass
            #vd.addLineSite( id_list[n], id_list[n_nxt])
        j = j + 1
Beispiel #10
0
def spiral_clear(myscreen, cutwidth, out_tangent, in_tangent, c1, r1, c2, r2,
                 out1, in1):
    print "( spiral clear! )"
    ngc_writer.pen_up()

    # end spiral at in1
    # archimedean spiral
    # r = a + b theta

    in1_dir = in1 - c1
    in1_theta = math.atan2(in1_dir.y, in1_dir.x)
    # in1_theta = in1_theta
    # print "c1 =", c1
    # print "in1 = ",in1
    # print " end theta = ",in1_theta
    drawPoint(myscreen, c1, ovdvtk.red)
    # drawPoint( myscreen, in1, ovdvtk.blue, 0.006 )
    # width = 2*pi*b
    # => b = width/(2*pi)
    b = cutwidth / (2 * math.pi)
    # r = a + b in1_theta = r_max
    # =>
    # a = r_max-b*in1_theta
    a = r1 - b * in1_theta

    # figure out the start-angle
    theta_min = in1_theta
    theta_max = in1_theta
    dtheta = 0.1
    min_r = 0.001
    while True:
        r = a + b * theta_min
        if r < min_r:
            break
        else:
            theta_min = theta_min - dtheta
    # print "start_theta = ", theta_min

    Npts = (theta_max - theta_min) / dtheta
    Npts = int(Npts)
    # print "spiral has ",Npts," points"
    p = ovd.Point(c1)
    ngc_writer.xy_rapid_to(p.x, p.y)
    ngc_writer.pen_down()

    theta_end = 0
    for n in range(Npts + 1):
        theta = theta_min + n * dtheta
        r = a + b * theta
        theta = theta - 2 * abs(in1_theta - math.pi / 2)
        trg = c1 + r * ovd.Point(-math.cos(theta), math.sin(theta))
        ovdvtk.drawLine(myscreen, p, trg, ovdvtk.pink)
        ngc_writer.xy_line_to(trg.x, trg.y)
        p = trg
        theta_end = theta

    # add a complete circle after the spiral.
    print "( spiral-clear: final circle )"
    Npts = (2 * math.pi) / dtheta
    Npts = int(Npts)
    for n in range(Npts + 2):
        theta = theta_end + (n + 1) * dtheta
        # theta = theta_min + n*dtheta
        r = r1  # a + b*theta
        # theta = theta - 2* abs(in1_theta - math.pi/2 )
        trg = c1 + r * ovd.Point(-math.cos(theta), math.sin(theta))
        ovdvtk.drawLine(myscreen, p, trg, ovdvtk.pink)
        ngc_writer.xy_line_to(trg.x, trg.y)

        # if n != Npts+1:
        #    drawPoint(myscreen, trg, ovdvtk.orange)
        # else:
        #    drawPoint(myscreen, trg, ovdvtk.orange,0.004)
        p = trg
# 2012-07-25: this reportedly hangs.

import openvoronoi

points = ((-0.7000000000000002, -0.5249999999990376),
          (0.7, -0.5249999999990376),
          )

print "OpenVoronoi version: ", openvoronoi.version()

dia = openvoronoi.VoronoiDiagram(0.972222, 2)
for p in points:
    ovp = openvoronoi.Point(*p)
    print "Adding ", ovp
    dia.addVertexSite(ovp)

print dia
print "VD OK?: ", dia.check()

# aewallin, I get:
"""
Adding  (-0.7, -0.525)
Adding  (0.7, -0.525)
VoronoiDiagram 
 num_vertices    = 18
 num_edges       = 31
 num_point_sites = 2
 num_line_sites  = 0
 num_split_vertices  = 0

VD OK?:  True
Beispiel #12
0
    vod.drawFarCircle()

    vod.textScale = 0.0002
    vod.vertexRadius = 0.0031
    vod.drawVertices = 0
    vod.drawVertexIndex = 1
    vod.drawGenerators = 0
    vod.offsetEdges = 1
    vd.setEdgeOffset(0.0001)

    linesegs = 1  # switch to turn on/off line-segments

    segs = []
    # ovd.Point(1,1)
    # eps=0.9
    p1 = ovd.Point(0.200412, 0.406533)  # l1  l2
    p2 = ovd.Point(0.196948, 0.406213)  # l1
    p3 = ovd.Point(0.201566, 0.40664)  # l2    l3
    p4 = ovd.Point(0.204032, 0.405097)  # l3
    #    p5=ovd.Point(-0.6,0.3)
    """
    LineSite: (0.200412, 0.406533) - (0.196948, 0.406213)
    LineSite: (0.201566, 0.40664) - (0.200412, 0.406533)
    LineSite: (0.204032, 0.405097) - (0.201566, 0.40664)
    """

    pts = [p1, p2, p3, p4]

    # t_after = time.time()
    # print ".done in {0:.3f} s.".format( t_after-t_before )
    times = []
Beispiel #13
0
    vod = ovdvtk.VD(myscreen,
                    vd,
                    float(scale),
                    textscale=0.01,
                    vertexradius=0.003)
    vod.drawFarCircle()
    vod.textScale = 0.02
    vod.vertexRadius = 0.0031
    vod.drawVertices = 1
    vod.drawVertexIndex = 1
    vod.drawGenerators = 1

    linesegs = 1  # switch to turn on/off line-segments

    segs = []
    s1 = [ovd.Point(-0.5, -0.7), ovd.Point(-0.5, +0.7)]
    s2 = [ovd.Point(+0.5, -0.7), ovd.Point(+0.5, +0.7)]
    s3 = [ovd.Point(+0.4, -0.7), ovd.Point(+0.4, +0.7)]
    s4 = [ovd.Point(-0.3, -0.7), ovd.Point(-0.3, +0.7)]
    s5 = [ovd.Point(+0.3, -0.7), ovd.Point(+0.3, +0.7)]

    #s3 = [ovd.Point(+0.4,+0.0) , ovd.Point(-0.4,+0.0) ]
    segs.append(s1)
    segs.append(s2)
    segs.append(s3)
    segs.append(s4)
    segs.append(s5)

    #t_after = time.time()
    #print ".done in {0:.3f} s.".format( t_after-t_before )
    times = []
    #mic_list = mapocket.get_mic_list()
    mic_components = mapocket.get_mic_components()
    mic_list = mic_components[0]

    t_after = time.time()
    #print "( ma-pocket done in ", 1e3*(t_after-t_before)," milliseconds. got ",  len(mic_list)," MICs )"
    print "( MA-pocket done in %.3f s. Got %d MICs )" % (
        (t_after - t_before), len(mic_list))

    maxmic = mic_list[0]

    #print maxmic
    previous_center = maxmic[0]
    previous_radius = maxmic[1]
    cl = ovd.Point(0, 0)

    # the initial largest MIC. to be cleared with a spiral-path
    drawCircle(myscreen, maxmic[0], maxmic[1], ovdvtk.red)

    myscreen.render()
    #myscreen.iren.Start()
    ngc_writer.scale = 10 / 0.03
    ngc_writer.preamble()

    # the rest of the MICs are then cleared
    nframe = 0
    first = True
    previous_out1 = ovd.Point()
    out_tangent = ovd.Point()
    in_tangent = ovd.Point()
def drawLinesegs(myscreen, points, lines):
    for l in lines:
        pt1 = ovd.Point(points[l[0]][0], points[l[0]][1])
        pt2 = ovd.Point(points[l[1]][0], points[l[1]][1])
        drawLine(myscreen, pt1, pt2, ovdvtk.yellow)
 def __init__(self, c=ovd.Point(0, 0), r=1, cw=1, k=1):
     self.c = c
     self.r = r
     self.cw = cw  # CW=1, CCW = -1
     self.k = k  # offset direction
Beispiel #17
0
def drawBitangents():
    myscreen = ovdvtk.VTKScreen()
    myscreen.camera.SetPosition(0.01, 0, 100)
    myscreen.camera.SetFocalPoint(0, 0, 0)
    myscreen.camera.SetClippingRange(-100, 3000)
    """
    c1 = ovd.Point(10,20)
    r1=20
    c2 = ovd.Point(6,13)
    r2=23
    """

    # external ma-pocket fails with this input:
    c1 = ovd.Point(0, -18)
    r1 = 16.7033
    c2 = ovd.Point(0, -17.2167)
    r2 = 15.9299

    drawCircle(myscreen, c1, r1, ovdvtk.red)
    drawCircle(myscreen, c2, r2, ovdvtk.green)

    # when machining c2 the maximum cut-width is
    # w_max = | c2 - c1 | + r2 - r1

    # we are looking for the bi-tangents of the two circles, given by
    # A x + B y + C = 0
    # with the constraint A^2 + B^2 = 1
    # the line-should be a bi-tangent, so:
    # +/- r1 = A c1x + B c1y + C
    # +/- r2 = A c2x + B c2y + C
    # which in matrix form is
    #   Mc=v
    # ( c1x c1y ) ( A ) = ( +/- r1 - C )
    # ( c2x c2y ) ( B ) = ( +/- r2 - C )
    #
    # now solve for A and B using Cramers rule
    #
    #  A = det(M_1) / det(M) =  det ( +/-r1-C   c1y ) / det(M)  =  mC + n
    #                               ( +/-r2-C   c2y )
    # and
    #  B = det(M_2) / det(M) = det ( c1x  +/-r1-C ) / det(M) = pC + q
    #                              ( c2x  +/-r2-C )
    # this can be inserted into the constraint
    # A^2 + B^2 = 1
    # (mC + n )^2 + (pC+q)^2
    # m^2 C^2 + 2mnC + n^2 + p^2 C^2 + 2pqC + q^2 =1
    #
    # C^2 ( m^2 + p^2 ) + C 2(mn+pq) + n^2 + q^2 = 1
    #
    # +r1 +r2 case:
    #  det( r1-C c1y ) = (r1-C)c2y - (r2-C)c1y = C (c1y-c2y) + (c2y*r1 - c1y*r2)
    #     ( r2-C c2y )
    #  det( c1x r1-C ) = c1x(r2-C) - c2x(r1-C) = C ( c2x-c1x ) + (c1x*r2 - c2x*r1)
    #     ( c2x r2-C )
    lines = []
    detM = c1.x * c2.y - c2.x * c1.y
    print "detM= ", detM
    m = (c1.y - c2.y) / detM
    p = (c2.x - c1.x) / detM

    n = (c2.y * r1 - c1.y * r2) / detM
    q = (c1.x * r2 - c2.x * r1) / detM
    roots1 = quadratic_roots(m * m + p * p, 2 * (m * n + p * q),
                             n * n + q * q - 1)
    print "roots1 ", roots1
    for r in roots1:
        lines.append(root_to_line(r, m, n, p, q))
    """
    n = ( c2.y*(-1)*r1 - c1.y*(-1)*r2 ) / detM
    q = ( c1.x*(-1)*r2 - c2.x*(-1)*r1 ) / detM
    roots2 = quadratic_roots( m*m+p*p, 2*(m*n+p*q),  n*n+q*q-1)
    print "roots2 ", roots2
    for r in roots2:
        lines.append( root_to_line(r,m,n,p,q) )
    """

    for l in lines:
        drawLine(myscreen, l, ovdvtk.yellow)

    # now figure out the tangent points
    # this is the point on the tangent closest to the center.
    # Ax + By + C = 0
    # (xc-x^2) + (yc-y^2) = r^2
    #
    # from C, go a distance r along the normal to the line.
    p1 = c1 - r1 * ovd.Point(lines[0].a, lines[0].b)
    p2 = c1 - r1 * ovd.Point(lines[1].a, lines[1].b)
    drawCircle(myscreen, p1, 0.5, ovdvtk.pink)
    drawCircle(myscreen, p2, 0.5, ovdvtk.pink)

    p3 = c2 - r2 * ovd.Point(lines[0].a, lines[0].b)
    p4 = c2 - r2 * ovd.Point(lines[1].a, lines[1].b)
    drawCircle(myscreen, p3, 0.5, ovdvtk.pink)
    drawCircle(myscreen, p4, 0.5, ovdvtk.pink)

    #drawLine( myscreen, l2, ovdvtk.orange )
    #print roots

    myscreen.render()
    myscreen.iren.Start()
    vod.drawFarCircle()

    vod.textScale = 0.002
    vod.vertexRadius = 0.0031
    vod.drawVertices = 0
    vod.drawVertexIndex = 1
    vod.drawGenerators = 0
    vod.offsetEdges = 1
    vd.setEdgeOffset(0.01)

    linesegs = 1  # switch to turn on/off line-segments

    segs = []
    # ovd.Point(1,1)
    # eps=0.9
    p1 = ovd.Point(0, 0)
    p2 = ovd.Point(0.4, 0.0)
    p3 = ovd.Point(0.0, 0.2)
    p4 = ovd.Point(0.4, 0.2)
    # p4=ovd.Point(0.6,0.6)
    # p5=ovd.Point(-0.6,0.3)

    pts = [p1, p2, p3, p4]

    # t_after = time.time()
    # print ".done in {0:.3f} s.".format( t_after-t_before )
    times = []
    id_list = []
    m = 0
    t_before = time.time()
    for p in pts:
    # for vtk visualization
    vod = ovdvtk.VD(myscreen, vd, float(scale), textscale=0.01, vertexradius=0.003)
    # these actions on the vod object control how the VD is drawn using VTK
    vod.drawFarCircle()
    vod.textScale = 0.02
    vod.vertexRadius = 0.0031
    vod.drawVertices = 0
    vod.drawVertexIndex = 1
    vod.drawGenerators = 1
    vod.offsetEdges = 1  # for debug. a bool flag to set null-edge drawing on/off. use together with setEdgeOffset()
    vd.setEdgeOffset(0.05)  # for debug. a non-zero value will draw null-edges as circular arcs
    # null-edges are an internal openvoronoi construction to avoid high-degree vertices in the VD-graph
    # they are not relevant for upstream or downstream algorithms

    # input points (vertices/sites)
    p1 = ovd.Point(-0.4, -0.2)
    p2 = ovd.Point(-0.4, 0.2)
    p3 = ovd.Point(0.0, 0.04)
    p4 = ovd.Point(0.4, 0.2)
    p5 = ovd.Point(0.4, -0.2)
    pts = [p1, p2, p3, p4, p5]  # a list of all points in the input

    # t_after = time.time()
    # print ".done in {0:.3f} s.".format( t_after-t_before )
    times = []
    id_list = []
    m = 0
    t_before = time.time()
    for p in pts:  # add all points before adding line-segments
        id_list.append(vd.addVertexSite(p))
        # print m," added vertex", seg_id[0]
Beispiel #20
0
    foo = WritableObject()  # a writable object
    sys.stdout = foo  # redirection

    print("( Medial-Axis pocketing. Proof-of-principle. 2012-02-12 )")
    print("( OpenVoronoi %s  )" % (ovd.version()))
    print("( TOOL/MILL,10,0,50 ) ")
    print("( COLOR,0,255,255 ) ")
    print(
        "( STOCK/BLOCK,700.0000,400.0000,10.0000,350.0000,160.0000,5.0000 ) ")

    linesegs = 1  # switch to turn on/off line-segments

    segs = []
    # ovd.Point(1,1)
    eps = 0.9
    p1 = ovd.Point(-0.1, -0.2)
    p2 = ovd.Point(0.2, 0.1)
    p3 = ovd.Point(0.4, 0.2)
    p4 = ovd.Point(0.6, 0.6)
    p5 = ovd.Point(-0.6, 0.3)

    pts = [p1, p2, p3, p4, p5]

    vd = ovd.VoronoiDiagram(far, 120)
    # t_after = time.time()
    # print ".done in {0:.3f} s.".format( t_after-t_before )
    times = []
    id_list = []
    m = 0
    t_before = time.time()
    for p in pts:
def drawArcPredicate2():
    myscreen = ovdvtk.VTKScreen()
    myscreen.camera.SetPosition(0.01, 0, 100)
    myscreen.camera.SetFocalPoint(0, 0, 0)
    myscreen.camera.SetClippingRange(-100, 3000)

    c1 = ovd.Point(0, 0)
    r1 = 20

    alfa1 = (float(23) / float(360)) * 2 * math.pi
    alfa2 = (float(123) / float(360)) * 2 * math.pi

    # alfa2, alfa1 = alfa1, alfa2 # swap

    alfa1_dir = ovd.Point(math.cos(alfa1), math.sin(alfa1))
    alfa2_dir = ovd.Point(math.cos(alfa2), math.sin(alfa2))
    p1 = c1 + r1 * alfa1_dir
    p2 = c1 + r1 * alfa2_dir
    cw = False

    drawVertex(myscreen, c1, ovdvtk.orange, rad=1)
    fa1 = ovdvtk.FollowerText(text="c",
                              color=ovdvtk.orange,
                              center=(c1.x + 1, c1.y, 0),
                              scale=1)
    myscreen.addActor(fa1)

    drawVertex(myscreen, p1, ovdvtk.green, rad=1)
    fa2 = ovdvtk.FollowerText(text="p1",
                              color=ovdvtk.green,
                              center=(p1.x + 1, p1.y, 0),
                              scale=1)
    myscreen.addActor(fa2)

    drawVertex(myscreen, p2, ovdvtk.red, rad=1)
    fa3 = ovdvtk.FollowerText(text="p2",
                              color=ovdvtk.red,
                              center=(p2.x + 1, p2.y, 0),
                              scale=1)
    myscreen.addActor(fa3)

    # drawArc(myscreen, p1, p2, c1, True, ovdvtk.yellow)
    # ovdvtk.drawArc(myscreen, p1, p2, (p1-c1).norm(), c1, True, ovdvtk.yellow, da=0.1)
    ovdvtk.drawArc(myscreen,
                   p1,
                   p2, (p1 - c1).norm(),
                   c1,
                   cw,
                   ovdvtk.orange,
                   da=0.1)

    Nmax = 5000
    for n in range(Nmax):
        p = 100 * ovd.Point(random.random() - 0.5, random.random() - 0.5)

        apex = apex_point(p1, p2, c1, cw, p)
        linecolor = ovdvtk.pink
        if arc_in_region(p1, p2, c1, cw, p):
            linecolor = ovdvtk.lgreen

        drawLine(myscreen, p, apex, linecolor)

    myscreen.render()
    myscreen.iren.Start()
Beispiel #22
0
                    float(scale),
                    textscale=0.01,
                    vertexradius=0.003)
    vod.drawFarCircle()

    vod.textScale = 0.005
    vod.vertexRadius = 0.00031
    vod.drawVertices = 1
    vod.drawVertexIndex = 1
    vod.drawGenerators = 1

    vod.offsetEdges = 1
    vd.setEdgeOffset(0.03)

    plist = []
    plist.append(ovd.Point(0.1, 0.1))
    plist.append(ovd.Point(-0.1, 0.1))

    plist.append(ovd.Point(0.1, -0.1))
    plist.append(ovd.Point(-0.1, -0.1))
    # plist.append( ovd.Point(-0.03,-0.03) )
    # plist.append( ovd.Point(-0.15, -0.15) )
    # + regularGridGenerators(far, Nmax) + circleGenerators(far, Nmax)

    # plist = [ovd.Point(0,0)]
    # print(plist)
    times = []
    t_before = time.time()
    n = 0
    id_list = []
    # vd.debug_on()
Beispiel #23
0
    vod.drawVertexIndex = 1
    vod.drawGenerators = 1
    vod.offsetEdges = 0
    vd.setEdgeOffset(0.05)
    """
    p1=ovd.Point(-0.1,-0.2)
    p2=ovd.Point(0.2,0.1)
    p3=ovd.Point(0.4,0.2)
    p4=ovd.Point(0.6,0.6)
    p5=ovd.Point(-0.6,0.3)

    pts = [p1,p2,p3,p4,p5]
    """
    pts = []
    for p in poly_points:
        pts.append(ovd.Point(p[0], p[1]))

    # t_after = time.time()
    # print ".done in {0:.3f} s.".format( t_after-t_before )
    times = []
    id_list = []
    m = 0
    t_before = time.time()
    for p in pts:
        pt_id = vd.addVertexSite(p)
        id_list.append(pt_id)
        print("%s added vertex %s at %s" % (m, pt_id, p))
        m = m + 1

    t_after = time.time()
    times.append(t_after - t_before)
Beispiel #24
0
    vod.drawFarCircle()

    vod.textScale = 0.002
    vod.vertexRadius = 0.0031
    vod.drawVertices = 0
    vod.drawVertexIndex = 1
    vod.drawGenerators = 0
    vod.offsetEdges = 1
    vd.setEdgeOffset(0.01)

    linesegs = 1  # switch to turn on/off line-segments

    segs = []
    # ovd.Point(1,1)
    # eps=0.9
    p1 = ovd.Point(-0.1, -0.1)
    p2 = ovd.Point(0.0, 0.0)
    p3 = ovd.Point(0.1, 0.1)
    p4 = ovd.Point(0.2, 0.3)
    # p4=ovd.Point(0.6,0.6)
    # p5=ovd.Point(-0.6,0.3)

    pts = [p1, p2, p3, p4]

    # t_after = time.time()
    # print ".done in {0:.3f} s.".format( t_after-t_before )
    times = []
    id_list = []
    m = 0
    t_before = time.time()
    for p in pts:
Beispiel #25
0
def drawToolPath(myscreen, mic_list, cut_width):
    maxmic = mic_list[0]
    previous_center = maxmic[0]
    previous_radius = maxmic[1]
    nframe = 0
    first = True
    previous_out1 = ovd.Point()
    out_tangent = ovd.Point()
    in_tangent = ovd.Point()
    for n in range(1, len(mic_list)):
        mic = mic_list[n]
        cen2 = mic[0]
        r2 = mic[1]
        previous_center = mic[6]
        previous_radius = mic[7]
        new_branch = mic[
            8]  # true/false indicates if we are starting on new branch
        prev_branch_center = mic[9]
        prev_branch_radius = mic[10]  # old branch MIC radius
        in1 = mic[3]
        in2 = mic[5]
        out2 = mic[4]
        out1 = mic[2]

        in_tangent = in2 - in1
        # rapid traverse to in1
        if not first:
            if new_branch:
                # new branch re-position move
                rapid_to_new_branch(myscreen, out_tangent, in_tangent,
                                    prev_branch_center, prev_branch_radius,
                                    cen2, r2, previous_out1, in1)
            else:
                # normal arc-rapid-arc to next MIC
                rapid_to_next(myscreen, out_tangent, in_tangent,
                              previous_center, previous_radius, cen2, r2,
                              previous_out1, in1)
        else:
            # spiral-clear the start-MIC. The spiral should end at in1
            spiral_clear(myscreen, cut_width, out_tangent, in_tangent,
                         previous_center, previous_radius, cen2, r2,
                         previous_out1, in1)
            # print "No rapid-move on first-iteration."
            first = False

        # in bi-tangent
        ovdvtk.drawLine(myscreen, in1, in2, ovdvtk.green)
        ngc_writer.xy_line_to(in2.x, in2.y)
        # cut-arc
        drawArc(myscreen, in2, out2, r2, cen2, True, ovdvtk.green)
        # out bi-tangent
        ovdvtk.drawLine(myscreen, out2, out1, ovdvtk.green)
        ngc_writer.xy_line_to(out1.x, out1.y)

        previous_out1 = out1  # this is used as the start-point for the rapid on the next iteration
        out_tangent = out1 - out2

        if n == len(mic_list) - 1:
            # end of operation. do a final lead-out arc.
            final_lead_out(myscreen, out_tangent, in_tangent, previous_center,
                           previous_radius, cen2, r2, previous_out1, in1)

        nframe = nframe + 1
Beispiel #26
0
    vod = ovdvtk.VD(myscreen, vd, scale)
    # vod.setAll(vd)
    drawFarCircle(myscreen, scale * vd.getFarRadius(), ovdvtk.orange)

    Nmax = 10

    # plist = randomGenerators(far, Nmax)
    # plist = regularGridGenerators(far, Nmax)
    # plist = circleGenerators(far, Nmax)

    plist = randomGenerators(far, Nmax) + regularGridGenerators(
        far, Nmax) + circleGenerators(far, Nmax)

    plist = [
        ovd.Point(0.622289, 0.522162),
        ovd.Point(0.81234, 0),
        ovd.Point(0.81234, -1.98966e-16)
    ]
    # print(plist[169])
    # exit()
    n = 1
    t_before = time.time()
    # delay = 1.5 # 0.533
    delay = 0.2  # 1 # 0.533
    ren = [1, 2, 3, 4, 5, 59, 60, 61, 62]
    # ren = [16,17]
    # ren = range(0,Nmax,100)
    # ren = range(0,len(plist)+1,1)
    # ren = [29]
    # ren = [0,1,Nmax-2, Nmax-1, Nmax]
Beispiel #27
0
    vod.drawFarCircle()

    vod.textScale = 0.02
    vod.vertexRadius = 0.0031
    vod.drawVertices = 0
    vod.drawVertexIndex = 1
    vod.drawGenerators = 0
    vod.offsetEdges = 0
    vd.setEdgeOffset(0.05)

    linesegs = 1  # switch to turn on/off line-segments

    segs = []
    #ovd.Point(1,1)
    eps = 0.9
    p1 = ovd.Point(-0.1, -0.2)
    p2 = ovd.Point(0.2, 0.1)
    p3 = ovd.Point(0.4, 0.2)
    p4 = ovd.Point(0.6, 0.6)
    p5 = ovd.Point(-0.6, 0.3)

    pts = [p1, p2, p3, p4, p5]

    #t_after = time.time()
    #print ".done in {0:.3f} s.".format( t_after-t_before )
    times = []
    id_list = []
    m = 0
    t_before = time.time()
    for p in pts:
Beispiel #28
0
                    textscale=0.01,
                    vertexradius=0.003)
    vod.drawFarCircle()

    vod.textScale = 0.0005
    vod.vertexRadius = 0.00031
    vod.drawVertices = 1
    vod.drawVertexIndex = 1
    vod.drawGenerators = 1

    vod.offsetEdges = 1
    vd.setEdgeOffset(0.0053)

    plist = []
    d = 0.02
    plist.append(ovd.Point(-0.1 + d, 0.1))  # 0
    plist.append(ovd.Point(0.1 - d, 0.1))  # 1
    plist.append(ovd.Point(0.1, 0.1 - d))  # 2
    plist.append(ovd.Point(0.1, -0.1 + d))  # 3
    plist.append(ovd.Point(0.1 - d, -0.1))  # 4
    plist.append(ovd.Point(-0.1 + d, -0.1))  # 5
    plist.append(ovd.Point(-0.1, -0.1 + d))  # 6
    plist.append(ovd.Point(-0.1, 0.1 - d))  # 7

    #plist.append( ovd.Point(-0.03,-0.03) )
    #plist.append( ovd.Point(-0.15, -0.15) )
    #+ regularGridGenerators(far, Nmax) + circleGenerators(far, Nmax)

    #plist = [ovd.Point(0,0)]
    #print plist
    times = []