1 | |
---|
2 | SET_COLOUR = 'red' |
---|
3 | DEFAULT_ATTRIBUTE = 'elevation' |
---|
4 | |
---|
5 | |
---|
6 | |
---|
7 | def Out_createSetTools(self): |
---|
8 | """ |
---|
9 | Add set tool buttons to the top of the GUI |
---|
10 | """ |
---|
11 | ToolBarButton(self, self.toolbar, 'sep', 'sep.gif', width=10, |
---|
12 | state='disabled') |
---|
13 | for key, func, balloon in [ |
---|
14 | ('threshold', self.threshold, 'threshold the set'), |
---|
15 | ('Courant_threshold', self.Courant_threshold, 'Courant_threshold the set'), |
---|
16 | ('gradient_threshold', self.gradient_threshold, 'gradient_threshold the set'), |
---|
17 | ('smooth', self.smooth_polySet, 'smooth the polygons'), |
---|
18 | ('polyset', self.triangles_to_polySet, 'make a poly set out of selected triangles')]: |
---|
19 | #('refineSet', self.refineSet, 'Refine the set')]: |
---|
20 | ToolBarButton(self, self.toolbar, key, '%s.gif' %key, |
---|
21 | command=func, balloonhelp=balloon, |
---|
22 | statushelp='' ) |
---|
23 | |
---|
24 | |
---|
25 | |
---|
26 | def createSetIcons(self): |
---|
27 | """ |
---|
28 | Add Edit buttons to the top of the GUI |
---|
29 | """ |
---|
30 | ToolBarButton(self, self.toolbar, 'sep', 'sep.gif', width=10, |
---|
31 | state='disabled') |
---|
32 | for key, func, balloon in [ |
---|
33 | ('selectAllTriangles', self.selectAllTriangles, 'select all'), |
---|
34 | ('none', self.clearSelection, 'clear selection')]: |
---|
35 | ToolBarButton(self, self.toolbar, key, '%s.gif' %key, |
---|
36 | command=func, balloonhelp=balloon, |
---|
37 | statushelp='' ) |
---|
38 | |
---|
39 | def refineSet(self,parent): |
---|
40 | self.mesh.refineSet(self.selSet) |
---|
41 | self.visualiseMesh(self.mesh) |
---|
42 | |
---|
43 | |
---|
44 | def setStructureNumber(self,parent): |
---|
45 | dialog = setStructureNumberDialog(self.canvas) |
---|
46 | if dialog.numberOK: |
---|
47 | self.structureSize = dialog.number |
---|
48 | |
---|
49 | def erode(self, parent): |
---|
50 | #Not implimented |
---|
51 | self.canvas.delete(ALL) |
---|
52 | self.mesh.erode(self.selSet,structureSize=self.structureSize) |
---|
53 | self.visualiseMesh(self.mesh) |
---|
54 | |
---|
55 | |
---|
56 | def dilate(self, parent): |
---|
57 | #Not implimented |
---|
58 | self.canvas.delete(ALL) |
---|
59 | self.mesh.dilate(self.selSet,structureSize=self.structureSize) |
---|
60 | self.visualiseMesh(self.mesh) |
---|
61 | |
---|
62 | def general_threshold(self,parent,function,function_description): |
---|
63 | """ |
---|
64 | add a vertex using a window and entering x y values. |
---|
65 | |
---|
66 | the parent attribute isn't used by this function. |
---|
67 | need to userstand toolbarbutton.py to know how to |
---|
68 | get rid of it. |
---|
69 | """ |
---|
70 | if self.selSet == 'None': |
---|
71 | self.selectAllTriangles(parent) |
---|
72 | |
---|
73 | dialog = GeneralThresholdDialog(self.canvas,self.mesh.attributeTitles,function_description) |
---|
74 | if dialog.minmaxValuesOk: |
---|
75 | self.canvas.delete(ALL) |
---|
76 | min = dialog.min |
---|
77 | max = dialog.max |
---|
78 | attribute_name = dialog.attribute_name |
---|
79 | self.mesh.general_threshold(self.selSet,min=min,max=max,attribute_name = attribute_name,function=function) |
---|
80 | self.visualiseMesh(self.mesh) |
---|
81 | |
---|
82 | def threshold(self, parent): |
---|
83 | """ |
---|
84 | add a vertex using a window and entering x y values. |
---|
85 | |
---|
86 | the parent attribute isn't used by this function. |
---|
87 | need to userstand toolbarbutton.py to know how to |
---|
88 | get rid of it. |
---|
89 | """ |
---|
90 | function = self.mesh.av_att |
---|
91 | function_description = 'average attribute of triangle' |
---|
92 | self.general_threshold(parent,function,function_description) |
---|
93 | |
---|
94 | |
---|
95 | def Courant_threshold(self, parent): |
---|
96 | """ |
---|
97 | add a vertex using a window and entering x y values. |
---|
98 | |
---|
99 | the parent attribute isn't used by this function. |
---|
100 | need to userstand toolbarbutton.py to know how to |
---|
101 | get rid of it. |
---|
102 | """ |
---|
103 | function = self.mesh.Courant_ratio |
---|
104 | function_description = 'average attribute/area of triangle' |
---|
105 | self.general_threshold(parent,function,function_description) |
---|
106 | |
---|
107 | def gradient_threshold(self, parent): |
---|
108 | """ |
---|
109 | add a vertex using a window and entering x y values. |
---|
110 | |
---|
111 | the parent attribute isn't used by this function. |
---|
112 | need to userstand toolbarbutton.py to know how to |
---|
113 | get rid of it. |
---|
114 | """ |
---|
115 | function = self.mesh.Gradient |
---|
116 | function_description = 'average gradient of triangle' |
---|
117 | self.general_threshold(parent,function,function_description) |
---|
118 | |
---|
119 | def smooth_polySet(self,parent): |
---|
120 | dialog = SmoothDialog(self.canvas) |
---|
121 | if dialog.valueOK: |
---|
122 | min_radius = dialog.min_radius |
---|
123 | self._smooth_polySet(min_radius) |
---|
124 | |
---|
125 | def _smooth_polySet(self,min_radius): |
---|
126 | userVertices,userSegments,alphaSegments = \ |
---|
127 | self.mesh.smooth_polySet(min_radius=min_radius) |
---|
128 | |
---|
129 | self.mesh.userVertices=[] |
---|
130 | self.mesh.userSegments=[] |
---|
131 | self.mesh.alphaSegments=[] |
---|
132 | self.canvas.delete(ALL) |
---|
133 | event = None |
---|
134 | print 'len(userVertices.keys())' |
---|
135 | print len(userVertices.keys()) |
---|
136 | print 'len(userSegments.keys())' |
---|
137 | print len(userSegments.keys()) |
---|
138 | print 'len(alphaSegments.keys())' |
---|
139 | print len(alphaSegments.keys()) |
---|
140 | |
---|
141 | ####### |
---|
142 | point_keys = {} |
---|
143 | for vert in userVertices.keys(): |
---|
144 | assert not point_keys.has_key((vert.x,vert.y)) |
---|
145 | point_keys[(vert.x,vert.y)]=vert |
---|
146 | assert len(point_keys.keys())==len(userVertices.keys()) |
---|
147 | ####### |
---|
148 | |
---|
149 | for v in userVertices.keys(): |
---|
150 | x = v.x*self.SCALE |
---|
151 | y = v.y*self.SCALE |
---|
152 | userVertices[(v.x,v.y)]=self.drawVertex(x,y,event) |
---|
153 | |
---|
154 | for line in userSegments.keys(): |
---|
155 | v0 = userVertices[line[0]] |
---|
156 | v1 = userVertices[line[1]] |
---|
157 | segment = self.drawSegment(v0,v1) |
---|
158 | segment.set_tag(userSegments[line].tag) |
---|
159 | |
---|
160 | for line in alphaSegments.keys(): |
---|
161 | v0 = userVertices[line[0]] |
---|
162 | v1 = userVertices[line[1]] |
---|
163 | segment = self.drawSegment(v0,v1) |
---|
164 | segment.set_tag(alphaSegments[line].tag) |
---|
165 | self.visualiseMesh(self.mesh) |
---|
166 | |
---|
167 | |
---|
168 | def triangles_to_polySet(self,parent): |
---|
169 | userVertices,userSegments,alphaSegments = \ |
---|
170 | self.mesh.triangles_to_polySet(self.selSet) |
---|
171 | |
---|
172 | self.mesh.userVertices=[] |
---|
173 | self.canvas.delete(ALL) |
---|
174 | |
---|
175 | event = None |
---|
176 | print 'len(userVertices.keys())' |
---|
177 | print len(userVertices.keys()) |
---|
178 | print 'len(userSegments.keys())' |
---|
179 | print len(userSegments.keys()) |
---|
180 | print 'len(alphaSegments.keys())' |
---|
181 | print len(alphaSegments.keys()) |
---|
182 | |
---|
183 | |
---|
184 | ####### |
---|
185 | point_keys = {} |
---|
186 | for vert in userVertices.keys(): |
---|
187 | assert not point_keys.has_key((vert.x,vert.y)) |
---|
188 | point_keys[(vert.x,vert.y)]=vert |
---|
189 | assert len(point_keys.keys())==len(userVertices.keys()) |
---|
190 | ####### |
---|
191 | |
---|
192 | for v in userVertices.keys(): |
---|
193 | if userVertices[v] is True: |
---|
194 | x = v.x*self.SCALE |
---|
195 | y = v.y*self.SCALE |
---|
196 | userVertices[(v.x,v.y)]=self.drawVertex(x,y,event) |
---|
197 | |
---|
198 | for line in userSegments.keys(): |
---|
199 | v0 = userVertices[line[0]] |
---|
200 | v1 = userVertices[line[1]] |
---|
201 | segment = self.drawSegment(v0,v1) |
---|
202 | segment.set_tag(userSegments[line].tag) |
---|
203 | |
---|
204 | for line in alphaSegments.keys(): |
---|
205 | v0 = userVertices[line[0]] |
---|
206 | v1 = userVertices[line[1]] |
---|
207 | segment = self.drawSegment(v0,v1) |
---|
208 | segment.set_tag(alphaSegments[line].tag) |
---|
209 | self.visualiseMesh(self.mesh) |
---|
210 | #self.smooth_polySet(parent) |
---|
211 | |
---|
212 | def selectTriangles(self,setName): |
---|
213 | """ |
---|
214 | """ |
---|
215 | self.canvas.delete(ALL) |
---|
216 | self.selSet = setName |
---|
217 | self.visualiseMesh(self.mesh) |
---|
218 | |
---|
219 | def selectAllTriangles(self,parent): |
---|
220 | """ |
---|
221 | selected all triangles in the mesh |
---|
222 | """ |
---|
223 | self.canvas.delete(ALL) |
---|
224 | self.selSet = self.mesh.selectAllTriangles() |
---|
225 | self.visualiseMesh(self.mesh) |
---|
226 | |
---|
227 | class GeneralThresholdDialog(Dialog): |
---|
228 | """ |
---|
229 | Dialog box for thresholding a set by entering minimum |
---|
230 | and maximum values |
---|
231 | """ |
---|
232 | def __init__(self, |
---|
233 | parent, |
---|
234 | attribute_titles, |
---|
235 | function_description): |
---|
236 | self.attribute_titles=attribute_titles |
---|
237 | self.function_description=function_description |
---|
238 | |
---|
239 | Dialog.__init__(self, parent) |
---|
240 | |
---|
241 | |
---|
242 | def body(self, master): |
---|
243 | """ |
---|
244 | GUI description |
---|
245 | """ |
---|
246 | self.title("Threshold selected set") |
---|
247 | blurb1 = 'Threshold selected set between minimum' |
---|
248 | blurb2 = 'and maximum ' + self.function_description |
---|
249 | |
---|
250 | Label(master,text=blurb1).grid(row=0, sticky=W) |
---|
251 | Label(master,text=blurb2).grid(row=1, sticky=W) |
---|
252 | |
---|
253 | Label(master, text='minimum attribute:').grid(row=2, sticky=W) |
---|
254 | Label(master, text='maximum attribute:').grid(row=3, sticky=W) |
---|
255 | Label(master, text='attribute name').grid(row=4, sticky=W) |
---|
256 | |
---|
257 | |
---|
258 | nameVar = StringVar() |
---|
259 | nameVar.set('elevation') |
---|
260 | |
---|
261 | self.minstr = Entry(master, width = 16, name ="entry") |
---|
262 | self.maxstr = Entry(master, width = 16) |
---|
263 | self.attstr = Entry(master, width = 16,textvariable = nameVar) |
---|
264 | |
---|
265 | self.minstr.grid(row=2, column=1, sticky=W) |
---|
266 | self.maxstr.grid(row=3, column=1, sticky=W) |
---|
267 | self.attstr.grid(row=4, column=1, sticky=W) |
---|
268 | self.minstr.focus_force() |
---|
269 | self.min = 0 |
---|
270 | self.max = 0 |
---|
271 | self.attribute_name = 'elevation' |
---|
272 | self.minmaxValuesOk = False |
---|
273 | |
---|
274 | def apply(self): |
---|
275 | self.minmaxValuesOk = True |
---|
276 | try: |
---|
277 | self.min = float(self.minstr.get()) |
---|
278 | self.max = float(self.maxstr.get()) |
---|
279 | except ValueError: |
---|
280 | self.minmaxValuesOk = False |
---|
281 | showerror('Bad mesh generation values', |
---|
282 | ' Values are not numbers.') |
---|
283 | try: |
---|
284 | self.attribute_titles.index(self.attstr.get())#dodgey. |
---|
285 | self.attribute_name = self.attstr.get() |
---|
286 | except ValueError: |
---|
287 | self.attribute_name = None |
---|
288 | showerror('Bad attribute name', |
---|
289 | 'Using h = 1') |
---|
290 | |
---|
291 | class ThresholdDialog(Dialog): |
---|
292 | """ |
---|
293 | Dialog box for thresholding a set by entering minimum |
---|
294 | and maximum values |
---|
295 | """ |
---|
296 | def __init__(self, |
---|
297 | parent, |
---|
298 | attribute_titles): |
---|
299 | self.attribute_titles=attribute_titles |
---|
300 | Dialog.__init__(self, parent) |
---|
301 | |
---|
302 | |
---|
303 | def body(self, master): |
---|
304 | """ |
---|
305 | GUI description |
---|
306 | """ |
---|
307 | self.title("Threshold selected set") |
---|
308 | |
---|
309 | Label(master, text='minimum attribute:').grid(row=0, sticky=W) |
---|
310 | Label(master, text='maximum attribute:').grid(row=1, sticky=W) |
---|
311 | Label(master, text='attribute name').grid(row=2, sticky=W) |
---|
312 | |
---|
313 | |
---|
314 | nameVar = StringVar() |
---|
315 | nameVar.set('elevation') |
---|
316 | |
---|
317 | self.minstr = Entry(master, width = 16, name ="entry") |
---|
318 | self.maxstr = Entry(master, width = 16) |
---|
319 | self.attstr = Entry(master, width = 16,textvariable = nameVar) |
---|
320 | |
---|
321 | self.minstr.grid(row=0, column=1, sticky=W) |
---|
322 | self.maxstr.grid(row=1, column=1, sticky=W) |
---|
323 | self.attstr.grid(row=2, column=1, sticky=W) |
---|
324 | self.minstr.focus_force() |
---|
325 | self.min = 0 |
---|
326 | self.max = 0 |
---|
327 | self.attribute_name = 'elevation' |
---|
328 | self.minmaxValuesOk = False |
---|
329 | |
---|
330 | def apply(self): |
---|
331 | self.minmaxValuesOk = True |
---|
332 | try: |
---|
333 | self.min = float(self.minstr.get()) |
---|
334 | self.max = float(self.maxstr.get()) |
---|
335 | except ValueError: |
---|
336 | self.minmaxValuesOk = False |
---|
337 | showerror('Bad mesh generation values', |
---|
338 | ' Values are not numbers.') |
---|
339 | try: |
---|
340 | self.attribute_titles.index(self.attstr.get())#dodgey. |
---|
341 | self.attribute_name = self.attstr.get() |
---|
342 | except ValueError: |
---|
343 | self.minmaxValuesOk = False |
---|
344 | showerror('Bad attribute name', |
---|
345 | ' Attribute not in mesh.') |
---|
346 | |
---|
347 | |
---|
348 | class Courant_ThresholdDialog(Dialog): |
---|
349 | """ |
---|
350 | Dialog box for thresholding a set by entering minimum |
---|
351 | and maximum values |
---|
352 | """ |
---|
353 | def __init__(self, |
---|
354 | parent, |
---|
355 | attribute_titles): |
---|
356 | self.attribute_titles=attribute_titles |
---|
357 | Dialog.__init__(self, parent) |
---|
358 | |
---|
359 | |
---|
360 | def body(self, master): |
---|
361 | """ |
---|
362 | GUI description |
---|
363 | """ |
---|
364 | self.title("Courant_Threshold selected set") |
---|
365 | |
---|
366 | Label(master, text='minimum attribute:').grid(row=0, sticky=W) |
---|
367 | Label(master, text='maximum attribute:').grid(row=1, sticky=W) |
---|
368 | Label(master, text='attribute name').grid(row=2, sticky=W) |
---|
369 | |
---|
370 | |
---|
371 | nameVar = StringVar() |
---|
372 | nameVar.set('elevation') |
---|
373 | |
---|
374 | self.minstr = Entry(master, width = 16, name ="entry") |
---|
375 | self.maxstr = Entry(master, width = 16) |
---|
376 | self.attstr = Entry(master, width = 16,textvariable = nameVar) |
---|
377 | |
---|
378 | self.minstr.grid(row=0, column=1, sticky=W) |
---|
379 | self.maxstr.grid(row=1, column=1, sticky=W) |
---|
380 | self.attstr.grid(row=2, column=1, sticky=W) |
---|
381 | self.minstr.focus_force() |
---|
382 | self.min = 0 |
---|
383 | self.max = 0 |
---|
384 | self.attribute_name = 'elevation' |
---|
385 | self.minmaxValuesOk = False |
---|
386 | |
---|
387 | def apply(self): |
---|
388 | self.minmaxValuesOk = True |
---|
389 | try: |
---|
390 | self.min = float(self.minstr.get()) |
---|
391 | self.max = float(self.maxstr.get()) |
---|
392 | except ValueError: |
---|
393 | self.minmaxValuesOk = False |
---|
394 | showerror('Bad mesh generation values', |
---|
395 | ' Values are not numbers.') |
---|
396 | try: |
---|
397 | self.attribute_titles.index(self.attstr.get())#dodgey. |
---|
398 | self.attribute_name = self.attstr.get() |
---|
399 | except ValueError: |
---|
400 | self.minmaxValuesOk = False |
---|
401 | showerror('Bad attribute name', |
---|
402 | ' Attribute not in mesh.') |
---|
403 | |
---|
404 | |
---|
405 | class SmoothDialog(Dialog): |
---|
406 | """ |
---|
407 | Dialog box for setting the number of triangles |
---|
408 | used to make up dilation or erosion |
---|
409 | """ |
---|
410 | def body(self, master): |
---|
411 | """ |
---|
412 | GUI description |
---|
413 | """ |
---|
414 | self.title("Enter the minimum radius to remove") |
---|
415 | |
---|
416 | Label(master, text='radius:').grid(row=0, sticky=W) |
---|
417 | |
---|
418 | self.min_radius = Entry(master, width = 16, name ="entry") |
---|
419 | |
---|
420 | self.min_radius.grid(row=0, column=1, sticky=W) |
---|
421 | self.min_radius.focus_force() |
---|
422 | self.min = 2. |
---|
423 | self.valueOK = False |
---|
424 | |
---|
425 | def apply(self): |
---|
426 | self.valueOK = True |
---|
427 | try: |
---|
428 | self.min = float(self.min_radius.get()) |
---|
429 | self.min_radius = self.min |
---|
430 | except ValueError: |
---|
431 | self.valueOK = False |
---|
432 | showerror('Bad Number', |
---|
433 | ' Value not a number') |
---|
434 | |
---|
435 | class setStructureNumberDialog(Dialog): |
---|
436 | """ |
---|
437 | Dialog box for setting the number of triangles |
---|
438 | used to make up dilation or erosion |
---|
439 | """ |
---|
440 | def body(self, master): |
---|
441 | """ |
---|
442 | GUI description |
---|
443 | """ |
---|
444 | self.title("Set number of elements effected by morphing sets") |
---|
445 | |
---|
446 | Label(master, text='number:').grid(row=0, sticky=W) |
---|
447 | |
---|
448 | self.number = Entry(master, width = 16, name ="entry") |
---|
449 | |
---|
450 | self.number.grid(row=0, column=1, sticky=W) |
---|
451 | self.number.focus_force() |
---|
452 | self.number = 0 |
---|
453 | self.numberOk = False |
---|
454 | |
---|
455 | def apply(self): |
---|
456 | self.numberOk = True |
---|
457 | try: |
---|
458 | self.number = int(self.number.get()) |
---|
459 | except ValueError: |
---|
460 | self.numberOK = False |
---|
461 | showerror('Bad mesh generation values', |
---|
462 | ' Values are not numbers.') |
---|
463 | |
---|
464 | |
---|
465 | |
---|