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 _order; |
---|
31 | } |
---|
32 | public method dimensions {} { |
---|
33 | return _dim; |
---|
34 | } |
---|
35 | private variable _order "x y z" |
---|
36 | private variable _dimensions 1 |
---|
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 | |
---|
59 | set mobj [$xmlobj element -as object $path] |
---|
60 | set order [$mobj get "axisorder"] |
---|
61 | if { $order != "" } { |
---|
62 | set _order $order |
---|
63 | } |
---|
64 | set dim [$mobj get "dimensions"] |
---|
65 | if { $dim != "" } { |
---|
66 | set _dimensions $dim |
---|
67 | } |
---|
68 | set _xmin [$mobj get "xaxis.min"] |
---|
69 | set _xmax [$mobj get "xaxis.max"] |
---|
70 | set _xnum [$mobj get "xaxis.numpoints"] |
---|
71 | set _ymin [$mobj get "yaxis.min"] |
---|
72 | set _ymax [$mobj get "yaxis.max"] |
---|
73 | set _ynum [$mobj get "yaxis.numpoints"] |
---|
74 | set _zmin [$mobj get "zaxis.min"] |
---|
75 | set _zmax [$mobj get "zaxis.max"] |
---|
76 | set _znum [$mobj get "zaxis.numpoints"] |
---|
77 | itcl::delete object $mobj |
---|
78 | |
---|
79 | set _values [blt::vector create #auto] |
---|
80 | $_values set [$field get "$cname.values"] |
---|
81 | } |
---|
82 | |
---|
83 | # ---------------------------------------------------------------------- |
---|
84 | # Destructor |
---|
85 | # ---------------------------------------------------------------------- |
---|
86 | itcl::body Rappture::Unirect3d::destructor {} { |
---|
87 | if { $_values != "" } { |
---|
88 | blt::vector destroy $_values |
---|
89 | } |
---|
90 | } |
---|
91 | |
---|
92 | # ---------------------------------------------------------------------- |
---|
93 | # method blob |
---|
94 | # Returns a base64 encoded, gzipped Tcl list that represents the |
---|
95 | # Tcl command and data to recreate the uniform rectangular grid |
---|
96 | # on the nanovis server. |
---|
97 | # ---------------------------------------------------------------------- |
---|
98 | itcl::body Rappture::Unirect3d::blob {} { |
---|
99 | set data "unirect3d" |
---|
100 | lappend data "xmin" $_xmin "xmax" $_xmax "xnum" $_xnum |
---|
101 | lappend data "ymin" $_ymin "ymax" $_ymax "ynum" $_ynum |
---|
102 | lappend data "zmin" $_zmin "zmax" $_zmax "znum" $_znum |
---|
103 | lappend data "axisorder" $_axisorder |
---|
104 | lappend data "dimensions" $_dim |
---|
105 | if { [$_values length] > 0 } { |
---|
106 | lappend data "values" [$_values range 0 end] |
---|
107 | } |
---|
108 | return [Rappture::encoding::encode -as zb64 $data] |
---|
109 | } |
---|
110 | |
---|
111 | # ---------------------------------------------------------------------- |
---|
112 | # method mesh |
---|
113 | # Returns a base64 encoded, gzipped Tcl list that represents the |
---|
114 | # Tcl command and data to recreate the uniform rectangular grid |
---|
115 | # on the nanovis server. |
---|
116 | # ---------------------------------------------------------------------- |
---|
117 | itcl::body Rappture::Unirect3d::mesh {} { |
---|
118 | set dx [expr {($_xmax - $_xmin) / double($_xnum)}] |
---|
119 | set dy [expr {($_ymax - $_ymin) / double($_ynum)}] |
---|
120 | set dz [expr {($_zmax - $_zmin) / double($_znum)}] |
---|
121 | foreach {a b c} $_axisorder break |
---|
122 | for { set i 0 } { $i < [set _${a}num] } { incr i } { |
---|
123 | set v1 [expr {[set _${a}min] + (double($i) * [set d${a}])}] |
---|
124 | for { set j 0 } { $j < [set _${b}num] } { incr j } { |
---|
125 | set v2 [expr {[set _${b}min] + (double($i) * [set d${b}])}] |
---|
126 | for { set k 0 } { $k < [set _{$c}num] } { incr k } { |
---|
127 | set v3 [expr {[set _${c}min] + (double($i) * [set d${c}])}] |
---|
128 | lappend data $v1 $v2 $v3 |
---|
129 | } |
---|
130 | } |
---|
131 | } |
---|
132 | return $data |
---|
133 | } |
---|
134 | |
---|
135 | # ---------------------------------------------------------------------- |
---|
136 | # method values |
---|
137 | # Returns a base64 encoded, gzipped Tcl list that represents the |
---|
138 | # Tcl command and data to recreate the uniform rectangular grid |
---|
139 | # on the nanovis server. |
---|
140 | # ---------------------------------------------------------------------- |
---|
141 | itcl::body Rappture::Unirect3d::values {} { |
---|
142 | if { [$_values length] > 0 } { |
---|
143 | return [$_values range 0 end] |
---|
144 | } |
---|
145 | return "" |
---|
146 | } |
---|
147 | |
---|
148 | # ---------------------------------------------------------------------- |
---|
149 | # method limits <axis> |
---|
150 | # Returns a list {min max} representing the limits for the |
---|
151 | # specified axis. |
---|
152 | # ---------------------------------------------------------------------- |
---|
153 | itcl::body Rappture::Unirect3d::limits {which} { |
---|
154 | set min "" |
---|
155 | set max "" |
---|
156 | |
---|
157 | switch -- $which { |
---|
158 | x - xlin - xlog { |
---|
159 | set min $_xmin |
---|
160 | set max $_xmax |
---|
161 | set axis "xaxis" |
---|
162 | } |
---|
163 | y - ylin - ylog { |
---|
164 | set min $_ymin |
---|
165 | set max $_ymax |
---|
166 | set axis "yaxis" |
---|
167 | } |
---|
168 | z - zlin - zlog { |
---|
169 | set min $_zmin |
---|
170 | set max $_zmax |
---|
171 | set axis "zaxis" |
---|
172 | } |
---|
173 | v - vlin - vlog { |
---|
174 | if { [$_values length] > 0 } { |
---|
175 | set min [blt::vector expr min($_values)] |
---|
176 | set max [blt::vector expr max($_values)] |
---|
177 | } else { |
---|
178 | set min 0.0 |
---|
179 | set max 1.0 |
---|
180 | } |
---|
181 | set axis "vaxis" |
---|
182 | } |
---|
183 | default { |
---|
184 | error "unknown axis description \"$which\"" |
---|
185 | } |
---|
186 | } |
---|
187 | return [list $min $max] |
---|
188 | } |
---|
189 | |
---|
190 | |
---|
191 | # ---------------------------------------------------------------------- |
---|
192 | # USAGE: hints ?<keyword>? |
---|
193 | # |
---|
194 | # Returns a list of key/value pairs for various hints about plotting |
---|
195 | # this curve. If a particular <keyword> is specified, then it returns |
---|
196 | # the hint for that <keyword>, if it exists. |
---|
197 | # ---------------------------------------------------------------------- |
---|
198 | itcl::body Rappture::Unirect3d::hints {{keyword ""}} { |
---|
199 | if {![info exists _hints]} { |
---|
200 | foreach {key path} { |
---|
201 | group about.group |
---|
202 | label about.label |
---|
203 | color about.color |
---|
204 | style about.style |
---|
205 | type about.type |
---|
206 | xlabel xaxis.label |
---|
207 | xdesc xaxis.description |
---|
208 | xunits xaxis.units |
---|
209 | xscale xaxis.scale |
---|
210 | ylabel yaxis.label |
---|
211 | ydesc yaxis.description |
---|
212 | yunits yaxis.units |
---|
213 | yscale yaxis.scale |
---|
214 | zlabel zaxis.label |
---|
215 | zdesc zaxis.description |
---|
216 | zunits zaxis.units |
---|
217 | zscale zaxis.scale |
---|
218 | dim about.dimension |
---|
219 | order about.axisorder |
---|
220 | } { |
---|
221 | set str [$_curve get $path] |
---|
222 | if {"" != $str} { |
---|
223 | set _hints($key) $str |
---|
224 | } |
---|
225 | } |
---|
226 | |
---|
227 | if {[info exists _hints(xlabel)] && "" != $_hints(xlabel) |
---|
228 | && [info exists _hints(xunits)] && "" != $_hints(xunits)} { |
---|
229 | set _hints(xlabel) "$_hints(xlabel) ($_hints(xunits))" |
---|
230 | } |
---|
231 | if {[info exists _hints(ylabel)] && "" != $_hints(ylabel) |
---|
232 | && [info exists _hints(yunits)] && "" != $_hints(yunits)} { |
---|
233 | set _hints(ylabel) "$_hints(ylabel) ($_hints(yunits))" |
---|
234 | } |
---|
235 | if {[info exists _hints(zlabel)] && "" != $_hints(zlabel) |
---|
236 | && [info exists _hints(zunits)] && "" != $_hints(zunits)} { |
---|
237 | set _hints(ylabel) "$_hints(zlabel) ($_hints(zunits))" |
---|
238 | } |
---|
239 | if {[info exists _hints(group)] && [info exists _hints(label)]} { |
---|
240 | # pop-up help for each curve |
---|
241 | set _hints(tooltip) $_hints(label) |
---|
242 | } |
---|
243 | } |
---|
244 | if {$keyword != ""} { |
---|
245 | if {[info exists _hints($keyword)]} { |
---|
246 | return $_hints($keyword) |
---|
247 | } |
---|
248 | return "" |
---|
249 | } |
---|
250 | return [array get _hints] |
---|
251 | } |
---|