source: trunk/gui/scripts/unirect2d.tcl @ 856

Last change on this file since 856 was 856, checked in by gah, 16 years ago

fix histogram download

File size: 5.2 KB
Line 
1# ----------------------------------------------------------------------
2#  COMPONENT: unirect2d - represents a uniform rectangular 2-D mesh.
3#
4#  This object represents one field in an XML description of a device.
5#  It simplifies the process of extracting data vectors that represent
6#  the field.
7# ======================================================================
8#  AUTHOR:  Michael McLennan, Purdue University
9#  Copyright (c) 2004-2005  Purdue Research Foundation
10#
11#  See the file "license.terms" for information on usage and
12#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13# ======================================================================
14package require Itcl
15package require BLT
16
17namespace eval Rappture { # forward declaration }
18
19itcl::class Rappture::UniRect2d {
20    constructor {xmlobj field cname} { # defined below }
21    destructor { # defined below }
22
23    public method limits {axis}
24    public method blob {}
25    public method mesh {}
26    public method values {}
27
28    private variable _xmax 0
29    private variable _xmin 0
30    private variable _xnum 0
31    private variable _ymax 0
32    private variable _ymin 0
33    private variable _ynum 0
34    private variable _zv "";            # BLT vector containing the z-values
35}
36
37# ----------------------------------------------------------------------
38# Constructor
39# ----------------------------------------------------------------------
40itcl::body Rappture::UniRect2d::constructor {xmlobj field cname} {
41    if {![Rappture::library isvalid $xmlobj]} {
42        error "bad value \"$xmlobj\": should be Rappture::library"
43    }
44    set path [$field get $cname.mesh]
45
46    set mobj [$xmlobj element -as object $path]
47    set _xmin [$mobj get "xaxis.min"]
48    set _xmax [$mobj get "xaxis.max"]
49    set _xnum [$mobj get "xaxis.numpoints"]
50    set _ymin [$mobj get "yaxis.min"]
51    set _ymax [$mobj get "yaxis.max"]
52    set _ynum [$mobj get "yaxis.numpoints"]
53    itcl::delete object $mobj
54
55    set _zv [blt::vector create #auto]
56    $_zv set [$field get "$cname.values"]
57}
58
59# ----------------------------------------------------------------------
60# Destructor
61# ----------------------------------------------------------------------
62itcl::body Rappture::UniRect2d::destructor {} {
63    if { $_zv != "" } {
64        blt::vector destroy $_zv
65    }
66}
67
68# ----------------------------------------------------------------------
69# method blob
70#       Returns a base64 encoded, gzipped Tcl list that represents the
71#       Tcl command and data to recreate the uniform rectangular grid
72#       on the nanovis server.
73# ----------------------------------------------------------------------
74itcl::body Rappture::UniRect2d::blob {} {
75    set data "unirect2d"
76    lappend data "xmin" $_xmin "xmax" $_xmax "xnum" $_xnum
77    lappend data "ymin" $_ymin "ymax" $_ymax "ynum" $_ynum
78    lappend data "xmin" $_xmin "ymin" $_ymin "xmax" $_xmax "ymax" $_ymax
79    if { [$_zv length] > 0 } {
80        lappend data "zvalues" [$_zv range 0 end]
81    }
82    return [Rappture::encoding::encode -as zb64 $data]
83}
84
85# ----------------------------------------------------------------------
86# method mesh
87#       Returns a base64 encoded, gzipped Tcl list that represents the
88#       Tcl command and data to recreate the uniform rectangular grid
89#       on the nanovis server.
90# ----------------------------------------------------------------------
91itcl::body Rappture::UniRect2d::mesh {} {
92    set dx [expr {($_xmax - $_xmin) / double($_xnum)}]
93    set dy [expr {($_ymax - $_ymin) / double($_ynum)}]
94    for { set i 0 } { $i < $_xnum } { incr i } {
95        set x [expr {$_xmin + (double($i) * $dx)}]
96        for { set j 0 } { $j < $_ynum } { incr j } {
97            set y [expr {$_ymin + (double($i) * $dy)}]
98            lappend data $x $y
99        }
100    }
101    return $data
102}
103
104# ----------------------------------------------------------------------
105# method values
106#       Returns a base64 encoded, gzipped Tcl list that represents the
107#       Tcl command and data to recreate the uniform rectangular grid
108#       on the nanovis server.
109# ----------------------------------------------------------------------
110itcl::body Rappture::UniRect2d::values {} {
111    if { [$_zv length] > 0 } {
112        return [$_zv range 0 end]
113    }
114    return ""
115}
116
117# ----------------------------------------------------------------------
118# method limits <axis>
119#       Returns a list {min max} representing the limits for the
120#       specified axis.
121# ----------------------------------------------------------------------
122itcl::body Rappture::UniRect2d::limits {which} {
123    set min ""
124    set max ""
125
126    switch -- $which {
127        x - xlin - xlog {
128            set min $_xmin
129            set max $_xmax
130            set axis "xaxis"
131        }
132        y - ylin - ylog {
133            set min $_ymin
134            set max $_ymax
135            set axis "yaxis"
136        }
137        v - xlin - vlog - z - zlin - zlog {
138            set min [blt::vector expr min($_zv)]
139            set max [blt::vector expr max($_zv)]
140            set axis "zaxis"
141        }
142    }
143#     set val [$_field get $axis.min]
144#     if {"" != $val && "" != $min} {
145#         if {$val > $min} {
146#             # tool specified this min -- don't go any lower
147#             set min $val
148#         }
149#     }
150#     set val [$_field get $axis.max]
151#     if {"" != $val && "" != $max} {
152#         if {$val < $max} {
153#             # tool specified this max -- don't go any higher
154#             set max $val
155#         }
156#     }
157
158    return [list $min $max]
159}
160
Note: See TracBrowser for help on using the repository browser.