# This file contains specific settings for the 
# Amira Virtual Insect Brain (VIB) scripts.
# It is included by all other scripts.

# This assumes that the scripts are located in a 
# sub directory of the same directory that holds 
# the directories for image data, label fields etc.

set VIBRoot ${SCRIPTDIR}/..

# input directory containing the original image data files
set VIBgreydir ${VIBRoot}/images


# input directory containing the corresponding label fields
set VIBlabeldir ${VIBRoot}/labels

# output directory for downsampled grey files
set VIBresgreydir ${VIBRoot}/images-small

# output directory for statistic files
set VIBstatisticsdir ${VIBRoot}/statistics

# output directory for surface files
set VIBsurfacedir ${VIBRoot}/surfaces

# output directory for snapshots
set VIBsnapshotdir ${VIBRoot}/snaps

# LabelField of the template individue. This is used for registration.
set VIBtemplatelabels ${VIBlabeldir}/F21b.labels

# Statistics file of the template individue. This is used for registration.
set VIBtemplatestatistics ${VIBstatisticsdir}/F21b.statistics

# Surface file of the template individue. 
set VIBtemplatesurface ${VIBsurfacedir}/F21b.surface

# Image data set of the template individue. This is used for registration.
set VIBtemplategrey ${VIBgreydir}/F21b.grey


# LabelField containing a correct set of material names and colors. 
# This is used by the relabel script.
set VIBmasterlabels ${VIBlabeldir}/F21b.labels

# number of different templates (to be used e.g. in alignment). 
# One is sufficient here
set VIBntemplates 2
set VIBtemplate(0) F21b
set VIBtemplate(1) F22b


# number of groups of animals 
# increase this number if needed and specify more 
# groups below

set VIBngroups 3

set VIBgroup(0) "*.grey"   # all files (ending with .grey)
set VIBgroup(1) "F*.grey"  # all files starting with F
set VIBgroup(2) "M*.grey"  # all files starting with M


######################################################################
# do not change anything beyond this point
######################################################################

set VIBntotalfiles 0

for { set i 0 } { $i < $VIBngroups } { incr i } {
    set VIBnfiles($i) [ llength [glob $VIBgreydir/$VIBgroup($i)] ]
    set VIBntotalfiles [ expr $VIBntotalfiles + $VIBnfiles($i) ]
}

proc getLastWord {arg1} {
    set n [string last "/" $arg1 ]
    incr n
    set result [string range $arg1 $n end]
    return $result
}

proc getGreyBaseName {arg1} {
    regexp {(.*/)([a-zA-Z_.0-9]+).grey} $arg1 all path file
    return $file
}


proc VIBgetFileName { group relidx } {
    global VIBngroups
    global VIBnfiles
    global VIBgreydir
    global VIBgroup
    if { $group < $VIBngroups } {
	set longfile [lindex [glob $VIBgreydir/$VIBgroup($group)] $relidx]
	set file [ getGreyBaseName $longfile ]
	return $file 
    } else {
	for { set i 0 } { $i < $VIBngroups } { incr i } {
	    if { $relidx < $VIBnfiles($i) }  {
		return [ VIBgetFileName $i $relidx ]
	    }
	    set relidx [ expr $relidx - $VIBnfiles($i) ]
	}
    }
}

proc VIBgetNumSelectedFiles { group } {
    global VIBngroups
    global VIBnfiles
    global VIBntotalfiles
    if { $group < $VIBngroups } {
	return $VIBnfiles($group)
    }
    return $VIBntotalfiles
}



# output directory for diffusion transformations
set VIBdifftransdir ${VIBRoot}/difftrans

# output directory for diffusion warped files
set VIBdiffwarpeddir ${VIBRoot}/diffwarped

# general directory for output files
set VIBoutputdir ${VIBRoot}/output

# Unix command to print to standard printer:
set VIBprinter lpr

