Changeset 2301
- Timestamp:
- Jan 30, 2006, 3:27:09 PM (19 years ago)
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
development/momentum_sink/create_buildings.py
r2298 r2301 28 28 m.add_hole_from_polygon(polygon, tags={'wall':[0,1,2,3]}) 29 29 30 m.add_circle([20,70], 5, hole=True, tag='wall') 30 31 m.generate_mesh(maximum_triangle_area=maximum_triangle_area) 31 triangle_count = len(m.getTriangulation())32 triangle_count = m.get_triangle_count() 32 33 33 34 if mesh_file is None: -
inundation/pmesh/mesh.py
r2297 r2301 673 673 so if the user whats to modify it they can. 674 674 """ 675 return self._add_area_from_polygon(polygon, tags=tags, 676 max_triangle_area=max_triangle_area, 677 geo_reference=geo_reference) 675 if max_triangle_area is None: 676 create_region = False 677 else: 678 create_region = True 679 680 region = self._add_area_from_polygon(polygon, tags=tags, 681 geo_reference=geo_reference, 682 region=create_region) 683 if max_triangle_area is not None: 684 region.setMaxArea(max_triangle_area) 685 return region 686 678 687 679 688 def _add_area_from_polygon(self, polygon, tags=None, 680 max_triangle_area=None,681 689 geo_reference=None, 682 hole=False): 690 hole=False, 691 region=False): 683 692 """ 684 693 Add a polygon with tags to the current mesh, as a region. … … 733 742 region_dict['segment_tags'] = segment_tags 734 743 735 self.addVertsSegs(region_dict) #this is assuming absolute geos 736 737 inner = None 738 739 if max_triangle_area is not None and hole is False: 744 self.addVertsSegs(region_dict) #this is passing absolute values 745 746 if region is True: 740 747 #get inner point - absolute values 741 748 inner_point = point_in_polygon(polygon) 742 749 inner = self.add_region(inner_point[0], inner_point[1], 743 750 geo_reference=None) 744 inner.setMaxArea(max_triangle_area) 745 746 if hole is True: 751 elif hole is True: 747 752 #get inner point - absolute values 748 753 inner_point = point_in_polygon(polygon) 749 754 inner = self.add_hole(inner_point[0], inner_point[1], 750 geo_reference=None) 755 geo_reference=None) 756 else: 757 inner = None 751 758 752 759 return inner 760 761 def add_circle(self, center, radius, segment_count=100, 762 center_geo_reference=None, tag = None, 763 region=False, hole=False): 764 """ 765 center is a point, in absulute or relative to center_geo_ref 766 radius is the radius of the circle 767 segment_count is the number of segments used to represent the circle 768 tag is a string name, given to the segments. 769 If region is True a region object is returned. 770 If hole is True a hole object is returned. 771 (Don't have them both True.) 772 773 774 """ 775 pass 776 # convert center and radius to a polygon 777 ### pi = math.pi 778 ### num_of_cuts = 100 779 cuts = [] 780 factor = 2* math.pi/segment_count 781 for cut in range(segment_count): 782 cuts.append(cut*factor) 783 784 polygon = [] 785 for cut in cuts: 786 787 x = center[0] + radius * math.cos(cut) 788 y = center[1] + radius * math.sin(cut) 789 polygon.append([x,y]) 790 # build the tags 791 tags = {tag:range(segment_count)} 792 793 return self._add_area_from_polygon(polygon, tags=tags, 794 region=region, hole=hole, 795 geo_reference=center_geo_reference) 796 797 def addVertsSegs(self, outlineDict): 798 """ 799 Add out-line (user Mesh) attributes given a dictionary of the lists 800 points: [(x1,y1),(x2,y2),...] (Tuples of doubles) 801 segments: [(point1,point2),(p3,p4),...] (Tuples of integers) 802 segment_tags: [S1Tag, S2Tag, ...] (list of strings) 803 804 Assume the values are in Eastings and Northings, with no reference 805 point. eg absolute 806 """ 807 if not outlineDict.has_key('segment_tags'): 808 outlineDict['segment_tags'] = [] 809 for i in range(len(outlineDict['segments'])): 810 outlineDict['segment_tags'].append('') 811 #print "outlineDict['segment_tags']",outlineDict['segment_tags'] 812 #print "outlineDict['points']",outlineDict['points'] 813 #print "outlineDict['segments']",outlineDict['segments'] 814 815 localUserVertices = [] 816 #index = 0 817 for point in outlineDict['points']: 818 v=Vertex(point[0]-self.geo_reference.xllcorner, 819 point[1]-self.geo_reference.yllcorner) 820 #v.index = index 821 #index +=1 822 self.userVertices.append(v) 823 localUserVertices.append(v) 824 825 #index = 0 826 for seg,seg_tag in map(None,outlineDict['segments'], 827 outlineDict['segment_tags']): 828 segObject = Segment( localUserVertices[seg[0]], 829 localUserVertices[seg[1]] ) 830 if not seg_tag == '': 831 segObject.set_tag(seg_tag) 832 #segObject.index = index 833 #index +=1 834 self.userSegments.append(segObject) 835 #DSG!!! 836 837 def get_triangle_count(self): 838 return len(self.getTriangulation()) 753 839 754 840 def getUserVertices(self): … … 1342 1428 #index +=1 1343 1429 self.regions.append(Object) 1344 1345 def addVertsSegs(self, outlineDict):1346 """1347 Add out-line (user Mesh) attributes given a dictionary of the lists1348 points: [(x1,y1),(x2,y2),...] (Tuples of doubles)1349 segments: [(point1,point2),(p3,p4),...] (Tuples of integers)1350 segment_tags: [S1Tag, S2Tag, ...] (list of strings)1351 1352 Assume the values are in Eastings and Northings, with no reference1353 point. eg absolute1354 """1355 if not outlineDict.has_key('segment_tags'):1356 outlineDict['segment_tags'] = []1357 for i in range(len(outlineDict['segments'])):1358 outlineDict['segment_tags'].append('')1359 #print "outlineDict['segment_tags']",outlineDict['segment_tags']1360 #print "outlineDict['points']",outlineDict['points']1361 #print "outlineDict['segments']",outlineDict['segments']1362 1363 localUserVertices = []1364 #index = 01365 for point in outlineDict['points']:1366 v=Vertex(point[0]-self.geo_reference.xllcorner,1367 point[1]-self.geo_reference.yllcorner)1368 #v.index = index1369 #index +=11370 self.userVertices.append(v)1371 localUserVertices.append(v)1372 1373 #index = 01374 for seg,seg_tag in map(None,outlineDict['segments'],1375 outlineDict['segment_tags']):1376 segObject = Segment( localUserVertices[seg[0]],1377 localUserVertices[seg[1]] )1378 if not seg_tag == '':1379 segObject.set_tag(seg_tag)1380 #segObject.index = index1381 #index +=11382 self.userSegments.append(segObject)1383 #DSG!!!1384 1430 1385 1431 def TestautoSegment(self): -
inundation/pmesh/pmesh.py
r1625 r2301 490 490 self.Segments = None 491 491 self.Triangles = None 492 492 493 493 494 def addCylinders(self): 494 495 """ 495 496 Automatically add some verts and segs to the mesh.Used in Debugging 496 """ 497 498 center and radius 499 500 """ 501 502 497 503 from coordinate_transforms.geo_reference import Geo_reference,DEFAULT_ZONE 498 504 offset_x = 30 499 505 offset_y = 40 500 v1 = self.drawVertex(0-offset_x,0-offset_y,None)501 v2 = self.drawVertex(50-offset_x,2-offset_y,None)502 v3 = self.drawVertex(70-offset_x,30-offset_y,None)503 v4 = self.drawVertex(25-offset_x,50-offset_y,None)504 v5 = self.drawVertex(-10-offset_x,20-offset_y,None)505 #v5 = self.drawVertex(25,50,None)506 s1 = self.drawSegment(v1,v2)507 s1.set_tag("s1")508 s2 = self.drawSegment(v2,v3)509 s2.set_tag("s2")510 s3 = self.drawSegment(v3,v4)511 s3.set_tag("s3")512 s4 = self.drawSegment(v4,v5)513 s4.set_tag("s4")514 s5 = self.drawSegment(v1,v5)515 s5.set_tag("s5")516 506 517 507 x_origin = 10-offset_x … … 567 557 #Since the new vertex may be off screen 568 558 self.scrolledcanvas.resizescrollregion() 569 570 # generate the mesh571 minAngle = 30.0572 numTriangles = 20000573 self.clearSelections()574 self.canvas.delete(ALL)575 self.mesh = self.MeshGenAreaNumTriangles (minAngle,576 numTriangles,577 self.mesh)578 self.UserMeshChanged = False579 self.visualiseMesh(self.mesh)580 print "Mesh Generation finished"581 559 582 560 def selectFunc(self, tag): -
inundation/pmesh/test_mesh.py
r2297 r2301 1849 1849 self.failUnless(point_x == new_point_x, ' failed') 1850 1850 self.failUnless(point_y == new_point_y, ' failed') 1851 1852 1851 1852 def test_add_circle(self): 1853 x=-500 1854 y=-1000 1855 m=Mesh(geo_reference=Geo_reference(56,x,y)) 1856 1857 # These are the absolute values 1858 tag = 'hey' 1859 segment_count = 104 1860 radius = 30 1861 circle_center_absolute = [100,80] 1862 x_p = -.666 1863 y_p = -.777 1864 geo_ref_poly = Geo_reference(56, x_p, y_p) 1865 circle_center = \ 1866 geo_ref_poly.change_points_geo_ref(circle_center_absolute) 1867 circle_center = circle_center[0] #make a list of lists a list 1868 poly_point = m.add_circle(circle_center, radius, segment_count, 1869 tag=tag, 1870 region=True, 1871 center_geo_reference=geo_ref_poly) 1872 # poly_point values are relative to the mesh geo-ref 1873 # make them absolute 1874 #print "poly_point.x+x",poly_point.x+x 1875 #print "polygon_absolute", polygon_absolute 1876 1877 1878 m.export_mesh_file("aaat.msh") 1879 1880 self.failUnless(len(m.regions)==1, 1881 'FAILED!') 1882 segs = m.getUserSegments() 1883 self.failUnless(len(segs)==segment_count, 1884 'FAILED!') 1885 self.failUnless(len(m.userVertices)==segment_count, 1886 'FAILED!') 1887 self.failUnless(segs[0].tag==tag, 1888 'FAILED!') 1889 self.failUnless(segs[1].tag==tag, 1890 'FAILED!') 1891 1892 verts = m.getUserVertices() 1893 1894 m.export_mesh_file("aaat.msh") 1895 1853 1896 1854 1897 def list_comp(A,B): -
inundation/pmesh/test_mesh_interface.py
r2295 r2301 47 47 48 48 # Test the mesh instance 49 50 49 self.failUnless(len(m.regions)==3, 51 50 'FAILED!') -
production/gippsland_2005/create_mesh2.py
r2163 r2301 3 3 """ 4 4 5 #import os, sys 6 #sys.path.append('..') 7 8 9 10 # add storm_surge dir to your pythonpath 5 # add inundation dir to your pythonpath 11 6 from pmesh.mesh import * 12 from pyvolution.coordinate_transforms.geo_reference import Geo_reference7 from coordinate_transforms.geo_reference import Geo_reference 13 8 14 9
Note: See TracChangeset
for help on using the changeset viewer.