1 | # -*- mode: tcl; indent-tabs-mode: nil -*- |
---|
2 | |
---|
3 | # ---------------------------------------------------------------------- |
---|
4 | # COMPONENT: nanovisviewer - 3D volume rendering |
---|
5 | # |
---|
6 | # This widget performs volume rendering on 3D scalar/vector datasets. |
---|
7 | # It connects to the Nanovis server running on a rendering farm, |
---|
8 | # transmits data, and displays the results. |
---|
9 | # ====================================================================== |
---|
10 | # AUTHOR: Michael McLennan, Purdue University |
---|
11 | # Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
12 | # |
---|
13 | # See the file "license.terms" for information on usage and |
---|
14 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
15 | # ====================================================================== |
---|
16 | package require Itk |
---|
17 | package require BLT |
---|
18 | package require Img |
---|
19 | |
---|
20 | # |
---|
21 | # FIXME: |
---|
22 | # Need to Add DX readers this client to examine the data before |
---|
23 | # it's sent to the server. This will eliminate 90% of the insanity in |
---|
24 | # computing the limits of all the volumes. I can rip out all the |
---|
25 | # "receive data" "send transfer function" event crap. |
---|
26 | # |
---|
27 | # This means we can compute the transfer function (relative values) and |
---|
28 | # draw the legend min/max values without waiting for the information to |
---|
29 | # come from the server. This will also prevent the flashing that occurs |
---|
30 | # when a new volume is drawn (using the default transfer function) and |
---|
31 | # then when the correct transfer function has been sent and linked to |
---|
32 | # the volume. |
---|
33 | # |
---|
34 | option add *NanovisViewer.width 4i widgetDefault |
---|
35 | option add *NanovisViewer*cursor crosshair widgetDefault |
---|
36 | option add *NanovisViewer.height 4i widgetDefault |
---|
37 | option add *NanovisViewer.foreground black widgetDefault |
---|
38 | option add *NanovisViewer.controlBackground gray widgetDefault |
---|
39 | option add *NanovisViewer.controlDarkBackground #999999 widgetDefault |
---|
40 | option add *NanovisViewer.plotBackground black widgetDefault |
---|
41 | option add *NanovisViewer.plotForeground white widgetDefault |
---|
42 | option add *NanovisViewer.plotOutline gray widgetDefault |
---|
43 | option add *NanovisViewer.font \ |
---|
44 | -*-helvetica-medium-r-normal-*-12-* widgetDefault |
---|
45 | |
---|
46 | # must use this name -- plugs into Rappture::resources::load |
---|
47 | proc NanovisViewer_init_resources {} { |
---|
48 | Rappture::resources::register \ |
---|
49 | nanovis_server Rappture::NanovisViewer::SetServerList |
---|
50 | } |
---|
51 | |
---|
52 | itcl::class Rappture::NanovisViewer { |
---|
53 | inherit Rappture::VisViewer |
---|
54 | |
---|
55 | itk_option define -plotforeground plotForeground Foreground "" |
---|
56 | itk_option define -plotbackground plotBackground Background "" |
---|
57 | itk_option define -plotoutline plotOutline PlotOutline "" |
---|
58 | |
---|
59 | constructor { hostlist args } { |
---|
60 | Rappture::VisViewer::constructor $hostlist |
---|
61 | } { |
---|
62 | # defined below |
---|
63 | } |
---|
64 | destructor { |
---|
65 | # defined below |
---|
66 | } |
---|
67 | public proc SetServerList { namelist } { |
---|
68 | Rappture::VisViewer::SetServerList "nanovis" $namelist |
---|
69 | } |
---|
70 | public method add {dataobj {settings ""}} |
---|
71 | public method camera {option args} |
---|
72 | public method delete {args} |
---|
73 | public method disconnect {} |
---|
74 | public method download {option args} |
---|
75 | public method get {args} |
---|
76 | public method isconnected {} |
---|
77 | public method limits { tf } |
---|
78 | public method overmarker { m x } |
---|
79 | public method parameters {title args} { |
---|
80 | # do nothing |
---|
81 | } |
---|
82 | public method rmdupmarker { m x } |
---|
83 | public method scale {args} |
---|
84 | public method updatetransferfuncs {} |
---|
85 | |
---|
86 | protected method Connect {} |
---|
87 | protected method CurrentDatasets {{what -all}} |
---|
88 | protected method Disconnect {} |
---|
89 | protected method DoResize {} |
---|
90 | protected method FixLegend {} |
---|
91 | protected method AdjustSetting {what {value ""}} |
---|
92 | protected method InitSettings { args } |
---|
93 | protected method Pan {option x y} |
---|
94 | protected method Rebuild {} |
---|
95 | protected method ReceiveData { args } |
---|
96 | protected method ReceiveImage { args } |
---|
97 | protected method ReceiveLegend { tf vmin vmax size } |
---|
98 | protected method Rotate {option x y} |
---|
99 | protected method SendTransferFuncs {} |
---|
100 | protected method Slice {option args} |
---|
101 | protected method SlicerTip {axis} |
---|
102 | protected method Zoom {option} |
---|
103 | |
---|
104 | # The following methods are only used by this class. |
---|
105 | private method AddIsoMarker { x y } |
---|
106 | private method BuildCameraTab {} |
---|
107 | private method BuildCutplanesTab {} |
---|
108 | private method BuildViewTab {} |
---|
109 | private method BuildVolumeTab {} |
---|
110 | private method ResetColormap { color } |
---|
111 | private method ComputeTransferFunc { tf } |
---|
112 | private method EventuallyResize { w h } |
---|
113 | private method EventuallyResizeLegend { } |
---|
114 | private method NameTransferFunc { dataobj comp } |
---|
115 | private method PanCamera {} |
---|
116 | private method ParseLevelsOption { tf levels } |
---|
117 | private method ParseMarkersOption { tf markers } |
---|
118 | private method volume { tag name } |
---|
119 | private method GetVolumeInfo { w } |
---|
120 | private method SetOrientation { side } |
---|
121 | |
---|
122 | private variable _arcball "" |
---|
123 | |
---|
124 | private variable _dlist "" ;# list of data objects |
---|
125 | private variable _allDataObjs |
---|
126 | private variable _obj2ovride ;# maps dataobj => style override |
---|
127 | private variable _serverDatasets ;# contains all the dataobj-component |
---|
128 | ;# to volumes in the server |
---|
129 | private variable _serverTfs ;# contains all the transfer functions |
---|
130 | ;# in the server. |
---|
131 | private variable _recvdDatasets ;# list of data objs to send to server |
---|
132 | private variable _dataset2style ;# maps dataobj-component to transfunc |
---|
133 | private variable _style2datasets ;# maps tf back to list of |
---|
134 | # dataobj-components using the tf. |
---|
135 | |
---|
136 | private variable _reset 1; # Connection to server has been reset |
---|
137 | private variable _click ;# info used for rotate operations |
---|
138 | private variable _limits ;# autoscale min/max for all axes |
---|
139 | private variable _view ;# view params for 3D view |
---|
140 | private variable _isomarkers ;# array of isosurface level values 0..1 |
---|
141 | private variable _settings |
---|
142 | # Array of transfer functions in server. If 0 the transfer has been |
---|
143 | # defined but not loaded. If 1 the transfer function has been named |
---|
144 | # and loaded. |
---|
145 | private variable _activeTfs |
---|
146 | private variable _first "" ;# This is the topmost volume. |
---|
147 | private variable _alphamap |
---|
148 | |
---|
149 | # This |
---|
150 | # indicates which isomarkers and transfer |
---|
151 | # function to use when changing markers, |
---|
152 | # opacity, or thickness. |
---|
153 | common _downloadPopup ;# download options from popup |
---|
154 | private common _hardcopy |
---|
155 | private variable _width 0 |
---|
156 | private variable _height 0 |
---|
157 | private variable _resizePending 0 |
---|
158 | private variable _resizeLegendPending 0 |
---|
159 | } |
---|
160 | |
---|
161 | itk::usual NanovisViewer { |
---|
162 | keep -background -foreground -cursor -font |
---|
163 | keep -plotbackground -plotforeground |
---|
164 | } |
---|
165 | |
---|
166 | # ---------------------------------------------------------------------- |
---|
167 | # CONSTRUCTOR |
---|
168 | # ---------------------------------------------------------------------- |
---|
169 | itcl::body Rappture::NanovisViewer::constructor {hostlist args} { |
---|
170 | set _serverType "nanovis" |
---|
171 | |
---|
172 | # Draw legend event |
---|
173 | $_dispatcher register !legend |
---|
174 | $_dispatcher dispatch $this !legend "[itcl::code $this FixLegend]; list" |
---|
175 | |
---|
176 | # Send transfer functions event |
---|
177 | $_dispatcher register !send_transfunc |
---|
178 | $_dispatcher dispatch $this !send_transfunc \ |
---|
179 | "[itcl::code $this SendTransferFuncs]; list" |
---|
180 | |
---|
181 | # Rebuild event |
---|
182 | $_dispatcher register !rebuild |
---|
183 | $_dispatcher dispatch $this !rebuild "[itcl::code $this Rebuild]; list" |
---|
184 | |
---|
185 | # Resize event |
---|
186 | $_dispatcher register !resize |
---|
187 | $_dispatcher dispatch $this !resize "[itcl::code $this DoResize]; list" |
---|
188 | |
---|
189 | # |
---|
190 | # Populate parser with commands handle incoming requests |
---|
191 | # |
---|
192 | $_parser alias image [itcl::code $this ReceiveImage] |
---|
193 | $_parser alias legend [itcl::code $this ReceiveLegend] |
---|
194 | $_parser alias data [itcl::code $this ReceiveData] |
---|
195 | |
---|
196 | # Initialize the view to some default parameters. |
---|
197 | array set _view { |
---|
198 | qw 0.853553 |
---|
199 | qx -0.353553 |
---|
200 | qy 0.353553 |
---|
201 | qz 0.146447 |
---|
202 | zoom 1.0 |
---|
203 | xpan 0 |
---|
204 | ypan 0 |
---|
205 | } |
---|
206 | set _arcball [blt::arcball create 100 100] |
---|
207 | set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] |
---|
208 | $_arcball quaternion $q |
---|
209 | |
---|
210 | set _limits(vmin) 0.0 |
---|
211 | set _limits(vmax) 1.0 |
---|
212 | set _reset 1 |
---|
213 | |
---|
214 | array set _settings [subst { |
---|
215 | $this-qw $_view(qw) |
---|
216 | $this-qx $_view(qx) |
---|
217 | $this-qy $_view(qy) |
---|
218 | $this-qz $_view(qz) |
---|
219 | $this-zoom $_view(zoom) |
---|
220 | $this-xpan $_view(xpan) |
---|
221 | $this-ypan $_view(ypan) |
---|
222 | $this-volume 1 |
---|
223 | $this-xcutplane 0 |
---|
224 | $this-xcutposition 0 |
---|
225 | $this-ycutplane 0 |
---|
226 | $this-ycutposition 0 |
---|
227 | $this-zcutplane 0 |
---|
228 | $this-zcutposition 0 |
---|
229 | }] |
---|
230 | |
---|
231 | itk_component add 3dview { |
---|
232 | label $itk_component(plotarea).view -image $_image(plot) \ |
---|
233 | -highlightthickness 0 -borderwidth 0 |
---|
234 | } { |
---|
235 | usual |
---|
236 | ignore -highlightthickness -borderwidth -background |
---|
237 | } |
---|
238 | bind $itk_component(3dview) <Control-F1> [itcl::code $this ToggleConsole] |
---|
239 | |
---|
240 | set f [$itk_component(main) component controls] |
---|
241 | itk_component add reset { |
---|
242 | button $f.reset -borderwidth 1 -padx 1 -pady 1 \ |
---|
243 | -highlightthickness 0 \ |
---|
244 | -image [Rappture::icon reset-view] \ |
---|
245 | -command [itcl::code $this Zoom reset] |
---|
246 | } { |
---|
247 | usual |
---|
248 | ignore -highlightthickness |
---|
249 | } |
---|
250 | pack $itk_component(reset) -side top -padx 2 -pady 2 |
---|
251 | Rappture::Tooltip::for $itk_component(reset) "Reset the view to the default zoom level" |
---|
252 | |
---|
253 | itk_component add zoomin { |
---|
254 | button $f.zin -borderwidth 1 -padx 1 -pady 1 \ |
---|
255 | -highlightthickness 0 \ |
---|
256 | -image [Rappture::icon zoom-in] \ |
---|
257 | -command [itcl::code $this Zoom in] |
---|
258 | } { |
---|
259 | usual |
---|
260 | ignore -highlightthickness |
---|
261 | } |
---|
262 | pack $itk_component(zoomin) -side top -padx 2 -pady 2 |
---|
263 | Rappture::Tooltip::for $itk_component(zoomin) "Zoom in" |
---|
264 | |
---|
265 | itk_component add zoomout { |
---|
266 | button $f.zout -borderwidth 1 -padx 1 -pady 1 \ |
---|
267 | -highlightthickness 0 \ |
---|
268 | -image [Rappture::icon zoom-out] \ |
---|
269 | -command [itcl::code $this Zoom out] |
---|
270 | } { |
---|
271 | usual |
---|
272 | ignore -highlightthickness |
---|
273 | } |
---|
274 | pack $itk_component(zoomout) -side top -padx 2 -pady 2 |
---|
275 | Rappture::Tooltip::for $itk_component(zoomout) "Zoom out" |
---|
276 | |
---|
277 | itk_component add volume { |
---|
278 | Rappture::PushButton $f.volume \ |
---|
279 | -onimage [Rappture::icon volume-on] \ |
---|
280 | -offimage [Rappture::icon volume-off] \ |
---|
281 | -command [itcl::code $this AdjustSetting volume] \ |
---|
282 | -variable [itcl::scope _settings($this-volume)] |
---|
283 | } |
---|
284 | $itk_component(volume) select |
---|
285 | Rappture::Tooltip::for $itk_component(volume) \ |
---|
286 | "Toggle the volume cloud on/off" |
---|
287 | pack $itk_component(volume) -padx 2 -pady 2 |
---|
288 | |
---|
289 | if { [catch { |
---|
290 | BuildViewTab |
---|
291 | BuildVolumeTab |
---|
292 | BuildCutplanesTab |
---|
293 | BuildCameraTab |
---|
294 | } errs] != 0 } { |
---|
295 | global errorInfo |
---|
296 | puts stderr "errs=$errs errorInfo=$errorInfo" |
---|
297 | } |
---|
298 | |
---|
299 | # Legend |
---|
300 | |
---|
301 | set _image(legend) [image create photo] |
---|
302 | itk_component add legend { |
---|
303 | canvas $itk_component(plotarea).legend -height 50 -highlightthickness 0 |
---|
304 | } { |
---|
305 | usual |
---|
306 | ignore -highlightthickness |
---|
307 | rename -background -plotbackground plotBackground Background |
---|
308 | } |
---|
309 | bind $itk_component(legend) <Configure> \ |
---|
310 | [itcl::code $this EventuallyResizeLegend] |
---|
311 | |
---|
312 | # Hack around the Tk panewindow. The problem is that the requested |
---|
313 | # size of the 3d view isn't set until an image is retrieved from |
---|
314 | # the server. So the panewindow uses the tiny size. |
---|
315 | set w 10000 |
---|
316 | pack forget $itk_component(3dview) |
---|
317 | blt::table $itk_component(plotarea) \ |
---|
318 | 0,0 $itk_component(3dview) -fill both -reqwidth $w \ |
---|
319 | 1,0 $itk_component(legend) -fill x |
---|
320 | blt::table configure $itk_component(plotarea) r1 -resize none |
---|
321 | |
---|
322 | # Bindings for rotation via mouse |
---|
323 | bind $itk_component(3dview) <ButtonPress-1> \ |
---|
324 | [itcl::code $this Rotate click %x %y] |
---|
325 | bind $itk_component(3dview) <B1-Motion> \ |
---|
326 | [itcl::code $this Rotate drag %x %y] |
---|
327 | bind $itk_component(3dview) <ButtonRelease-1> \ |
---|
328 | [itcl::code $this Rotate release %x %y] |
---|
329 | bind $itk_component(3dview) <Configure> \ |
---|
330 | [itcl::code $this EventuallyResize %w %h] |
---|
331 | |
---|
332 | # Bindings for panning via mouse |
---|
333 | bind $itk_component(3dview) <ButtonPress-2> \ |
---|
334 | [itcl::code $this Pan click %x %y] |
---|
335 | bind $itk_component(3dview) <B2-Motion> \ |
---|
336 | [itcl::code $this Pan drag %x %y] |
---|
337 | bind $itk_component(3dview) <ButtonRelease-2> \ |
---|
338 | [itcl::code $this Pan release %x %y] |
---|
339 | |
---|
340 | # Bindings for panning via keyboard |
---|
341 | bind $itk_component(3dview) <KeyPress-Left> \ |
---|
342 | [itcl::code $this Pan set -10 0] |
---|
343 | bind $itk_component(3dview) <KeyPress-Right> \ |
---|
344 | [itcl::code $this Pan set 10 0] |
---|
345 | bind $itk_component(3dview) <KeyPress-Up> \ |
---|
346 | [itcl::code $this Pan set 0 -10] |
---|
347 | bind $itk_component(3dview) <KeyPress-Down> \ |
---|
348 | [itcl::code $this Pan set 0 10] |
---|
349 | bind $itk_component(3dview) <Shift-KeyPress-Left> \ |
---|
350 | [itcl::code $this Pan set -2 0] |
---|
351 | bind $itk_component(3dview) <Shift-KeyPress-Right> \ |
---|
352 | [itcl::code $this Pan set 2 0] |
---|
353 | bind $itk_component(3dview) <Shift-KeyPress-Up> \ |
---|
354 | [itcl::code $this Pan set 0 -2] |
---|
355 | bind $itk_component(3dview) <Shift-KeyPress-Down> \ |
---|
356 | [itcl::code $this Pan set 0 2] |
---|
357 | |
---|
358 | # Bindings for zoom via keyboard |
---|
359 | bind $itk_component(3dview) <KeyPress-Prior> \ |
---|
360 | [itcl::code $this Zoom out] |
---|
361 | bind $itk_component(3dview) <KeyPress-Next> \ |
---|
362 | [itcl::code $this Zoom in] |
---|
363 | |
---|
364 | bind $itk_component(3dview) <Enter> "focus $itk_component(3dview)" |
---|
365 | |
---|
366 | if {[string equal "x11" [tk windowingsystem]]} { |
---|
367 | # Bindings for zoom via mouse |
---|
368 | bind $itk_component(3dview) <4> [itcl::code $this Zoom out] |
---|
369 | bind $itk_component(3dview) <5> [itcl::code $this Zoom in] |
---|
370 | } |
---|
371 | |
---|
372 | set _image(download) [image create photo] |
---|
373 | |
---|
374 | eval itk_initialize $args |
---|
375 | |
---|
376 | Connect |
---|
377 | } |
---|
378 | |
---|
379 | # ---------------------------------------------------------------------- |
---|
380 | # DESTRUCTOR |
---|
381 | # ---------------------------------------------------------------------- |
---|
382 | itcl::body Rappture::NanovisViewer::destructor {} { |
---|
383 | $_dispatcher cancel !rebuild |
---|
384 | $_dispatcher cancel !send_transfunc |
---|
385 | $_dispatcher cancel !resize |
---|
386 | image delete $_image(plot) |
---|
387 | image delete $_image(legend) |
---|
388 | image delete $_image(download) |
---|
389 | catch { blt::arcball destroy $_arcball } |
---|
390 | array unset _settings $this-* |
---|
391 | } |
---|
392 | |
---|
393 | # ---------------------------------------------------------------------- |
---|
394 | # USAGE: add <dataobj> ?<settings>? |
---|
395 | # |
---|
396 | # Clients use this to add a data object to the plot. The optional |
---|
397 | # <settings> are used to configure the plot. Allowed settings are |
---|
398 | # -color, -brightness, -width, -linestyle, and -raise. |
---|
399 | # ---------------------------------------------------------------------- |
---|
400 | itcl::body Rappture::NanovisViewer::add {dataobj {settings ""}} { |
---|
401 | if { ![$dataobj isvalid] } { |
---|
402 | return; # Object doesn't contain valid data. |
---|
403 | } |
---|
404 | array set params { |
---|
405 | -color auto |
---|
406 | -width 1 |
---|
407 | -linestyle solid |
---|
408 | -brightness 0 |
---|
409 | -raise 0 |
---|
410 | -description "" |
---|
411 | -param "" |
---|
412 | } |
---|
413 | array set params $settings |
---|
414 | |
---|
415 | if {$params(-color) == "auto" || $params(-color) == "autoreset"} { |
---|
416 | # can't handle -autocolors yet |
---|
417 | set params(-color) black |
---|
418 | } |
---|
419 | set pos [lsearch -exact $_dlist $dataobj] |
---|
420 | if {$pos < 0} { |
---|
421 | lappend _dlist $dataobj |
---|
422 | set _allDataObjs($dataobj) 1 |
---|
423 | set _obj2ovride($dataobj-color) $params(-color) |
---|
424 | set _obj2ovride($dataobj-width) $params(-width) |
---|
425 | set _obj2ovride($dataobj-raise) $params(-raise) |
---|
426 | $_dispatcher event -idle !rebuild |
---|
427 | } |
---|
428 | } |
---|
429 | |
---|
430 | # ---------------------------------------------------------------------- |
---|
431 | # USAGE: get ?-objects? |
---|
432 | # USAGE: get ?-image 3dview|legend? |
---|
433 | # |
---|
434 | # Clients use this to query the list of objects being plotted, in |
---|
435 | # order from bottom to top of this result. The optional "-image" |
---|
436 | # flag can also request the internal images being shown. |
---|
437 | # ---------------------------------------------------------------------- |
---|
438 | itcl::body Rappture::NanovisViewer::get {args} { |
---|
439 | if {[llength $args] == 0} { |
---|
440 | set args "-objects" |
---|
441 | } |
---|
442 | |
---|
443 | set op [lindex $args 0] |
---|
444 | switch -- $op { |
---|
445 | -objects { |
---|
446 | # put the dataobj list in order according to -raise options |
---|
447 | set dlist $_dlist |
---|
448 | foreach obj $dlist { |
---|
449 | if {[info exists _obj2ovride($obj-raise)] && $_obj2ovride($obj-raise)} { |
---|
450 | set i [lsearch -exact $dlist $obj] |
---|
451 | if {$i >= 0} { |
---|
452 | set dlist [lreplace $dlist $i $i] |
---|
453 | lappend dlist $obj |
---|
454 | } |
---|
455 | } |
---|
456 | } |
---|
457 | return $dlist |
---|
458 | } |
---|
459 | -image { |
---|
460 | if {[llength $args] != 2} { |
---|
461 | error "wrong # args: should be \"get -image 3dview|legend\"" |
---|
462 | } |
---|
463 | switch -- [lindex $args end] { |
---|
464 | 3dview { |
---|
465 | return $_image(plot) |
---|
466 | } |
---|
467 | legend { |
---|
468 | return $_image(legend) |
---|
469 | } |
---|
470 | default { |
---|
471 | error "bad image name \"[lindex $args end]\": should be 3dview or legend" |
---|
472 | } |
---|
473 | } |
---|
474 | } |
---|
475 | default { |
---|
476 | error "bad option \"$op\": should be -objects or -image" |
---|
477 | } |
---|
478 | } |
---|
479 | } |
---|
480 | |
---|
481 | # ---------------------------------------------------------------------- |
---|
482 | # USAGE: delete ?<dataobj1> <dataobj2> ...? |
---|
483 | # |
---|
484 | # Clients use this to delete a dataobj from the plot. If no dataobjs |
---|
485 | # are specified, then all dataobjs are deleted. No data objects are |
---|
486 | # deleted. They are only removed from the display list. |
---|
487 | # |
---|
488 | # ---------------------------------------------------------------------- |
---|
489 | itcl::body Rappture::NanovisViewer::delete {args} { |
---|
490 | if {[llength $args] == 0} { |
---|
491 | set args $_dlist |
---|
492 | } |
---|
493 | # Delete all specified dataobjs |
---|
494 | set changed 0 |
---|
495 | foreach dataobj $args { |
---|
496 | set pos [lsearch -exact $_dlist $dataobj] |
---|
497 | if { $pos >= 0 } { |
---|
498 | set _dlist [lreplace $_dlist $pos $pos] |
---|
499 | array unset _limits $dataobj* |
---|
500 | array unset _obj2ovride $dataobj-* |
---|
501 | set changed 1 |
---|
502 | } |
---|
503 | } |
---|
504 | # If anything changed, then rebuild the plot |
---|
505 | if {$changed} { |
---|
506 | $_dispatcher event -idle !rebuild |
---|
507 | } |
---|
508 | } |
---|
509 | |
---|
510 | # ---------------------------------------------------------------------- |
---|
511 | # USAGE: scale ?<data1> <data2> ...? |
---|
512 | # |
---|
513 | # Sets the default limits for the overall plot according to the |
---|
514 | # limits of the data for all of the given <data> objects. This |
---|
515 | # accounts for all objects--even those not showing on the screen. |
---|
516 | # Because of this, the limits are appropriate for all objects as |
---|
517 | # the user scans through data in the ResultSet viewer. |
---|
518 | # ---------------------------------------------------------------------- |
---|
519 | itcl::body Rappture::NanovisViewer::scale {args} { |
---|
520 | foreach val {xmin xmax ymin ymax zmin zmax vmin vmax} { |
---|
521 | set _limits($val) "" |
---|
522 | } |
---|
523 | foreach dataobj $args { |
---|
524 | if { ![$dataobj isvalid] } { |
---|
525 | continue; # Object doesn't contain valid data. |
---|
526 | } |
---|
527 | foreach axis {x y z v} { |
---|
528 | foreach { min max } [$dataobj limits $axis] break |
---|
529 | if {"" != $min && "" != $max} { |
---|
530 | if {"" == $_limits(${axis}min)} { |
---|
531 | set _limits(${axis}min) $min |
---|
532 | set _limits(${axis}max) $max |
---|
533 | } else { |
---|
534 | if {$min < $_limits(${axis}min)} { |
---|
535 | set _limits(${axis}min) $min |
---|
536 | } |
---|
537 | if {$max > $_limits(${axis}max)} { |
---|
538 | set _limits(${axis}max) $max |
---|
539 | } |
---|
540 | } |
---|
541 | } |
---|
542 | } |
---|
543 | } |
---|
544 | } |
---|
545 | |
---|
546 | # ---------------------------------------------------------------------- |
---|
547 | # USAGE: download coming |
---|
548 | # USAGE: download controls <downloadCommand> |
---|
549 | # USAGE: download now |
---|
550 | # |
---|
551 | # Clients use this method to create a downloadable representation |
---|
552 | # of the plot. Returns a list of the form {ext string}, where |
---|
553 | # "ext" is the file extension (indicating the type of data) and |
---|
554 | # "string" is the data itself. |
---|
555 | # ---------------------------------------------------------------------- |
---|
556 | itcl::body Rappture::NanovisViewer::download {option args} { |
---|
557 | switch $option { |
---|
558 | coming { |
---|
559 | if {[catch { |
---|
560 | blt::winop snap $itk_component(plotarea) $_image(download) |
---|
561 | }]} { |
---|
562 | $_image(download) configure -width 1 -height 1 |
---|
563 | $_image(download) put #000000 |
---|
564 | } |
---|
565 | } |
---|
566 | controls { |
---|
567 | # no controls for this download yet |
---|
568 | return "" |
---|
569 | } |
---|
570 | now { |
---|
571 | # Get the image data (as base64) and decode it back to binary. |
---|
572 | # This is better than writing to temporary files. When we switch |
---|
573 | # to the BLT picture image it won't be necessary to decode the |
---|
574 | # image data. |
---|
575 | if { [image width $_image(plot)] > 0 && |
---|
576 | [image height $_image(plot)] > 0 } { |
---|
577 | set bytes [$_image(plot) data -format "jpeg -quality 100"] |
---|
578 | set bytes [Rappture::encoding::decode -as b64 $bytes] |
---|
579 | return [list .jpg $bytes] |
---|
580 | } |
---|
581 | return "" |
---|
582 | } |
---|
583 | default { |
---|
584 | error "bad option \"$option\": should be coming, controls, now" |
---|
585 | } |
---|
586 | } |
---|
587 | } |
---|
588 | |
---|
589 | # ---------------------------------------------------------------------- |
---|
590 | # USAGE: Connect ?<host:port>,<host:port>...? |
---|
591 | # |
---|
592 | # Clients use this method to establish a connection to a new |
---|
593 | # server, or to reestablish a connection to the previous server. |
---|
594 | # Any existing connection is automatically closed. |
---|
595 | # ---------------------------------------------------------------------- |
---|
596 | itcl::body Rappture::NanovisViewer::Connect {} { |
---|
597 | set _hosts [GetServerList "nanovis"] |
---|
598 | if { "" == $_hosts } { |
---|
599 | return 0 |
---|
600 | } |
---|
601 | set _reset 1 |
---|
602 | set result [VisViewer::Connect $_hosts] |
---|
603 | if { $result } { |
---|
604 | if { $_reportClientInfo } { |
---|
605 | # Tell the server the viewer, hub, user and session. |
---|
606 | # Do this immediately on connect before buffering any commands |
---|
607 | global env |
---|
608 | |
---|
609 | set info {} |
---|
610 | set user "???" |
---|
611 | if { [info exists env(USER)] } { |
---|
612 | set user $env(USER) |
---|
613 | } |
---|
614 | set session "???" |
---|
615 | if { [info exists env(SESSION)] } { |
---|
616 | set session $env(SESSION) |
---|
617 | } |
---|
618 | lappend info "hub" [exec hostname] |
---|
619 | lappend info "client" "nanovisviewer" |
---|
620 | lappend info "user" $user |
---|
621 | lappend info "session" $session |
---|
622 | SendCmd "clientinfo [list $info]" |
---|
623 | } |
---|
624 | |
---|
625 | set w [winfo width $itk_component(3dview)] |
---|
626 | set h [winfo height $itk_component(3dview)] |
---|
627 | EventuallyResize $w $h |
---|
628 | } |
---|
629 | return $result |
---|
630 | } |
---|
631 | |
---|
632 | # |
---|
633 | # isconnected -- |
---|
634 | # |
---|
635 | # Indicates if we are currently connected to the visualization server. |
---|
636 | # |
---|
637 | itcl::body Rappture::NanovisViewer::isconnected {} { |
---|
638 | return [VisViewer::IsConnected] |
---|
639 | } |
---|
640 | |
---|
641 | # |
---|
642 | # disconnect -- |
---|
643 | # |
---|
644 | itcl::body Rappture::NanovisViewer::disconnect {} { |
---|
645 | Disconnect |
---|
646 | } |
---|
647 | |
---|
648 | # |
---|
649 | # Disconnect -- |
---|
650 | # |
---|
651 | # Clients use this method to disconnect from the current rendering |
---|
652 | # server. |
---|
653 | # |
---|
654 | itcl::body Rappture::NanovisViewer::Disconnect {} { |
---|
655 | VisViewer::Disconnect |
---|
656 | |
---|
657 | # disconnected -- no more data sitting on server |
---|
658 | array unset _serverDatasets |
---|
659 | } |
---|
660 | |
---|
661 | # ---------------------------------------------------------------------- |
---|
662 | # USAGE: SendTransferFuncs |
---|
663 | # ---------------------------------------------------------------------- |
---|
664 | itcl::body Rappture::NanovisViewer::SendTransferFuncs {} { |
---|
665 | if { $_first == "" } { |
---|
666 | puts stderr "first not set" |
---|
667 | return |
---|
668 | } |
---|
669 | # Ensure that the global opacity and thickness settings (in the slider |
---|
670 | # settings widgets) are used for the active transfer-function. Update |
---|
671 | # the values in the _settings varible. |
---|
672 | set opacity [expr { double($_settings($this-opacity)) * 0.01 }] |
---|
673 | # Scale values between 0.00001 and 0.01000 |
---|
674 | set thickness [expr {double($_settings($this-thickness)) * 0.0001}] |
---|
675 | |
---|
676 | foreach tag [CurrentDatasets] { |
---|
677 | if { ![info exists _serverDatasets($tag)] || !$_serverDatasets($tag) } { |
---|
678 | # The volume hasn't reached the server yet. How did we get |
---|
679 | # here? |
---|
680 | puts stderr "Don't have $tag in _serverDatasets" |
---|
681 | continue |
---|
682 | } |
---|
683 | if { ![info exists _dataset2style($tag)] } { |
---|
684 | puts stderr "don't have style for volume $tag" |
---|
685 | continue; # How does this happen? |
---|
686 | } |
---|
687 | set tf $_dataset2style($tag) |
---|
688 | set _settings($this-$tf-opacity) $opacity |
---|
689 | set _settings($this-$tf-thickness) $thickness |
---|
690 | ComputeTransferFunc $tf |
---|
691 | # FIXME: Need to the send information as to what transfer functions |
---|
692 | # to update so that we only update the transfer function |
---|
693 | # as necessary. Right now, all transfer functions are |
---|
694 | # updated. This makes moving the isomarker slider chunky. |
---|
695 | if { ![info exists _activeTfs($tf)] || !$_activeTfs($tf) } { |
---|
696 | set _activeTfs($tf) 1 |
---|
697 | } |
---|
698 | SendCmd "volume shading transfunc $tf $tag" |
---|
699 | } |
---|
700 | FixLegend |
---|
701 | } |
---|
702 | |
---|
703 | # ---------------------------------------------------------------------- |
---|
704 | # USAGE: ReceiveImage -bytes <size> -type <type> -token <token> |
---|
705 | # |
---|
706 | # Invoked automatically whenever the "image" command comes in from |
---|
707 | # the rendering server. Indicates that binary image data with the |
---|
708 | # specified <size> will follow. |
---|
709 | # ---------------------------------------------------------------------- |
---|
710 | itcl::body Rappture::NanovisViewer::ReceiveImage { args } { |
---|
711 | array set info { |
---|
712 | -token "???" |
---|
713 | -bytes 0 |
---|
714 | -type image |
---|
715 | } |
---|
716 | array set info $args |
---|
717 | set bytes [ReceiveBytes $info(-bytes)] |
---|
718 | ReceiveEcho <<line "<read $info(-bytes) bytes" |
---|
719 | if { $info(-type) == "image" } { |
---|
720 | ReceiveEcho "for [image width $_image(plot)]x[image height $_image(plot)] image>" |
---|
721 | $_image(plot) configure -data $bytes |
---|
722 | } elseif { $info(-type) == "print" } { |
---|
723 | set tag $this-print-$info(-token) |
---|
724 | set _hardcopy($tag) $bytes |
---|
725 | } |
---|
726 | } |
---|
727 | |
---|
728 | # |
---|
729 | # ReceiveLegend -- |
---|
730 | # |
---|
731 | # The procedure is the response from the render server to each "legend" |
---|
732 | # command. The server sends back a "legend" command invoked our |
---|
733 | # the slave interpreter. The purpose is to collect data of the image |
---|
734 | # representing the legend in the canvas. In addition, the isomarkers |
---|
735 | # of the active transfer function are displayed. |
---|
736 | # |
---|
737 | # I don't know is this is the right place to display the isomarkers. |
---|
738 | # I don't know all the different paths used to draw the plot. There's |
---|
739 | # "Rebuild", "add", etc. |
---|
740 | # |
---|
741 | itcl::body Rappture::NanovisViewer::ReceiveLegend { tf vmin vmax size } { |
---|
742 | if { ![isconnected] } { |
---|
743 | return |
---|
744 | } |
---|
745 | set bytes [ReceiveBytes $size] |
---|
746 | $_image(legend) configure -data $bytes |
---|
747 | ReceiveEcho <<line "<read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>" |
---|
748 | set c $itk_component(legend) |
---|
749 | set w [winfo width $c] |
---|
750 | set h [winfo height $c] |
---|
751 | set lx 10 |
---|
752 | set ly [expr {$h - 1}] |
---|
753 | if {"" == [$c find withtag transfunc]} { |
---|
754 | $c create image 10 10 -anchor nw \ |
---|
755 | -image $_image(legend) -tags transfunc |
---|
756 | $c create text $lx $ly -anchor sw \ |
---|
757 | -fill $itk_option(-plotforeground) -tags "limits vmin" |
---|
758 | $c create text [expr {$w-$lx}] $ly -anchor se \ |
---|
759 | -fill $itk_option(-plotforeground) -tags "limits vmax" |
---|
760 | $c lower transfunc |
---|
761 | $c bind transfunc <ButtonRelease-1> \ |
---|
762 | [itcl::code $this AddIsoMarker %x %y] |
---|
763 | } |
---|
764 | # Display the markers used by the active transfer function. |
---|
765 | |
---|
766 | array set limits [limits $tf] |
---|
767 | $c itemconfigure vmin -text [format %g $limits(min)] |
---|
768 | $c coords vmin $lx $ly |
---|
769 | |
---|
770 | $c itemconfigure vmax -text [format %g $limits(max)] |
---|
771 | $c coords vmax [expr {$w-$lx}] $ly |
---|
772 | |
---|
773 | if { [info exists _isomarkers($tf)] } { |
---|
774 | foreach m $_isomarkers($tf) { |
---|
775 | $m visible yes |
---|
776 | } |
---|
777 | } |
---|
778 | |
---|
779 | # The colormap may have changed. Resync the slicers with the colormap. |
---|
780 | set datasets [CurrentDatasets -cutplanes] |
---|
781 | SendCmd "volume data state $_settings($this-volume) $datasets" |
---|
782 | |
---|
783 | # Adjust the cutplane for only the first component in the topmost volume |
---|
784 | # (i.e. the first volume designated in the field). |
---|
785 | set tag [lindex $datasets 0] |
---|
786 | foreach axis {x y z} { |
---|
787 | # Turn off cutplanes for all volumes |
---|
788 | SendCmd "cutplane state 0 $axis" |
---|
789 | if { $_settings($this-${axis}cutplane) } { |
---|
790 | # Turn on cutplane for this particular volume and set the position |
---|
791 | SendCmd "cutplane state 1 $axis $tag" |
---|
792 | set pos [expr {0.01*$_settings($this-${axis}cutposition)}] |
---|
793 | SendCmd "cutplane position $pos $axis $tag" |
---|
794 | } |
---|
795 | } |
---|
796 | } |
---|
797 | |
---|
798 | # |
---|
799 | # ReceiveData -- |
---|
800 | # |
---|
801 | # The procedure is the response from the render server to each "data |
---|
802 | # follows" command. The server sends back a "data" command invoked our |
---|
803 | # the slave interpreter. The purpose is to collect the min/max of the |
---|
804 | # volume sent to the render server. Since the client (nanovisviewer) |
---|
805 | # doesn't parse 3D data formats, we rely on the server (nanovis) to |
---|
806 | # tell us what the limits are. Once we've received the limits to all |
---|
807 | # the data we've sent (tracked by _recvdDatasets) we can then determine |
---|
808 | # what the transfer functions are for these volumes. |
---|
809 | # |
---|
810 | # |
---|
811 | # Note: There is a considerable tradeoff in having the server report |
---|
812 | # back what the data limits are. It means that much of the code |
---|
813 | # having to do with transfer-functions has to wait for the data |
---|
814 | # to come back, since the isomarkers are calculated based upon |
---|
815 | # the data limits. The client code is much messier because of |
---|
816 | # this. The alternative is to parse any of the 3D formats on the |
---|
817 | # client side. |
---|
818 | # |
---|
819 | itcl::body Rappture::NanovisViewer::ReceiveData { args } { |
---|
820 | if { ![isconnected] } { |
---|
821 | return |
---|
822 | } |
---|
823 | |
---|
824 | # Arguments from server are name value pairs. Stuff them in an array. |
---|
825 | array set info $args |
---|
826 | |
---|
827 | set tag $info(tag) |
---|
828 | set parts [split $tag -] |
---|
829 | |
---|
830 | # |
---|
831 | # Volumes don't exist until we're told about them. |
---|
832 | # |
---|
833 | set dataobj [lindex $parts 0] |
---|
834 | set _serverDatasets($tag) 1 |
---|
835 | if { $_settings($this-volume) && $dataobj == $_first } { |
---|
836 | SendCmd "volume state 1 $tag" |
---|
837 | } |
---|
838 | set _limits($tag-min) $info(min); # Minimum value of the volume. |
---|
839 | set _limits($tag-max) $info(max); # Maximum value of the volume. |
---|
840 | set _limits(vmin) $info(vmin); # Overall minimum value. |
---|
841 | set _limits(vmax) $info(vmax); # Overall maximum value. |
---|
842 | |
---|
843 | unset _recvdDatasets($tag) |
---|
844 | if { [array size _recvdDatasets] == 0 } { |
---|
845 | # The active transfer function is by default the first component of |
---|
846 | # the first data object. This assumes that the data is always |
---|
847 | # successfully transferred. |
---|
848 | updatetransferfuncs |
---|
849 | } |
---|
850 | } |
---|
851 | |
---|
852 | # ---------------------------------------------------------------------- |
---|
853 | # USAGE: Rebuild |
---|
854 | # |
---|
855 | # Called automatically whenever something changes that affects the |
---|
856 | # data in the widget. Clears any existing data and rebuilds the |
---|
857 | # widget to display new data. |
---|
858 | # ---------------------------------------------------------------------- |
---|
859 | itcl::body Rappture::NanovisViewer::Rebuild {} { |
---|
860 | set w [winfo width $itk_component(3dview)] |
---|
861 | set h [winfo height $itk_component(3dview)] |
---|
862 | if { $w < 2 || $h < 2 } { |
---|
863 | $_dispatcher event -idle !rebuild |
---|
864 | return |
---|
865 | } |
---|
866 | |
---|
867 | # Turn on buffering of commands to the server. We don't want to |
---|
868 | # be preempted by a server disconnect/reconnect (which automatically |
---|
869 | # generates a new call to Rebuild). |
---|
870 | StartBufferingCommands |
---|
871 | |
---|
872 | # Hide all the isomarkers. Can't remove them. Have to remember the |
---|
873 | # settings since the user may have created/deleted/moved markers. |
---|
874 | |
---|
875 | foreach tf [array names _isomarkers] { |
---|
876 | foreach m $_isomarkers($tf) { |
---|
877 | $m visible no |
---|
878 | } |
---|
879 | } |
---|
880 | |
---|
881 | if { $_width != $w || $_height != $h || $_reset } { |
---|
882 | set _width $w |
---|
883 | set _height $h |
---|
884 | $_arcball resize $w $h |
---|
885 | DoResize |
---|
886 | } |
---|
887 | foreach dataobj [get] { |
---|
888 | foreach cname [$dataobj components] { |
---|
889 | set tag $dataobj-$cname |
---|
890 | if { ![info exists _serverDatasets($tag)] } { |
---|
891 | # Send the data as one huge base64-encoded mess -- yuck! |
---|
892 | if { [$dataobj type] == "dx" } { |
---|
893 | if { ![$dataobj isvalid] } { |
---|
894 | puts stderr "??? $dataobj is invalid" |
---|
895 | } |
---|
896 | set data [$dataobj values $cname] |
---|
897 | } else { |
---|
898 | set data [$dataobj vtkdata $cname] |
---|
899 | if 0 { |
---|
900 | set f [open "/tmp/volume.vtk" "w"] |
---|
901 | puts $f $data |
---|
902 | close $f |
---|
903 | } |
---|
904 | } |
---|
905 | set nbytes [string length $data] |
---|
906 | if { $_reportClientInfo } { |
---|
907 | set info {} |
---|
908 | lappend info "tool_id" [$dataobj hints toolId] |
---|
909 | lappend info "tool_name" [$dataobj hints toolName] |
---|
910 | lappend info "tool_version" [$dataobj hints toolRevision] |
---|
911 | lappend info "tool_title" [$dataobj hints toolTitle] |
---|
912 | lappend info "dataset_label" [$dataobj hints label] |
---|
913 | lappend info "dataset_size" $nbytes |
---|
914 | lappend info "dataset_tag" $tag |
---|
915 | SendCmd "clientinfo [list $info]" |
---|
916 | } |
---|
917 | SendCmd "volume data follows $nbytes $tag" |
---|
918 | append _outbuf $data |
---|
919 | set _recvdDatasets($tag) 1 |
---|
920 | set _serverDatasets($tag) 0 |
---|
921 | } |
---|
922 | NameTransferFunc $dataobj $cname |
---|
923 | } |
---|
924 | } |
---|
925 | set _first [lindex [get] 0] |
---|
926 | if { $_reset } { |
---|
927 | # |
---|
928 | # Reset the camera and other view parameters |
---|
929 | # |
---|
930 | set _settings($this-qw) $_view(qw) |
---|
931 | set _settings($this-qx) $_view(qx) |
---|
932 | set _settings($this-qy) $_view(qy) |
---|
933 | set _settings($this-qz) $_view(qz) |
---|
934 | set _settings($this-xpan) $_view(xpan) |
---|
935 | set _settings($this-ypan) $_view(ypan) |
---|
936 | set _settings($this-zoom) $_view(zoom) |
---|
937 | |
---|
938 | set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] |
---|
939 | $_arcball quaternion $q |
---|
940 | SendCmd "camera orient $q" |
---|
941 | SendCmd "camera reset" |
---|
942 | PanCamera |
---|
943 | SendCmd "camera zoom $_view(zoom)" |
---|
944 | InitSettings light2side light transp isosurface grid axes |
---|
945 | |
---|
946 | foreach axis {x y z} { |
---|
947 | # Turn off cutplanes for all volumes |
---|
948 | SendCmd "cutplane state 0 $axis" |
---|
949 | } |
---|
950 | if {"" != $_first} { |
---|
951 | set axis [$_first hints updir] |
---|
952 | if { "" != $axis } { |
---|
953 | SendCmd "up $axis" |
---|
954 | } |
---|
955 | set location [$_first hints camera] |
---|
956 | if { $location != "" } { |
---|
957 | array set _view $location |
---|
958 | } |
---|
959 | } |
---|
960 | } |
---|
961 | # Outline seems to need to be reset every update. |
---|
962 | InitSettings outline |
---|
963 | # nothing to send -- activate the proper ivol |
---|
964 | SendCmd "volume state 0" |
---|
965 | if {"" != $_first} { |
---|
966 | set datasets [array names _serverDatasets $_first-*] |
---|
967 | if { $datasets != "" } { |
---|
968 | SendCmd "volume state 1 $datasets" |
---|
969 | } |
---|
970 | # If the first volume already exists on the server, then make sure |
---|
971 | # we display the proper transfer function in the legend. |
---|
972 | set cname [lindex [$_first components] 0] |
---|
973 | if { [info exists _serverDatasets($_first-$cname)] } { |
---|
974 | updatetransferfuncs |
---|
975 | } |
---|
976 | } |
---|
977 | # Actually write the commands to the server socket. If it fails, we don't |
---|
978 | # care. We're finished here. |
---|
979 | blt::busy hold $itk_component(hull) |
---|
980 | StopBufferingCommands |
---|
981 | blt::busy release $itk_component(hull) |
---|
982 | set _reset 0 |
---|
983 | } |
---|
984 | |
---|
985 | # ---------------------------------------------------------------------- |
---|
986 | # USAGE: CurrentDatasets ?-cutplanes? |
---|
987 | # |
---|
988 | # Returns a list of volume server IDs for the current volume being |
---|
989 | # displayed. This is normally a single ID, but it might be a list |
---|
990 | # of IDs if the current data object has multiple components. |
---|
991 | # ---------------------------------------------------------------------- |
---|
992 | itcl::body Rappture::NanovisViewer::CurrentDatasets {{what -all}} { |
---|
993 | set rlist "" |
---|
994 | if { $_first == "" } { |
---|
995 | return |
---|
996 | } |
---|
997 | foreach cname [$_first components] { |
---|
998 | set tag $_first-$cname |
---|
999 | if { [info exists _serverDatasets($tag)] && $_serverDatasets($tag) } { |
---|
1000 | array set styles { |
---|
1001 | -cutplanes 1 |
---|
1002 | } |
---|
1003 | array set styles [lindex [$_first components -style $cname] 0] |
---|
1004 | if { $what != "-cutplanes" || $styles(-cutplanes) } { |
---|
1005 | lappend rlist $tag |
---|
1006 | } |
---|
1007 | } |
---|
1008 | } |
---|
1009 | return $rlist |
---|
1010 | } |
---|
1011 | |
---|
1012 | # ---------------------------------------------------------------------- |
---|
1013 | # USAGE: Zoom in |
---|
1014 | # USAGE: Zoom out |
---|
1015 | # USAGE: Zoom reset |
---|
1016 | # |
---|
1017 | # Called automatically when the user clicks on one of the zoom |
---|
1018 | # controls for this widget. Changes the zoom for the current view. |
---|
1019 | # ---------------------------------------------------------------------- |
---|
1020 | itcl::body Rappture::NanovisViewer::Zoom {option} { |
---|
1021 | switch -- $option { |
---|
1022 | "in" { |
---|
1023 | set _view(zoom) [expr {$_view(zoom)*1.25}] |
---|
1024 | set _settings($this-zoom) $_view(zoom) |
---|
1025 | SendCmd "camera zoom $_view(zoom)" |
---|
1026 | } |
---|
1027 | "out" { |
---|
1028 | set _view(zoom) [expr {$_view(zoom)*0.8}] |
---|
1029 | set _settings($this-zoom) $_view(zoom) |
---|
1030 | SendCmd "camera zoom $_view(zoom)" |
---|
1031 | } |
---|
1032 | "reset" { |
---|
1033 | array set _view { |
---|
1034 | qw 0.853553 |
---|
1035 | qx -0.353553 |
---|
1036 | qy 0.353553 |
---|
1037 | qz 0.146447 |
---|
1038 | zoom 1.0 |
---|
1039 | xpan 0 |
---|
1040 | ypan 0 |
---|
1041 | } |
---|
1042 | if { $_first != "" } { |
---|
1043 | set location [$_first hints camera] |
---|
1044 | if { $location != "" } { |
---|
1045 | array set _view $location |
---|
1046 | } |
---|
1047 | } |
---|
1048 | set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] |
---|
1049 | $_arcball quaternion $q |
---|
1050 | SendCmd "camera orient $q" |
---|
1051 | SendCmd "camera reset" |
---|
1052 | set _settings($this-qw) $_view(qw) |
---|
1053 | set _settings($this-qx) $_view(qx) |
---|
1054 | set _settings($this-qy) $_view(qy) |
---|
1055 | set _settings($this-qz) $_view(qz) |
---|
1056 | set _settings($this-xpan) $_view(xpan) |
---|
1057 | set _settings($this-ypan) $_view(ypan) |
---|
1058 | set _settings($this-zoom) $_view(zoom) |
---|
1059 | } |
---|
1060 | } |
---|
1061 | } |
---|
1062 | |
---|
1063 | itcl::body Rappture::NanovisViewer::PanCamera {} { |
---|
1064 | #set x [expr ($_view(xpan)) / $_limits(xrange)] |
---|
1065 | #set y [expr ($_view(ypan)) / $_limits(yrange)] |
---|
1066 | set x $_view(xpan) |
---|
1067 | set y $_view(ypan) |
---|
1068 | SendCmd "camera pan $x $y" |
---|
1069 | } |
---|
1070 | |
---|
1071 | |
---|
1072 | # ---------------------------------------------------------------------- |
---|
1073 | # USAGE: Rotate click <x> <y> |
---|
1074 | # USAGE: Rotate drag <x> <y> |
---|
1075 | # USAGE: Rotate release <x> <y> |
---|
1076 | # |
---|
1077 | # Called automatically when the user clicks/drags/releases in the |
---|
1078 | # plot area. Moves the plot according to the user's actions. |
---|
1079 | # ---------------------------------------------------------------------- |
---|
1080 | itcl::body Rappture::NanovisViewer::Rotate {option x y} { |
---|
1081 | switch -- $option { |
---|
1082 | click { |
---|
1083 | $itk_component(3dview) configure -cursor fleur |
---|
1084 | set _click(x) $x |
---|
1085 | set _click(y) $y |
---|
1086 | } |
---|
1087 | drag { |
---|
1088 | if {[array size _click] == 0} { |
---|
1089 | Rotate click $x $y |
---|
1090 | } else { |
---|
1091 | set w [winfo width $itk_component(3dview)] |
---|
1092 | set h [winfo height $itk_component(3dview)] |
---|
1093 | if {$w <= 0 || $h <= 0} { |
---|
1094 | return |
---|
1095 | } |
---|
1096 | |
---|
1097 | if {[catch { |
---|
1098 | # this fails sometimes for no apparent reason |
---|
1099 | set dx [expr {double($x-$_click(x))/$w}] |
---|
1100 | set dy [expr {double($y-$_click(y))/$h}] |
---|
1101 | }]} { |
---|
1102 | return |
---|
1103 | } |
---|
1104 | |
---|
1105 | set q [$_arcball rotate $x $y $_click(x) $_click(y)] |
---|
1106 | foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break |
---|
1107 | set _settings($this-qw) $_view(qw) |
---|
1108 | set _settings($this-qx) $_view(qx) |
---|
1109 | set _settings($this-qy) $_view(qy) |
---|
1110 | set _settings($this-qz) $_view(qz) |
---|
1111 | SendCmd "camera orient $q" |
---|
1112 | |
---|
1113 | set _click(x) $x |
---|
1114 | set _click(y) $y |
---|
1115 | } |
---|
1116 | } |
---|
1117 | release { |
---|
1118 | Rotate drag $x $y |
---|
1119 | $itk_component(3dview) configure -cursor "" |
---|
1120 | catch {unset _click} |
---|
1121 | } |
---|
1122 | default { |
---|
1123 | error "bad option \"$option\": should be click, drag, release" |
---|
1124 | } |
---|
1125 | } |
---|
1126 | } |
---|
1127 | |
---|
1128 | # ---------------------------------------------------------------------- |
---|
1129 | # USAGE: $this Pan click x y |
---|
1130 | # $this Pan drag x y |
---|
1131 | # $this Pan release x y |
---|
1132 | # |
---|
1133 | # Called automatically when the user clicks on one of the zoom |
---|
1134 | # controls for this widget. Changes the zoom for the current view. |
---|
1135 | # ---------------------------------------------------------------------- |
---|
1136 | itcl::body Rappture::NanovisViewer::Pan {option x y} { |
---|
1137 | # Experimental stuff |
---|
1138 | set w [winfo width $itk_component(3dview)] |
---|
1139 | set h [winfo height $itk_component(3dview)] |
---|
1140 | if { $option == "set" } { |
---|
1141 | set x [expr $x / double($w)] |
---|
1142 | set y [expr $y / double($h)] |
---|
1143 | set _view(xpan) [expr $_view(xpan) + $x] |
---|
1144 | set _view(ypan) [expr $_view(ypan) + $y] |
---|
1145 | PanCamera |
---|
1146 | set _settings($this-xpan) $_view(xpan) |
---|
1147 | set _settings($this-ypan) $_view(ypan) |
---|
1148 | return |
---|
1149 | } |
---|
1150 | if { $option == "click" } { |
---|
1151 | set _click(x) $x |
---|
1152 | set _click(y) $y |
---|
1153 | $itk_component(3dview) configure -cursor hand1 |
---|
1154 | } |
---|
1155 | if { $option == "drag" || $option == "release" } { |
---|
1156 | set dx [expr ($_click(x) - $x)/double($w)] |
---|
1157 | set dy [expr ($_click(y) - $y)/double($h)] |
---|
1158 | set _click(x) $x |
---|
1159 | set _click(y) $y |
---|
1160 | set _view(xpan) [expr $_view(xpan) - $dx] |
---|
1161 | set _view(ypan) [expr $_view(ypan) - $dy] |
---|
1162 | PanCamera |
---|
1163 | set _settings($this-xpan) $_view(xpan) |
---|
1164 | set _settings($this-ypan) $_view(ypan) |
---|
1165 | } |
---|
1166 | if { $option == "release" } { |
---|
1167 | $itk_component(3dview) configure -cursor "" |
---|
1168 | } |
---|
1169 | } |
---|
1170 | |
---|
1171 | # ---------------------------------------------------------------------- |
---|
1172 | # USAGE: InitSettings <what> ?<value>? |
---|
1173 | # |
---|
1174 | # Used internally to update rendering settings whenever parameters |
---|
1175 | # change in the popup settings panel. Sends the new settings off |
---|
1176 | # to the back end. |
---|
1177 | # ---------------------------------------------------------------------- |
---|
1178 | itcl::body Rappture::NanovisViewer::InitSettings { args } { |
---|
1179 | foreach arg $args { |
---|
1180 | AdjustSetting $arg |
---|
1181 | } |
---|
1182 | } |
---|
1183 | |
---|
1184 | # ---------------------------------------------------------------------- |
---|
1185 | # USAGE: AdjustSetting <what> ?<value>? |
---|
1186 | # |
---|
1187 | # Used internally to update rendering settings whenever parameters |
---|
1188 | # change in the popup settings panel. Sends the new settings off |
---|
1189 | # to the back end. |
---|
1190 | # ---------------------------------------------------------------------- |
---|
1191 | itcl::body Rappture::NanovisViewer::AdjustSetting {what {value ""}} { |
---|
1192 | if {![isconnected]} { |
---|
1193 | return |
---|
1194 | } |
---|
1195 | switch -- $what { |
---|
1196 | light { |
---|
1197 | set val $_settings($this-light) |
---|
1198 | set diffuse [expr {0.01*$val}] |
---|
1199 | set ambient [expr {1.0-$diffuse}] |
---|
1200 | set specularLevel 0.3 |
---|
1201 | set specularExp 90.0 |
---|
1202 | SendCmd "volume shading ambient $ambient" |
---|
1203 | SendCmd "volume shading diffuse $diffuse" |
---|
1204 | SendCmd "volume shading specularLevel $specularLevel" |
---|
1205 | SendCmd "volume shading specularExp $specularExp" |
---|
1206 | } |
---|
1207 | light2side { |
---|
1208 | set val $_settings($this-light2side) |
---|
1209 | SendCmd "volume shading light2side $val" |
---|
1210 | } |
---|
1211 | transp { |
---|
1212 | set val $_settings($this-transp) |
---|
1213 | set sval [expr { 0.01 * double($val) }] |
---|
1214 | SendCmd "volume shading opacity $sval" |
---|
1215 | } |
---|
1216 | opacity { |
---|
1217 | set val $_settings($this-opacity) |
---|
1218 | set sval [expr { 0.01 * double($val) }] |
---|
1219 | foreach tf [array names _activeTfs] { |
---|
1220 | set _settings($this-$tf-opacity) $sval |
---|
1221 | set _activeTfs($tf) 0 |
---|
1222 | } |
---|
1223 | updatetransferfuncs |
---|
1224 | } |
---|
1225 | thickness { |
---|
1226 | if { [array names _activeTfs] > 0 } { |
---|
1227 | set val $_settings($this-thickness) |
---|
1228 | # Scale values between 0.00001 and 0.01000 |
---|
1229 | set sval [expr {0.0001*double($val)}] |
---|
1230 | foreach tf [array names _activeTfs] { |
---|
1231 | set _settings($this-$tf-thickness) $sval |
---|
1232 | set _activeTfs($tf) 0 |
---|
1233 | } |
---|
1234 | updatetransferfuncs |
---|
1235 | } |
---|
1236 | } |
---|
1237 | "outline" { |
---|
1238 | SendCmd "volume outline state $_settings($this-outline)" |
---|
1239 | } |
---|
1240 | "isosurface" { |
---|
1241 | SendCmd "volume shading isosurface $_settings($this-isosurface)" |
---|
1242 | } |
---|
1243 | "colormap" { |
---|
1244 | set color [$itk_component(colormap) value] |
---|
1245 | set _settings(colormap) $color |
---|
1246 | # Only set the colormap on the first volume. Ignore the others. |
---|
1247 | #ResetColormap $color |
---|
1248 | } |
---|
1249 | "grid" { |
---|
1250 | SendCmd "grid visible $_settings($this-grid)" |
---|
1251 | } |
---|
1252 | "axes" { |
---|
1253 | SendCmd "axis visible $_settings($this-axes)" |
---|
1254 | } |
---|
1255 | "legend" { |
---|
1256 | if { $_settings($this-legend) } { |
---|
1257 | blt::table $itk_component(plotarea) \ |
---|
1258 | 0,0 $itk_component(3dview) -fill both \ |
---|
1259 | 1,0 $itk_component(legend) -fill x |
---|
1260 | blt::table configure $itk_component(plotarea) r1 -resize none |
---|
1261 | } else { |
---|
1262 | blt::table forget $itk_component(legend) |
---|
1263 | } |
---|
1264 | } |
---|
1265 | "volume" { |
---|
1266 | set datasets [CurrentDatasets -cutplanes] |
---|
1267 | SendCmd "volume data state $_settings($this-volume) $datasets" |
---|
1268 | } |
---|
1269 | "xcutplane" - "ycutplane" - "zcutplane" { |
---|
1270 | set axis [string range $what 0 0] |
---|
1271 | set bool $_settings($this-$what) |
---|
1272 | set datasets [CurrentDatasets -cutplanes] |
---|
1273 | set tag [lindex $datasets 0] |
---|
1274 | SendCmd "cutplane state $bool $axis $tag" |
---|
1275 | if { $bool } { |
---|
1276 | $itk_component(${axis}CutScale) configure -state normal \ |
---|
1277 | -troughcolor white |
---|
1278 | } else { |
---|
1279 | $itk_component(${axis}CutScale) configure -state disabled \ |
---|
1280 | -troughcolor grey82 |
---|
1281 | } |
---|
1282 | } |
---|
1283 | default { |
---|
1284 | error "don't know how to fix $what" |
---|
1285 | } |
---|
1286 | } |
---|
1287 | } |
---|
1288 | |
---|
1289 | # ---------------------------------------------------------------------- |
---|
1290 | # USAGE: FixLegend |
---|
1291 | # |
---|
1292 | # Used internally to update the legend area whenever it changes size |
---|
1293 | # or when the field changes. Asks the server to send a new legend |
---|
1294 | # for the current field. |
---|
1295 | # ---------------------------------------------------------------------- |
---|
1296 | itcl::body Rappture::NanovisViewer::FixLegend {} { |
---|
1297 | set _resizeLegendPending 0 |
---|
1298 | set lineht [font metrics $itk_option(-font) -linespace] |
---|
1299 | set w [expr {$_width-20}] |
---|
1300 | set h [expr {[winfo height $itk_component(legend)]-20-$lineht}] |
---|
1301 | if {$w > 0 && $h > 0 && [array names _activeTfs] > 0 && $_first != "" } { |
---|
1302 | set tag [lindex [CurrentDatasets] 0] |
---|
1303 | if { [info exists _dataset2style($tag)] } { |
---|
1304 | SendCmd "legend $_dataset2style($tag) $w $h" |
---|
1305 | } |
---|
1306 | } else { |
---|
1307 | # Can't do this as this will remove the items associated with the |
---|
1308 | # isomarkers. |
---|
1309 | |
---|
1310 | #$itk_component(legend) delete all |
---|
1311 | } |
---|
1312 | } |
---|
1313 | |
---|
1314 | # |
---|
1315 | # NameTransferFunc -- |
---|
1316 | # |
---|
1317 | # Creates a transfer function name based on the <style> settings in the |
---|
1318 | # library run.xml file. This placeholder will be used later to create |
---|
1319 | # and send the actual transfer function once the data info has been sent |
---|
1320 | # to us by the render server. [We won't know the volume limits until the |
---|
1321 | # server parses the 3D data and sends back the limits via ReceiveData.] |
---|
1322 | # |
---|
1323 | # FIXME: The current way we generate transfer-function names completely |
---|
1324 | # ignores the -markers option. The problem is that we are forced |
---|
1325 | # to compute the name from an increasing complex set of values: |
---|
1326 | # color, levels, marker, opacity. I think we're stuck doing it |
---|
1327 | # now. |
---|
1328 | # |
---|
1329 | itcl::body Rappture::NanovisViewer::NameTransferFunc { dataobj cname } { |
---|
1330 | array set styles { |
---|
1331 | -color BCGYR |
---|
1332 | -levels 6 |
---|
1333 | -opacity 1.0 |
---|
1334 | -markers "" |
---|
1335 | } |
---|
1336 | set tag $dataobj-$cname |
---|
1337 | array set styles [lindex [$dataobj components -style $cname] 0] |
---|
1338 | set tf "$styles(-color):$styles(-levels):$styles(-opacity)" |
---|
1339 | set _dataset2style($tag) $tf |
---|
1340 | lappend _style2datasets($tf) $tag |
---|
1341 | return $tf |
---|
1342 | } |
---|
1343 | |
---|
1344 | # |
---|
1345 | # ComputeTransferFunc -- |
---|
1346 | # |
---|
1347 | # Computes and sends the transfer function to the render server. It's |
---|
1348 | # assumed that the volume data limits are known and that the global |
---|
1349 | # transfer-functions slider values have been set up. Both parts are |
---|
1350 | # needed to compute the relative value (location) of the marker, and |
---|
1351 | # the alpha map of the transfer function. |
---|
1352 | # |
---|
1353 | itcl::body Rappture::NanovisViewer::ComputeTransferFunc { tf } { |
---|
1354 | array set styles { |
---|
1355 | -color BCGYR |
---|
1356 | -levels 6 |
---|
1357 | -opacity 1.0 |
---|
1358 | -markers "" |
---|
1359 | -alphamap "" |
---|
1360 | } |
---|
1361 | |
---|
1362 | foreach {dataobj cname} [split [lindex $_style2datasets($tf) 0] -] break |
---|
1363 | array set styles [lindex [$dataobj components -style $cname] 0] |
---|
1364 | |
---|
1365 | # We have to parse the style attributes for a volume using this |
---|
1366 | # transfer-function *once*. This sets up the initial isomarkers for the |
---|
1367 | # transfer function. The user may add/delete markers, so we have to |
---|
1368 | # maintain a list of markers for each transfer-function. We use the one |
---|
1369 | # of the volumes (the first in the list) using the transfer-function as a |
---|
1370 | # reference. |
---|
1371 | # |
---|
1372 | # FIXME: The current way we generate transfer-function names completely |
---|
1373 | # ignores the -markers option. The problem is that we are forced |
---|
1374 | # to compute the name from an increasing complex set of values: |
---|
1375 | # color, levels, marker, opacity. I think the cow's out of the |
---|
1376 | # barn on this one. |
---|
1377 | |
---|
1378 | if { ![info exists _isomarkers($tf)] } { |
---|
1379 | # Have to defer creation of isomarkers until we have data limits |
---|
1380 | if { [info exists styles(-markers)] && |
---|
1381 | [llength $styles(-markers)] > 0 } { |
---|
1382 | ParseMarkersOption $tf $styles(-markers) |
---|
1383 | } else { |
---|
1384 | ParseLevelsOption $tf $styles(-levels) |
---|
1385 | } |
---|
1386 | if { $styles(-alphamap) != "" } { |
---|
1387 | set _alphamap($cname) $styles(-alphamap) |
---|
1388 | } |
---|
1389 | } |
---|
1390 | set cmap [ColorsToColormap $styles(-color)] |
---|
1391 | set tag $this-$tf |
---|
1392 | if { ![info exists _settings($tag-opacity)] } { |
---|
1393 | set _settings($tag-opacity) $styles(-opacity) |
---|
1394 | } |
---|
1395 | set max 1.0 ;#$_settings($tag-opacity) |
---|
1396 | |
---|
1397 | set isovalues {} |
---|
1398 | foreach m $_isomarkers($tf) { |
---|
1399 | lappend isovalues [$m relval] |
---|
1400 | } |
---|
1401 | # Sort the isovalues |
---|
1402 | set isovalues [lsort -real $isovalues] |
---|
1403 | |
---|
1404 | if { ![info exists _settings($tag-thickness)]} { |
---|
1405 | set _settings($tag-thickness) 0.005 |
---|
1406 | } |
---|
1407 | set delta $_settings($tag-thickness) |
---|
1408 | |
---|
1409 | set first [lindex $isovalues 0] |
---|
1410 | set last [lindex $isovalues end] |
---|
1411 | set wmap "" |
---|
1412 | if { $first == "" || $first != 0.0 } { |
---|
1413 | lappend wmap 0.0 0.0 |
---|
1414 | } |
---|
1415 | foreach x $isovalues { |
---|
1416 | set x1 [expr {$x-$delta-0.00001}] |
---|
1417 | set x2 [expr {$x-$delta}] |
---|
1418 | set x3 [expr {$x+$delta}] |
---|
1419 | set x4 [expr {$x+$delta+0.00001}] |
---|
1420 | if { $x1 < 0.0 } { |
---|
1421 | set x1 0.0 |
---|
1422 | } elseif { $x1 > 1.0 } { |
---|
1423 | set x1 1.0 |
---|
1424 | } |
---|
1425 | if { $x2 < 0.0 } { |
---|
1426 | set x2 0.0 |
---|
1427 | } elseif { $x2 > 1.0 } { |
---|
1428 | set x2 1.0 |
---|
1429 | } |
---|
1430 | if { $x3 < 0.0 } { |
---|
1431 | set x3 0.0 |
---|
1432 | } elseif { $x3 > 1.0 } { |
---|
1433 | set x3 1.0 |
---|
1434 | } |
---|
1435 | if { $x4 < 0.0 } { |
---|
1436 | set x4 0.0 |
---|
1437 | } elseif { $x4 > 1.0 } { |
---|
1438 | set x4 1.0 |
---|
1439 | } |
---|
1440 | # add spikes in the middle |
---|
1441 | lappend wmap $x1 0.0 |
---|
1442 | lappend wmap $x2 $max |
---|
1443 | lappend wmap $x3 $max |
---|
1444 | lappend wmap $x4 0.0 |
---|
1445 | } |
---|
1446 | if { $last == "" || $last != 1.0 } { |
---|
1447 | lappend wmap 1.0 0.0 |
---|
1448 | } |
---|
1449 | if { [info exists _alphamap($cname)] } { |
---|
1450 | set wmap $_alphamap($cname) |
---|
1451 | } |
---|
1452 | SendCmd [list transfunc define $tf $cmap $wmap] |
---|
1453 | } |
---|
1454 | |
---|
1455 | # ---------------------------------------------------------------------- |
---|
1456 | # CONFIGURATION OPTION: -plotbackground |
---|
1457 | # ---------------------------------------------------------------------- |
---|
1458 | itcl::configbody Rappture::NanovisViewer::plotbackground { |
---|
1459 | if { [isconnected] } { |
---|
1460 | foreach {r g b} [Color2RGB $itk_option(-plotbackground)] break |
---|
1461 | #fix this! |
---|
1462 | #SendCmd "color background $r $g $b" |
---|
1463 | } |
---|
1464 | } |
---|
1465 | |
---|
1466 | # ---------------------------------------------------------------------- |
---|
1467 | # CONFIGURATION OPTION: -plotforeground |
---|
1468 | # ---------------------------------------------------------------------- |
---|
1469 | itcl::configbody Rappture::NanovisViewer::plotforeground { |
---|
1470 | if { [isconnected] } { |
---|
1471 | foreach {r g b} [Color2RGB $itk_option(-plotforeground)] break |
---|
1472 | #fix this! |
---|
1473 | #SendCmd "color background $r $g $b" |
---|
1474 | } |
---|
1475 | } |
---|
1476 | |
---|
1477 | # ---------------------------------------------------------------------- |
---|
1478 | # CONFIGURATION OPTION: -plotoutline |
---|
1479 | # ---------------------------------------------------------------------- |
---|
1480 | itcl::configbody Rappture::NanovisViewer::plotoutline { |
---|
1481 | # Must check if we are connected because this routine is called from the |
---|
1482 | # class body when the -plotoutline itk_option is defined. At that point |
---|
1483 | # the NanovisViewer class constructor hasn't been called, so we can't |
---|
1484 | # start sending commands to visualization server. |
---|
1485 | if { [isconnected] } { |
---|
1486 | if {"" == $itk_option(-plotoutline)} { |
---|
1487 | SendCmd "volume outline state off" |
---|
1488 | } else { |
---|
1489 | SendCmd "volume outline state on" |
---|
1490 | SendCmd "volume outline color [Color2RGB $itk_option(-plotoutline)]" |
---|
1491 | } |
---|
1492 | } |
---|
1493 | } |
---|
1494 | |
---|
1495 | # |
---|
1496 | # The -levels option takes a single value that represents the number |
---|
1497 | # of evenly distributed markers based on the current data range. Each |
---|
1498 | # marker is a relative value from 0.0 to 1.0. |
---|
1499 | # |
---|
1500 | itcl::body Rappture::NanovisViewer::ParseLevelsOption { tf levels } { |
---|
1501 | set c $itk_component(legend) |
---|
1502 | regsub -all "," $levels " " levels |
---|
1503 | if {[string is int $levels]} { |
---|
1504 | for {set i 1} { $i <= $levels } {incr i} { |
---|
1505 | set x [expr {double($i)/($levels+1)}] |
---|
1506 | set m [Rappture::IsoMarker \#auto $c $this $tf] |
---|
1507 | $m relval $x |
---|
1508 | lappend _isomarkers($tf) $m |
---|
1509 | } |
---|
1510 | } else { |
---|
1511 | foreach x $levels { |
---|
1512 | set m [Rappture::IsoMarker \#auto $c $this $tf] |
---|
1513 | $m relval $x |
---|
1514 | lappend _isomarkers($tf) $m |
---|
1515 | } |
---|
1516 | } |
---|
1517 | } |
---|
1518 | |
---|
1519 | # |
---|
1520 | # The -markers option takes a list of zero or more values (the values |
---|
1521 | # may be separated either by spaces or commas) that have the following |
---|
1522 | # format: |
---|
1523 | # |
---|
1524 | # N% Percent of current total data range. Converted to |
---|
1525 | # to a relative value between 0.0 and 1.0. |
---|
1526 | # N Absolute value of marker. If the marker is outside of |
---|
1527 | # the current range, it will be displayed on the outer |
---|
1528 | # edge of the legends, but it range it represents will |
---|
1529 | # not be seen. |
---|
1530 | # |
---|
1531 | itcl::body Rappture::NanovisViewer::ParseMarkersOption { tf markers } { |
---|
1532 | set c $itk_component(legend) |
---|
1533 | regsub -all "," $markers " " markers |
---|
1534 | foreach marker $markers { |
---|
1535 | set n [scan $marker "%g%s" value suffix] |
---|
1536 | if { $n == 2 && $suffix == "%" } { |
---|
1537 | # ${n}% : Set relative value. |
---|
1538 | set value [expr {$value * 0.01}] |
---|
1539 | set m [Rappture::IsoMarker \#auto $c $this $tf] |
---|
1540 | $m relval $value |
---|
1541 | lappend _isomarkers($tf) $m |
---|
1542 | } else { |
---|
1543 | # ${n} : Set absolute value. |
---|
1544 | set m [Rappture::IsoMarker \#auto $c $this $tf] |
---|
1545 | $m absval $value |
---|
1546 | lappend _isomarkers($tf) $m |
---|
1547 | } |
---|
1548 | } |
---|
1549 | } |
---|
1550 | |
---|
1551 | # ---------------------------------------------------------------------- |
---|
1552 | # USAGE: UndateTransferFuncs |
---|
1553 | # ---------------------------------------------------------------------- |
---|
1554 | itcl::body Rappture::NanovisViewer::updatetransferfuncs {} { |
---|
1555 | $_dispatcher event -idle !send_transfunc |
---|
1556 | } |
---|
1557 | |
---|
1558 | itcl::body Rappture::NanovisViewer::AddIsoMarker { x y } { |
---|
1559 | if { $_first == "" } { |
---|
1560 | error "active transfer function isn't set" |
---|
1561 | } |
---|
1562 | set tag [lindex [CurrentDatasets] 0] |
---|
1563 | set tf $_dataset2style($tag) |
---|
1564 | set c $itk_component(legend) |
---|
1565 | set m [Rappture::IsoMarker \#auto $c $this $tf] |
---|
1566 | set w [winfo width $c] |
---|
1567 | $m relval [expr {double($x-10)/($w-20)}] |
---|
1568 | lappend _isomarkers($tf) $m |
---|
1569 | updatetransferfuncs |
---|
1570 | return 1 |
---|
1571 | } |
---|
1572 | |
---|
1573 | itcl::body Rappture::NanovisViewer::rmdupmarker { marker x } { |
---|
1574 | set tf [$marker transferfunc] |
---|
1575 | set bool 0 |
---|
1576 | if { [info exists _isomarkers($tf)] } { |
---|
1577 | set list {} |
---|
1578 | set marker [namespace tail $marker] |
---|
1579 | foreach m $_isomarkers($tf) { |
---|
1580 | set sx [$m screenpos] |
---|
1581 | if { $m != $marker } { |
---|
1582 | if { $x >= ($sx-3) && $x <= ($sx+3) } { |
---|
1583 | $marker relval [$m relval] |
---|
1584 | itcl::delete object $m |
---|
1585 | bell |
---|
1586 | set bool 1 |
---|
1587 | continue |
---|
1588 | } |
---|
1589 | } |
---|
1590 | lappend list $m |
---|
1591 | } |
---|
1592 | set _isomarkers($tf) $list |
---|
1593 | updatetransferfuncs |
---|
1594 | } |
---|
1595 | return $bool |
---|
1596 | } |
---|
1597 | |
---|
1598 | itcl::body Rappture::NanovisViewer::overmarker { marker x } { |
---|
1599 | set tf [$marker transferfunc] |
---|
1600 | if { [info exists _isomarkers($tf)] } { |
---|
1601 | set marker [namespace tail $marker] |
---|
1602 | foreach m $_isomarkers($tf) { |
---|
1603 | set sx [$m screenpos] |
---|
1604 | if { $m != $marker } { |
---|
1605 | set bool [expr { $x >= ($sx-3) && $x <= ($sx+3) }] |
---|
1606 | $m activate $bool |
---|
1607 | } |
---|
1608 | } |
---|
1609 | } |
---|
1610 | return "" |
---|
1611 | } |
---|
1612 | |
---|
1613 | itcl::body Rappture::NanovisViewer::limits { tf } { |
---|
1614 | set _limits(min) 0.0 |
---|
1615 | set _limits(max) 1.0 |
---|
1616 | if { ![info exists _style2datasets($tf)] } { |
---|
1617 | return [array get _limits] |
---|
1618 | } |
---|
1619 | set min ""; set max "" |
---|
1620 | foreach tag $_style2datasets($tf) { |
---|
1621 | if { ![info exists _serverDatasets($tag)] } { |
---|
1622 | continue |
---|
1623 | } |
---|
1624 | if { ![info exists _limits($tag-min)] } { |
---|
1625 | continue |
---|
1626 | } |
---|
1627 | if { $min == "" || $min > $_limits($tag-min) } { |
---|
1628 | set min $_limits($tag-min) |
---|
1629 | } |
---|
1630 | if { $max == "" || $max < $_limits($tag-max) } { |
---|
1631 | set max $_limits($tag-max) |
---|
1632 | } |
---|
1633 | } |
---|
1634 | if { $min != "" } { |
---|
1635 | set _limits(min) $min |
---|
1636 | } |
---|
1637 | if { $max != "" } { |
---|
1638 | set _limits(max) $max |
---|
1639 | } |
---|
1640 | return [array get _limits] |
---|
1641 | } |
---|
1642 | |
---|
1643 | |
---|
1644 | itcl::body Rappture::NanovisViewer::BuildViewTab {} { |
---|
1645 | foreach { key value } { |
---|
1646 | grid 0 |
---|
1647 | axes 1 |
---|
1648 | outline 0 |
---|
1649 | volume 1 |
---|
1650 | legend 1 |
---|
1651 | particles 1 |
---|
1652 | lic 1 |
---|
1653 | } { |
---|
1654 | set _settings($this-$key) $value |
---|
1655 | } |
---|
1656 | |
---|
1657 | set fg [option get $itk_component(hull) font Font] |
---|
1658 | #set bfg [option get $itk_component(hull) boldFont Font] |
---|
1659 | |
---|
1660 | set inner [$itk_component(main) insert end \ |
---|
1661 | -title "View Settings" \ |
---|
1662 | -icon [Rappture::icon wrench]] |
---|
1663 | $inner configure -borderwidth 4 |
---|
1664 | |
---|
1665 | set ::Rappture::NanovisViewer::_settings($this-isosurface) 0 |
---|
1666 | checkbutton $inner.isosurface \ |
---|
1667 | -text "Isosurface shading" \ |
---|
1668 | -variable [itcl::scope _settings($this-isosurface)] \ |
---|
1669 | -command [itcl::code $this AdjustSetting isosurface] \ |
---|
1670 | -font "Arial 9" |
---|
1671 | |
---|
1672 | checkbutton $inner.axes \ |
---|
1673 | -text "Axes" \ |
---|
1674 | -variable [itcl::scope _settings($this-axes)] \ |
---|
1675 | -command [itcl::code $this AdjustSetting axes] \ |
---|
1676 | -font "Arial 9" |
---|
1677 | |
---|
1678 | checkbutton $inner.grid \ |
---|
1679 | -text "Grid" \ |
---|
1680 | -variable [itcl::scope _settings($this-grid)] \ |
---|
1681 | -command [itcl::code $this AdjustSetting grid] \ |
---|
1682 | -font "Arial 9" |
---|
1683 | |
---|
1684 | checkbutton $inner.outline \ |
---|
1685 | -text "Outline" \ |
---|
1686 | -variable [itcl::scope _settings($this-outline)] \ |
---|
1687 | -command [itcl::code $this AdjustSetting outline] \ |
---|
1688 | -font "Arial 9" |
---|
1689 | |
---|
1690 | checkbutton $inner.legend \ |
---|
1691 | -text "Legend" \ |
---|
1692 | -variable [itcl::scope _settings($this-legend)] \ |
---|
1693 | -command [itcl::code $this AdjustSetting legend] \ |
---|
1694 | -font "Arial 9" |
---|
1695 | |
---|
1696 | checkbutton $inner.volume \ |
---|
1697 | -text "Volume" \ |
---|
1698 | -variable [itcl::scope _settings($this-volume)] \ |
---|
1699 | -command [itcl::code $this AdjustSetting volume] \ |
---|
1700 | -font "Arial 9" |
---|
1701 | |
---|
1702 | blt::table $inner \ |
---|
1703 | 0,0 $inner.axes -cspan 2 -anchor w \ |
---|
1704 | 1,0 $inner.grid -cspan 2 -anchor w \ |
---|
1705 | 2,0 $inner.outline -cspan 2 -anchor w \ |
---|
1706 | 3,0 $inner.volume -cspan 2 -anchor w \ |
---|
1707 | 4,0 $inner.legend -cspan 2 -anchor w |
---|
1708 | |
---|
1709 | if 0 { |
---|
1710 | bind $inner <Map> [itcl::code $this GetVolumeInfo $inner] |
---|
1711 | } |
---|
1712 | blt::table configure $inner r* -resize none |
---|
1713 | blt::table configure $inner r5 -resize expand |
---|
1714 | } |
---|
1715 | |
---|
1716 | itcl::body Rappture::NanovisViewer::BuildVolumeTab {} { |
---|
1717 | foreach { key value } { |
---|
1718 | light2side 1 |
---|
1719 | light 40 |
---|
1720 | transp 50 |
---|
1721 | opacity 100 |
---|
1722 | thickness 350 |
---|
1723 | } { |
---|
1724 | set _settings($this-$key) $value |
---|
1725 | } |
---|
1726 | |
---|
1727 | set inner [$itk_component(main) insert end \ |
---|
1728 | -title "Volume Settings" \ |
---|
1729 | -icon [Rappture::icon volume-on]] |
---|
1730 | $inner configure -borderwidth 4 |
---|
1731 | |
---|
1732 | set fg [option get $itk_component(hull) font Font] |
---|
1733 | #set bfg [option get $itk_component(hull) boldFont Font] |
---|
1734 | |
---|
1735 | checkbutton $inner.vol -text "Show volume" -font $fg \ |
---|
1736 | -variable [itcl::scope _settings($this-volume)] \ |
---|
1737 | -command [itcl::code $this AdjustSetting volume] |
---|
1738 | label $inner.shading -text "Shading:" -font $fg |
---|
1739 | |
---|
1740 | checkbutton $inner.light2side -text "Two-sided lighting" -font $fg \ |
---|
1741 | -variable [itcl::scope _settings($this-light2side)] \ |
---|
1742 | -command [itcl::code $this AdjustSetting light2side] |
---|
1743 | |
---|
1744 | label $inner.dim -text "Glow" -font $fg |
---|
1745 | ::scale $inner.light -from 0 -to 100 -orient horizontal \ |
---|
1746 | -variable [itcl::scope _settings($this-light)] \ |
---|
1747 | -width 10 \ |
---|
1748 | -showvalue off -command [itcl::code $this AdjustSetting light] |
---|
1749 | label $inner.bright -text "Surface" -font $fg |
---|
1750 | |
---|
1751 | label $inner.fog -text "Clear" -font $fg |
---|
1752 | ::scale $inner.transp -from 0 -to 100 -orient horizontal \ |
---|
1753 | -variable [itcl::scope _settings($this-transp)] \ |
---|
1754 | -width 10 \ |
---|
1755 | -showvalue off -command [itcl::code $this AdjustSetting transp] |
---|
1756 | label $inner.plastic -text "Opaque" -font $fg |
---|
1757 | |
---|
1758 | label $inner.clear -text "Clear" -font $fg |
---|
1759 | ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ |
---|
1760 | -variable [itcl::scope _settings($this-opacity)] \ |
---|
1761 | -width 10 \ |
---|
1762 | -showvalue off -command [itcl::code $this AdjustSetting opacity] |
---|
1763 | label $inner.opaque -text "Opaque" -font $fg |
---|
1764 | |
---|
1765 | label $inner.thin -text "Thin" -font $fg |
---|
1766 | ::scale $inner.thickness -from 0 -to 1000 -orient horizontal \ |
---|
1767 | -variable [itcl::scope _settings($this-thickness)] \ |
---|
1768 | -width 10 \ |
---|
1769 | -showvalue off -command [itcl::code $this AdjustSetting thickness] |
---|
1770 | label $inner.thick -text "Thick" -font $fg |
---|
1771 | |
---|
1772 | label $inner.colormap_l -text "Colormap" -font "Arial 9" |
---|
1773 | itk_component add colormap { |
---|
1774 | Rappture::Combobox $inner.colormap -width 10 -editable no |
---|
1775 | } |
---|
1776 | |
---|
1777 | $inner.colormap choices insert end [GetColormapList -includeNone] |
---|
1778 | $itk_component(colormap) value "BCGYR" |
---|
1779 | bind $inner.colormap <<Value>> \ |
---|
1780 | [itcl::code $this AdjustSetting colormap] |
---|
1781 | |
---|
1782 | blt::table $inner \ |
---|
1783 | 0,0 $inner.vol -cspan 4 -anchor w -pady 2 \ |
---|
1784 | 1,0 $inner.shading -cspan 4 -anchor w -pady {10 2} \ |
---|
1785 | 2,0 $inner.light2side -cspan 4 -anchor w -pady 2 \ |
---|
1786 | 3,0 $inner.dim -anchor e -pady 2 \ |
---|
1787 | 3,1 $inner.light -cspan 2 -pady 2 -fill x \ |
---|
1788 | 3,3 $inner.bright -anchor w -pady 2 \ |
---|
1789 | 4,0 $inner.fog -anchor e -pady 2 \ |
---|
1790 | 4,1 $inner.transp -cspan 2 -pady 2 -fill x \ |
---|
1791 | 4,3 $inner.plastic -anchor w -pady 2 \ |
---|
1792 | 5,0 $inner.thin -anchor e -pady 2 \ |
---|
1793 | 5,1 $inner.thickness -cspan 2 -pady 2 -fill x\ |
---|
1794 | 5,3 $inner.thick -anchor w -pady 2 |
---|
1795 | |
---|
1796 | blt::table configure $inner c0 c1 c3 r* -resize none |
---|
1797 | blt::table configure $inner r6 -resize expand |
---|
1798 | } |
---|
1799 | |
---|
1800 | itcl::body Rappture::NanovisViewer::BuildCutplanesTab {} { |
---|
1801 | set inner [$itk_component(main) insert end \ |
---|
1802 | -title "Cutplane Settings" \ |
---|
1803 | -icon [Rappture::icon cutbutton]] |
---|
1804 | $inner configure -borderwidth 4 |
---|
1805 | |
---|
1806 | # X-value slicer... |
---|
1807 | itk_component add xCutButton { |
---|
1808 | Rappture::PushButton $inner.xbutton \ |
---|
1809 | -onimage [Rappture::icon x-cutplane] \ |
---|
1810 | -offimage [Rappture::icon x-cutplane] \ |
---|
1811 | -command [itcl::code $this AdjustSetting xcutplane] \ |
---|
1812 | -variable [itcl::scope _settings($this-xcutplane)] |
---|
1813 | } |
---|
1814 | Rappture::Tooltip::for $itk_component(xCutButton) \ |
---|
1815 | "Toggle the X cut plane on/off" |
---|
1816 | |
---|
1817 | itk_component add xCutScale { |
---|
1818 | ::scale $inner.xval -from 100 -to 0 \ |
---|
1819 | -width 10 -orient vertical -showvalue off \ |
---|
1820 | -borderwidth 1 -highlightthickness 0 \ |
---|
1821 | -command [itcl::code $this Slice move x] \ |
---|
1822 | -variable [itcl::scope _settings($this-xcutposition)] |
---|
1823 | } { |
---|
1824 | usual |
---|
1825 | ignore -borderwidth -highlightthickness |
---|
1826 | } |
---|
1827 | # Set the default cutplane value before disabling the scale. |
---|
1828 | $itk_component(xCutScale) set 50 |
---|
1829 | $itk_component(xCutScale) configure -state disabled |
---|
1830 | Rappture::Tooltip::for $itk_component(xCutScale) \ |
---|
1831 | "@[itcl::code $this SlicerTip x]" |
---|
1832 | |
---|
1833 | # Y-value slicer... |
---|
1834 | itk_component add yCutButton { |
---|
1835 | Rappture::PushButton $inner.ybutton \ |
---|
1836 | -onimage [Rappture::icon y-cutplane] \ |
---|
1837 | -offimage [Rappture::icon y-cutplane] \ |
---|
1838 | -command [itcl::code $this AdjustSetting ycutplane] \ |
---|
1839 | -variable [itcl::scope _settings($this-ycutplane)] |
---|
1840 | } |
---|
1841 | Rappture::Tooltip::for $itk_component(yCutButton) \ |
---|
1842 | "Toggle the Y cut plane on/off" |
---|
1843 | |
---|
1844 | itk_component add yCutScale { |
---|
1845 | ::scale $inner.yval -from 100 -to 0 \ |
---|
1846 | -width 10 -orient vertical -showvalue off \ |
---|
1847 | -borderwidth 1 -highlightthickness 0 \ |
---|
1848 | -command [itcl::code $this Slice move y] \ |
---|
1849 | -variable [itcl::scope _settings($this-ycutposition)] |
---|
1850 | } { |
---|
1851 | usual |
---|
1852 | ignore -borderwidth -highlightthickness |
---|
1853 | } |
---|
1854 | Rappture::Tooltip::for $itk_component(yCutScale) \ |
---|
1855 | "@[itcl::code $this SlicerTip y]" |
---|
1856 | # Set the default cutplane value before disabling the scale. |
---|
1857 | $itk_component(yCutScale) set 50 |
---|
1858 | $itk_component(yCutScale) configure -state disabled |
---|
1859 | |
---|
1860 | # Z-value slicer... |
---|
1861 | itk_component add zCutButton { |
---|
1862 | Rappture::PushButton $inner.zbutton \ |
---|
1863 | -onimage [Rappture::icon z-cutplane] \ |
---|
1864 | -offimage [Rappture::icon z-cutplane] \ |
---|
1865 | -command [itcl::code $this AdjustSetting zcutplane] \ |
---|
1866 | -variable [itcl::scope _settings($this-zcutplane)] |
---|
1867 | } |
---|
1868 | Rappture::Tooltip::for $itk_component(zCutButton) \ |
---|
1869 | "Toggle the Z cut plane on/off" |
---|
1870 | |
---|
1871 | itk_component add zCutScale { |
---|
1872 | ::scale $inner.zval -from 100 -to 0 \ |
---|
1873 | -width 10 -orient vertical -showvalue off \ |
---|
1874 | -borderwidth 1 -highlightthickness 0 \ |
---|
1875 | -command [itcl::code $this Slice move z] \ |
---|
1876 | -variable [itcl::scope _settings($this-zcutposition)] |
---|
1877 | } { |
---|
1878 | usual |
---|
1879 | ignore -borderwidth -highlightthickness |
---|
1880 | } |
---|
1881 | $itk_component(zCutScale) set 50 |
---|
1882 | $itk_component(zCutScale) configure -state disabled |
---|
1883 | #$itk_component(zCutScale) configure -state disabled |
---|
1884 | Rappture::Tooltip::for $itk_component(zCutScale) \ |
---|
1885 | "@[itcl::code $this SlicerTip z]" |
---|
1886 | |
---|
1887 | blt::table $inner \ |
---|
1888 | 1,1 $itk_component(xCutButton) \ |
---|
1889 | 1,2 $itk_component(yCutButton) \ |
---|
1890 | 1,3 $itk_component(zCutButton) \ |
---|
1891 | 0,1 $itk_component(xCutScale) \ |
---|
1892 | 0,2 $itk_component(yCutScale) \ |
---|
1893 | 0,3 $itk_component(zCutScale) |
---|
1894 | |
---|
1895 | blt::table configure $inner r0 r1 c* -resize none |
---|
1896 | blt::table configure $inner r2 c4 -resize expand |
---|
1897 | blt::table configure $inner c0 -width 2 |
---|
1898 | blt::table configure $inner c1 c2 c3 -padx 2 |
---|
1899 | } |
---|
1900 | |
---|
1901 | itcl::body Rappture::NanovisViewer::BuildCameraTab {} { |
---|
1902 | set inner [$itk_component(main) insert end \ |
---|
1903 | -title "Camera Settings" \ |
---|
1904 | -icon [Rappture::icon camera]] |
---|
1905 | $inner configure -borderwidth 4 |
---|
1906 | |
---|
1907 | label $inner.view_l -text "view" -font "Arial 9" |
---|
1908 | set f [frame $inner.view] |
---|
1909 | foreach side { front back left right top bottom } { |
---|
1910 | button $f.$side -image [Rappture::icon view$side] \ |
---|
1911 | -command [itcl::code $this SetOrientation $side] |
---|
1912 | Rappture::Tooltip::for $f.$side "Change the view to $side" |
---|
1913 | pack $f.$side -side left |
---|
1914 | } |
---|
1915 | |
---|
1916 | blt::table $inner \ |
---|
1917 | 0,0 $inner.view_l -anchor e -pady 2 \ |
---|
1918 | 0,1 $inner.view -anchor w -pady 2 |
---|
1919 | |
---|
1920 | set row 1 |
---|
1921 | set labels { qw qx qy qz xpan ypan zoom } |
---|
1922 | foreach tag $labels { |
---|
1923 | label $inner.${tag}label -text $tag -font "Arial 9" |
---|
1924 | entry $inner.${tag} -font "Arial 9" -bg white \ |
---|
1925 | -textvariable [itcl::scope _settings($this-$tag)] |
---|
1926 | bind $inner.${tag} <Return> \ |
---|
1927 | [itcl::code $this camera set ${tag}] |
---|
1928 | bind $inner.${tag} <KP_Enter> \ |
---|
1929 | [itcl::code $this camera set ${tag}] |
---|
1930 | blt::table $inner \ |
---|
1931 | $row,0 $inner.${tag}label -anchor e -pady 2 \ |
---|
1932 | $row,1 $inner.${tag} -anchor w -pady 2 |
---|
1933 | blt::table configure $inner r$row -resize none |
---|
1934 | incr row |
---|
1935 | } |
---|
1936 | |
---|
1937 | blt::table configure $inner c* r* -resize none |
---|
1938 | blt::table configure $inner c2 -resize expand |
---|
1939 | blt::table configure $inner r$row -resize expand |
---|
1940 | } |
---|
1941 | |
---|
1942 | # ---------------------------------------------------------------------- |
---|
1943 | # USAGE: Slice move x|y|z <newval> |
---|
1944 | # |
---|
1945 | # Called automatically when the user drags the slider to move the |
---|
1946 | # cut plane that slices 3D data. Gets the current value from the |
---|
1947 | # slider and moves the cut plane to the appropriate point in the |
---|
1948 | # data set. |
---|
1949 | # ---------------------------------------------------------------------- |
---|
1950 | itcl::body Rappture::NanovisViewer::Slice {option args} { |
---|
1951 | switch -- $option { |
---|
1952 | move { |
---|
1953 | if {[llength $args] != 2} { |
---|
1954 | error "wrong # args: should be \"Slice move x|y|z newval\"" |
---|
1955 | } |
---|
1956 | set axis [lindex $args 0] |
---|
1957 | set newval [lindex $args 1] |
---|
1958 | |
---|
1959 | set newpos [expr {0.01*$newval}] |
---|
1960 | set datasets [CurrentDatasets -cutplanes] |
---|
1961 | set tag [lindex $datasets 0] |
---|
1962 | SendCmd "cutplane position $newpos $axis $tag" |
---|
1963 | } |
---|
1964 | default { |
---|
1965 | error "bad option \"$option\": should be axis, move, or volume" |
---|
1966 | } |
---|
1967 | } |
---|
1968 | } |
---|
1969 | |
---|
1970 | # ---------------------------------------------------------------------- |
---|
1971 | # USAGE: SlicerTip <axis> |
---|
1972 | # |
---|
1973 | # Used internally to generate a tooltip for the x/y/z slicer controls. |
---|
1974 | # Returns a message that includes the current slicer value. |
---|
1975 | # ---------------------------------------------------------------------- |
---|
1976 | itcl::body Rappture::NanovisViewer::SlicerTip {axis} { |
---|
1977 | set val [$itk_component(${axis}CutScale) get] |
---|
1978 | # set val [expr {0.01*($val-50) |
---|
1979 | # *($_limits(${axis}max)-$_limits(${axis}min)) |
---|
1980 | # + 0.5*($_limits(${axis}max)+$_limits(${axis}min))}] |
---|
1981 | return "Move the [string toupper $axis] cut plane.\nCurrently: $axis = $val%" |
---|
1982 | } |
---|
1983 | |
---|
1984 | |
---|
1985 | itcl::body Rappture::NanovisViewer::DoResize {} { |
---|
1986 | $_arcball resize $_width $_height |
---|
1987 | SendCmd "screen size $_width $_height" |
---|
1988 | set _resizePending 0 |
---|
1989 | } |
---|
1990 | |
---|
1991 | itcl::body Rappture::NanovisViewer::EventuallyResize { w h } { |
---|
1992 | set _width $w |
---|
1993 | set _height $h |
---|
1994 | $_arcball resize $w $h |
---|
1995 | if { !$_resizePending } { |
---|
1996 | $_dispatcher event -idle !resize |
---|
1997 | set _resizePending 1 |
---|
1998 | } |
---|
1999 | } |
---|
2000 | |
---|
2001 | itcl::body Rappture::NanovisViewer::EventuallyResizeLegend {} { |
---|
2002 | if { !$_resizeLegendPending } { |
---|
2003 | $_dispatcher event -idle !legend |
---|
2004 | set _resizeLegendPending 1 |
---|
2005 | } |
---|
2006 | } |
---|
2007 | |
---|
2008 | # camera -- |
---|
2009 | # |
---|
2010 | itcl::body Rappture::NanovisViewer::camera {option args} { |
---|
2011 | switch -- $option { |
---|
2012 | "show" { |
---|
2013 | puts [array get _view] |
---|
2014 | } |
---|
2015 | "set" { |
---|
2016 | set who [lindex $args 0] |
---|
2017 | set x $_settings($this-$who) |
---|
2018 | set code [catch { string is double $x } result] |
---|
2019 | if { $code != 0 || !$result } { |
---|
2020 | set _settings($this-$who) $_view($who) |
---|
2021 | return |
---|
2022 | } |
---|
2023 | switch -- $who { |
---|
2024 | "xpan" - "ypan" { |
---|
2025 | set _view($who) $_settings($this-$who) |
---|
2026 | PanCamera |
---|
2027 | } |
---|
2028 | "qx" - "qy" - "qz" - "qw" { |
---|
2029 | set _view($who) $_settings($this-$who) |
---|
2030 | set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] |
---|
2031 | $_arcball quaternion $q |
---|
2032 | SendCmd "camera orient $q" |
---|
2033 | } |
---|
2034 | "zoom" { |
---|
2035 | set _view($who) $_settings($this-$who) |
---|
2036 | SendCmd "camera zoom $_view(zoom)" |
---|
2037 | } |
---|
2038 | } |
---|
2039 | } |
---|
2040 | } |
---|
2041 | } |
---|
2042 | |
---|
2043 | itcl::body Rappture::NanovisViewer::GetVolumeInfo { w } { |
---|
2044 | set flowobj "" |
---|
2045 | foreach key [array names _obj2flow] { |
---|
2046 | set flowobj $_obj2flow($key) |
---|
2047 | break |
---|
2048 | } |
---|
2049 | if { $flowobj == "" } { |
---|
2050 | return |
---|
2051 | } |
---|
2052 | if { [winfo exists $w.frame] } { |
---|
2053 | destroy $w.frame |
---|
2054 | } |
---|
2055 | set inner [frame $w.frame] |
---|
2056 | blt::table $w \ |
---|
2057 | 5,0 $inner -fill both -cspan 2 -anchor nw |
---|
2058 | array set hints [$dataobj hints] |
---|
2059 | |
---|
2060 | label $inner.volumes -text "Volumes" -font "Arial 9 bold" |
---|
2061 | blt::table $inner \ |
---|
2062 | 1,0 $inner.volumes -anchor w \ |
---|
2063 | blt::table configure $inner c0 c1 -resize none |
---|
2064 | blt::table configure $inner c2 -resize expand |
---|
2065 | |
---|
2066 | set row 3 |
---|
2067 | set volumes [get] |
---|
2068 | if { [llength $volumes] > 0 } { |
---|
2069 | blt::table $inner $row,0 $inner.volumes -anchor w |
---|
2070 | incr row |
---|
2071 | } |
---|
2072 | foreach vol $volumes { |
---|
2073 | array unset info |
---|
2074 | array set info $vol |
---|
2075 | set name $info(name) |
---|
2076 | if { ![info exists _settings($this-volume-$name)] } { |
---|
2077 | set _settings($this-volume-$name) $info(hide) |
---|
2078 | } |
---|
2079 | checkbutton $inner.vol$row -text $info(label) \ |
---|
2080 | -variable [itcl::scope _settings($this-volume-$name)] \ |
---|
2081 | -onvalue 0 -offvalue 1 \ |
---|
2082 | -command [itcl::code $this volume $key $name] \ |
---|
2083 | -font "Arial 9" |
---|
2084 | Rappture::Tooltip::for $inner.vol$row $info(description) |
---|
2085 | blt::table $inner $row,0 $inner.vol$row -anchor w |
---|
2086 | if { !$_settings($this-volume-$name) } { |
---|
2087 | $inner.vol$row select |
---|
2088 | } |
---|
2089 | incr row |
---|
2090 | } |
---|
2091 | blt::table configure $inner r* -resize none |
---|
2092 | blt::table configure $inner r$row -resize expand |
---|
2093 | blt::table configure $inner c3 -resize expand |
---|
2094 | event generate [winfo parent [winfo parent $w]] <Configure> |
---|
2095 | } |
---|
2096 | |
---|
2097 | itcl::body Rappture::NanovisViewer::volume { tag name } { |
---|
2098 | set bool $_settings($this-volume-$name) |
---|
2099 | SendCmd "volume statue $bool $name" |
---|
2100 | } |
---|
2101 | |
---|
2102 | itcl::body Rappture::NanovisViewer::SetOrientation { side } { |
---|
2103 | array set positions { |
---|
2104 | front "1 0 0 0" |
---|
2105 | back "0 0 1 0" |
---|
2106 | left "0.707107 0 -0.707107 0" |
---|
2107 | right "0.707107 0 0.707107 0" |
---|
2108 | top "0.707107 -0.707107 0 0" |
---|
2109 | bottom "0.707107 0.707107 0 0" |
---|
2110 | } |
---|
2111 | foreach name { qw qx qy qz } value $positions($side) { |
---|
2112 | set _view($name) $value |
---|
2113 | } |
---|
2114 | set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] |
---|
2115 | $_arcball quaternion $q |
---|
2116 | SendCmd "camera orient $q" |
---|
2117 | SendCmd "camera reset" |
---|
2118 | set _view(xpan) 0 |
---|
2119 | set _view(ypan) 0 |
---|
2120 | set _view(zoom) 1.0 |
---|
2121 | set _settings($this-xpan) $_view(xpan) |
---|
2122 | set _settings($this-ypan) $_view(ypan) |
---|
2123 | set _settings($this-zoom) $_view(zoom) |
---|
2124 | } |
---|
2125 | |
---|