1 | #!/bin/sh |
---|
2 | # -*- mode: Tcl -*- |
---|
3 | # ---------------------------------------------------------------------- |
---|
4 | # TEST PROGRAM for VtkVolumeViewer |
---|
5 | # |
---|
6 | # This program is a test harness for the VtkVis visualization |
---|
7 | # engine. It allows you to monitor the commands being sent back |
---|
8 | # and forth between a standard Rappture application and the VtkVis |
---|
9 | # server. You can also send your own commands to the server, to |
---|
10 | # debug new features. |
---|
11 | # |
---|
12 | # ====================================================================== |
---|
13 | # AUTHOR: Michael McLennan, Purdue University |
---|
14 | # Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
15 | # |
---|
16 | # See the file "license.terms" for information on usage and |
---|
17 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
18 | # ====================================================================== |
---|
19 | #\ |
---|
20 | bindir=`dirname $0` ; \ |
---|
21 | . $bindir/rappture.env ; \ |
---|
22 | exec $bindir/wish "$0" "$@" |
---|
23 | # ---------------------------------------------------------------------- |
---|
24 | # wish executes everything from here on... |
---|
25 | package require Itcl |
---|
26 | package require Rappture |
---|
27 | package require RapptureGUI |
---|
28 | |
---|
29 | option add *comm.font -*-courier-medium-r-normal-*-*-120-* |
---|
30 | option add *Menu.tearOff off |
---|
31 | |
---|
32 | option add *Tooltip.background white |
---|
33 | option add *Editor.background white |
---|
34 | option add *Gauge.textBackground white |
---|
35 | option add *TemperatureGauge.textBackground white |
---|
36 | option add *Switch.textBackground white |
---|
37 | option add *Progress.barColor #ffffcc |
---|
38 | option add *Balloon.titleBackground #6666cc |
---|
39 | option add *Balloon.titleForeground white |
---|
40 | option add *Balloon*Label.font -*-helvetica-medium-r-normal-*-*-120-* |
---|
41 | option add *Balloon*Radiobutton.font -*-helvetica-medium-r-normal-*-*-120-* |
---|
42 | option add *Balloon*Checkbutton.font -*-helvetica-medium-r-normal-*-*-120-* |
---|
43 | option add *ResultSet.controlbarBackground #6666cc |
---|
44 | option add *ResultSet.controlbarForeground white |
---|
45 | option add *ResultSet.activeControlBackground #ccccff |
---|
46 | option add *ResultSet.activeControlForeground black |
---|
47 | option add *Radiodial.length 3i |
---|
48 | option add *BugReport*banner*foreground white |
---|
49 | option add *BugReport*banner*background #a9a9a9 |
---|
50 | option add *BugReport*banner*highlightBackground #a9a9a9 |
---|
51 | option add *BugReport*banner*font -*-helvetica-bold-r-normal-*-*-180-* |
---|
52 | |
---|
53 | # fix the "grab" command to support a stack of grab windows |
---|
54 | #Rappture::grab::init |
---|
55 | |
---|
56 | # ---------------------------------------------------------------------- |
---|
57 | # LOAD RESOURCE SETTINGS |
---|
58 | # |
---|
59 | # Try to load the $SESSIONDIR/resources file, which contains |
---|
60 | # middleware settings, such as the application name and the |
---|
61 | # filexfer settings. |
---|
62 | # ---------------------------------------------------------------------- |
---|
63 | Rappture::resources::load |
---|
64 | |
---|
65 | # ---------------------------------------------------------------------- |
---|
66 | # Fake data object for sending VTK data file... |
---|
67 | # ---------------------------------------------------------------------- |
---|
68 | itcl::class visData { |
---|
69 | inherit Rappture::Field |
---|
70 | |
---|
71 | constructor {args} { |
---|
72 | Rappture::Field::constructor [Rappture::library standard] "" |
---|
73 | } { |
---|
74 | set _data [lindex $args 0] |
---|
75 | GetTypeAndSize $_cname |
---|
76 | GetAssociation $_cname |
---|
77 | ReadVtkDataSet $_cname $_data |
---|
78 | set _type [lindex $args 1] |
---|
79 | } |
---|
80 | |
---|
81 | public method components {args} { |
---|
82 | Rappture::getopts args params { |
---|
83 | flag what -name default |
---|
84 | flag what -dimensions |
---|
85 | flag what -style |
---|
86 | flag what -particles |
---|
87 | flag what -flow |
---|
88 | flag what -box |
---|
89 | } |
---|
90 | if { $params(what) == "-dimensions" } { |
---|
91 | return "${_dim}D" |
---|
92 | } |
---|
93 | if {[llength $args] == 0} { |
---|
94 | return "one" |
---|
95 | } |
---|
96 | return "" |
---|
97 | } |
---|
98 | public method isvalid {} { |
---|
99 | return 1 |
---|
100 | } |
---|
101 | public method data {args} { |
---|
102 | return $_data |
---|
103 | } |
---|
104 | public method vtkdata {args} { |
---|
105 | return $_data |
---|
106 | } |
---|
107 | public method values {args} { |
---|
108 | return $_data |
---|
109 | } |
---|
110 | public method style {args} { |
---|
111 | return "" |
---|
112 | } |
---|
113 | public method hints {args} { |
---|
114 | return "" |
---|
115 | } |
---|
116 | public method type {args} { |
---|
117 | return $_type |
---|
118 | } |
---|
119 | public method viewer {args} { |
---|
120 | return "vtkvolume" |
---|
121 | } |
---|
122 | |
---|
123 | private variable _cname "one" |
---|
124 | private variable _data "" |
---|
125 | private variable _type "" |
---|
126 | } |
---|
127 | |
---|
128 | # ---------------------------------------------------------------------- |
---|
129 | # USAGE: send_file |
---|
130 | # |
---|
131 | # Prompts the user for a text file, and then sends the text within |
---|
132 | # that file along to the rendering widget. |
---|
133 | # ---------------------------------------------------------------------- |
---|
134 | proc send_file {} { |
---|
135 | global widgets |
---|
136 | |
---|
137 | set file [tk_getOpenFile -title "Open VTK File"] |
---|
138 | if {"" != $file && [catch { |
---|
139 | set fid [open $file r] |
---|
140 | fconfigure $fid -translation binary -encoding binary |
---|
141 | set info [read $fid] |
---|
142 | close $fid |
---|
143 | }] == 0} { |
---|
144 | set obj [visData #auto $info "vtkvolume"] |
---|
145 | $widgets(vtkvolumeviewer) add $obj |
---|
146 | $widgets(vtkvolumeviewer) scale $obj |
---|
147 | } |
---|
148 | } |
---|
149 | |
---|
150 | # ---------------------------------------------------------------------- |
---|
151 | # USAGE: load_script |
---|
152 | # |
---|
153 | # Prompts the user for a text file, and then sends the text within |
---|
154 | # that file along to the rendering widget. |
---|
155 | # ---------------------------------------------------------------------- |
---|
156 | proc load_script {} { |
---|
157 | global widgets |
---|
158 | |
---|
159 | set file [tk_getOpenFile -title "Open Command File"] |
---|
160 | if {"" != $file && [catch { |
---|
161 | set fid [open $file r] |
---|
162 | fconfigure $fid -translation binary |
---|
163 | set info [read $fid] |
---|
164 | close $fid |
---|
165 | }] == 0} { |
---|
166 | |
---|
167 | $widgets(command) insert 0 $info |
---|
168 | send_command |
---|
169 | } |
---|
170 | } |
---|
171 | |
---|
172 | # ---------------------------------------------------------------------- |
---|
173 | # USAGE: send_command |
---|
174 | # |
---|
175 | # Invoked automatically whenever the user enters a command and |
---|
176 | # presses <Return>. Sends the command along to the rendering |
---|
177 | # widget. |
---|
178 | # ---------------------------------------------------------------------- |
---|
179 | proc send_command {} { |
---|
180 | global widgets |
---|
181 | global last_command |
---|
182 | |
---|
183 | set cmd [$widgets(command) get] |
---|
184 | |
---|
185 | if {[string length $cmd] > 0} { |
---|
186 | set last_command $cmd |
---|
187 | } else { |
---|
188 | set cmd $last_command |
---|
189 | } |
---|
190 | namespace eval Rappture::VtkVolumeViewer [list $widgets(vtkvolumeviewer) SendCmd $cmd] |
---|
191 | $widgets(command) delete 0 end |
---|
192 | } |
---|
193 | |
---|
194 | # ---------------------------------------------------------------------- |
---|
195 | # USAGE: reset |
---|
196 | # |
---|
197 | # Used internally to reset the connection to the rendering server. |
---|
198 | # Discards all data and resets the widget connection to the server. |
---|
199 | # ---------------------------------------------------------------------- |
---|
200 | proc reset {} { |
---|
201 | global widgets |
---|
202 | $widgets(vtkvolumeviewer) delete |
---|
203 | $widgets(vtkvolumeviewer) disconnect |
---|
204 | $widgets(comm) configure -state normal |
---|
205 | $widgets(comm) delete 1.0 end |
---|
206 | $widgets(comm) configure -state disabled |
---|
207 | } |
---|
208 | |
---|
209 | # ---------------------------------------------------------------------- |
---|
210 | # USAGE: show_comm <channel> <data> |
---|
211 | # |
---|
212 | # Invoked automatically whenever there is communication between |
---|
213 | # the rendering widget and the server. Eavesdrops on the communication |
---|
214 | # and posts the commands in a text viewer. |
---|
215 | # ---------------------------------------------------------------------- |
---|
216 | proc show_comm {channel {data ""}} { |
---|
217 | global widgets |
---|
218 | |
---|
219 | $widgets(comm) configure -state normal |
---|
220 | switch -- $channel { |
---|
221 | closed { |
---|
222 | $widgets(comm) insert end "--CLOSED--\n" error |
---|
223 | } |
---|
224 | <<line { |
---|
225 | $widgets(comm) insert end $data incoming "\n" incoming |
---|
226 | images_refresh |
---|
227 | } |
---|
228 | >>line { |
---|
229 | $widgets(comm) insert end $data outgoing "\n" outgoing |
---|
230 | } |
---|
231 | error { |
---|
232 | $widgets(comm) insert end $data error "\n" error |
---|
233 | } |
---|
234 | default { |
---|
235 | $widgets(comm) insert end "$data\n" |
---|
236 | } |
---|
237 | } |
---|
238 | $widgets(comm) configure -state disabled |
---|
239 | $widgets(comm) see end |
---|
240 | } |
---|
241 | |
---|
242 | # ---------------------------------------------------------------------- |
---|
243 | # TOPLEVEL FOR IMAGES |
---|
244 | # ---------------------------------------------------------------------- |
---|
245 | # USAGE: images_save |
---|
246 | # |
---|
247 | # Invoked when the user presses the "Save As..." button on the |
---|
248 | # images panel. Saves the current image in a file, which can be |
---|
249 | # examined by some external program. |
---|
250 | # ---------------------------------------------------------------------- |
---|
251 | proc images_save {} { |
---|
252 | global widgets images |
---|
253 | |
---|
254 | set imh [$widgets(vtkvolumeviewer) get -image $images(which)] |
---|
255 | |
---|
256 | set file [tk_getSaveFile -title "Save Image File" \ |
---|
257 | -defaultextension .jpg -filetypes {{{JPEG files} .jpg} {{All Files} *}}] |
---|
258 | |
---|
259 | if {"" != $file} { |
---|
260 | set cmds { |
---|
261 | $imh write $file -format jpeg |
---|
262 | } |
---|
263 | if {[catch $cmds err]} { |
---|
264 | tk_messageBox -icon error -message "Oops! Save failed:\n$err" |
---|
265 | } |
---|
266 | } |
---|
267 | } |
---|
268 | |
---|
269 | # ---------------------------------------------------------------------- |
---|
270 | # USAGE: images_refresh |
---|
271 | # |
---|
272 | # Invoked automatically whenever there is a change in the view/legend |
---|
273 | # controls on the images panel. Updates the image being shown based |
---|
274 | # on the current selection. |
---|
275 | # ---------------------------------------------------------------------- |
---|
276 | proc images_refresh {} { |
---|
277 | global widgets images |
---|
278 | set c $widgets(viewer) |
---|
279 | |
---|
280 | set w [winfo width $c] |
---|
281 | set h [winfo height $c] |
---|
282 | |
---|
283 | set imh [$widgets(vtkvolumeviewer) get -image $images(which)] |
---|
284 | set iw [image width $imh] |
---|
285 | set ih [image height $imh] |
---|
286 | |
---|
287 | $c coords image [expr {$w/2}] [expr {$h/2}] |
---|
288 | $c itemconfigure image -image $imh |
---|
289 | $c coords outline [expr {$w/2-$iw/2}] [expr {$h/2-$ih/2}] \ |
---|
290 | [expr {$w/2+$iw/2}] [expr {$h/2+$ih/2}] |
---|
291 | } |
---|
292 | |
---|
293 | toplevel .images |
---|
294 | wm title .images "Vtkvolumeviewer: Images" |
---|
295 | wm withdraw .images |
---|
296 | wm protocol .images WM_DELETE_WINDOW {wm withdraw .images} |
---|
297 | |
---|
298 | frame .images.cntls |
---|
299 | pack .images.cntls -side bottom -fill x |
---|
300 | button .images.cntls.save -text "Save As..." -command images_save |
---|
301 | pack .images.cntls.save -side right -padx 4 |
---|
302 | radiobutton .images.cntls.view -text "3D View" -variable images(which) \ |
---|
303 | -value "view" -command images_refresh |
---|
304 | pack .images.cntls.view -side top -anchor w |
---|
305 | radiobutton .images.cntls.legend -text "Legend" -variable images(which) \ |
---|
306 | -value "legend" -command images_refresh |
---|
307 | pack .images.cntls.legend -side top -anchor w |
---|
308 | set images(which) "view" |
---|
309 | |
---|
310 | canvas .images.viewer -background black -width 500 -height 500 |
---|
311 | pack .images.viewer -expand yes -fill both |
---|
312 | bind .images.viewer <Configure> images_refresh |
---|
313 | set widgets(viewer) .images.viewer |
---|
314 | |
---|
315 | $widgets(viewer) create image 0 0 -anchor c \ |
---|
316 | -image [image create photo] -tags image |
---|
317 | $widgets(viewer) create rectangle 0 0 1 1 -width 2 -outline red -fill "" \ |
---|
318 | -tags outline |
---|
319 | |
---|
320 | |
---|
321 | # ---------------------------------------------------------------------- |
---|
322 | # MAIN WINDOW |
---|
323 | # ---------------------------------------------------------------------- |
---|
324 | menu .mbar |
---|
325 | menu .mbar.file |
---|
326 | .mbar.file add command -label "Send VTK File..." -underline 0 -command send_file |
---|
327 | .mbar.file add command -label "Load script..." -underline 0 -command load_script |
---|
328 | .mbar.file add command -label "Reset" -underline 0 -command reset |
---|
329 | .mbar.file add separator |
---|
330 | .mbar.file add command -label "Exit" -underline 1 -command exit |
---|
331 | .mbar add cascade -label "File" -underline 0 -menu .mbar.file |
---|
332 | |
---|
333 | menu .mbar.view |
---|
334 | .mbar.view add command -label "Images..." -underline 0 \ |
---|
335 | -command {wm deiconify .images} |
---|
336 | .mbar add cascade -label "View" -underline 0 -menu .mbar.view |
---|
337 | |
---|
338 | . configure -menu .mbar |
---|
339 | |
---|
340 | |
---|
341 | Rappture::Panes .main -sashwidth 4 -sashrelief raised -sashpadding 4 \ |
---|
342 | -width 6i -height 4i |
---|
343 | pack .main -expand yes -fill both |
---|
344 | |
---|
345 | set f [.main pane 0] |
---|
346 | Rappture::VtkVolumeViewer $f.viewer |
---|
347 | pack $f.viewer -expand yes -fill both |
---|
348 | set widgets(vtkvolumeviewer) $f.viewer |
---|
349 | |
---|
350 | $f.viewer configure \ |
---|
351 | -sendcommand show_comm \ |
---|
352 | -receivecommand show_comm |
---|
353 | |
---|
354 | set f [.main insert end -fraction 0.5] |
---|
355 | frame $f.send |
---|
356 | pack $f.send -side bottom -fill x |
---|
357 | label $f.send.l -text "Send:" |
---|
358 | pack $f.send.l -side left |
---|
359 | set widgets(command) [entry $f.send.e] |
---|
360 | pack $f.send.e -side left -expand yes -fill x |
---|
361 | bind $f.send.e <KeyPress-Return> send_command |
---|
362 | |
---|
363 | scrollbar $f.sb -orient vertical -command "$f.comm yview" |
---|
364 | pack $f.sb -side right -fill y |
---|
365 | text $f.comm -wrap char -yscrollcommand "$f.sb set" |
---|
366 | pack $f.comm -expand yes -fill both |
---|
367 | set widgets(comm) $f.comm |
---|
368 | |
---|
369 | $widgets(comm) tag configure error -foreground red \ |
---|
370 | -font -*-courier-medium-o-normal-*-*-120-* |
---|
371 | $widgets(comm) tag configure incoming -foreground blue |
---|