Changeset 5207 for anuga_core/source/anuga/pmesh/mesh.py
- Timestamp:
- Apr 11, 2008, 4:18:26 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/pmesh/mesh.py
r5188 r5207 583 583 return h 584 584 585 def add_region(self, x,y, geo_reference=None ):585 def add_region(self, x,y, geo_reference=None, tag=None): 586 586 """ 587 587 adds a point, which represents a region. … … 594 594 [[x,y]] = self.geo_reference.change_points_geo_ref([x,y], 595 595 points_geo_ref=geo_reference) 596 return self._addRegion(x, y) 596 region = self._addRegion(x, y) 597 if tag is not None: 598 region.setTag(tag) 599 return region 597 600 598 601 def build_grid(self, vert_rows, vert_columns): … … 680 683 so if the user whats to modify it they can. 681 684 """ 682 if max_triangle_area is None :685 if max_triangle_area is None and region_tag is None: 683 686 create_region = False 684 687 else: … … 779 782 # Due to this default this method is too connected to 780 783 # _add_area_from_polygon 781 782 784 segment_tags = ['']*number_of_segs 783 785 if tags is not None: … … 1881 1883 1882 1884 1883 def import_ungenerate_file(self,ofile, tag=None ):1885 def import_ungenerate_file(self,ofile, tag=None, region_tag=None): 1884 1886 """ 1885 1887 Imports an ungenerate file, from arcGIS into mesh. 1886 1888 1887 1889 ofile is the name of the ungenerated file. 1888 Tag is a string name to be taggged on each segment. 1890 Tag is a string name to be taggged on each segment. 1891 1892 region_tag is the tag applied to the building regions. 1893 if it is a string the one value will be assigned to all regions 1894 if it is a list the first value in the list will be applied to the first polygon etc. 1895 WARNING: size of list and number of polygons isn't checked 1889 1896 1890 1897 WARNING values are assumed to be absolute. … … 1896 1903 if tag is not None: 1897 1904 Segment.set_default_tag(str(tag)) 1898 self.addVertsSegs(dict) 1905 1906 if region_tag is None: 1907 self.addVertsSegs(dict) 1908 else: 1909 if not isinstance(region_tag, list): 1910 region_tag = [region_tag]*len(dict['polygons']) 1911 for a_tag,polygon in map(None, region_tag, dict['polygons']): 1912 segment_tags = {tag:range(len(polygon))} 1913 self.add_region_from_polygon(polygon,segment_tags=segment_tags, 1914 region_tag=a_tag) 1915 1916 1899 1917 Segment.set_default_tag(default_tag) 1900 1918 1901 # change the tag back to 1919 # change the tag back to it's default 1902 1920 1903 1921 … … 2164 2182 last line: "END" 2165 2183 """ 2184 2166 2185 END_DELIMITER = 'END' 2167 2186 2168 2187 points = [] 2169 2188 segments = [] 2189 polygons = [] 2170 2190 2171 2191 isEnd = False 2172 2192 line = fd.readline() #not used <# of polynomial> <x> <y> 2173 2193 while not isEnd: 2194 poly = [] 2174 2195 line = fd.readline() 2175 2196 fragments = line.split() 2176 vert = [float(fragments.pop(0)),float(fragments.pop(0))] 2177 points.append(vert) 2197 x = float(fragments.pop(0)) 2198 y = float(fragments.pop(0)) 2199 points.append([x,y]) 2200 poly.append([x,y]) 2178 2201 PreviousVertIndex = len(points)-1 2179 2202 firstVertIndex = PreviousVertIndex … … 2183 2206 #print "line >" + line + "<" 2184 2207 fragments = line.split() 2185 vert = [float(fragments.pop(0)),float(fragments.pop(0))] 2186 points.append(vert) 2208 x = float(fragments.pop(0)) 2209 y = float(fragments.pop(0)) 2210 points.append([x,y]) 2211 poly.append([x,y]) 2187 2212 thisVertIndex = len(points)-1 2188 2213 segment = [PreviousVertIndex,thisVertIndex] … … 2190 2215 PreviousVertIndex = thisVertIndex 2191 2216 line = fd.readline() #Read the next line 2192 i =+ 12193 2217 # If the last and first segments are the same, 2194 2218 # Remove the last segment and the last vertex … … 2202 2226 points.pop() 2203 2227 segments.pop() 2228 poly.pop() 2204 2229 thisVertIndex = len(points)-1 2205 2230 segments.append([thisVertIndex, firstVertIndex]) 2206 2231 2207 2232 line = fd.readline() # read <# of polynomial> <x> <y> OR END 2208 2233 #print "line >>" + line + "<<" 2234 # do poly stuff here 2235 polygons.append(poly) 2209 2236 if line.startswith(END_DELIMITER): 2210 2237 isEnd = True … … 2215 2242 ungenerated_dict['points'] = points 2216 2243 ungenerated_dict['segments'] = segments 2244 ungenerated_dict['polygons'] = polygons 2217 2245 return ungenerated_dict 2218 2246
Note: See TracChangeset
for help on using the changeset viewer.