Exemple #1
0
def test_move1():
    plot=False
    dt = Triangulation()
    pnts = [ [0,0],
             [5,0],
             [10,0],
             [5,5] ]

    dt.add_node( x=pnts[0] ) # This tests insert into empty
    dt.add_node( x=pnts[1] ) # adjacent_vertex
    dt.add_node( x=pnts[2] ) # adjacent_vertex
    dt.add_node( x=pnts[3] ) # adjacent_edge

    dt.add_node( x=[3,0] ) # colinear

    if plot:
        plt.clf()
        dt.plot_nodes()
        dt.plot_edges(alpha=0.5,lw=2)
        dt.plot_cells(lw=13,facecolor='#ddddff',edgecolor='w',zorder=-5)

    n=dt.add_node( x=[6,2] ) # into cell interior

    dt.modify_node(4,x=[3.01,0.25])

    dt.modify_node(4,x=[3.01,-0.25])
    if plot:
        plt.clf()
        dt.plot_nodes(labeler=lambda n,nrec: str(n) )
        dt.plot_edges(alpha=0.5,lw=2)
        dt.plot_cells(lw=13,facecolor='#ddddff',edgecolor='w',zorder=-5)

    dt.check_global_delaunay()
    return dt
Exemple #2
0
def test_extra1():
    plot=False
    dt = Triangulation()
    pnts = [ [0,0],
             [5,0],
             [10,0],
             [5,5] ]

    dt.add_node( x=pnts[0] ) # This tests insert into empty
    dt.add_node( x=pnts[1] ) # adjacent_vertex
    dt.add_node( x=pnts[2] ) # adjacent_vertex
    dt.add_node( x=pnts[3] ) # adjacent_edge

    dt.add_node( x=[3,0] ) # colinear

    if plot:
        plt.clf()
        dt.plot_nodes()
        dt.plot_edges(alpha=0.5,lw=2)
        dt.plot_cells(lw=13,facecolor='#ddddff',edgecolor='w',zorder=-5)

    n=dt.add_node( x=[6,2] ) # into cell interior

    if plot:
        plt.clf()
        dt.plot_nodes(labeler=lambda n,nrec: str(n) )
        dt.plot_edges(alpha=0.5,lw=2)
        dt.plot_cells(lw=13,facecolor='#ddddff',edgecolor='w',zorder=-5)
Exemple #3
0
def test_delete3():
    plot=False
    dt = Triangulation()

    nodes=[ dt.add_node( x=[10,i] )
            for i in range(10) ]

    dt.delete_node( nodes[0])
    dt.delete_node( nodes[4])
    if plot:
        plt.cla()
        dt.plot_nodes()
        dt.plot_edges(alpha=0.5,lw=2)
        dt.plot_cells(lw=13,facecolor='#ddddff',edgecolor='w',zorder=-5)
Exemple #4
0
def test_flip2():
    plot=False
    dt = Triangulation()

    dt.add_node( x=[0,0] )
    for i in range(5):
        dt.add_node( x=[10,i] )
    # This one requires a flip:
    n=dt.add_node( x=[5,1] )
    
    if plot:
        plt.cla()
        dt.plot_nodes()
        dt.plot_edges(alpha=0.5,lw=2)
        dt.plot_cells(lw=13,facecolor='#ddddff',edgecolor='w',zorder=-5)
Exemple #5
0
def test_delete4():
    plot=False
    dt = Triangulation()

    dt.add_node( x=[0,0] )
    dt.add_node( x=[5,0] )
    dt.add_node( x=[10,0] )
    dt.add_node( x=[-2,3] )
    dt.add_node( x=[-2,-3] )

    # and now delete the one in the middle:
    dt.delete_node(1)

    if plot:
        plt.cla()
        dt.plot_nodes(labeler=lambda n,nrec: str(n) )
        dt.plot_edges(alpha=0.5,lw=2)
        dt.plot_cells(lw=7,facecolor='#ddddff',edgecolor='w',zorder=-5)
Exemple #6
0
def test_flip1():
    plot=False
    dt = Triangulation()
    pnts = [ [0,0],
             [8,0],
             [10,5],
             [5,5] ]

    dt.add_node( x=pnts[0] ) # This tests insert into empty
    dt.add_node( x=pnts[1] ) # adjacent_vertex
    dt.add_node( x=pnts[2] ) # adjacent_vertex
    dt.add_node( x=pnts[3] ) # adjacent_edge

    dt.add_node( x=[3,0] ) # colinear
    if plot:
        plt.clf()
        dt.plot_nodes()
        dt.plot_edges(alpha=0.5,lw=2)
        dt.plot_cells(lw=13,facecolor='#ddddff',edgecolor='w',zorder=-5)
