[3330] | 1 | # -*- mode: tcl; indent-tabs-mode: nil -*- |
---|
[1373] | 2 | |
---|
| 3 | # ---------------------------------------------------------------------- |
---|
| 4 | # COMPONENT: unirect3d - represents a uniform rectangular 2-D mesh. |
---|
| 5 | # |
---|
| 6 | # This object represents one field in an XML description of a device. |
---|
| 7 | # It simplifies the process of extracting data vectors that represent |
---|
| 8 | # the field. |
---|
| 9 | # ====================================================================== |
---|
| 10 | # AUTHOR: Michael McLennan, Purdue University |
---|
[3177] | 11 | # Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
[1373] | 12 | # |
---|
| 13 | # See the file "license.terms" for information on usage and |
---|
| 14 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
| 15 | # ====================================================================== |
---|
| 16 | package require Itcl |
---|
| 17 | package require BLT |
---|
| 18 | |
---|
| 19 | namespace eval Rappture { # forward declaration } |
---|
| 20 | |
---|
| 21 | itcl::class Rappture::Unirect3d { |
---|
[1525] | 22 | constructor {xmlobj field cname {extents 1}} { # defined below } |
---|
[1373] | 23 | destructor { # defined below } |
---|
| 24 | |
---|
| 25 | public method limits {axis} |
---|
| 26 | public method blob {} |
---|
| 27 | public method mesh {} |
---|
| 28 | public method values {} |
---|
[3940] | 29 | public method valuesObj {} |
---|
[3917] | 30 | public method units { axis } |
---|
| 31 | public method label { axis } |
---|
[1373] | 32 | public method hints {{keyword ""}} |
---|
| 33 | public method order {} { |
---|
[1929] | 34 | return _axisOrder; |
---|
[1373] | 35 | } |
---|
[1463] | 36 | private method GetString { obj path varName } |
---|
| 37 | private method GetValue { obj path varName } |
---|
| 38 | private method GetSize { obj path varName } |
---|
| 39 | |
---|
[2744] | 40 | private variable _axisOrder "x y z" |
---|
| 41 | private variable _xMax 0 |
---|
| 42 | private variable _xMin 0 |
---|
| 43 | private variable _xNum 0; # Number of points along x-axis. |
---|
| 44 | private variable _yMax 0 |
---|
| 45 | private variable _yMin 0 |
---|
| 46 | private variable _yNum 0; # Number of points along y-axis. |
---|
| 47 | private variable _zMax 0 |
---|
| 48 | private variable _zMin 0 |
---|
| 49 | private variable _zNum 0; # Number of points along z-axis. |
---|
| 50 | private variable _compNum 1; # Number of components in values. |
---|
| 51 | private variable _values ""; # BLT vector containing the z-values |
---|
[1373] | 52 | private variable _hints |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | # ---------------------------------------------------------------------- |
---|
| 56 | # Constructor |
---|
| 57 | # ---------------------------------------------------------------------- |
---|
[1525] | 58 | itcl::body Rappture::Unirect3d::constructor {xmlobj field cname {extents 1}} { |
---|
[1373] | 59 | if {![Rappture::library isvalid $xmlobj]} { |
---|
[1929] | 60 | error "bad value \"$xmlobj\": should be Rappture::library" |
---|
[1373] | 61 | } |
---|
| 62 | set path [$field get $cname.mesh] |
---|
[1463] | 63 | set m [$xmlobj element -as object $path] |
---|
| 64 | GetValue $m "xaxis.max" _xMax |
---|
| 65 | GetValue $m "xaxis.min" _xMin |
---|
| 66 | GetValue $m "yaxis.max" _yMax |
---|
| 67 | GetValue $m "yaxis.min" _yMin |
---|
| 68 | GetValue $m "zaxis.max" _zMax |
---|
| 69 | GetValue $m "zaxis.min" _zMin |
---|
| 70 | GetSize $m "xaxis.numpoints" _xNum |
---|
| 71 | GetSize $m "yaxis.numpoints" _yNum |
---|
| 72 | GetSize $m "zaxis.numpoints" _zNum |
---|
[1525] | 73 | set _compNum $extents |
---|
[2830] | 74 | foreach {key path} { |
---|
| 75 | group about.group |
---|
| 76 | label about.label |
---|
| 77 | color about.color |
---|
| 78 | style about.style |
---|
| 79 | type about.type |
---|
| 80 | xlabel xaxis.label |
---|
| 81 | xdesc xaxis.description |
---|
| 82 | xunits xaxis.units |
---|
| 83 | xscale xaxis.scale |
---|
| 84 | ylabel yaxis.label |
---|
| 85 | ydesc yaxis.description |
---|
| 86 | yunits yaxis.units |
---|
| 87 | yscale yaxis.scale |
---|
| 88 | zlabel zaxis.label |
---|
| 89 | zdesc zaxis.description |
---|
| 90 | zunits zaxis.units |
---|
| 91 | zscale zaxis.scale |
---|
| 92 | order about.axisorder |
---|
| 93 | } { |
---|
| 94 | set str [$m get $path] |
---|
| 95 | if {"" != $str} { |
---|
| 96 | set _hints($key) $str |
---|
| 97 | } |
---|
| 98 | } |
---|
| 99 | foreach {key} { axisorder } { |
---|
| 100 | set str [$field get $cname.$key] |
---|
| 101 | if {"" != $str} { |
---|
| 102 | set _hints($key) $str |
---|
| 103 | } |
---|
| 104 | } |
---|
[1463] | 105 | itcl::delete object $m |
---|
[1373] | 106 | |
---|
| 107 | set _values [blt::vector create #auto] |
---|
| 108 | $_values set [$field get "$cname.values"] |
---|
[1525] | 109 | set n [expr $_xNum * $_yNum * $_zNum * $_compNum] |
---|
| 110 | if { [$_values length] != $n } { |
---|
[3050] | 111 | error "wrong \# of values in \"$cname.values\": expected $n values, got [$_values length]" |
---|
[1525] | 112 | } |
---|
[1373] | 113 | } |
---|
| 114 | |
---|
| 115 | # ---------------------------------------------------------------------- |
---|
| 116 | # Destructor |
---|
| 117 | # ---------------------------------------------------------------------- |
---|
| 118 | itcl::body Rappture::Unirect3d::destructor {} { |
---|
| 119 | if { $_values != "" } { |
---|
[1929] | 120 | blt::vector destroy $_values |
---|
[1373] | 121 | } |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | # ---------------------------------------------------------------------- |
---|
| 125 | # method blob |
---|
[2744] | 126 | # Returns a base64 encoded, gzipped Tcl list that represents the |
---|
| 127 | # Tcl command and data to recreate the uniform rectangular grid |
---|
| 128 | # on the nanovis server. |
---|
[1373] | 129 | # ---------------------------------------------------------------------- |
---|
| 130 | itcl::body Rappture::Unirect3d::blob {} { |
---|
[1463] | 131 | lappend data "unirect3d" |
---|
| 132 | lappend data "xmin" $_xMin "xmax" $_xMax "xnum" $_xNum |
---|
| 133 | lappend data "ymin" $_yMin "ymax" $_yMax "ynum" $_yNum |
---|
| 134 | lappend data "zmin" $_zMin "zmax" $_zMax "znum" $_zNum |
---|
| 135 | lappend data "axisorder" $_axisOrder |
---|
[1373] | 136 | if { [$_values length] > 0 } { |
---|
[1929] | 137 | lappend data "values" [$_values range 0 end] |
---|
[1373] | 138 | } |
---|
[1509] | 139 | return $data |
---|
[1373] | 140 | } |
---|
| 141 | |
---|
| 142 | # ---------------------------------------------------------------------- |
---|
| 143 | # method mesh |
---|
[2744] | 144 | # Returns a base64 encoded, gzipped Tcl list that represents the |
---|
| 145 | # Tcl command and data to recreate the uniform rectangular grid |
---|
| 146 | # on the nanovis server. |
---|
[1373] | 147 | # ---------------------------------------------------------------------- |
---|
| 148 | itcl::body Rappture::Unirect3d::mesh {} { |
---|
[1463] | 149 | set dx [expr {($_xMax - $_xMin) / double($_xNum)}] |
---|
| 150 | set dy [expr {($_yMax - $_yMin) / double($_yNum)}] |
---|
| 151 | set dz [expr {($_zMax - $_zMin) / double($_zNum)}] |
---|
| 152 | foreach {a b c} $_axisOrder break |
---|
| 153 | for { set i 0 } { $i < [set _${a}Num] } { incr i } { |
---|
[1929] | 154 | set v1 [expr {[set _${a}Min] + (double($i) * [set d${a}])}] |
---|
| 155 | for { set j 0 } { $j < [set _${b}Num] } { incr j } { |
---|
| 156 | set v2 [expr {[set _${b}Min] + (double($i) * [set d${b}])}] |
---|
| 157 | for { set k 0 } { $k < [set _${c}Num] } { incr k } { |
---|
| 158 | set v3 [expr {[set _${c}Min] + (double($i) * [set d${c}])}] |
---|
| 159 | lappend data $v1 $v2 $v3 |
---|
| 160 | } |
---|
| 161 | } |
---|
[1373] | 162 | } |
---|
| 163 | return $data |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | # ---------------------------------------------------------------------- |
---|
| 167 | # method values |
---|
[2744] | 168 | # Returns a base64 encoded, gzipped Tcl list that represents the |
---|
| 169 | # Tcl command and data to recreate the uniform rectangular grid |
---|
| 170 | # on the nanovis server. |
---|
[1373] | 171 | # ---------------------------------------------------------------------- |
---|
| 172 | itcl::body Rappture::Unirect3d::values {} { |
---|
| 173 | if { [$_values length] > 0 } { |
---|
[1929] | 174 | return [$_values range 0 end] |
---|
[1373] | 175 | } |
---|
| 176 | return "" |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | # ---------------------------------------------------------------------- |
---|
[3940] | 180 | # method valuesObj |
---|
| 181 | # Returns a base64 encoded, gzipped Tcl list that represents the |
---|
| 182 | # Tcl command and data to recreate the uniform rectangular grid |
---|
| 183 | # on the nanovis server. |
---|
| 184 | # ---------------------------------------------------------------------- |
---|
| 185 | itcl::body Rappture::Unirect3d::valuesObj {} { |
---|
| 186 | return $_values |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | # ---------------------------------------------------------------------- |
---|
[1373] | 190 | # method limits <axis> |
---|
[2744] | 191 | # Returns a list {min max} representing the limits for the |
---|
| 192 | # specified axis. |
---|
[1373] | 193 | # ---------------------------------------------------------------------- |
---|
| 194 | itcl::body Rappture::Unirect3d::limits {which} { |
---|
| 195 | set min "" |
---|
| 196 | set max "" |
---|
| 197 | |
---|
| 198 | switch -- $which { |
---|
[1929] | 199 | x - xlin - xlog { |
---|
| 200 | set min $_xMin |
---|
| 201 | set max $_xMax |
---|
| 202 | } |
---|
| 203 | y - ylin - ylog { |
---|
| 204 | set min $_yMin |
---|
| 205 | set max $_yMax |
---|
| 206 | } |
---|
| 207 | z - zlin - zlog { |
---|
| 208 | set min $_zMin |
---|
| 209 | set max $_zMax |
---|
| 210 | } |
---|
| 211 | v - vlin - vlog { |
---|
| 212 | if { [$_values length] > 0 } { |
---|
| 213 | set min [blt::vector expr min($_values)] |
---|
| 214 | set max [blt::vector expr max($_values)] |
---|
| 215 | } else { |
---|
| 216 | set min 0.0 |
---|
| 217 | set max 1.0 |
---|
| 218 | } |
---|
| 219 | } |
---|
| 220 | default { |
---|
| 221 | error "unknown axis description \"$which\"" |
---|
| 222 | } |
---|
[1373] | 223 | } |
---|
| 224 | return [list $min $max] |
---|
| 225 | } |
---|
| 226 | |
---|
[3917] | 227 | # |
---|
| 228 | # units -- |
---|
| 229 | # |
---|
| 230 | # Returns the units of the given axis. |
---|
| 231 | # |
---|
| 232 | itcl::body Rappture::Unirect3d::units { axis } { |
---|
| 233 | if { [info exists _hints({$axis}units)] } { |
---|
| 234 | return $_hints(${axis}units) |
---|
| 235 | } |
---|
| 236 | return "" |
---|
| 237 | } |
---|
[1373] | 238 | |
---|
[3917] | 239 | # |
---|
| 240 | # label -- |
---|
| 241 | # |
---|
| 242 | # Returns the label of the given axis. |
---|
| 243 | # |
---|
| 244 | itcl::body Rappture::Unirect3d::label { axis } { |
---|
| 245 | if { [info exists _hints({$axis}label)] } { |
---|
| 246 | return $_hints(${axis}label) |
---|
| 247 | } |
---|
| 248 | return "" |
---|
| 249 | } |
---|
| 250 | |
---|
[1373] | 251 | # ---------------------------------------------------------------------- |
---|
| 252 | # USAGE: hints ?<keyword>? |
---|
| 253 | # |
---|
| 254 | # Returns a list of key/value pairs for various hints about plotting |
---|
| 255 | # this curve. If a particular <keyword> is specified, then it returns |
---|
| 256 | # the hint for that <keyword>, if it exists. |
---|
| 257 | # ---------------------------------------------------------------------- |
---|
| 258 | itcl::body Rappture::Unirect3d::hints {{keyword ""}} { |
---|
[2830] | 259 | if {[info exists _hints(xlabel)] && "" != $_hints(xlabel) |
---|
| 260 | && [info exists _hints(xunits)] && "" != $_hints(xunits)} { |
---|
| 261 | set _hints(xlabel) "$_hints(xlabel) ($_hints(xunits))" |
---|
| 262 | } |
---|
| 263 | if {[info exists _hints(ylabel)] && "" != $_hints(ylabel) |
---|
| 264 | && [info exists _hints(yunits)] && "" != $_hints(yunits)} { |
---|
| 265 | set _hints(ylabel) "$_hints(ylabel) ($_hints(yunits))" |
---|
| 266 | } |
---|
| 267 | if {[info exists _hints(zlabel)] && "" != $_hints(zlabel) |
---|
| 268 | && [info exists _hints(zunits)] && "" != $_hints(zunits)} { |
---|
| 269 | set _hints(ylabel) "$_hints(zlabel) ($_hints(zunits))" |
---|
| 270 | } |
---|
[1373] | 271 | |
---|
[2830] | 272 | if {[info exists _hints(group)] && [info exists _hints(label)]} { |
---|
| 273 | # pop-up help for each curve |
---|
| 274 | set _hints(tooltip) $_hints(label) |
---|
[1373] | 275 | } |
---|
| 276 | if {$keyword != ""} { |
---|
[1929] | 277 | if {[info exists _hints($keyword)]} { |
---|
| 278 | return $_hints($keyword) |
---|
| 279 | } |
---|
| 280 | return "" |
---|
[1373] | 281 | } |
---|
| 282 | return [array get _hints] |
---|
| 283 | } |
---|
[1463] | 284 | |
---|
| 285 | itcl::body Rappture::Unirect3d::GetSize { obj path varName } { |
---|
| 286 | set string [$obj get $path] |
---|
| 287 | if { [scan $string "%d" value] != 1 || $value < 0 } { |
---|
[1929] | 288 | puts stderr "can't get size \"$string\" of \"$path\"" |
---|
| 289 | return |
---|
[1463] | 290 | } |
---|
| 291 | upvar $varName size |
---|
| 292 | set size $value |
---|
| 293 | } |
---|
| 294 | |
---|
| 295 | itcl::body Rappture::Unirect3d::GetValue { obj path varName } { |
---|
| 296 | set string [$obj get $path] |
---|
| 297 | if { [scan $string "%g" value] != 1 } { |
---|
[1929] | 298 | puts stderr "can't get value \"$string\" of \"$path\"" |
---|
| 299 | return |
---|
[1463] | 300 | } |
---|
| 301 | upvar $varName number |
---|
| 302 | set number $value |
---|
| 303 | } |
---|
| 304 | |
---|
| 305 | itcl::body Rappture::Unirect3d::GetString { obj path varName } { |
---|
| 306 | set string [$obj get $path] |
---|
| 307 | if { $string == "" } { |
---|
[1929] | 308 | puts stderr "can't get string \"$string\" of \"$path\"" |
---|
| 309 | return |
---|
[1463] | 310 | } |
---|
| 311 | upvar $varName str |
---|
| 312 | set str $string |
---|
| 313 | } |
---|