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

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

Use vtk image viewer instead of contour viewer for dicom

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