Changeset 3038


Ignore:
Timestamp:
Jun 1, 2006, 12:13:01 PM (18 years ago)
Author:
ole
Message:

Added test for detecting interior polygons that stick outside bounding polygon
and also Jane's code for catching it. However, due to the way georeferencing
is resolved it is not so simple. Currently, the new test is failing.

Location:
inundation/pmesh
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/pmesh/mesh_interface.py

    r2430 r3038  
    6363    #In addition I reckon the polygons could be of class Geospatial_data
    6464
     65
     66    # First check that interior polygons are fully contained in bounding polygon
     67
     68    # FIXME (Ole): This causes the tests to fail because coordinates have been
     69    # converted to relative coordinates (I think). How can we simplify this?
     70    #
     71    #if interior_regions is not None:       
     72    #    from utilities.polygon import inside_polygon
     73    #
     74    #    for interior_polygon, res in interior_regions:
     75    #        indices = inside_polygon(interior_polygon, bounding_polygon,
     76    #                                 closed = True, verbose = False)
     77    #
     78    #        if len(indices) <> len(interior_polygon):
     79    #            msg = 'Interior polygon %s is outside bounding polygon: %s'\
     80    #                  %(str(interior_polygon), str(bounding_polygon))
     81    #            raise msg
     82
     83
     84
     85    # Resolve geo referencing       
    6586    if mesh_geo_reference is None:
    6687        bounding_polygon = ensure_numeric(bounding_polygon, Float)
     
    81102    m = Mesh(geo_reference=mesh_geo_reference)
    82103
    83     #Do bounding polygon
     104    # Do bounding polygon
    84105    m.add_region_from_polygon(bounding_polygon,
    85106                              tags=boundary_tags,
    86107                              geo_reference=poly_geo_reference)
    87108
    88     #Find one point inside region automatically
     109    # Find one point inside region automatically
    89110    if interior_regions is not None:
    90111        excluded_polygons = []       
     
    97118
    98119
    99     # convert bounding poly to absolute values
     120    # Convert bounding poly to absolute values
    100121    # this sort of thing can be fixed with the geo_points class
    101122    if poly_geo_reference is not None:
     
    110131    inner.setMaxArea(maximum_triangle_area)
    111132
    112     #Do interior regions
     133    # Do interior regions
    113134    if interior_regions is not None:   
    114135        for polygon, res in interior_regions:
  • inundation/pmesh/test_mesh_interface.py

    r3013 r3038  
    221221                        'FAILED!')
    222222
     223    def test_create_mesh_from_regions_interior_regions(self):
     224        """Test that create_mesh_from_regions fails when an interior region is
     225        outside bounding polygon.
     226        """
     227
     228        # These are the absolute values
     229        min_x = 10
     230        min_y = 88
     231        polygon = [[min_x,min_y],[1000,100],[1000,1000],[100,1000]]
     232
     233       
     234        boundary_tags = {'walls':[0,1],'bom':[2]}
     235
     236        # This one is inside bounding polygon - should pass
     237        inner_polygon = [[800,400],[900,500],[800,600]]
     238       
     239        interior_regions = [(inner_polygon, 5)]
     240        m = create_mesh_from_regions(polygon,
     241                                     boundary_tags,
     242                                     10000000,
     243                                     interior_regions=interior_regions)
     244
     245
     246        # This one sticks outside bounding polygon - should fail
     247        inner_polygon = [[800,400],[1100,500],[800,600]]
     248        interior_regions = [(inner_polygon, 5)]
     249
     250
     251       
     252        try:
     253            m = create_mesh_from_regions(polygon,
     254                                         boundary_tags,
     255                                         10000000,
     256                                         interior_regions=interior_regions)
     257        except:
     258            pass
     259        else:
     260            msg = 'Interior polygon sticking outside bounding polygon should '
     261            msg += 'cause an Exception to be raised'
     262            raise msg
     263
     264       
     265
    223266
    224267    def test_create_mesh_from_regions_with_duplicate_verts(self):
Note: See TracChangeset for help on using the changeset viewer.