Changeset 5679 for branches/uq/gui/scripts/unirect3d.tcl
- Timestamp:
- Jun 9, 2015 1:55:08 PM (9 years ago)
- Location:
- branches/uq
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/uq
- Property svn:mergeinfo changed
-
branches/uq/gui/scripts/unirect3d.tcl
r5121 r5679 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 3 # ---------------------------------------------------------------------- 4 # COMPONENT: unirect3d - represents a uniform rectangular 2-D mesh. 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 # ---------------------------------------------------------------------- 3 # COMPONENT: unirect3d - represents a uniform rectangular 3-D mesh. 5 4 # 6 5 # This object represents one field in an XML description of a device. … … 20 19 21 20 itcl::class Rappture::Unirect3d { 22 constructor {xmlobj field cname {extents 1}} { # defined below } 23 destructor { # defined below } 24 21 constructor {xmlobj path} { 22 # defined below 23 } 24 destructor { 25 # defined below 26 } 27 public proc fetch {xmlobj path} 28 public proc release {obj} 29 30 public method dimensions {} { 31 return 3 32 } 33 public method hints {{keyword ""}} 34 public method isvalid {} { 35 return $_isValid 36 } 37 public method label { axis } 25 38 public method limits {axis} 26 public method blob {} 27 public method mesh {} 28 public method values {} 29 public method valuesObj {} 39 public method numpoints {} { 40 return $_numPoints 41 } 30 42 public method units { axis } 31 public method label { axis } 32 public method hints {{keyword ""}} 33 public method order {} { 34 return _axisOrder; 35 } 43 public method vtkdata {{what -partial}} {} 44 36 45 private method GetString { obj path varName } 37 46 private method GetValue { obj path varName } 38 47 private method GetSize { obj path varName } 39 48 40 private variable _axisOrder "x y z"41 49 private variable _xMax 0 42 50 private variable _xMin 0 … … 48 56 private variable _zMin 0 49 57 private variable _zNum 0; # Number of points along z-axis 50 private variable _compNum 1; # Number of components in values51 private variable _values ""; # BLT vector containing the values52 58 private variable _hints 59 private variable _vtkdata "" 60 private variable _numPoints 0 61 private variable _isValid 0; # Indicates if the data is valid. 62 63 private common _xp2obj ; # used for fetch/release ref counting 64 private common _obj2ref ; # used for fetch/release ref counting 65 } 66 67 # 68 # fetch <xmlobj> <path> 69 # 70 # Clients use this instead of a constructor to fetch the Mesh for a 71 # particular <path> in the <xmlobj>. When the client is done with the mesh, 72 # he calls "release" to decrement the reference count. When the mesh is no 73 # longer needed, it is cleaned up automatically. 74 # 75 itcl::body Rappture::Unirect3d::fetch {xmlobj path} { 76 set handle "$xmlobj|$path" 77 if {[info exists _xp2obj($handle)]} { 78 set obj $_xp2obj($handle) 79 incr _obj2ref($obj) 80 return $obj 81 } 82 set obj [Rappture::Unirect3d ::#auto $xmlobj $path] 83 set _xp2obj($handle) $obj 84 set _obj2ref($obj) 1 85 return $obj 86 } 87 88 # ---------------------------------------------------------------------- 89 # USAGE: Rappture::Unirect3d::release <obj> 90 # 91 # Clients call this when they're no longer using a Mesh fetched 92 # previously by the "fetch" proc. This decrements the reference 93 # count for the mesh and destroys the object when it is no longer 94 # in use. 95 # ---------------------------------------------------------------------- 96 itcl::body Rappture::Unirect3d::release { obj } { 97 if { ![info exists _obj2ref($obj)] } { 98 error "can't find reference count for $obj" 99 } 100 incr _obj2ref($obj) -1 101 if {$_obj2ref($obj) <= 0} { 102 unset _obj2ref($obj) 103 foreach handle [array names _xp2obj] { 104 if {$_xp2obj($handle) == $obj} { 105 unset _xp2obj($handle) 106 } 107 } 108 itcl::delete object $obj 109 } 53 110 } 54 111 … … 56 113 # Constructor 57 114 # ---------------------------------------------------------------------- 58 itcl::body Rappture::Unirect3d::constructor {xmlobj field cname {extents 1}} {115 itcl::body Rappture::Unirect3d::constructor {xmlobj path} { 59 116 if {![Rappture::library isvalid $xmlobj]} { 60 117 error "bad value \"$xmlobj\": should be Rappture::library" 61 118 } 62 set path [$field get $cname.mesh]63 119 set m [$xmlobj element -as object $path] 120 GetValue $m "xaxis.min" _xMin 64 121 GetValue $m "xaxis.max" _xMax 65 GetValue $m " xaxis.min" _xMin122 GetValue $m "yaxis.min" _yMin 66 123 GetValue $m "yaxis.max" _yMax 67 GetValue $m " yaxis.min" _yMin124 GetValue $m "zaxis.min" _zMin 68 125 GetValue $m "zaxis.max" _zMax 69 GetValue $m "zaxis.min" _zMin70 126 GetSize $m "xaxis.numpoints" _xNum 71 127 GetSize $m "yaxis.numpoints" _yNum 72 128 GetSize $m "zaxis.numpoints" _zNum 73 set _compNum $extents74 129 foreach {key path} { 75 group about.group76 130 label about.label 77 131 color about.color 78 132 style about.style 79 type about.type80 133 xlabel xaxis.label 81 134 xdesc xaxis.description 82 135 xunits xaxis.units 83 136 xscale xaxis.scale 137 xmin xaxis.min 138 xmax xaxis.max 84 139 ylabel yaxis.label 85 140 ydesc yaxis.description 86 141 yunits yaxis.units 87 142 yscale yaxis.scale 143 ymin yaxis.min 144 ymax yaxis.max 88 145 zlabel zaxis.label 89 146 zdesc zaxis.description 90 147 zunits zaxis.units 91 148 zscale zaxis.scale 92 order about.axisorder 149 zmin zaxis.min 150 zmax zaxis.max 93 151 } { 94 152 set str [$m get $path] … … 97 155 } 98 156 } 99 foreach {key} { axisorder } {100 set str [$field get $cname.$key]101 if {"" != $str} {102 set _hints($key) $str103 }104 }105 157 itcl::delete object $m 106 107 set _values [blt::vector create #auto] 108 $_values set [$field get "$cname.values"] 109 set n [expr $_xNum * $_yNum * $_zNum * $_compNum] 110 if { [$_values length] != $n } { 111 error "wrong \# of values in \"$cname.values\": expected $n values, got [$_values length]" 112 } 158 set _numPoints [expr $_xNum * $_yNum * $_zNum] 159 if { $_numPoints == 0 } { 160 set _vtkdata "" 161 return 162 } 163 append out "DATASET STRUCTURED_POINTS\n" 164 append out "DIMENSIONS $_xNum $_yNum $_zNum\n" 165 append out "ORIGIN $_xMin $_yMin $_zMin\n" 166 if { $_xNum > 1 } { 167 set xSpace [expr (double($_xMax) - double($_xMin))/double($_xNum - 1)] 168 } else { 169 set xSpace 0.0 170 } 171 if { $_yNum > 1 } { 172 set ySpace [expr (double($_yMax) - double($_yMin))/double($_yNum - 1)] 173 } else { 174 set ySpace 0.0 175 } 176 if { $_zNum > 1 } { 177 set zSpace [expr (double($_zMax) - double($_zMin))/double($_zNum - 1)] 178 } else { 179 set zSpace 0.0 180 } 181 append out "SPACING $xSpace $ySpace $zSpace\n" 182 set _vtkdata $out 183 set _isValid 1 184 puts stderr "WARNING: The <unirect3d> element is deprecated. Please use a <mesh> instead." 113 185 } 114 186 … … 117 189 # ---------------------------------------------------------------------- 118 190 itcl::body Rappture::Unirect3d::destructor {} { 119 if { $_values != "" } { 120 blt::vector destroy $_values 121 } 122 } 123 124 # ---------------------------------------------------------------------- 125 # method blob 126 # Returns a Tcl list that represents the Tcl command and data to 127 # recreate the uniform rectangular grid on the nanovis server. 128 # ---------------------------------------------------------------------- 129 itcl::body Rappture::Unirect3d::blob {} { 130 lappend data "unirect3d" 131 lappend data "xmin" $_xMin "xmax" $_xMax "xnum" $_xNum 132 lappend data "ymin" $_yMin "ymax" $_yMax "ynum" $_yNum 133 lappend data "zmin" $_zMin "zmax" $_zMax "znum" $_zNum 134 lappend data "axisorder" $_axisOrder 135 if { [$_values length] > 0 } { 136 lappend data "values" [$_values range 0 end] 137 } 138 return $data 139 } 140 141 # ---------------------------------------------------------------------- 142 # method mesh 143 # Returns a Tcl list that represents the points of the uniform 144 # grid. 145 # ---------------------------------------------------------------------- 146 itcl::body Rappture::Unirect3d::mesh {} { 147 set dx [expr {($_xMax - $_xMin) / double($_xNum)}] 148 set dy [expr {($_yMax - $_yMin) / double($_yNum)}] 149 set dz [expr {($_zMax - $_zMin) / double($_zNum)}] 150 foreach {a b c} $_axisOrder break 151 for { set i 0 } { $i < [set _${a}Num] } { incr i } { 152 set v1 [expr {[set _${a}Min] + (double($i) * [set d${a}])}] 153 for { set j 0 } { $j < [set _${b}Num] } { incr j } { 154 set v2 [expr {[set _${b}Min] + (double($i) * [set d${b}])}] 155 for { set k 0 } { $k < [set _${c}Num] } { incr k } { 156 set v3 [expr {[set _${c}Min] + (double($i) * [set d${c}])}] 157 lappend data $v1 $v2 $v3 158 } 159 } 160 } 161 return $data 162 } 163 164 # ---------------------------------------------------------------------- 165 # method values 166 # Returns a Tcl list that represents the field values 167 # ---------------------------------------------------------------------- 168 itcl::body Rappture::Unirect3d::values {} { 169 if { [$_values length] > 0 } { 170 return [$_values range 0 end] 171 } 172 return "" 173 } 174 175 # ---------------------------------------------------------------------- 176 # method valuesObj 177 # Returns a BLT vector that represents the field values 178 # ---------------------------------------------------------------------- 179 itcl::body Rappture::Unirect3d::valuesObj {} { 180 return $_values 191 # empty 181 192 } 182 193 183 194 # ---------------------------------------------------------------------- 184 195 # method limits <axis> 185 # Returns a list {min max} representing the limits for the 196 # Returns a list {min max} representing the limits for the 186 197 # specified axis. 187 198 # ---------------------------------------------------------------------- … … 203 214 set max $_zMax 204 215 } 205 v - vlin - vlog {206 if { [$_values length] > 0 } {207 set min [blt::vector expr min($_values)]208 set max [blt::vector expr max($_values)]209 } else {210 set min 0.0211 set max 1.0212 }213 }214 216 default { 215 217 error "unknown axis description \"$which\"" … … 225 227 # 226 228 itcl::body Rappture::Unirect3d::units { axis } { 227 if { [info exists _hints( {$axis}units)] } {229 if { [info exists _hints(${axis}units)] } { 228 230 return $_hints(${axis}units) 229 231 } … … 237 239 # 238 240 itcl::body Rappture::Unirect3d::label { axis } { 239 if { [info exists _hints( {$axis}label)] } {241 if { [info exists _hints(${axis}label)] } { 240 242 return $_hints(${axis}label) 241 243 } … … 250 252 # the hint for that <keyword>, if it exists. 251 253 # ---------------------------------------------------------------------- 252 itcl::body Rappture::Unirect3d::hints { {keyword ""}} {254 itcl::body Rappture::Unirect3d::hints { {keyword ""} } { 253 255 if {[info exists _hints(xlabel)] && "" != $_hints(xlabel) 254 256 && [info exists _hints(xunits)] && "" != $_hints(xunits)} { … … 263 265 set _hints(ylabel) "$_hints(zlabel) ($_hints(zunits))" 264 266 } 265 266 267 if {[info exists _hints(group)] && [info exists _hints(label)]} { 267 268 # pop-up help for each curve … … 275 276 } 276 277 return [array get _hints] 278 } 279 280 itcl::body Rappture::Unirect3d::vtkdata {{what -partial}} { 281 if {$what == "-full"} { 282 append out "# vtk DataFile Version 3.0\n" 283 append out "[hints label]\n" 284 append out "ASCII\n" 285 append out $_vtkdata 286 return $out 287 } else { 288 return $_vtkdata 289 } 277 290 } 278 291
Note: See TracChangeset
for help on using the changeset viewer.