# $Application should exit when this script is finished.
$Application ExitOnReturnOn

set kw(vtkTemp1) [$Application GetMainWindow]
set pv(vtkTemp43) [$kw(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

$kw(vtkTemp1) SetUseMessageDialog 0

# Open an image data set.
$kw(vtkTemp1) Open "$DataDir/Data/iron protein.vtk"
set kw(vtkTemp257) [$kw(vtkTemp1) GetCurrentPVSource]
set kw(vtkTemp266) [$kw(vtkTemp257) GetPVWidget {Filename}]
$kw(vtkTemp266) SetValue "$DataDir/Data/iron protein.vtk"

# Choose the file name/type based on whether we are in parallel mode.
set kw(vtkTemp1000) [$Application GetController]
set nprocs [$kw(vtkTemp1000) GetNumberOfProcesses]

set ext "vti"
if {$nprocs > 1} { set ext "pvti" }

# Write the vtkImageData.
$kw(vtkTemp1) WriteVTKFile "testImageData.$ext"

# Delete the old pipeline.
$kw(vtkTemp257) DeleteCallback

# Read the vtkImageData from the temporary file.
$kw(vtkTemp1) Open "testImageData.$ext"
set kw(vtkTemp289) [$kw(vtkTemp1) GetCurrentPVSource]
$kw(vtkTemp289) AcceptCallback

# Contour it to produce some actual data for display.
set kw(vtkTemp319) [$kw(vtkTemp1) CreatePVSource Contour]
set kw(vtkTemp325) [$kw(vtkTemp319) GetPVWidget {Scalars}]
$kw(vtkTemp325) SetValue {scalars}
set kw(vtkTemp328) [$kw(vtkTemp319) GetPVWidget {Contour Values}]
$kw(vtkTemp328) RemoveAllValues
$kw(vtkTemp328) AddValue 10.0
set kw(vtkTemp1029) [$kw(vtkTemp319) GetPVWidget {Compute Scalars}]
$kw(vtkTemp1029) SetState 1
$kw(vtkTemp319) AcceptCallback

# 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]]
    }
}

# Delete the temporary file.
catch { file delete -force "testImageData.$ext" }

if {$nprocs > 1} {
  # Delete the temporary file's pieces.
  for {set i 0} { $i < $nprocs } { incr i } {
  catch { file delete -force "testImageData$i.vti" }
  }
}
