示例#1
0
def test_basic():
    pa = field.PyApolloniusField()

    pa.insert([0, 0], 10)
    pa.insert([100, 100], 5)

    g = pa.to_grid(100, 100)
示例#2
0
def test_larger():
    # About 1.5s on basic macbook
    pa = field.PyApolloniusField()

    for it in range(1000):
        xy = 1000 * np.random.random(2)
        pa.insert(xy, 10)

    g = pa.to_grid(200, 200)
示例#3
0
def test_basic():
    pa = field.PyApolloniusField()

    pa.insert([0, 0], 10)
    pa.insert([100, 100], 5)

    g = pa.to_grid(100, 100)

    # good to test a single point, too
    pa([10, 10])
示例#4
0
def test_basic_apollo():
    # Define a polygon
    boundary=np.array([[0,0],[1000,0],[1000,1000],[0,1000]])
    island  =np.array([[200,200],[600,200],[200,600]])

    rings=[boundary,island]

    # And the scale:
    scale=field.PyApolloniusField()
    scale.insert([50,50],20)

    p=paver.Paving(rings=rings,density=scale)

    p.pave_all()
    return p
示例#5
0
import matplotlib.pyplot as plt

from shapely import geometry
from stompy import utils
from stompy.spatial import wkb2shp, field
from stompy.grid import unstructured_grid, shadow_cdt

from stompy.spatial import linestring_utils
from stompy.grid import front
from stompy.grid import shadow_cdt, exact_delaunay

##
bounds = wkb2shp.shp2geom('region-bounds-v00.shp')

xyz = np.loadtxt('apollo-xyz.txt')  # run gen_scale to make this
apollo = field.PyApolloniusField(X=xyz[:, :2], F=xyz[:, 2])

##

six.moves.reload_module(exact_delaunay)
six.moves.reload_module(shadow_cdt)
six.moves.reload_module(front)

# The actually grid generation step
g = unstructured_grid.UnstructuredGrid()

for geo in bounds['geom']:
    pnts = np.array(geo)

    A = pnts[:-1]
    B = pnts[1:]
示例#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
示例#7
0
        he = af.grid.nodes_to_halfedge(a, b)
        af.grid.edges['cells'][he.j, 1 - he.orient] = af.grid.UNDEFINED

    for n in node_string:
        if len(g_janet.node_to_cells(n)) > 0:
            af.grid.nodes['fixed'][n] = af.RIGID

# Edge rigid status
rigid_edges = g_janet.edges['cells'].max(axis=1) >= 0
af.grid.edges['fixed'][rigid_edges] = af.RIGID

# Update scale to be edge lengths for existing boundary edges
scale_edges = (af.grid.edges['cells'].min(axis=1)
               == af.grid.UNMESHED) & (af.grid.edges['cells'].max(axis=1) >= 0)

scale = field.PyApolloniusField(X=g_janet.edges_center()[scale_edges],
                                F=g_janet.edges_length()[scale_edges])
af.set_edge_scale(scale)

##

plt.figure(1).clf()
g_janet.plot_edges(color='k', lw=0.5)
P = np.array(internal_pnts)
plt.plot(P[:, 0], P[:, 1], 'go')
plt.axis('equal')

##

# This often has scale issues at the end
# af.loop(1000)
示例#8
0
# But only do this for edges that are part of one of the original grids
g_merge.edge_to_cells()  # update edges['cells']
sample_xy = []
sample_scale = []
ec = g_merge.edges_center()

for na, nb in utils.circular_pairs(nodes):
    j = g_merge.nodes_to_edge([na, nb])
    if np.any(g_merge.edges['cells'][j] >= 0):
        sample_xy.append(ec[j])
        sample_scale.append(
            utils.dist(g_merge.nodes['x'][na], g_merge.nodes['x'][nb]))
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.
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)