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