$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(vtkTemp89) [$pv(vtkTemp1) GetPVSource GlyphSources Arrow]
set pv(vtkTemp93) [$pv(vtkTemp1) GetPVSource GlyphSources Cone]
set pv(vtkTemp97) [$pv(vtkTemp1) GetPVSource GlyphSources Sphere]
set pv(vtkTemp98) [$pv(vtkTemp1) CreatePVSource Axes]
$pv(vtkTemp98) AcceptCallback
[$pv(vtkTemp98) GetPVOutput] SetLineWidth 3
set pv(vtkTemp168) [$pv(vtkTemp1) CreatePVSource Axes]
set pv(vtkTemp183) [$pv(vtkTemp168) GetPVWidget {Origin}]
$pv(vtkTemp183) SetValue 0 3 0
set pv(vtkTemp188) [$pv(vtkTemp168) GetPVWidget {Symmetric}]
$pv(vtkTemp188) SetState 1
$pv(vtkTemp168) AcceptCallback
[$pv(vtkTemp168) GetPVOutput] SetLineWidth 3
$pv(vtkTemp1) ResetCameraCallback
$pv(vtkTemp1) SetCurrentPVSourceCallback $pv(vtkTemp98)
$pv(vtkTemp1) ShowCurrentSourcePropertiesCallback


# Position the camera
set Ren1 [[[$Application GetMainWindow] GetMainView] GetRenderer]
set camera [$Ren1 GetActiveCamera]
$camera  SetPosition 7.96507 9.75632 6.90566
$camera SetFocalPoint 0.190213 2.17507 -0.136077
$camera SetViewUp 0.252184 0.506968 -0.824249
$camera SetViewAngle 30
$camera SetClippingRange 8.34501 19.084

# Retracing produces wrong image for some reason
# 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
