-------------------------------------------
 The MGHTools -> Make Final Surface menu item
 starts a two-part background process to create
 the final left and right hemisphere cortical
 surfaces and calculate cortical thickness
-------------------------------------------
(1a) Make Final Right Hemisphere Surfaces
(1b) Make Final Left Hemisphere Surfaces

The input file required are:

 volume: $SUBJECTS_DIR/$name/mri/brain[.mgz]
 volume: $SUBJECTS_DIR/$name/mri/wm[.mgz]
 volume: $SUBJECTS_DIR/$name/mri/filled[.mgz]
 surface: $SUBJECTS_DIR/$name/surf/rh.orig
 surface: $SUBJECTS_DIR/$name/surf/lh.orig

The output files written by this procedure are:

 surface: $SUBJECTS_DIR/$name/surf/rh.white
 surface: $SUBJECTS_DIR/$name/surf/rh.graymid
 surface: $SUBJECTS_DIR/$name/surf/rh.pial
 vtxdata: $SUBJECTS_DIR/$name/surf/rh.thickness

 surface: $SUBJECTS_DIR/$name/surf/lh.white
 surface: $SUBJECTS_DIR/$name/surf/lh.graymid
 surface: $SUBJECTS_DIR/$name/surf/lh.pial
 vtxdata: $SUBJECTS_DIR/$name/surf/lh.thickness

Cortical thickness algorithm

 (1) foreach vertex -> search opposite surface

   (a) pick pial surface vertex
   (b) find distance to same-numbered
          vertex in white matter surface
   (c) find neighbors of same-numbered
          white matter vertex
   (d) check distance from pial surface
          vertex to neighbors, too
   (e) find minumum distance of all these pairs

 (2) foreach vertex -> same search inverted

   (a) pick same-number white matter surface vertex
   ... search neighbors on pial as above

   Since surfs same topo, needn't re-find neighbors

 (3) average results of two above

Note that this doesn't refer to the normal,
which is only used to calculate a dot product
to determine if it is pointing in or out.


==========================
internal parameters
==========================
#define MAX_WHITE 120
#define MAX_BORDER_WHITE 105
#define MIN_BORDER_WHITE 85
#define MIN_GRAY_AT_WHITE_BORDER 70

#define MAX_GRAY 95
#define MIN_GRAY_AT_CSF_BORDER 40
#define MID_GRAY   \
  ((MAX_GRAY + MIN_GRAY_AT_CSF_BORDER) / 2)
#define MAX_GRAY_AT_CSF_BORDER 75
#define MIN_CSF 10
#define MAX_CSF 40

static int
  max_border_white_set = 0,
  min_border_white_set = 0,
  min_gray_at_white_border_set = 0,
  max_gray_set = 0,
  max_gray_at_csf_border_set = 0,
  min_gray_at_csf_border_set = 0,
  min_csf_set = 0,
  max_csf_set = 0;

static  float
  max_border_white = MAX_BORDER_WHITE,
  min_border_white = MIN_BORDER_WHITE,
  min_gray_at_white_border =
                   MIN_GRAY_AT_WHITE_BORDER,
  max_gray = MAX_GRAY,
 max_gray_at_csf_border=MAX_GRAY_AT_CSF_BORDER,
  min_gray_at_csf_border=MIN_GRAY_AT_CSF_BORDER,
  min_csf = MIN_CSF,
  max_csf = MAX_CSF;

