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