Пример #1
0
def medial_axis(coords, far=500.0, v_flop=False, clean=False):

    segs = get_loops_from_coords(coords)
    if v_flop:
        reverse_segments(segs)

    n_bins = int(sqrt(len(coords)))  # approx. sqrt(nr of sites)
    vd = ovd.VoronoiDiagram(far, n_bins)
    # vd.debug_on()
    # vd.set_silent(True)  # suppress Warnings  # JvO: not implemented?

    insert_many_polygons(vd, segs)

    print("VD check: %s" % vd.check())

    pi = ovd.PolygonInterior(
        True)  # filter so that only polygon interior remains
    vd.filter_graph(pi)
    ma = ovd.MedialAxis()  # filter so that only medial axis remains
    vd.filter_graph(ma)

    maw = ovd.MedialAxisWalk(vd.getGraph())
    toolpath = maw.walk()

    # print_toolpath(toolpath, 1.0)  # write ngc to output.ngc

    return toolpath_to_v_coords(toolpath)
Пример #2
0
def medial_axis(segs, clean=False):
    import sys

    # svg = "../samples/Hello_flattened2_rev.svg" if len(sys.argv) < 2 else sys.argv[1]
    # svgr = SvgReader(svg, error_threshold=.6)
    # svgr.parse()
    # svgr.centerPolys()

    # far = svgr.radius * 1.2
    far = 100.0
    n_bins = int(sqrt(1200))  # approx. sqrt(nr of sites)
    vd = ovd.VoronoiDiagram(far, n_bins)

    times = insert_many_polygons(vd, segs)
    print("all sites inserted: %d " % len(times))
    # print("all sites inserted.")
    print("VD check: %s" % vd.check())

    pi = ovd.PolygonInterior(True)
    vd.filter_graph(pi)
    ma = ovd.MedialAxis()
    vd.filter_graph(ma)

    printMedial(vd, 1)  # write ngc to output.ngc
Пример #3
0
    vd.addLineSite(id_list[3], id_list[4])
    vd.check()

    vd.addLineSite(id_list[4], id_list[0])
    vd.check()

    t_after = time.time()
    line_time = t_after - t_before
    if line_time < 1e-3:
        line_time = 1
    times.append(line_time)

    pi = ovd.PolygonInterior(True)
    vd.filter_graph(pi)
    ma = ovd.MedialAxis()
    vd.filter_graph(ma)

    mapocket = ovd.MedialAxisPocket(vd.getGraph())
    mapocket.setWidth(0.01)

    mapocket.run()
    mic_components = mapocket.get_mic_components()
    for mic_list in mic_components:
        for n in range(len(mic_list)):
            mic = mic_list[n]
            if n == 0:
                print "hello", mic[0], " r = ", mic[1]
                drawCircle(myscreen, mic[0], mic[1], ovdvtk.red)
            else:
                drawCircle(myscreen, mic[0], mic[1], ovdvtk.green)
Пример #4
0
    vod.drawGenerators = 0
    vod.offsetEdges = 0
    vod.drawNullEdges = 1
    vd.setEdgeOffset(0.001)

    all_segs = segs + segs2  #+segs3 +segs4+segs5
    #all_segs=segs
    #all_segs=segs3 #+segs4
    #all_segs = segs6
    #insert_many_polygons(vd,all_segs)
    times = insert_many_polygons(vd, all_segs)
    #vd.check()
    vod.setVDText2(times)

    ovd.PolygonInterior(vd.getGraph(), True)
    ovd.MedialAxis(vd.getGraph())
    vod.setAll()  # this draws the medial-axis interior to the letters

    vd.filterReset()
    # another vod to draw outside text:
    vod2 = ovdvtk.VD(myscreen,
                     vd,
                     float(scale),
                     textscale=0.01,
                     vertexradius=0.003)
    #vod.drawFarCircle()
    vod2.textScale = 0.0002
    vod2.vertexRadius = 0.0011
    vod2.drawVertices = 0
    vod2.drawVertexIndex = 0
    vod2.drawGenerators = 0
Пример #5
0
                    textscale=0.01,
                    vertexradius=0.003)
    vod.drawFarCircle()
    vod.textScale = 0.0002
    vod.vertexRadius = 0.0011
    vod.drawVertices = 0
    vod.drawVertexIndex = 0
    vod.drawGenerators = 0
    vod.offsetEdges = 0
    vod.drawNullEdges = 1
    vd.setEdgeOffset(0.001)

    all_segs = segs  #+segs2 #+segs3 +segs4+segs5
    #all_segs=segs
    #all_segs=segs3 #+segs4
    #all_segs = segs6
    #insert_many_polygons(vd,all_segs)
    times = insert_many_polygons(vd, all_segs)
    #vd.check()
    vod.setVDText2(times)

    pi = ovd.PolygonInterior(True)
    vd.filter_graph(pi)
    ma = ovd.MedialAxis(0.90)
    vd.filter_graph(ma)

    vod.setAll()
    print "PYTHON All DONE."
    myscreen.render()
    myscreen.iren.Start()
Пример #6
0
    # count the number of segments
    num_segs = 0
    for s in segs:
        num_segs = num_segs + len(s)

    text_length = (extents.maxx - extents.minx) * scale * print_scale
    text_height = (extents.maxy - extents.miny) * scale * print_scale

    # print comments to g-code file
    print "( ttt2medial.py - experimental v-carving script )"
    print "( TTT++", ttt.version(), "                      )"
    print "( OpenVoronoi", ovd.version(), "                )"
    print "( number of polygons: ", len(segs), "                )"
    print "( number of segments: ", num_segs, "                )"
    print "( text length: ", text_length, " )"
    print "( text height: ", text_height, "                )"
    print "( VD built in %02.3f seconds   = %02f  us* n*log2{n} )" % (
        sum(times), 1e6 * float(sum(times)) /
        (float(num_segs) * float(math.log10(num_segs) / math.log10(2))))
    print "( VD check: ", vd.check(), "                              )"

    pi = ovd.PolygonInterior(
        True)  # filter so that only polygon interior remains
    vd.filter_graph(pi)
    ma = ovd.MedialAxis()  # filter so that only medial axis remains
    vd.filter_graph(ma)

    ngc_writer.preamble()
    printMedial(vd, print_scale)  # the actual cutting g-code
    ngc_writer.postamble()
Пример #7
0
    vod.offsetEdges = 0
    vod.drawNullEdges = 1
    vd.setEdgeOffset(0.001)

    all_segs = segs + segs2  # +segs3 +segs4+segs5
    # all_segs=segs
    # all_segs=segs3 #+segs4
    # all_segs = segs6
    # insert_many_polygons(vd,all_segs)
    times = insert_many_polygons(vd, all_segs)
    # vd.check()
    vod.setVDText2(times)

    pi_filt = ovd.PolygonInterior(True)
    vd.filter_graph(pi_filt)
    ma_filt = ovd.MedialAxis()
    vd.filter_graph(ma_filt)
    vod.setAll()  # this draws the medial-axis interior to the letters

    vd.filterReset()
    # another vod to draw outside text:
    vod2 = ovdvtk.VD(myscreen,
                     vd,
                     float(scale),
                     textscale=0.01,
                     vertexradius=0.003)
    # vod.drawFarCircle()
    vod2.textScale = 0.0002
    vod2.vertexRadius = 0.0011
    vod2.drawVertices = 0
    vod2.drawVertexIndex = 0