$Application ExitOnReturnOn

set pv(vtkTemp1) [$Application GetMainWindow]
set pv(vtkTemp43) [$pv(vtkTemp1) GetMainView]

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]]
        }
        if {[lindex $argv $i] == "-UC" && $i < $argcm1} {
            set rmui [$pv(vtkTemp43) GetRenderModuleUI]
            catch {$rmui SetCompositeThreshold 0}
        }
    }
} 


$pv(vtkTemp43) SetBackgroundColor 0 0 0

set pv(vtkTemp603) [$pv(vtkTemp1) InitializeReadCustom "ImageReader" "$DataDir/Data/headsq/quarter.1"]
$pv(vtkTemp1) ReadFileInformation $pv(vtkTemp603) "$DataDir/Data/headsq/quarter.1"
$pv(vtkTemp1) FinalizeRead $pv(vtkTemp603) "$DataDir/Data/headsq/quarter.1"
set pv(vtkTemp646) [$pv(vtkTemp603) GetPVWidget {Filename}]
$pv(vtkTemp646) SetValue "$DataDir/Data/headsq/quarter"
set pv(vtkTemp609) [$pv(vtkTemp603) GetPVWidget {FilePattern}]
$pv(vtkTemp609) SetValue {%s.%d}
set pv(vtkTemp617) [$pv(vtkTemp603) GetPVWidget {DataByteOrder}]
$pv(vtkTemp617) SetCurrentValue {1}
set pv(vtkTemp621) [$pv(vtkTemp603) GetPVWidget {Dimensionality}]
$pv(vtkTemp621) SetCurrentValue {2}
set pv(vtkTemp634) [$pv(vtkTemp603) GetPVWidget {Extent}]
$pv(vtkTemp634) SetValue 0 63 0 63 1 64
$pv(vtkTemp603) AcceptCallback

set pv(vtkTemp187) [$pv(vtkTemp1) CreatePVSource Contour]
set pv(vtkTemp198) [$pv(vtkTemp187) GetPVWidget {Contour Values}]
$pv(vtkTemp198) RemoveAllValues
$pv(vtkTemp198) AddValue 600.000000
set pv(vtkTemp204) [$pv(vtkTemp187) GetPVWidget {Compute Normals}]
$pv(vtkTemp204) SetState 0
set kw(vtkTemp1029) [$pv(vtkTemp187) GetPVWidget {Compute Scalars}]
$kw(vtkTemp1029) SetState 1
$pv(vtkTemp187) AcceptCallback

[$pv(vtkTemp187) GetPVOutput] SetColorRange 0 3926

set Ren1 [[[$Application GetMainWindow] GetMainView] GetRenderer]
set activeCamera [$Ren1 GetActiveCamera]
$activeCamera SetPosition 31.5 250.821 20.5266
$activeCamera SetFocalPoint 31.5 31.5 31.5
$activeCamera SetViewUp 0 -0.049971 -0.998751
$activeCamera SetViewAngle 30
$activeCamera SetClippingRange 151.66 305.641

$pv(vtkTemp1) ResetCameraCallback

# 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
