blob: 0af3ec8518733829ff2371b8912d7a23c62b0fc5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
|
# Copyright (C) 1999-2017
# Smithsonian Astrophysical Observatory, Cambridge, MA, USA
# For conditions of distribution and use, see copyright notice in "copyright"
package provide DS9 1.0
proc SmoothDef {} {
global smooth
global ismooth
global psmooth
set ismooth(top) .sm
set ismooth(mb) .smmb
set smooth(lock) 0
set smooth(view) 0
set smooth(function) gaussian
set smooth(kernel) 3
set smooth(radius) 3
array set psmooth [array get smooth]
}
proc SmoothUpdate {} {
global smooth
global current
global rgb
if {$current(frame) != {}} {
SetWatchCursor
if {$smooth(view)} {
RGBEvalLockCurrent rgb(lock,smooth) [list $current(frame) smooth $smooth(function) $smooth(kernel) $smooth(radius)]
} else {
RGBEvalLockCurrent rgb(lock,smooth) [list $current(frame) smooth delete]
}
ResetWatchCursor
}
LockSmoothCurrent
UpdateCubeDialog
UpdateContourScale
UpdateContourDialog
UpdateScaleDialog
UpdateGraphAxis $current(frame)
UpdateMain
}
proc SmoothDialog {} {
global ds9
global smooth
global ismooth
# see if we already have a window visible
if {[winfo exists $ismooth(top)]} {
raise $ismooth(top)
return
}
# create the window
set w $ismooth(top)
set mb $ismooth(mb)
Toplevel $w $mb 6 [msgcat::mc {Smooth Parameters}] SmoothDestroyDialog
$mb add cascade -label [msgcat::mc {File}] -menu $mb.file
$mb add cascade -label [msgcat::mc {Edit}] -menu $mb.edit
menu $mb.file
$mb.file add command -label [msgcat::mc {Apply}] -command SmoothApplyDialog
$mb.file add command -label [msgcat::mc {Clear}] -command SmoothOffDialog
$mb.file add separator
$mb.file add command -label [msgcat::mc {Close}] \
-command SmoothDestroyDialog
EditMenu $mb ismooth
# Function
set f [ttk::labelframe $w.func -text [msgcat::mc {Function}] -padding 2]
ttk::radiobutton $f.boxcar -text [msgcat::mc {Boxcar}] \
-variable smooth(function) -value boxcar
ttk::radiobutton $f.tophat -text [msgcat::mc {Tophat}] \
-variable smooth(function) -value tophat
ttk::radiobutton $f.gaussian -text [msgcat::mc {Gaussian}] \
-variable smooth(function) -value gaussian
ttk::label $f.rbtitle -text {Boxcar width = 2*radius+1}
ttk::label $f.rttitle -text {Tophat diameter = 2*radius+1}
ttk::label $f.rgtitle -text {Gaussian sigma = radius/2}
slider $f.rslider 1 20 {Radius} smooth(radius) {SmoothCheckRadius}
grid $f.boxcar $f.tophat $f.gaussian -padx 2 -pady 2 -sticky w
grid $f.rbtitle - - -padx 2 -pady 2 -sticky ew
grid $f.rttitle - - -padx 2 -pady 2 -sticky ew
grid $f.rgtitle - - -padx 2 -pady 2 -sticky ew
grid $f.rslider - - -padx 2 -pady 2 -sticky ew
# Kernal
set f [ttk::labelframe $w.rad -text [msgcat::mc {Kernel}] -padding 2]
ttk::label $f.ktitle -text {Width/Height = 2*size+1; radius <= size}
slider $f.kslider 1 20 {Size} smooth(kernel) {SmoothCheckKernel}
grid $f.ktitle -padx 2 -pady 2 -sticky ew
grid $f.kslider -padx 2 -pady 2 -sticky ew
# Buttons
set f [ttk::frame $w.buttons]
ttk::button $f.apply -text [msgcat::mc {Apply}] -command SmoothApplyDialog
ttk::button $f.clear -text [msgcat::mc {Clear}] -command SmoothOffDialog
ttk::button $f.close -text [msgcat::mc {Close}] -command SmoothDestroyDialog
pack $f.apply $f.clear $f.close -side left -expand true -padx 2 -pady 4
# Fini
grid $w.func -sticky news
grid $w.rad -sticky news
grid $w.buttons -sticky ew
grid rowconfigure $w 0 -weight 1
grid rowconfigure $w 1 -weight 1
grid columnconfigure $w 0 -weight 1
}
proc SmoothCheckRadius {} {
global smooth
if {$smooth(radius) > $smooth(kernel)} {
set smooth(kernel) $smooth(radius)
}
}
proc SmoothCheckKernel {} {
global smooth
if {$smooth(kernel) < $smooth(radius)} {
set smooth(radius) $smooth(kernel)
}
}
proc SmoothApplyDialog {} {
global smooth
set smooth(view) 1
SmoothUpdate
}
proc SmoothDestroyDialog {} {
global ismooth
if {[winfo exists $ismooth(top)]} {
destroy $ismooth(top)
destroy $ismooth(mb)
}
}
proc SmoothOffDialog {} {
global smooth
set smooth(view) 0
SmoothUpdate
}
proc UpdateSmoothMenu {} {
global smooth
global current
global debug
if {$debug(tcl,update)} {
puts stderr "UpdateSmoothMenu"
}
if {$current(frame) != {}} {
set smooth(view) [$current(frame) has smooth]
set smooth(function) [$current(frame) get smooth function]
set smooth(radius) [$current(frame) get smooth radius]
set smooth(kernel) [$current(frame) get smooth kernel]
}
}
proc MatchSmoothCurrent {} {
global current
if {$current(frame) != {}} {
MatchSmooth $current(frame)
}
}
proc MatchSmooth {which} {
global ds9
global rgb
set view [$which has smooth]
set function [$which get smooth function]
set radius [$which get smooth radius]
foreach ff $ds9(frames) {
if {$ff != $which} {
if {$view} {
RGBEvalLock rgb(lock,smooth) $ff [list $ff smooth $function $radius]
} else {
RGBEvalLock rgb(lock,smooth) $ff [list $ff smooth delete]
}
}
}
}
proc LockSmoothCurrent {} {
global current
if {$current(frame) != {}} {
LockSmooth $current(frame)
}
}
proc LockSmooth {which} {
global smooth
if {$smooth(lock)} {
MatchSmooth $which
}
}
proc SmoothBackup {ch which} {
switch [$which get type] {
base -
3d {SmoothBackupBase $ch $which}
rgb {SmoothBackupRGB $ch $which}
}
}
proc SmoothBackupBase {ch which} {
if {[$which has smooth]} {
set function [$which get smooth function]
set radius [$which get smooth radius]
puts $ch "$which smooth $function $radius"
}
}
proc SmoothBackupRGB {ch which} {
set sav [$which get rgb channel]
foreach cc {red green blue} {
$which rgb channel $cc
puts $ch "$which rgb channel $cc"
SmoothBackupBase $ch $which
}
$which rgb channel $sav
puts $ch "$which rgb channel $sav"
}
proc PrefsDialogSmooth {} {
global dprefs
set w $dprefs(tab)
$dprefs(list) insert end [msgcat::mc {Smooth}]
lappend dprefs(tabs) [ttk::frame $w.smooth]
set f [ttk::labelframe $w.smooth.param -text [msgcat::mc {Smooth}]]
ttk::label $f.title -text [msgcat::mc {Function}]
ttk::menubutton $f.function -textvariable psmooth(function) \
-menu $f.function.menu
menu $f.function.menu
$f.function.menu add radiobutton -label [msgcat::mc {Boxcar}] \
-variable psmooth(function) -value boxcar
$f.function.menu add radiobutton -label [msgcat::mc {Tophat}] \
-variable psmooth(function) -value tophat
$f.function.menu add radiobutton -label [msgcat::mc {Gaussian}] \
-variable psmooth(function) -value gaussian
grid $f.title $f.function -padx 2 -pady 2 -sticky w
pack $f -side top -fill both -expand true
}
proc ProcessSmoothCmd {varname iname} {
upvar $varname var
upvar $iname i
global smooth
switch -- [string tolower [lindex $var $i]] {
open {SmoothDialog}
close {SmoothDestroyDialog}
match {MatchSmoothCurrent}
lock {
incr i
if {!([string range [lindex $var $i] 0 0] == "-")} {
set smooth(lock) [FromYesNo [lindex $var $i]]
} else {
set smooth(lock) 1
incr i -1
}
LockSmoothCurrent
}
radius {
incr i
set smooth(radius) [lindex $var $i]
SmoothUpdate
}
kernel {
incr i
set smooth(kernel) [lindex $var $i]
SmoothUpdate
}
function {
incr i
set smooth(function) [lindex $var $i]
SmoothUpdate
}
yes -
true -
on -
1 -
no -
false -
off -
0 {
set smooth(view) [FromYesNo [lindex $var $i]]
SmoothUpdate
}
default {
set smooth(view) 1
SmoothUpdate
incr i -1
}
}
}
proc ProcessSendSmoothCmd {proc id param} {
global smooth
switch -- [lindex $param 0] {
lock {$proc $id [ToYesNo $smooth(lock)]}
function {$proc $id "$smooth(function)\n"}
radius {$proc $id "$smooth(radius)\n"}
kernel {$proc $id "$smooth(kernel)\n"}
default {$proc $id [ToYesNo $smooth(view)]}
}
}
|