###################################################################
UPDATE: 11 Apr 2016
###################################################################

Sample data to another subject

A new overload of the "fsavg" button on the View
Functional Data panel allows re-sampling the
surface data from one single subject to another
(standard left click resamples to fsaverage).

A shift-middle-click on the "fsavg" button brings
up a panel to select the other subject (must be in
current SUBJECTS_DIR).  This does:

  current subject -> fsaverage -> another subject

See R-click help for details (N.B.: middle-click
on "fsavg" to get sample-to-opposite-hemisphere of
fsaverage still IN PROGRESS).


Display MGH morph target template (.tif) frame as curv

Individual frames in the MGH freesurfer tif
template target (e.g., average curv or average
sulc) can be loaded onto a subject's sphere.reg
surface (or any other surface after sphere.reg has
been loaded at least once).  The average target
tif's are in the standard MGH distribution, so
this requires that FSURF_DIR is defined.

See S/V help for how to blink back and forth
between target and indiv subj data (uses
swap_curv_curvbak).


Multi-parameter Spherical Morph

An new spherical morph option ("REG" on F3 panel)
can simultaneously minimize error in curvature
(e.g., sulc), a second real-valued measure (e.g.,
qT1), and a third complex-valued measure (e.g.,
polar angle) all while trying to preserve
geometry (I know, I have gone to the dark side
here...).

The procedure is:

  (1) open a sphere.reg surface

  (2) load curvature, and/or real-valued target
  data, and/or complex-valued data to surface

  (3) sample surface data to target volumes
  ("reverse paint", using alternate clicks on the
  "val:" line "W" button)

  (4) load data to be morphed onto the surface

  (5) run sphere_morph

