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