Changeset 4907
- Timestamp:
- Jan 4, 2008, 4:57:46 PM (17 years ago)
- Location:
- anuga_core/source
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/pmesh/graphical_mesh_generator.py
r4905 r4907 23 23 TRIANGLE_COLOUR = 'green' 24 24 APPLICATION_NAME = 'Pmesh' 25 SET_COLOUR = 'red'26 DEFAULT_ATTRIBUTE = 'elevation'27 25 28 26 #for alpha shapes … … 216 214 217 215 218 219 def Out_createSetTools(self):220 """221 Add set tool buttons to the top of the GUI222 """223 ToolBarButton(self, self.toolbar, 'sep', 'sep.gif', width=10,224 state='disabled')225 for key, func, balloon in [226 ('threshold', self.threshold, 'threshold the set'),227 ('Courant_threshold', self.Courant_threshold, 'Courant_threshold the set'),228 ('gradient_threshold', self.gradient_threshold, 'gradient_threshold the set'),229 ('smooth', self.smooth_polySet, 'smooth the polygons'),230 ('polyset', self.triangles_to_polySet, 'make a poly set out of selected triangles')]:231 #('refineSet', self.refineSet, 'Refine the set')]:232 ToolBarButton(self, self.toolbar, key, '%s.gif' %key,233 command=func, balloonhelp=balloon,234 statushelp='' )235 236 def createSetIcons(self):237 """238 Add Edit buttons to the top of the GUI239 """240 ToolBarButton(self, self.toolbar, 'sep', 'sep.gif', width=10,241 state='disabled')242 for key, func, balloon in [243 ('selectAllTriangles', self.selectAllTriangles, 'select all'),244 ('none', self.clearSelection, 'clear selection')]:245 ToolBarButton(self, self.toolbar, key, '%s.gif' %key,246 command=func, balloonhelp=balloon,247 statushelp='' )248 249 216 def createVisualiseIcons(self): 250 217 """ … … 261 228 262 229 263 def refineSet(self,parent):264 self.mesh.refineSet(self.selSet)265 self.visualiseMesh(self.mesh)266 267 268 def setStructureNumber(self,parent):269 dialog = setStructureNumberDialog(self.canvas)270 if dialog.numberOK:271 self.structureSize = dialog.number272 273 def erode(self, parent):274 #Not implimented275 self.canvas.delete(ALL)276 self.mesh.erode(self.selSet,structureSize=self.structureSize)277 self.visualiseMesh(self.mesh)278 279 280 def dilate(self, parent):281 #Not implimented282 self.canvas.delete(ALL)283 self.mesh.dilate(self.selSet,structureSize=self.structureSize)284 self.visualiseMesh(self.mesh)285 286 def general_threshold(self,parent,function,function_description):287 """288 add a vertex using a window and entering x y values.289 290 the parent attribute isn't used by this function.291 need to userstand toolbarbutton.py to know how to292 get rid of it.293 """294 if self.selSet == 'None':295 self.selectAllTriangles(parent)296 297 dialog = GeneralThresholdDialog(self.canvas,self.mesh.attributeTitles,function_description)298 if dialog.minmaxValuesOk:299 self.canvas.delete(ALL)300 min = dialog.min301 max = dialog.max302 attribute_name = dialog.attribute_name303 self.mesh.general_threshold(self.selSet,min=min,max=max,attribute_name = attribute_name,function=function)304 self.visualiseMesh(self.mesh)305 306 def threshold(self, parent):307 """308 add a vertex using a window and entering x y values.309 310 the parent attribute isn't used by this function.311 need to userstand toolbarbutton.py to know how to312 get rid of it.313 """314 function = self.mesh.av_att315 function_description = 'average attribute of triangle'316 self.general_threshold(parent,function,function_description)317 318 319 def Courant_threshold(self, parent):320 """321 add a vertex using a window and entering x y values.322 323 the parent attribute isn't used by this function.324 need to userstand toolbarbutton.py to know how to325 get rid of it.326 """327 function = self.mesh.Courant_ratio328 function_description = 'average attribute/area of triangle'329 self.general_threshold(parent,function,function_description)330 331 def gradient_threshold(self, parent):332 """333 add a vertex using a window and entering x y values.334 335 the parent attribute isn't used by this function.336 need to userstand toolbarbutton.py to know how to337 get rid of it.338 """339 function = self.mesh.Gradient340 function_description = 'average gradient of triangle'341 self.general_threshold(parent,function,function_description)342 343 def smooth_polySet(self,parent):344 dialog = SmoothDialog(self.canvas)345 if dialog.valueOK:346 min_radius = dialog.min_radius347 self._smooth_polySet(min_radius)348 349 def _smooth_polySet(self,min_radius):350 userVertices,userSegments,alphaSegments = \351 self.mesh.smooth_polySet(min_radius=min_radius)352 353 self.mesh.userVertices=[]354 self.mesh.userSegments=[]355 self.mesh.alphaSegments=[]356 self.canvas.delete(ALL)357 event = None358 print 'len(userVertices.keys())'359 print len(userVertices.keys())360 print 'len(userSegments.keys())'361 print len(userSegments.keys())362 print 'len(alphaSegments.keys())'363 print len(alphaSegments.keys())364 365 #######366 point_keys = {}367 for vert in userVertices.keys():368 assert not point_keys.has_key((vert.x,vert.y))369 point_keys[(vert.x,vert.y)]=vert370 assert len(point_keys.keys())==len(userVertices.keys())371 #######372 373 for v in userVertices.keys():374 x = v.x*self.SCALE375 y = v.y*self.SCALE376 userVertices[(v.x,v.y)]=self.drawVertex(x,y,event)377 378 for line in userSegments.keys():379 v0 = userVertices[line[0]]380 v1 = userVertices[line[1]]381 segment = self.drawSegment(v0,v1)382 segment.set_tag(userSegments[line].tag)383 384 for line in alphaSegments.keys():385 v0 = userVertices[line[0]]386 v1 = userVertices[line[1]]387 segment = self.drawSegment(v0,v1)388 segment.set_tag(alphaSegments[line].tag)389 self.visualiseMesh(self.mesh)390 391 392 def triangles_to_polySet(self,parent):393 userVertices,userSegments,alphaSegments = \394 self.mesh.triangles_to_polySet(self.selSet)395 396 self.mesh.userVertices=[]397 self.canvas.delete(ALL)398 399 event = None400 print 'len(userVertices.keys())'401 print len(userVertices.keys())402 print 'len(userSegments.keys())'403 print len(userSegments.keys())404 print 'len(alphaSegments.keys())'405 print len(alphaSegments.keys())406 407 408 #######409 point_keys = {}410 for vert in userVertices.keys():411 assert not point_keys.has_key((vert.x,vert.y))412 point_keys[(vert.x,vert.y)]=vert413 assert len(point_keys.keys())==len(userVertices.keys())414 #######415 416 for v in userVertices.keys():417 if userVertices[v] is True:418 x = v.x*self.SCALE419 y = v.y*self.SCALE420 userVertices[(v.x,v.y)]=self.drawVertex(x,y,event)421 422 for line in userSegments.keys():423 v0 = userVertices[line[0]]424 v1 = userVertices[line[1]]425 segment = self.drawSegment(v0,v1)426 segment.set_tag(userSegments[line].tag)427 428 for line in alphaSegments.keys():429 v0 = userVertices[line[0]]430 v1 = userVertices[line[1]]431 segment = self.drawSegment(v0,v1)432 segment.set_tag(alphaSegments[line].tag)433 self.visualiseMesh(self.mesh)434 #self.smooth_polySet(parent)435 436 def selectTriangles(self,setName):437 """438 """439 self.canvas.delete(ALL)440 self.selSet = setName441 self.visualiseMesh(self.mesh)442 443 def selectAllTriangles(self,parent):444 """445 selected all triangles in the mesh446 """447 self.canvas.delete(ALL)448 self.selSet = self.mesh.selectAllTriangles()449 self.visualiseMesh(self.mesh)450 451 230 def clearSelection(self,parent): 452 231 #FIXME looks like self.clearSelections - change name (Peter) … … 478 257 self.Regions = visualmesh.vRegions(mesh.Region) 479 258 self.UserMesh = visualmesh.vMesh([self.Vertices,self.Segments,self.Holes,self.Regions]) 480 481 self.Triangles = visualmesh.vTriangles(mesh.Triangle)482 self.selSet='None'483 259 484 260 … … 490 266 self.Vertices = None 491 267 self.Segments = None 492 self.Triangles = None493 494 268 495 269 def addCylinders(self): … … 500 274 501 275 """ 502 503 504 276 from anuga.coordinate_transforms.geo_reference import Geo_reference, \ 505 277 DEFAULT_ZONE … … 1423 1195 self.createZooms() 1424 1196 self.createEdits() 1425 #self.createSetTools()1426 #self.createSetIcons()1427 1197 self.createVisualiseIcons() 1428 print "FIX THIS BEFORE "1429 self.addCylinders() # !!!DSG start pmesh with a triangle1198 #print "FIX THIS BEFORE " 1199 #self.addCylinders() # !!!DSG start pmesh with a triangle 1430 1200 self.selectFunc('pointer') 1431 1201 self.currentPath = os.getcwd() … … 1747 1517 showerror('Bad mesh generation values', 1748 1518 'Values are out of range.') 1749 class GeneralThresholdDialog(Dialog): 1750 """ 1751 Dialog box for thresholding a set by entering minimum 1752 and maximum values 1753 """ 1754 def __init__(self, 1755 parent, 1756 attribute_titles, 1757 function_description): 1758 self.attribute_titles=attribute_titles 1759 self.function_description=function_description 1760 1761 Dialog.__init__(self, parent) 1762 1763 1764 def body(self, master): 1765 """ 1766 GUI description 1767 """ 1768 self.title("Threshold selected set") 1769 blurb1 = 'Threshold selected set between minimum' 1770 blurb2 = 'and maximum ' + self.function_description 1771 1772 Label(master,text=blurb1).grid(row=0, sticky=W) 1773 Label(master,text=blurb2).grid(row=1, sticky=W) 1774 1775 Label(master, text='minimum attribute:').grid(row=2, sticky=W) 1776 Label(master, text='maximum attribute:').grid(row=3, sticky=W) 1777 Label(master, text='attribute name').grid(row=4, sticky=W) 1778 1779 1780 nameVar = StringVar() 1781 nameVar.set('elevation') 1782 1783 self.minstr = Entry(master, width = 16, name ="entry") 1784 self.maxstr = Entry(master, width = 16) 1785 self.attstr = Entry(master, width = 16,textvariable = nameVar) 1786 1787 self.minstr.grid(row=2, column=1, sticky=W) 1788 self.maxstr.grid(row=3, column=1, sticky=W) 1789 self.attstr.grid(row=4, column=1, sticky=W) 1790 self.minstr.focus_force() 1791 self.min = 0 1792 self.max = 0 1793 self.attribute_name = 'elevation' 1794 self.minmaxValuesOk = False 1795 1796 def apply(self): 1797 self.minmaxValuesOk = True 1798 try: 1799 self.min = float(self.minstr.get()) 1800 self.max = float(self.maxstr.get()) 1801 except ValueError: 1802 self.minmaxValuesOk = False 1803 showerror('Bad mesh generation values', 1804 ' Values are not numbers.') 1805 try: 1806 self.attribute_titles.index(self.attstr.get())#dodgey. 1807 self.attribute_name = self.attstr.get() 1808 except ValueError: 1809 self.attribute_name = None 1810 showerror('Bad attribute name', 1811 'Using h = 1') 1812 1813 class ThresholdDialog(Dialog): 1814 """ 1815 Dialog box for thresholding a set by entering minimum 1816 and maximum values 1817 """ 1818 def __init__(self, 1819 parent, 1820 attribute_titles): 1821 self.attribute_titles=attribute_titles 1822 Dialog.__init__(self, parent) 1823 1824 1825 def body(self, master): 1826 """ 1827 GUI description 1828 """ 1829 self.title("Threshold selected set") 1830 1831 Label(master, text='minimum attribute:').grid(row=0, sticky=W) 1832 Label(master, text='maximum attribute:').grid(row=1, sticky=W) 1833 Label(master, text='attribute name').grid(row=2, sticky=W) 1834 1835 1836 nameVar = StringVar() 1837 nameVar.set('elevation') 1838 1839 self.minstr = Entry(master, width = 16, name ="entry") 1840 self.maxstr = Entry(master, width = 16) 1841 self.attstr = Entry(master, width = 16,textvariable = nameVar) 1842 1843 self.minstr.grid(row=0, column=1, sticky=W) 1844 self.maxstr.grid(row=1, column=1, sticky=W) 1845 self.attstr.grid(row=2, column=1, sticky=W) 1846 self.minstr.focus_force() 1847 self.min = 0 1848 self.max = 0 1849 self.attribute_name = 'elevation' 1850 self.minmaxValuesOk = False 1851 1852 def apply(self): 1853 self.minmaxValuesOk = True 1854 try: 1855 self.min = float(self.minstr.get()) 1856 self.max = float(self.maxstr.get()) 1857 except ValueError: 1858 self.minmaxValuesOk = False 1859 showerror('Bad mesh generation values', 1860 ' Values are not numbers.') 1861 try: 1862 self.attribute_titles.index(self.attstr.get())#dodgey. 1863 self.attribute_name = self.attstr.get() 1864 except ValueError: 1865 self.minmaxValuesOk = False 1866 showerror('Bad attribute name', 1867 ' Attribute not in mesh.') 1868 1869 1870 class Courant_ThresholdDialog(Dialog): 1871 """ 1872 Dialog box for thresholding a set by entering minimum 1873 and maximum values 1874 """ 1875 def __init__(self, 1876 parent, 1877 attribute_titles): 1878 self.attribute_titles=attribute_titles 1879 Dialog.__init__(self, parent) 1880 1881 1882 def body(self, master): 1883 """ 1884 GUI description 1885 """ 1886 self.title("Courant_Threshold selected set") 1887 1888 Label(master, text='minimum attribute:').grid(row=0, sticky=W) 1889 Label(master, text='maximum attribute:').grid(row=1, sticky=W) 1890 Label(master, text='attribute name').grid(row=2, sticky=W) 1891 1892 1893 nameVar = StringVar() 1894 nameVar.set('elevation') 1895 1896 self.minstr = Entry(master, width = 16, name ="entry") 1897 self.maxstr = Entry(master, width = 16) 1898 self.attstr = Entry(master, width = 16,textvariable = nameVar) 1899 1900 self.minstr.grid(row=0, column=1, sticky=W) 1901 self.maxstr.grid(row=1, column=1, sticky=W) 1902 self.attstr.grid(row=2, column=1, sticky=W) 1903 self.minstr.focus_force() 1904 self.min = 0 1905 self.max = 0 1906 self.attribute_name = 'elevation' 1907 self.minmaxValuesOk = False 1908 1909 def apply(self): 1910 self.minmaxValuesOk = True 1911 try: 1912 self.min = float(self.minstr.get()) 1913 self.max = float(self.maxstr.get()) 1914 except ValueError: 1915 self.minmaxValuesOk = False 1916 showerror('Bad mesh generation values', 1917 ' Values are not numbers.') 1918 try: 1919 self.attribute_titles.index(self.attstr.get())#dodgey. 1920 self.attribute_name = self.attstr.get() 1921 except ValueError: 1922 self.minmaxValuesOk = False 1923 showerror('Bad attribute name', 1924 ' Attribute not in mesh.') 1925 1926 1927 class SmoothDialog(Dialog): 1928 """ 1929 Dialog box for setting the number of triangles 1930 used to make up dilation or erosion 1931 """ 1932 def body(self, master): 1933 """ 1934 GUI description 1935 """ 1936 self.title("Enter the minimum radius to remove") 1937 1938 Label(master, text='radius:').grid(row=0, sticky=W) 1939 1940 self.min_radius = Entry(master, width = 16, name ="entry") 1941 1942 self.min_radius.grid(row=0, column=1, sticky=W) 1943 self.min_radius.focus_force() 1944 self.min = 2. 1945 self.valueOK = False 1946 1947 def apply(self): 1948 self.valueOK = True 1949 try: 1950 self.min = float(self.min_radius.get()) 1951 self.min_radius = self.min 1952 except ValueError: 1953 self.valueOK = False 1954 showerror('Bad Number', 1955 ' Value not a number') 1956 1957 class setStructureNumberDialog(Dialog): 1958 """ 1959 Dialog box for setting the number of triangles 1960 used to make up dilation or erosion 1961 """ 1962 def body(self, master): 1963 """ 1964 GUI description 1965 """ 1966 self.title("Set number of elements effected by morphing sets") 1967 1968 Label(master, text='number:').grid(row=0, sticky=W) 1969 1970 self.number = Entry(master, width = 16, name ="entry") 1971 1972 self.number.grid(row=0, column=1, sticky=W) 1973 self.number.focus_force() 1974 self.number = 0 1975 self.numberOk = False 1976 1977 def apply(self): 1978 self.numberOk = True 1979 try: 1980 self.number = int(self.number.get()) 1981 except ValueError: 1982 self.numberOK = False 1983 showerror('Bad mesh generation values', 1984 ' Values are not numbers.') 1985 1986 1987 1519 1988 1520 if __name__ == '__main__': 1989 1521 draw = Draw()
Note: See TracChangeset
for help on using the changeset viewer.