source: trunk/gui/scripts/unirect3d.tcl @ 4045

Last change on this file since 4045 was 4030, checked in by ldelgass, 11 years ago

Better fix for z axis limits issue addressed in r3996 and r4021 : return [0,0]
z limits from unirect2d, always treat z as mesh dimension, don't alias to value
limits.

File size: 10.3 KB
Line 
1# -*- mode: tcl; indent-tabs-mode: nil -*-
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
11#  Copyright (c) 2004-2012  HUBzero Foundation, LLC
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# ======================================================================
16package require Itcl
17package require BLT
18
19namespace eval Rappture { # forward declaration }
20
21itcl::class Rappture::Unirect3d {
22    constructor {xmlobj field cname {extents 1}} { # defined below }
23    destructor { # defined below }
24
25    public method limits {axis}
26    public method blob {}
27    public method mesh {}
28    public method values {}
29    public method valuesObj {}
30    public method units { axis }
31    public method label { axis }
32    public method hints {{keyword ""}}
33    public method order {} {
34        return _axisOrder;
35    }
36    private method GetString { obj path varName }
37    private method GetValue { obj path varName }
38    private method GetSize { obj path varName }
39
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
52    private variable _hints
53}
54
55# ----------------------------------------------------------------------
56# Constructor
57# ----------------------------------------------------------------------
58itcl::body Rappture::Unirect3d::constructor {xmlobj field cname {extents 1}} {
59    if {![Rappture::library isvalid $xmlobj]} {
60        error "bad value \"$xmlobj\": should be Rappture::library"
61    }
62    set path [$field get $cname.mesh]
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
73    set _compNum $extents
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    }
105    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    }
113}
114
115# ----------------------------------------------------------------------
116# Destructor
117# ----------------------------------------------------------------------
118itcl::body Rappture::Unirect3d::destructor {} {
119    if { $_values != "" } {
120        blt::vector destroy $_values
121    }
122}
123
124# ----------------------------------------------------------------------
125# method blob
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.
129# ----------------------------------------------------------------------
130itcl::body Rappture::Unirect3d::blob {} {
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
136    if { [$_values length] > 0 } {
137        lappend data "values" [$_values range 0 end]
138    }
139    return $data
140}
141
142# ----------------------------------------------------------------------
143# method mesh
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.
147# ----------------------------------------------------------------------
148itcl::body Rappture::Unirect3d::mesh {} {
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 } {
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        }
162    }
163    return $data
164}
165
166# ----------------------------------------------------------------------
167# method values
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.
171# ----------------------------------------------------------------------
172itcl::body Rappture::Unirect3d::values {} {
173    if { [$_values length] > 0 } {
174        return [$_values range 0 end]
175    }
176    return ""
177}
178
179# ----------------------------------------------------------------------
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# ----------------------------------------------------------------------
185itcl::body Rappture::Unirect3d::valuesObj {} {
186    return $_values
187}
188
189# ----------------------------------------------------------------------
190# method limits <axis>
191#       Returns a list {min max} representing the limits for the
192#       specified axis.
193# ----------------------------------------------------------------------
194itcl::body Rappture::Unirect3d::limits {which} {
195    set min ""
196    set max ""
197
198    switch -- $which {
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        }
223    }
224    return [list $min $max]
225}
226
227#
228# units --
229#
230#       Returns the units of the given axis.
231#
232itcl::body Rappture::Unirect3d::units { axis } {
233    if { [info exists _hints({$axis}units)] } {
234        return $_hints(${axis}units)
235    }
236    return ""
237}
238
239#
240# label --
241#
242#       Returns the label of the given axis.
243#
244itcl::body Rappture::Unirect3d::label { axis } {
245    if { [info exists _hints({$axis}label)] } {
246        return $_hints(${axis}label)
247    }
248    return ""
249}
250
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# ----------------------------------------------------------------------
258itcl::body Rappture::Unirect3d::hints {{keyword ""}} {
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    }
271
272    if {[info exists _hints(group)] && [info exists _hints(label)]} {
273        # pop-up help for each curve
274        set _hints(tooltip) $_hints(label)
275    }
276    if {$keyword != ""} {
277        if {[info exists _hints($keyword)]} {
278            return $_hints($keyword)
279        }
280        return ""
281    }
282    return [array get _hints]
283}
284
285itcl::body Rappture::Unirect3d::GetSize { obj path varName } {
286    set string [$obj get $path]
287    if { [scan $string "%d" value] != 1 || $value < 0 } {
288        puts stderr "can't get size \"$string\" of \"$path\""
289        return
290    }
291    upvar $varName size
292    set size $value
293}
294
295itcl::body Rappture::Unirect3d::GetValue { obj path varName } {
296    set string [$obj get $path]
297    if { [scan $string "%g" value] != 1 } {
298        puts stderr "can't get value \"$string\" of \"$path\""
299        return
300    }
301    upvar $varName number
302    set number $value
303}
304
305itcl::body Rappture::Unirect3d::GetString { obj path varName } {
306    set string [$obj get $path]
307    if { $string == "" } {
308        puts stderr "can't get string \"$string\" of \"$path\""
309        return
310    }
311    upvar $varName str
312    set str $string
313}
Note: See TracBrowser for help on using the repository browser.