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

Last change on this file since 839 was 839, checked in by gah, 17 years ago

changes for surface plots

File size: 5.1 KB
RevLine 
[839]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    lappend data "zvalues" [$_zv range 0 end]
80    return [Rappture::encoding::encode -as zb64 $data]
81}
82
83# ----------------------------------------------------------------------
84# method mesh
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# ----------------------------------------------------------------------
89itcl::body Rappture::UniRect2d::mesh {} {
90    set dx [expr {($_xmax - $_xmin) / double($_xnum)}]
91    set dy [expr {($_ymax - $_ymin) / double($_ynum)}]
92    for { set i 0 } { $i < $_xnum } { incr i } {
93        set x [expr {$_xmin + (double($i) * $dx)}]
94        for { set j 0 } { $j < $_ynum } { incr j } {
95            set y [expr {$_ymin + (double($i) * $dy)}]
96            lappend data $x $y
97        }
98    }
99    return $data
100}
101
102# ----------------------------------------------------------------------
103# method values
104#       Returns a base64 encoded, gzipped Tcl list that represents the
105#       Tcl command and data to recreate the uniform rectangular grid
106#       on the nanovis server.
107# ----------------------------------------------------------------------
108itcl::body Rappture::UniRect2d::values {} {
109    return [$_zv range 0 end]
110}
111
112# ----------------------------------------------------------------------
113# method limits <axis>
114#       Returns a list {min max} representing the limits for the
115#       specified axis.
116# ----------------------------------------------------------------------
117itcl::body Rappture::UniRect2d::limits {which} {
118    set min ""
119    set max ""
120
121    switch -- $which {
122        x - xlin - xlog {
123            set min $_xmin
124            set max $_xmax
125            set axis "xaxis"
126        }
127        y - ylin - ylog {
128            set min $_ymin
129            set max $_ymax
130            set axis "yaxis"
131        }
132        v - xlin - vlog - z - zlin - zlog {
133            set min [blt::vector expr min($_zv)]
134            set max [blt::vector expr max($_zv)]
135            set axis "zaxis"
136        }
137    }
138#     set val [$_field get $axis.min]
139#     if {"" != $val && "" != $min} {
140#         if {$val > $min} {
141#             # tool specified this min -- don't go any lower
142#             set min $val
143#         }
144#     }
145#     set val [$_field get $axis.max]
146#     if {"" != $val && "" != $max} {
147#         if {$val < $max} {
148#             # tool specified this max -- don't go any higher
149#             set max $val
150#         }
151#     }
152
153    return [list $min $max]
154}
155
Note: See TracBrowser for help on using the repository browser.