Exemple #7
0
def test_fuzz1():
    plot=False
    # Fuzzing, regular
    x=np.arange(5)
    y=np.arange(5)

    X,Y=np.meshgrid(x,y)
    xys=np.array([X.ravel(),Y.ravel()]).T

    if plot:
        plt.figure(1).clf()
        fig,ax=plt.subplots(num=1)

        ax.plot(xys[:,0],xys[:,1],'go',alpha=0.4)
        ax.axis([-1,5,-1,5])

    idxs=np.zeros(len(xys),'i8')-1

    dt = Triangulation()

    # definitely slows down as the number of nodes gets larger.
    # starting off with <1s per 100 operations, later more like 2s
    for repeat in range(1):
        print "Repeat: ",repeat
        for step in range(1000):
            if step%200==0:
                print "  step: ",step
            toggle=np.random.randint(len(idxs))
            if idxs[toggle]<0:
                idxs[toggle] = dt.add_node( x=xys[toggle] )
            else:
                dt.delete_node(idxs[toggle])
                idxs[toggle]=-1

            if plot:
                del ax.lines[1:]
                ax.texts=[]
                ax.collections=[]
                dt.plot_nodes(labeler=lambda n,nrec: str(n) )
                dt.plot_edges(alpha=0.5,lw=2)
                dt.plot_cells(lw=7,facecolor='#ddddff',edgecolor='w',zorder=-5)
                plt.draw()
Exemple #8
0
def test_delete2():
    plot=False
    dt = Triangulation() # ExactDelaunay()

    dt.add_node( x=[0,0] )
    for i in range(5):
        if 0: # sparser nodes for testing
            if i>0 and i<4:
                continue
        dt.add_node( x=[10,i] )
    # This one requires a flip:
    n=dt.add_node( x=[5,1] )
    
    far=dt.add_node( x=[12,4] ) 

    dt.delete_node(0) 
    if plot:
        plt.cla()
        dt.plot_nodes(labeler=lambda n,nr:str(n))
        dt.plot_edges(alpha=0.5,lw=2)
        dt.plot_cells(lw=6,facecolor='#ddddff',edgecolor='w',zorder=-5)
Exemple #9
0
def test_flip2():
    plot=False
    # testing Delaunay flipping
    dt = Triangulation() # ExactDelaunay()

    dt.add_node( x=[0,0] )
    for i in range(10):
        dt.add_node( x=[10,i] )

    dt.add_node( x=[5,1.0] ) 

    dt.add_node( x=[10,10] ) 
    dt.add_node( x=[5,2] )
    
    # and test a flip when the new vertex is outside the convex hull
    dt.add_node( x=[5,-1])

    dt.delete_node(11)

    if plot:
        plt.cla()
        dt.plot_nodes(labeler=lambda n,nrec: str(n) )
        dt.plot_edges(alpha=0.5,lw=2)
        dt.plot_cells(lw=13,facecolor='#ddddff',edgecolor='w',zorder=-5)
Exemple #10
0
def test_delete1():
    plot=False
    dt = Triangulation() # ExactDelaunay()

    dt.add_node( x=[0,0] )
    for i in range(5):
        dt.add_node( x=[10,i] )
    # This one requires a flip:
    n=dt.add_node( x=[5,1] )
    if plot:
        plt.cla()
        dt.plot_nodes(labeler=lambda n,nr:str(n))
        dt.plot_edges(alpha=0.5,lw=2)

        bad=(~dt.cells['deleted'])&(dt.cells_area()<=0)
        good=(~dt.cells['deleted'])&(dt.cells_area()>0)
        dt.plot_cells(lw=8,facecolor='#ddddff',edgecolor='w',zorder=-5,mask=good)
        dt.plot_cells(lw=8,facecolor='#ffdddd',edgecolor='r',zorder=-5,mask=bad)

    # deleting n work okay
    dt.delete_node(n)

    if plot:
        plt.cla()
        dt.plot_nodes(labeler=lambda n,nr:str(n))
        dt.plot_edges(alpha=0.5,lw=2)

        bad=(~dt.cells['deleted'])&(dt.cells_area()<=0)
        good=(~dt.cells['deleted'])&(dt.cells_area()>0)
        dt.plot_cells(lw=8,facecolor='#ddddff',edgecolor='w',zorder=-5,mask=good)
        dt.plot_cells(lw=8,facecolor='#ffdddd',edgecolor='r',zorder=-5,mask=bad)

    # delete a node which defines part of the convex hull:
    dt.delete_node(5) # works, though may need to patch up edges['cells'] ?
    dt.delete_node(2) # collinear portion of the convex hull
    dt.delete_node(3)

    # everything looks okay.  Surprising that we didn't have to
    # add code to deal with this case...

    if plot:
        plt.cla()
        dt.plot_nodes(labeler=lambda n,nr:str(n))
        dt.plot_edges(alpha=0.5,lw=2)

        bad=(~dt.cells['deleted'])&(dt.cells_area()<=0)
        good=(~dt.cells['deleted'])&(dt.cells_area()>0)
        dt.plot_cells(lw=8,facecolor='#ddddff',edgecolor='w',zorder=-5,mask=good)
        dt.plot_cells(lw=8,facecolor='#ffdddd',edgecolor='r',zorder=-5,mask=bad)

    dt.delete_node(0)

    if plot:
        assert dt.dim() == 1

        plt.cla()
        dt.plot_nodes(labeler=lambda n,nr:str(n))
        dt.plot_edges(alpha=0.5,lw=2)

        bad=(~dt.cells['deleted'])&(dt.cells_area()<=0)
        good=(~dt.cells['deleted'])&(dt.cells_area()>0)
        dt.plot_cells(lw=8,facecolor='#ddddff',edgecolor='w',zorder=-5,mask=good)
        dt.plot_cells(lw=8,facecolor='#ffdddd',edgecolor='r',zorder=-5,mask=bad)