-------------------------------------------
function: smooth_val_weighted <steps>
-------------------------------------------
keyboard equivalent: none

The "w" radio button (lower right) causes the
"SMOOTH" button to perform a distance- and
number-weighted smoothing (as opposed to nearest
neighbor smoothing) on overlaid data

By selecting "w", smooth_val_weighted is used to
smooth current vertex data (if real data,
vertex[i].val, else if complexvalflag=1,
vertex[i].val and vertex[i].val2).

This function produces similar results to
smooth_val ("val") but can be adjusted to smooth
less agressively using $halfweightdist
(default=0.4).  This is useful for high
resolution data that approaches the resolution of
the surface mesh.

To control, R-click the "w" radio button to get a
popup.

This iterative nearest-neighbor smoothing is like
smooth_val except that it is distance- and
density-weighted.  The distance-weighting uses
neighboring vertex distances from the $origcoords
surface (usu. ?h.orig) and is controlled by the
tcl var $halfweightdist (default=0.4), which
indicates the distance in mm where the Gaussian
weight drops to 0.5 (before density weighting).

This is still an operation that only involves
neighboring vertices.

The density-weighting controls varying number of
neighboring vertices (~6 for a triangular
surface).

Here is schematic C-code:

  fwhm = 2.0*halfweightdist;
  sigma = fwhm/(2.0*sqrt(2.0*log(2.0)));
  foreach vertex {
    foreach neighbor {
      weight = exp(-(d*d)/(2.0*(sigma*sigma)));
      weight *= avgneigbors/currneighbors;
      sumweight += weight;
      sumvertexdata += weight*vertexdata;
    }
    newvertexdata = sumvertexdata/sumweight;
  }

As $halfweightdist is increased, the behavior of
smooth_val_weighted approaches the behavior of
smooth_val (R-click smooth steps entry for
empirical estimates of nearest-neighbor kernel
size -- e.g., 10 steps ~3.2mm FWMM).

The first time this function is used, it may have
to read in the $origcoords surface to find
original intervertex distances.

Here are tcl script commands for 10 steps (~3 mm
FWHM) of surface-smoothing of already-read-in
complex data (what SMOOTH button does with
complex data):

  swap_val_val2
  smooth_val_weighted 10
  swap_val_val2
  smooth_val_weighted 10

Here are tcl script commands for 1 step
of Gaussian smoothing with a FWHM of 1 mm:

  set halfweightdist 0.5
  swap_val_val2
  smooth_val_weighted 1
  swap_val_val2
  smooth_val_weighted 1
