#
# HELP: SYNOPSIS:
# HELP:     colotux/helper/PolyRGtoRYG
# HELP:
# HELP: DESCRIPTION:
# HELP:     Change an old style red/green polyp marking to a new style
# HELP:     red/yellow/green marking. Note, that the sense of red and 
# HELP:     green is inverted by this!
#

DECLARE int $x
DECLARE int $y
DECLARE int $z
DECLARE int $red
DECLARE int $green

# Find all red/green blobs. 
# Any blob that is purely red now, is mapped to 2 temporarily.
# Any blob that has at maximum 3 times as many red voxels as green ones
# is marked to 1 temporarily.
# Anything else is marked to 14(yellow)
POS 0 0 0
{ WHILE1 1
	CLASS_FINDCOLOR 10,12 1
	CECHO ${$x=$root.rc.x} ${$y=$root.rc.y} ${$z=$root.rc.z}
	IF ${$x==-1} BREAK WHILE1
	CLASS_FILLCONNECTED ${$x} ${$y} ${$z} 14 10,12
	CECHO ${$red=$root.rc[12]} ${$green=$root.rc[10]}
	IF ${$green==0} CLASS_FILLCONNECTED ${$x} ${$y} ${$z} 2 14
	IF ${$green*3>=$red} CLASS_FILLCONNECTED ${$x} ${$y} ${$z} 1 14
} WHILE1 1 1

# Remap 1 to 12 (red)
POS 0 0 0
{ WHILE2 1
	CLASS_FINDCOLOR 1 1
	CECHO ${$x=$root.rc.x} ${$y=$root.rc.y} ${$z=$root.rc.z}
	IF ${$x==-1} BREAK WHILE2
	CLASS_FILLCONNECTED ${$x} ${$y} ${$z} 12 1
} WHILE2 1 1

# Remap 2 to 10 (green)
POS 0 0 0
{ WHILE3 1
	CLASS_FINDCOLOR 2 1
	CECHO ${$x=$root.rc.x} ${$y=$root.rc.y} ${$z=$root.rc.z}
	IF ${$x==-1} BREAK WHILE3
	CLASS_FILLCONNECTED ${$x} ${$y} ${$z} 10 2
} WHILE3 1 1

POS ${$root.vol[current].size.x/2} ${$root.vol[current].size.y/2} ${$root.vol[current].size.z/2}
