1 | |
---|
2 | # ---------------------------------------------------------------------- |
---|
3 | # COMPONENT: drawing3d - 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. |
---|
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 | package require vtk |
---|
18 | |
---|
19 | namespace eval Rappture { |
---|
20 | # forward declaration |
---|
21 | } |
---|
22 | |
---|
23 | itcl::class Rappture::Drawing3d { |
---|
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 _drawing3d |
---|
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::Drawing3d::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 _drawing3d [$xmlobj element -as object $path] |
---|
56 | set _units [$_drawing3d 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 [$_xmlobj get $path.$elem.vtk] |
---|
75 | set arr [vtkCharArray $this-xvtkCharArray] |
---|
76 | $arr SetArray $data [string length $data] 1 |
---|
77 | set reader [vtkPolyDataReader $this-xvtkPolyDataReader] |
---|
78 | $reader SetInputArray $arr |
---|
79 | $reader ReadFromInputStringOn |
---|
80 | set mapper [vtkPolyDataMapper $this-xvtkPolyDataMapper] |
---|
81 | $mapper SetInput [$reader GetOutput] |
---|
82 | set actor [vtkActor $this-xvthActor] |
---|
83 | $actor SetMapper $mapper |
---|
84 | set _actors($elem) $actor |
---|
85 | set _limits($elem) [$actor GetBounds] |
---|
86 | set _styles($elem) [$_xmlobj get $path.$elem.style] |
---|
87 | set _data($elem) $mapper |
---|
88 | } |
---|
89 | } |
---|
90 | } |
---|
91 | foreach {key path} { |
---|
92 | group about.group |
---|
93 | label about.label |
---|
94 | color about.color |
---|
95 | type about.type |
---|
96 | xlabel xaxis.label |
---|
97 | xdesc xaxis.description |
---|
98 | xunits xaxis.units |
---|
99 | xscale xaxis.scale |
---|
100 | xmin xaxis.min |
---|
101 | xmax xaxis.max |
---|
102 | ylabel yaxis.label |
---|
103 | ydesc yaxis.description |
---|
104 | yunits yaxis.units |
---|
105 | yscale yaxis.scale |
---|
106 | ymin yaxis.min |
---|
107 | ymax yaxis.max |
---|
108 | } { |
---|
109 | set str [$_drawing3d get $path] |
---|
110 | if {"" != $str} { |
---|
111 | set _hints($key) $str |
---|
112 | } |
---|
113 | } |
---|
114 | foreach {key} { axisorder } { |
---|
115 | set str [$_drawing3d get $key] |
---|
116 | if {"" != $str} { |
---|
117 | set _hints($key) $str |
---|
118 | } |
---|
119 | } |
---|
120 | } |
---|
121 | |
---|
122 | # ---------------------------------------------------------------------- |
---|
123 | # Destructor |
---|
124 | # ---------------------------------------------------------------------- |
---|
125 | itcl::body Rappture::Drawing3d::destructor {} { |
---|
126 | foreach key [array names _actors] { |
---|
127 | set actor _actors($key) |
---|
128 | } |
---|
129 | } |
---|
130 | |
---|
131 | # ---------------------------------------------------------------------- |
---|
132 | # method style |
---|
133 | # Returns a base64 encoded, gzipped Tcl list that represents the |
---|
134 | # Tcl command and data to recreate the uniform rectangular grid |
---|
135 | # on the nanovis server. |
---|
136 | # ---------------------------------------------------------------------- |
---|
137 | itcl::body Rappture::Drawing3d::style { elem } { |
---|
138 | if { [info exists _styles($elem)] } { |
---|
139 | return $_styles($elem) |
---|
140 | } |
---|
141 | return "" |
---|
142 | } |
---|
143 | |
---|
144 | # ---------------------------------------------------------------------- |
---|
145 | # method data |
---|
146 | # Returns a base64 encoded, gzipped Tcl list that represents the |
---|
147 | # Tcl command and data to recreate the uniform rectangular grid |
---|
148 | # on the nanovis server. |
---|
149 | # ---------------------------------------------------------------------- |
---|
150 | itcl::body Rappture::Drawing3d::data { elem } { |
---|
151 | if { [info exists _data($elem)] } { |
---|
152 | return $_data($elem) |
---|
153 | } |
---|
154 | return "" |
---|
155 | } |
---|
156 | |
---|
157 | # ---------------------------------------------------------------------- |
---|
158 | # method values |
---|
159 | # Returns a base64 encoded, gzipped Tcl list that represents the |
---|
160 | # Tcl command and data to recreate the uniform rectangular grid |
---|
161 | # on the nanovis server. |
---|
162 | # ---------------------------------------------------------------------- |
---|
163 | itcl::body Rappture::Drawing3d::values { elem } { |
---|
164 | if { [info exists _actors($elem)] } { |
---|
165 | return $_actors($elem) |
---|
166 | } |
---|
167 | return "" |
---|
168 | } |
---|
169 | |
---|
170 | itcl::body Rappture::Drawing3d::components { args } { |
---|
171 | return [array names _actors] |
---|
172 | } |
---|
173 | |
---|
174 | # ---------------------------------------------------------------------- |
---|
175 | # method limits <axis> |
---|
176 | # Returns a list {min max} representing the limits for the |
---|
177 | # specified axis. |
---|
178 | # ---------------------------------------------------------------------- |
---|
179 | itcl::body Rappture::Drawing3d::limits {which} { |
---|
180 | set min "" |
---|
181 | set max "" |
---|
182 | foreach key [array names _actors] { |
---|
183 | set actor $_actors($key) |
---|
184 | foreach key { xMin xMax yMin yMax zMin zMax} value [$actor GetBounds] { |
---|
185 | set _limits($key) $value |
---|
186 | } |
---|
187 | break |
---|
188 | } |
---|
189 | |
---|
190 | foreach key [array names _actors] { |
---|
191 | set actor $_actors($key) |
---|
192 | foreach { xMin xMax yMin yMax zMin zMax} [$actor GetBounds] break |
---|
193 | if { $xMin < $_limits(xMin) } { |
---|
194 | set _limits(xMin) $xMin |
---|
195 | } |
---|
196 | if { $xMax > $_limits(xMax) } { |
---|
197 | set _limits(xMax) $xMax |
---|
198 | } |
---|
199 | if { $yMin < $_limits(yMin) } { |
---|
200 | set _limits(yMin) $yMin |
---|
201 | } |
---|
202 | if { $yMax > $_limits(yMax) } { |
---|
203 | set _limits(yMax) $yMax |
---|
204 | } |
---|
205 | if { $zMin < $_limits(zMin) } { |
---|
206 | set _limits(zMin) $zMin |
---|
207 | } |
---|
208 | if { $zMax > $_limits(zMax) } { |
---|
209 | set _limits(zMax) $zMax |
---|
210 | } |
---|
211 | } |
---|
212 | switch -- $which { |
---|
213 | x { |
---|
214 | set min $_limits(xMin) |
---|
215 | set max $_limits(xMax) |
---|
216 | set axis "xaxis" |
---|
217 | } |
---|
218 | y { |
---|
219 | set min $_limits(yMin) |
---|
220 | set max $_limits(yMax) |
---|
221 | set axis "yaxis" |
---|
222 | } |
---|
223 | v - z { |
---|
224 | set min $_limits(zMin) |
---|
225 | set max $_limits(zMax) |
---|
226 | set axis "zaxis" |
---|
227 | } |
---|
228 | default { |
---|
229 | error "unknown axis description \"$which\"" |
---|
230 | } |
---|
231 | } |
---|
232 | return [list $min $max] |
---|
233 | } |
---|
234 | |
---|
235 | |
---|
236 | # ---------------------------------------------------------------------- |
---|
237 | # USAGE: hints ?<keyword>? |
---|
238 | # |
---|
239 | # Returns a list of key/value pairs for various hints about plotting |
---|
240 | # this curve. If a particular <keyword> is specified, then it returns |
---|
241 | # the hint for that <keyword>, if it exists. |
---|
242 | # ---------------------------------------------------------------------- |
---|
243 | itcl::body Rappture::Drawing3d::hints { {keyword ""} } { |
---|
244 | if {[info exists _hints(xlabel)] && "" != $_hints(xlabel) |
---|
245 | && [info exists _hints(xunits)] && "" != $_hints(xunits)} { |
---|
246 | set _hints(xlabel) "$_hints(xlabel) ($_hints(xunits))" |
---|
247 | } |
---|
248 | if {[info exists _hints(ylabel)] && "" != $_hints(ylabel) |
---|
249 | && [info exists _hints(yunits)] && "" != $_hints(yunits)} { |
---|
250 | set _hints(ylabel) "$_hints(ylabel) ($_hints(yunits))" |
---|
251 | } |
---|
252 | |
---|
253 | if {[info exists _hints(group)] && [info exists _hints(label)]} { |
---|
254 | # pop-up help for each curve |
---|
255 | set _hints(tooltip) $_hints(label) |
---|
256 | } |
---|
257 | if {$keyword != ""} { |
---|
258 | if {[info exists _hints($keyword)]} { |
---|
259 | return $_hints($keyword) |
---|
260 | } |
---|
261 | return "" |
---|
262 | } |
---|
263 | return [array get _hints] |
---|
264 | } |
---|
265 | |
---|