Changeset 9242
- Timestamp:
- Jul 4, 2014, 11:31:31 AM (10 years ago)
- Location:
- trunk/anuga_core/source/anuga/utilities
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/utilities/spatialInputUtil.py
r9233 r9242 352 352 353 353 ################################################################################# 354 def insert_intersection_point(intersectionPt, line_pts, point_movement_threshold ):354 def insert_intersection_point(intersectionPt, line_pts, point_movement_threshold, verbose=False): 355 355 """ 356 356 Add intersectionPt to line_pts, either by inserting it, or if a point on line_pts is … … 381 381 # account for the possibility of L1_pts having > 2 coordinates 382 382 # (riverWalls) 383 if verbose: 384 print ' Inserting new point' 383 385 dummyPt=copy.copy(L1_pts[tmp[1]]) 384 386 L1_pts.insert(tmp[1]+1,dummyPt) … … 390 392 # Set 3rd coordinate as distance-weighted average of the others 391 393 d0=((L1_pts[tmp[1]][0]-L1_pts[tmp[1]+1][0])**2.+\ 392 (L1_pts[tmp[1]][ 0]-L1_pts[tmp[1]+1][1])**2.)**0.5394 (L1_pts[tmp[1]][1]-L1_pts[tmp[1]+1][1])**2.)**0.5 393 395 d1=((L1_pts[tmp[1]+2][0]-L1_pts[tmp[1]+1][0])**2.+\ 394 396 (L1_pts[tmp[1]+2][1]-L1_pts[tmp[1]+1][1])**2.)**0.5 … … 396 398 397 399 else: 400 if verbose: 401 print ' Shifting existing point' 398 402 # Move a point already on L1 399 403 L1_pts=shift_point_on_line(iP, L1_pts, tmp[1]) … … 435 439 ####################################################################################################### 436 440 437 def addIntersectionPtsToLines(L1,L2, point_movement_threshold=0.0, buf=1.0e-0 6, tol2 = 100,441 def addIntersectionPtsToLines(L1,L2, point_movement_threshold=0.0, buf=1.0e-05, tol2 = 100, 438 442 verbose=True, nameFlag=''): 439 443 """ … … 495 499 # Insert the points into the line segments 496 500 for i in range(len(intersectionPts)): 497 L1_pts = insert_intersection_point(intersectionPts[i], L1_pts, point_movement_threshold )498 L2_pts = insert_intersection_point(intersectionPts[i], L2_pts, point_movement_threshold )501 L1_pts = insert_intersection_point(intersectionPts[i], L1_pts, point_movement_threshold, verbose=verbose) 502 L2_pts = insert_intersection_point(intersectionPts[i], L2_pts, point_movement_threshold, verbose=verbose) 499 503 500 504 # Convert to the input format … … 796 800 verbose=verbose, nameFlag='Bounding Pol intersects '+ n1) 797 801 riverWalls[n1]=Wkb2ListPts(rw1) 798 bounding_polygon=Wkb2ListPts(bp2,removeLast=True) 802 # Since the bounding polygon is a loop, the first/last points are the same 803 # If one of these was moved, the other should be moved too. Since we 804 # will drop the last bounding_polygon point, we only need to worry about the first 805 bounding_polygon=Wkb2ListPts(bp2,removeLast=False) 806 if(bounding_polygon[-1] is not bounding_polygon[0]): 807 bounding_polygon[0]=bounding_polygon[-1] 808 # Drop the last point 809 bounding_polygon=bounding_polygon[:-1] 799 810 800 811 # Clean intersections of bounding polygon and breaklines … … 813 824 verbose=verbose, nameFlag='Bounding Pol intersects '+n1) 814 825 breakLines[n1]=Wkb2ListPts(bl1) 815 bounding_polygon=Wkb2ListPts(bp2, removeLast=True) 816 826 # Since the bounding polygon is a loop, the first/last points are the same 827 # If one of these was moved, the other should be moved too. Since we 828 # will drop the last bp2 point, we only need to worry about the first 829 bounding_polygon=Wkb2ListPts(bp2,removeLast=False) 830 if(bounding_polygon[-1] is not bounding_polygon[0]): 831 bounding_polygon[0]=bounding_polygon[-1] 832 # Drop the last point 833 bounding_polygon=bounding_polygon[:-1] 834 817 835 # Remove the extra 0.0 from bounding polygon [this cannot have 3 coordinates] 818 836 bounding_polygon = [ bounding_polygon[i][0:2] for i in range(len(bounding_polygon))] … … 820 838 for n1 in breakLines.keys(): 821 839 breakLines[n1] = [breakLines[n1][i][0:2] for i in range(len(breakLines[n1]))] 840 841 # Check that all mesh-boundary points are inside the bounding polygon 842 from anuga.geometry.polygon import outside_polygon 843 for blCat in [riverWalls, breakLines]: 844 for n1 in blCat.keys(): 845 l=len(blCat[n1]) 846 # Test every point -- means we can strip 3rd coordinate if needed 847 for j in range(l): 848 isOut=outside_polygon(blCat[n1][j][0:2], bounding_polygon) 849 if(len(isOut)>0): 850 msg='Breakline/riverwall point '+str(blCat[n1][j][0:2]) +' on '+ n1+\ 851 ' is outside the bounding polygon.\n'+\ 852 'Check that it exceeds the bounding polygon by a distance < point_movement_threshold \n'+\ 853 ' so it can be moved back onto the polygon' 854 print 'Polygon\n ' 855 print bounding_polygon 856 print 'Line \n' 857 print blCat[n1] 858 raise Exception, msg 822 859 823 860 return [bounding_polygon, breakLines, riverWalls] … … 961 998 raise ImportError, msg 962 999 963 def insert_intersection_point(intersectionPt, line_pts, point_movement_threshold ):1000 def insert_intersection_point(intersectionPt, line_pts, point_movement_threshold,verbose=False): 964 1001 raise ImportError, msg 965 1002 -
trunk/anuga_core/source/anuga/utilities/test_spatialInputUtil.py
r9219 r9242 362 362 assert True 363 363 364 #print 'After first add_iinersections'365 364 ################################################################# 366 365 # Fix the riverwall, and it should work 367 riverWalls={ 'rw1': [[-0.0 1, 8., 2.],[10.01, 4., 3.]],368 'rw2': [[5.3, -0.01, 1.], [10., 10.01, 2.]]}366 riverWalls={ 'rw1': [[-0.000001, 8., 2.],[10.0000001, 4., 3.]] 367 } 369 368 # This should work 370 369 newBP, newBL, newRW=su.add_intersections_to_domain_features(bounding_polygon,\ 371 370 breakLines, riverWalls, point_movement_threshold=0.02,\ 372 371 verbose=verbose) 372 373 # There should be several new points on breakLines + riverWalls 374 assert newBL['bl1'][1]==newBL['bl2'][1] 375 assert newRW['rw1'][2][0:2]==newBL['bl1'][2] 376 assert newRW['rw1'][1][0:2]==newBL['bl2'][2] 377 # rw1 x/y coords are close to y=8-3/10*x 378 # x/z coords are close to z=2+x/10 379 assert numpy.allclose(newRW['rw1'][1][2], newRW['rw1'][1][0]/10.+2) 380 assert numpy.allclose(newRW['rw1'][2][2], newRW['rw1'][2][0]/10.+2) 373 381 374 382 return
Note: See TracChangeset
for help on using the changeset viewer.