2 package require vtkinteraction
4 #----- get startup directory and name -----------------------------------------
5 set cmd_name
[file tail
$argv0]
6 set cmd_dir
[file dirname
$argv0]
7 if {![file exists
$argv0] ||
[file isdirectory
$argv0]} {
8 if {$tcl_platform(platform
) == "windows"} {
13 foreach i
[split $env(PATH
) $sep] {
15 set i
[join [split $i \\] /]
17 if {[file exists
$i/$cmd_name] && ![file isdirectory
$i/$cmd_name]} {
24 if ![catch {cd $cmd_dir}] {
28 if {$tcl_platform(platform
) == "windows"} {
29 set cmd_dir
[file attributes
$cmd_dir -shortname]
33 #----- set path to tcl scripts ------------------------------------------------
34 if {[info exists env
(GSS_DIR
)]} {
35 set auto_path
"$env(GSS_DIR)/lib/gui_script $cmd_dir $cmd_dir/../lib/gui_script . $auto_path"
38 proc error_exit
{msg
} {
40 tk_dialog .
error Error
$msg error 0 Exit
44 if [catch {do_config
-win} msg
] {error_exit
$msg}
46 #----- global variable array --------------------------------------------------
57 vtkInteractorStyleTrackballCamera style1
58 vtkUnstructuredGridReader reader
59 vtkWarpScalar rubberPlane
60 vtkConnectivityFilter connect
61 vtkGeometryFilter parison
62 vtkOutlineCornerFilter bbox
63 vtkPolyDataNormals normals
64 vtkPolyDataMapper parisonMapper
65 vtkDataSetMapper moldMapper
71 vtkCubeAxesActor2D modelAxes
74 vtkOrientationMarkerWidget marker1
75 vtkTextProperty tprop1
76 vtkTextProperty tprop2
77 vtkTextProperty tprop3
78 vtkTextProperty tprop4
79 vtkScalarBarActor scalarBar
81 #----- create main window -----------------------------------------------------
83 wm title .
"GSS 3D plot Window"
85 wm protocol . WM_DELETE_WINDOW
exit
87 #----- create menu -------------------------------------------------------------
88 menubar_create
{File Display Option Help
}
90 #----- file menu ---------------------------------------------------------------
91 set m
[menubar_get File
]
92 $m add command
-label "Save Screen..." -command save_image_file
94 $m add command
-label "Quit" -command exit
96 proc save_image_file
{ } {
97 # Save window to image
99 set file_name
[FileSave
"Save Image File" "" .
\
100 {{{jpeg Files
} {.png
}} {{All Files
} {*}}} png
]
101 if {$file_name == ""} return
103 vtkWindowToImageFilter renderImage
104 renderImage SetInput renWin
108 #vtkJPEGWriter writer
109 #vtkMetaImageWriter writer
110 #vtkPostScriptWriter writer
111 #writer ProgressiveOn
112 #writer SetQuality 100
113 writer SetFileName
$file_name
114 writer SetInput
[renderImage GetOutput
]
120 #----- Option menu ---------------------------------------------------------------
121 set m
[menubar_get Display
]
122 $m add
checkbutton -label "3D View" -variable VTKPlot
(view3D
) \
123 -onvalue 1 -offvalue 0 -command {Plot_Update
}
125 $m add command
-label "Surface" -command surface_view
126 $m add command
-label "Wire frame" -command wireframe_view
127 $m add command
-label "Points" -command points_view
129 proc surface_view
{} {
131 global ren modelActor
132 set VTKPlot
(view
) "surface"
133 ren RemoveActor modelActor
137 proc wireframe_view
{} {
139 global ren modelActor
140 set VTKPlot
(view
) "wireframe"
141 ren RemoveActor modelActor
145 proc points_view
{} {
147 global ren modelActor
148 set VTKPlot
(view
) "points"
149 ren RemoveActor modelActor
153 proc Plot_Update
{} {
156 if {$VTKPlot(view3D
)} {
166 #---------- images ------------------------------------------------------------
167 image create
photo img_about
-file $env(GSS_DIR
)/lib
/gss.logos.gif
169 #----- help menu --------------------------------------------------------------
170 set m
[menubar_get Help
]
171 $m add command
-label "About..." -underline 0 -command do_about
175 dialog .about
-1 -1 "About GSS VTK Plot Window" \
177 A GUI
for post-process.
180 Email
: gdiso
@ustc.edu
} \
184 #----- create VTK display window------------------------------------------------
186 vtkRenderWindow renWin
187 renWin AddRenderer ren
190 pack .f1
-fill both
-expand 1
191 set vtkw
[vtkTkRenderWidget .f1.r1
-width 640 -height 480 -rw renWin
]
192 pack $vtkw -side left
-padx 3 -pady 3 -fill both
-expand 1
193 ::vtk::bind_tk_render_widget $vtkw
194 #vtkRenderWindowInteractor iren
195 # iren SetRenderWindow renWin
197 # iren AddObserver UserEvent {wm deiconify .vtkInteract}
198 # iren SetInteractorStyle style1
203 global VTKPlot reader
204 reader SetFileName
$VTKPlot(vtk_data_file
)
205 reader SetScalarsName
$VTKPlot(scalarname
)
207 set range
[[reader GetOutput
] GetScalarRange
]
208 set VTKPlot
(min
) [lindex $range 0]
209 set VTKPlot
(max
) [lindex $range 1]
213 # set the scale value to z.
215 global reader rubberPlane connect parison normals
216 rubberPlane SetInput
[reader GetOutput
]
217 rubberPlane SetScaleFactor
[expr 2.0/($VTKPlot(max
)-$VTKPlot(min
))]
218 # The threshold filter has been used to extract the parison.
219 connect SetInputConnection
[rubberPlane GetOutputPort
]
220 parison SetInputConnection
[connect GetOutputPort
]
221 normals SetInputConnection
[parison GetOutputPort
]
222 normals SetFeatureAngle
0
227 global reader rubberPlane connect parison normals
228 rubberPlane SetInput
[reader GetOutput
]
229 rubberPlane SetScaleFactor
0.00
230 # The threshold filter has been used to extract the parison.
231 connect SetInputConnection
[rubberPlane GetOutputPort
]
232 parison SetInputConnection
[connect GetOutputPort
]
233 normals SetInputConnection
[parison GetOutputPort
]
234 normals SetFeatureAngle
0
239 lut SetHueRange
0.6667 0.0
246 global parisonMapper normals lut modelActor ren
247 parisonMapper SetInputConnection
[normals GetOutputPort
]
248 parisonMapper SetLookupTable lut
249 parisonMapper SetScalarRange
$VTKPlot(min
) $VTKPlot(max
)
250 modelActor SetMapper parisonMapper
251 if {$VTKPlot(view
)=="surface"} {
252 [modelActor GetProperty
] SetRepresentationToSurface
254 if {$VTKPlot(view
)=="wireframe"} {
255 [modelActor GetProperty
] SetRepresentationToWireframe
257 if {$VTKPlot(view
)=="points"} {
258 [modelActor GetProperty
] SetRepresentationToPoints
260 ren AddActor modelActor
266 global axes tprop1 tprop2 tprop3 marker1
267 axes SetShaftTypeToCylinder
268 axes SetXAxisLabelText
"x"
269 axes SetYAxisLabelText
"y"
270 axes SetZAxisLabelText
"z"
271 axes SetTotalLength
1.5 1.5 1.5
275 tprop1 SetFontFamilyToTimes
276 [ axes GetXAxisCaptionActor2D
] SetCaptionTextProperty tprop1
277 tprop2 ShallowCopy tprop1
278 [ axes GetYAxisCaptionActor2D
] SetCaptionTextProperty tprop2
279 tprop3 ShallowCopy tprop1
280 [ axes GetZAxisCaptionActor2D
] SetCaptionTextProperty tprop3
282 marker1 SetOutlineColor
0.93 0.57 0.13
283 marker1 SetOrientationMarker axes
284 marker1 SetViewport
0.0 0.0 0.2 0.3
285 marker1 SetInteractor
[renWin GetInteractor
]
287 marker1 InteractiveOff
292 proc scalar_bar_obj
{} {
294 global scalarBar parisonMapper ren
295 scalarBar SetLookupTable
[parisonMapper GetLookupTable
]
296 scalarBar SetTitle
$VTKPlot(scalarname
)
297 [scalarBar GetPositionCoordinate
] SetCoordinateSystemToNormalizedViewport
298 [scalarBar GetPositionCoordinate
] SetValue
0.86 0.1
299 scalarBar SetOrientationToVertical
300 scalarBar SetWidth
0.12
301 scalarBar SetHeight
0.9
302 scalarBar SetLabelFormat
"%-#6.3e"
303 ren AddActor2D scalarBar
306 proc model_axes_obj
{} {
308 global modelAxes rubberPlane ren tprop1
309 modelAxes SetInput
[rubberPlane GetOutput
]
310 modelAxes SetCamera
[ren GetActiveCamera
]
311 modelAxes SetScaling
1
312 modelAxes SetZLabel
"scaled value"
313 modelAxes SetLabelFormat
"%6.4g"
314 modelAxes SetFlyModeToOuterEdges
315 modelAxes SetFontFactor
0.8
316 modelAxes SetAxisTitleTextProperty tprop1
317 modelAxes SetAxisLabelTextProperty tprop1
319 ren AddViewProp modelAxes
322 proc draw_window
{} {
326 #adjust angle of z and xy-plane
327 [ren GetActiveCamera
] Azimuth
0
328 #adjust angle roll from x
329 [ren GetActiveCamera
] Roll
10
331 [ren GetActiveCamera
] Dolly
1
333 [ren GetActiveCamera
] ComputeViewPlaneNormal
334 [ren GetActiveCamera
] SetViewUp
1 1 1
335 [ren GetActiveCamera
] OrthogonalizeViewUp
336 ren ResetCameraClippingRange
337 ren SetBackground
0.33 0.35 0.43
341 #---------- produce cmd line arg ----------------------------------------------
344 set VTKPlot
(vtk_data_file
) [lindex $argv [expr $argc - 2]]
345 set VTKPlot
(scalarname
) [lindex $argv [expr $argc - 1]]
346 if {[string index
$VTKPlot(vtk_data_file
) 0] != "-" && [file exists
$VTKPlot(vtk_data_file
)]} {
347 cd [file dirname
$VTKPlot(vtk_data_file
)]