$Application ExitOnReturnOn
if {[info exists argc]} { 
    set argcm1 [expr $argc - 1]
    for {set i 0} {$i < $argcm1} {incr i} {
        if {[lindex $argv $i] == "-D" && $i < $argcm1} {
		set DataDir [lindex $argv [expr $i + 1]]
        }
    }
} 


set pv(vtkTemp1) [$Application GetMainWindow]
set pv(vtkTemp44) [$pv(vtkTemp1) GetMainView]
$pv(vtkTemp44) SetBackgroundColor 0 0 0
set pv(vtkTemp90) [$pv(vtkTemp1) GetPVSource GlyphSources Arrow0]
set pv(vtkTemp94) [$pv(vtkTemp1) GetPVSource GlyphSources Cone0]
set pv(vtkTemp98) [$pv(vtkTemp1) GetPVSource GlyphSources Sphere0]
$pv(vtkTemp1) Open "$DataDir/Data/vox8_bin.vtk"
set pv(vtkTemp101) [$pv(vtkTemp1) GetCurrentPVSource]

set pv(vtkTemp129) [$pv(vtkTemp1) CreatePVSource Threshold]
set pv(vtkTemp137) [$pv(vtkTemp129) GetPVWidget {FieldMenu}]
$pv(vtkTemp137) SetValue 2
set pv(vtkTemp135) [$pv(vtkTemp129) GetPVWidget {Input}]
$pv(vtkTemp135) SetCurrentValue $pv(vtkTemp101)
set pv(vtkTemp141) [$pv(vtkTemp129) GetPVWidget {MinMax}]
$pv(vtkTemp141) SetMaxValue 0.41
$pv(vtkTemp141) SetMinValue 0.14
set pv(vtkTemp146) [$pv(vtkTemp129) GetPVWidget {AllScalars}]
$pv(vtkTemp146) SetState 0
$pv(vtkTemp129) AcceptCallback

set pv(vtkTemp304) [$pv(vtkTemp1) CreatePVSource DataSetTriangleFilter]
$pv(vtkTemp304) AcceptCallback
[$pv(vtkTemp304) GetPVOutput] DrawSurface
set pv(vtkTemp321) [$pv(vtkTemp304) GetPVOutput]
$pv(vtkTemp321) SetVisibility 0
set pv(vtkTemp158) [$pv(vtkTemp1) CreatePVSource DataSetSurfaceFilter]
set pv(vtkTemp164) [$pv(vtkTemp158) GetPVWidget {Input}]
$pv(vtkTemp164) SetCurrentValue $pv(vtkTemp129)
$pv(vtkTemp158) AcceptCallback
$pv(vtkTemp158) SetVisibility 0

# Retrace
update
$Application StopRecordingScript
[ $Application GetMainWindow ] DeleteAllSources
# Source the trace to regenerate the sources.
if {[catch {set channel [open test.tmp w]}] == 0 } {
   close $channel
   file delete -force test.tmp
   source "[$Application GetTraceFileName]"
}

# Fix the size of the image.
set RenWin1 [[[$Application GetMainWindow] GetMainView] GetRenderWindow]
$RenWin1 SetSize 300 300
$RenWin1 Render
update

for {set i  1} {$i < [expr $argc - 1]} {incr i} {
    if {[lindex $argv $i] == "-C"} {
	source [lindex $argv [expr $i + 1]]
	$Application SetExitStatus [CompareImage [[$Application GetMainWindow] GetMainView]]
    }
}
   
$Application Exit
