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