source: trunk/gui/scripts/fieldresult.tcl @ 4735

Last change on this file since 4735 was 4344, checked in by ldelgass, 11 years ago

Add VTK surface viewer for viewing colormapped surfaces from any field.

File size: 7.7 KB
Line 
1# -*- mode: tcl; indent-tabs-mode: nil -*-
2# ----------------------------------------------------------------------
3#  COMPONENT: fieldresult - plot a field in a ResultSet
4#
5#  This widget visualizes fields on meshes.
6#  It is normally used in the ResultViewer to show results from the
7#  run of a Rappture tool.  Use the "add" and "delete" methods to
8#  control the dataobjs showing on the plot.
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 Itk
17
18option add *FieldResult.width 4i widgetDefault
19option add *FieldResult.height 4i widgetDefault
20option add *FieldResult.foreground black widgetDefault
21option add *FieldResult.controlBackground gray widgetDefault
22option add *FieldResult.controlDarkBackground #999999 widgetDefault
23option add *FieldResult.plotBackground black widgetDefault
24option add *FieldResult.plotForeground white widgetDefault
25option add *FieldResult.font \
26    -*-helvetica-medium-r-normal-*-12-* widgetDefault
27
28itcl::class Rappture::FieldResult {
29    inherit itk::Widget
30
31    itk_option define -mode mode Mode ""
32
33    constructor {args} { # defined below }
34    destructor { # defined below }
35
36    public method add {dataobj {settings ""}}
37    public method get {}
38    public method delete {args}
39    public method scale {args}
40    public method snap {w h}
41    public method parameters {title args} { # do nothing }
42    public method download {option args}
43}
44
45itk::usual FieldResult {
46    keep -background -foreground -cursor -font
47    keep -plotbackground -plotforeground
48}
49
50# ----------------------------------------------------------------------
51# CONSTRUCTOR
52# ----------------------------------------------------------------------
53itcl::body Rappture::FieldResult::constructor {args} {
54    array set flags {
55        -mode ""
56    }
57    array set flags $args
58    set servers ""
59    switch -- $flags(-mode) {
60        "nanovis" - "flowvis" {
61            set servers [Rappture::VisViewer::GetServerList "nanovis"]
62        }
63        "contour" - "glyphs" - "heightmap" - "isosurface" - "streamlines" - "surface" - "vtkimage" - "vtkviewer" - "vtkvolume" {
64            set servers [Rappture::VisViewer::GetServerList "vtkvis"]
65        }
66        default {
67            puts stderr "unknown render mode \"$flags(-mode)\""
68        }
69    }
70    if {"" != $servers} {
71        switch -- $flags(-mode) {
72            "nanovis" {
73                itk_component add renderer {
74                    Rappture::NanovisViewer $itk_interior.ren $servers
75                }
76            }
77            "flowvis" {
78                itk_component add renderer {
79                    Rappture::FlowvisViewer $itk_interior.ren $servers
80                }
81            }
82            "glyphs" {
83                itk_component add renderer {
84                    Rappture::VtkGlyphViewer $itk_interior.ren $servers
85                }
86            }
87            "contour" - "heightmap" {
88                itk_component add renderer {
89                    Rappture::VtkHeightmapViewer $itk_interior.ren $servers \
90                        -mode $flags(-mode)
91                }
92            }
93            "isosurface" {
94                itk_component add renderer {
95                    Rappture::VtkIsosurfaceViewer $itk_interior.ren $servers
96                }
97            }
98            "streamlines" {
99                itk_component add renderer {
100                    Rappture::VtkStreamlinesViewer $itk_interior.ren $servers
101                }
102            }
103            "surface" {
104                itk_component add renderer {
105                    Rappture::VtkSurfaceViewer $itk_interior.ren $servers
106                }
107            }
108            "vtkimage" {
109                itk_component add renderer {
110                    Rappture::VtkImageViewer $itk_interior.ren $servers
111                }
112            }
113            "vtkviewer" {
114                itk_component add renderer {
115                    Rappture::VtkViewer $itk_interior.ren $servers
116                }
117            }
118            "vtkvolume" {
119                itk_component add renderer {
120                    Rappture::VtkVolumeViewer $itk_interior.ren $servers
121                }
122            }
123            default {
124                puts stderr "unknown render mode \"$flags(-mode)\""
125            }
126        }               
127        pack $itk_component(renderer) -expand yes -fill both
128
129        # can't connect to rendering farm?
130        if {![$itk_component(renderer) isconnected]} {
131            # Should show a message here
132            #destroy $itk_component(renderer)
133        }
134    }
135
136    if {![info exists itk_component(renderer)]} {
137        # No valid renderer (or couldn't connect?)
138        # Should show a message here
139    }
140    eval itk_initialize $args
141    #update
142}
143
144# ----------------------------------------------------------------------
145# DESTRUCTOR
146# ----------------------------------------------------------------------
147itcl::body Rappture::FieldResult::destructor {} {
148}
149
150# ----------------------------------------------------------------------
151# USAGE: add <dataobj> ?<settings>?
152#
153# Clients use this to add a data object to the plot.  The optional
154# <settings> are used to configure the plot.  Allowed settings are
155# -color, -brightness, -width, -linestyle, and -raise.
156# ----------------------------------------------------------------------
157itcl::body Rappture::FieldResult::add {dataobj {settings ""}} {
158    eval $itk_component(renderer) add $dataobj [list $settings]
159}
160
161# ----------------------------------------------------------------------
162# USAGE: get
163#
164# Clients use this to query the list of objects being plotted, in
165# order from bottom to top of this result.
166# ----------------------------------------------------------------------
167itcl::body Rappture::FieldResult::get {} {
168    return [$itk_component(renderer) get]
169}
170
171# ----------------------------------------------------------------------
172# USAGE: delete ?<dataobj1> <dataobj2> ...?
173#
174# Clients use this to delete a dataobj from the plot.  If no dataobjs
175# are specified, then all dataobjs are deleted.
176# ----------------------------------------------------------------------
177itcl::body Rappture::FieldResult::delete {args} {
178    if { [info exists itk_component(renderer)] } {
179        eval $itk_component(renderer) delete $args
180    }
181}
182
183# ----------------------------------------------------------------------
184# USAGE: scale ?<data1> <data2> ...?
185#
186# Sets the default limits for the overall plot according to the
187# limits of the data for all of the given <data> objects.  This
188# accounts for all objects--even those not showing on the screen.
189# Because of this, the limits are appropriate for all objects as
190# the user scans through data in the ResultSet viewer.
191# ----------------------------------------------------------------------
192itcl::body Rappture::FieldResult::scale {args} {
193    eval $itk_component(renderer) scale $args
194}
195
196# ----------------------------------------------------------------------
197# USAGE: download coming
198# USAGE: download controls <downloadCommand>
199# USAGE: download now
200#
201# Clients use this method to create a downloadable representation
202# of the plot.  Returns a list of the form {ext string}, where
203# "ext" is the file extension (indicating the type of data) and
204# "string" is the data itself.
205# ----------------------------------------------------------------------
206itcl::body Rappture::FieldResult::download {option args} {
207    eval $itk_component(renderer) download $option $args
208}
209
210itcl::body Rappture::FieldResult::snap { w h } {
211    return [$itk_component(renderer) snap $w $h]
212}
Note: See TracBrowser for help on using the repository browser.