- Timestamp:
- Aug 16, 2011, 11:51:03 AM (13 years ago)
- Location:
- trunk/gui/scripts
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/Makefile.in
r2259 r2385 43 43 $(srcdir)/dispatcher.tcl \ 44 44 $(srcdir)/drawing.tcl \ 45 $(srcdir)/drawing3d.tcl \46 45 $(srcdir)/scene.tcl \ 47 46 $(srcdir)/drawingentry.tcl \ … … 129 128 $(srcdir)/visviewer.tcl \ 130 129 $(srcdir)/vtkviewer.tcl \ 131 $(srcdir)/vtkviewer2.tcl \132 130 $(srcdir)/vtkcontourviewer.tcl \ 133 131 $(srcdir)/xylegend.tcl \ -
trunk/gui/scripts/analyzer.tcl
r2266 r2385 547 547 _autoLabel $xmlobj output.$item "Plot" counters 548 548 } 549 scene* - drawing3d* {549 drawing* { 550 550 _autoLabel $xmlobj output.$item "Drawing" counters 551 551 } -
trunk/gui/scripts/drawing.tcl
r1929 r2385 1 # ---------------------------------------------------------------------- 2 # COMPONENT: drawing - 2D drawing of data 1 2 # ---------------------------------------------------------------------- 3 # COMPONENT: drawing - represents a vtk drawing. 4 # 5 # This object represents one field in an XML description of a device. 6 # It simplifies the process of extracting data vectors that represent 7 # the field. 3 8 # ====================================================================== 4 9 # AUTHOR: Michael McLennan, Purdue University 5 # Copyright (c) 2004-200 7Purdue Research Foundation10 # Copyright (c) 2004-2005 Purdue Research Foundation 6 11 # 7 12 # See the file "license.terms" for information on usage and 8 13 # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 9 14 # ====================================================================== 10 package require Itk 11 12 option add *Drawing.width 4i widgetDefault 13 option add *Drawing.height 3i widgetDefault 15 package require Itcl 16 package require BLT 17 package require vtk 18 19 namespace eval Rappture { 20 # forward declaration 21 } 14 22 15 23 itcl::class Rappture::Drawing { 16 inherit itk::Widget 17 18 # constructor {owner path args} { 19 # Rappture::ControlOwner::constructor $owner 20 # } { # defined below } 21 constructor {owner path args} { # defined below } 22 private variable _xmlobj "" 23 private variable _owner "" 24 private variable _path "" 25 26 public method value {args} 27 public method hilite {elem state} 28 public method activate {elem x y} 29 30 protected method _buildPopup {elem} 31 32 private variable _elem2popup ;# maps drawing elem => popup of controls 33 } 34 35 itk::usual Drawing { 36 keep -cursor -background 37 } 38 39 # ---------------------------------------------------------------------- 40 # CONSTRUCTOR 41 # ---------------------------------------------------------------------- 42 itcl::body Rappture::Drawing::constructor {owner path args} { 43 set _owner $owner 44 set _path $path 45 46 itk_component add canvas { 47 canvas $itk_interior.canv 24 constructor {xmlobj path} { 25 # defined below 26 } 27 destructor { 28 # defined below 29 } 30 public method limits {axis} 31 public method style { elem } 32 public method values { elem } 33 public method data { elem } 34 public method hints {{keyword ""}} 35 public method components { args } 36 37 private variable _drawing 38 private variable _xmlobj 39 private variable _actors 40 private variable _styles 41 private variable _data 42 private variable _hints 43 private variable _units 44 private variable _limits 45 } 46 47 # ---------------------------------------------------------------------- 48 # Constructor 49 # ---------------------------------------------------------------------- 50 itcl::body Rappture::Drawing::constructor {xmlobj path} { 51 if {![Rappture::library isvalid $xmlobj]} { 52 error "bad value \"$xmlobj\": should be Rappture::library" 53 } 54 set _xmlobj $xmlobj 55 set _drawing [$xmlobj element -as object $path] 56 set _units [$_drawing get units] 57 58 set xunits [$xmlobj get units] 59 if {"" == $xunits || "arbitrary" == $xunits} { 60 set xunits "um" 61 } 62 array set _limits { 63 xMin 0 64 xMax 0 65 yMin 0 66 yMax 0 67 zMin 0 68 zMax 0 69 } 70 # determine the overall size of the device 71 foreach elem [$_xmlobj children $path] { 72 switch -glob -- $elem { 73 polygon* { 74 set _data($elem) [$_xmlobj get $path.$elem.vtk] 75 } 76 } 77 } 78 foreach {key path} { 79 group about.group 80 label about.label 81 color about.color 82 camera about.camera 83 type about.type 84 xlabel xaxis.label 85 xdesc xaxis.description 86 xunits xaxis.units 87 xscale xaxis.scale 88 xmin xaxis.min 89 xmax xaxis.max 90 ylabel yaxis.label 91 ydesc yaxis.description 92 yunits yaxis.units 93 yscale yaxis.scale 94 ymin yaxis.min 95 ymax yaxis.max 96 zlabel zaxis.label 97 zdesc zaxis.description 98 zunits zaxis.units 99 zscale zaxis.scale 100 zmin zaxis.min 101 zmax zaxis.max 48 102 } { 49 usual 50 keep -width -height 51 } 52 pack $itk_component(canvas) -expand yes -fill both 53 54 eval itk_initialize $args 55 } 56 57 # ---------------------------------------------------------------------- 58 # USAGE: value ?-check? ?<newval>? 103 set str [$_drawing get $path] 104 if {"" != $str} { 105 set _hints($key) $str 106 } 107 } 108 foreach {key} { axisorder } { 109 set str [$_drawing get $key] 110 if {"" != $str} { 111 set _hints($key) $str 112 } 113 } 114 } 115 116 # ---------------------------------------------------------------------- 117 # Destructor 118 # ---------------------------------------------------------------------- 119 itcl::body Rappture::Drawing::destructor {} { 120 # empty 121 } 122 123 # ---------------------------------------------------------------------- 124 # method style 125 # Returns a base64 encoded, gzipped Tcl list that represents the 126 # Tcl command and data to recreate the uniform rectangular grid 127 # on the nanovis server. 128 # ---------------------------------------------------------------------- 129 itcl::body Rappture::Drawing::style { elem } { 130 if { [info exists _styles($elem)] } { 131 return $_styles($elem) 132 } 133 return "" 134 } 135 136 # ---------------------------------------------------------------------- 137 # method data 138 # Returns a base64 encoded, gzipped Tcl list that represents the 139 # Tcl command and data to recreate the uniform rectangular grid 140 # on the nanovis server. 141 # ---------------------------------------------------------------------- 142 itcl::body Rappture::Drawing::data { elem } { 143 if { [info exists _data($elem)] } { 144 return $_data($elem) 145 } 146 return "" 147 } 148 149 # ---------------------------------------------------------------------- 150 # method values 151 # Returns a base64 encoded, gzipped Tcl list that represents the 152 # Tcl command and data to recreate the uniform rectangular grid 153 # on the nanovis server. 154 # ---------------------------------------------------------------------- 155 itcl::body Rappture::Drawing::values { elem } { 156 if { [info exists _data($elem)] } { 157 return $_data($elem) 158 } 159 return "" 160 } 161 162 itcl::body Rappture::Drawing::components { args } { 163 return [array names _data] 164 } 165 166 # ---------------------------------------------------------------------- 167 # method limits <axis> 168 # Returns a list {min max} representing the limits for the 169 # specified axis. 170 # ---------------------------------------------------------------------- 171 itcl::body Rappture::Drawing::limits {which} { 172 set min "" 173 set max "" 174 foreach key [array names _data] { 175 set actor $_actors($key) 176 foreach key { xMin xMax yMin yMax zMin zMax} value [$actor GetBounds] { 177 set _limits($key) $value 178 } 179 break 180 } 181 182 foreach key [array names _actors] { 183 set actor $_actors($key) 184 foreach { xMin xMax yMin yMax zMin zMax} [$actor GetBounds] break 185 if { $xMin < $_limits(xMin) } { 186 set _limits(xMin) $xMin 187 } 188 if { $xMax > $_limits(xMax) } { 189 set _limits(xMax) $xMax 190 } 191 if { $yMin < $_limits(yMin) } { 192 set _limits(yMin) $yMin 193 } 194 if { $yMax > $_limits(yMax) } { 195 set _limits(yMax) $yMax 196 } 197 if { $zMin < $_limits(zMin) } { 198 set _limits(zMin) $zMin 199 } 200 if { $zMax > $_limits(zMax) } { 201 set _limits(zMax) $zMax 202 } 203 } 204 switch -- $which { 205 x { 206 set min $_limits(xMin) 207 set max $_limits(xMax) 208 set axis "xaxis" 209 } 210 y { 211 set min $_limits(yMin) 212 set max $_limits(yMax) 213 set axis "yaxis" 214 } 215 v - z { 216 set min $_limits(zMin) 217 set max $_limits(zMax) 218 set axis "zaxis" 219 } 220 default { 221 error "unknown axis description \"$which\"" 222 } 223 } 224 return [list $min $max] 225 } 226 227 228 # ---------------------------------------------------------------------- 229 # USAGE: hints ?<keyword>? 59 230 # 60 # Clients use this to query/set the value for this widget. With 61 # no args, it returns the current value for the widget. If the 62 # <newval> is specified, it sets the value of the widget and 63 # sends a <<Value>> event. If the -check flag is included, the 64 # new value is not actually applied, but just checked for correctness. 65 # ---------------------------------------------------------------------- 66 itcl::body Rappture::Drawing::value {args} { 67 set onlycheck 0 68 set i [lsearch -exact $args -check] 69 if {$i >= 0} { 70 set onlycheck 1 71 set args [lreplace $args $i $i] 72 } 73 74 if {[llength $args] == 0} { 75 return $_xmlobj 76 } elseif {[llength $args] > 1} { 77 error "wrong # args: should be \"value ?-check? ?newval?\"" 78 } 79 80 if {$onlycheck} { 81 # someday we may add validation... 82 return 83 } 84 85 set c $itk_component(canvas) 86 $c delete all 87 foreach elem [array names _elem2popup] { 88 destroy $_elem2popup($elem) 89 } 90 catch {unset $elem} 91 set _xmlobj [lindex $args 0] 92 93 if {"" != $_xmlobj} { 94 foreach elem [$_xmlobj children] { 95 switch -glob -- $elem { 96 about* { 97 continue 98 } 99 rectangle* { 100 set xy0 [$_xmlobj get $elem.xya] 101 set xy1 [$_xmlobj get $elem.xyb] 102 set fill [$_xmlobj get $elem.fill] 103 set outl [$_xmlobj get $elem.outl] 104 set wdth [$_xmlobj get $elem.width] 105 if {"" != $wdth && $wdth > 0 && $outl == ""} { 106 set outl black 107 } 108 if {"" == $fill && "" == $outl} { 109 _buildPopup $elem 110 111 # this part gets highlighted 112 eval $c create rect $xy0 $xy1 [list -outline "" -fill "" -tags $elem] 113 # this part is the sensor that detects events 114 set id [eval $c create rect $xy0 $xy1 [list -outline "" -fill ""]] 115 $c bind $id <Enter> [itcl::code $this hilite $elem on] 116 $c bind $id <Leave> [itcl::code $this hilite $elem off] 117 $c bind $id <ButtonPress> [itcl::code $this activate $elem %X %Y] 118 } else { 119 if {"" == $fill} { set fill "{}" } 120 if {"" == $outl} { set outl "{}" } 121 eval $c create rect $xy0 $xy1 -width $wdth -outline $outl -fill $fill 122 } 123 } 124 oval* { 125 set xy0 [$_xmlobj get $elem.xya] 126 set xy1 [$_xmlobj get $elem.xyb] 127 set fill [$_xmlobj get $elem.fill] 128 set outl [$_xmlobj get $elem.outl] 129 set wdth [$_xmlobj get $elem.width] 130 if {"" != $wdth && $wdth > 0 && $outl == ""} { 131 set outl black 132 } 133 if {"" == $fill && "" == $outl} { 134 } else { 135 if {"" == $fill} { set fill "{}" } 136 if {"" == $outl} { set outl "{}" } 137 } 138 eval $c create oval $xy0 $xy1 -width $wdth -outline $outl -fill $fill 139 } 140 polygon* { 141 set xy [$_xmlobj get $elem.xy] 142 regsub -all "\n" $xy " " xy 143 set smth [$_xmlobj get $elem.smooth] 144 set fill [$_xmlobj get $elem.fill] 145 set outl [$_xmlobj get $elem.outl] 146 set wdth [$_xmlobj get $elem.width] 147 if {"" != $wdth && $wdth > 0 && $outl == ""} { 148 set outl black 149 } 150 if {"" == $fill && "" == $outl} { 151 } else { 152 if {"" == $fill} { set fill "{}" } 153 if {"" == $outl} { set outl "{}" } 154 } 155 eval $c create polygon $xy -width $wdth -outline $outl -fill $fill -smooth $smth 156 } 157 text* { 158 set xy [$_xmlobj get $elem.xy] 159 set txt [$_xmlobj get $elem.text] 160 eval $c create text $xy -text $txt 161 } 162 } 163 } 164 } 165 return $_xmlobj 166 } 167 168 # ---------------------------------------------------------------------- 169 # USAGE: hilite <elem> <state> 170 # 171 # Used internally to highlight parts of the drawing when the mouse 172 # passes over it. 173 # ---------------------------------------------------------------------- 174 itcl::body Rappture::Drawing::hilite {elem state} { 175 if {$state} { 176 $itk_component(canvas) itemconfigure $elem -outline red -width 2 177 } else { 178 $itk_component(canvas) itemconfigure $elem -width 0 179 } 180 } 181 182 # ---------------------------------------------------------------------- 183 # USAGE: activate <elem> <x> <y> 184 # 185 # Pops up the controls associated with a drawing element. 186 # ---------------------------------------------------------------------- 187 itcl::body Rappture::Drawing::activate {elem x y} { 188 if {[info exists _elem2popup($elem)]} { 189 after 10 [list $_elem2popup($elem) activate @$x,$y above] 190 } 191 } 192 193 # ---------------------------------------------------------------------- 194 # USAGE: _buildPopup <elem> 195 # 196 # Pops up the controls associated with a drawing element. 197 # ---------------------------------------------------------------------- 198 itcl::body Rappture::Drawing::_buildPopup {elem} { 199 if {![info exists _elem2popup($elem)]} { 200 set n 0 201 while {1} { 202 set popup $itk_component(canvas).popup[incr n] 203 if {![winfo exists $popup]} { 204 break 205 } 206 } 207 Rappture::Balloon $popup -title [$_xmlobj get $elem.parameters.about.label] 208 set inner [$popup component inner] 209 Rappture::Controls $inner.cntls $_owner 210 pack $inner.cntls -expand yes -fill both 211 foreach child [$_xmlobj children $elem.parameters] { 212 if {[string match about* $child]} { 213 continue 214 } 215 $inner.cntls insert end $_path.$elem.parameters.$child 216 } 217 218 set _elem2popup($elem) $popup 219 } 220 } 231 # Returns a list of key/value pairs for various hints about plotting 232 # this curve. If a particular <keyword> is specified, then it returns 233 # the hint for that <keyword>, if it exists. 234 # ---------------------------------------------------------------------- 235 itcl::body Rappture::Drawing::hints { {keyword ""} } { 236 if 0 { 237 if {[info exists _hints(xlabel)] && "" != $_hints(xlabel) 238 && [info exists _hints(xunits)] && "" != $_hints(xunits)} { 239 set _hints(xlabel) "$_hints(xlabel) ($_hints(xunits))" 240 } 241 if {[info exists _hints(ylabel)] && "" != $_hints(ylabel) 242 && [info exists _hints(yunits)] && "" != $_hints(yunits)} { 243 set _hints(ylabel) "$_hints(ylabel) ($_hints(yunits))" 244 } 245 } 246 if {[info exists _hints(group)] && [info exists _hints(label)]} { 247 # pop-up help for each curve 248 set _hints(tooltip) $_hints(label) 249 } 250 if {$keyword != ""} { 251 if {[info exists _hints($keyword)]} { 252 return $_hints($keyword) 253 } 254 return "" 255 } 256 return [array get _hints] 257 } 258 -
trunk/gui/scripts/resultviewer.tcl
r2259 r2385 215 215 } 216 216 } 217 ::Rappture::Drawing3d { 218 set mode "vtkviewer" 219 if {![info exists _mode2widget($mode)]} { 220 set w $itk_interior.vtkviewer1 221 Rappture::VtkViewer $w 222 set _mode2widget($mode) $w 223 } 224 } 225 ::Rappture::Scene { 217 ::Rappture::Drawing { 226 218 set mode "vtkviewer2" 227 219 if {![info exists _mode2widget($mode)]} { … … 494 486 return [$xmlobj element -as object $path] 495 487 } 496 drawing3d {497 return [Rappture::Drawing 3d::#auto $xmlobj $path]488 drawing3d - drawing { 489 return [Rappture::Drawing ::#auto $xmlobj $path] 498 490 } 499 491 scene { -
trunk/gui/scripts/scene.tcl
r2259 r2385 1 1 2 2 # ---------------------------------------------------------------------- 3 # COMPONENT: scene- represents a vtk drawing.3 # COMPONENT: drawing - represents a vtk drawing. 4 4 # 5 5 # This object represents one field in an XML description of a device. … … 21 21 } 22 22 23 itcl::class Rappture:: Scene{23 itcl::class Rappture::Drawing { 24 24 constructor {xmlobj path} { 25 25 # defined below … … 35 35 public method components { args } 36 36 37 private variable _ scene37 private variable _drawing 38 38 private variable _xmlobj 39 39 private variable _actors … … 48 48 # Constructor 49 49 # ---------------------------------------------------------------------- 50 itcl::body Rappture:: Scene::constructor {xmlobj path} {50 itcl::body Rappture::Drawing::constructor {xmlobj path} { 51 51 if {![Rappture::library isvalid $xmlobj]} { 52 52 error "bad value \"$xmlobj\": should be Rappture::library" 53 53 } 54 54 set _xmlobj $xmlobj 55 set _ scene[$xmlobj element -as object $path]56 set _units [$_ sceneget units]55 set _drawing [$xmlobj element -as object $path] 56 set _units [$_drawing get units] 57 57 58 58 set xunits [$xmlobj get units] … … 101 101 zmax zaxis.max 102 102 } { 103 set str [$_ sceneget $path]103 set str [$_drawing get $path] 104 104 if {"" != $str} { 105 105 set _hints($key) $str … … 107 107 } 108 108 foreach {key} { axisorder } { 109 set str [$_ sceneget $key]109 set str [$_drawing get $key] 110 110 if {"" != $str} { 111 111 set _hints($key) $str … … 117 117 # Destructor 118 118 # ---------------------------------------------------------------------- 119 itcl::body Rappture:: Scene::destructor {} {119 itcl::body Rappture::Drawing::destructor {} { 120 120 # empty 121 121 } … … 127 127 # on the nanovis server. 128 128 # ---------------------------------------------------------------------- 129 itcl::body Rappture:: Scene::style { elem } {129 itcl::body Rappture::Drawing::style { elem } { 130 130 if { [info exists _styles($elem)] } { 131 131 return $_styles($elem) … … 140 140 # on the nanovis server. 141 141 # ---------------------------------------------------------------------- 142 itcl::body Rappture:: Scene::data { elem } {142 itcl::body Rappture::Drawing::data { elem } { 143 143 if { [info exists _data($elem)] } { 144 144 return $_data($elem) … … 153 153 # on the nanovis server. 154 154 # ---------------------------------------------------------------------- 155 itcl::body Rappture:: Scene::values { elem } {155 itcl::body Rappture::Drawing::values { elem } { 156 156 if { [info exists _data($elem)] } { 157 157 return $_data($elem) … … 160 160 } 161 161 162 itcl::body Rappture:: Scene::components { args } {162 itcl::body Rappture::Drawing::components { args } { 163 163 return [array names _data] 164 164 } … … 169 169 # specified axis. 170 170 # ---------------------------------------------------------------------- 171 itcl::body Rappture:: Scene::limits {which} {171 itcl::body Rappture::Drawing::limits {which} { 172 172 set min "" 173 173 set max "" … … 233 233 # the hint for that <keyword>, if it exists. 234 234 # ---------------------------------------------------------------------- 235 itcl::body Rappture:: Scene::hints { {keyword ""} } {235 itcl::body Rappture::Drawing::hints { {keyword ""} } { 236 236 if 0 { 237 237 if {[info exists _hints(xlabel)] && "" != $_hints(xlabel) -
trunk/gui/scripts/vtkviewer.tcl
r2149 r2385 1 1 2 2 # ---------------------------------------------------------------------- 3 # COMPONENT: contourresult - contour plot in a ResultSet 4 # 5 # This widget is a contour plot for 2D meshes with a scalar value. 6 # It is normally used in the ResultViewer to show results from the 7 # run of a Rappture tool. Use the "add" and "delete" methods to 8 # control the dataobjs showing on the plot. 3 # COMPONENT: vtkviewer - Vtk drawing object viewer 4 # 5 # It connects to the Vtk server running on a rendering farm, 6 # transmits data, and displays the results. 9 7 # ====================================================================== 10 8 # AUTHOR: Michael McLennan, Purdue University … … 15 13 # ====================================================================== 16 14 package require Itk 17 package require vtk18 package require vtkinteraction19 15 package require BLT 20 16 #package require Img 21 17 22 18 option add *VtkViewer.width 4i widgetDefault 19 option add *VtkViewer*cursor crosshair widgetDefault 23 20 option add *VtkViewer.height 4i widgetDefault 24 21 option add *VtkViewer.foreground black widgetDefault … … 30 27 -*-helvetica-medium-r-normal-*-12-* widgetDefault 31 28 29 # must use this name -- plugs into Rappture::resources::load 30 proc VtkViewer_init_resources {} { 31 Rappture::resources::register \ 32 vtkvis_server Rappture::VtkViewer::SetServerList 33 } 34 32 35 itcl::class Rappture::VtkViewer { 33 inherit itk::Widget36 inherit Rappture::VisViewer 34 37 35 38 itk_option define -plotforeground plotForeground Foreground "" 36 39 itk_option define -plotbackground plotBackground Background "" 37 40 41 constructor { hostlist args } { 42 Rappture::VisViewer::constructor $hostlist 43 } { 44 # defined below 45 } 46 destructor { 47 # defined below 48 } 49 public proc SetServerList { namelist } { 50 Rappture::VisViewer::SetServerList "vtkvis" $namelist 51 } 52 public method add {dataobj {settings ""}} 53 public method camera {option args} 54 public method delete {args} 55 public method disconnect {} 56 public method download {option args} 57 public method get {args} 58 public method isconnected {} 59 public method limits { colormap } 60 public method sendto { string } 61 public method parameters {title args} { 62 # do nothing 63 } 64 public method scale {args} 65 66 protected method Connect {} 67 protected method CurrentDatasets {args} 68 protected method Disconnect {} 69 protected method DoResize {} 70 protected method FixSettings {what {value ""}} 71 protected method Pan {option x y} 72 protected method Rebuild {} 73 protected method ReceiveDataset { args } 74 protected method ReceiveImage { args } 75 protected method Rotate {option x y} 76 protected method SendCmd {string} 77 protected method Zoom {option} 78 79 # The following methods are only used by this class. 80 private method BuildCameraTab {} 81 private method BuildViewTab {} 82 private method BuildAxisTab {} 83 private method BuildColormap { colormap dataobj comp } 84 private method EventuallyResize { w h } 85 private method SetStyles { dataobj comp } 86 private method PanCamera {} 87 private method ConvertToVtkData { dataobj comp } 88 private method GetImage { args } 89 private method GetVtkData { args } 90 private method BuildDownloadPopup { widget command } 91 private method SetObjectStyle { dataobj comp } 92 private method IsValidObject { dataobj } 93 94 private variable _arcball "" 95 private variable _outbuf ;# buffer for outgoing commands 96 38 97 private variable _dlist "" ;# list of data objects 39 private variable _dims "" ;# dimensionality of data objects 40 private variable _obj2color ;# maps dataobj => plotting color 41 private variable _obj2width ;# maps dataobj => line width 42 private variable _obj2raise ;# maps dataobj => raise flag 0/1 43 private variable _dataobj2vtk ;# maps dataobj => vtk objects 44 private variable _actors ;# array of actors for each dataobj. 45 private variable _lights ;# list of lights for each renderer 46 private variable _click ;# info used for _move operations 98 private variable _allDataObjs 99 private variable _obj2datasets 100 private variable _obj2ovride ;# maps dataobj => style override 101 private variable _datasets ;# contains all the dataobj-component 102 ;# datasets in the server 103 private variable _colormaps ;# contains all the colormaps 104 ;# in the server. 105 private variable _dataset2style ;# maps dataobj-component to transfunc 106 private variable _style2datasets ;# maps tf back to list of 107 # dataobj-components using the tf. 108 109 private variable _click ;# info used for rotate operations 47 110 private variable _limits ;# autoscale min/max for all axes 48 111 private variable _view ;# view params for 3D view 49 private variable _download "" ;# snapshot for download 50 51 private variable _renderer ""; 52 private variable _window ""; 53 private variable _interactor ""; 54 private variable _style ""; 55 private variable _light ""; 56 private variable _cubeAxesActor "" 57 private variable _axesActor "" 58 private variable _axesWidget ""; 59 private variable _settings 60 constructor {args} { 61 # defined below 62 } 63 destructor { 64 # defined below 65 } 66 67 public method add {dataobj {settings ""}} 68 public method get {} 69 public method delete {args} 70 public method scale {args} 71 public method parameters {title args} { 72 # do nothing 73 } 74 public method download {option args} 75 76 protected method Rebuild {} 77 protected method Clear {} 78 protected method Zoom {option} 79 protected method Move {option x y} 80 protected method _3dView {theta phi} 81 protected method _fixLimits {} 82 protected method _color2rgb {color} 83 protected method SetActorProperties { actor style } 84 85 private method ComputeLimits { args } 86 private method GetLimits {} 87 private method BuildCameraTab {} 88 private method UpdateCameraInfo {} 89 private method BuildViewTab {} 90 private method BuildVolumeTab {} 91 protected method FixSettings {what {value ""}} 92 112 private common _settings 113 private variable _reset 1 ;# indicates if camera needs to be reset 114 # to starting position. 115 116 # Array of transfer functions in server. If 0 the transfer has been 117 # defined but not loaded. If 1 the transfer function has been named 118 # and loaded. 119 private variable _first "" ;# This is the topmost dataset. 120 private variable _start 0 121 private variable _buffering 0 122 123 # This indicates which isomarkers and transfer function to use when 124 # changing markers, opacity, or thickness. 125 common _downloadPopup ;# download options from popup 126 private common _hardcopy 127 private variable _width 0 128 private variable _height 0 129 private variable _resizePending 0 130 private variable _outline 93 131 } 94 132 … … 101 139 # CONSTRUCTOR 102 140 # ---------------------------------------------------------------------- 103 itcl::body Rappture::VtkViewer::constructor {args} { 104 option add hull.width hull.height 105 pack propagate $itk_component(hull) no 106 set _view(theta) 0 107 set _view(phi) 0 108 109 array set _limits { 110 xMin 0 111 xMax 1 112 yMin 0 113 yMax 1 114 zMin 0 115 zMax 1 116 vMin 0 117 vMax 1 118 } 119 120 121 foreach { key value } { 122 edges 1 123 axes 1 124 smallaxes 0 125 wireframe 0 126 } { 127 set _settings($this-$key) $value 128 } 129 itk_component add main { 130 Rappture::SidebarFrame $itk_interior.main 131 } 132 pack $itk_component(main) -expand yes -fill both 133 set f [$itk_component(main) component frame] 134 135 itk_component add controls { 136 frame $f.cntls 141 itcl::body Rappture::VtkViewer::constructor {hostlist args} { 142 if {[catch {info level -1} caller]} { 143 puts stderr "Enter constructor" 144 } else { 145 puts stderr "Enter constructor: $caller" 146 } 147 148 # Rebuild event 149 $_dispatcher register !rebuild 150 $_dispatcher dispatch $this !rebuild "[itcl::code $this Rebuild]; list" 151 152 # Resize event 153 $_dispatcher register !resize 154 $_dispatcher dispatch $this !resize "[itcl::code $this DoResize]; list" 155 156 set _outbuf "" 157 158 # 159 # Populate parser with commands handle incoming requests 160 # 161 $_parser alias image [itcl::code $this ReceiveImage] 162 $_parser alias dataset [itcl::code $this ReceiveDataset] 163 164 array set _outline { 165 id -1 166 afterId -1 167 x1 -1 168 y1 -1 169 x2 -1 170 y2 -1 171 } 172 # Initialize the view to some default parameters. 173 array set _view { 174 qx 0 175 qy 0 176 qz 0 177 qw 1 178 zoom 1.0 179 pan-x 0 180 pan-y 0 181 zoom-x 1.0 182 zoom-y 1.0 183 } 184 set _arcball [blt::arcball create 100 100] 185 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 186 $_arcball quaternion $q 187 188 set _limits(vmin) 0.0 189 set _limits(vmax) 1.0 190 191 array set _settings [subst { 192 $this-axes 1 193 $this-edges 1 194 $this-lighting 1 195 $this-opacity 1 196 $this-volume 1 197 $this-wireframe 0 198 $this-grid-x 0 199 $this-grid-y 0 200 $this-grid-z 0 201 }] 202 203 itk_component add view { 204 canvas $itk_component(plotarea).view \ 205 -highlightthickness 0 -borderwidth 0 137 206 } { 138 207 usual 139 rename -background -controlbackground controlBackground Background 140 } 141 pack $itk_component(controls) -side right -fill y 142 143 itk_component add zoom { 144 frame $itk_component(controls).zoom 145 } { 146 usual 147 rename -background -controlbackground controlBackground Background 148 } 149 pack $itk_component(zoom) -side top 150 208 ignore -highlightthickness -borderwidth -background 209 } 210 211 set c $itk_component(view) 212 bind $c <Configure> [itcl::code $this EventuallyResize %w %h] 213 bind $c <4> [itcl::code $this Zoom in 0.25] 214 bind $c <5> [itcl::code $this Zoom out 0.25] 215 bind $c <KeyPress-Left> [list %W xview scroll 10 units] 216 bind $c <KeyPress-Right> [list %W xview scroll -10 units] 217 bind $c <KeyPress-Up> [list %W yview scroll 10 units] 218 bind $c <KeyPress-Down> [list %W yview scroll -10 units] 219 bind $c <Enter> "focus %W" 220 221 # Fix the scrollregion in case we go off screen 222 $c configure -scrollregion [$c bbox all] 223 224 set _map(id) [$c create image 0 0 -anchor nw -image $_image(plot)] 225 set _map(cwidth) -1 226 set _map(cheight) -1 227 set _map(zoom) 1.0 228 set _map(original) "" 229 230 set f [$itk_component(main) component controls] 151 231 itk_component add reset { 152 button $ itk_component(zoom).reset\153 - borderwidth 1 -padx 1 -pady 1\154 - bitmap [Rappture::icon reset] \232 button $f.reset -borderwidth 1 -padx 1 -pady 1 \ 233 -highlightthickness 0 \ 234 -image [Rappture::icon reset-view] \ 155 235 -command [itcl::code $this Zoom reset] 156 236 } { 157 237 usual 158 ignore -borderwidth 159 rename -highlightbackground -controlbackground controlBackground Background 160 } 161 pack $itk_component(reset) -padx 4 -pady 4 162 Rappture::Tooltip::for $itk_component(reset) \ 163 "Reset the view to the default zoom level" 238 ignore -highlightthickness 239 } 240 pack $itk_component(reset) -side top -padx 2 -pady 2 241 Rappture::Tooltip::for $itk_component(reset) "Reset the view to the default zoom level" 164 242 165 243 itk_component add zoomin { 166 button $ itk_component(zoom).zin\167 - borderwidth 1 -padx 1 -pady 1\168 - bitmap [Rappture::icon zoomin] \244 button $f.zin -borderwidth 1 -padx 1 -pady 1 \ 245 -highlightthickness 0 \ 246 -image [Rappture::icon zoom-in] \ 169 247 -command [itcl::code $this Zoom in] 170 248 } { 171 249 usual 172 ignore -borderwidth 173 rename -highlightbackground -controlbackground controlBackground \ 174 Background 175 } 176 pack $itk_component(zoomin) -padx 4 -pady 4 250 ignore -highlightthickness 251 } 252 pack $itk_component(zoomin) -side top -padx 2 -pady 2 177 253 Rappture::Tooltip::for $itk_component(zoomin) "Zoom in" 178 254 179 255 itk_component add zoomout { 180 button $ itk_component(zoom).zout\181 - borderwidth 1 -padx 1 -pady 1\182 - bitmap [Rappture::icon zoomout] \256 button $f.zout -borderwidth 1 -padx 1 -pady 1 \ 257 -highlightthickness 0 \ 258 -image [Rappture::icon zoom-out] \ 183 259 -command [itcl::code $this Zoom out] 184 260 } { 185 261 usual 186 ignore -borderwidth 187 rename -highlightbackground -controlbackground controlBackground \ 188 Background 189 } 190 pack $itk_component(zoomout) -padx 4 -pady 4 262 ignore -highlightthickness 263 } 264 pack $itk_component(zoomout) -side top -padx 2 -pady 2 191 265 Rappture::Tooltip::for $itk_component(zoomout) "Zoom out" 192 193 # 194 # RENDERING AREA 195 # 196 itk_component add area { 197 frame $f.area 198 } 199 pack $itk_component(area) -expand yes -fill both 200 201 set _renderer [vtkRenderer $this-Renderer] 202 set _window [vtkRenderWindow $this-RenderWindow] 203 itk_component add plot { 204 vtkTkRenderWidget $itk_component(area).plot -rw $_window \ 205 -width 1 -height 1 206 } { 207 # empty 208 } 209 pack $itk_component(plot) -expand yes -fill both 210 $_window AddRenderer $_renderer 211 $_window LineSmoothingOn 212 $_window PolygonSmoothingOn 213 214 set _interactor [vtkRenderWindowInteractor $this-Interactor] 215 set _style [vtkInteractorStyleTrackballCamera $this-InteractorStyle] 216 $_interactor SetRenderWindow $_window 217 $_interactor SetInteractorStyle $_style 218 $_interactor Initialize 219 220 set _cubeAxesActor [vtkCubeAxesActor $this-CubeAxesActor] 221 $_cubeAxesActor SetCamera [$_renderer GetActiveCamera] 222 $_renderer AddActor $_cubeAxesActor 223 224 # Supply small axes guide. 225 set _axesActor [vtkAxesActor $this-AxesActor] 226 set _axesWidget [vtkOrientationMarkerWidget $this-AxesWidget] 227 $_axesWidget SetOrientationMarker $_axesActor 228 $_axesWidget SetInteractor $_interactor 229 $_axesWidget SetEnabled $_settings($this-smallaxes) 230 $_axesWidget SetInteractive 0 231 $_axesWidget SetViewport .7 0 1.0 0.3 232 266 233 267 BuildViewTab 268 BuildAxisTab 234 269 BuildCameraTab 235 236 set v0 0 237 set v1 1 238 set _lookup [vtkLookupTable $this-Lookup] 239 $_lookup SetTableRange $v0 $v1 240 $_lookup SetHueRange 0.66667 0.0 241 $_lookup Build 242 243 set lightKit [vtkLightKit $this-LightKit] 244 $lightKit AddLightsToRenderer $_renderer 245 246 # 247 # Create a picture for download snapshots 248 # 249 set _download [image create photo] 250 270 271 # Hack around the Tk panewindow. The problem is that the requested 272 # size of the 3d view isn't set until an image is retrieved from 273 # the server. So the panewindow uses the tiny size. 274 set w 10000 275 pack forget $itk_component(view) 276 blt::table $itk_component(plotarea) \ 277 0,0 $itk_component(view) -fill both -reqwidth $w 278 blt::table configure $itk_component(plotarea) c1 -resize none 279 280 # Bindings for rotation via mouse 281 bind $itk_component(view) <ButtonPress-1> \ 282 [itcl::code $this Rotate click %x %y] 283 bind $itk_component(view) <B1-Motion> \ 284 [itcl::code $this Rotate drag %x %y] 285 bind $itk_component(view) <ButtonRelease-1> \ 286 [itcl::code $this Rotate release %x %y] 287 bind $itk_component(view) <Configure> \ 288 [itcl::code $this EventuallyResize %w %h] 289 290 if 0 { 291 bind $itk_component(view) <Configure> \ 292 [itcl::code $this EventuallyResize %w %h] 293 } 294 # Bindings for panning via mouse 295 bind $itk_component(view) <ButtonPress-2> \ 296 [itcl::code $this Pan click %x %y] 297 bind $itk_component(view) <B2-Motion> \ 298 [itcl::code $this Pan drag %x %y] 299 bind $itk_component(view) <ButtonRelease-2> \ 300 [itcl::code $this Pan release %x %y] 301 302 # Bindings for panning via keyboard 303 bind $itk_component(view) <KeyPress-Left> \ 304 [itcl::code $this Pan set -10 0] 305 bind $itk_component(view) <KeyPress-Right> \ 306 [itcl::code $this Pan set 10 0] 307 bind $itk_component(view) <KeyPress-Up> \ 308 [itcl::code $this Pan set 0 -10] 309 bind $itk_component(view) <KeyPress-Down> \ 310 [itcl::code $this Pan set 0 10] 311 bind $itk_component(view) <Shift-KeyPress-Left> \ 312 [itcl::code $this Pan set -2 0] 313 bind $itk_component(view) <Shift-KeyPress-Right> \ 314 [itcl::code $this Pan set 2 0] 315 bind $itk_component(view) <Shift-KeyPress-Up> \ 316 [itcl::code $this Pan set 0 -2] 317 bind $itk_component(view) <Shift-KeyPress-Down> \ 318 [itcl::code $this Pan set 0 2] 319 320 # Bindings for zoom via keyboard 321 bind $itk_component(view) <KeyPress-Prior> \ 322 [itcl::code $this Zoom out] 323 bind $itk_component(view) <KeyPress-Next> \ 324 [itcl::code $this Zoom in] 325 326 bind $itk_component(view) <Enter> "focus $itk_component(view)" 327 328 if {[string equal "x11" [tk windowingsystem]]} { 329 # Bindings for zoom via mouse 330 bind $itk_component(view) <4> [itcl::code $this Zoom out] 331 bind $itk_component(view) <5> [itcl::code $this Zoom in] 332 } 333 334 set _image(download) [image create photo] 335 251 336 eval itk_initialize $args 337 338 Connect 252 339 } 253 340 … … 256 343 # ---------------------------------------------------------------------- 257 344 itcl::body Rappture::VtkViewer::destructor {} { 258 Clear 259 after cancel [itcl::code $this Rebuild] 260 261 foreach c [info commands $this-vtk*] { 262 rename $c "" 263 } 264 image delete $_download 345 Disconnect 346 $_dispatcher cancel !rebuild 347 $_dispatcher cancel !resize 348 image delete $_image(plot) 349 image delete $_image(download) 350 array unset _settings $this-* 351 catch { blt::arcball destroy $_arcball} 352 } 353 354 itcl::body Rappture::VtkViewer::DoResize {} { 355 if { $_width < 2 } { 356 set _width 500 357 } 358 if { $_height < 2 } { 359 set _height 500 360 } 361 puts stderr "screen size $_width $_height" 362 set _start [clock clicks -milliseconds] 363 SendCmd "screen size $_width $_height" 364 set _resizePending 0 365 } 366 367 itcl::body Rappture::VtkViewer::EventuallyResize { w h } { 368 puts stderr "EventuallyResize $w $h" 369 set _width $w 370 set _height $h 371 $_arcball resize $w $h 372 if { !$_resizePending } { 373 $_dispatcher event -after 400 !resize 374 set _resizePending 1 375 } 265 376 } 266 377 … … 281 392 -description "" 282 393 -param "" 283 } 394 -type "" 395 } 396 array set params $settings 397 set params(-description) "" 398 set params(-param) "" 284 399 foreach {opt val} $settings { 285 400 if {![info exists params($opt)]} { … … 294 409 set pos [lsearch -exact $dataobj $_dlist] 295 410 if {$pos < 0} { 296 lappend _dlist $dataobj 297 298 set _obj2color($dataobj) $params(-color) 299 set _obj2width($dataobj) $params(-width) 300 set _obj2raise($dataobj) $params(-raise) 301 302 after cancel [itcl::code $this Rebuild] 303 after idle [itcl::code $this Rebuild] 304 } 305 } 306 307 # ---------------------------------------------------------------------- 308 # USAGE: get 309 # 310 # Clients use this to query the list of objects being plotted, in 311 # order from bottom to top of this result. 312 # ---------------------------------------------------------------------- 313 itcl::body Rappture::VtkViewer::get {} { 314 # put the dataobj list in order according to -raise options 315 set dlist $_dlist 316 foreach obj $dlist { 317 if {[info exists _obj2raise($obj)] && $_obj2raise($obj)} { 318 set i [lsearch -exact $dlist $obj] 319 if {$i >= 0} { 320 set dlist [lreplace $dlist $i $i] 321 lappend dlist $obj 322 } 323 } 324 } 325 return $dlist 326 } 411 lappend _dlist $dataobj 412 } 413 set _allDataObjs($dataobj) 1 414 set _obj2ovride($dataobj-color) $params(-color) 415 set _obj2ovride($dataobj-width) $params(-width) 416 set _obj2ovride($dataobj-raise) $params(-raise) 417 $_dispatcher event -idle !rebuild 418 } 419 327 420 328 421 # ---------------------------------------------------------------------- 329 422 # USAGE: delete ?<dataobj1> <dataobj2> ...? 330 423 # 331 # Clients use this to delete a dataobj from the plot. If no dataobjs 332 # are specified, then all dataobjs are deleted. 424 # Clients use this to delete a dataobj from the plot. If no dataobjs 425 # are specified, then all dataobjs are deleted. No data objects are 426 # deleted. They are only removed from the display list. 427 # 333 428 # ---------------------------------------------------------------------- 334 429 itcl::body Rappture::VtkViewer::delete {args} { 335 if { [llength $args] == 0} {430 if { [llength $args] == 0} { 336 431 set args $_dlist 337 432 } 338 339 # delete all specified dataobjs 433 # Delete all specified dataobjs 340 434 set changed 0 341 435 foreach dataobj $args { 342 set i [lsearch -exact $_dlist $dataobj] 343 if {$i >= 0} { 344 set _dlist [lreplace $_dlist $i $i] 345 catch {unset _obj2color($dataobj)} 346 catch {unset _obj2width($dataobj)} 347 catch {unset _obj2raise($dataobj)} 348 foreach actor $_actors($dataobj) { 349 $_renderer RemoveActor $actor 436 set pos [lsearch -exact $_dlist $dataobj] 437 if { $pos < 0 } { 438 continue; # Don't know anything about it. 439 } 440 # Remove it from the dataobj list. 441 set _dlist [lreplace $_dlist $pos $pos] 442 foreach comp [$dataobj components] { 443 SendCmd "dataset visible 0 $dataobj-$comp" 444 } 445 array unset _obj2ovride $dataobj-* 446 # Append to the end of the dataobj list. 447 lappend _dlist $dataobj 448 set changed 1 449 } 450 # If anything changed, then rebuild the plot 451 if { $changed } { 452 $_dispatcher event -idle !rebuild 453 } 454 } 455 456 # ---------------------------------------------------------------------- 457 # USAGE: get ?-objects? 458 # USAGE: get ?-visible? 459 # USAGE: get ?-image view? 460 # 461 # Clients use this to query the list of objects being plotted, in 462 # order from bottom to top of this result. The optional "-image" 463 # flag can also request the internal images being shown. 464 # ---------------------------------------------------------------------- 465 itcl::body Rappture::VtkViewer::get {args} { 466 if {[llength $args] == 0} { 467 set args "-objects" 468 } 469 470 set op [lindex $args 0] 471 switch -- $op { 472 "-objects" { 473 # put the dataobj list in order according to -raise options 474 set dlist {} 475 foreach dataobj $_dlist { 476 if { ![IsValidObject $dataobj] } { 477 continue 478 } 479 if {[info exists _obj2ovride($dataobj-raise)] && 480 $_obj2ovride($dataobj-raise)} { 481 set dlist [linsert $dlist 0 $dataobj] 482 } else { 483 lappend dlist $dataobj 484 } 350 485 } 351 array unset _actors $dataobj 352 array unset _dataobj2vtk $dataobj-* 353 set changed 1 354 } 355 } 356 # If anything changed, then rebuild the plot 357 if {$changed} { 358 after cancel [itcl::code $this Rebuild] 359 after idle [itcl::code $this Rebuild] 486 return $dlist 487 } 488 "-visible" { 489 set dlist {} 490 foreach dataobj $_dlist { 491 if { ![IsValidObject $dataobj] } { 492 continue 493 } 494 if { ![info exists _obj2ovride($dataobj-raise)] } { 495 # No setting indicates that the object isn't invisible. 496 continue 497 } 498 # Otherwise use the -raise parameter to put the object to 499 # the front of the list. 500 if { $_obj2ovride($dataobj-raise) } { 501 set dlist [linsert $dlist 0 $dataobj] 502 } else { 503 lappend dlist $dataobj 504 } 505 } 506 return $dlist 507 } 508 -image { 509 if {[llength $args] != 2} { 510 error "wrong # args: should be \"get -image view\"" 511 } 512 switch -- [lindex $args end] { 513 view { 514 return $_image(plot) 515 } 516 default { 517 error "bad image name \"[lindex $args end]\": should be view" 518 } 519 } 520 } 521 default { 522 error "bad option \"$op\": should be -objects or -image" 523 } 360 524 } 361 525 } … … 371 535 # ---------------------------------------------------------------------- 372 536 itcl::body Rappture::VtkViewer::scale {args} { 373 eval ComputeLimits $args 374 _fixLimits 537 array unset _limits 538 foreach dataobj $args { 539 array set bounds [limits $dataobj] 540 if {![info exists _limits(xmin)] || $_limits(xmin) > $bounds(xmin)} { 541 set _limits(xmin) $bounds(xmin) 542 } 543 if {![info exists _limits(xmax)] || $_limits(xmax) < $bounds(xmax)} { 544 set _limits(xmax) $bounds(xmax) 545 } 546 547 if {![info exists _limits(ymin)] || $_limits(ymin) > $bounds(ymin)} { 548 set _limits(ymin) $bounds(ymin) 549 } 550 if {![info exists _limits(ymax)] || $_limits(ymax) < $bounds(ymax)} { 551 set _limits(ymax) $bounds(ymax) 552 } 553 554 if {![info exists _limits(zmin)] || $_limits(zmin) > $bounds(zmin)} { 555 set _limits(zmin) $bounds(zmin) 556 } 557 if {![info exists _limits(zmax)] || $_limits(zmax) < $bounds(zmax)} { 558 set _limits(zmax) $bounds(zmax) 559 } 560 } 375 561 } 376 562 … … 389 575 coming { 390 576 if {[catch { 391 blt::winop snap $itk_component(plotarea) $_ download577 blt::winop snap $itk_component(plotarea) $_image(download) 392 578 }]} { 393 $_ downloadconfigure -width 1 -height 1394 $_ downloadput #000000579 $_image(download) configure -width 1 -height 1 580 $_image(download) put #000000 395 581 } 396 582 } 397 583 controls { 398 # no controls for this download yet 584 set popup .vtkviewerdownload 585 if { ![winfo exists .vtkviewerdownload] } { 586 set inner [BuildDownloadPopup $popup [lindex $args 0]] 587 } else { 588 set inner [$popup component inner] 589 } 590 set _downloadPopup(image_controls) $inner.image_frame 591 set num [llength [get]] 592 set num [expr {($num == 1) ? "1 result" : "$num results"}] 593 set word [Rappture::filexfer::label downloadWord] 594 $inner.summary configure -text "$word $num in the following format:" 595 update idletasks ;# Fix initial sizes 596 return $popup 597 } 598 now { 599 set popup .vtkviewerdownload 600 if {[winfo exists .vtkviewerdownload]} { 601 $popup deactivate 602 } 603 switch -- $_downloadPopup(format) { 604 "image" { 605 return [$this GetImage [lindex $args 0]] 606 } 607 "vtk" { 608 return [$this GetVtkData [lindex $args 0]] 609 } 610 } 399 611 return "" 400 }401 now {402 set writer [vtkJPEGWriter $this-vtkJPEGWriter]403 set large [vtkRenderLargeImage $this-RenderLargeImage]404 $_axesWidget SetEnabled 0405 $large SetInput $_renderer406 $large SetMagnification 4407 $writer SetInputConnection [$large GetOutputPort]408 409 $writer SetFileName junk.jpg410 $writer Write411 rename $writer ""412 rename $large ""413 FixSettings smallaxes414 415 set img [image create photo -file junk.jpg]416 set bytes [$img data -format "jpeg -quality 100"]417 set bytes [Rappture::encoding::decode -as b64 $bytes]418 image delete $img419 return [list .jpg $bytes]420 612 } 421 613 default { … … 426 618 427 619 # ---------------------------------------------------------------------- 428 # USAGE: Clear 429 # 430 # Used internally to clear the drawing area and tear down all vtk 431 # objects in the current scene. 432 # ---------------------------------------------------------------------- 433 itcl::body Rappture::VtkViewer::Clear {} { 434 # clear out any old constructs 620 # USAGE: Connect ?<host:port>,<host:port>...? 621 # 622 # Clients use this method to establish a connection to a new 623 # server, or to reestablish a connection to the previous server. 624 # Any existing connection is automatically closed. 625 # ---------------------------------------------------------------------- 626 itcl::body Rappture::VtkViewer::Connect {} { 627 puts stderr "Enter Connect: [info level -1]" 628 set _hosts [GetServerList "vtkvis"] 629 if { "" == $_hosts } { 630 return 0 631 } 632 set result [VisViewer::Connect $_hosts] 633 if { $result } { 634 puts stderr "Connected to $_hostname sid=$_sid" 635 set w [winfo width $itk_component(view)] 636 set h [winfo height $itk_component(view)] 637 EventuallyResize $w $h 638 } 639 return $result 640 } 641 642 # 643 # isconnected -- 644 # 645 # Indicates if we are currently connected to the visualization server. 646 # 647 itcl::body Rappture::VtkViewer::isconnected {} { 648 return [VisViewer::IsConnected] 649 } 650 651 # 652 # disconnect -- 653 # 654 itcl::body Rappture::VtkViewer::disconnect {} { 655 Disconnect 656 set _reset 1 657 } 658 659 # 660 # Disconnect -- 661 # 662 # Clients use this method to disconnect from the current rendering 663 # server. 664 # 665 itcl::body Rappture::VtkViewer::Disconnect {} { 666 VisViewer::Disconnect 667 668 # disconnected -- no more data sitting on server 669 set _outbuf "" 670 array unset _datasets 671 array unset _data 672 array unset _colormaps 673 } 674 675 # 676 # sendto -- 677 # 678 itcl::body Rappture::VtkViewer::sendto { bytes } { 679 SendBytes "$bytes\n" 680 } 681 682 # 683 # SendCmd 684 # 685 # Send commands off to the rendering server. If we're currently 686 # sending data objects to the server, buffer the commands to be 687 # sent later. 688 # 689 itcl::body Rappture::VtkViewer::SendCmd {string} { 690 if { $_buffering } { 691 append _outbuf $string "\n" 692 } else { 693 foreach line [split $string \n] { 694 SendEcho >>line $line 695 } 696 SendBytes "$string\n" 697 } 698 } 699 700 # ---------------------------------------------------------------------- 701 # USAGE: ReceiveImage -bytes <size> -type <type> -token <token> 702 # 703 # Invoked automatically whenever the "image" command comes in from 704 # the rendering server. Indicates that binary image data with the 705 # specified <size> will follow. 706 # ---------------------------------------------------------------------- 707 itcl::body Rappture::VtkViewer::ReceiveImage { args } { 708 array set info { 709 -token "???" 710 -bytes 0 711 -type image 712 } 713 array set info $args 714 set bytes [ReceiveBytes $info(-bytes)] 715 ReceiveEcho <<line "<read $info(-bytes) bytes" 716 if { $info(-type) == "image" } { 717 if 1 { 718 set f [open "last.ppm" "w"] 719 puts $f $bytes 720 close $f 721 } 722 $_image(plot) configure -data $bytes 723 set time [clock seconds] 724 set date [clock format $time] 725 puts stderr "$date: received image [image width $_image(plot)]x[image height $_image(plot)] image>" 726 if { $_start > 0 } { 727 set finish [clock clicks -milliseconds] 728 puts stderr "round trip time [expr $finish -$_start] milliseconds" 729 set _start 0 730 } 731 } elseif { $info(type) == "print" } { 732 set tag $this-print-$info(-token) 733 set _hardcopy($tag) $bytes 734 } 735 } 736 737 # 738 # ReceiveDataset -- 739 # 740 itcl::body Rappture::VtkViewer::ReceiveDataset { args } { 741 if { ![isconnected] } { 742 return 743 } 744 set option [lindex $args 0] 745 switch -- $option { 746 "value" { 747 set option [lindex $args 1] 748 switch -- $option { 749 "world" { 750 foreach { x y z value } [lrange $args 2 end] break 751 } 752 "pixel" { 753 foreach { x y value } [lrange $args 2 end] break 754 } 755 } 756 } 757 default { 758 error "unknown dataset option \"$option\" from server" 759 } 760 } 761 } 762 763 # ---------------------------------------------------------------------- 764 # USAGE: Rebuild 765 # 766 # Called automatically whenever something changes that affects the 767 # data in the widget. Clears any existing data and rebuilds the 768 # widget to display new data. 769 # ---------------------------------------------------------------------- 770 itcl::body Rappture::VtkViewer::Rebuild {} { 771 772 set w [winfo width $itk_component(view)] 773 set h [winfo height $itk_component(view)] 774 if { $w < 2 || $h < 2 } { 775 $_dispatcher event -idle !rebuild 776 return 777 } 778 779 # Turn on buffering of commands to the server. We don't want to 780 # be preempted by a server disconnect/reconnect (which automatically 781 # generates a new call to Rebuild). 782 set _buffering 1 783 784 set _width $w 785 set _height $h 786 $_arcball resize $w $h 787 DoResize 435 788 436 foreach ren [array names _lights] { 437 foreach light $_lights($ren) { 438 $ren RemoveLight $light 439 rename $light "" 440 } 441 set _lights($ren) "" 442 } 443 foreach dataobj $_dlist { 444 foreach actor $_actors($dataobj) { 445 $_renderer RemoveActor $actor 446 } 447 } 448 array unset _actors 449 set _dlist "" 450 array unset _dataobj2vtk 789 set _limits(vmin) "" 790 set _limits(vmax) "" 791 set _first "" 792 foreach dataobj [get -objects] { 793 if { [info exists _obj2ovride($dataobj-raise)] && $_first == "" } { 794 set _first $dataobj 795 } 796 set _obj2datasets($dataobj) "" 797 foreach comp [$dataobj components] { 798 set tag $dataobj-$comp 799 if { ![info exists _datasets($tag)] } { 800 set bytes [$dataobj data $comp] 801 set length [string length $bytes] 802 append _outbuf "dataset add $tag data follows $length\n" 803 append _outbuf $bytes 804 append _outbuf "polydata add $tag\n" 805 set _datasets($tag) 1 806 } 807 lappend _obj2datasets($dataobj) $tag 808 SetObjectStyle $dataobj $comp 809 if { [info exists _obj2ovride($dataobj-raise)] } { 810 SendCmd "dataset visible 1 $tag" 811 } else { 812 SendCmd "dataset visible 0 $tag" 813 } 814 } 815 } 816 # 817 # Reset the camera and other view parameters 818 # 819 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 820 $_arcball quaternion $q 821 SendCmd "camera orient $q" 822 PanCamera 823 SendCmd "camera mode persp" 824 if { $_reset || $_first == "" } { 825 Zoom reset 826 set _reset 0 827 } 828 FixSettings opacity 829 FixSettings grid-x 830 FixSettings grid-y 831 FixSettings grid-z 832 FixSettings volume 833 FixSettings lighting 834 FixSettings axes 835 FixSettings edges 836 FixSettings axismode 837 838 if {"" != $_first} { 839 set location [$_first hints camera] 840 if { $location != "" } { 841 array set view $location 842 } 843 } 844 845 set _buffering 0; # Turn off buffering. 846 847 # Actually write the commands to the server socket. If it fails, we don't 848 # care. We're finished here. 849 blt::busy hold $itk_component(hull) 850 SendBytes $_outbuf; 851 blt::busy release $itk_component(hull) 852 set _outbuf ""; # Clear the buffer. 853 } 854 855 # ---------------------------------------------------------------------- 856 # USAGE: CurrentDatasets ?-all -visible? ?dataobjs? 857 # 858 # Returns a list of server IDs for the current datasets being displayed. This 859 # is normally a single ID, but it might be a list of IDs if the current data 860 # object has multiple components. 861 # ---------------------------------------------------------------------- 862 itcl::body Rappture::VtkViewer::CurrentDatasets {args} { 863 set flag [lindex $args 0] 864 switch -- $flag { 865 "-all" { 866 if { [llength $args] > 1 } { 867 error "CurrentDatasets: can't specify dataobj after \"-all\"" 868 } 869 set dlist [get -objects] 870 } 871 "-visible" { 872 if { [llength $args] > 1 } { 873 set dlist {} 874 set args [lrange $args 1 end] 875 foreach dataobj $args { 876 if { [info exists _obj2ovride($dataobj-raise)] } { 877 lappend dlist $dataobj 878 } 879 } 880 } else { 881 set dlist [get -visible] 882 } 883 } 884 default { 885 set dlist $args 886 } 887 } 888 set rlist "" 889 foreach dataobj $dlist { 890 foreach comp [$dataobj components] { 891 set tag $dataobj-$comp 892 if { [info exists _datasets($tag)] && $_datasets($tag) } { 893 lappend rlist $tag 894 } 895 } 896 } 897 return $rlist 451 898 } 452 899 … … 460 907 # ---------------------------------------------------------------------- 461 908 itcl::body Rappture::VtkViewer::Zoom {option} { 462 set cam [$_renderer GetActiveCamera]463 909 switch -- $option { 464 in { 465 $cam Zoom 1.25 466 $_window Render 467 } 468 out { 469 $cam Zoom 0.8 470 $_window Render 471 } 472 reset { 473 $cam SetViewAngle 30 474 $_renderer ResetCamera 475 _3dView 90 -90 476 array set camera { 477 xpos 1.73477e-06 ypos 74.7518 zpos -1.73477e-06 478 xviewup 5.38569e-16 yviewup 2.32071e-08 zviewup 1.0 479 xfocal 0.0 yfocal 0.0 zfocal 0.0 480 angle 30 481 } 482 set dataobj [lindex $_dlist end] 483 if { $dataobj != "" } { 484 array set camera [$dataobj hints camera] 485 } 486 if { [info exists camera(clipmin)] } { 487 $cam SetClippingRange $camera(clipmin) $camera(clipmax) 488 } 489 if { [info exists camera(parallelscale)] } { 490 $cam SetParallelScale $camera(parallelscale) 491 } 492 $cam SetViewAngle $camera(angle) 493 $cam SetFocalPoint $camera(xfocal) $camera(yfocal) $camera(zfocal) 494 $cam SetPosition $camera(xpos) $camera(ypos) $camera(zpos) 495 $cam SetViewUp $camera(xviewup) $camera(yviewup) $camera(zviewup) 496 foreach key [array names camera] { 497 set _settings($this-$key) $camera($key) 498 } 499 $cam ComputeViewPlaneNormal 500 $_window Render 501 } 502 } 503 } 504 505 # ---------------------------------------------------------------------- 506 # USAGE: Move click <x> <y> 507 # USAGE: Move drag <x> <y> 508 # USAGE: Move release <x> <y> 910 "in" { 911 set _view(zoom) [expr {$_view(zoom)*1.25}] 912 SendCmd "camera zoom $_view(zoom)" 913 } 914 "out" { 915 set _view(zoom) [expr {$_view(zoom)*0.8}] 916 SendCmd "camera zoom $_view(zoom)" 917 } 918 "reset" { 919 array set _view { 920 qx 0 921 qy 0 922 qz 0 923 qw 1 924 zoom 1.0 925 pan-x 0 926 pan-y 0 927 zoom-x 1.0 928 zoom-y 1.0 929 } 930 SendCmd "camera reset all" 931 if { $_first != "" } { 932 set location [$_first hints camera] 933 if { $location != "" } { 934 array set _view $location 935 } 936 } 937 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 938 $_arcball quaternion $q 939 SendCmd "camera orient $q" 940 PanCamera 941 } 942 } 943 } 944 945 itcl::body Rappture::VtkViewer::PanCamera {} { 946 # set w [winfo width $itk_component(view)] 947 # set h [winfo height $itk_component(view)] 948 # set x [expr ($_view(pan-x)) / $w] 949 # set y [expr ($_view(pan-y)) / $h] 950 # set x [expr $x * $_limits(xmax) - $_limits(xmin)] 951 # set y [expr $y * $_limits(ymax) - $_limits(ymin)] 952 set x $_view(pan-x) 953 set y $_view(pan-y) 954 SendCmd "camera pan $x $y" 955 } 956 957 958 # ---------------------------------------------------------------------- 959 # USAGE: Rotate click <x> <y> 960 # USAGE: Rotate drag <x> <y> 961 # USAGE: Rotate release <x> <y> 509 962 # 510 963 # Called automatically when the user clicks/drags/releases in the 511 964 # plot area. Moves the plot according to the user's actions. 512 965 # ---------------------------------------------------------------------- 513 itcl::body Rappture::VtkViewer:: Move {option x y} {966 itcl::body Rappture::VtkViewer::Rotate {option x y} { 514 967 switch -- $option { 515 click{516 blt::busy configure $itk_component(area)-cursor fleur968 "click" { 969 $itk_component(view) configure -cursor fleur 517 970 set _click(x) $x 518 971 set _click(y) $y 519 set _click(theta) $_view(theta) 520 set _click(phi) $_view(phi) 521 } 522 drag { 972 } 973 "drag" { 523 974 if {[array size _click] == 0} { 524 Move click $x $y975 Rotate click $x $y 525 976 } else { 526 set w [winfo width $itk_component(plot)] 527 set h [winfo height $itk_component(plot)] 528 set scalex [expr {$_limits(xMax)-$_limits(xMin)}] 529 set scaley [expr {$_limits(yMax)-$_limits(yMin)}] 530 set dx [expr {double($x-$_click(x))/$w*$scalex}] 531 set dy [expr {double($y-$_click(y))/$h*$scaley}] 532 533 if {$_dims == "2D"} { 534 # 535 # Shift the contour plot in 2D 536 # 537 foreach dataobj $_dlist { 538 foreach actor $_actors($dataobj) { 539 foreach {ax ay az} [$actor GetPosition] break 540 $actor SetPosition [expr {$ax+$dx}] \ 541 [expr {$ay-$dy}] 0 542 } 543 } 544 $_window Render 545 } elseif {$_dims == "3D"} { 546 # 547 # Rotate the camera in 3D 548 # 549 set theta [expr {$_view(theta) - $dy*180}] 550 if {$theta < 2} { set theta 2 } 551 if {$theta > 178} { set theta 178 } 552 set phi [expr {$_view(phi) - $dx*360}] 553 554 _3dView $theta $phi 555 $_window Render 977 set w [winfo width $itk_component(view)] 978 set h [winfo height $itk_component(view)] 979 if {$w <= 0 || $h <= 0} { 980 return 556 981 } 982 983 if {[catch { 984 # this fails sometimes for no apparent reason 985 set dx [expr {double($x-$_click(x))/$w}] 986 set dy [expr {double($y-$_click(y))/$h}] 987 }]} { 988 return 989 } 990 if { $dx == 0 && $dy == 0 } { 991 return 992 } 993 set q [$_arcball rotate $x $y $_click(x) $_click(y)] 994 foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break 995 SendCmd "camera orient $q" 557 996 set _click(x) $x 558 997 set _click(y) $y 559 998 } 560 999 } 561 release{562 Move drag $x $y563 blt::busy configure $itk_component(area) -cursor left_ptr1000 "release" { 1001 Rotate drag $x $y 1002 $itk_component(view) configure -cursor "" 564 1003 catch {unset _click} 565 1004 } … … 568 1007 } 569 1008 } 570 UpdateCameraInfo 571 } 572 573 574 # ---------------------------------------------------------------------- 575 # USAGE: _3dView <theta> <phi> 576 # 577 # Used internally to change the position of the camera for 3D data 578 # sets. Sets the camera according to the angles <theta> (angle from 579 # the z-axis) and <phi> (angle from the x-axis in the x-y plane). 580 # Both angles are in degrees. 581 # ---------------------------------------------------------------------- 582 itcl::body Rappture::VtkViewer::_3dView {theta phi} { 583 return 584 set deg2rad 0.0174532927778 585 set xn [expr {sin($theta*$deg2rad)*cos($phi*$deg2rad)}] 586 set yn [expr {sin($theta*$deg2rad)*sin($phi*$deg2rad)}] 587 set zn [expr {cos($theta*$deg2rad)}] 588 589 set xm [expr {0.5*($_limits(xMax)+$_limits(xMin))}] 590 set ym [expr {0.5*($_limits(yMax)+$_limits(yMin))}] 591 set zm [expr {0.5*($_limits(zMax)+$_limits(zMin))}] 592 593 set cam [$_renderer GetActiveCamera] 594 set zoom [$cam GetViewAngle] 595 $cam SetViewAngle 30 596 $cam SetFocalPoint $xm $ym $zm 597 $cam SetPosition [expr {$xm-$xn}] [expr {$ym-$yn}] [expr {$zm+$zn}] 598 $cam ComputeViewPlaneNormal 599 $cam SetViewUp 0 0 1 ;# z-dir is up 600 $cam OrthogonalizeViewUp 601 $_renderer ResetCamera 602 $cam SetViewAngle $zoom 603 604 set _view(theta) $theta 605 set _view(phi) $phi 606 } 607 608 # ---------------------------------------------------------------------- 609 # USAGE: _fixLimits 610 # 611 # Used internally to apply automatic limits to the axes for the 612 # current plot. 613 # ---------------------------------------------------------------------- 614 itcl::body Rappture::VtkViewer::_fixLimits {} { 615 $_renderer ResetCamera 616 set camera [$_renderer GetActiveCamera] 617 $camera Zoom 1.5 618 $_window Render 619 if 0 { 620 $this-vtkRenderWindow2 Render 621 } 622 } 623 624 # ---------------------------------------------------------------------- 625 # USAGE: _color2rgb <color> 626 # 627 # Used internally to convert a color name to a set of {r g b} values 628 # needed for vtk. Each r/g/b component is scaled in the range 0-1. 629 # ---------------------------------------------------------------------- 630 itcl::body Rappture::VtkViewer::_color2rgb {color} { 631 foreach {r g b} [winfo rgb $itk_component(hull) $color] break 632 set r [expr {$r/65535.0}] 633 set g [expr {$g/65535.0}] 634 set b [expr {$b/65535.0}] 635 return [list $r $g $b] 1009 } 1010 1011 # ---------------------------------------------------------------------- 1012 # USAGE: $this Pan click x y 1013 # $this Pan drag x y 1014 # $this Pan release x y 1015 # 1016 # Called automatically when the user clicks on one of the zoom 1017 # controls for this widget. Changes the zoom for the current view. 1018 # ---------------------------------------------------------------------- 1019 itcl::body Rappture::VtkViewer::Pan {option x y} { 1020 switch -- $option { 1021 "set" { 1022 set w [winfo width $itk_component(view)] 1023 set h [winfo height $itk_component(view)] 1024 set x [expr $x / double($w)] 1025 set y [expr $y / double($h)] 1026 set _view(pan-x) [expr $_view(pan-x) + $x] 1027 set _view(pan-y) [expr $_view(pan-y) + $y] 1028 PanCamera 1029 return 1030 } 1031 "click" { 1032 set _click(x) $x 1033 set _click(y) $y 1034 $itk_component(view) configure -cursor hand1 1035 } 1036 "drag" { 1037 set w [winfo width $itk_component(view)] 1038 set h [winfo height $itk_component(view)] 1039 set dx [expr ($_click(x) - $x)/double($w)] 1040 set dy [expr ($_click(y) - $y)/double($h)] 1041 set _click(x) $x 1042 set _click(y) $y 1043 set _view(pan-x) [expr $_view(pan-x) - $dx] 1044 set _view(pan-y) [expr $_view(pan-y) - $dy] 1045 PanCamera 1046 } 1047 "release" { 1048 Pan drag $x $y 1049 $itk_component(view) configure -cursor "" 1050 } 1051 default { 1052 error "unknown option \"$option\": should set, click, drag, or release" 1053 } 1054 } 1055 } 1056 1057 # ---------------------------------------------------------------------- 1058 # USAGE: FixSettings <what> ?<value>? 1059 # 1060 # Used internally to update rendering settings whenever parameters 1061 # change in the popup settings panel. Sends the new settings off 1062 # to the back end. 1063 # ---------------------------------------------------------------------- 1064 itcl::body Rappture::VtkViewer::FixSettings {what {value ""}} { 1065 switch -- $what { 1066 "opacity" { 1067 if {[isconnected]} { 1068 set val $_settings($this-opacity) 1069 set sval [expr { 0.01 * double($val) }] 1070 foreach dataset [CurrentDatasets -visible $_first] { 1071 SendCmd "polydata opacity $sval $dataset" 1072 } 1073 } 1074 } 1075 "wireframe" { 1076 if {[isconnected]} { 1077 set bool $_settings($this-wireframe) 1078 foreach dataset [CurrentDatasets -visible $_first] { 1079 SendCmd "polydata wireframe $bool $dataset" 1080 } 1081 } 1082 } 1083 "volume" { 1084 if {[isconnected]} { 1085 set bool $_settings($this-volume) 1086 foreach dataset [CurrentDatasets -visible $_first] { 1087 SendCmd "polydata visible $bool $dataset" 1088 } 1089 } 1090 } 1091 "lighting" { 1092 if {[isconnected]} { 1093 set bool $_settings($this-lighting) 1094 foreach dataset [CurrentDatasets -visible $_first] { 1095 SendCmd "polydata lighting $bool $dataset" 1096 } 1097 } 1098 } 1099 "grid-x" { 1100 if {[isconnected]} { 1101 set bool $_settings($this-grid-x) 1102 SendCmd "axis grid x $bool" 1103 } 1104 } 1105 "grid-y" { 1106 if {[isconnected]} { 1107 set bool $_settings($this-grid-y) 1108 SendCmd "axis grid y $bool" 1109 } 1110 } 1111 "grid-z" { 1112 if {[isconnected]} { 1113 set bool $_settings($this-grid-z) 1114 SendCmd "axis grid z $bool" 1115 } 1116 } 1117 "edges" { 1118 if {[isconnected]} { 1119 set bool $_settings($this-edges) 1120 foreach dataset [CurrentDatasets -visible $_first] { 1121 SendCmd "polydata edges $bool $dataset" 1122 } 1123 } 1124 } 1125 "axes" { 1126 if { [isconnected] } { 1127 set bool $_settings($this-axes) 1128 SendCmd "axis visible all $bool" 1129 } 1130 } 1131 "axismode" { 1132 if { [isconnected] } { 1133 set mode [$itk_component(axismode) value] 1134 set mode [$itk_component(axismode) translate $mode] 1135 SendCmd "axis flymode $mode" 1136 } 1137 } 1138 default { 1139 error "don't know how to fix $what" 1140 } 1141 } 1142 } 1143 1144 # 1145 # SetStyles -- 1146 # 1147 itcl::body Rappture::VtkViewer::SetStyles { dataobj comp } { 1148 array set style { 1149 -color rainbow 1150 -levels 6 1151 -opacity 1.0 1152 } 1153 set tag $dataobj-$comp 1154 array set style [lindex [$dataobj components -style $comp] 0] 1155 set colormap "$style(-color):$style(-levels):$style(-opacity)" 1156 if { [info exists _colormaps($colormap)] } { 1157 puts stderr "Colormap $colormap already built" 1158 } 1159 if { ![info exists _dataset2style($tag)] } { 1160 set _dataset2style($tag) $colormap 1161 lappend _style2datasets($colormap) $tag 1162 } 1163 if { ![info exists _colormaps($colormap)] } { 1164 # Build the pseudo colormap if it doesn't exist. 1165 BuildColormap $colormap $dataobj $comp 1166 set _colormaps($colormap) 1 1167 } 1168 #SendCmd "polydata add $style(-levels) $tag\n" 1169 SendCmd "pseudocolor colormap $colormap $tag" 1170 return $colormap 1171 } 1172 1173 # 1174 # BuildColormap -- 1175 # 1176 itcl::body Rappture::VtkViewer::BuildColormap { colormap dataobj comp } { 1177 array set style { 1178 -color rainbow 1179 -levels 6 1180 -opacity 1.0 1181 } 1182 array set style [lindex [$dataobj components -style $comp] 0] 1183 1184 if {$style(-color) == "rainbow"} { 1185 set style(-color) "white:yellow:green:cyan:blue:magenta" 1186 } 1187 set clist [split $style(-color) :] 1188 set cmap {} 1189 for {set i 0} {$i < [llength $clist]} {incr i} { 1190 set x [expr {double($i)/([llength $clist]-1)}] 1191 set color [lindex $clist $i] 1192 append cmap "$x [Color2RGB $color] " 1193 } 1194 if { [llength $cmap] == 0 } { 1195 set cmap "0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0" 1196 } 1197 set tag $this-$colormap 1198 if { ![info exists _settings($tag-opacity)] } { 1199 set _settings($tag-opacity) $style(-opacity) 1200 } 1201 set max $_settings($tag-opacity) 1202 1203 set wmap "0.0 1.0 1.0 1.0" 1204 SendCmd "colormap add $colormap { $cmap } { $wmap }" 636 1205 } 637 1206 … … 640 1209 # ---------------------------------------------------------------------- 641 1210 itcl::configbody Rappture::VtkViewer::plotbackground { 642 foreach {r g b} [_color2rgb $itk_option(-plotbackground)] break 643 $_renderer SetBackground $r $g $b 644 $_window Render 645 if 0 { 646 $this-vtkRenderer2 SetBackground $r $g $b 647 $this-vtkRenderWindow2 Render 1211 if { [isconnected] } { 1212 foreach {r g b} [Color2RGB $itk_option(-plotbackground)] break 1213 SendCmd "screen bgcolor $r $g $b" 648 1214 } 649 1215 } … … 653 1219 # ---------------------------------------------------------------------- 654 1220 itcl::configbody Rappture::VtkViewer::plotforeground { 655 after cancel [itcl::code $this Rebuild] 656 after idle [itcl::code $this Rebuild] 657 } 658 659 itcl::body Rappture::VtkViewer::SetActorProperties { actor style } { 660 array set props { 661 -color \#6666FF 662 -edgevisibility yes 663 -edgecolor black 664 -linewidth 1.0 665 -opacity 1.0 666 } 667 # Parse style string. 668 array set props $style 669 set prop [$actor GetProperty] 670 eval $prop SetColor [_color2rgb $props(-color)] 671 if { $props(-edgevisibility) } { 672 $prop EdgeVisibilityOn 673 } else { 674 $prop EdgeVisibilityOff 675 } 676 set _settings($this-edges) $props(-edgevisibility) 677 eval $prop SetEdgeColor [_color2rgb $props(-edgecolor)] 678 $prop SetLineWidth $props(-linewidth) 679 $prop SetOpacity $props(-opacity) 680 set _settings($this-opacity) [expr $props(-opacity) * 100.0] 681 } 682 683 # ---------------------------------------------------------------------- 684 # USAGE: Rebuild 685 # 686 # Called automatically whenever something changes that affects the 687 # data in the widget. Clears any existing data and rebuilds the 688 # widget to display new data. 689 # ---------------------------------------------------------------------- 690 itcl::body Rappture::VtkViewer::Rebuild {} { 691 set id 0 692 693 # determine the dimensionality from the topmost (raised) object 694 set dlist [get] 695 set dataobj [lindex $dlist end] 696 if {$dataobj != ""} { 697 set _dims [lindex [lsort [$dataobj components -dimensions]] end] 698 } else { 699 set _dims "0D" 700 } 701 ComputeLimits 702 $_cubeAxesActor SetCamera [$_renderer GetActiveCamera] 703 eval $_cubeAxesActor SetBounds [GetLimits] 704 705 if 1 { 706 # 707 # LOOKUP TABLE FOR COLOR CONTOURS 708 # 709 # Use vmin/vmax if possible, otherwise get from data 710 if {$_limits(vMin) == "" || $_limits(vMax) == ""} { 711 set v0 0 712 set v1 1 713 if { [info exists _dataobj2vtk($dataobj)] } { 714 set pd [lindex $_dataobj2vtk($dataobj) 0] 715 if {"" != $pd} { 716 foreach {v0 v1} [$pd GetScalarRange] break 717 } 718 } 719 } else { 720 set v0 $_limits(vMin) 721 set v1 $_limits(vMax) 722 } 723 } 724 # scan through all data objects and build the contours 725 set firstobj 1 726 foreach dataobj $_dlist { 727 foreach comp [$dataobj components] { 728 set tag $dataobj-$comp 729 if { ![info exists _dataobj2vtk($tag)] } { 730 set actor [$dataobj values $comp] 731 set style [$dataobj style $comp] 732 set _dataobj2vtk($tag) $actor 733 lappend _actors($dataobj) $actor 734 $_renderer AddActor $actor 735 SetActorProperties $actor $style 736 incr id 737 } 738 } 739 set firstobj 0 740 } 741 set top [lindex [get] end] 742 if { $top != "" } { 743 foreach axis { x y z } { 744 set title [$top hints ${axis}label] 745 set units [$top hints ${axis}units] 746 set method Set[string toupper $axis]Title 747 set label "$title" 748 if { $units != "" } { 749 append label " ($units)" 750 } 751 $_cubeAxesActor $method $label 752 } 753 } 754 if 1 { 755 _fixLimits 756 Zoom reset 757 758 } 759 $_interactor Start 760 $_window Render 761 return 762 763 # 764 # HACK ALERT! A single ResetCamera doesn't seem to work for 765 # some contour data. You have to do it multiple times to 766 # get to the right zoom factor on data. I hope 20 times is 767 # enough. I hate Vtk sometimes... 768 # 769 for {set i 0} {$i < 20} {incr i} { 770 $_renderer ResetCamera 771 [$_renderer GetActiveCamera] Zoom 1.5 772 } 773 # prevent interactions -- use our own 774 blt::busy hold $itk_component(area) -cursor left_ptr 775 bind $itk_component(area)_Busy <ButtonPress> \ 776 [itcl::code $this Move click %x %y] 777 bind $itk_component(area)_Busy <B1-Motion> \ 778 [itcl::code $this Move drag %x %y] 779 bind $itk_component(area)_Busy <ButtonRelease> \ 780 [itcl::code $this Move release %x %y] 781 } 1221 if { [isconnected] } { 1222 foreach {r g b} [Color2RGB $itk_option(-plotforeground)] break 1223 #fix this! 1224 #SendCmd "color background $r $g $b" 1225 } 1226 } 1227 1228 itcl::body Rappture::VtkViewer::limits { dataobj } { 1229 1230 array unset _limits $dataobj-* 1231 foreach comp [$dataobj components] { 1232 set tag $dataobj-$comp 1233 if { ![info exists _limits($tag)] } { 1234 set data [$dataobj data $comp] 1235 set arr [vtkCharArray $tag-xvtkCharArray] 1236 $arr SetArray $data [string length $data] 1 1237 set reader [vtkPolyDataReader $tag-xvtkPolyDataReader] 1238 $reader SetInputArray $arr 1239 $reader ReadFromInputStringOn 1240 set mapper [vtkPolyDataMapper $tag-xvtkPolyDataMapper] 1241 $mapper SetInput [$reader GetOutput] 1242 set actor [vtkActor $tag-xvthActor] 1243 $actor SetMapper $mapper 1244 set _limits($tag) [$actor GetBounds] 1245 rename $actor "" 1246 rename $reader "" 1247 rename $arr "" 1248 rename $mapper "" 1249 } 1250 foreach { xMin xMax yMin yMax zMin zMax} $_limits($tag) break 1251 if {![info exists limits(xmin)] || $limits(xmin) > $xMin} { 1252 set limits(xmin) $xMin 1253 } 1254 if {![info exists limits(xmax)] || $limits(xmax) < $xMax} { 1255 set limits(xmax) $xMax 1256 } 1257 if {![info exists limits(ymin)] || $limits(ymin) > $yMin} { 1258 set limits(ymin) $xMin 1259 } 1260 if {![info exists limits(ymax)] || $limits(ymax) < $yMax} { 1261 set limits(ymax) $yMax 1262 } 1263 if {![info exists limits(zmin)] || $limits(zmin) > $zMin} { 1264 set limits(zmin) $zMin 1265 } 1266 if {![info exists limits(zmax)] || $limits(zmax) < $zMax} { 1267 set limits(zmax) $zMax 1268 } 1269 } 1270 return [array get limits] 1271 } 1272 782 1273 783 1274 itcl::body Rappture::VtkViewer::BuildViewTab {} { … … 786 1277 #set bfg [option get $itk_component(hull) boldFont Font] 787 1278 788 set tab[$itk_component(main) insert end \1279 set inner [$itk_component(main) insert end \ 789 1280 -title "View Settings" \ 790 1281 -icon [Rappture::icon wrench]] 791 set inner $tab792 if 0 {793 blt::scrollset $tab.ss \794 -xscrollbar $tab.ss.xs \795 -yscrollbar $tab.ss.ys \796 -window $tab.ss.frame797 pack $tab.ss -fill both -expand yes798 blt::tk::scrollbar $tab.ss.xs799 blt::tk::scrollbar $tab.ss.ys800 set inner [blt::tk::frame $tab.ss.frame]801 1282 $inner configure -borderwidth 4 802 } 803 set ::Rappture::VtkViewer::_settings($this-isosurface) 0 804 checkbutton $inner.isosurface \ 805 -text "Isosurface shading" \ 806 -variable [itcl::scope _settings($this-isosurface)] \ 807 -command [itcl::code $this FixSettings isosurface] \ 1283 1284 checkbutton $inner.wireframe \ 1285 -text "Wireframe" \ 1286 -variable [itcl::scope _settings($this-wireframe)] \ 1287 -command [itcl::code $this FixSettings wireframe] \ 808 1288 -font "Arial 9" 809 1289 … … 814 1294 -font "Arial 9" 815 1295 1296 checkbutton $inner.volume \ 1297 -text "Volume" \ 1298 -variable [itcl::scope _settings($this-volume)] \ 1299 -command [itcl::code $this FixSettings volume] \ 1300 -font "Arial 9" 1301 1302 checkbutton $inner.lighting \ 1303 -text "Lighting" \ 1304 -variable [itcl::scope _settings($this-lighting)] \ 1305 -command [itcl::code $this FixSettings lighting] \ 1306 -font "Arial 9" 1307 816 1308 checkbutton $inner.edges \ 817 1309 -text "Edges" \ … … 820 1312 -font "Arial 9" 821 1313 822 checkbutton $inner.smallaxes \ 823 -text "Small Axes" \ 824 -variable [itcl::scope _settings($this-smallaxes)] \ 825 -command [itcl::code $this FixSettings smallaxes] \ 826 -font "Arial 9" 827 828 checkbutton $inner.wireframe \ 829 -text "Wireframe" \ 830 -variable [itcl::scope _settings($this-wireframe)] \ 831 -command [itcl::code $this FixSettings wireframe] \ 832 -font "Arial 9" 833 834 blt::table $inner \ 835 0,0 $inner.axes -columnspan 2 -anchor w \ 836 1,0 $inner.edges -columnspan 2 -anchor w \ 837 2,0 $inner.wireframe -columnspan 2 -anchor w \ 838 3,0 $inner.smallaxes -columnspan 2 -anchor w 839 840 blt::table configure $inner r* -resize none 841 blt::table configure $inner r5 -resize expand 842 } 843 844 itcl::body Rappture::VtkViewer::BuildVolumeTab {} { 845 foreach { key value } { 846 light 40 847 transp 50 848 opacity 1000 849 } { 850 set _settings($this-$key) $value 851 } 852 853 set tab [$itk_component(main) insert end \ 854 -title "Volume Settings" \ 855 -icon [Rappture::icon volume-on]] 856 set inner $tab 857 if 0 { 858 blt::scrollset $tab.ss \ 859 -xscrollbar $tab.ss.xs \ 860 -yscrollbar $tab.ss.ys \ 861 -window $tab.ss.frame 862 pack $tab.ss -fill both -expand yes 863 blt::tk::scrollbar $tab.ss.xs 864 blt::tk::scrollbar $tab.ss.ys 865 set inner [blt::tk::frame $tab.ss.frame] 866 $inner configure -borderwidth 4 867 } 868 set fg [option get $itk_component(hull) font Font] 869 #set bfg [option get $itk_component(hull) boldFont Font] 870 871 checkbutton $inner.vol -text "Show volume" -font $fg \ 872 -variable [itcl::scope _settings($this-volume)] \ 873 -command [itcl::code $this FixSettings volume] 874 label $inner.shading -text "Shading:" -font $fg 875 876 label $inner.dim -text "Dim" -font $fg 877 ::scale $inner.light -from 0 -to 100 -orient horizontal \ 878 -variable [itcl::scope _settings($this-light)] \ 879 -width 10 \ 880 -showvalue off -command [itcl::code $this FixSettings light] 881 label $inner.bright -text "Bright" -font $fg 882 883 label $inner.fog -text "Fog" -font $fg 884 ::scale $inner.transp -from 0 -to 100 -orient horizontal \ 885 -variable [itcl::scope _settings($this-transp)] \ 886 -width 10 \ 887 -showvalue off -command [itcl::code $this FixSettings transp] 888 label $inner.plastic -text "Plastic" -font $fg 889 890 label $inner.clear -text "Clear" -font $fg 1314 label $inner.clear -text "Clear" -font "Arial 9" 891 1315 ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ 892 1316 -variable [itcl::scope _settings($this-opacity)] \ 893 1317 -width 10 \ 894 1318 -showvalue off -command [itcl::code $this FixSettings opacity] 895 label $inner.opaque -text "Opaque" -font $fg1319 label $inner.opaque -text "Opaque" -font "Arial 9" 896 1320 897 1321 blt::table $inner \ 898 0,0 $inner.vol -columnspan 4 -anchor w -pady 2 \ 899 1,0 $inner.shading -columnspan 4 -anchor w -pady {10 2} \ 900 2,0 $inner.dim -anchor e -pady 2 \ 901 2,1 $inner.light -columnspan 2 -pady 2 -fill x \ 902 2,3 $inner.bright -anchor w -pady 2 \ 903 3,0 $inner.fog -anchor e -pady 2 \ 904 3,1 $inner.transp -columnspan 2 -pady 2 -fill x \ 905 3,3 $inner.plastic -anchor w -pady 2 \ 906 4,0 $inner.clear -anchor e -pady 2 \ 907 4,1 $inner.opacity -columnspan 2 -pady 2 -fill x\ 908 4,3 $inner.opaque -anchor w -pady 2 909 910 blt::table configure $inner c0 c1 c3 r* -resize none 911 blt::table configure $inner r6 -resize expand 912 } 913 914 itcl::body Rappture::VtkViewer::UpdateCameraInfo {} { 915 set cam [$_renderer GetActiveCamera] 916 foreach key { x y z } \ 917 pt [$cam GetFocalPoint] \ 918 up [$cam GetViewUp] \ 919 pos [$cam GetPosition] { 920 set _settings($this-${key}focal) $pt 921 set _settings($this-${key}up) $up 922 set _settings($this-${key}pos) $pos 923 } 924 foreach {min max} [$cam GetClippingRange] break 925 set _settings($this-clipmin) $min 926 set _settings($this-clipmax) $max 927 set _settings($this-parallelscale) [$cam GetParallelScale] 928 set _settings($this-angle) [$cam GetViewAngle] 929 foreach key { xpos ypos zpos xviewup yviewup zviewup 930 xfocal yfocal zfocal angle clipmin clipmax parallelscale 931 } { 932 set out($key) $_settings($this-$key) 933 } 934 puts \"[array get out]\" 1322 0,0 $inner.axes -columnspan 4 -anchor w -pady 2 \ 1323 1,0 $inner.volume -columnspan 4 -anchor w -pady 2 \ 1324 2,0 $inner.wireframe -columnspan 4 -anchor w -pady 2 \ 1325 3,0 $inner.lighting -columnspan 4 -anchor w \ 1326 4,0 $inner.edges -columnspan 4 -anchor w -pady 2 \ 1327 5,0 $inner.clear -anchor e -pady 2 \ 1328 6,1 $inner.opacity -columnspan 2 -pady 2 -fill x\ 1329 6,3 $inner.opaque -anchor w -pady 2 1330 1331 blt::table configure $inner r* -resize none 1332 blt::table configure $inner r7 -resize expand 1333 } 1334 1335 itcl::body Rappture::VtkViewer::BuildAxisTab {} { 1336 1337 set fg [option get $itk_component(hull) font Font] 1338 #set bfg [option get $itk_component(hull) boldFont Font] 1339 1340 set inner [$itk_component(main) insert end \ 1341 -title "Axis Settings" \ 1342 -icon [Rappture::icon cog]] 1343 $inner configure -borderwidth 4 1344 1345 checkbutton $inner.axes \ 1346 -text "Visible" \ 1347 -variable [itcl::scope _settings($this-axes)] \ 1348 -command [itcl::code $this FixSettings axes] \ 1349 -font "Arial 9" 1350 1351 label $inner.grid -text "Grid" -font "Arial 9" 1352 set f [frame $inner.gridf] 1353 checkbutton $f.x \ 1354 -text "X" \ 1355 -variable [itcl::scope _settings($this-grid-x)] \ 1356 -command [itcl::code $this FixSettings grid-x] \ 1357 -font "Arial 9" 1358 checkbutton $f.y \ 1359 -text "Y" \ 1360 -variable [itcl::scope _settings($this-grid-y)] \ 1361 -command [itcl::code $this FixSettings grid-y] \ 1362 -font "Arial 9" 1363 checkbutton $f.z \ 1364 -text "Z" \ 1365 -variable [itcl::scope _settings($this-grid-z)] \ 1366 -command [itcl::code $this FixSettings grid-z] \ 1367 -font "Arial 9" 1368 pack $f.x $f.y $f.z -side left 1369 1370 label $inner.axismode -text "Mode" \ 1371 -font "Arial 9" 1372 1373 itk_component add axismode { 1374 Rappture::Combobox $inner.axismode_combo -width 10 -editable no 1375 } 1376 $inner.axismode_combo choices insert end \ 1377 "static_triad" "static" \ 1378 "closest_triad" "closest" \ 1379 "furthest_triad" "furthest" \ 1380 "outer_edges" "outer" 1381 $itk_component(axismode) value "outer" 1382 bind $inner.axismode_combo <<Value>> [itcl::code $this FixSettings axismode] 1383 1384 blt::table $inner \ 1385 0,0 $inner.axes -columnspan 4 -anchor w -pady 2 \ 1386 1,0 $inner.axismode -anchor w -pady 2 \ 1387 1,1 $inner.axismode_combo -cspan 3 -anchor w -pady 2 \ 1388 2,0 $inner.grid -anchor w -pady 2 \ 1389 2,1 $inner.gridf -anchor w -cspan 3 -fill x 1390 1391 blt::table configure $inner r* -resize none 1392 blt::table configure $inner r3 -resize expand 935 1393 } 936 1394 … … 938 1396 set inner [$itk_component(main) insert end \ 939 1397 -title "Camera Settings" \ 940 -icon [Rappture::icon camera]] 1398 -icon [Rappture::icon camera]] 941 1399 $inner configure -borderwidth 4 942 bind $inner <Map> [itcl::code $this UpdateCameraInfo] 943 944 label $inner.xposl -text "Position" 945 entry $inner.xpos -bg white \ 946 -textvariable [itcl::scope _settings($this-xpos)] 947 entry $inner.ypos -bg white \ 948 -textvariable [itcl::scope _settings($this-ypos)] 949 entry $inner.zpos -bg white \ 950 -textvariable [itcl::scope _settings($this-zpos)] 951 label $inner.xviewupl -text "View Up" 952 entry $inner.xviewup -bg white \ 953 -textvariable [itcl::scope _settings($this-xviewup)] 954 entry $inner.yviewup -bg white \ 955 -textvariable [itcl::scope _settings($this-yviewup)] 956 entry $inner.zviewup -bg white \ 957 -textvariable [itcl::scope _settings($this-zviewup)] 958 label $inner.xfocall -text "Focal Point" 959 entry $inner.xfocal -bg white \ 960 -textvariable [itcl::scope _settings($this-xfocal)] 961 entry $inner.yfocal -bg white \ 962 -textvariable [itcl::scope _settings($this-yfocal)] 963 entry $inner.zfocal -bg white \ 964 -textvariable [itcl::scope _settings($this-zfocal)] 965 label $inner.anglel -text "View Angle" 966 entry $inner.angle -bg white \ 967 -textvariable [itcl::scope _settings($this-angle)] 968 label $inner.clipl -text "Clipping Range" 969 entry $inner.clipmin -bg white \ 970 -textvariable [itcl::scope _settings($this-clipmin)] 971 entry $inner.clipmax -bg white \ 972 -textvariable [itcl::scope _settings($this-clipmax)] 973 label $inner.pscalel -text "Parallel Scale" 974 entry $inner.pscale -bg white \ 975 -textvariable [itcl::scope _settings($this-parallelscale)] 976 977 button $inner.refresh -text "Refresh" \ 978 -command [itcl::code $this UpdateCameraInfo] 1400 1401 set labels { qx qy qz qw pan-x pan-y zoom } 1402 set row 0 1403 foreach tag $labels { 1404 label $inner.${tag}label -text $tag -font "Arial 9" 1405 entry $inner.${tag} -font "Arial 9" -bg white \ 1406 -textvariable [itcl::scope _view($tag)] 1407 bind $inner.${tag} <KeyPress-Return> \ 1408 [itcl::code $this camera set ${tag}] 1409 blt::table $inner \ 1410 $row,0 $inner.${tag}label -anchor e -pady 2 \ 1411 $row,1 $inner.${tag} -anchor w -pady 2 1412 blt::table configure $inner r$row -resize none 1413 incr row 1414 } 1415 blt::table configure $inner c0 c1 -resize none 1416 blt::table configure $inner c2 -resize expand 1417 blt::table configure $inner r$row -resize expand 1418 } 1419 1420 1421 # 1422 # camera -- 1423 # 1424 itcl::body Rappture::VtkViewer::camera {option args} { 1425 switch -- $option { 1426 "show" { 1427 puts [array get _view] 1428 } 1429 "set" { 1430 set who [lindex $args 0] 1431 set x $_view($who) 1432 set code [catch { string is double $x } result] 1433 if { $code != 0 || !$result } { 1434 set x _view($who) 1435 return 1436 } 1437 switch -- $who { 1438 "pan-x" - "pan-y" { 1439 PanCamera 1440 } 1441 "qx" - "qy" - "qz" - "qw" { 1442 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 1443 $_arcball quaternion $q 1444 SendCmd "camera orient $q" 1445 } 1446 "zoom" { 1447 SendCmd "camera zoom $_view(zoom)" 1448 } 1449 } 1450 } 1451 } 1452 } 1453 1454 itcl::body Rappture::VtkViewer::ConvertToVtkData { dataobj comp } { 1455 foreach { x1 x2 xN y1 y2 yN } [$dataobj mesh $comp] break 1456 set values [$dataobj values $comp] 1457 append out "# vtk DataFile Version 2.0 \n" 1458 append out "Test data \n" 1459 append out "ASCII \n" 1460 append out "DATASET STRUCTURED_POINTS \n" 1461 append out "DIMENSIONS $xN $yN 1 \n" 1462 append out "ORIGIN 0 0 0 \n" 1463 append out "SPACING 1 1 1 \n" 1464 append out "POINT_DATA [expr $xN * $yN] \n" 1465 append out "SCALARS field float 1 \n" 1466 append out "LOOKUP_TABLE default \n" 1467 append out [join $values "\n"] 1468 append out "\n" 1469 return $out 1470 } 1471 1472 1473 itcl::body Rappture::VtkViewer::GetVtkData { args } { 1474 set bytes "" 1475 foreach dataobj [get] { 1476 foreach comp [$dataobj components] { 1477 set tag $dataobj-$comp 1478 set contents [ConvertToVtkData $dataobj $comp] 1479 append bytes "$contents\n\n" 1480 } 1481 } 1482 return [list .txt $bytes] 1483 } 1484 1485 itcl::body Rappture::VtkViewer::GetImage { args } { 1486 if { [image width $_image(download)] > 0 && 1487 [image height $_image(download)] > 0 } { 1488 set bytes [$_image(download) data -format "jpeg -quality 100"] 1489 set bytes [Rappture::encoding::decode -as b64 $bytes] 1490 return [list .jpg $bytes] 1491 } 1492 return "" 1493 } 1494 1495 itcl::body Rappture::VtkViewer::BuildDownloadPopup { popup command } { 1496 Rappture::Balloon $popup \ 1497 -title "[Rappture::filexfer::label downloadWord] as..." 1498 set inner [$popup component inner] 1499 label $inner.summary -text "" -anchor w 1500 radiobutton $inner.vtk_button -text "VTK data file" \ 1501 -variable [itcl::scope _downloadPopup(format)] \ 1502 -font "Helvetica 9 " \ 1503 -value vtk 1504 Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file." 1505 radiobutton $inner.image_button -text "Image File" \ 1506 -variable [itcl::scope _downloadPopup(format)] \ 1507 -value image 1508 Rappture::Tooltip::for $inner.image_button \ 1509 "Save as digital image." 1510 1511 button $inner.ok -text "Save" \ 1512 -highlightthickness 0 -pady 2 -padx 3 \ 1513 -command $command \ 1514 -compound left \ 1515 -image [Rappture::icon download] 1516 1517 button $inner.cancel -text "Cancel" \ 1518 -highlightthickness 0 -pady 2 -padx 3 \ 1519 -command [list $popup deactivate] \ 1520 -compound left \ 1521 -image [Rappture::icon cancel] 1522 979 1523 blt::table $inner \ 980 0,0 $inner.xposl -anchor w -pady 2 \ 981 1,0 $inner.xpos -pady 2 -fill x\ 982 2,0 $inner.ypos -pady 2 -fill x\ 983 3,0 $inner.zpos -pady 2 -fill x\ 984 4,0 $inner.xviewupl -anchor w -pady 2 \ 985 5,0 $inner.xviewup -pady 2 -fill x \ 986 6,0 $inner.yviewup -pady 2 -fill x \ 987 7,0 $inner.zviewup -pady 2 -fill x \ 988 8,0 $inner.xfocall -anchor w -pady 2 \ 989 9,0 $inner.xfocal -pady 2 -fill x \ 990 10,0 $inner.yfocal -pady 2 -fill x \ 991 11,0 $inner.zfocal -pady 2 -fill x \ 992 16,0 $inner.anglel -anchor w -pady 2 \ 993 17,0 $inner.angle -pady 2 -fill x \ 994 18,0 $inner.clipl -anchor w -pady 2 \ 995 19,0 $inner.clipmin -pady 2 -fill x \ 996 20,0 $inner.clipmax -pady 2 -fill x \ 997 21,0 $inner.pscalel -anchor w -pady 2 \ 998 22,0 $inner.pscale -pady 2 -fill x \ 999 23,0 $inner.refresh 1000 1001 blt::table configure $inner r* c* -resize none 1002 blt::table configure $inner c0 -resize expand 1003 blt::table configure $inner r24 -resize expand 1004 } 1005 1006 # ---------------------------------------------------------------------- 1007 # USAGE: FixSettings <what> ?<value>? 1008 # 1009 # Used internally to update rendering settings whenever parameters 1010 # change in the popup settings panel. Sends the new settings off 1011 # to the back end. 1012 # ---------------------------------------------------------------------- 1013 itcl::body Rappture::VtkViewer::FixSettings {what {value ""}} { 1014 switch -- $what { 1015 light { 1016 } 1017 transp { 1018 } 1019 opacity { 1020 set new [expr $_settings($this-opacity) * 0.01] 1021 foreach dataobj [get] { 1022 foreach comp [$dataobj components] { 1023 set actor [$dataobj values $comp] 1024 set prop [$actor GetProperty] 1025 $prop SetOpacity $new 1026 } 1027 } 1028 $_window Render 1029 } 1030 1031 "wireframe" { 1032 foreach dataobj [get] { 1033 foreach comp [$dataobj components] { 1034 set actor [$dataobj values $comp] 1035 set prop [$actor GetProperty] 1036 if { $_settings($this-wireframe) } { 1037 $prop SetRepresentationToWireframe 1038 } else { 1039 $prop SetRepresentationToSurface 1040 } 1041 } 1042 } 1043 $_window Render 1044 } 1045 "isosurface" { 1046 } 1047 "edges" { 1048 foreach dataobj [get] { 1049 foreach comp [$dataobj components] { 1050 set actor [$dataobj values $comp] 1051 set prop [$actor GetProperty] 1052 if { $_settings($this-edges) } { 1053 $prop EdgeVisibilityOn 1054 } else { 1055 $prop EdgeVisibilityOff 1056 } 1057 } 1058 } 1059 $_window Render 1060 } 1061 "axes" { 1062 if { $_settings($this-axes) } { 1063 $_cubeAxesActor VisibilityOn 1064 } else { 1065 $_cubeAxesActor VisibilityOff 1066 } 1067 $_window Render 1068 } 1069 "smallaxes" { 1070 $_axesWidget SetEnabled $_settings($this-smallaxes) 1071 $_window Render 1072 } 1073 default { 1074 error "don't know how to fix $what" 1075 } 1076 } 1077 } 1078 1079 itcl::body Rappture::VtkViewer::GetLimits {} { 1080 return [list $_limits(xMin) $_limits(xMax) \ 1081 $_limits(yMin) $_limits(yMax) \ 1082 $_limits(zMin) $_limits(zMax)] 1083 } 1084 1085 itcl::body Rappture::VtkViewer::ComputeLimits { args } { 1086 array set _limits { 1087 xMin 0 1088 xMax 1 1089 yMin 0 1090 yMax 1 1091 zMin 0 1092 zMax 1 1093 vMin 0 1094 vMax 1 1095 } 1096 set actors {} 1097 if { [llength $args] > 0 } { 1098 foreach dataobj $args { 1099 foreach comp [$dataobj components] { 1100 lappend actors [$dataobj values $comp] 1101 } 1102 } 1103 } else { 1104 foreach dataobj [get] { 1105 foreach comp [$dataobj components] { 1106 lappend actors [$dataobj values $comp] 1107 } 1108 } 1109 } 1110 if { [llength $actors] == 0 } { 1111 return 1112 } 1113 set actor [lindex $actors 0] 1114 foreach key { xMin xMax yMin yMax zMin zMax} value [$actor GetBounds] { 1115 set _limits($key) $value 1116 } 1117 foreach actor [lrange $actors 1 end] { 1118 foreach { xMin xMax yMin yMax zMin zMax} [$actor GetBounds] break 1119 if { $xMin < $_limits(xMin) } { 1120 set _limits(xMin) $xMin 1121 } 1122 if { $xMax > $_limits(xMax) } { 1123 set _limits(xMax) $xMax 1124 } 1125 if { $yMin < $_limits(yMin) } { 1126 set _limits(yMin) $yMin 1127 } 1128 if { $yMax > $_limits(yMax) } { 1129 set _limits(yMax) $yMax 1130 } 1131 if { $zMin < $_limits(zMin) } { 1132 set _limits(zMin) $zMin 1133 } 1134 if { $zMax > $_limits(zMax) } { 1135 set _limits(zMax) $zMax 1136 } 1137 } 1138 set _limits(vMin) $_limits(zMin) 1139 set _limits(vMax) $_limits(zMax) 1140 } 1524 0,0 $inner.summary -cspan 2 \ 1525 1,0 $inner.vtk_button -anchor w -cspan 2 -padx { 4 0 } \ 1526 2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \ 1527 4,1 $inner.cancel -width .9i -fill y \ 1528 4,0 $inner.ok -padx 2 -width .9i -fill y 1529 blt::table configure $inner r3 -height 4 1530 blt::table configure $inner r4 -pady 4 1531 raise $inner.image_button 1532 $inner.vtk_button invoke 1533 return $inner 1534 } 1535 1536 itcl::body Rappture::VtkViewer::SetObjectStyle { dataobj comp } { 1537 array set props { 1538 -color \#6666FF 1539 -edgevisibility 1 1540 -edgecolor black 1541 -linewidth 1.0 1542 -opacity 1.0 1543 -wireframe 0 1544 -lighting 1 1545 } 1546 # Parse style string. 1547 set style [$dataobj style $comp] 1548 set tag $dataobj-$comp 1549 array set props $style 1550 SendCmd "polydata color [Color2RGB $props(-color)] $tag" 1551 SendCmd "polydata edges $props(-edgevisibility) $tag" 1552 SendCmd "polydata lighting $props(-lighting) $tag" 1553 SendCmd "polydata linecolor [Color2RGB $props(-edgecolor)] $tag" 1554 SendCmd "polydata linewidth $props(-linewidth) $tag" 1555 SendCmd "polydata opacity $props(-opacity) $tag" 1556 if { $dataobj != $_first } { 1557 set props(-wireframe) 1 1558 } 1559 SendCmd "polydata wireframe $props(-wireframe) $tag" 1560 set _settings($this-opacity) [expr $props(-opacity) * 100.0] 1561 } 1562 1563 itcl::body Rappture::VtkViewer::IsValidObject { dataobj } { 1564 if {[catch {$dataobj isa Rappture::Scene} valid] != 0 || !$valid} { 1565 return 0 1566 } 1567 return 1 1568 } -
trunk/gui/scripts/vtkviewer2.tcl
r2259 r2385 1 1 2 2 # ---------------------------------------------------------------------- 3 # COMPONENT: vtkviewer 2- Vtk drawing object viewer3 # COMPONENT: vtkviewer - Vtk drawing object viewer 4 4 # 5 5 # It connects to the Vtk server running on a rendering farm, … … 16 16 #package require Img 17 17 18 option add *VtkViewer 2.width 4i widgetDefault19 option add *VtkViewer 2*cursor crosshair widgetDefault20 option add *VtkViewer 2.height 4i widgetDefault21 option add *VtkViewer 2.foreground black widgetDefault22 option add *VtkViewer 2.controlBackground gray widgetDefault23 option add *VtkViewer 2.controlDarkBackground #999999 widgetDefault24 option add *VtkViewer 2.plotBackground black widgetDefault25 option add *VtkViewer 2.plotForeground white widgetDefault26 option add *VtkViewer 2.font \18 option add *VtkViewer.width 4i widgetDefault 19 option add *VtkViewer*cursor crosshair widgetDefault 20 option add *VtkViewer.height 4i widgetDefault 21 option add *VtkViewer.foreground black widgetDefault 22 option add *VtkViewer.controlBackground gray widgetDefault 23 option add *VtkViewer.controlDarkBackground #999999 widgetDefault 24 option add *VtkViewer.plotBackground black widgetDefault 25 option add *VtkViewer.plotForeground white widgetDefault 26 option add *VtkViewer.font \ 27 27 -*-helvetica-medium-r-normal-*-12-* widgetDefault 28 28 29 29 # must use this name -- plugs into Rappture::resources::load 30 proc VtkViewer 2_init_resources {} {30 proc VtkViewer_init_resources {} { 31 31 Rappture::resources::register \ 32 vtkvis_server Rappture::VtkViewer 2::SetServerList33 } 34 35 itcl::class Rappture::VtkViewer 2{32 vtkvis_server Rappture::VtkViewer::SetServerList 33 } 34 35 itcl::class Rappture::VtkViewer { 36 36 inherit Rappture::VisViewer 37 37 … … 131 131 } 132 132 133 itk::usual VtkViewer 2{133 itk::usual VtkViewer { 134 134 keep -background -foreground -cursor -font 135 135 keep -plotbackground -plotforeground … … 139 139 # CONSTRUCTOR 140 140 # ---------------------------------------------------------------------- 141 itcl::body Rappture::VtkViewer 2::constructor {hostlist args} {141 itcl::body Rappture::VtkViewer::constructor {hostlist args} { 142 142 if {[catch {info level -1} caller]} { 143 143 puts stderr "Enter constructor" … … 342 342 # DESTRUCTOR 343 343 # ---------------------------------------------------------------------- 344 itcl::body Rappture::VtkViewer 2::destructor {} {344 itcl::body Rappture::VtkViewer::destructor {} { 345 345 Disconnect 346 346 $_dispatcher cancel !rebuild … … 352 352 } 353 353 354 itcl::body Rappture::VtkViewer 2::DoResize {} {354 itcl::body Rappture::VtkViewer::DoResize {} { 355 355 if { $_width < 2 } { 356 356 set _width 500 … … 365 365 } 366 366 367 itcl::body Rappture::VtkViewer 2::EventuallyResize { w h } {367 itcl::body Rappture::VtkViewer::EventuallyResize { w h } { 368 368 puts stderr "EventuallyResize $w $h" 369 369 set _width $w … … 383 383 # -color, -brightness, -width, -linestyle, and -raise. 384 384 # ---------------------------------------------------------------------- 385 itcl::body Rappture::VtkViewer 2::add {dataobj {settings ""}} {385 itcl::body Rappture::VtkViewer::add {dataobj {settings ""}} { 386 386 array set params { 387 387 -color auto … … 427 427 # 428 428 # ---------------------------------------------------------------------- 429 itcl::body Rappture::VtkViewer 2::delete {args} {429 itcl::body Rappture::VtkViewer::delete {args} { 430 430 if { [llength $args] == 0} { 431 431 set args $_dlist … … 463 463 # flag can also request the internal images being shown. 464 464 # ---------------------------------------------------------------------- 465 itcl::body Rappture::VtkViewer 2::get {args} {465 itcl::body Rappture::VtkViewer::get {args} { 466 466 if {[llength $args] == 0} { 467 467 set args "-objects" … … 534 534 # the user scans through data in the ResultSet viewer. 535 535 # ---------------------------------------------------------------------- 536 itcl::body Rappture::VtkViewer 2::scale {args} {536 itcl::body Rappture::VtkViewer::scale {args} { 537 537 array unset _limits 538 538 foreach dataobj $args { … … 571 571 # "string" is the data itself. 572 572 # ---------------------------------------------------------------------- 573 itcl::body Rappture::VtkViewer 2::download {option args} {573 itcl::body Rappture::VtkViewer::download {option args} { 574 574 switch $option { 575 575 coming { … … 624 624 # Any existing connection is automatically closed. 625 625 # ---------------------------------------------------------------------- 626 itcl::body Rappture::VtkViewer 2::Connect {} {626 itcl::body Rappture::VtkViewer::Connect {} { 627 627 puts stderr "Enter Connect: [info level -1]" 628 628 set _hosts [GetServerList "vtkvis"] … … 645 645 # Indicates if we are currently connected to the visualization server. 646 646 # 647 itcl::body Rappture::VtkViewer 2::isconnected {} {647 itcl::body Rappture::VtkViewer::isconnected {} { 648 648 return [VisViewer::IsConnected] 649 649 } … … 652 652 # disconnect -- 653 653 # 654 itcl::body Rappture::VtkViewer 2::disconnect {} {654 itcl::body Rappture::VtkViewer::disconnect {} { 655 655 Disconnect 656 656 set _reset 1 … … 663 663 # server. 664 664 # 665 itcl::body Rappture::VtkViewer 2::Disconnect {} {665 itcl::body Rappture::VtkViewer::Disconnect {} { 666 666 VisViewer::Disconnect 667 667 … … 676 676 # sendto -- 677 677 # 678 itcl::body Rappture::VtkViewer 2::sendto { bytes } {678 itcl::body Rappture::VtkViewer::sendto { bytes } { 679 679 SendBytes "$bytes\n" 680 680 } … … 687 687 # sent later. 688 688 # 689 itcl::body Rappture::VtkViewer 2::SendCmd {string} {689 itcl::body Rappture::VtkViewer::SendCmd {string} { 690 690 if { $_buffering } { 691 691 append _outbuf $string "\n" … … 705 705 # specified <size> will follow. 706 706 # ---------------------------------------------------------------------- 707 itcl::body Rappture::VtkViewer 2::ReceiveImage { args } {707 itcl::body Rappture::VtkViewer::ReceiveImage { args } { 708 708 array set info { 709 709 -token "???" … … 738 738 # ReceiveDataset -- 739 739 # 740 itcl::body Rappture::VtkViewer 2::ReceiveDataset { args } {740 itcl::body Rappture::VtkViewer::ReceiveDataset { args } { 741 741 if { ![isconnected] } { 742 742 return … … 768 768 # widget to display new data. 769 769 # ---------------------------------------------------------------------- 770 itcl::body Rappture::VtkViewer 2::Rebuild {} {770 itcl::body Rappture::VtkViewer::Rebuild {} { 771 771 772 772 set w [winfo width $itk_component(view)] … … 860 860 # object has multiple components. 861 861 # ---------------------------------------------------------------------- 862 itcl::body Rappture::VtkViewer 2::CurrentDatasets {args} {862 itcl::body Rappture::VtkViewer::CurrentDatasets {args} { 863 863 set flag [lindex $args 0] 864 864 switch -- $flag { … … 906 906 # controls for this widget. Changes the zoom for the current view. 907 907 # ---------------------------------------------------------------------- 908 itcl::body Rappture::VtkViewer 2::Zoom {option} {908 itcl::body Rappture::VtkViewer::Zoom {option} { 909 909 switch -- $option { 910 910 "in" { … … 943 943 } 944 944 945 itcl::body Rappture::VtkViewer 2::PanCamera {} {945 itcl::body Rappture::VtkViewer::PanCamera {} { 946 946 # set w [winfo width $itk_component(view)] 947 947 # set h [winfo height $itk_component(view)] … … 964 964 # plot area. Moves the plot according to the user's actions. 965 965 # ---------------------------------------------------------------------- 966 itcl::body Rappture::VtkViewer 2::Rotate {option x y} {966 itcl::body Rappture::VtkViewer::Rotate {option x y} { 967 967 switch -- $option { 968 968 "click" { … … 1017 1017 # controls for this widget. Changes the zoom for the current view. 1018 1018 # ---------------------------------------------------------------------- 1019 itcl::body Rappture::VtkViewer 2::Pan {option x y} {1019 itcl::body Rappture::VtkViewer::Pan {option x y} { 1020 1020 switch -- $option { 1021 1021 "set" { … … 1062 1062 # to the back end. 1063 1063 # ---------------------------------------------------------------------- 1064 itcl::body Rappture::VtkViewer 2::FixSettings {what {value ""}} {1064 itcl::body Rappture::VtkViewer::FixSettings {what {value ""}} { 1065 1065 switch -- $what { 1066 1066 "opacity" { … … 1145 1145 # SetStyles -- 1146 1146 # 1147 itcl::body Rappture::VtkViewer 2::SetStyles { dataobj comp } {1147 itcl::body Rappture::VtkViewer::SetStyles { dataobj comp } { 1148 1148 array set style { 1149 1149 -color rainbow … … 1174 1174 # BuildColormap -- 1175 1175 # 1176 itcl::body Rappture::VtkViewer 2::BuildColormap { colormap dataobj comp } {1176 itcl::body Rappture::VtkViewer::BuildColormap { colormap dataobj comp } { 1177 1177 array set style { 1178 1178 -color rainbow … … 1208 1208 # CONFIGURATION OPTION: -plotbackground 1209 1209 # ---------------------------------------------------------------------- 1210 itcl::configbody Rappture::VtkViewer 2::plotbackground {1210 itcl::configbody Rappture::VtkViewer::plotbackground { 1211 1211 if { [isconnected] } { 1212 1212 foreach {r g b} [Color2RGB $itk_option(-plotbackground)] break … … 1218 1218 # CONFIGURATION OPTION: -plotforeground 1219 1219 # ---------------------------------------------------------------------- 1220 itcl::configbody Rappture::VtkViewer 2::plotforeground {1220 itcl::configbody Rappture::VtkViewer::plotforeground { 1221 1221 if { [isconnected] } { 1222 1222 foreach {r g b} [Color2RGB $itk_option(-plotforeground)] break … … 1226 1226 } 1227 1227 1228 itcl::body Rappture::VtkViewer 2::limits { dataobj } {1228 itcl::body Rappture::VtkViewer::limits { dataobj } { 1229 1229 1230 1230 array unset _limits $dataobj-* … … 1272 1272 1273 1273 1274 itcl::body Rappture::VtkViewer 2::BuildViewTab {} {1274 itcl::body Rappture::VtkViewer::BuildViewTab {} { 1275 1275 1276 1276 set fg [option get $itk_component(hull) font Font] … … 1333 1333 } 1334 1334 1335 itcl::body Rappture::VtkViewer 2::BuildAxisTab {} {1335 itcl::body Rappture::VtkViewer::BuildAxisTab {} { 1336 1336 1337 1337 set fg [option get $itk_component(hull) font Font] … … 1393 1393 } 1394 1394 1395 itcl::body Rappture::VtkViewer 2::BuildCameraTab {} {1395 itcl::body Rappture::VtkViewer::BuildCameraTab {} { 1396 1396 set inner [$itk_component(main) insert end \ 1397 1397 -title "Camera Settings" \ … … 1422 1422 # camera -- 1423 1423 # 1424 itcl::body Rappture::VtkViewer 2::camera {option args} {1424 itcl::body Rappture::VtkViewer::camera {option args} { 1425 1425 switch -- $option { 1426 1426 "show" { … … 1452 1452 } 1453 1453 1454 itcl::body Rappture::VtkViewer 2::ConvertToVtkData { dataobj comp } {1454 itcl::body Rappture::VtkViewer::ConvertToVtkData { dataobj comp } { 1455 1455 foreach { x1 x2 xN y1 y2 yN } [$dataobj mesh $comp] break 1456 1456 set values [$dataobj values $comp] … … 1471 1471 1472 1472 1473 itcl::body Rappture::VtkViewer 2::GetVtkData { args } {1473 itcl::body Rappture::VtkViewer::GetVtkData { args } { 1474 1474 set bytes "" 1475 1475 foreach dataobj [get] { … … 1483 1483 } 1484 1484 1485 itcl::body Rappture::VtkViewer 2::GetImage { args } {1485 itcl::body Rappture::VtkViewer::GetImage { args } { 1486 1486 if { [image width $_image(download)] > 0 && 1487 1487 [image height $_image(download)] > 0 } { … … 1493 1493 } 1494 1494 1495 itcl::body Rappture::VtkViewer 2::BuildDownloadPopup { popup command } {1495 itcl::body Rappture::VtkViewer::BuildDownloadPopup { popup command } { 1496 1496 Rappture::Balloon $popup \ 1497 1497 -title "[Rappture::filexfer::label downloadWord] as..." … … 1534 1534 } 1535 1535 1536 itcl::body Rappture::VtkViewer 2::SetObjectStyle { dataobj comp } {1536 itcl::body Rappture::VtkViewer::SetObjectStyle { dataobj comp } { 1537 1537 array set props { 1538 1538 -color \#6666FF … … 1561 1561 } 1562 1562 1563 itcl::body Rappture::VtkViewer 2::IsValidObject { dataobj } {1563 itcl::body Rappture::VtkViewer::IsValidObject { dataobj } { 1564 1564 if {[catch {$dataobj isa Rappture::Scene} valid] != 0 || !$valid} { 1565 1565 return 0
Note: See TracChangeset
for help on using the changeset viewer.