more fix on Ec/Ev.
[gss-tcad.git] / bin / vtk_plot.tcl
blobadc2ee4f84a6777fd3b7da931131e5a2f9189991
1 package require vtk
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"} {
9 set sep ";"
10 } else {
11 set sep ":"
13 foreach i [split $env(PATH) $sep] {
14 if {$sep == ";"} {
15 set i [join [split $i \\] /]
17 if {[file exists $i/$cmd_name] && ![file isdirectory $i/$cmd_name]} {
18 set cmd_dir $i
19 break;
23 set curdir [pwd]
24 if ![catch {cd $cmd_dir}] {
25 set cmd_dir [pwd]
26 cd $curdir
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} {
39 wm withdraw .
40 tk_dialog .error Error $msg error 0 Exit
41 exit 1
44 if [catch {do_config -win} msg] {error_exit $msg}
46 #----- global variable array --------------------------------------------------
47 array set VTKPlot {
48 vtk_data_file ""
49 scalarname ""
50 view "surface"
51 min 0
52 max 0
53 view3D 0
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
67 vtkActor modelActor
68 vtkActor modelActor3D
69 vtkActor meshActor
70 vtkActor bboxActor
71 vtkCubeAxesActor2D modelAxes
72 vtkAxesActor axes
73 vtkLookupTable lut
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"
84 wm minsize . 640 480
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
93 $m add separator
94 $m add command -label "Quit" -command exit
96 proc save_image_file { } {
97 # Save window to image
98 global renWin
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
106 vtkPNGWriter writer
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]
115 writer Write
116 renderImage Delete
117 writer Delete
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}
124 $m add separator
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 {} {
130 global VTKPlot
131 global ren modelActor
132 set VTKPlot(view) "surface"
133 ren RemoveActor modelActor
134 Plot_Update
137 proc wireframe_view {} {
138 global VTKPlot
139 global ren modelActor
140 set VTKPlot(view) "wireframe"
141 ren RemoveActor modelActor
142 Plot_Update
145 proc points_view {} {
146 global VTKPlot
147 global ren modelActor
148 set VTKPlot(view) "points"
149 ren RemoveActor modelActor
150 Plot_Update
153 proc Plot_Update {} {
154 global VTKPlot
155 global renWin
156 if {$VTKPlot(view3D)} {
157 wrap_z
158 } else {
159 plan_z
161 model_obj
162 draw_window
163 renWin Render
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
173 proc do_about {} {
174 global ProgData
175 dialog .about -1 -1 "About GSS VTK Plot Window" \
176 { GSS VTK Window 0.1
177 A GUI for post-process.
178 Date : 11/10/2006
179 Author : Gong Ding
180 Email : gdiso@ustc.edu} \
181 img_about 0 Close
184 #----- create VTK display window------------------------------------------------
185 vtkRenderer ren
186 vtkRenderWindow renWin
187 renWin AddRenderer ren
189 frame .f1
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
196 # iren Initialize
197 # iren AddObserver UserEvent {wm deiconify .vtkInteract}
198 # iren SetInteractorStyle style1
202 proc read_data {} {
203 global VTKPlot reader
204 reader SetFileName $VTKPlot(vtk_data_file)
205 reader SetScalarsName $VTKPlot(scalarname)
206 reader Update
207 set range [[reader GetOutput] GetScalarRange]
208 set VTKPlot(min) [lindex $range 0]
209 set VTKPlot(max) [lindex $range 1]
212 proc wrap_z {} {
213 # set the scale value to z.
214 global VTKPlot
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
225 proc plan_z {} {
226 global VTKPlot
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
237 proc build_lut {} {
238 global VTKPlot lut
239 lut SetHueRange 0.6667 0.0
240 lut Build
244 proc model_obj {} {
245 global VTKPlot
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
264 proc axes_obj {} {
265 global VTKPlot
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
273 tprop1 ItalicOn
274 tprop1 ShadowOn
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]
286 marker1 SetEnabled 1
287 marker1 InteractiveOff
292 proc scalar_bar_obj {} {
293 global VTKPlot
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 {} {
307 global VTKPlot
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 {} {
323 global VTKPlot
324 global ren renWin
325 ren ResetCamera
326 #adjust angle of z and xy-plane
327 [ren GetActiveCamera] Azimuth 0
328 #adjust angle roll from x
329 [ren GetActiveCamera] Roll 10
330 #resize rate
331 [ren GetActiveCamera] Dolly 1
332 #adjust Camera
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
338 renWin Render
341 #---------- produce cmd line arg ----------------------------------------------
342 if {$argc} {
343 global VTKPlot
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)]
348 read_data
349 plan_z
350 build_lut
351 model_obj
352 model_axes_obj
353 axes_obj
354 scalar_bar_obj
355 draw_window
359 tkwait window .