# Script to get voxel values from the image
# Will run only on a 3D image
# Will ask for threshold value and image dimensions
# Only those values will be returned that are above the threshold
# These values willbe written to a file called voxels.txt in /tmp
#
# Written By Raj Jagannathan - 12/27/00

InputFromWidget "Voxel Values" 5 "Threshold Value" T 8 "No. of Rows(x)" rows 4 "No. of Columns(y)" cols 4 "Begin Slice" beg_slice 4 "End Slice" end_slice 4

MxGetCurrentPage P0
set voxels [open /tmp/voxels.txt w]

puts $voxels "X \t Y \t Z \t Intensity"
puts $voxels "- \t - \t - \t ---------"

for {set x 0} { $x < $rows } { incr x } {
     
	for {set y 0} { $y < $cols } {incr y} { 	
		
		for {set z $beg_slice} { $z <= $end_slice } {incr z} {  

			MxGetVoxel $P0 $x $y $z a
			
			if {$a >= $T} {

				puts $voxels "$x \t $y \t $z \t $a"
				puts "$x \t $y \t $z \t $a"
					
			}

		}
	}

}

flush $voxels
close $voxels
MxPause "The script is done"





