source: trunk/gui/scripts/drawing3d.tcl @ 2271

Last change on this file since 2271 was 2259, checked in by gah, 13 years ago

temporary: don't use

File size: 8.4 KB
Line 
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# ======================================================================
15package require Itcl
16package require BLT
17package require vtk
18
19namespace eval Rappture {
20    # forward declaration
21}
22
23itcl::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# ----------------------------------------------------------------------
50itcl::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        camera  about.camera
96        type    about.type
97        xlabel  xaxis.label
98        xdesc   xaxis.description
99        xunits  xaxis.units
100        xscale  xaxis.scale
101        xmin    xaxis.min
102        xmax    xaxis.max
103        ylabel  yaxis.label
104        ydesc   yaxis.description
105        yunits  yaxis.units
106        yscale  yaxis.scale
107        ymin    yaxis.min
108        ymax    yaxis.max
109        zlabel  zaxis.label
110        zdesc   zaxis.description
111        zunits  zaxis.units
112        zscale  zaxis.scale
113        zmin    zaxis.min
114        zmax    zaxis.max
115    } {
116        set str [$_drawing3d get $path]
117        if {"" != $str} {
118            set _hints($key) $str
119        }
120    }
121    foreach {key} { axisorder } {
122        set str [$_drawing3d get $key]
123        if {"" != $str} {
124            set _hints($key) $str
125        }
126    }
127}
128
129# ----------------------------------------------------------------------
130# Destructor
131# ----------------------------------------------------------------------
132itcl::body Rappture::Drawing3d::destructor {} {
133    foreach key [array names _actors] {
134        set actor _actors($key)
135    }
136}
137
138# ----------------------------------------------------------------------
139# method style
140#       Returns a base64 encoded, gzipped Tcl list that represents the
141#       Tcl command and data to recreate the uniform rectangular grid
142#       on the nanovis server.
143# ----------------------------------------------------------------------
144itcl::body Rappture::Drawing3d::style { elem } {
145    if { [info exists _styles($elem)] } {
146        return $_styles($elem)
147    }
148    return ""
149}
150
151# ----------------------------------------------------------------------
152# method data
153#       Returns a base64 encoded, gzipped Tcl list that represents the
154#       Tcl command and data to recreate the uniform rectangular grid
155#       on the nanovis server.
156# ----------------------------------------------------------------------
157itcl::body Rappture::Drawing3d::data { elem } {
158    if { [info exists _data($elem)] } {
159        return $_data($elem)
160    }
161    return ""
162}
163
164# ----------------------------------------------------------------------
165# method values
166#       Returns a base64 encoded, gzipped Tcl list that represents the
167#       Tcl command and data to recreate the uniform rectangular grid
168#       on the nanovis server.
169# ----------------------------------------------------------------------
170itcl::body Rappture::Drawing3d::values { elem } {
171    if { [info exists _actors($elem)] } {
172        return $_actors($elem)
173    }
174    return ""
175}
176
177itcl::body Rappture::Drawing3d::components { args } {
178    return [array names _actors]
179}
180
181# ----------------------------------------------------------------------
182# method limits <axis>
183#       Returns a list {min max} representing the limits for the
184#       specified axis.
185# ----------------------------------------------------------------------
186itcl::body Rappture::Drawing3d::limits {which} {
187    set min ""
188    set max ""
189    foreach key [array names _actors] {
190        set actor $_actors($key)
191        foreach key { xMin xMax yMin yMax zMin zMax} value [$actor GetBounds] {
192            set _limits($key) $value
193        }
194        break
195    }   
196   
197    foreach key [array names _actors] {
198        set actor $_actors($key)
199        foreach { xMin xMax yMin yMax zMin zMax} [$actor GetBounds] break
200        if { $xMin < $_limits(xMin) } {
201            set _limits(xMin) $xMin
202        }
203        if { $xMax > $_limits(xMax) } {
204            set _limits(xMax) $xMax
205        }
206        if { $yMin < $_limits(yMin) } {
207            set _limits(yMin) $yMin
208        }
209        if { $yMax > $_limits(yMax) } {
210            set _limits(yMax) $yMax
211        }
212        if { $zMin < $_limits(zMin) } {
213            set _limits(zMin) $zMin
214        }
215        if { $zMax > $_limits(zMax) } {
216            set _limits(zMax) $zMax
217        }
218    }
219    switch -- $which {
220        x {
221            set min $_limits(xMin)
222            set max $_limits(xMax)
223            set axis "xaxis"
224        }
225        y {
226            set min $_limits(yMin)
227            set max $_limits(yMax)
228            set axis "yaxis"
229        }
230        v - z {
231            set min $_limits(zMin)
232            set max $_limits(zMax)
233            set axis "zaxis"
234        }
235        default {
236            error "unknown axis description \"$which\""
237        }
238    }
239    return [list $min $max]
240}
241
242
243# ----------------------------------------------------------------------
244# USAGE: hints ?<keyword>?
245#
246# Returns a list of key/value pairs for various hints about plotting
247# this curve.  If a particular <keyword> is specified, then it returns
248# the hint for that <keyword>, if it exists.
249# ----------------------------------------------------------------------
250itcl::body Rappture::Drawing3d::hints { {keyword ""} } {
251    if 0 {
252    if {[info exists _hints(xlabel)] && "" != $_hints(xlabel)
253        && [info exists _hints(xunits)] && "" != $_hints(xunits)} {
254        set _hints(xlabel) "$_hints(xlabel) ($_hints(xunits))"
255    }
256    if {[info exists _hints(ylabel)] && "" != $_hints(ylabel)
257        && [info exists _hints(yunits)] && "" != $_hints(yunits)} {
258        set _hints(ylabel) "$_hints(ylabel) ($_hints(yunits))"
259    }
260    }
261    if {[info exists _hints(group)] && [info exists _hints(label)]} {
262        # pop-up help for each curve
263        set _hints(tooltip) $_hints(label)
264    }
265    if {$keyword != ""} {
266        if {[info exists _hints($keyword)]} {
267            return $_hints($keyword)
268        }
269        return ""
270    }
271    return [array get _hints]
272}
273
Note: See TracBrowser for help on using the repository browser.