[3330] | 1 | # -*- mode: tcl; indent-tabs-mode: nil -*- |
---|
[2504] | 2 | # ---------------------------------------------------------------------- |
---|
| 3 | # COMPONENT: vtkviewer - Vtk drawing object viewer |
---|
| 4 | # |
---|
| 5 | # It connects to the Vtk server running on a rendering farm, |
---|
| 6 | # transmits data, and displays the results. |
---|
| 7 | # ====================================================================== |
---|
| 8 | # AUTHOR: Michael McLennan, Purdue University |
---|
[3177] | 9 | # Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
[2504] | 10 | # |
---|
| 11 | # See the file "license.terms" for information on usage and |
---|
| 12 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
| 13 | # ====================================================================== |
---|
| 14 | package require Itk |
---|
| 15 | package require BLT |
---|
[2743] | 16 | package require Img |
---|
[2504] | 17 | |
---|
| 18 | option add *VtkStreamlinesViewer.width 4i widgetDefault |
---|
| 19 | option add *VtkStreamlinesViewer*cursor crosshair widgetDefault |
---|
| 20 | option add *VtkStreamlinesViewer.height 4i widgetDefault |
---|
| 21 | option add *VtkStreamlinesViewer.foreground black widgetDefault |
---|
| 22 | option add *VtkStreamlinesViewer.controlBackground gray widgetDefault |
---|
| 23 | option add *VtkStreamlinesViewer.controlDarkBackground #999999 widgetDefault |
---|
| 24 | option add *VtkStreamlinesViewer.plotBackground black widgetDefault |
---|
| 25 | option add *VtkStreamlinesViewer.plotForeground white widgetDefault |
---|
| 26 | option add *VtkStreamlinesViewer.font \ |
---|
| 27 | -*-helvetica-medium-r-normal-*-12-* widgetDefault |
---|
| 28 | |
---|
| 29 | # must use this name -- plugs into Rappture::resources::load |
---|
| 30 | proc VtkStreamlinesViewer_init_resources {} { |
---|
| 31 | Rappture::resources::register \ |
---|
| 32 | vtkvis_server Rappture::VtkStreamlinesViewer::SetServerList |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | itcl::class Rappture::VtkStreamlinesViewer { |
---|
| 36 | inherit Rappture::VisViewer |
---|
| 37 | |
---|
| 38 | itk_option define -plotforeground plotForeground Foreground "" |
---|
| 39 | itk_option define -plotbackground plotBackground Background "" |
---|
| 40 | |
---|
| 41 | constructor { hostlist args } { |
---|
| 42 | Rappture::VisViewer::constructor $hostlist |
---|
| 43 | } { |
---|
| 44 | # defined below |
---|
| 45 | } |
---|
| 46 | destructor { |
---|
| 47 | # defined below |
---|
| 48 | } |
---|
| 49 | public proc SetServerList { namelist } { |
---|
| 50 | Rappture::VisViewer::SetServerList "vtkvis" $namelist |
---|
| 51 | } |
---|
| 52 | public method add {dataobj {settings ""}} |
---|
| 53 | public method camera {option args} |
---|
| 54 | public method delete {args} |
---|
| 55 | public method disconnect {} |
---|
| 56 | public method download {option args} |
---|
| 57 | public method get {args} |
---|
| 58 | public method isconnected {} |
---|
| 59 | public method parameters {title args} { |
---|
| 60 | # do nothing |
---|
| 61 | } |
---|
| 62 | public method scale {args} |
---|
| 63 | |
---|
| 64 | protected method Connect {} |
---|
| 65 | protected method CurrentDatasets {args} |
---|
| 66 | protected method Disconnect {} |
---|
| 67 | protected method DoResize {} |
---|
[2600] | 68 | protected method DoReseed {} |
---|
[2504] | 69 | protected method DoRotate {} |
---|
| 70 | protected method AdjustSetting {what {value ""}} |
---|
[2600] | 71 | protected method InitSettings { args } |
---|
[2504] | 72 | protected method Pan {option x y} |
---|
| 73 | protected method Pick {x y} |
---|
| 74 | protected method Rebuild {} |
---|
| 75 | protected method ReceiveDataset { args } |
---|
| 76 | protected method ReceiveImage { args } |
---|
| 77 | protected method ReceiveLegend { colormap title vmin vmax size } |
---|
| 78 | protected method Rotate {option x y} |
---|
| 79 | protected method Zoom {option} |
---|
| 80 | |
---|
| 81 | # The following methods are only used by this class. |
---|
| 82 | private method BuildAxisTab {} |
---|
| 83 | private method BuildCameraTab {} |
---|
[2585] | 84 | private method BuildColormap { name colors } |
---|
[2584] | 85 | private method BuildCutplaneTab {} |
---|
[2504] | 86 | private method BuildDownloadPopup { widget command } |
---|
| 87 | private method BuildStreamsTab {} |
---|
| 88 | private method BuildVolumeTab {} |
---|
| 89 | private method ConvertToVtkData { dataobj comp } |
---|
[3442] | 90 | private method DrawLegend {} |
---|
[2649] | 91 | private method Combo { option } |
---|
[2504] | 92 | private method EnterLegend { x y } |
---|
| 93 | private method EventuallyResize { w h } |
---|
[2600] | 94 | private method EventuallyReseed { numPoints } |
---|
[2504] | 95 | private method EventuallyRotate { q } |
---|
[2584] | 96 | private method EventuallySetCutplane { axis args } |
---|
[2504] | 97 | private method GetImage { args } |
---|
| 98 | private method GetVtkData { args } |
---|
| 99 | private method IsValidObject { dataobj } |
---|
| 100 | private method LeaveLegend {} |
---|
| 101 | private method MotionLegend { x y } |
---|
| 102 | private method PanCamera {} |
---|
[2587] | 103 | private method RequestLegend {} |
---|
[2504] | 104 | private method SetColormap { dataobj comp } |
---|
[2586] | 105 | private method ChangeColormap { dataobj comp color } |
---|
[2504] | 106 | private method SetLegendTip { x y } |
---|
| 107 | private method SetObjectStyle { dataobj comp } |
---|
| 108 | private method Slice {option args} |
---|
| 109 | |
---|
| 110 | private variable _arcball "" |
---|
| 111 | |
---|
[2744] | 112 | private variable _dlist "" ; # list of data objects |
---|
[2504] | 113 | private variable _obj2datasets |
---|
[2744] | 114 | private variable _obj2ovride ; # maps dataobj => style override |
---|
| 115 | private variable _datasets ; # contains all the dataobj-component |
---|
| 116 | ; # datasets in the server |
---|
| 117 | private variable _colormaps ; # contains all the colormaps |
---|
| 118 | ; # in the server. |
---|
[2504] | 119 | private variable _dataset2style ;# maps dataobj-component to transfunc |
---|
| 120 | |
---|
[2744] | 121 | private variable _click ; # info used for rotate operations |
---|
| 122 | private variable _limits ; # autoscale min/max for all axes |
---|
| 123 | private variable _view ; # view params for 3D view |
---|
[2504] | 124 | private variable _settings |
---|
[2744] | 125 | private variable _style; # Array of current component styles. |
---|
| 126 | private variable _initialStyle; # Array of initial component styles. |
---|
| 127 | private variable _reset 1; # indicates if camera needs to be reset |
---|
| 128 | # to starting position. |
---|
[2504] | 129 | |
---|
[2744] | 130 | private variable _first "" ; # This is the topmost dataset. |
---|
[2504] | 131 | private variable _start 0 |
---|
| 132 | private variable _title "" |
---|
[2547] | 133 | private variable _seeds |
---|
[2504] | 134 | |
---|
[2744] | 135 | common _downloadPopup; # download options from popup |
---|
[2504] | 136 | private common _hardcopy |
---|
| 137 | private variable _width 0 |
---|
| 138 | private variable _height 0 |
---|
| 139 | private variable _resizePending 0 |
---|
[2600] | 140 | private variable _reseedPending 0 |
---|
[2504] | 141 | private variable _rotatePending 0 |
---|
[2584] | 142 | private variable _cutplanePending 0 |
---|
[2652] | 143 | private variable _legendPending 0 |
---|
[2504] | 144 | private variable _outline |
---|
[2600] | 145 | private variable _vectorFields |
---|
| 146 | private variable _scalarFields |
---|
[2604] | 147 | private variable _fields |
---|
[3405] | 148 | private variable _curFldName "" |
---|
| 149 | private variable _curFldLabel "" |
---|
[2744] | 150 | private variable _field "" |
---|
[2600] | 151 | private variable _numSeeds 200 |
---|
[2587] | 152 | private variable _colorMode "vmag";# Mode of colormap (vmag or scalar) |
---|
[2504] | 153 | } |
---|
| 154 | |
---|
| 155 | itk::usual VtkStreamlinesViewer { |
---|
| 156 | keep -background -foreground -cursor -font |
---|
| 157 | keep -plotbackground -plotforeground |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | # ---------------------------------------------------------------------- |
---|
| 161 | # CONSTRUCTOR |
---|
| 162 | # ---------------------------------------------------------------------- |
---|
| 163 | itcl::body Rappture::VtkStreamlinesViewer::constructor {hostlist args} { |
---|
[2792] | 164 | package require vtk |
---|
[2671] | 165 | set _serverType "vtkvis" |
---|
| 166 | |
---|
[3454] | 167 | EnableWaitDialog 2000 |
---|
[3446] | 168 | |
---|
[2504] | 169 | # Rebuild event |
---|
| 170 | $_dispatcher register !rebuild |
---|
| 171 | $_dispatcher dispatch $this !rebuild "[itcl::code $this Rebuild]; list" |
---|
| 172 | |
---|
| 173 | # Resize event |
---|
| 174 | $_dispatcher register !resize |
---|
| 175 | $_dispatcher dispatch $this !resize "[itcl::code $this DoResize]; list" |
---|
| 176 | |
---|
[2600] | 177 | # Reseed event |
---|
| 178 | $_dispatcher register !reseed |
---|
| 179 | $_dispatcher dispatch $this !reseed "[itcl::code $this DoReseed]; list" |
---|
| 180 | |
---|
[2504] | 181 | # Rotate event |
---|
| 182 | $_dispatcher register !rotate |
---|
| 183 | $_dispatcher dispatch $this !rotate "[itcl::code $this DoRotate]; list" |
---|
| 184 | |
---|
[2652] | 185 | # Legend event |
---|
| 186 | $_dispatcher register !legend |
---|
| 187 | $_dispatcher dispatch $this !legend "[itcl::code $this RequestLegend]; list" |
---|
| 188 | |
---|
[2584] | 189 | # X-Cutplane event |
---|
| 190 | $_dispatcher register !xcutplane |
---|
| 191 | $_dispatcher dispatch $this !xcutplane \ |
---|
[3330] | 192 | "[itcl::code $this AdjustSetting cutplaneXPosition]; list" |
---|
[2504] | 193 | |
---|
[2584] | 194 | # Y-Cutplane event |
---|
| 195 | $_dispatcher register !ycutplane |
---|
| 196 | $_dispatcher dispatch $this !ycutplane \ |
---|
[3330] | 197 | "[itcl::code $this AdjustSetting cutplaneYPosition]; list" |
---|
[2584] | 198 | |
---|
| 199 | # Z-Cutplane event |
---|
| 200 | $_dispatcher register !zcutplane |
---|
| 201 | $_dispatcher dispatch $this !zcutplane \ |
---|
[3330] | 202 | "[itcl::code $this AdjustSetting cutplaneZPosition]; list" |
---|
[2584] | 203 | |
---|
[2504] | 204 | # |
---|
| 205 | # Populate parser with commands handle incoming requests |
---|
| 206 | # |
---|
| 207 | $_parser alias image [itcl::code $this ReceiveImage] |
---|
| 208 | $_parser alias dataset [itcl::code $this ReceiveDataset] |
---|
| 209 | $_parser alias legend [itcl::code $this ReceiveLegend] |
---|
| 210 | |
---|
| 211 | array set _outline { |
---|
[2744] | 212 | id -1 |
---|
| 213 | afterId -1 |
---|
| 214 | x1 -1 |
---|
| 215 | y1 -1 |
---|
| 216 | x2 -1 |
---|
| 217 | y2 -1 |
---|
[2504] | 218 | } |
---|
| 219 | # Initialize the view to some default parameters. |
---|
| 220 | array set _view { |
---|
[3330] | 221 | qw 0.853553 |
---|
| 222 | qx -0.353553 |
---|
| 223 | qy 0.353553 |
---|
| 224 | qz 0.146447 |
---|
[2744] | 225 | zoom 1.0 |
---|
| 226 | xpan 0 |
---|
| 227 | ypan 0 |
---|
| 228 | ortho 0 |
---|
[2504] | 229 | } |
---|
| 230 | set _arcball [blt::arcball create 100 100] |
---|
| 231 | set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] |
---|
| 232 | $_arcball quaternion $q |
---|
| 233 | |
---|
| 234 | array set _settings [subst { |
---|
[3330] | 235 | axesVisible 1 |
---|
| 236 | axisLabelsVisible 1 |
---|
| 237 | axisXGrid 0 |
---|
| 238 | axisYGrid 0 |
---|
| 239 | axisZGrid 0 |
---|
| 240 | cutplaneEdges 0 |
---|
| 241 | cutplaneLighting 1 |
---|
| 242 | cutplaneOpacity 100 |
---|
| 243 | cutplaneVisible 0 |
---|
| 244 | cutplaneWireframe 0 |
---|
| 245 | cutplaneXPosition 50 |
---|
| 246 | cutplaneXVisible 1 |
---|
| 247 | cutplaneYPosition 50 |
---|
| 248 | cutplaneYVisible 1 |
---|
| 249 | cutplaneZPosition 50 |
---|
| 250 | cutplaneZVisible 1 |
---|
| 251 | legendVisible 1 |
---|
| 252 | streamlinesLighting 1 |
---|
| 253 | streamlinesMode lines |
---|
| 254 | streamlinesNumSeeds 200 |
---|
| 255 | streamlinesOpacity 100 |
---|
| 256 | streamlinesScale 1 |
---|
| 257 | streamlinesSeedsVisible 0 |
---|
| 258 | streamlinesVisible 1 |
---|
| 259 | volumeEdges 0 |
---|
| 260 | volumeLighting 1 |
---|
| 261 | volumeOpacity 40 |
---|
| 262 | volumeVisible 1 |
---|
| 263 | volumeWireframe 0 |
---|
[2504] | 264 | }] |
---|
| 265 | |
---|
| 266 | itk_component add view { |
---|
| 267 | canvas $itk_component(plotarea).view \ |
---|
| 268 | -highlightthickness 0 -borderwidth 0 |
---|
| 269 | } { |
---|
| 270 | usual |
---|
| 271 | ignore -highlightthickness -borderwidth -background |
---|
| 272 | } |
---|
| 273 | |
---|
[2649] | 274 | itk_component add fieldmenu { |
---|
| 275 | menu $itk_component(plotarea).menu -bg black -fg white -relief flat \ |
---|
[2744] | 276 | -tearoff no |
---|
[2649] | 277 | } { |
---|
[2744] | 278 | usual |
---|
| 279 | ignore -background -foreground -relief -tearoff |
---|
[2649] | 280 | } |
---|
[2504] | 281 | set c $itk_component(view) |
---|
| 282 | bind $c <Configure> [itcl::code $this EventuallyResize %w %h] |
---|
| 283 | bind $c <4> [itcl::code $this Zoom in 0.25] |
---|
| 284 | bind $c <5> [itcl::code $this Zoom out 0.25] |
---|
| 285 | bind $c <KeyPress-Left> [list %W xview scroll 10 units] |
---|
| 286 | bind $c <KeyPress-Right> [list %W xview scroll -10 units] |
---|
| 287 | bind $c <KeyPress-Up> [list %W yview scroll 10 units] |
---|
| 288 | bind $c <KeyPress-Down> [list %W yview scroll -10 units] |
---|
| 289 | bind $c <Enter> "focus %W" |
---|
[3330] | 290 | bind $c <Control-F1> [itcl::code $this ToggleConsole] |
---|
[2504] | 291 | |
---|
| 292 | # Fix the scrollregion in case we go off screen |
---|
| 293 | $c configure -scrollregion [$c bbox all] |
---|
| 294 | |
---|
| 295 | set _map(id) [$c create image 0 0 -anchor nw -image $_image(plot)] |
---|
| 296 | set _map(cwidth) -1 |
---|
| 297 | set _map(cheight) -1 |
---|
| 298 | set _map(zoom) 1.0 |
---|
| 299 | set _map(original) "" |
---|
| 300 | |
---|
| 301 | set f [$itk_component(main) component controls] |
---|
| 302 | itk_component add reset { |
---|
| 303 | button $f.reset -borderwidth 1 -padx 1 -pady 1 \ |
---|
| 304 | -highlightthickness 0 \ |
---|
| 305 | -image [Rappture::icon reset-view] \ |
---|
| 306 | -command [itcl::code $this Zoom reset] |
---|
| 307 | } { |
---|
| 308 | usual |
---|
| 309 | ignore -highlightthickness |
---|
| 310 | } |
---|
| 311 | pack $itk_component(reset) -side top -padx 2 -pady 2 |
---|
| 312 | Rappture::Tooltip::for $itk_component(reset) "Reset the view to the default zoom level" |
---|
| 313 | |
---|
| 314 | itk_component add zoomin { |
---|
| 315 | button $f.zin -borderwidth 1 -padx 1 -pady 1 \ |
---|
| 316 | -highlightthickness 0 \ |
---|
| 317 | -image [Rappture::icon zoom-in] \ |
---|
| 318 | -command [itcl::code $this Zoom in] |
---|
| 319 | } { |
---|
| 320 | usual |
---|
| 321 | ignore -highlightthickness |
---|
| 322 | } |
---|
| 323 | pack $itk_component(zoomin) -side top -padx 2 -pady 2 |
---|
| 324 | Rappture::Tooltip::for $itk_component(zoomin) "Zoom in" |
---|
| 325 | |
---|
| 326 | itk_component add zoomout { |
---|
| 327 | button $f.zout -borderwidth 1 -padx 1 -pady 1 \ |
---|
| 328 | -highlightthickness 0 \ |
---|
| 329 | -image [Rappture::icon zoom-out] \ |
---|
| 330 | -command [itcl::code $this Zoom out] |
---|
| 331 | } { |
---|
| 332 | usual |
---|
| 333 | ignore -highlightthickness |
---|
| 334 | } |
---|
| 335 | pack $itk_component(zoomout) -side top -padx 2 -pady 2 |
---|
| 336 | Rappture::Tooltip::for $itk_component(zoomout) "Zoom out" |
---|
| 337 | |
---|
[2584] | 338 | itk_component add volume { |
---|
| 339 | Rappture::PushButton $f.volume \ |
---|
| 340 | -onimage [Rappture::icon volume-on] \ |
---|
| 341 | -offimage [Rappture::icon volume-off] \ |
---|
[3330] | 342 | -variable [itcl::scope _settings(volumeVisible)] \ |
---|
| 343 | -command [itcl::code $this AdjustSetting volumeVisible] |
---|
[2584] | 344 | } |
---|
| 345 | $itk_component(volume) select |
---|
| 346 | Rappture::Tooltip::for $itk_component(volume) \ |
---|
[2585] | 347 | "Don't display the volume" |
---|
[2584] | 348 | pack $itk_component(volume) -padx 2 -pady 2 |
---|
| 349 | |
---|
| 350 | itk_component add streamlines { |
---|
| 351 | Rappture::PushButton $f.streamlines \ |
---|
[2585] | 352 | -onimage [Rappture::icon streamlines-on] \ |
---|
| 353 | -offimage [Rappture::icon streamlines-off] \ |
---|
[3330] | 354 | -variable [itcl::scope _settings(streamlinesVisible)] \ |
---|
| 355 | -command [itcl::code $this AdjustSetting streamlinesVisible] \ |
---|
[2584] | 356 | } |
---|
| 357 | $itk_component(streamlines) select |
---|
| 358 | Rappture::Tooltip::for $itk_component(streamlines) \ |
---|
| 359 | "Toggle the streamlines on/off" |
---|
| 360 | pack $itk_component(streamlines) -padx 2 -pady 2 |
---|
| 361 | |
---|
[2622] | 362 | itk_component add cutplane { |
---|
| 363 | Rappture::PushButton $f.cutplane \ |
---|
| 364 | -onimage [Rappture::icon cutbutton] \ |
---|
| 365 | -offimage [Rappture::icon cutbutton] \ |
---|
[3330] | 366 | -variable [itcl::scope _settings(cutplaneVisible)] \ |
---|
| 367 | -command [itcl::code $this AdjustSetting cutplaneVisible] |
---|
[2622] | 368 | } |
---|
| 369 | Rappture::Tooltip::for $itk_component(cutplane) \ |
---|
| 370 | "Show/Hide cutplanes" |
---|
| 371 | pack $itk_component(cutplane) -padx 2 -pady 2 |
---|
| 372 | |
---|
| 373 | |
---|
[2504] | 374 | if { [catch { |
---|
[2744] | 375 | BuildVolumeTab |
---|
| 376 | BuildStreamsTab |
---|
| 377 | BuildCutplaneTab |
---|
| 378 | BuildAxisTab |
---|
| 379 | BuildCameraTab |
---|
[2504] | 380 | } errs] != 0 } { |
---|
[2744] | 381 | puts stderr errs=$errs |
---|
[2504] | 382 | } |
---|
| 383 | # Legend |
---|
| 384 | |
---|
| 385 | set _image(legend) [image create photo] |
---|
| 386 | itk_component add legend { |
---|
| 387 | canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0 |
---|
| 388 | } { |
---|
| 389 | usual |
---|
| 390 | ignore -highlightthickness |
---|
| 391 | rename -background -plotbackground plotBackground Background |
---|
| 392 | } |
---|
| 393 | |
---|
| 394 | # Hack around the Tk panewindow. The problem is that the requested |
---|
| 395 | # size of the 3d view isn't set until an image is retrieved from |
---|
| 396 | # the server. So the panewindow uses the tiny size. |
---|
| 397 | set w 10000 |
---|
| 398 | pack forget $itk_component(view) |
---|
| 399 | blt::table $itk_component(plotarea) \ |
---|
| 400 | 0,0 $itk_component(view) -fill both -reqwidth $w |
---|
| 401 | blt::table configure $itk_component(plotarea) c1 -resize none |
---|
| 402 | |
---|
| 403 | # Bindings for rotation via mouse |
---|
| 404 | bind $itk_component(view) <ButtonPress-1> \ |
---|
| 405 | [itcl::code $this Rotate click %x %y] |
---|
| 406 | bind $itk_component(view) <B1-Motion> \ |
---|
| 407 | [itcl::code $this Rotate drag %x %y] |
---|
| 408 | bind $itk_component(view) <ButtonRelease-1> \ |
---|
| 409 | [itcl::code $this Rotate release %x %y] |
---|
| 410 | bind $itk_component(view) <Configure> \ |
---|
| 411 | [itcl::code $this EventuallyResize %w %h] |
---|
| 412 | |
---|
| 413 | if 0 { |
---|
| 414 | bind $itk_component(view) <Configure> \ |
---|
| 415 | [itcl::code $this EventuallyResize %w %h] |
---|
| 416 | } |
---|
| 417 | # Bindings for panning via mouse |
---|
| 418 | bind $itk_component(view) <ButtonPress-2> \ |
---|
| 419 | [itcl::code $this Pan click %x %y] |
---|
| 420 | bind $itk_component(view) <B2-Motion> \ |
---|
| 421 | [itcl::code $this Pan drag %x %y] |
---|
| 422 | bind $itk_component(view) <ButtonRelease-2> \ |
---|
| 423 | [itcl::code $this Pan release %x %y] |
---|
| 424 | |
---|
[3443] | 425 | #bind $itk_component(view) <ButtonRelease-3> \ |
---|
| 426 | # [itcl::code $this Pick %x %y] |
---|
[2504] | 427 | |
---|
| 428 | # Bindings for panning via keyboard |
---|
| 429 | bind $itk_component(view) <KeyPress-Left> \ |
---|
| 430 | [itcl::code $this Pan set -10 0] |
---|
| 431 | bind $itk_component(view) <KeyPress-Right> \ |
---|
| 432 | [itcl::code $this Pan set 10 0] |
---|
| 433 | bind $itk_component(view) <KeyPress-Up> \ |
---|
| 434 | [itcl::code $this Pan set 0 -10] |
---|
| 435 | bind $itk_component(view) <KeyPress-Down> \ |
---|
| 436 | [itcl::code $this Pan set 0 10] |
---|
| 437 | bind $itk_component(view) <Shift-KeyPress-Left> \ |
---|
| 438 | [itcl::code $this Pan set -2 0] |
---|
| 439 | bind $itk_component(view) <Shift-KeyPress-Right> \ |
---|
| 440 | [itcl::code $this Pan set 2 0] |
---|
| 441 | bind $itk_component(view) <Shift-KeyPress-Up> \ |
---|
| 442 | [itcl::code $this Pan set 0 -2] |
---|
| 443 | bind $itk_component(view) <Shift-KeyPress-Down> \ |
---|
| 444 | [itcl::code $this Pan set 0 2] |
---|
| 445 | |
---|
| 446 | # Bindings for zoom via keyboard |
---|
| 447 | bind $itk_component(view) <KeyPress-Prior> \ |
---|
| 448 | [itcl::code $this Zoom out] |
---|
| 449 | bind $itk_component(view) <KeyPress-Next> \ |
---|
| 450 | [itcl::code $this Zoom in] |
---|
| 451 | |
---|
| 452 | bind $itk_component(view) <Enter> "focus $itk_component(view)" |
---|
| 453 | |
---|
| 454 | if {[string equal "x11" [tk windowingsystem]]} { |
---|
| 455 | # Bindings for zoom via mouse |
---|
| 456 | bind $itk_component(view) <4> [itcl::code $this Zoom out] |
---|
| 457 | bind $itk_component(view) <5> [itcl::code $this Zoom in] |
---|
| 458 | } |
---|
| 459 | |
---|
| 460 | set _image(download) [image create photo] |
---|
| 461 | |
---|
| 462 | eval itk_initialize $args |
---|
| 463 | Connect |
---|
[2587] | 464 | update |
---|
[2504] | 465 | } |
---|
| 466 | |
---|
| 467 | # ---------------------------------------------------------------------- |
---|
| 468 | # DESTRUCTOR |
---|
| 469 | # ---------------------------------------------------------------------- |
---|
| 470 | itcl::body Rappture::VtkStreamlinesViewer::destructor {} { |
---|
| 471 | Disconnect |
---|
| 472 | image delete $_image(plot) |
---|
| 473 | image delete $_image(download) |
---|
| 474 | catch { blt::arcball destroy $_arcball } |
---|
| 475 | } |
---|
| 476 | |
---|
| 477 | itcl::body Rappture::VtkStreamlinesViewer::DoResize {} { |
---|
| 478 | if { $_width < 2 } { |
---|
[2744] | 479 | set _width 500 |
---|
[2504] | 480 | } |
---|
| 481 | if { $_height < 2 } { |
---|
[2744] | 482 | set _height 500 |
---|
[2504] | 483 | } |
---|
| 484 | set _start [clock clicks -milliseconds] |
---|
| 485 | SendCmd "screen size $_width $_height" |
---|
[3438] | 486 | |
---|
[2673] | 487 | set _legendPending 1 |
---|
[2504] | 488 | set _resizePending 0 |
---|
| 489 | } |
---|
| 490 | |
---|
| 491 | itcl::body Rappture::VtkStreamlinesViewer::DoRotate {} { |
---|
| 492 | set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] |
---|
| 493 | SendCmd "camera orient $q" |
---|
| 494 | set _rotatePending 0 |
---|
| 495 | } |
---|
| 496 | |
---|
[2600] | 497 | itcl::body Rappture::VtkStreamlinesViewer::DoReseed {} { |
---|
| 498 | foreach dataset [CurrentDatasets -visible] { |
---|
[2744] | 499 | foreach {dataobj comp} [split $dataset -] break |
---|
| 500 | # This command works for either random or fmesh seeds |
---|
| 501 | SendCmd "streamlines seed numpts $_numSeeds $dataset" |
---|
[2600] | 502 | } |
---|
| 503 | set _reseedPending 0 |
---|
| 504 | } |
---|
| 505 | |
---|
[2504] | 506 | itcl::body Rappture::VtkStreamlinesViewer::EventuallyResize { w h } { |
---|
| 507 | set _width $w |
---|
| 508 | set _height $h |
---|
| 509 | $_arcball resize $w $h |
---|
| 510 | if { !$_resizePending } { |
---|
| 511 | set _resizePending 1 |
---|
[2600] | 512 | $_dispatcher event -after 400 !resize |
---|
[2504] | 513 | } |
---|
| 514 | } |
---|
| 515 | |
---|
[2600] | 516 | itcl::body Rappture::VtkStreamlinesViewer::EventuallyReseed { numPoints } { |
---|
| 517 | set _numSeeds $numPoints |
---|
| 518 | if { !$_reseedPending } { |
---|
| 519 | set _reseedPending 1 |
---|
| 520 | $_dispatcher event -after 600 !reseed |
---|
| 521 | } |
---|
| 522 | } |
---|
| 523 | |
---|
[2504] | 524 | set rotate_delay 100 |
---|
| 525 | |
---|
| 526 | itcl::body Rappture::VtkStreamlinesViewer::EventuallyRotate { q } { |
---|
| 527 | foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break |
---|
| 528 | if { !$_rotatePending } { |
---|
| 529 | set _rotatePending 1 |
---|
[2744] | 530 | global rotate_delay |
---|
[2504] | 531 | $_dispatcher event -after $rotate_delay !rotate |
---|
| 532 | } |
---|
| 533 | } |
---|
| 534 | |
---|
[2584] | 535 | itcl::body Rappture::VtkStreamlinesViewer::EventuallySetCutplane { axis args } { |
---|
| 536 | if { !$_cutplanePending } { |
---|
| 537 | set _cutplanePending 1 |
---|
| 538 | $_dispatcher event -after 100 !${axis}cutplane |
---|
| 539 | } |
---|
| 540 | } |
---|
| 541 | |
---|
[2504] | 542 | # ---------------------------------------------------------------------- |
---|
| 543 | # USAGE: add <dataobj> ?<settings>? |
---|
| 544 | # |
---|
| 545 | # Clients use this to add a data object to the plot. The optional |
---|
| 546 | # <settings> are used to configure the plot. Allowed settings are |
---|
| 547 | # -color, -brightness, -width, -linestyle, and -raise. |
---|
| 548 | # ---------------------------------------------------------------------- |
---|
| 549 | itcl::body Rappture::VtkStreamlinesViewer::add {dataobj {settings ""}} { |
---|
| 550 | array set params { |
---|
| 551 | -color auto |
---|
| 552 | -width 1 |
---|
| 553 | -linestyle solid |
---|
| 554 | -brightness 0 |
---|
| 555 | -raise 0 |
---|
| 556 | -description "" |
---|
| 557 | -param "" |
---|
[2744] | 558 | -type "" |
---|
[2504] | 559 | } |
---|
| 560 | array set params $settings |
---|
| 561 | set params(-description) "" |
---|
| 562 | set params(-param) "" |
---|
| 563 | foreach {opt val} $settings { |
---|
| 564 | if {![info exists params($opt)]} { |
---|
| 565 | error "bad setting \"$opt\": should be [join [lsort [array names params]] {, }]" |
---|
| 566 | } |
---|
| 567 | set params($opt) $val |
---|
| 568 | } |
---|
| 569 | if {$params(-color) == "auto" || $params(-color) == "autoreset"} { |
---|
| 570 | # can't handle -autocolors yet |
---|
| 571 | set params(-color) black |
---|
| 572 | } |
---|
| 573 | set pos [lsearch -exact $dataobj $_dlist] |
---|
| 574 | if {$pos < 0} { |
---|
[2744] | 575 | lappend _dlist $dataobj |
---|
[2504] | 576 | } |
---|
| 577 | set _obj2ovride($dataobj-color) $params(-color) |
---|
| 578 | set _obj2ovride($dataobj-width) $params(-width) |
---|
| 579 | set _obj2ovride($dataobj-raise) $params(-raise) |
---|
| 580 | $_dispatcher event -idle !rebuild |
---|
| 581 | } |
---|
| 582 | |
---|
| 583 | |
---|
| 584 | # ---------------------------------------------------------------------- |
---|
| 585 | # USAGE: delete ?<dataobj1> <dataobj2> ...? |
---|
| 586 | # |
---|
| 587 | # Clients use this to delete a dataobj from the plot. If no dataobjs |
---|
| 588 | # are specified, then all dataobjs are deleted. No data objects are |
---|
| 589 | # deleted. They are only removed from the display list. |
---|
| 590 | # |
---|
| 591 | # ---------------------------------------------------------------------- |
---|
| 592 | itcl::body Rappture::VtkStreamlinesViewer::delete {args} { |
---|
| 593 | if { [llength $args] == 0} { |
---|
| 594 | set args $_dlist |
---|
| 595 | } |
---|
| 596 | # Delete all specified dataobjs |
---|
| 597 | set changed 0 |
---|
| 598 | foreach dataobj $args { |
---|
| 599 | set pos [lsearch -exact $_dlist $dataobj] |
---|
[2744] | 600 | if { $pos < 0 } { |
---|
| 601 | continue; # Don't know anything about it. |
---|
| 602 | } |
---|
| 603 | # Remove it from the dataobj list. |
---|
| 604 | set _dlist [lreplace $_dlist $pos $pos] |
---|
| 605 | array unset _obj2ovride $dataobj-* |
---|
| 606 | array unset _settings $dataobj-* |
---|
| 607 | # Append to the end of the dataobj list. |
---|
| 608 | lappend _dlist $dataobj |
---|
| 609 | set changed 1 |
---|
[2504] | 610 | } |
---|
| 611 | # If anything changed, then rebuild the plot |
---|
| 612 | if { $changed } { |
---|
| 613 | $_dispatcher event -idle !rebuild |
---|
| 614 | } |
---|
| 615 | } |
---|
| 616 | |
---|
| 617 | # ---------------------------------------------------------------------- |
---|
| 618 | # USAGE: get ?-objects? |
---|
| 619 | # USAGE: get ?-visible? |
---|
| 620 | # USAGE: get ?-image view? |
---|
| 621 | # |
---|
| 622 | # Clients use this to query the list of objects being plotted, in |
---|
| 623 | # order from bottom to top of this result. The optional "-image" |
---|
| 624 | # flag can also request the internal images being shown. |
---|
| 625 | # ---------------------------------------------------------------------- |
---|
| 626 | itcl::body Rappture::VtkStreamlinesViewer::get {args} { |
---|
| 627 | if {[llength $args] == 0} { |
---|
| 628 | set args "-objects" |
---|
| 629 | } |
---|
| 630 | |
---|
| 631 | set op [lindex $args 0] |
---|
| 632 | switch -- $op { |
---|
[2744] | 633 | "-objects" { |
---|
| 634 | # put the dataobj list in order according to -raise options |
---|
| 635 | set dlist {} |
---|
| 636 | foreach dataobj $_dlist { |
---|
| 637 | if { ![IsValidObject $dataobj] } { |
---|
| 638 | continue |
---|
| 639 | } |
---|
| 640 | if {[info exists _obj2ovride($dataobj-raise)] && |
---|
| 641 | $_obj2ovride($dataobj-raise)} { |
---|
| 642 | set dlist [linsert $dlist 0 $dataobj] |
---|
| 643 | } else { |
---|
| 644 | lappend dlist $dataobj |
---|
| 645 | } |
---|
| 646 | } |
---|
| 647 | return $dlist |
---|
| 648 | } |
---|
| 649 | "-visible" { |
---|
| 650 | set dlist {} |
---|
| 651 | foreach dataobj $_dlist { |
---|
| 652 | if { ![IsValidObject $dataobj] } { |
---|
| 653 | continue |
---|
| 654 | } |
---|
| 655 | if { ![info exists _obj2ovride($dataobj-raise)] } { |
---|
| 656 | # No setting indicates that the object isn't visible. |
---|
| 657 | continue |
---|
| 658 | } |
---|
| 659 | # Otherwise use the -raise parameter to put the object to |
---|
| 660 | # the front of the list. |
---|
| 661 | if { $_obj2ovride($dataobj-raise) } { |
---|
| 662 | set dlist [linsert $dlist 0 $dataobj] |
---|
| 663 | } else { |
---|
| 664 | lappend dlist $dataobj |
---|
| 665 | } |
---|
| 666 | } |
---|
| 667 | return $dlist |
---|
| 668 | } |
---|
| 669 | -image { |
---|
| 670 | if {[llength $args] != 2} { |
---|
| 671 | error "wrong # args: should be \"get -image view\"" |
---|
| 672 | } |
---|
| 673 | switch -- [lindex $args end] { |
---|
| 674 | view { |
---|
| 675 | return $_image(plot) |
---|
| 676 | } |
---|
| 677 | default { |
---|
| 678 | error "bad image name \"[lindex $args end]\": should be view" |
---|
| 679 | } |
---|
| 680 | } |
---|
| 681 | } |
---|
| 682 | default { |
---|
| 683 | error "bad option \"$op\": should be -objects or -image" |
---|
| 684 | } |
---|
[2504] | 685 | } |
---|
| 686 | } |
---|
| 687 | |
---|
| 688 | # ---------------------------------------------------------------------- |
---|
| 689 | # USAGE: scale ?<data1> <data2> ...? |
---|
| 690 | # |
---|
| 691 | # Sets the default limits for the overall plot according to the |
---|
| 692 | # limits of the data for all of the given <data> objects. This |
---|
| 693 | # accounts for all objects--even those not showing on the screen. |
---|
| 694 | # Because of this, the limits are appropriate for all objects as |
---|
| 695 | # the user scans through data in the ResultSet viewer. |
---|
| 696 | # ---------------------------------------------------------------------- |
---|
| 697 | itcl::body Rappture::VtkStreamlinesViewer::scale {args} { |
---|
| 698 | foreach dataobj $args { |
---|
[3431] | 699 | foreach axis { x y z } { |
---|
| 700 | set lim [$dataobj limits $axis] |
---|
| 701 | if { ![info exists _limits($axis)] } { |
---|
| 702 | set _limits($axis) $lim |
---|
| 703 | continue |
---|
| 704 | } |
---|
| 705 | foreach {min max} $lim break |
---|
| 706 | foreach {amin amax} $_limits($axis) break |
---|
| 707 | if { $amin > $min } { |
---|
| 708 | set amin $min |
---|
| 709 | } |
---|
| 710 | if { $amax < $max } { |
---|
| 711 | set amax $max |
---|
| 712 | } |
---|
| 713 | set _limits($axis) [list $amin $amax] |
---|
[2744] | 714 | } |
---|
[3431] | 715 | foreach { fname lim } [$dataobj fieldlimits] { |
---|
| 716 | if { ![info exists _limits($fname)] } { |
---|
| 717 | set _limits($fname) $lim |
---|
| 718 | continue |
---|
| 719 | } |
---|
| 720 | foreach {min max} $lim break |
---|
| 721 | foreach {fmin fmax} $_limits($fname) break |
---|
| 722 | if { $fmin > $min } { |
---|
| 723 | set fmin $min |
---|
| 724 | } |
---|
| 725 | if { $fmax < $max } { |
---|
| 726 | set fmax $max |
---|
| 727 | } |
---|
| 728 | set _limits($fname) [list $fmin $fmax] |
---|
[2744] | 729 | } |
---|
[2504] | 730 | } |
---|
| 731 | } |
---|
| 732 | |
---|
| 733 | # ---------------------------------------------------------------------- |
---|
| 734 | # USAGE: download coming |
---|
| 735 | # USAGE: download controls <downloadCommand> |
---|
| 736 | # USAGE: download now |
---|
| 737 | # |
---|
| 738 | # Clients use this method to create a downloadable representation |
---|
| 739 | # of the plot. Returns a list of the form {ext string}, where |
---|
| 740 | # "ext" is the file extension (indicating the type of data) and |
---|
| 741 | # "string" is the data itself. |
---|
| 742 | # ---------------------------------------------------------------------- |
---|
| 743 | itcl::body Rappture::VtkStreamlinesViewer::download {option args} { |
---|
| 744 | switch $option { |
---|
| 745 | coming { |
---|
| 746 | if {[catch { |
---|
| 747 | blt::winop snap $itk_component(plotarea) $_image(download) |
---|
| 748 | }]} { |
---|
| 749 | $_image(download) configure -width 1 -height 1 |
---|
| 750 | $_image(download) put #000000 |
---|
| 751 | } |
---|
| 752 | } |
---|
| 753 | controls { |
---|
| 754 | set popup .vtkviewerdownload |
---|
| 755 | if { ![winfo exists .vtkviewerdownload] } { |
---|
| 756 | set inner [BuildDownloadPopup $popup [lindex $args 0]] |
---|
| 757 | } else { |
---|
| 758 | set inner [$popup component inner] |
---|
| 759 | } |
---|
| 760 | set _downloadPopup(image_controls) $inner.image_frame |
---|
| 761 | set num [llength [get]] |
---|
| 762 | set num [expr {($num == 1) ? "1 result" : "$num results"}] |
---|
| 763 | set word [Rappture::filexfer::label downloadWord] |
---|
| 764 | $inner.summary configure -text "$word $num in the following format:" |
---|
[2744] | 765 | update idletasks ;# Fix initial sizes |
---|
[2504] | 766 | return $popup |
---|
| 767 | } |
---|
| 768 | now { |
---|
| 769 | set popup .vtkviewerdownload |
---|
| 770 | if {[winfo exists .vtkviewerdownload]} { |
---|
| 771 | $popup deactivate |
---|
| 772 | } |
---|
| 773 | switch -- $_downloadPopup(format) { |
---|
| 774 | "image" { |
---|
| 775 | return [$this GetImage [lindex $args 0]] |
---|
| 776 | } |
---|
| 777 | "vtk" { |
---|
| 778 | return [$this GetVtkData [lindex $args 0]] |
---|
| 779 | } |
---|
| 780 | } |
---|
| 781 | return "" |
---|
| 782 | } |
---|
| 783 | default { |
---|
| 784 | error "bad option \"$option\": should be coming, controls, now" |
---|
| 785 | } |
---|
| 786 | } |
---|
| 787 | } |
---|
| 788 | |
---|
| 789 | # ---------------------------------------------------------------------- |
---|
| 790 | # USAGE: Connect ?<host:port>,<host:port>...? |
---|
| 791 | # |
---|
| 792 | # Clients use this method to establish a connection to a new |
---|
| 793 | # server, or to reestablish a connection to the previous server. |
---|
| 794 | # Any existing connection is automatically closed. |
---|
| 795 | # ---------------------------------------------------------------------- |
---|
| 796 | itcl::body Rappture::VtkStreamlinesViewer::Connect {} { |
---|
| 797 | set _hosts [GetServerList "vtkvis"] |
---|
| 798 | if { "" == $_hosts } { |
---|
| 799 | return 0 |
---|
| 800 | } |
---|
| 801 | set result [VisViewer::Connect $_hosts] |
---|
| 802 | if { $result } { |
---|
| 803 | set w [winfo width $itk_component(view)] |
---|
| 804 | set h [winfo height $itk_component(view)] |
---|
| 805 | EventuallyResize $w $h |
---|
| 806 | } |
---|
| 807 | return $result |
---|
| 808 | } |
---|
| 809 | |
---|
| 810 | # |
---|
| 811 | # isconnected -- |
---|
| 812 | # |
---|
| 813 | # Indicates if we are currently connected to the visualization server. |
---|
| 814 | # |
---|
| 815 | itcl::body Rappture::VtkStreamlinesViewer::isconnected {} { |
---|
| 816 | return [VisViewer::IsConnected] |
---|
| 817 | } |
---|
| 818 | |
---|
| 819 | # |
---|
| 820 | # disconnect -- |
---|
| 821 | # |
---|
| 822 | itcl::body Rappture::VtkStreamlinesViewer::disconnect {} { |
---|
| 823 | Disconnect |
---|
| 824 | set _reset 1 |
---|
| 825 | } |
---|
| 826 | |
---|
| 827 | # |
---|
| 828 | # Disconnect -- |
---|
| 829 | # |
---|
| 830 | # Clients use this method to disconnect from the current rendering |
---|
| 831 | # server. |
---|
| 832 | # |
---|
| 833 | itcl::body Rappture::VtkStreamlinesViewer::Disconnect {} { |
---|
| 834 | VisViewer::Disconnect |
---|
| 835 | |
---|
[2652] | 836 | $_dispatcher cancel !rebuild |
---|
| 837 | $_dispatcher cancel !resize |
---|
| 838 | $_dispatcher cancel !reseed |
---|
| 839 | $_dispatcher cancel !rotate |
---|
| 840 | $_dispatcher cancel !xcutplane |
---|
| 841 | $_dispatcher cancel !ycutplane |
---|
| 842 | $_dispatcher cancel !zcutplane |
---|
| 843 | $_dispatcher cancel !legend |
---|
[2504] | 844 | # disconnected -- no more data sitting on server |
---|
| 845 | array unset _datasets |
---|
| 846 | array unset _data |
---|
| 847 | array unset _colormaps |
---|
[2611] | 848 | array unset _seeds |
---|
| 849 | array unset _dataset2style |
---|
| 850 | array unset _obj2datasets |
---|
[2504] | 851 | } |
---|
| 852 | |
---|
| 853 | # ---------------------------------------------------------------------- |
---|
| 854 | # USAGE: ReceiveImage -bytes <size> -type <type> -token <token> |
---|
| 855 | # |
---|
| 856 | # Invoked automatically whenever the "image" command comes in from |
---|
| 857 | # the rendering server. Indicates that binary image data with the |
---|
| 858 | # specified <size> will follow. |
---|
| 859 | # ---------------------------------------------------------------------- |
---|
| 860 | itcl::body Rappture::VtkStreamlinesViewer::ReceiveImage { args } { |
---|
| 861 | array set info { |
---|
| 862 | -token "???" |
---|
| 863 | -bytes 0 |
---|
| 864 | -type image |
---|
| 865 | } |
---|
| 866 | array set info $args |
---|
| 867 | set bytes [ReceiveBytes $info(-bytes)] |
---|
| 868 | if { $info(-type) == "image" } { |
---|
[2744] | 869 | if 0 { |
---|
| 870 | set f [open "last.ppm" "w"] |
---|
| 871 | puts $f $bytes |
---|
| 872 | close $f |
---|
| 873 | } |
---|
[2504] | 874 | $_image(plot) configure -data $bytes |
---|
[2744] | 875 | set time [clock seconds] |
---|
| 876 | set date [clock format $time] |
---|
[2504] | 877 | #puts stderr "$date: received image [image width $_image(plot)]x[image height $_image(plot)] image>" |
---|
[2744] | 878 | if { $_start > 0 } { |
---|
| 879 | set finish [clock clicks -milliseconds] |
---|
| 880 | #puts stderr "round trip time [expr $finish -$_start] milliseconds" |
---|
| 881 | set _start 0 |
---|
| 882 | } |
---|
[2504] | 883 | } elseif { $info(type) == "print" } { |
---|
| 884 | set tag $this-print-$info(-token) |
---|
| 885 | set _hardcopy($tag) $bytes |
---|
| 886 | } |
---|
[2652] | 887 | if { $_legendPending } { |
---|
[2744] | 888 | RequestLegend |
---|
[2652] | 889 | } |
---|
[2504] | 890 | } |
---|
| 891 | |
---|
| 892 | # |
---|
| 893 | # ReceiveDataset -- |
---|
| 894 | # |
---|
| 895 | itcl::body Rappture::VtkStreamlinesViewer::ReceiveDataset { args } { |
---|
| 896 | if { ![isconnected] } { |
---|
| 897 | return |
---|
| 898 | } |
---|
| 899 | set option [lindex $args 0] |
---|
| 900 | switch -- $option { |
---|
[2744] | 901 | "scalar" { |
---|
| 902 | set option [lindex $args 1] |
---|
| 903 | switch -- $option { |
---|
| 904 | "world" { |
---|
| 905 | foreach { x y z value tag } [lrange $args 2 end] break |
---|
| 906 | } |
---|
| 907 | "pixel" { |
---|
| 908 | foreach { x y value tag } [lrange $args 2 end] break |
---|
| 909 | } |
---|
| 910 | } |
---|
| 911 | } |
---|
| 912 | "vector" { |
---|
| 913 | set option [lindex $args 1] |
---|
| 914 | switch -- $option { |
---|
| 915 | "world" { |
---|
| 916 | foreach { x y z vx vy vz tag } [lrange $args 2 end] break |
---|
| 917 | } |
---|
| 918 | "pixel" { |
---|
| 919 | foreach { x y vx vy vz tag } [lrange $args 2 end] break |
---|
| 920 | } |
---|
| 921 | } |
---|
| 922 | } |
---|
| 923 | "names" { |
---|
[2504] | 924 | foreach { name } [lindex $args 1] { |
---|
| 925 | #puts stderr "Dataset: $name" |
---|
| 926 | } |
---|
[2744] | 927 | } |
---|
| 928 | default { |
---|
| 929 | error "unknown dataset option \"$option\" from server" |
---|
| 930 | } |
---|
[2504] | 931 | } |
---|
| 932 | } |
---|
| 933 | |
---|
| 934 | # ---------------------------------------------------------------------- |
---|
| 935 | # USAGE: Rebuild |
---|
| 936 | # |
---|
| 937 | # Called automatically whenever something changes that affects the |
---|
| 938 | # data in the widget. Clears any existing data and rebuilds the |
---|
| 939 | # widget to display new data. |
---|
| 940 | # ---------------------------------------------------------------------- |
---|
| 941 | itcl::body Rappture::VtkStreamlinesViewer::Rebuild {} { |
---|
[2585] | 942 | update |
---|
[2504] | 943 | set w [winfo width $itk_component(view)] |
---|
| 944 | set h [winfo height $itk_component(view)] |
---|
| 945 | if { $w < 2 || $h < 2 } { |
---|
[2744] | 946 | $_dispatcher event -idle !rebuild |
---|
| 947 | return |
---|
[2504] | 948 | } |
---|
| 949 | |
---|
| 950 | # Turn on buffering of commands to the server. We don't want to |
---|
| 951 | # be preempted by a server disconnect/reconnect (which automatically |
---|
[3418] | 952 | # generates a new call to Rebuild). |
---|
[3421] | 953 | StartBufferingCommands |
---|
| 954 | set _legendPending 1 |
---|
[3330] | 955 | |
---|
| 956 | set _first "" |
---|
| 957 | if { $_reset } { |
---|
[3421] | 958 | if { $_reportClientInfo } { |
---|
[3392] | 959 | # Tell the server the name of the tool, the version, and dataset |
---|
| 960 | # that we are rendering. Have to do it here because we don't know |
---|
| 961 | # what data objects are using the renderer until be get here. |
---|
| 962 | global env |
---|
| 963 | |
---|
| 964 | set info {} |
---|
| 965 | set user "???" |
---|
| 966 | if { [info exists env(USER)] } { |
---|
| 967 | set user $env(USER) |
---|
| 968 | } |
---|
| 969 | set session "???" |
---|
| 970 | if { [info exists env(SESSION)] } { |
---|
| 971 | set session $env(SESSION) |
---|
| 972 | } |
---|
| 973 | lappend info "hub" [exec hostname] |
---|
| 974 | lappend info "client" "vtkstreamlinesviewer" |
---|
| 975 | lappend info "user" $user |
---|
| 976 | lappend info "session" $session |
---|
| 977 | SendCmd "clientinfo [list $info]" |
---|
| 978 | } |
---|
[3330] | 979 | set _width $w |
---|
| 980 | set _height $h |
---|
| 981 | $_arcball resize $w $h |
---|
| 982 | DoResize |
---|
| 983 | InitSettings axisXGrid axisYGrid axisZGrid axis-mode \ |
---|
[3400] | 984 | axesVisible axisLabelsVisible |
---|
| 985 | # This "imgflush" is to force an image returned before vtkvis starts |
---|
| 986 | # reading a (big) dataset. This will display an empty plot with axes |
---|
| 987 | # at the correct image size. |
---|
| 988 | SendCmd "imgflush" |
---|
[2504] | 989 | } |
---|
| 990 | |
---|
| 991 | set _first "" |
---|
[3400] | 992 | SendCmd "dataset visible 0" |
---|
[2504] | 993 | foreach dataobj [get -objects] { |
---|
[2744] | 994 | if { [info exists _obj2ovride($dataobj-raise)] && $_first == "" } { |
---|
| 995 | set _first $dataobj |
---|
| 996 | } |
---|
| 997 | set _obj2datasets($dataobj) "" |
---|
[2504] | 998 | foreach comp [$dataobj components] { |
---|
| 999 | set tag $dataobj-$comp |
---|
| 1000 | if { ![info exists _datasets($tag)] } { |
---|
[3330] | 1001 | set bytes [$dataobj vtkdata $comp] |
---|
[2504] | 1002 | set length [string length $bytes] |
---|
[3421] | 1003 | if 0 { |
---|
[3405] | 1004 | set f [open /tmp/vtkstreamlines.vtk "w"] |
---|
| 1005 | fconfigure $f -translation binary -encoding binary |
---|
| 1006 | puts $f $bytes |
---|
| 1007 | close $f |
---|
| 1008 | } |
---|
[3421] | 1009 | if { $_reportClientInfo } { |
---|
[3392] | 1010 | set info {} |
---|
| 1011 | lappend info "tool_id" [$dataobj hints toolId] |
---|
| 1012 | lappend info "tool_name" [$dataobj hints toolName] |
---|
| 1013 | lappend info "tool_version" [$dataobj hints toolRevision] |
---|
| 1014 | lappend info "tool_title" [$dataobj hints toolTitle] |
---|
| 1015 | lappend info "dataset_label" [$dataobj hints label] |
---|
| 1016 | lappend info "dataset_size" $length |
---|
[3394] | 1017 | lappend info "dataset_tag" $tag |
---|
[3392] | 1018 | SendCmd "clientinfo [list $info]" |
---|
| 1019 | } |
---|
[3421] | 1020 | SendCmd "dataset add $tag data follows $length" |
---|
[2504] | 1021 | append _outbuf $bytes |
---|
| 1022 | set _datasets($tag) 1 |
---|
[2744] | 1023 | SetObjectStyle $dataobj $comp |
---|
| 1024 | } |
---|
| 1025 | lappend _obj2datasets($dataobj) $tag |
---|
| 1026 | if { [info exists _obj2ovride($dataobj-raise)] } { |
---|
| 1027 | SendCmd "dataset visible 1 $tag" |
---|
| 1028 | } |
---|
[2504] | 1029 | } |
---|
| 1030 | } |
---|
| 1031 | if {"" != $_first} { |
---|
| 1032 | set location [$_first hints camera] |
---|
| 1033 | if { $location != "" } { |
---|
| 1034 | array set view $location |
---|
| 1035 | } |
---|
[2744] | 1036 | foreach axis { x y z } { |
---|
| 1037 | set label [$_first hints ${axis}label] |
---|
| 1038 | if { $label != "" } { |
---|
| 1039 | SendCmd "axis name $axis $label" |
---|
| 1040 | } |
---|
| 1041 | set units [$_first hints ${axis}units] |
---|
| 1042 | if { $units != "" } { |
---|
| 1043 | SendCmd "axis units $axis $units" |
---|
| 1044 | } |
---|
| 1045 | } |
---|
[3405] | 1046 | $itk_component(field) choices delete 0 end |
---|
| 1047 | $itk_component(fieldmenu) delete 0 end |
---|
| 1048 | array unset _fields |
---|
[3421] | 1049 | set _curFldName "" |
---|
[3405] | 1050 | foreach cname [$_first components] { |
---|
| 1051 | foreach fname [$_first fieldnames $cname] { |
---|
| 1052 | if { [info exists _fields($fname)] } { |
---|
| 1053 | continue |
---|
| 1054 | } |
---|
| 1055 | foreach { label units components } \ |
---|
| 1056 | [$_first fieldinfo $fname] break |
---|
| 1057 | $itk_component(field) choices insert end "$fname" "$label" |
---|
| 1058 | $itk_component(fieldmenu) add radiobutton -label "$label" \ |
---|
| 1059 | -value $label -variable [itcl::scope _curFldLabel] \ |
---|
| 1060 | -selectcolor red \ |
---|
| 1061 | -activebackground $itk_option(-plotbackground) \ |
---|
| 1062 | -activeforeground $itk_option(-plotforeground) \ |
---|
| 1063 | -font "Arial 8" \ |
---|
| 1064 | -command [itcl::code $this Combo invoke] |
---|
| 1065 | set _fields($fname) [list $label $units $components] |
---|
[3421] | 1066 | if { $_curFldName == "" } { |
---|
| 1067 | set _curFldName $fname |
---|
| 1068 | set _curFldLabel $label |
---|
| 1069 | } |
---|
[3405] | 1070 | } |
---|
| 1071 | } |
---|
| 1072 | $itk_component(field) value $_curFldLabel |
---|
[2504] | 1073 | } |
---|
[2601] | 1074 | |
---|
[2605] | 1075 | if { $_reset } { |
---|
[3330] | 1076 | InitSettings streamlinesSeedsVisible streamlinesOpacity \ |
---|
[3442] | 1077 | streamlinesVisible streamlinesColormap \ |
---|
[3400] | 1078 | streamlinesLighting \ |
---|
[3442] | 1079 | streamlinesColormap field \ |
---|
[3400] | 1080 | volumeVisible volumeEdges volumeLighting volumeOpacity \ |
---|
| 1081 | volumeWireframe \ |
---|
[3330] | 1082 | cutplaneVisible \ |
---|
| 1083 | cutplaneXPosition cutplaneYPosition cutplaneZPosition \ |
---|
| 1084 | cutplaneXVisible cutplaneYVisible cutplaneZVisible |
---|
[3400] | 1085 | |
---|
| 1086 | # FIXME: Don't know exactly why this "imgflush" is needed. |
---|
[3421] | 1087 | # But this makes the "camera reset" below to work correctly. |
---|
| 1088 | # I left this in because the axis labels are scaled too big. |
---|
[3400] | 1089 | SendCmd "imgflush" |
---|
| 1090 | |
---|
[3330] | 1091 | # Reset the camera and other view parameters |
---|
| 1092 | set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] |
---|
| 1093 | $_arcball quaternion $q |
---|
| 1094 | if {$_view(ortho)} { |
---|
| 1095 | SendCmd "camera mode ortho" |
---|
| 1096 | } else { |
---|
| 1097 | SendCmd "camera mode persp" |
---|
| 1098 | } |
---|
| 1099 | DoRotate |
---|
| 1100 | PanCamera |
---|
[2744] | 1101 | Zoom reset |
---|
[3394] | 1102 | SendCmd "camera reset" |
---|
[2744] | 1103 | set _reset 0 |
---|
[2592] | 1104 | } |
---|
[2504] | 1105 | # Actually write the commands to the server socket. If it fails, we don't |
---|
| 1106 | # care. We're finished here. |
---|
| 1107 | blt::busy hold $itk_component(hull) |
---|
[3421] | 1108 | StopBufferingCommands |
---|
[2504] | 1109 | blt::busy release $itk_component(hull) |
---|
| 1110 | } |
---|
| 1111 | |
---|
| 1112 | # ---------------------------------------------------------------------- |
---|
| 1113 | # USAGE: CurrentDatasets ?-all -visible? ?dataobjs? |
---|
| 1114 | # |
---|
| 1115 | # Returns a list of server IDs for the current datasets being displayed. This |
---|
| 1116 | # is normally a single ID, but it might be a list of IDs if the current data |
---|
| 1117 | # object has multiple components. |
---|
| 1118 | # ---------------------------------------------------------------------- |
---|
| 1119 | itcl::body Rappture::VtkStreamlinesViewer::CurrentDatasets {args} { |
---|
| 1120 | set flag [lindex $args 0] |
---|
| 1121 | switch -- $flag { |
---|
[2744] | 1122 | "-all" { |
---|
| 1123 | if { [llength $args] > 1 } { |
---|
| 1124 | error "CurrentDatasets: can't specify dataobj after \"-all\"" |
---|
| 1125 | } |
---|
| 1126 | set dlist [get -objects] |
---|
| 1127 | } |
---|
| 1128 | "-visible" { |
---|
| 1129 | if { [llength $args] > 1 } { |
---|
| 1130 | set dlist {} |
---|
| 1131 | set args [lrange $args 1 end] |
---|
| 1132 | foreach dataobj $args { |
---|
| 1133 | if { [info exists _obj2ovride($dataobj-raise)] } { |
---|
| 1134 | lappend dlist $dataobj |
---|
| 1135 | } |
---|
| 1136 | } |
---|
| 1137 | } else { |
---|
| 1138 | set dlist [get -visible] |
---|
| 1139 | } |
---|
| 1140 | } |
---|
| 1141 | default { |
---|
| 1142 | set dlist $args |
---|
| 1143 | } |
---|
[2504] | 1144 | } |
---|
| 1145 | set rlist "" |
---|
| 1146 | foreach dataobj $dlist { |
---|
[2744] | 1147 | foreach comp [$dataobj components] { |
---|
| 1148 | set tag $dataobj-$comp |
---|
| 1149 | if { [info exists _datasets($tag)] && $_datasets($tag) } { |
---|
| 1150 | lappend rlist $tag |
---|
| 1151 | } |
---|
| 1152 | } |
---|
[2504] | 1153 | } |
---|
| 1154 | return $rlist |
---|
| 1155 | } |
---|
| 1156 | |
---|
| 1157 | # ---------------------------------------------------------------------- |
---|
| 1158 | # USAGE: Zoom in |
---|
| 1159 | # USAGE: Zoom out |
---|
| 1160 | # USAGE: Zoom reset |
---|
| 1161 | # |
---|
| 1162 | # Called automatically when the user clicks on one of the zoom |
---|
| 1163 | # controls for this widget. Changes the zoom for the current view. |
---|
| 1164 | # ---------------------------------------------------------------------- |
---|
| 1165 | itcl::body Rappture::VtkStreamlinesViewer::Zoom {option} { |
---|
| 1166 | switch -- $option { |
---|
| 1167 | "in" { |
---|
| 1168 | set _view(zoom) [expr {$_view(zoom)*1.25}] |
---|
[2744] | 1169 | SendCmd "camera zoom $_view(zoom)" |
---|
[2504] | 1170 | } |
---|
| 1171 | "out" { |
---|
| 1172 | set _view(zoom) [expr {$_view(zoom)*0.8}] |
---|
[2744] | 1173 | SendCmd "camera zoom $_view(zoom)" |
---|
[2504] | 1174 | } |
---|
| 1175 | "reset" { |
---|
| 1176 | array set _view { |
---|
[3482] | 1177 | qw 0.853553 |
---|
| 1178 | qx -0.353553 |
---|
| 1179 | qy 0.353553 |
---|
| 1180 | qz 0.146447 |
---|
[2504] | 1181 | zoom 1.0 |
---|
[3482] | 1182 | xpan 0 |
---|
| 1183 | ypan 0 |
---|
[2504] | 1184 | } |
---|
| 1185 | SendCmd "camera reset all" |
---|
| 1186 | if { $_first != "" } { |
---|
| 1187 | set location [$_first hints camera] |
---|
| 1188 | if { $location != "" } { |
---|
| 1189 | array set _view $location |
---|
| 1190 | } |
---|
| 1191 | } |
---|
[2744] | 1192 | set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] |
---|
| 1193 | $_arcball quaternion $q |
---|
| 1194 | DoRotate |
---|
[2504] | 1195 | } |
---|
| 1196 | } |
---|
| 1197 | } |
---|
| 1198 | |
---|
| 1199 | itcl::body Rappture::VtkStreamlinesViewer::PanCamera {} { |
---|
| 1200 | set x $_view(xpan) |
---|
| 1201 | set y $_view(ypan) |
---|
| 1202 | SendCmd "camera pan $x $y" |
---|
| 1203 | } |
---|
| 1204 | |
---|
| 1205 | |
---|
| 1206 | # ---------------------------------------------------------------------- |
---|
| 1207 | # USAGE: Rotate click <x> <y> |
---|
| 1208 | # USAGE: Rotate drag <x> <y> |
---|
| 1209 | # USAGE: Rotate release <x> <y> |
---|
| 1210 | # |
---|
| 1211 | # Called automatically when the user clicks/drags/releases in the |
---|
| 1212 | # plot area. Moves the plot according to the user's actions. |
---|
| 1213 | # ---------------------------------------------------------------------- |
---|
| 1214 | itcl::body Rappture::VtkStreamlinesViewer::Rotate {option x y} { |
---|
| 1215 | switch -- $option { |
---|
| 1216 | "click" { |
---|
| 1217 | $itk_component(view) configure -cursor fleur |
---|
| 1218 | set _click(x) $x |
---|
| 1219 | set _click(y) $y |
---|
| 1220 | } |
---|
| 1221 | "drag" { |
---|
| 1222 | if {[array size _click] == 0} { |
---|
| 1223 | Rotate click $x $y |
---|
| 1224 | } else { |
---|
| 1225 | set w [winfo width $itk_component(view)] |
---|
| 1226 | set h [winfo height $itk_component(view)] |
---|
| 1227 | if {$w <= 0 || $h <= 0} { |
---|
| 1228 | return |
---|
| 1229 | } |
---|
| 1230 | |
---|
| 1231 | if {[catch { |
---|
| 1232 | # this fails sometimes for no apparent reason |
---|
| 1233 | set dx [expr {double($x-$_click(x))/$w}] |
---|
| 1234 | set dy [expr {double($y-$_click(y))/$h}] |
---|
| 1235 | }]} { |
---|
| 1236 | return |
---|
| 1237 | } |
---|
[2744] | 1238 | if { $dx == 0 && $dy == 0 } { |
---|
| 1239 | return |
---|
| 1240 | } |
---|
| 1241 | set q [$_arcball rotate $x $y $_click(x) $_click(y)] |
---|
| 1242 | EventuallyRotate $q |
---|
[2504] | 1243 | set _click(x) $x |
---|
| 1244 | set _click(y) $y |
---|
| 1245 | } |
---|
| 1246 | } |
---|
| 1247 | "release" { |
---|
| 1248 | Rotate drag $x $y |
---|
| 1249 | $itk_component(view) configure -cursor "" |
---|
| 1250 | catch {unset _click} |
---|
| 1251 | } |
---|
| 1252 | default { |
---|
| 1253 | error "bad option \"$option\": should be click, drag, release" |
---|
| 1254 | } |
---|
| 1255 | } |
---|
| 1256 | } |
---|
| 1257 | |
---|
| 1258 | itcl::body Rappture::VtkStreamlinesViewer::Pick {x y} { |
---|
| 1259 | foreach tag [CurrentDatasets -visible] { |
---|
[3421] | 1260 | SendCmdNoWait "dataset getscalar pixel $x $y $tag" |
---|
[2504] | 1261 | } |
---|
| 1262 | } |
---|
| 1263 | |
---|
| 1264 | # ---------------------------------------------------------------------- |
---|
| 1265 | # USAGE: $this Pan click x y |
---|
| 1266 | # $this Pan drag x y |
---|
| 1267 | # $this Pan release x y |
---|
| 1268 | # |
---|
| 1269 | # Called automatically when the user clicks on one of the zoom |
---|
| 1270 | # controls for this widget. Changes the zoom for the current view. |
---|
| 1271 | # ---------------------------------------------------------------------- |
---|
| 1272 | itcl::body Rappture::VtkStreamlinesViewer::Pan {option x y} { |
---|
| 1273 | switch -- $option { |
---|
[2744] | 1274 | "set" { |
---|
| 1275 | set w [winfo width $itk_component(view)] |
---|
| 1276 | set h [winfo height $itk_component(view)] |
---|
| 1277 | set x [expr $x / double($w)] |
---|
| 1278 | set y [expr $y / double($h)] |
---|
| 1279 | set _view(xpan) [expr $_view(xpan) + $x] |
---|
| 1280 | set _view(ypan) [expr $_view(ypan) + $y] |
---|
| 1281 | PanCamera |
---|
| 1282 | return |
---|
| 1283 | } |
---|
| 1284 | "click" { |
---|
| 1285 | set _click(x) $x |
---|
| 1286 | set _click(y) $y |
---|
| 1287 | $itk_component(view) configure -cursor hand1 |
---|
| 1288 | } |
---|
| 1289 | "drag" { |
---|
| 1290 | if { ![info exists _click(x)] } { |
---|
| 1291 | set _click(x) $x |
---|
| 1292 | } |
---|
| 1293 | if { ![info exists _click(y)] } { |
---|
| 1294 | set _click(y) $y |
---|
| 1295 | } |
---|
| 1296 | set w [winfo width $itk_component(view)] |
---|
| 1297 | set h [winfo height $itk_component(view)] |
---|
| 1298 | set dx [expr ($_click(x) - $x)/double($w)] |
---|
| 1299 | set dy [expr ($_click(y) - $y)/double($h)] |
---|
| 1300 | set _click(x) $x |
---|
| 1301 | set _click(y) $y |
---|
| 1302 | set _view(xpan) [expr $_view(xpan) - $dx] |
---|
| 1303 | set _view(ypan) [expr $_view(ypan) - $dy] |
---|
| 1304 | PanCamera |
---|
| 1305 | } |
---|
| 1306 | "release" { |
---|
| 1307 | Pan drag $x $y |
---|
| 1308 | $itk_component(view) configure -cursor "" |
---|
| 1309 | } |
---|
| 1310 | default { |
---|
| 1311 | error "unknown option \"$option\": should set, click, drag, or release" |
---|
| 1312 | } |
---|
[2504] | 1313 | } |
---|
| 1314 | } |
---|
| 1315 | |
---|
| 1316 | # ---------------------------------------------------------------------- |
---|
[2600] | 1317 | # USAGE: InitSettings <what> ?<value>? |
---|
[2504] | 1318 | # |
---|
| 1319 | # Used internally to update rendering settings whenever parameters |
---|
| 1320 | # change in the popup settings panel. Sends the new settings off |
---|
| 1321 | # to the back end. |
---|
| 1322 | # ---------------------------------------------------------------------- |
---|
[2600] | 1323 | itcl::body Rappture::VtkStreamlinesViewer::InitSettings { args } { |
---|
| 1324 | foreach spec $args { |
---|
[2744] | 1325 | if { [info exists _settings($_first-$spec)] } { |
---|
| 1326 | # Reset global setting with dataobj specific setting |
---|
| 1327 | set _settings($spec) $_settings($_first-$spec) |
---|
| 1328 | } |
---|
| 1329 | AdjustSetting $spec |
---|
[2504] | 1330 | } |
---|
| 1331 | } |
---|
| 1332 | |
---|
| 1333 | # |
---|
| 1334 | # AdjustSetting -- |
---|
| 1335 | # |
---|
[2744] | 1336 | # Changes/updates a specific setting in the widget. There are |
---|
| 1337 | # usually user-setable option. Commands are sent to the render |
---|
| 1338 | # server. |
---|
[2504] | 1339 | # |
---|
| 1340 | itcl::body Rappture::VtkStreamlinesViewer::AdjustSetting {what {value ""}} { |
---|
| 1341 | if { ![isconnected] } { |
---|
[2744] | 1342 | return |
---|
[2504] | 1343 | } |
---|
| 1344 | switch -- $what { |
---|
[3330] | 1345 | "volumeOpacity" { |
---|
| 1346 | set val $_settings(volumeOpacity) |
---|
[2744] | 1347 | set sval [expr { 0.01 * double($val) }] |
---|
[3400] | 1348 | SendCmd "polydata opacity $sval" |
---|
[2504] | 1349 | } |
---|
[3330] | 1350 | "volumeWireframe" { |
---|
| 1351 | set bool $_settings(volumeWireframe) |
---|
[3400] | 1352 | SendCmd "polydata wireframe $bool" |
---|
[2504] | 1353 | } |
---|
[3330] | 1354 | "volumeVisible" { |
---|
| 1355 | set bool $_settings(volumeVisible) |
---|
[3400] | 1356 | SendCmd "polydata visible $bool" |
---|
[2744] | 1357 | if { $bool } { |
---|
| 1358 | Rappture::Tooltip::for $itk_component(volume) \ |
---|
| 1359 | "Hide the volume" |
---|
| 1360 | } else { |
---|
| 1361 | Rappture::Tooltip::for $itk_component(volume) \ |
---|
| 1362 | "Show the volume" |
---|
| 1363 | } |
---|
[2504] | 1364 | } |
---|
[3330] | 1365 | "volumeLighting" { |
---|
| 1366 | set bool $_settings(volumeLighting) |
---|
[3400] | 1367 | SendCmd "polydata lighting $bool" |
---|
[2504] | 1368 | } |
---|
[3330] | 1369 | "volumeEdges" { |
---|
| 1370 | set bool $_settings(volumeEdges) |
---|
[3400] | 1371 | SendCmd "polydata edges $bool" |
---|
[2504] | 1372 | } |
---|
[3330] | 1373 | "axesVisible" { |
---|
| 1374 | set bool $_settings(axesVisible) |
---|
[2744] | 1375 | SendCmd "axis visible all $bool" |
---|
[2504] | 1376 | } |
---|
[3330] | 1377 | "axisLabelsVisible" { |
---|
| 1378 | set bool $_settings(axisLabelsVisible) |
---|
[2744] | 1379 | SendCmd "axis labels all $bool" |
---|
[2504] | 1380 | } |
---|
[3330] | 1381 | "axisXGrid" - "axisYGrid" - "axisZGrid" { |
---|
| 1382 | set axis [string tolower [string range $what 4 4]] |
---|
[2744] | 1383 | set bool $_settings($what) |
---|
| 1384 | SendCmd "axis grid $axis $bool" |
---|
[2504] | 1385 | } |
---|
| 1386 | "axis-mode" { |
---|
[2744] | 1387 | set mode [$itk_component(axismode) value] |
---|
| 1388 | set mode [$itk_component(axismode) translate $mode] |
---|
| 1389 | set _settings($what) $mode |
---|
| 1390 | SendCmd "axis flymode $mode" |
---|
[2504] | 1391 | } |
---|
[3330] | 1392 | "cutplaneEdges" { |
---|
[2744] | 1393 | set bool $_settings($what) |
---|
[3400] | 1394 | SendCmd "cutplane edges $bool" |
---|
[2587] | 1395 | } |
---|
[3330] | 1396 | "cutplaneVisible" { |
---|
[2744] | 1397 | set bool $_settings($what) |
---|
[3400] | 1398 | SendCmd "cutplane visible $bool" |
---|
[2587] | 1399 | } |
---|
[3330] | 1400 | "cutplaneWireframe" { |
---|
[2744] | 1401 | set bool $_settings($what) |
---|
[3400] | 1402 | SendCmd "cutplane wireframe $bool" |
---|
[2587] | 1403 | } |
---|
[3330] | 1404 | "cutplaneLighting" { |
---|
[2744] | 1405 | set bool $_settings($what) |
---|
[3400] | 1406 | SendCmd "cutplane lighting $bool" |
---|
[2587] | 1407 | } |
---|
[3330] | 1408 | "cutplaneOpacity" { |
---|
[2744] | 1409 | set val $_settings($what) |
---|
| 1410 | set sval [expr { 0.01 * double($val) }] |
---|
[3400] | 1411 | SendCmd "cutplane opacity $sval" |
---|
[2587] | 1412 | } |
---|
[3330] | 1413 | "cutplaneXVisible" - "cutplaneYVisible" - "cutplaneZVisible" { |
---|
| 1414 | set axis [string tolower [string range $what 8 8]] |
---|
[2744] | 1415 | set bool $_settings($what) |
---|
[2504] | 1416 | if { $bool } { |
---|
| 1417 | $itk_component(${axis}CutScale) configure -state normal \ |
---|
| 1418 | -troughcolor white |
---|
| 1419 | } else { |
---|
| 1420 | $itk_component(${axis}CutScale) configure -state disabled \ |
---|
| 1421 | -troughcolor grey82 |
---|
| 1422 | } |
---|
[3400] | 1423 | SendCmd "cutplane axis $axis $bool" |
---|
[2744] | 1424 | } |
---|
[3330] | 1425 | "cutplaneXPosition" - "cutplaneYPosition" - "cutplaneZPosition" { |
---|
| 1426 | set axis [string tolower [string range $what 8 8]] |
---|
[2744] | 1427 | set pos [expr $_settings($what) * 0.01] |
---|
[3400] | 1428 | SendCmd "cutplane slice ${axis} ${pos}" |
---|
[2744] | 1429 | set _cutplanePending 0 |
---|
| 1430 | } |
---|
[3330] | 1431 | "streamlinesSeedsVisible" { |
---|
[2744] | 1432 | set bool $_settings($what) |
---|
[3400] | 1433 | SendCmd "streamlines seed visible $bool" |
---|
[2504] | 1434 | } |
---|
[3330] | 1435 | "streamlinesNumSeeds" { |
---|
[2744] | 1436 | set density $_settings($what) |
---|
| 1437 | EventuallyReseed $density |
---|
[2579] | 1438 | } |
---|
[3330] | 1439 | "streamlinesVisible" { |
---|
[2744] | 1440 | set bool $_settings($what) |
---|
[3400] | 1441 | SendCmd "streamlines visible $bool" |
---|
[2744] | 1442 | if { $bool } { |
---|
| 1443 | Rappture::Tooltip::for $itk_component(streamlines) \ |
---|
| 1444 | "Hide the streamlines" |
---|
| 1445 | } else { |
---|
| 1446 | Rappture::Tooltip::for $itk_component(streamlines) \ |
---|
| 1447 | "Show the streamlines" |
---|
| 1448 | } |
---|
[2504] | 1449 | } |
---|
[3330] | 1450 | "streamlinesMode" { |
---|
[2744] | 1451 | set mode [$itk_component(streammode) value] |
---|
[3330] | 1452 | set _settings(streamlinesMode) $mode |
---|
[3400] | 1453 | switch -- $mode { |
---|
| 1454 | "lines" { |
---|
| 1455 | SendCmd "streamlines lines" |
---|
[2744] | 1456 | } |
---|
[3400] | 1457 | "ribbons" { |
---|
| 1458 | SendCmd "streamlines ribbons 3 0" |
---|
| 1459 | } |
---|
| 1460 | "tubes" { |
---|
| 1461 | SendCmd "streamlines tubes 5 3" |
---|
| 1462 | } |
---|
[2504] | 1463 | } |
---|
| 1464 | } |
---|
[3442] | 1465 | "streamlinesColormap" { |
---|
| 1466 | set colormap [$itk_component(colormap) value] |
---|
| 1467 | set _settings(streamlinesColormap) $colormap |
---|
[2744] | 1468 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
| 1469 | foreach {dataobj comp} [split $dataset -] break |
---|
[3442] | 1470 | ChangeColormap $dataobj $comp $colormap |
---|
[2586] | 1471 | } |
---|
[2744] | 1472 | set _legendPending 1 |
---|
[2586] | 1473 | } |
---|
[3330] | 1474 | "streamlinesOpacity" { |
---|
| 1475 | set val $_settings(streamlinesOpacity) |
---|
[2744] | 1476 | set sval [expr { 0.01 * double($val) }] |
---|
[3400] | 1477 | SendCmd "streamlines opacity $sval" |
---|
[2504] | 1478 | } |
---|
[3330] | 1479 | "streamlinesScale" { |
---|
| 1480 | set val $_settings(streamlinesScale) |
---|
[2744] | 1481 | set sval [expr { 0.01 * double($val) }] |
---|
[3400] | 1482 | SendCmd "streamlines scale $sval $sval $sval" |
---|
[2579] | 1483 | } |
---|
[3330] | 1484 | "streamlinesLighting" { |
---|
| 1485 | set bool $_settings(streamlinesLighting) |
---|
[3400] | 1486 | SendCmd "streamlines lighting $bool" |
---|
[2579] | 1487 | } |
---|
[3421] | 1488 | "field" { |
---|
[3405] | 1489 | set label [$itk_component(field) value] |
---|
| 1490 | set fname [$itk_component(field) translate $label] |
---|
[3421] | 1491 | set _settings(field) $fname |
---|
[3405] | 1492 | if { [info exists _fields($fname)] } { |
---|
| 1493 | foreach { label units components } $_fields($fname) break |
---|
| 1494 | if { $components > 1 } { |
---|
| 1495 | set _colorMode vmag |
---|
| 1496 | } else { |
---|
| 1497 | set _colorMode scalar |
---|
| 1498 | } |
---|
| 1499 | set _curFldName $fname |
---|
| 1500 | set _curFldLabel $label |
---|
[2744] | 1501 | } else { |
---|
[3405] | 1502 | puts stderr "unknown field \"$fname\"" |
---|
[2744] | 1503 | return |
---|
[2584] | 1504 | } |
---|
[3421] | 1505 | # Get the new limits because the field changed. |
---|
[3442] | 1506 | SendCmd "dataset maprange explicit $_limits($_curFldName) $_curFldName" |
---|
| 1507 | SendCmd "streamlines colormode $_colorMode $_curFldName" |
---|
| 1508 | SendCmd "cutplane colormode $_colorMode $_curFldName" |
---|
| 1509 | DrawLegend |
---|
[2584] | 1510 | } |
---|
[2504] | 1511 | default { |
---|
| 1512 | error "don't know how to fix $what" |
---|
| 1513 | } |
---|
| 1514 | } |
---|
| 1515 | } |
---|
| 1516 | |
---|
| 1517 | # |
---|
| 1518 | # RequestLegend -- |
---|
| 1519 | # |
---|
[2744] | 1520 | # Request a new legend from the server. The size of the legend |
---|
| 1521 | # is determined from the height of the canvas. It will be rotated |
---|
| 1522 | # to be vertical when drawn. |
---|
[2504] | 1523 | # |
---|
[2587] | 1524 | itcl::body Rappture::VtkStreamlinesViewer::RequestLegend {} { |
---|
[2504] | 1525 | set font "Arial 8" |
---|
| 1526 | set lineht [font metrics $font -linespace] |
---|
| 1527 | set c $itk_component(legend) |
---|
| 1528 | set w 12 |
---|
[2584] | 1529 | set h [expr {$_height - 3 * ($lineht + 2)}] |
---|
[2504] | 1530 | if { $h < 1} { |
---|
[2744] | 1531 | return |
---|
[2504] | 1532 | } |
---|
| 1533 | # Set the legend on the first streamlines dataset. |
---|
[2600] | 1534 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
[2744] | 1535 | foreach {dataobj comp} [split $dataset -] break |
---|
| 1536 | if { [info exists _dataset2style($dataset)] } { |
---|
[3421] | 1537 | SendCmdNoWait \ |
---|
[3405] | 1538 | "legend $_dataset2style($dataset) $_colorMode $_curFldName {} $w $h 0" |
---|
[2744] | 1539 | break; |
---|
[2504] | 1540 | } |
---|
| 1541 | } |
---|
| 1542 | } |
---|
| 1543 | |
---|
| 1544 | # |
---|
[2586] | 1545 | # ChangeColormap -- |
---|
| 1546 | # |
---|
| 1547 | itcl::body Rappture::VtkStreamlinesViewer::ChangeColormap {dataobj comp color} { |
---|
| 1548 | set tag $dataobj-$comp |
---|
[2587] | 1549 | if { ![info exist _style($tag)] } { |
---|
[2744] | 1550 | error "no initial colormap" |
---|
[2586] | 1551 | } |
---|
[2587] | 1552 | array set style $_style($tag) |
---|
| 1553 | set style(-color) $color |
---|
| 1554 | set _style($tag) [array get style] |
---|
[2586] | 1555 | SetColormap $dataobj $comp |
---|
| 1556 | } |
---|
| 1557 | |
---|
| 1558 | # |
---|
[2504] | 1559 | # SetColormap -- |
---|
| 1560 | # |
---|
| 1561 | itcl::body Rappture::VtkStreamlinesViewer::SetColormap { dataobj comp } { |
---|
| 1562 | array set style { |
---|
[2786] | 1563 | -color BCGYR |
---|
[2504] | 1564 | -levels 6 |
---|
| 1565 | -opacity 1.0 |
---|
| 1566 | } |
---|
| 1567 | set tag $dataobj-$comp |
---|
[2586] | 1568 | if { ![info exists _initialStyle($tag)] } { |
---|
[2744] | 1569 | # Save the initial component style. |
---|
| 1570 | set _initialStyle($tag) [$dataobj style $comp] |
---|
[2504] | 1571 | } |
---|
[2586] | 1572 | |
---|
| 1573 | # Override defaults with initial style defined in xml. |
---|
| 1574 | array set style $_initialStyle($tag) |
---|
| 1575 | |
---|
| 1576 | if { ![info exists _style($tag)] } { |
---|
[2744] | 1577 | set _style($tag) [array get style] |
---|
[2504] | 1578 | } |
---|
[2586] | 1579 | # Override initial style with current style. |
---|
| 1580 | array set style $_style($tag) |
---|
| 1581 | |
---|
| 1582 | set name "$style(-color):$style(-levels):$style(-opacity)" |
---|
| 1583 | if { ![info exists _colormaps($name)] } { |
---|
[2744] | 1584 | BuildColormap $name [array get style] |
---|
| 1585 | set _colormaps($name) 1 |
---|
[2504] | 1586 | } |
---|
[2586] | 1587 | if { ![info exists _dataset2style($tag)] || |
---|
[2744] | 1588 | $_dataset2style($tag) != $name } { |
---|
| 1589 | SendCmd "streamlines colormap $name $tag" |
---|
| 1590 | SendCmd "cutplane colormap $name $tag" |
---|
| 1591 | set _dataset2style($tag) $name |
---|
[2586] | 1592 | } |
---|
[2504] | 1593 | } |
---|
| 1594 | |
---|
[2585] | 1595 | |
---|
| 1596 | # |
---|
| 1597 | # BuildColormap -- |
---|
| 1598 | # |
---|
[2586] | 1599 | itcl::body Rappture::VtkStreamlinesViewer::BuildColormap { name styles } { |
---|
| 1600 | array set style $styles |
---|
| 1601 | set cmap [ColorsToColormap $style(-color)] |
---|
[2504] | 1602 | if { [llength $cmap] == 0 } { |
---|
[2744] | 1603 | set cmap "0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0" |
---|
[2504] | 1604 | } |
---|
[3330] | 1605 | if { ![info exists _settings(volumeOpacity)] } { |
---|
| 1606 | set _settings(volumeOpacity) $style(-opacity) |
---|
[2504] | 1607 | } |
---|
[3330] | 1608 | set max $_settings(volumeOpacity) |
---|
[2504] | 1609 | |
---|
| 1610 | set wmap "0.0 1.0 1.0 1.0" |
---|
[2585] | 1611 | SendCmd "colormap add $name { $cmap } { $wmap }" |
---|
[2504] | 1612 | } |
---|
| 1613 | |
---|
| 1614 | # ---------------------------------------------------------------------- |
---|
| 1615 | # CONFIGURATION OPTION: -plotbackground |
---|
| 1616 | # ---------------------------------------------------------------------- |
---|
| 1617 | itcl::configbody Rappture::VtkStreamlinesViewer::plotbackground { |
---|
| 1618 | if { [isconnected] } { |
---|
| 1619 | foreach {r g b} [Color2RGB $itk_option(-plotbackground)] break |
---|
| 1620 | SendCmd "screen bgcolor $r $g $b" |
---|
| 1621 | } |
---|
| 1622 | } |
---|
| 1623 | |
---|
| 1624 | # ---------------------------------------------------------------------- |
---|
| 1625 | # CONFIGURATION OPTION: -plotforeground |
---|
| 1626 | # ---------------------------------------------------------------------- |
---|
| 1627 | itcl::configbody Rappture::VtkStreamlinesViewer::plotforeground { |
---|
| 1628 | if { [isconnected] } { |
---|
| 1629 | foreach {r g b} [Color2RGB $itk_option(-plotforeground)] break |
---|
| 1630 | #fix this! |
---|
| 1631 | #SendCmd "color background $r $g $b" |
---|
| 1632 | } |
---|
| 1633 | } |
---|
| 1634 | |
---|
| 1635 | itcl::body Rappture::VtkStreamlinesViewer::BuildVolumeTab {} { |
---|
| 1636 | |
---|
| 1637 | set fg [option get $itk_component(hull) font Font] |
---|
| 1638 | #set bfg [option get $itk_component(hull) boldFont Font] |
---|
| 1639 | |
---|
| 1640 | set inner [$itk_component(main) insert end \ |
---|
| 1641 | -title "Volume Settings" \ |
---|
| 1642 | -icon [Rappture::icon volume-on]] |
---|
| 1643 | $inner configure -borderwidth 4 |
---|
| 1644 | |
---|
| 1645 | checkbutton $inner.volume \ |
---|
| 1646 | -text "Show Volume" \ |
---|
[3330] | 1647 | -variable [itcl::scope _settings(volumeVisible)] \ |
---|
| 1648 | -command [itcl::code $this AdjustSetting volumeVisible] \ |
---|
[2504] | 1649 | -font "Arial 9" |
---|
| 1650 | |
---|
| 1651 | checkbutton $inner.wireframe \ |
---|
| 1652 | -text "Show Wireframe" \ |
---|
[3330] | 1653 | -variable [itcl::scope _settings(volumeWireframe)] \ |
---|
| 1654 | -command [itcl::code $this AdjustSetting volumeWireframe] \ |
---|
[2504] | 1655 | -font "Arial 9" |
---|
| 1656 | |
---|
| 1657 | checkbutton $inner.lighting \ |
---|
| 1658 | -text "Enable Lighting" \ |
---|
[3330] | 1659 | -variable [itcl::scope _settings(volumeLighting)] \ |
---|
| 1660 | -command [itcl::code $this AdjustSetting volumeLighting] \ |
---|
[2504] | 1661 | -font "Arial 9" |
---|
| 1662 | |
---|
| 1663 | checkbutton $inner.edges \ |
---|
| 1664 | -text "Show Edges" \ |
---|
[3330] | 1665 | -variable [itcl::scope _settings(volumeEdges)] \ |
---|
| 1666 | -command [itcl::code $this AdjustSetting volumeEdges] \ |
---|
[2504] | 1667 | -font "Arial 9" |
---|
| 1668 | |
---|
| 1669 | label $inner.opacity_l -text "Opacity" -font "Arial 9" |
---|
| 1670 | ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ |
---|
[3330] | 1671 | -variable [itcl::scope _settings(volumeOpacity)] \ |
---|
[2504] | 1672 | -width 10 \ |
---|
| 1673 | -showvalue off \ |
---|
[3330] | 1674 | -command [itcl::code $this AdjustSetting volumeOpacity] |
---|
[2504] | 1675 | |
---|
| 1676 | blt::table $inner \ |
---|
[3330] | 1677 | 0,0 $inner.wireframe -anchor w -pady 2 -cspan 2 \ |
---|
| 1678 | 1,0 $inner.lighting -anchor w -pady 2 -cspan 2 \ |
---|
| 1679 | 2,0 $inner.edges -anchor w -pady 2 -cspan 3 \ |
---|
| 1680 | 3,0 $inner.opacity_l -anchor w -pady 2 \ |
---|
| 1681 | 3,1 $inner.opacity -fill x -pady 2 |
---|
[2504] | 1682 | |
---|
| 1683 | blt::table configure $inner r* c* -resize none |
---|
[3330] | 1684 | blt::table configure $inner r4 c1 -resize expand |
---|
[2504] | 1685 | } |
---|
| 1686 | |
---|
| 1687 | |
---|
| 1688 | itcl::body Rappture::VtkStreamlinesViewer::BuildStreamsTab {} { |
---|
| 1689 | |
---|
| 1690 | set fg [option get $itk_component(hull) font Font] |
---|
| 1691 | #set bfg [option get $itk_component(hull) boldFont Font] |
---|
| 1692 | |
---|
| 1693 | set inner [$itk_component(main) insert end \ |
---|
| 1694 | -title "Streams Settings" \ |
---|
[2585] | 1695 | -icon [Rappture::icon streamlines-on]] |
---|
[2504] | 1696 | $inner configure -borderwidth 4 |
---|
| 1697 | |
---|
| 1698 | checkbutton $inner.streamlines \ |
---|
| 1699 | -text "Show Streamlines" \ |
---|
[3330] | 1700 | -variable [itcl::scope _settings(streamlinesVisible)] \ |
---|
| 1701 | -command [itcl::code $this AdjustSetting streamlinesVisible] \ |
---|
[2504] | 1702 | -font "Arial 9" |
---|
[2585] | 1703 | |
---|
[2579] | 1704 | checkbutton $inner.lighting \ |
---|
| 1705 | -text "Enable Lighting" \ |
---|
[3330] | 1706 | -variable [itcl::scope _settings(streamlinesLighting)] \ |
---|
| 1707 | -command [itcl::code $this AdjustSetting streamlinesLighting] \ |
---|
[2579] | 1708 | -font "Arial 9" |
---|
| 1709 | |
---|
[2504] | 1710 | checkbutton $inner.seeds \ |
---|
| 1711 | -text "Show Seeds" \ |
---|
[3330] | 1712 | -variable [itcl::scope _settings(streamlinesSeedsVisible)] \ |
---|
| 1713 | -command [itcl::code $this AdjustSetting streamlinesSeedsVisible] \ |
---|
[2504] | 1714 | -font "Arial 9" |
---|
| 1715 | |
---|
| 1716 | label $inner.mode_l -text "Mode" -font "Arial 9" |
---|
| 1717 | itk_component add streammode { |
---|
[2744] | 1718 | Rappture::Combobox $inner.mode -width 10 -editable no |
---|
[2504] | 1719 | } |
---|
| 1720 | $inner.mode choices insert end \ |
---|
| 1721 | "lines" "lines" \ |
---|
| 1722 | "ribbons" "ribbons" \ |
---|
| 1723 | "tubes" "tubes" |
---|
[3330] | 1724 | $itk_component(streammode) value $_settings(streamlinesMode) |
---|
| 1725 | bind $inner.mode <<Value>> [itcl::code $this AdjustSetting streamlinesMode] |
---|
[2504] | 1726 | |
---|
| 1727 | label $inner.opacity_l -text "Opacity" -font "Arial 9" |
---|
| 1728 | ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ |
---|
[3330] | 1729 | -variable [itcl::scope _settings(streamlinesOpacity)] \ |
---|
[2504] | 1730 | -width 10 \ |
---|
| 1731 | -showvalue off \ |
---|
[3330] | 1732 | -command [itcl::code $this AdjustSetting streamlinesOpacity] |
---|
[2504] | 1733 | |
---|
[3330] | 1734 | label $inner.density_l -text "No. Seeds" -font "Arial 9" |
---|
[2587] | 1735 | ::scale $inner.density -from 1 -to 1000 -orient horizontal \ |
---|
[3330] | 1736 | -variable [itcl::scope _settings(streamlinesNumSeeds)] \ |
---|
[2579] | 1737 | -width 10 \ |
---|
[2587] | 1738 | -showvalue on \ |
---|
[3330] | 1739 | -command [itcl::code $this AdjustSetting streamlinesNumSeeds] |
---|
[2579] | 1740 | |
---|
| 1741 | label $inner.scale_l -text "Scale" -font "Arial 9" |
---|
| 1742 | ::scale $inner.scale -from 1 -to 100 -orient horizontal \ |
---|
[3330] | 1743 | -variable [itcl::scope _settings(streamlinesScale)] \ |
---|
[2579] | 1744 | -width 10 \ |
---|
| 1745 | -showvalue off \ |
---|
[3330] | 1746 | -command [itcl::code $this AdjustSetting streamlinesScale] |
---|
[2579] | 1747 | |
---|
[2584] | 1748 | label $inner.field_l -text "Field" -font "Arial 9" |
---|
| 1749 | itk_component add field { |
---|
[2744] | 1750 | Rappture::Combobox $inner.field -width 10 -editable no |
---|
[2584] | 1751 | } |
---|
| 1752 | bind $inner.field <<Value>> \ |
---|
[3421] | 1753 | [itcl::code $this AdjustSetting field] |
---|
[2584] | 1754 | |
---|
[3442] | 1755 | label $inner.colormap_l -text "Colormap" -font "Arial 9" |
---|
| 1756 | itk_component add colormap { |
---|
| 1757 | Rappture::Combobox $inner.colormap -width 10 -editable no |
---|
[2586] | 1758 | } |
---|
[3442] | 1759 | $inner.colormap choices insert end \ |
---|
[2744] | 1760 | "BCGYR" "BCGYR" \ |
---|
| 1761 | "BGYOR" "BGYOR" \ |
---|
| 1762 | "blue" "blue" \ |
---|
| 1763 | "blue-to-brown" "blue-to-brown" \ |
---|
| 1764 | "blue-to-orange" "blue-to-orange" \ |
---|
| 1765 | "blue-to-grey" "blue-to-grey" \ |
---|
| 1766 | "green-to-magenta" "green-to-magenta" \ |
---|
| 1767 | "greyscale" "greyscale" \ |
---|
| 1768 | "nanohub" "nanohub" \ |
---|
| 1769 | "rainbow" "rainbow" \ |
---|
| 1770 | "spectral" "spectral" \ |
---|
| 1771 | "ROYGB" "ROYGB" \ |
---|
| 1772 | "RYGCB" "RYGCB" \ |
---|
| 1773 | "brown-to-blue" "brown-to-blue" \ |
---|
| 1774 | "grey-to-blue" "grey-to-blue" \ |
---|
| 1775 | "orange-to-blue" "orange-to-blue" |
---|
[2587] | 1776 | |
---|
[3442] | 1777 | $itk_component(colormap) value "BCGYR" |
---|
| 1778 | bind $inner.colormap <<Value>> \ |
---|
| 1779 | [itcl::code $this AdjustSetting streamlinesColormap] |
---|
[2586] | 1780 | |
---|
[2504] | 1781 | blt::table $inner \ |
---|
[3442] | 1782 | 0,0 $inner.field_l -anchor w -pady 2 \ |
---|
| 1783 | 0,1 $inner.field -fill x -pady 2 \ |
---|
| 1784 | 1,0 $inner.colormap_l -anchor w -pady 2 \ |
---|
| 1785 | 1,1 $inner.colormap -fill x -pady 2 \ |
---|
[3330] | 1786 | 2,0 $inner.mode_l -anchor w -pady 2 \ |
---|
| 1787 | 2,1 $inner.mode -fill x -pady 2 \ |
---|
| 1788 | 3,0 $inner.opacity_l -anchor w -pady 2 \ |
---|
[3442] | 1789 | 3,1 $inner.opacity -fill x -pady 2 \ |
---|
[3330] | 1790 | 5,0 $inner.lighting -anchor w -pady 2 -cspan 2 \ |
---|
| 1791 | 6,0 $inner.seeds -anchor w -pady 2 -cspan 2 \ |
---|
| 1792 | 7,0 $inner.density_l -anchor w -pady 2 \ |
---|
| 1793 | 7,1 $inner.density -fill x -pady 2 \ |
---|
[2504] | 1794 | |
---|
| 1795 | blt::table configure $inner r* c* -resize none |
---|
[2586] | 1796 | blt::table configure $inner r10 c1 c2 -resize expand |
---|
[2504] | 1797 | } |
---|
| 1798 | |
---|
| 1799 | itcl::body Rappture::VtkStreamlinesViewer::BuildAxisTab {} { |
---|
| 1800 | |
---|
| 1801 | set fg [option get $itk_component(hull) font Font] |
---|
| 1802 | #set bfg [option get $itk_component(hull) boldFont Font] |
---|
| 1803 | |
---|
| 1804 | set inner [$itk_component(main) insert end \ |
---|
| 1805 | -title "Axis Settings" \ |
---|
| 1806 | -icon [Rappture::icon axis1]] |
---|
| 1807 | $inner configure -borderwidth 4 |
---|
| 1808 | |
---|
| 1809 | checkbutton $inner.visible \ |
---|
| 1810 | -text "Show Axes" \ |
---|
[3330] | 1811 | -variable [itcl::scope _settings(axesVisible)] \ |
---|
| 1812 | -command [itcl::code $this AdjustSetting axesVisible] \ |
---|
[2504] | 1813 | -font "Arial 9" |
---|
| 1814 | |
---|
| 1815 | checkbutton $inner.labels \ |
---|
| 1816 | -text "Show Axis Labels" \ |
---|
[3330] | 1817 | -variable [itcl::scope _settings(axisLabelsVisible)] \ |
---|
| 1818 | -command [itcl::code $this AdjustSetting axisLabelsVisible] \ |
---|
[2504] | 1819 | -font "Arial 9" |
---|
| 1820 | |
---|
[3330] | 1821 | checkbutton $inner.xgrid \ |
---|
[2504] | 1822 | -text "Show X Grid" \ |
---|
[3330] | 1823 | -variable [itcl::scope _settings(axisXGrid)] \ |
---|
| 1824 | -command [itcl::code $this AdjustSetting axisXGrid] \ |
---|
[2504] | 1825 | -font "Arial 9" |
---|
[3330] | 1826 | checkbutton $inner.ygrid \ |
---|
[2504] | 1827 | -text "Show Y Grid" \ |
---|
[3330] | 1828 | -variable [itcl::scope _settings(axisYGrid)] \ |
---|
| 1829 | -command [itcl::code $this AdjustSetting axisYGrid] \ |
---|
[2504] | 1830 | -font "Arial 9" |
---|
[3330] | 1831 | checkbutton $inner.zgrid \ |
---|
[2504] | 1832 | -text "Show Z Grid" \ |
---|
[3330] | 1833 | -variable [itcl::scope _settings(axisZGrid)] \ |
---|
| 1834 | -command [itcl::code $this AdjustSetting axisZGrid] \ |
---|
[2504] | 1835 | -font "Arial 9" |
---|
| 1836 | |
---|
| 1837 | label $inner.mode_l -text "Mode" -font "Arial 9" |
---|
| 1838 | |
---|
| 1839 | itk_component add axismode { |
---|
[2744] | 1840 | Rappture::Combobox $inner.mode -width 10 -editable no |
---|
[2504] | 1841 | } |
---|
| 1842 | $inner.mode choices insert end \ |
---|
| 1843 | "static_triad" "static" \ |
---|
| 1844 | "closest_triad" "closest" \ |
---|
| 1845 | "furthest_triad" "furthest" \ |
---|
| 1846 | "outer_edges" "outer" |
---|
| 1847 | $itk_component(axismode) value "static" |
---|
| 1848 | bind $inner.mode <<Value>> [itcl::code $this AdjustSetting axis-mode] |
---|
| 1849 | |
---|
| 1850 | blt::table $inner \ |
---|
| 1851 | 0,0 $inner.visible -anchor w -cspan 2 \ |
---|
| 1852 | 1,0 $inner.labels -anchor w -cspan 2 \ |
---|
[3330] | 1853 | 2,0 $inner.xgrid -anchor w -cspan 2 \ |
---|
| 1854 | 3,0 $inner.ygrid -anchor w -cspan 2 \ |
---|
| 1855 | 4,0 $inner.zgrid -anchor w -cspan 2 \ |
---|
[2504] | 1856 | 5,0 $inner.mode_l -anchor w -cspan 2 -padx { 2 0 } \ |
---|
| 1857 | 6,0 $inner.mode -fill x -cspan 2 |
---|
| 1858 | |
---|
| 1859 | blt::table configure $inner r* c* -resize none |
---|
| 1860 | blt::table configure $inner r7 c1 -resize expand |
---|
| 1861 | } |
---|
| 1862 | |
---|
| 1863 | |
---|
| 1864 | itcl::body Rappture::VtkStreamlinesViewer::BuildCameraTab {} { |
---|
| 1865 | set inner [$itk_component(main) insert end \ |
---|
| 1866 | -title "Camera Settings" \ |
---|
| 1867 | -icon [Rappture::icon camera]] |
---|
| 1868 | $inner configure -borderwidth 4 |
---|
| 1869 | |
---|
| 1870 | set labels { qx qy qz qw xpan ypan zoom } |
---|
| 1871 | set row 0 |
---|
| 1872 | foreach tag $labels { |
---|
| 1873 | label $inner.${tag}label -text $tag -font "Arial 9" |
---|
| 1874 | entry $inner.${tag} -font "Arial 9" -bg white \ |
---|
| 1875 | -textvariable [itcl::scope _view($tag)] |
---|
| 1876 | bind $inner.${tag} <KeyPress-Return> \ |
---|
| 1877 | [itcl::code $this camera set ${tag}] |
---|
| 1878 | blt::table $inner \ |
---|
| 1879 | $row,0 $inner.${tag}label -anchor e -pady 2 \ |
---|
| 1880 | $row,1 $inner.${tag} -anchor w -pady 2 |
---|
| 1881 | blt::table configure $inner r$row -resize none |
---|
| 1882 | incr row |
---|
| 1883 | } |
---|
| 1884 | checkbutton $inner.ortho \ |
---|
| 1885 | -text "Orthographic Projection" \ |
---|
| 1886 | -variable [itcl::scope _view(ortho)] \ |
---|
| 1887 | -command [itcl::code $this camera set ortho] \ |
---|
| 1888 | -font "Arial 9" |
---|
| 1889 | blt::table $inner \ |
---|
[3441] | 1890 | $row,0 $inner.ortho -cspan 2 -anchor w -pady 2 |
---|
[2504] | 1891 | blt::table configure $inner r$row -resize none |
---|
| 1892 | incr row |
---|
| 1893 | |
---|
| 1894 | blt::table configure $inner c0 c1 -resize none |
---|
| 1895 | blt::table configure $inner c2 -resize expand |
---|
| 1896 | blt::table configure $inner r$row -resize expand |
---|
| 1897 | } |
---|
| 1898 | |
---|
[2584] | 1899 | itcl::body Rappture::VtkStreamlinesViewer::BuildCutplaneTab {} { |
---|
[2504] | 1900 | |
---|
| 1901 | set fg [option get $itk_component(hull) font Font] |
---|
| 1902 | |
---|
| 1903 | set inner [$itk_component(main) insert end \ |
---|
[2587] | 1904 | -title "Cutplane Settings" \ |
---|
[2744] | 1905 | -icon [Rappture::icon cutbutton]] |
---|
[2504] | 1906 | |
---|
| 1907 | $inner configure -borderwidth 4 |
---|
| 1908 | |
---|
[2587] | 1909 | checkbutton $inner.visible \ |
---|
| 1910 | -text "Show Cutplanes" \ |
---|
[3330] | 1911 | -variable [itcl::scope _settings(cutplaneVisible)] \ |
---|
| 1912 | -command [itcl::code $this AdjustSetting cutplaneVisible] \ |
---|
[2587] | 1913 | -font "Arial 9" |
---|
| 1914 | |
---|
| 1915 | checkbutton $inner.wireframe \ |
---|
| 1916 | -text "Show Wireframe" \ |
---|
[3330] | 1917 | -variable [itcl::scope _settings(cutplaneWireframe)] \ |
---|
| 1918 | -command [itcl::code $this AdjustSetting cutplaneWireframe] \ |
---|
[2587] | 1919 | -font "Arial 9" |
---|
| 1920 | |
---|
| 1921 | checkbutton $inner.lighting \ |
---|
| 1922 | -text "Enable Lighting" \ |
---|
[3330] | 1923 | -variable [itcl::scope _settings(cutplaneLighting)] \ |
---|
| 1924 | -command [itcl::code $this AdjustSetting cutplaneLighting] \ |
---|
[2587] | 1925 | -font "Arial 9" |
---|
| 1926 | |
---|
| 1927 | checkbutton $inner.edges \ |
---|
| 1928 | -text "Show Edges" \ |
---|
[3330] | 1929 | -variable [itcl::scope _settings(cutplaneEdges)] \ |
---|
| 1930 | -command [itcl::code $this AdjustSetting cutplaneEdges] \ |
---|
[2587] | 1931 | -font "Arial 9" |
---|
| 1932 | |
---|
| 1933 | label $inner.opacity_l -text "Opacity" -font "Arial 9" |
---|
| 1934 | ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ |
---|
[3330] | 1935 | -variable [itcl::scope _settings(cutplaneOpacity)] \ |
---|
[2587] | 1936 | -width 10 \ |
---|
| 1937 | -showvalue off \ |
---|
[3330] | 1938 | -command [itcl::code $this AdjustSetting cutplaneOpacity] |
---|
| 1939 | $inner.opacity set $_settings(cutplaneOpacity) |
---|
[2587] | 1940 | |
---|
[2504] | 1941 | # X-value slicer... |
---|
| 1942 | itk_component add xCutButton { |
---|
| 1943 | Rappture::PushButton $inner.xbutton \ |
---|
[3330] | 1944 | -onimage [Rappture::icon x-cutplane-red] \ |
---|
| 1945 | -offimage [Rappture::icon x-cutplane-red] \ |
---|
| 1946 | -command [itcl::code $this AdjustSetting cutplaneXVisible] \ |
---|
| 1947 | -variable [itcl::scope _settings(cutplaneXVisible)] |
---|
[2504] | 1948 | } |
---|
| 1949 | Rappture::Tooltip::for $itk_component(xCutButton) \ |
---|
[2584] | 1950 | "Toggle the X-axis cutplane on/off" |
---|
[3330] | 1951 | $itk_component(xCutButton) select |
---|
[2504] | 1952 | |
---|
| 1953 | itk_component add xCutScale { |
---|
[3330] | 1954 | ::scale $inner.xval -from 100 -to 0 \ |
---|
[2504] | 1955 | -width 10 -orient vertical -showvalue yes \ |
---|
| 1956 | -borderwidth 1 -highlightthickness 0 \ |
---|
[2584] | 1957 | -command [itcl::code $this EventuallySetCutplane x] \ |
---|
[3330] | 1958 | -variable [itcl::scope _settings(cutplaneXPosition)] \ |
---|
| 1959 | -foreground red3 -font "Arial 9 bold" |
---|
[2504] | 1960 | } { |
---|
| 1961 | usual |
---|
[3330] | 1962 | ignore -borderwidth -highlightthickness -foreground -font |
---|
[2504] | 1963 | } |
---|
[2584] | 1964 | # Set the default cutplane value before disabling the scale. |
---|
[2600] | 1965 | $itk_component(xCutScale) set 50 |
---|
[2504] | 1966 | $itk_component(xCutScale) configure -state disabled |
---|
| 1967 | Rappture::Tooltip::for $itk_component(xCutScale) \ |
---|
| 1968 | "@[itcl::code $this Slice tooltip x]" |
---|
| 1969 | |
---|
| 1970 | # Y-value slicer... |
---|
| 1971 | itk_component add yCutButton { |
---|
| 1972 | Rappture::PushButton $inner.ybutton \ |
---|
[3330] | 1973 | -onimage [Rappture::icon y-cutplane-green] \ |
---|
| 1974 | -offimage [Rappture::icon y-cutplane-green] \ |
---|
| 1975 | -command [itcl::code $this AdjustSetting cutplaneYVisible] \ |
---|
| 1976 | -variable [itcl::scope _settings(cutplaneYVisible)] |
---|
[2504] | 1977 | } |
---|
| 1978 | Rappture::Tooltip::for $itk_component(yCutButton) \ |
---|
[2584] | 1979 | "Toggle the Y-axis cutplane on/off" |
---|
[3330] | 1980 | $itk_component(yCutButton) select |
---|
[2504] | 1981 | |
---|
| 1982 | itk_component add yCutScale { |
---|
[3330] | 1983 | ::scale $inner.yval -from 100 -to 0 \ |
---|
[2504] | 1984 | -width 10 -orient vertical -showvalue yes \ |
---|
| 1985 | -borderwidth 1 -highlightthickness 0 \ |
---|
[2584] | 1986 | -command [itcl::code $this EventuallySetCutplane y] \ |
---|
[3330] | 1987 | -variable [itcl::scope _settings(cutplaneYPosition)] \ |
---|
| 1988 | -foreground green3 -font "Arial 9 bold" |
---|
[2504] | 1989 | } { |
---|
| 1990 | usual |
---|
[3330] | 1991 | ignore -borderwidth -highlightthickness -foreground -font |
---|
[2504] | 1992 | } |
---|
| 1993 | Rappture::Tooltip::for $itk_component(yCutScale) \ |
---|
| 1994 | "@[itcl::code $this Slice tooltip y]" |
---|
[2584] | 1995 | # Set the default cutplane value before disabling the scale. |
---|
[2600] | 1996 | $itk_component(yCutScale) set 50 |
---|
[2504] | 1997 | $itk_component(yCutScale) configure -state disabled |
---|
| 1998 | |
---|
| 1999 | # Z-value slicer... |
---|
| 2000 | itk_component add zCutButton { |
---|
| 2001 | Rappture::PushButton $inner.zbutton \ |
---|
[3330] | 2002 | -onimage [Rappture::icon z-cutplane-blue] \ |
---|
| 2003 | -offimage [Rappture::icon z-cutplane-blue] \ |
---|
| 2004 | -command [itcl::code $this AdjustSetting cutplaneZVisible] \ |
---|
| 2005 | -variable [itcl::scope _settings(cutplaneZVisible)] |
---|
[2504] | 2006 | } |
---|
| 2007 | Rappture::Tooltip::for $itk_component(zCutButton) \ |
---|
[2584] | 2008 | "Toggle the Z-axis cutplane on/off" |
---|
[3330] | 2009 | $itk_component(zCutButton) select |
---|
[2504] | 2010 | |
---|
| 2011 | itk_component add zCutScale { |
---|
[3330] | 2012 | ::scale $inner.zval -from 100 -to 0 \ |
---|
[2504] | 2013 | -width 10 -orient vertical -showvalue yes \ |
---|
| 2014 | -borderwidth 1 -highlightthickness 0 \ |
---|
[2584] | 2015 | -command [itcl::code $this EventuallySetCutplane z] \ |
---|
[3330] | 2016 | -variable [itcl::scope _settings(cutplaneZPosition)] \ |
---|
| 2017 | -foreground blue3 -font "Arial 9 bold" |
---|
[2504] | 2018 | } { |
---|
| 2019 | usual |
---|
[3330] | 2020 | ignore -borderwidth -highlightthickness -foreground -font |
---|
[2504] | 2021 | } |
---|
[2600] | 2022 | $itk_component(zCutScale) set 50 |
---|
[2504] | 2023 | $itk_component(zCutScale) configure -state disabled |
---|
| 2024 | #$itk_component(zCutScale) configure -state disabled |
---|
| 2025 | Rappture::Tooltip::for $itk_component(zCutScale) \ |
---|
| 2026 | "@[itcl::code $this Slice tooltip z]" |
---|
| 2027 | |
---|
| 2028 | blt::table $inner \ |
---|
[3330] | 2029 | 0,0 $inner.lighting -anchor w -pady 2 -cspan 4 \ |
---|
| 2030 | 1,0 $inner.wireframe -anchor w -pady 2 -cspan 4 \ |
---|
| 2031 | 2,0 $inner.edges -anchor w -pady 2 -cspan 4 \ |
---|
| 2032 | 3,0 $inner.opacity_l -anchor w -pady 2 -cspan 1 \ |
---|
| 2033 | 3,1 $inner.opacity -fill x -pady 2 -cspan 3 \ |
---|
| 2034 | 4,0 $itk_component(xCutButton) -anchor w -padx 2 -pady 2 \ |
---|
| 2035 | 5,0 $itk_component(yCutButton) -anchor w -padx 2 -pady 2 \ |
---|
| 2036 | 6,0 $itk_component(zCutButton) -anchor w -padx 2 -pady 2 \ |
---|
| 2037 | 4,1 $itk_component(xCutScale) -fill y -rspan 4 \ |
---|
| 2038 | 4,2 $itk_component(yCutScale) -fill y -rspan 4 \ |
---|
| 2039 | 4,3 $itk_component(zCutScale) -fill y -rspan 4 \ |
---|
[2504] | 2040 | |
---|
| 2041 | blt::table configure $inner r* c* -resize none |
---|
[3330] | 2042 | blt::table configure $inner r7 c4 -resize expand |
---|
[2504] | 2043 | } |
---|
| 2044 | |
---|
| 2045 | |
---|
| 2046 | |
---|
| 2047 | # |
---|
| 2048 | # camera -- |
---|
| 2049 | # |
---|
| 2050 | itcl::body Rappture::VtkStreamlinesViewer::camera {option args} { |
---|
| 2051 | switch -- $option { |
---|
| 2052 | "show" { |
---|
| 2053 | puts [array get _view] |
---|
| 2054 | } |
---|
| 2055 | "set" { |
---|
| 2056 | set who [lindex $args 0] |
---|
| 2057 | set x $_view($who) |
---|
| 2058 | set code [catch { string is double $x } result] |
---|
| 2059 | if { $code != 0 || !$result } { |
---|
| 2060 | return |
---|
| 2061 | } |
---|
| 2062 | switch -- $who { |
---|
| 2063 | "ortho" { |
---|
| 2064 | if {$_view(ortho)} { |
---|
| 2065 | SendCmd "camera mode ortho" |
---|
| 2066 | } else { |
---|
| 2067 | SendCmd "camera mode persp" |
---|
| 2068 | } |
---|
| 2069 | } |
---|
| 2070 | "xpan" - "ypan" { |
---|
| 2071 | PanCamera |
---|
| 2072 | } |
---|
| 2073 | "qx" - "qy" - "qz" - "qw" { |
---|
| 2074 | set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] |
---|
[2744] | 2075 | $_arcball quaternion $q |
---|
| 2076 | EventuallyRotate $q |
---|
[2504] | 2077 | } |
---|
| 2078 | "zoom" { |
---|
| 2079 | SendCmd "camera zoom $_view(zoom)" |
---|
| 2080 | } |
---|
| 2081 | } |
---|
| 2082 | } |
---|
| 2083 | } |
---|
| 2084 | } |
---|
| 2085 | |
---|
| 2086 | itcl::body Rappture::VtkStreamlinesViewer::ConvertToVtkData { dataobj comp } { |
---|
| 2087 | foreach { x1 x2 xN y1 y2 yN } [$dataobj mesh $comp] break |
---|
| 2088 | set values [$dataobj values $comp] |
---|
| 2089 | append out "# vtk DataFile Version 2.0 \n" |
---|
| 2090 | append out "Test data \n" |
---|
| 2091 | append out "ASCII \n" |
---|
| 2092 | append out "DATASET STRUCTURED_POINTS \n" |
---|
| 2093 | append out "DIMENSIONS $xN $yN 1 \n" |
---|
| 2094 | append out "ORIGIN 0 0 0 \n" |
---|
| 2095 | append out "SPACING 1 1 1 \n" |
---|
| 2096 | append out "POINT_DATA [expr $xN * $yN] \n" |
---|
| 2097 | append out "SCALARS field float 1 \n" |
---|
| 2098 | append out "LOOKUP_TABLE default \n" |
---|
| 2099 | append out [join $values "\n"] |
---|
| 2100 | append out "\n" |
---|
| 2101 | return $out |
---|
| 2102 | } |
---|
| 2103 | |
---|
| 2104 | |
---|
| 2105 | itcl::body Rappture::VtkStreamlinesViewer::GetVtkData { args } { |
---|
| 2106 | set bytes "" |
---|
| 2107 | foreach dataobj [get] { |
---|
| 2108 | foreach comp [$dataobj components] { |
---|
| 2109 | set tag $dataobj-$comp |
---|
[2744] | 2110 | #set contents [ConvertToVtkData $dataobj $comp] |
---|
| 2111 | set contents [$dataobj blob $comp] |
---|
| 2112 | append bytes "$contents\n\n" |
---|
[2504] | 2113 | } |
---|
| 2114 | } |
---|
[2584] | 2115 | return [list .vtk $bytes] |
---|
[2504] | 2116 | } |
---|
| 2117 | |
---|
| 2118 | itcl::body Rappture::VtkStreamlinesViewer::GetImage { args } { |
---|
| 2119 | if { [image width $_image(download)] > 0 && |
---|
[2744] | 2120 | [image height $_image(download)] > 0 } { |
---|
| 2121 | set bytes [$_image(download) data -format "jpeg -quality 100"] |
---|
| 2122 | set bytes [Rappture::encoding::decode -as b64 $bytes] |
---|
| 2123 | return [list .jpg $bytes] |
---|
[2504] | 2124 | } |
---|
| 2125 | return "" |
---|
| 2126 | } |
---|
| 2127 | |
---|
| 2128 | itcl::body Rappture::VtkStreamlinesViewer::BuildDownloadPopup { popup command } { |
---|
| 2129 | Rappture::Balloon $popup \ |
---|
| 2130 | -title "[Rappture::filexfer::label downloadWord] as..." |
---|
| 2131 | set inner [$popup component inner] |
---|
| 2132 | label $inner.summary -text "" -anchor w |
---|
| 2133 | radiobutton $inner.vtk_button -text "VTK data file" \ |
---|
| 2134 | -variable [itcl::scope _downloadPopup(format)] \ |
---|
| 2135 | -font "Helvetica 9 " \ |
---|
| 2136 | -value vtk |
---|
| 2137 | Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file." |
---|
| 2138 | radiobutton $inner.image_button -text "Image File" \ |
---|
| 2139 | -variable [itcl::scope _downloadPopup(format)] \ |
---|
| 2140 | -value image |
---|
| 2141 | Rappture::Tooltip::for $inner.image_button \ |
---|
| 2142 | "Save as digital image." |
---|
| 2143 | |
---|
| 2144 | button $inner.ok -text "Save" \ |
---|
[2744] | 2145 | -highlightthickness 0 -pady 2 -padx 3 \ |
---|
[2504] | 2146 | -command $command \ |
---|
[2744] | 2147 | -compound left \ |
---|
| 2148 | -image [Rappture::icon download] |
---|
[2504] | 2149 | |
---|
| 2150 | button $inner.cancel -text "Cancel" \ |
---|
[2744] | 2151 | -highlightthickness 0 -pady 2 -padx 3 \ |
---|
| 2152 | -command [list $popup deactivate] \ |
---|
| 2153 | -compound left \ |
---|
| 2154 | -image [Rappture::icon cancel] |
---|
[2504] | 2155 | |
---|
| 2156 | blt::table $inner \ |
---|
| 2157 | 0,0 $inner.summary -cspan 2 \ |
---|
| 2158 | 1,0 $inner.vtk_button -anchor w -cspan 2 -padx { 4 0 } \ |
---|
| 2159 | 2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \ |
---|
| 2160 | 4,1 $inner.cancel -width .9i -fill y \ |
---|
| 2161 | 4,0 $inner.ok -padx 2 -width .9i -fill y |
---|
| 2162 | blt::table configure $inner r3 -height 4 |
---|
| 2163 | blt::table configure $inner r4 -pady 4 |
---|
| 2164 | raise $inner.image_button |
---|
| 2165 | $inner.vtk_button invoke |
---|
| 2166 | return $inner |
---|
| 2167 | } |
---|
| 2168 | |
---|
| 2169 | itcl::body Rappture::VtkStreamlinesViewer::SetObjectStyle { dataobj comp } { |
---|
| 2170 | # Parse style string. |
---|
| 2171 | set tag $dataobj-$comp |
---|
| 2172 | set style [$dataobj style $comp] |
---|
| 2173 | array set settings { |
---|
[2744] | 2174 | -color \#808080 |
---|
| 2175 | -edges 0 |
---|
| 2176 | -edgecolor black |
---|
| 2177 | -linewidth 1.0 |
---|
| 2178 | -opacity 0.4 |
---|
| 2179 | -wireframe 0 |
---|
| 2180 | -lighting 1 |
---|
| 2181 | -seeds 1 |
---|
| 2182 | -seedcolor white |
---|
| 2183 | -visible 1 |
---|
[2504] | 2184 | } |
---|
[2600] | 2185 | if { $dataobj != $_first } { |
---|
[2744] | 2186 | set settings(-opacity) 1 |
---|
[2600] | 2187 | } |
---|
[2504] | 2188 | array set settings $style |
---|
| 2189 | SendCmd "streamlines add $tag" |
---|
[2569] | 2190 | SendCmd "streamlines seed visible off $tag" |
---|
[2547] | 2191 | set seeds [$dataobj hints seeds] |
---|
| 2192 | if { $seeds != "" && ![info exists _seeds($dataobj)] } { |
---|
[2744] | 2193 | set length [string length $seeds] |
---|
| 2194 | SendCmd "streamlines seed fmesh 200 data follows $length $tag" |
---|
| 2195 | SendCmd "$seeds" |
---|
| 2196 | set _seeds($dataobj) 1 |
---|
[2547] | 2197 | } |
---|
[2584] | 2198 | SendCmd "cutplane add $tag" |
---|
[2504] | 2199 | SendCmd "polydata add $tag" |
---|
[3330] | 2200 | set _settings(volumeEdges) $settings(-edges) |
---|
| 2201 | set _settings(volumeLighting) $settings(-lighting) |
---|
| 2202 | set _settings(volumeOpacity) $settings(-opacity) |
---|
| 2203 | set _settings(volumeWireframe) $settings(-wireframe) |
---|
| 2204 | set _settings(volumeOpacity) [expr $settings(-opacity) * 100.0] |
---|
[2504] | 2205 | SetColormap $dataobj $comp |
---|
| 2206 | } |
---|
| 2207 | |
---|
| 2208 | itcl::body Rappture::VtkStreamlinesViewer::IsValidObject { dataobj } { |
---|
| 2209 | if {[catch {$dataobj isa Rappture::Field} valid] != 0 || !$valid} { |
---|
[2744] | 2210 | return 0 |
---|
[2504] | 2211 | } |
---|
| 2212 | return 1 |
---|
| 2213 | } |
---|
| 2214 | |
---|
| 2215 | # ---------------------------------------------------------------------- |
---|
| 2216 | # USAGE: ReceiveLegend <colormap> <title> <vmin> <vmax> <size> |
---|
| 2217 | # |
---|
| 2218 | # Invoked automatically whenever the "legend" command comes in from |
---|
| 2219 | # the rendering server. Indicates that binary image data with the |
---|
| 2220 | # specified <size> will follow. |
---|
| 2221 | # ---------------------------------------------------------------------- |
---|
| 2222 | itcl::body Rappture::VtkStreamlinesViewer::ReceiveLegend { colormap title vmin vmax size } { |
---|
[2673] | 2223 | set _legendPending 0 |
---|
[2504] | 2224 | set _title $title |
---|
[2606] | 2225 | regsub {\(mag\)} $title "" _title |
---|
[2504] | 2226 | if { [IsConnected] } { |
---|
| 2227 | set bytes [ReceiveBytes $size] |
---|
| 2228 | if { ![info exists _image(legend)] } { |
---|
| 2229 | set _image(legend) [image create photo] |
---|
| 2230 | } |
---|
| 2231 | $_image(legend) configure -data $bytes |
---|
| 2232 | #puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>" |
---|
[3442] | 2233 | if { [catch {DrawLegend} errs] != 0 } { |
---|
[2744] | 2234 | puts stderr errs=$errs |
---|
| 2235 | } |
---|
[2504] | 2236 | } |
---|
| 2237 | } |
---|
| 2238 | |
---|
| 2239 | # |
---|
| 2240 | # DrawLegend -- |
---|
| 2241 | # |
---|
[2744] | 2242 | # Draws the legend in it's own canvas which resides to the right |
---|
| 2243 | # of the contour plot area. |
---|
[2504] | 2244 | # |
---|
[3442] | 2245 | itcl::body Rappture::VtkStreamlinesViewer::DrawLegend {} { |
---|
| 2246 | set fname $_curFldName |
---|
[2504] | 2247 | set c $itk_component(view) |
---|
| 2248 | set w [winfo width $c] |
---|
| 2249 | set h [winfo height $c] |
---|
| 2250 | set font "Arial 8" |
---|
| 2251 | set lineht [font metrics $font -linespace] |
---|
| 2252 | |
---|
[3442] | 2253 | if { [info exists _fields($fname)] } { |
---|
| 2254 | foreach { title units } $_fields($fname) break |
---|
[2744] | 2255 | if { $units != "" } { |
---|
| 2256 | set title [format "%s (%s)" $title $units] |
---|
| 2257 | } |
---|
[2606] | 2258 | } else { |
---|
[3442] | 2259 | set title $fname |
---|
[2604] | 2260 | } |
---|
[3330] | 2261 | if { $_settings(legendVisible) } { |
---|
[2744] | 2262 | set x [expr $w - 2] |
---|
| 2263 | if { [$c find withtag "legend"] == "" } { |
---|
| 2264 | set y 2 |
---|
| 2265 | $c create text $x $y \ |
---|
| 2266 | -anchor ne \ |
---|
| 2267 | -fill $itk_option(-plotforeground) -tags "title legend" \ |
---|
| 2268 | -font $font |
---|
| 2269 | incr y $lineht |
---|
| 2270 | $c create text $x $y \ |
---|
| 2271 | -anchor ne \ |
---|
| 2272 | -fill $itk_option(-plotforeground) -tags "vmax legend" \ |
---|
| 2273 | -font $font |
---|
| 2274 | incr y $lineht |
---|
| 2275 | $c create image $x $y \ |
---|
| 2276 | -anchor ne \ |
---|
| 2277 | -image $_image(legend) -tags "colormap legend" |
---|
| 2278 | $c create text $x [expr {$h-2}] \ |
---|
| 2279 | -anchor se \ |
---|
| 2280 | -fill $itk_option(-plotforeground) -tags "vmin legend" \ |
---|
| 2281 | -font $font |
---|
| 2282 | #$c bind colormap <Enter> [itcl::code $this EnterLegend %x %y] |
---|
| 2283 | $c bind colormap <Leave> [itcl::code $this LeaveLegend] |
---|
| 2284 | $c bind colormap <Motion> [itcl::code $this MotionLegend %x %y] |
---|
| 2285 | } |
---|
| 2286 | $c bind title <ButtonPress> [itcl::code $this Combo post] |
---|
| 2287 | $c bind title <Enter> [itcl::code $this Combo activate] |
---|
| 2288 | $c bind title <Leave> [itcl::code $this Combo deactivate] |
---|
| 2289 | # Reset the item coordinates according the current size of the plot. |
---|
| 2290 | $c itemconfigure title -text $title |
---|
[3431] | 2291 | if { [info exists _limits($_curFldName)] } { |
---|
| 2292 | foreach {vmin vmax} $_limits($_curFldName) break |
---|
| 2293 | $c itemconfigure vmin -text [format %g $vmin] |
---|
| 2294 | $c itemconfigure vmax -text [format %g $vmax] |
---|
[2744] | 2295 | } |
---|
| 2296 | set y 2 |
---|
| 2297 | $c coords title $x $y |
---|
| 2298 | incr y $lineht |
---|
| 2299 | $c coords vmax $x $y |
---|
| 2300 | incr y $lineht |
---|
| 2301 | $c coords colormap $x $y |
---|
| 2302 | $c coords vmin $x [expr {$h - 2}] |
---|
[2504] | 2303 | } |
---|
| 2304 | } |
---|
| 2305 | |
---|
| 2306 | # |
---|
| 2307 | # EnterLegend -- |
---|
| 2308 | # |
---|
| 2309 | itcl::body Rappture::VtkStreamlinesViewer::EnterLegend { x y } { |
---|
| 2310 | SetLegendTip $x $y |
---|
| 2311 | } |
---|
| 2312 | |
---|
| 2313 | # |
---|
| 2314 | # MotionLegend -- |
---|
| 2315 | # |
---|
| 2316 | itcl::body Rappture::VtkStreamlinesViewer::MotionLegend { x y } { |
---|
| 2317 | Rappture::Tooltip::tooltip cancel |
---|
| 2318 | set c $itk_component(view) |
---|
| 2319 | SetLegendTip $x $y |
---|
| 2320 | } |
---|
| 2321 | |
---|
| 2322 | # |
---|
| 2323 | # LeaveLegend -- |
---|
| 2324 | # |
---|
| 2325 | itcl::body Rappture::VtkStreamlinesViewer::LeaveLegend { } { |
---|
| 2326 | Rappture::Tooltip::tooltip cancel |
---|
| 2327 | .rappturetooltip configure -icon "" |
---|
| 2328 | } |
---|
| 2329 | |
---|
| 2330 | # |
---|
| 2331 | # SetLegendTip -- |
---|
| 2332 | # |
---|
| 2333 | itcl::body Rappture::VtkStreamlinesViewer::SetLegendTip { x y } { |
---|
| 2334 | set c $itk_component(view) |
---|
| 2335 | set w [winfo width $c] |
---|
| 2336 | set h [winfo height $c] |
---|
| 2337 | set font "Arial 8" |
---|
| 2338 | set lineht [font metrics $font -linespace] |
---|
| 2339 | |
---|
| 2340 | set imgHeight [image height $_image(legend)] |
---|
| 2341 | set coords [$c coords colormap] |
---|
| 2342 | set imgX [expr $w - [image width $_image(legend)] - 2] |
---|
[2584] | 2343 | set imgY [expr $y - 2 * ($lineht + 2)] |
---|
[2504] | 2344 | |
---|
[2606] | 2345 | if { [info exists _fields($_title)] } { |
---|
[2744] | 2346 | foreach { title units } $_fields($_title) break |
---|
| 2347 | if { $units != "" } { |
---|
| 2348 | set title [format "%s (%s)" $title $units] |
---|
| 2349 | } |
---|
[2606] | 2350 | } else { |
---|
[2744] | 2351 | set title $_title |
---|
[2606] | 2352 | } |
---|
[2504] | 2353 | # Make a swatch of the selected color |
---|
| 2354 | if { [catch { $_image(legend) get 10 $imgY } pixel] != 0 } { |
---|
[2744] | 2355 | #puts stderr "out of range: $imgY" |
---|
| 2356 | return |
---|
[2504] | 2357 | } |
---|
| 2358 | if { ![info exists _image(swatch)] } { |
---|
[2744] | 2359 | set _image(swatch) [image create photo -width 24 -height 24] |
---|
[2504] | 2360 | } |
---|
| 2361 | set color [eval format "\#%02x%02x%02x" $pixel] |
---|
| 2362 | $_image(swatch) put black -to 0 0 23 23 |
---|
| 2363 | $_image(swatch) put $color -to 1 1 22 22 |
---|
| 2364 | .rappturetooltip configure -icon $_image(swatch) |
---|
| 2365 | |
---|
| 2366 | # Compute the value of the point |
---|
[3431] | 2367 | if { [info exists _limits($_curFldName)] } { |
---|
| 2368 | foreach {vmin vmax} $_limits($_curFldName) break |
---|
[2744] | 2369 | set t [expr 1.0 - (double($imgY) / double($imgHeight-1))] |
---|
[3431] | 2370 | set value [expr $t * ($vmax - $vmin) + $vmin] |
---|
[2622] | 2371 | } else { |
---|
[2744] | 2372 | set value 0.0 |
---|
[2622] | 2373 | } |
---|
[2504] | 2374 | set tipx [expr $x + 15] |
---|
| 2375 | set tipy [expr $y - 5] |
---|
[2606] | 2376 | Rappture::Tooltip::text $c "$title $value" |
---|
[2504] | 2377 | Rappture::Tooltip::tooltip show $c +$tipx,+$tipy |
---|
| 2378 | } |
---|
| 2379 | |
---|
| 2380 | |
---|
| 2381 | # ---------------------------------------------------------------------- |
---|
| 2382 | # USAGE: Slice move x|y|z <newval> |
---|
| 2383 | # |
---|
| 2384 | # Called automatically when the user drags the slider to move the |
---|
| 2385 | # cut plane that slices 3D data. Gets the current value from the |
---|
| 2386 | # slider and moves the cut plane to the appropriate point in the |
---|
| 2387 | # data set. |
---|
| 2388 | # ---------------------------------------------------------------------- |
---|
| 2389 | itcl::body Rappture::VtkStreamlinesViewer::Slice {option args} { |
---|
| 2390 | switch -- $option { |
---|
| 2391 | "move" { |
---|
| 2392 | set axis [lindex $args 0] |
---|
[2600] | 2393 | set oldval $_settings(axis-${axis}position) |
---|
[2504] | 2394 | set newval [lindex $args 1] |
---|
| 2395 | if {[llength $args] != 2} { |
---|
| 2396 | error "wrong # args: should be \"Slice move x|y|z newval\"" |
---|
| 2397 | } |
---|
| 2398 | set newpos [expr {0.01*$newval}] |
---|
[2584] | 2399 | SendCmd "cutplane slice $axis $newpos" |
---|
[2504] | 2400 | } |
---|
[2744] | 2401 | "tooltip" { |
---|
| 2402 | set axis [lindex $args 0] |
---|
| 2403 | set val [$itk_component(${axis}CutScale) get] |
---|
| 2404 | return "Move the [string toupper $axis] cut plane.\nCurrently: $axis = $val%" |
---|
| 2405 | } |
---|
[2504] | 2406 | default { |
---|
| 2407 | error "bad option \"$option\": should be axis, move, or tooltip" |
---|
| 2408 | } |
---|
| 2409 | } |
---|
| 2410 | } |
---|
[2649] | 2411 | |
---|
| 2412 | |
---|
| 2413 | # ---------------------------------------------------------------------- |
---|
| 2414 | # USAGE: _dropdown post |
---|
| 2415 | # USAGE: _dropdown unpost |
---|
| 2416 | # USAGE: _dropdown select |
---|
| 2417 | # |
---|
| 2418 | # Used internally to handle the dropdown list for this combobox. The |
---|
| 2419 | # post/unpost options are invoked when the list is posted or unposted |
---|
| 2420 | # to manage the relief of the controlling button. The select option |
---|
| 2421 | # is invoked whenever there is a selection from the list, to assign |
---|
| 2422 | # the value back to the gauge. |
---|
| 2423 | # ---------------------------------------------------------------------- |
---|
| 2424 | itcl::body Rappture::VtkStreamlinesViewer::Combo {option} { |
---|
| 2425 | set c $itk_component(view) |
---|
| 2426 | switch -- $option { |
---|
| 2427 | post { |
---|
[2744] | 2428 | foreach { x1 y1 x2 y2 } [$c bbox title] break |
---|
| 2429 | set x1 [expr [winfo width $itk_component(view)] - [winfo reqwidth $itk_component(fieldmenu)]] |
---|
| 2430 | set x [expr $x1 + [winfo rootx $itk_component(view)]] |
---|
| 2431 | set y [expr $y2 + [winfo rooty $itk_component(view)]] |
---|
| 2432 | tk_popup $itk_component(fieldmenu) $x $y |
---|
[2649] | 2433 | } |
---|
| 2434 | activate { |
---|
[2744] | 2435 | $c itemconfigure title -fill red |
---|
[2649] | 2436 | } |
---|
| 2437 | deactivate { |
---|
[2744] | 2438 | $c itemconfigure title -fill white |
---|
[2649] | 2439 | } |
---|
[2744] | 2440 | invoke { |
---|
[3405] | 2441 | $itk_component(field) value $_curFldLabel |
---|
[3421] | 2442 | AdjustSetting field |
---|
[2744] | 2443 | } |
---|
[2649] | 2444 | default { |
---|
| 2445 | error "bad option \"$option\": should be post, unpost, select" |
---|
| 2446 | } |
---|
| 2447 | } |
---|
| 2448 | } |
---|
[3421] | 2449 | |
---|