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