The parameters (weights) controlling the 4 main
vertex-wise terms in deformation are found at the
bottom left of the large F3 interface along with a
new "REG" button.  The gradient descent terms,
each summed across neighboring vertices, are:

  ws: geometry restoration (neighboring vertices
    vector sum)

  wcrv: curvature (.curv) error at current vertex,
    times gradient component of target curvature,
    in neighboring vertex direction

  wsta: real-valued statistic (.stat) error at
    current vertex, times gradient component of
    target statistic, in neighboring vertex
    direction

  wcpx: angle (atan2(.val2,.val)) error (circular
    subtraction) at current vertex, times gradient
    component of target angle, times complex
    amplitude of target (hypot(.val,.val2), in
    neighboring vertex direction

Setting any of these parameters to 0.0 causes this
kind of data to be ignored in during error
minimization.

Thus, there are potentially 8 different vertexwise
data sets that can be involved (not including the
surface geometry):

  CURV
    --target .curv sampled to image
    --moveable surface .curv
  STAT
    --target .stat sampled to image
    --moveable surface .stat
  COMPLEX
    --target .val sampled to image
    --moveable surface .val
    --target .val2 sampled to image
    --moveable surface .val2

Here is how to use all 8 kinds of data (N.B.: to a
sphere.reg surface!) via the interface:

  ### load target data to surface
  select TARGET sulc file from "curv:" dropdown
  left-click "R" on "curv:" line to read to surface
  select TARGET real-valued stat from "val:" dropdown (e.g., qT1)
  left-click "R" on "val:" line to read to surface
  left-click "S/V" on "val:" line to move it to .stat
  select TARGET complex data dropdown (e.g., polar _r,_i)
  left-click "R" on "val:" line to read to surface
  ### "reverse paint" target data to volume
  shift-middle-click "W" on "val:" line (rev paint curv)
  shift-right-click "W" on "val:" line (rev paint stat)
  shift-left-click "W" on "val:" line (rev paint complex)
  ### load moveable data (data to be morphed)
  select MOVEABLE sulc file from "curv:" dropdown
  left-click "R" on "curv:" line to read to surface
  select MOVEABLE real-valued stat from "val:" dropdown (e.g., qT1)
  left-click "R" on "val:" line to read to surface
  left-click "S/V" on "val:" line to move it to .stat
  select MOVEABLE complex data dropdown (e.g., polar _r,_i)
  left-click "R" on "val:" line to read to surface
  ### morph (F3 interface)
  set parms: ws, wcrv, wsta, wcpx (start small)
  set steps/cycles
  click REG

or as tcl commands:

  ### load target to surface
  set curv ~/surf/targ-$hemi.sulc
  read_binary_curv
  set val ~/surf/targ-qT1-$hemi.w (or .curv/.mgh/.vtk)
  read_binary_values
  swap_stat_val
  set val ~/surf/targ-polarangle_i-$hemi.w
  read_binary_values
  swap_val_val2
  set val ~/surf/targ-polarangle_r-$hemi.w
  read_binary_values
  ### "reverse paint" target data to volume
  surf2sphim 0
  surf2sphim 1
  surf2sphim 2
  surf2sphim 3
  ### load data to be morphed
  set curv ~/surf/moveable-$hemi.sulc
  read_binary_curv
  set val ~/surf/moveable-qT1-$hemi.w (or .curv/.mgh/.vtk)
  read_binary_values
  swap_stat_val
  set val ~/surf/moveable-polarangle_i-$hemi.w
  read_binary_values
  swap_val_val2
  set val ~/surf/moveable-polarangle_r-$hemi.w
  read_binary_values
  ### morph
  set wc 0.5
  set wcrv 0.5
  set wsta 0.001   ;# inv proportional to real values
  set wcpx 0.1
  sphere_morph 20

-----------------------------------------------
Bug fixes, small changes
-----------------------------------------------

New S/V alt functions: swap_curv_curvbak, sawp_curv_val

Fix View Functional Data reset of saved lutw colscale to standard wheel

Phase color LUT does discrete colors if intp unticked ($interpolatelutflag)

Fix smaller combobox dropdown every 3rd click on dropdown

Fix prev unclearable old/white vtx selections when re-read surface w/selected

Fix 'permissions' error (my bug) on start Mac TextEdit for NOTES

Fix Mac recon-all error (from SUBJECTS_DIR env no longer passed by El Capitan)

Surface/Volume window R-double-click help for surface window clicks

##########################################################################
UPDATE: 11 Apr 2016
##########################################################################
--tksurfer.c: sphere_morph: precalc surf/targim ang/amp (baks so no wheel biff)
--tksurfer.tcl: REG checks {curv,stat,real,imag}imloadeflag's
--tksurfer.tcl: "W" butt "val:" overload: shift-L:val_to_sphim 2,val_to_sphim 3
--tksurfer.tcl: swap rare parm: shrink2d(wsh->shear) for sphere_morph(wcpx)
--tksurfer.c,tcl: rename wval to wsta
--tksurfer.c: add ***revpnt_stat,SPH_STAT to not overlap val/val2
--tksurfer.c: recalc sphere norm every step: simply {x,y,x}/100
--tksurfer.tcl: read .tif template popup warn sphere.reg coords not yet loaded
--csurf: add shrink/morph help to all-help panel
--lib/help/tksurfer/morph: new helpfile (added to mk0{.csh})
--lib/help/tksurfer/{curv,curv_read,val_write}: update tif template,surf2sphim
--tksurfer.tcl: val "W" overload: shift-M:val_to_sphim 0, shift-R:val_to_sphim 1
--tksurfer.tcl: swap rare parms: area_shrink(wt/wc) for sphere_morph(wcrv/wval)
--tksurfer.tcl: add REG button to run/interrupt sphere_morph
--lib/help/tksurfer/swapstatval: doc new bindings
--tksurfer.tcl: 4th,5th S/V bindings to expose swap_curv_curvbak,swap_curv_val
--tksurfer.tcl: rm read_tif_* frames arg to parallel read_binary_values mgh,vtk
--tksurfer.c: change surf2sphim to read from curv/val/va2 (was just val)
--tksurfer.c: add/export functs: surf2sphim,sphere_morph, parms: wcrv,wval
--lib/help/csurf/csurf: update to describe .tif format
--tksurfer.tcl: if select template .tif -> chooseframe popup (documents frames)
--tksurfer.tcl: load abs FSURF_DIR template .tif's into curv dropdown
--tksurfer.c: rm read_tif_* frames arg to parallel read_binary_values mgh,vtk
--tksurfer.c: add/export read_tif_template(), read_tif_header(), templateframe
--tksurfer.c: add/export swap_curv_val(), assume curv always loaded
--tksurfer.tcl: add (tif) $template to setfile sessionfiles
--csurf: blkcallback colscaletype bind stops select_colscaletype reset config'd
--offsetmovie.tcl: add HOWTO in error if angle_offset wrap
--wrappers.tcl: always print report on source except by csurf
--wrappers.tcl: helpwin: add linux/mac find/next help to right of title
--lib/help/tksurfer/{intplut,botedge,zerosymm,val2rgb}: update
--tksurfer.tcl: if ltw, botedgelutflag=1,zerosymmfadeflag=0 (no effect:reflect)
--tksurfer.c: phase LUT: discrete colors works (both assume botedgelutflag=1)
--tksurfer.c: printeventtype =>tkmedit:printXevent (count,Mac-specific Generic)
--lib/help/csurf/spheresurface: explain average.tif vs. average...buckner40.tif
--lib/help/tkmedit/clks: new file (add to mk0{.csh})
--tkmedit.c: right-double-click for volume window click help
--mk0{.csh}: add new helpfile
--lib/help/csurf/fsavg: new file
--csurf: R-click fsavg gives first widget-specific setupscans-panel help
--csurf: shift-middle-click fsavg sets up: curr -> fsaverage -> othersubj
--wrappers.tcl: rename tmpcontrols => modalcontrols, killbox => killboxOK
--csurf: if paint single subj onto fsaverage, allow use fsaverage-only patches
--csurf: more bakcompat in addrawavgscan for 000319CF
--csurf: 30 combos on notebook pages to -listwidth <pix> only, adjust some
--tkmedit.tcl: 8 lg: -listwidth <pix>: im,roiup,roin,valup,valn,mskup,mksn,lut
--tkmedit.tcl: 2 sm: -listwidth <pix> *and* listbox.width: surf,im2
--tksurfer.tcl: 7 lg: only -listwidth <pix>: tcl,patch,label,lut,val,val3d,rgb
--tksurfer.tcl: 3 sm: -listwidth <pix> *and* listbox.width: surf,curv,area
--csurf: 6 on mainwin: tixComboBox -listwidth 208 vs. -options listbox.width 25
--need listwidth+options for <20 char else min const width increases
--small width: (<20chars) -listwidth <pix> *and* -options listbox.width <chars>
--large width: (>=20chars) only -listwidth <pix> required
--tixComboBox add -listwidth <pix> vs. -options "... listbox.width <chars>"
--on linux, smaller only appears after previously clicking different dropdown
---------------------------------------------------------------------
--finally, fix for every 3rd click on combo shrinks listbox to entry size
--table of char->pix
--less than than 20 chars: -listwidth <pix> *and* -options listbox.width <char>
    17->153, 18->159, 19->166
--more than 20 chars: just -listwidth <pix>
    20->173, 21->180, 22->187, 23->194, 24->201, 25->208, 26->215, 30->243
    35->278, 38->297, 40->315, 42->327, 45->348, 55->418, 60->453
---------------------------------------------------------------------
--lib/help/csurf/{rc-vol,rc-volradio}: update
--lib/help/tksurfer/erode: update
--tksurfer.tcl: ROI butt unsets dilatingfillflag, update/restore tick label
--tksurfer.tcl: change "er" to bold "dl" if dilating FILL, better state report
--csurf: localize csurf help next to each widget code
--csurf: convert mritype entry to autofill combo to allow load non-standard vol
--csurf: fix auto-cancel ViewFunct/Sphere type (no tkwait, set makingsetupscan)
--csurf: inline env AFNI_ENFORCE_ASPECT=YES for afni
--csurf: choosedir (mabye dir/file) uses entry title vs. "Choose Directory"
--csurf: differentiate choosedir entry title strings (Choose vs. Enter)
--tk{med,reg}.c,orig2cor.c: cleanup MRI_DIR->VOL_DIR
--mk0{.csh}: insttmp makes tclsh/wish links (so bare matches CSURF_LIBRARY_PATH)
--FreeSurferEnv.{c}sh: report *LD_LIBRARY_PATH copied to CSURF_LIBRARY_PATH
--bin/noarch/{bsurf,csurffonts}: fix 10.10+ wish startup (left tclsh general)
--lib/help/csurf/{tkstrip,rc-VOLUME}: update
--csurf: shift-mid-click on VOLUME opens tkstrip on currently selected volume
--csurf: add TkStrip to all-help panel
--mk0{.csh}: new helpfiles
--lib/help/csurf/tkstrip: new helpfile
--tkstrip.tcl: add upper-left "h" button
--lib/help/tksurfer/clks: new helpfile
--tksurfer.c: fix/update cmdline click help
--tksurfer.c: surface window R-double-click help for surface window clicks
--lib/help/tksurfer/label_write: update for nhits display
--csurf: add setenv SUBJECTS_DIR to recon-all script: ElCapitan no longer passes
--tksurfer.c: don't re-malloc/destroy marked[] on re-read same vertexcnt surf
--csurf: exec $editor $file >& /dev/null & => exec open -e $file (no multiple)
--csurf: editfile: TextEdit case (bad geom arg -> 'permissions' err begin 10.9+)
--lib/help/csurf/tkmedit: document main window clicks at top
--tkmedit.c: raise/focus glx win after gnuplot histogram, popup warn rad=1
--tksurfer.tcl: do_lut2annot displays/rotates assembled labels, then hitcount
--tksurfer.c: write_mgh_annot accumulates label hit count (nhits) in .stat
--csurf: wrong type (funct/sphavg) warning now closes setupscans panel
--tksurfer.tcl: reset flag/alpha for read/write_mgh_annot reset for log
--tksurfer.c: harmonize read/write_mgh_annot (tksurfer.tcl resets flag/alpha)
 
##########################################################################
UPDATE: 30 Jan 2016
##########################################################################
--tksurfer.tcl: Linux:100ms delay block runaway updates w/fast slidertrough clks
--lib/help/tksurfer/label_write: update for write_mgh_annot
...




