#
# HELP: SYNOPSIS:
# HELP:     colotux/user/FastPolys
# HELP:
# HELP: DESCRIPTION:
# HELP:     Prepare an acquired volume for display, including denoising
# HELP:     and autodetection of polyps.
#

! generic/menu/confirm_longrun
IF ${!$result} QUIT

# Check if already processed
VOL_ALLOC_DEPTH
VOL_ALLOC_CLASS
{ CSR ${$root.rc==-1}
	! colotux/helper/ComplainScriptRerun
	QUIT
} CSR 0 0

# Normalize the Volume first.
! colotux/helper/NormalizeVolume

# Shut down noisy progress bars.
WAITBARTITLE 0 100 FastPolys

VIEW_SET Main
VOL_ALLOC_DEPTH
VOL_ALLOC_CLASS

! colotux/helper/FindBody

! colotux/helper/Filtering

WAITBARTITLE 0 100 Finding colon

WAITBARTITLE 0 12 Finding colon
MARKCG 0 ${$root.func.eccet.fromHU(-750)} 0 3
WAITBARTITLE 12 25 Finding colon
MARKCC_SIZE 1000 3 0 2
WAITBARTITLE 25 37 Finding colon
MARKCG 65535 65535 0 4
WAITBARTITLE 37 50 Finding colon
MARKCC_SIZE 10 0 2 3
WAITBARTITLE 50 60 Finding colon
MARKCC 3,4 0
WAITBARTITLE 60 70 Finding colon
MARKCC_KILL_FACE z e 2 3
WAITBARTITLE 70 85 Finding colon
MARKCC_DILATE 1 2,3 32,36
WAITBARTITLE 85 100 Finding colon
norm2 32,36 2,3 2 3
# Re-enable noisy progress bars.
WAITBARTITLE -1

! colotux/helper/FindPolyps
VIEW_DISP 0

#
# O.K. - we are ready - now convert to colotux format
#

! colotux/helper/SaveC2D

! colotux/helper/MergeAndFilter

# Push the greyscale stuff into the classes
# Erase the target field
WAITBARTITLE 0 25 Generating 3D data
GREYTOCLASS 0 65535 0 0
# Let the air/tissue level flip at around -750 HU
WAITBARTITLE 25 75 Generating 3D data
GREYTOCLASS ${$root.func.eccet.fromHU(-1000)} ${$root.func.eccet.fromHU(-500)} 0 255
# Everything denser is opaque.
WAITBARTITLE 75 100 Generating 3D data
GREYTOCLASS ${$root.func.eccet.fromHU(-500)} 65535 255 255
# Re-enable noisy progress bars.
WAITBARTITLE -1

! colotux/helper/MergeOriginal
! colotux/helper/PolyRGtoRYG

! colotux/helper/Prepare3dClass
