Exemple #1
0
def test_basic_setup():
    boundary=hex_curve()
    af=front.AdvancingTriangles()
    scale=field.ConstantField(3)

    af.add_curve(boundary)
    af.set_edge_scale(scale)

    # create boundary edges based on scale and curves:
    af.initialize_boundaries()

    return af
Exemple #2
0
def trifront_wrapper(rings, scale, label=None):
    af = front.AdvancingTriangles()
    af.set_edge_scale(scale)

    af.add_curve(rings[0], interior=False)
    for ring in rings[1:]:
        af.add_curve(ring, interior=True)
    af.initialize_boundaries()

    try:
        result = af.loop()
    finally:
        if label is not None:
            plt.figure(1).clf()
            af.grid.plot_edges(lw=0.5)
            plt.savefig('af-%s.png' % label)
    assert result

    return af
Exemple #3
0
def test_free_span():
    r = 5
    theta = np.linspace(-np.pi / 2, np.pi / 2, 20)
    cap = r * np.swapaxes(np.array([np.cos(theta), np.sin(theta)]), 0, 1)
    box = np.array([[-3 * r, r], [-4 * r, -r]])
    ring = np.concatenate((box, cap))

    density = field.ConstantField(2 * r / (np.sqrt(3) / 2))
    af = front.AdvancingTriangles()
    af.set_edge_scale(density)

    af.add_curve(ring, interior=False)
    af.initialize_boundaries()

    # N.B. this edge is not given proper cell neighbors
    af.grid.add_edge(nodes=[22, 3])

    af.plot_summary()

    he = af.grid.nodes_to_halfedge(4, 5)
    span_dist, span_nodes = af.free_span(he, 25, 1)
    assert span_nodes[-1] != 4
Exemple #4
0
def test_basic_setup():
    boundary = hex_curve()
    af = front.AdvancingTriangles()
    scale = field.ConstantField(3)

    af.add_curve(boundary)
    af.set_edge_scale(scale)

    # create boundary edges based on scale and curves:
    af.initialize_boundaries()

    if 0 and plt:
        plt.clf()
        g = af.grid
        g.plot_edges()
        g.plot_nodes()

        #
        coll = g.plot_halfedges(values=g.edges['cells'])
        coll.set_lw(0)
        coll.set_cmap('winter')

    return af
    B = pnts[1:]

    for a, b in zip(A, B):
        na = g.add_or_find_node(x=a)
        nb = g.add_or_find_node(x=b)
        try:
            j = g.add_edge(nodes=[na, nb])
        except g.GridException:
            pass

cycles = g.find_cycles(max_cycle_len=g.Nnodes())
polys = [geometry.Polygon(g.nodes['x'][cycle]) for cycle in cycles]

# scale=field.ConstantField(100)
scale = apollo  # out of order, from below
af = front.AdvancingTriangles(grid=g, scale=scale)
af.cost_method = 'base'  # trying that again..
af.initialize_boundaries()

# May need to doctor up some things

# Nodes of degree>2 are fixed:
for n in g.valid_node_iter():
    if g.node_degree(n) > 2:
        g.nodes['fixed'][n] = af.RIGID

g.nodes['oring'] = 0

node_rigid = af.grid.nodes['fixed'] == af.RIGID

