#
# NEED_PARMS stepsize width
#

DECLARE int $fd
DECLARE struct $mvec,$file
DECLARE double $deltaang,$angstep,$amplify,$AxisAngle

WAITBARTITLE -2

CECHO ${$amplify=1.6}
CECHO ${$file=$root.func.file}

CECHO ${$angstep = ($argv[1]!=(void)0) ? (double)$argv[1] : 2.0 } 
CECHO ${$deltaang= ($argv[2]!=(void)0) ? (double)$argv[2]/2.0 : 5.0 } 

CECHO ${$angstep = ($angstep<1.0) ? 1.0 : $angstep }

CECHO ${$fd=$file.open($root.vol[current].path+"_angle.csv","wct",0666)}

# Remove all possible prior measurement meshes.
! angiotux2d/user/angleplot_remove_ovl
VIEW_DATALINE 4 rCBV Plot

# First measure the right basalganglion
! angiotux2d/helper/BlobMeasure ${$fd} 4 "BG rechts" BGRE "ffff 0000 0000"

# Now get the COG of the ring we will measure
! angiotux2d/helper/GetCOG "2"
! angiotux2d/helper/GetAxisAngle "2"

# Now place a few nice circles around it
! angiotux2d/helper/DrawCircle 10 "0000 aaaa 0000" ${$amplify} 18
! angiotux2d/helper/DrawCircle 20 "0000 bbbb 0000" ${$amplify} 18
! angiotux2d/helper/DrawCircle 30 "0000 cccc 0000" ${$amplify} 24
! angiotux2d/helper/DrawCircle 40 "0000 dddd 0000" ${$amplify} 36
! angiotux2d/helper/DrawCircle 50 "0000 eeee 0000" ${$amplify} 36
! angiotux2d/helper/DrawCircle 60 "0000 ffff 0000" ${$amplify} 36

# Draw the coordinate system cross
! angiotux2d/helper/DrawCross 60 "0000 0000 ffff" ${$amplify} ${$AxisAngle}

# Do the measurement
! angiotux2d/helper/APMeasure Messung "4444 ffff ffff" "2" ${$fd} ${$angstep} ${$deltaang} ${$amplify} ${$AxisAngle}

# Last measure the left basalganglion
! angiotux2d/helper/BlobMeasure ${$fd} 5 "BG links" BGLI "ffff 0000 ffff"

CECHO ${$file.close($fd)}

# Make sure everything is drawn before making a snapshot.
VIEW_RENDER
RECORDSNAP ${$root.func.strings.quote($root.vol[current].path+"_angle.png")} PPM:PNG

WAITBARTITLE -1