# All of these nodes go on Curves
Exemple #6
0
def triangulate_hole(grid,seed_point,max_nodes=5000):
    # manually tell it where the region to be filled is.
    # 5000 ought to be plenty of nodes to get around this loop
    nodes=grid.enclosing_nodestring(seed_point,max_nodes)
    xy_shore=grid.nodes['x'][nodes]

    # Construct a scale based on existing spacing
    # But only do this for edges that are part of one of the original grids
    grid.edge_to_cells() # update edges['cells']
    sample_xy=[]
    sample_scale=[]
    ec=grid.edges_center()
    el=grid.edges_length()

    for na,nb in utils.circular_pairs(nodes):
        j=grid.nodes_to_edge([na,nb])
        if np.any( grid.edges['cells'][j] >= 0 ):
            sample_xy.append(ec[j])
            sample_scale.append(el[j])

    sample_xy=np.array(sample_xy)
    sample_scale=np.array(sample_scale)

    apollo=field.PyApolloniusField(X=sample_xy,F=sample_scale)

    # Prepare that shoreline for grid generation.

    grid_to_pave=unstructured_grid.UnstructuredGrid(max_sides=6)

    AT=front.AdvancingTriangles(grid=grid_to_pave)

    AT.add_curve(xy_shore)
    # This should be safe about not resampling existing edges
    AT.scale=field.ConstantField(50000)

    AT.initialize_boundaries()

    AT.grid.nodes['fixed'][:]=AT.RIGID
    AT.grid.edges['fixed'][:]=AT.RIGID

    # Old code compared nodes to original grids to figure out RIGID
    # more general, if it works, to see if a node participates in any cells.
    # At the same time, record original nodes which end up HINT, so they can
    # be removed later on.
    src_hints=[]
    for n in AT.grid.valid_node_iter():
        n_src=grid.select_nodes_nearest(AT.grid.nodes['x'][n])
        delta=utils.dist( grid.nodes['x'][n_src], AT.grid.nodes['x'][n] )
        assert delta<0.1 # should be 0.0

        if len(grid.node_to_cells(n_src))==0:
            # It should be a HINT
            AT.grid.nodes['fixed'][n]=AT.HINT
            src_hints.append(n_src)
            # And any edges it participates in should not be RIGID either.
            for j in AT.grid.node_to_edges(n):
                AT.grid.edges['fixed'][j]=AT.UNSET

    AT.scale=apollo
    
    if AT.loop():
        AT.grid.renumber()
    else:
        print("Grid generation failed")
        return AT # for debugging -- need to keep a handle on this to see what's up.

    for n in src_hints:
        grid.delete_node_cascade(n)
        
    grid.add_grid(AT.grid)

    # Surprisingly, this works!
    grid.merge_duplicate_nodes()

    grid.renumber()

    return grid
Exemple #7
0
    [569065, 4150143],
    [571104, 4152122],
    [571454, 4152500],
    [571926, 4151130],
    [569398, 4151137],
    [572595, 4149360],
    [567825, 4154910],
]

# Point [568704, 4150722] returned no node string

# Had been 50, but maybe 65 will get us up to scale faster?
#scale=field.PyApolloniusField(X=g_janet.nodes['x'],
#                              F=65*np.ones(g_janet.Nnodes()))

af = front.AdvancingTriangles(grid=g_janet)  # ,scale=scale)
af.cost_method = 'base'  # trying that again..

# superceded by all_missing below

# furthermore, only the inward facing edges in the selected cycle should be flagged
# UNMESHED and subject to gridding.  Set all missing cells to UNDEFINED, then come
# back to set just the cycle we want.
all_missing = af.grid.edges['cells'] < 0
af.grid.edges['cells'][all_missing] = af.grid.UNDEFINED

if 1:
    # Select enclosing polygons for specific points:
    for internal_pnt in internal_pnts:
        node_string = g_janet.enclosing_nodestring(internal_pnt, max_nodes=-1)
        if node_string is None:
Exemple #8
0
apollo = field.PyApolloniusField(X=sample_xy, F=sample_scale)

##

# Prepare that shoreline for grid generation.
from stompy.grid import front, cgal_line_walk, shadow_cdt
from stompy.spatial import field, robust_predicates

six.moves.reload_module(robust_predicates)
six.moves.reload_module(cgal_line_walk)
six.moves.reload_module(shadow_cdt)
six.moves.reload_module(front)

grid_to_pave = unstructured_grid.UnstructuredGrid(max_sides=6)

AT = front.AdvancingTriangles(grid=grid_to_pave)

AT.add_curve(xy_shore)
# This should be safe about not resampling existing edges
AT.scale = field.ConstantField(50000)

AT.initialize_boundaries()

##
AT.grid.nodes['fixed'][:] = AT.RIGID
AT.grid.edges['fixed'][:] = AT.RIGID

# Loop through the nodes, and if it doesn't line up exactly with
# a node in one of the source grids, then it becomes HINT
src_grids = [g_sfb, g_roms]