1 /*****************************************************************************
2    Major portions of this software are copyrighted by the Medical College
3    of Wisconsin, 1994-2000, and are released under the Gnu General Public
4    License, Version 2.  See the file README.Copyright for details.
5 ******************************************************************************/
6 
7 #ifndef _AFNI_HEADER_
8 #define _AFNI_HEADER_
9 
10 #include "mrilib.h"
11 #include "imseq.h"
12 #include "xutil.h"
13 #include "pbar.h"
14 #include "afni_graph.h"
15 #include "afni_pcor.h"
16 
17 #include <stdio.h>
18 #include <string.h>
19 #include <stdlib.h>
20 #include <math.h>
21 #include <time.h>
22 
23 #include <Xm/Separator.h>
24 #include <Xm/Display.h>
25 #include <Xm/CascadeB.h>
26 
27 #include "logo.h"
28 
29 #define WARP_4D
30 
31 #ifndef DONT_USE_OPTMENUS
32 #ifndef USE_OPTMENUS
33 #define USE_OPTMENUS
34 #endif
35 #endif
36 
37 /*------------------------------------------------------------
38   Global data holding command line arguments information
39 --------------------------------------------------------------*/
40 
41 typedef struct {
42       float dy , dz , gamma , gsfac ;
43       RwcBoolean read_images , read_sessions , auto_purge ,
44               resize_images , keep_logo , pos_func ,
45               destruct , tlrc_big , warp_4D , unique_dcs ;
46       int ncolor , datum , ignore , allow_rt , skip_afnirc ;
47       int xtwarns ;
48       char orient_code[4] ;
49       char title_name[32] ;
50 #ifdef ALLOW_PLUGINS
51       int noplugins , noplugouts ;
52       int plugout_code ;
53 #endif
54 
55       int first_file_arg , recurse ;
56       int elide_quality ;
57       int no_frivolities ;
58       int install_cmap ;
59       int left_is_left ;  /* 09 Oct 1998 */
60       int read_tim ;      /* 19 Oct 1999 */
61       int read_1D ;       /* 27 Jan 2000 */
62       int read_tcsv ;     /* 16 Jun 2020 */
63 
64       RwcBoolean read_dsets ;    /* 17 Mar 2000 */
65 
66       char *layout_fname ;    /* 23 Sep 2000 */
67 
68       int enable_suma ;       /* 29 Aug 2001 */
69 
70       int quiet ;             /* 25 Aug 2001 */
71       int disable_done ;      /* 21 Aug 2008 [rickr] */
72 
73       int yes_niml ;          /* 28 Feb 2002 */
74 
75                /* port_niml no longer in use. ZSS June 2011 */
76                /* int port_niml ;         10 Dec 2002 */
77 
78       int all_dsets_startup ; /* 04/06/2020 discoraj */
79       char *script_fname ;    /* 21 Jan 2003 */
80 
81       int cat_sess ;          /* 02 Jun 2016 */
82 
83       int only_images ;       /* 24 Feb 2017 */
84       int left_is_posterior ; /* 27 Mar 2017 */
85 
86 } AF_options ;
87 
88 #ifdef MAIN
89    AF_options GLOBAL_argopt ;
90 #else
91    extern AF_options GLOBAL_argopt ;
92 #endif
93 
94 /*-----------------------------------------------------------*/
95 /** On Motif 2.0 on Linux, resized pbar pieces causes the
96     threshold scale to behave bizarrely.                     */
97 /** Fixing scale size removed to a function [03 Jun 2019] **/
98 
99 struct Three_D_View ;  /* incomplete type definition */
100 extern void AFNI_fix_scale_size_direct( struct Three_D_View *im3d ) ;
101 extern void AFNI_fix_scale_size_timer_CB( XtPointer , XtIntervalId * ) ;
102 
103 #define FIX_SCALE_SIZE(iqqq) /*nada*/
104 #define HIDE_SCALE(iqqq)     /*nada*/
105 
106 /*-----------------------------------------------------------*/
107 
108 /* define this to put "chooser" controls on the popup menu */
109 #undef POPUP_CHOOSERS
110 
111 #undef POPTOG
112 
113 /*-----------------------------------------------------------*/
114 
115 #define UNDERLAY_ANAT      0
116 #define UNDERLAY_ALLFUNC   1
117 #define UNDERLAY_THRFUNC   2   /* 29 Jul 2003: eliminated in all code! */
118 
119 #define UNDERLAY_ANAT_BVAL     (1 << UNDERLAY_ANAT   )
120 #define UNDERLAY_ALLFUNC_BVAL  (1 << UNDERLAY_ALLFUNC)
121 #define UNDERLAY_THRFUNC_BVAL  (1 << UNDERLAY_THRFUNC)
122 
123 #define LAST_UNDERLAY_TYPE 1  /* 29 Jul 2003: changed from 2 */
124 #define ISFUNC_UNDERLAY(uu) \
125    ((uu)==UNDERLAY_ALLFUNC||(uu)==UNDERLAY_THRFUNC)
126 
127 static char * UNDERLAY_typestr[] =
128    { "bkgd:ULay" , "bkgd:OLay" , "ulay:O@Thr" } ;
129 
130 #if 0
131 #define DEFAULT_FIM_SCALE 10000   /* change this and bad things will happen! */
132 #else
133 #define DEFAULT_FIM_SCALE 1       /* change this and bad things will happen! */
134 #endif
135 
136 #define DMODE_BRICK      0
137 #define DMODE_WOD        1
138 
139 #define DMODE_BRICK_BVAL (1 << DMODE_BRICK)
140 #define DMODE_WOD_BVAL   (1 << DMODE_WOD  )
141 
142 /*------------------------------------------------------------------*/
143 #define USE_SONNETS
144 #define WANT_RWCOX_IMAGE
145 #define USE_SKIT
146 
147 #ifdef NO_FRIVOLITIES
148 # undef USE_SONNETS
149 # undef WANT_RWCOX_IMAGE
150 # undef USE_SKIT
151 #endif
152 
153 #define TOPSIZE 2048
154 
155 /* #include "AFNI_label.h"   from mrilib.h      29 Dec 2015 [rickr] */
156 #define AVERZHN AFNI_VERSION_LABEL    /* 21 chars long */
157 
158 /* moved from .c files, and prepended w/AFNI_   28 Dec 2015 [rickr] */
159 
160 #define AFNI_VERSION_URL  "https://afni.nimh.nih.gov/pub/dist/AFNI.version"
161 
162 
163 #ifdef  __cplusplus
164 extern "C" {
165 #endif
166 
167 #ifdef MAIN
168 #define AFNI_about \
169      "************************************************\n"  \
170      "* GPL AFNI: Analysis of Functional NeuroImages *\n"  \
171      "*           Version " AVERZHN          "       *\n"  \
172      "*                                              *\n"  \
173      "* Major portions are Copyright 1994-2000,      *\n"  \
174      "*   Medical College of Wisconsin               *\n"  \
175      "*   Milwaukee, WI 53226-0509                   *\n"  \
176      "* See file README.copyright for information,   *\n"  \
177      "* or the Datamode->Misc->License menu item.    *\n"  \
178      "*                                              *\n"  \
179      "* Released to the public by MCW under the GNU  *\n"  \
180      "* General Public License (version 2), Dec 2000 *\n"  \
181      "*                                              *\n"  \
182      "* Author:  Robert W Cox, PhD                   *\n"  \
183      "************************************************"
184 
185 char AFNI_tophelp[TOPSIZE] = AFNI_about ;
186 char AFNI_abohelp[1024]    = AFNI_about ;
187 #else
188 extern char AFNI_tophelp[TOPSIZE] ;
189 extern char AFNI_abohelp[1024] ;
190 #endif
191 
192 #ifdef USE_SONNETS
193 
194     extern void AFNI_popup_sonnet( Widget,int ) ; /* 12 Dec 2001 */
195 
196 #   ifdef MAIN
197 #     include "sonnets.h"
198       static int sonnet_index = 0 ;
RESET_sonnet(void)199       void RESET_sonnet(void)
200       { int ll ;
201         sprintf( AFNI_tophelp , "                    * %d *\n" ,
202                  sonnet_index+1 ) ; ll = strlen(AFNI_tophelp) ;
203         strcpy( &(AFNI_tophelp[ll]) , sonnets[sonnet_index] ) ;
204         sonnet_index = (sonnet_index+lrand48()) % NUM_SONNETS ;
205       }
206 #   else
207       extern void RESET_sonnet(void) ; /* prototype */
208 #   endif  /* MAIN */
209 
210 #   define RESET_AFNI_QUIT(iqqq) \
211      { AFNI_quit_CB(NULL,(XtPointer)(iqqq),NULL) ; RESET_sonnet() ; }
212 
213 #else  /* don't USE_SONNETS */
214 
215 #   define RESET_AFNI_QUIT(iqqq) AFNI_quit_CB(NULL,(XtPointer)(iqqq),NULL)
216 
217 #endif /* USE_SONNETS */
218 /*------------------------------------------------------------------*/
219 
220 /** macro to clear the montage information in the
221     z-direction of a particular brick, in a particular controller **/
222 
223 #define CLEAR_MONTAGE(iq,bb)               \
224   do{ int bz = abs((bb)->a123.ijk[2])-1 ;  \
225       (iq)->vinfo->xhairs_ndown.ijk[bz] =  \
226        (iq)->vinfo->xhairs_nup.ijk[bz]   = \
227         (iq)->vinfo->xhairs_nskip.ijk[bz] = 0 ; } while(0)
228 
229 /* 31 Dec 1998: mask for xhairs orientations */
230 
231 #define ORIMASK_LR ((1<<ORI_R2L_TYPE) | (1<<ORI_L2R_TYPE))
232 #define ORIMASK_AP ((1<<ORI_P2A_TYPE) | (1<<ORI_A2P_TYPE))
233 #define ORIMASK_IS ((1<<ORI_I2S_TYPE) | (1<<ORI_S2I_TYPE))
234 
235 #define ORIMASK_LR_AP (ORIMASK_LR | ORIMASK_AP)
236 #define ORIMASK_LR_IS (ORIMASK_LR | ORIMASK_IS)
237 #define ORIMASK_AP_IS (ORIMASK_AP | ORIMASK_IS)
238 #define ORIMASK_ALL   (ORIMASK_LR | ORIMASK_AP | ORIMASK_IS)
239 
240 /*-- callbacks to receive various kinds of transactions --*/
241 
242 /* whys for input to the receiver routine */
243 
244 #define RECEIVE_POINTS         101
245 #define RECEIVE_VIEWPOINT      102
246 #define RECEIVE_OVERLAY        103
247 #define RECEIVE_CLOSURE        104
248 #define RECEIVE_ALTERATION     105
249 #define RECEIVE_DRAWNOTICE     106  /* 30 Mar 1999 */
250 #define RECEIVE_DSETCHANGE     107  /* 31 Mar 1999 */
251 #define RECEIVE_TTATLAS        108  /* 12 Jul 2001 */
252 #define RECEIVE_REDISPLAY      109  /* 04 Mar 2002 */
253 #define RECEIVE_FUNCDISPLAY    110  /* 04 Mar 2002 */
254 #define RECEIVE_TIMEINDEX      111  /* 29 Jan 2003 */
255 
256 #define RECEIVE_BASEVAL        101
257 #define RECEIVE_LASTVAL        111
258 #define RECEIVE_NUMVAL         (RECEIVE_LASTVAL-RECEIVE_BASEVAL+1)
259 
260 typedef struct {                             /* 29 Mar 1999 */
261       gen_func * receiver_func ;
262       void *     receiver_data ;
263       int        receiver_mask ;
264       char *     receiver_funcname ;         /* 20 Feb 2003 */
265       int        last_when[RECEIVE_NUMVAL] ; /* 08 Sep 2009 */
266 } AFNI_receiver ;
267 
268 typedef struct {
269       int   i1 , j2 , k3 ;  /* integer coordinates of current point */
270       float xi , yj , zk ;  /* float (DICOM mm) coordinates (take priority) */
271 
272       int   i1_old , j2_old , k3_old ;  /* for jumpback */
273 
274       RwcBoolean   xhairs_show_montage , xhairs_periodic , xhairs_all ;
275       THD_ivec3 xhairs_ndown , xhairs_nup , xhairs_nskip ; /* montage crosshairs */
276       int       time_index , top_index , time_on ;
277 
278       int xhairs_orimask ;    /* 31 Dec 1998 */
279 
280       int       anat_index , fim_index , thr_index ; /* 30 Nov 1997 */
281 
282       RwcBoolean crosshair_visible , inverted_pause ;
283       int     crosshair_gap , crosshair_ovcolor , crosshair_gap_old ;
284 
285       int view_type     ,  /* one of the VIEW_ constants in 3ddata.h */
286           underlay_type ;  /* one of the UNDERLAY_ constants above */
287 
288       int sess_num , anat_num , func_num ;  /* codes pointing to datasets */
289 
290       XmString old_crosshair_label ;
291 
292       RwcBoolean    func_visible , force_anat_wod , force_func_wod ,
293                  pts_visible , show_voxind ;
294       int        func_visible_count , func_init_subbricks ;
295       float      func_threshold , resam_vox ;
296       float      func_thresh_top ;              /* 23 Jul 1997 */
297       int        func_resam_mode , anat_resam_mode , pts_color ;
298       int        thr_resam_mode ;               /* 09 Dec 1997 */
299       int        thr_onoff ;                    /* 28 Jun 2007 */
300       int        thr_olayx ;                    /* 13 Aug 2010 */
301       int        thr_sign ;                     /* 08 Aug 2007 */
302       int        thr_use_alpha ;                /* 08 Dec 2014 */
303       float      thr_alpha_floor ;              /* 09 Dec 2014 */ /* == 0 for now */
304       int        thr_use_boxed ;                /* 02 Nov 2018 */
305 
306       /* 3/24/95: range data for conversion of pbar
307                   values to thresholding values in the data */
308 
309       RwcBoolean  use_autorange , use_posfunc ;
310       float    fim_autorange , fim_range ;
311       XmString old_range_label , autorange_label ;
312 
313       char     anat_val[32] , func_val[32] , thr_val[32] ;
314 
315       /** Feb 1998: stuff for the "receive" modules **/
316       /** Mar 1999: modified to allow for more than one receiver **/
317 
318       AFNI_receiver **receiver ;
319       int             num_receiver ;
320       int             drawing_enabled , drawing_mode ;
321       Pixel           drawing_pixel ;
322 
323       int writeownsize ; /* 01 Aug 1999 */
324 
325       int tempflag ;     /* 15 Mar 2000: for quick communication of state */
326 
327       int see_ttatlas ;  /* 25 Jul 2001 */
328 
329       int view_setter ;  /* 20 Feb 2003 */
330 
331       float func_pval ;  /* 06 Feb 2004 */
332       float func_qval ;  /* 23 Jan 2008 */
333 
334       int   fix_pval   , fix_qval   ;  /* 27 Feb 2014 */
335       float fixed_pval , fixed_qval ;
336 
337       int stats_anat_ok,     /* 29 Mar 2005: set in AFNI_range_label() */
338           stats_func_ok,     /*   to indicate if the sub-brick range  */
339           arang_func_ok,     /*   statistics are loaded properly     */
340           stats_thresh_ok ;
341 
342       int   i1_icor , j2_icor , k3_icor;  /* for InstaCorr -- 08 May 2009 */
343       float xi_icor , yj_icor , zk_icor ; /* DICOM coords -- 17 Mar 2010 */
344 
345       float *th_sort;  /* sorted values of overlay threshold */
346       int N_th_sort; /* number of values stored in th_sort */
347       char  th_sortid[256]; /* indentifier of provenance of th_sort */
348 
349       int clusterize_nnlev , clusterize_size , clusterize_bisid ;
350 } AFNI_view_info ;
351 
352 #define AXIAL    1       /* 20 Feb 2003: view_setter codes */
353 #define SAGITTAL 2
354 #define CORONAL  3
355 
356 #undef USE_WRITEOWNSIZE  /* 01 Aug 1999 */
357 
358 #define SAVE_VPT(iqq)                           \
359    ( (iqq)->vinfo->i1_old = (iqq)->vinfo->i1 ,  \
360      (iqq)->vinfo->j2_old = (iqq)->vinfo->j2 ,  \
361      (iqq)->vinfo->k3_old = (iqq)->vinfo->k3  )
362 
363 #define WARPED_VIEW(vvv)  ((vvv)+1)
364 #define ISVALID_VIEW(vvv) ((vvv) >= FIRST_VIEW_TYPE && (vvv) <= LAST_VIEW_TYPE)
365 
366 /*-----------------------------------------------------------*/
367 
368 #define MAXOVSIZE 19
369 #define MAXOVPIX  (MAXOVSIZE*(MAXOVSIZE-1))
370 typedef struct {
371       int numpix ;
372       short dx[MAXOVPIX] , dy[MAXOVPIX] ;
373 } AFNI_ovtemplate ;
374 
375 /*-------------------------------------------------------------------*/
376 /*--------------- define display control widgets --------------------*/
377 
378 #define BKGD_COUNT 3
379 #define INIT_BKGD_LAB(iq) \
380    do{ int qq = ((iq)->s123!=NULL) + ((iq)->s231!=NULL) + ((iq)->s312!=NULL); \
381        if( qq >= BKGD_COUNT || (qq > 0 && !AFNI_noenv("AFNI_VALUE_LABEL")) ){ \
382           (iq)->vwid->imag->do_bkgd_lab = True ;                              \
383        } else {                                                               \
384           (iq)->vwid->imag->do_bkgd_lab = False ;                             \
385           XtUnmanageChild(im3d->vwid->imag->pop_bkgd_lab) ;                   \
386           XtUnmanageChild(im3d->vwid->func->bkgd_lab) ;                       \
387           FIX_SCALE_SIZE(im3d) ;                                              \
388        } break ; } while(0)
389 
390 #define AFNI_XHAIRS_OFF    0
391 #define AFNI_XHAIRS_SINGLE 1
392 #define AFNI_XHAIRS_MULTI  2
393 
394 #define AFNI_XHAIRS_LR_AP  3  /* 31 Dec 1998 */
395 #define AFNI_XHAIRS_LR_IS  4
396 #define AFNI_XHAIRS_AP_IS  5
397 #define AFNI_XHAIRS_LR     6
398 #define AFNI_XHAIRS_AP     7
399 #define AFNI_XHAIRS_IS     8
400 
401 #define AFNI_XHAIRS_LASTOPTION 8
402 
403 #define AFNI_HAVE_WAMI_WIDGET(im3d) \
404    ( ( im3d && im3d->vwid && im3d->vwid->imag && \
405        (im3d->vwid->imag->pop_whereami_twin ||  \
406         im3d->vwid->imag->pop_whereami_htmlwin) ) ? 1 : 0 )
407 
408 typedef struct {
409       Widget frame , rowcol ;
410       Widget topper , popmenu , pop_bkgd_lab ,
411              pop_jumpback_pb , pop_imageonly_pb , pop_jumpto_pb , pop_talto_pb ;
412       Widget pop_jumpto_ijk_pb ;
413       Widget pop_jumpto_ijk_olay_pb ;                               /* 20 Apr 2016 */
414       Widget pop_jumpto_clus_pb ;                                   /* 19 Oct 2012 */
415 
416       Widget crosshair_frame , crosshair_rowcol , crosshair_label ;
417 
418       Widget crosshair_menu, crosshair_dicom_pb, crosshair_spm_pb ; /* 12 Mar 2004 */
419       Widget crosshair_ijk_pb ;                                     /* 04 Oct 2010 */
420       Widget crosshair_jtxyz_pb , crosshair_jtijk_pb ;              /* 01 Aug 2011 */
421       Widget crosshair_jtijk_olay_pb ;                              /* 20 Apr 2016 */
422 
423       Widget        xhair_rowcol ;
424       MCW_arrowval *crosshair_av ;
425       MCW_bbox     *xhall_bbox ;
426 
427       MCW_arrowval *crosshair_color_av ;
428       MCW_arrowval *time_index_av ;
429 
430       Widget        gap_wrap_rowcol ;
431       MCW_arrowval *crosshair_gap_av ;
432       MCW_bbox     *wrap_bbox ;
433 
434       Widget view_frame , view_rowcol ,
435              xyz_rowcol   , yzx_rowcol   , zxy_rowcol   ,
436              name_xyz_lab , name_yzx_lab , name_zxy_lab ,   /* xyz = Axial    */
437              image_xyz_pb , image_yzx_pb , image_zxy_pb ,   /* yzx = Sagittal */
438              graph_xyz_pb , graph_yzx_pb , graph_zxy_pb  ;  /* zxy = Coronal  */
439 
440       RwcBoolean do_bkgd_lab ;
441 
442       Widget pop_whereami_pb , pop_ttren_pb ;
443       MCW_textwin *pop_whereami_twin ;
444       MCW_htmlwin *pop_whereami_htmlwin ;
445 
446       Widget pop_sumato_pb ;
447       Widget pop_mnito_pb ;  /* 01 May 2002 */
448 
449       Widget pop_environment_pb ; /* 05 Nov 2003 */
450       Widget pop_drawdataset_pb ; /* 17 May 2005 */
451 
452       Widget pop_instacorr_pb ;   /* 06 May 2009 */
453       Widget pop_icorrjump_pb ;
454       Widget pop_icorrapair_pb;   /* Apr 2013 */
455       Widget pop_icorramirr_pb;
456 } AFNI_imaging_widgets ;
457 
458 /*--- 19 Aug 2002: Switch Surface control box ---*/
459 
460 typedef struct {
461       Widget wtop , rowcol , top_lab , done_pb ;
462       int nrow , nall ;
463       Widget *surf_rc ;
464       MCW_bbox **surf_bbox ;                       /* 19 Feb 2003 */
465       MCW_arrowval **surf_node_av, **surf_line_av ;
466       MCW_arrowval **surf_ledg_av ;                /* 26 Feb 2003 */
467       MCW_arrowval *boxsize_av , *linewidth_av ;   /* 23 Feb 2003 */
468 } AFNI_surface_widgets ;
469 
470 /*---*/
471 
472 #define MAX_CLU_AUXDSET 4   /* 19 Oct 2015 */
473 
474 #define CLU_CLEAR_AUXDSET(ccww)                   \
475   do{ int ww ;                                    \
476       if( (ccww) != NULL ){                       \
477         for( ww=0 ; ww < MAX_CLU_AUXDSET ; ww++ ) \
478           (ccww)->auxdset[ww] = NULL ;            \
479       }                                           \
480   } while(0)
481 
482 typedef struct {
483   Widget wtop, rowcol;      /* containers */
484   Widget top_lab;           /* overall report text */
485   Widget top_menu , histrange_pb ;
486   MCW_bbox *save_as_mask_bbox ; /* 16 Jun 2014 */
487   MCW_bbox *histsqrt_bbox ;
488   MCW_bbox *spearman_bbox ; /* 02 Jan 2013 */
489   MCW_bbox *despike_bbox ;  /* 26 Oct 2015 */
490   MCW_bbox *detrend_bbox  ; /* 14 May 2015 */
491   MCW_bbox *ebar_bbox ;     /* 26 Oct 2015 */
492 
493   MCW_bbox *usemask_bbox ;       /* zero-th row of controls [01 Aug 2011] */
494   Widget linkrbrain_pb;          /* 21 Jan 2014 */
495   MCW_arrowval *linkrbrain_av;   /* 31 Mar 2014 */
496 
497   MCW_arrowval *cmode_av ;       /* first row of controls */
498   Widget clust3d_pb, savetable_pb, index_lab, prefix_tf, done_pb ;
499   Widget savemask_pb ;           /* 01 May 2008 */
500   Widget whermask_pb ;           /* 04 Aug 2010 */
501 
502   Widget        auxdset_arrow ;
503   Widget        auxdset_master_rowcol ;
504 
505   MCW_bbox     *auxdset_bbox   [MAX_CLU_AUXDSET] ;  /* Aux Dataset rows */
506   Widget        auxdset_pb     [MAX_CLU_AUXDSET] ;
507   MCW_arrowval *auxdset_from_av[MAX_CLU_AUXDSET] ;
508   MCW_arrowval *auxdset_to_av  [MAX_CLU_AUXDSET] ;
509   MCW_arrowval *auxdset_clr_av [MAX_CLU_AUXDSET] ;
510   Widget        auxdset_namlab [MAX_CLU_AUXDSET] ;
511 
512   MCW_arrowval *aver_av ;                   /* row after Aux Dataset rows */
513   Widget        splot_pb , splot_clear_pb ;
514   Widget        auxdset_lab ;
515 
516   Widget clusters_lab ;     /* label at top of clusters table */
517   int nrow, nall, is_open ;
518   Widget *clu_rc ;          /* rows of widgets */
519   MCW_bbox **clu_see_bbox ; /* 14 Oct 2015 */
520   Widget *clu_lab ;
521   Widget *clu_jump_pb ;
522   Widget *clu_plot_pb ;
523   Widget *clu_save_pb ;
524   Widget *clu_flsh_pb ;
525   Widget *clu_writ_pb ;   /* 08 Dec 2015 */
526   Widget *clu_alph_lab ;
527 
528   THD_3dim_dataset *auxdset[MAX_CLU_AUXDSET] ;  /* selected from auxdset_pb */
529   MRI_IMAGE *splotim ;                          /* selected from splot_pb */
530   int coord_mode ;
531   int receive_on ;
532   int save_as_mask ;
533   float hbot,htop ;
534 
535   int linkrbrain_nclu ;     /* 09 Sep 2015 */
536 
537 } AFNI_clu_widgets ;      /** not yet used **/
538 
539 extern void CLU_free_table( CLU_threshtable *ctab ) ;
540 
541 /*---*/
542 
543 typedef struct {
544   Widget        rc ;
545   MCW_bbox     *tog_bbox ;
546   MCW_arrowval *menu_av ;
547   Widget        chooser_pb ;
548   MCW_arrowval *index_av ;
549   Widget        chooser_lab ;
550   Widget        string_lab ;
551   Widget        string_text ;
552 } ICALC_widget_row ;
553 
554 typedef struct {
555   Widget wtop, rowcol ;  /* top level containers */
556 
557   Widget actar ;         /* action area holding control buttons */
558 
559   Widget olay_expr_text ;
560 
561   ICALC_widget_row  war[26] ;
562   void             *var[26] ;
563 
564   int is_open ;
565   struct Three_D_View *im3d ;
566 } ICALC_widget_set ;
567 
568 typedef struct {
569    int is_good ; char *prefix ;
570 
571    char *olay_expr ;
572    void *olay_pcode ;
573    THD_3dim_dataset *dset_master ;
574    char *value_string ;
575 
576    int               intyp[26] ;
577    THD_3dim_dataset *inset[26] ; int inidx[26] ;
578    double            inval[26] ;
579 
580    int dshift_mode , cxcode ;
581    int dshift  [26] ;
582    int dshift_i[26] ;
583    int dshift_j[26] ;
584    int dshift_k[26] ;
585    int dshift_l[26] ;
586    int has_sym[26] , has_predefined, has_xyz, mangle_xyz ;
587 } ICALC_setup ;
588 
589 #undef  INIT_ICALC_setup
590 #define INIT_ICALC_setup(qcs)                                \
591  do{ int qx ;                                                \
592      (qcs) = (ICALC_setup *)calloc(1,sizeof(ICALC_setup)) ;  \
593      for( qx=0 ; qx < 26 ; qx++ ) (qcs)->intyp[qx] = -666 ;  \
594  } while(0)
595 
596 /* the following macro is unused (as yet) */
597 
598 #undef  DESTROY_ICALC_setup
599 #define DESTROY_ICALC_setup(qcs)     \
600  do{ if( (qcs) != NULL ){            \
601        free((qcs)) ; (qcs) = NULL ;  \
602  }} while(0)
603 
604 /*---*/
605 
606 #include "gicor.h"   /* ZSS Jan 2010 */
607 
608 /*---*/
609 
610 typedef struct {
611       Widget    frame , rowcol ;
612       MCW_bbox *view_bbox ;
613 
614       Widget    marks_frame , marks_rowcol ;
615       Widget    define_marks_pb ;
616       MCW_bbox *see_marks_bbox ;
617       int       marks_enabled ;
618 
619       Widget    func_frame , func_rowcol ;
620       Widget    define_func_pb ;
621       MCW_bbox *see_func_bbox ;
622 
623       Widget    define_dmode_pb ;
624 
625       Widget dataset_frame     , dataset_rowcol    ,
626              choose_anat_pb    , choose_func_pb    ,
627              popchoose_sess_pb , popchoose_anat_pb , popchoose_func_pb ;
628 
629       Widget choose_rowcol , rescan_pb, nimlpo_pb ;                    /* 02 Feb 2007 */
630       Widget session_rowcol, sess_lab , choose_sess_pb, read_sess_pb ; /* 03 Dec 2009 */
631       int    session_horz ;                                            /* 29 Apr 2010 */
632 
633       RwcBoolean marks_pb_inverted , func_pb_inverted , dmode_pb_inverted ;
634 
635       Widget choose_surf_pb ;  /* 19 Aug 2002 */
636       AFNI_surface_widgets *swid ;
637 } AFNI_viewing_widgets ;
638 
639 extern void AFNI_sesslab_EV( Widget, XtPointer, XEvent *, RwcBoolean * ) ; /* 30 Apr 2010 */
640 
641 extern void flush_vinfo_sort(AFNI_view_info *vinfo, char *sel);/*ZSS: 04/26/12*/
642 extern void flush_3Dview_sort(struct Three_D_View *im3d, char *sel);
643 extern float *get_3Dview_sort(struct Three_D_View *im3d, char *sel);
644 extern float  get_3Dview_func_thresh(struct Three_D_View *im3d,
645                                      int apply_power);
646 extern float AFNI_thresh_from_percentile(struct Three_D_View *im3d, float perc);
647 
648 extern void reset_mnito(struct Three_D_View *im3d);
649 
650 #define OPEN_PANEL(iq,panel)                                              \
651    {  XtManageChild( (iq)->vwid->  panel  ->frame ) ;                     \
652       if( ! (iq)->vwid->view->  panel ## _pb_inverted ){                  \
653          MCW_invert_widget( (iq)->vwid->view->define_ ## panel ## _pb ) ; \
654          (iq)->vwid->view->  panel ## _pb_inverted = True ;               \
655          (iq)->vwid->func->inten_pbar->update_me = 2 ;                    \
656          update_MCW_pbar((iq)->vwid->func->inten_pbar) ; }                \
657       XMapRaised( XtDisplay( (iq)->vwid->  panel  ->frame ) ,             \
658                    XtWindow( (iq)->vwid->  panel  ->frame )  ) ;          \
659       FIX_SCALE_SIZE(iq) ; }
660 
661 #define CLOSE_PANEL(iq,panel)                                             \
662    {  XtUnmanageChild( (iq)->vwid->  panel  ->frame ) ;                   \
663       FIX_TOPFORM_HEIGHT(iq) ; HIDE_SCALE(iq) ; FIX_SCALE_SIZE(iq) ;      \
664       if( (iq)->vwid->view->  panel ## _pb_inverted ){                    \
665          MCW_invert_widget( (iq)->vwid->view->define_ ## panel ## _pb ) ; \
666          (iq)->vwid->view->  panel ## _pb_inverted = False ; } }
667 
668 /*---*/
669 
670 #define MARKS_MAXPOP (MARKS_MAXNUM+10)
671 
672 typedef struct {
673       Widget  frame , rowcol ;
674 
675       Widget  tog_frame , tog_rowcol , tog_topper ;
676       Widget  tog[MARKS_MAXNUM] ;
677       Widget  poptog[MARKS_MAXNUM] ;
678       Widget  always_popup[MARKS_MAXPOP] ,
679               sometimes_popup[MARKS_MAXPOP] ;
680       int     num_always_popup , num_sometimes_popup ;
681       RwcBoolean inverted[MARKS_MAXNUM] , editable ;
682 
683       Widget         control_frame , control_rowcol ;
684       MCW_bbox *     edits_bbox ;
685       Widget         disp_frame     , disp_rowcol ;
686       MCW_arrowval * disp_pcolor_av , * disp_scolor_av ,
687                    * disp_size_av   , * disp_gap_av ;
688       Widget         action_rowcol  ,
689                      action_set_pb  , action_clear_pb ,
690                      action_quality_pb ,
691                      pop_set_pb     , pop_clear_pb ;
692 
693       Widget         transform_pb ;
694 
695       MCW_bbox *     tlrc_big_bbox ;
696       AFNI_ovtemplate ov_mask ;
697 
698       int     ov_pcolor , ov_scolor , ov_size , ov_gap ;
699       RwcBoolean ov_visible , old_visible ;
700 
701       char tog_help[MARKS_MAXNUM][MARKS_MAXHELP] ;
702 
703       RwcBoolean isprimary[MARKS_MAXNUM] ;
704       RwcBoolean changed ;
705 
706       RwcBoolean tag_visible ;   /* 23 Oct 1998 */
707 } AFNI_marks_widgets ;
708 
709 /*---*/
710 
711 #define THR_PVAL_LABEL_NONE " [N/A] "
712 
713 #if 0
714 #define THR_TOP_EXPON  4         /* 30 Nov 1997 */
715 #define THR_FACTOR     0.0001    /* pow(10,-THR_TOP_EXPON) */
716 #define THR_TOP_VALUE  9999.0    /* pow(10,THR_TOP_EXPON)-1 */
717 #endif
718 
719 #ifdef MAIN
720 int   THR_top_expon = 4       ;
721 float THR_factor    = 0.0001f ;
722 float THR_top_value = 9999.0f ;
723 #else
724 extern int   THR_top_expon ;
725 extern float THR_factor    ;
726 extern float THR_top_value ;
727 #endif
728 
729 #undef USE_FUNC_FIM              /* 09 Dec 1997 */
730 
731 #undef USE_UNDERLAY_BBOX         /* 18 Jun 2014 */
732 
733 typedef struct {
734       Widget frame , rowcol ;
735 
736       Widget thr_rowcol , thr_label , thr_scale , thr_pval_label ;
737       MCW_arrowval *thr_top_av ;
738 
739       Widget thrtop_rowcol , thrtop_alpha_pb , thrtop_boxed_pb ; /* 02 Nov 2018 */
740 
741       Widget thr_menu ;
742       MCW_bbox *thr_onoff_bbox ;
743       MCW_bbox *thr_olayx_bbox ;
744       Widget thr_autothresh_pb ;
745       Widget thr_setthresh_pb ;    /* 16 Jul 2020 discoraj */
746       Widget thr_setpval_pb ;      /* 03 Dec 2013 */
747       Widget thr_setqval_pb ;      /* 26 Feb 2014 */
748       Widget thr_setpval_001_pb ;  /* 05 Nov 2018 */
749       MCW_arrowval *thr_sign_av ;  /* 08 Aug 2007 */
750       MCW_arrowval *thr_alpha_av;  /* 08 Dec 2014 */ /* restored 28 Jun 2021 */
751 #if 0
752       MCW_arrowval *thr_floor_av;  /* 09 Dec 2014 */ /* disabled */
753 #endif
754       Widget thr_fdr_pb ;          /* 29 Jan 2008 */
755       Widget thr_pvalue_pb ;       /* 06 Mar 2014 */
756 
757       Widget inten_rowcol , inten_label ;
758       MCW_pbar     *inten_pbar ;
759       MCW_arrowval *inten_av ;
760       MCW_bbox     *inten_bbox ;
761 
762       Widget pbar_menu , pbar_equalize_pb , pbar_settop_pb ,
763              pbar_readin_pb , pbar_writeout_pb ;
764       MCW_arrowval *pbar_palette_av ;
765       Widget pbar_showtable_pb ;
766       Widget pbar_environment_pb ; /* 10 Feb 2004 */
767       Widget pbar_setrange_1_pb ;  /* 16 Nov 2018 */
768 
769       Widget pbar_saveim_pb  ;                  /* 15 Jun 2000 */
770       MCW_arrowval *pbar_transform0D_av ;
771       generic_func *pbar_transform0D_func ;
772       int           pbar_transform0D_index ;
773       MCW_arrowval *pbar_transform2D_av ;
774       generic_func *pbar_transform2D_func ;
775       int           pbar_transform2D_index ;
776       Widget        pbar_flip_pb ;              /* 08 Feb 2012 */
777       Widget        pbar_jumpto_thmax_pb ;      /* 21 Jul 2014 */
778       Widget        pbar_jumpto_thmin_pb ;
779 
780       Widget options_rowcol , options_top_rowcol , options_label ;
781       MCW_arrowval *options_vedit_av ;
782       Widget ulaclu_rowcol , vedit_frame ;
783       MCW_bbox     *underlay_bbox ;
784       Widget clu_rowcol, clu_clear_pb, clu_cluster_pb, clu_report_pb ;  /* 05 Sep 2006 */
785 
786       Widget icor_rowcol  , icor_pb  , icor_label  ; /* 05 May 2009 */
787 
788       Widget icalc_rowcol , icalc_pb , icalc_label ; /* 18 Sep 2009 */
789 
790       Widget gicor_rowcol , gicor_pb , gicor_label ; /* 22 Dec 2009 */
791 
792       Widget tstat_rowcol , tstat_pb , tstat_label ; /* 22 Mar 2018 */
793 
794       Widget        buck_frame , buck_rowcol ;
795       MCW_arrowval *anat_buck_av , *fim_buck_av , *thr_buck_av ;  /* 30 Nov 1997 */
796 
797       Widget range_frame , range_rowcol , range_label ;
798       MCW_bbox     *range_bbox ;
799       MCW_bbox     *perc_bbox ;
800       MCW_arrowval *range_av ;
801 
802 #ifdef USE_FUNC_FIM
803       Widget fim_frame , fim_rowcol , fim_dset_label , fim_mbar ;
804       FIM_menu *fim_menu ;
805 #endif
806 
807       Widget bkgd_lab ;
808 
809       MCW_arrowval *range_rotate_av ;  /* 30 Mar 2001 */
810       Widget pbar_flip_pb2 ;           /* 08 Feb 2012 */
811 
812       MCW_bbox *see_ttatlas_bbox ;     /* 25 Jul 2001 */
813 
814       AFNI_clu_widgets   *cwid ;       /* 18 Dec 2007 */
815       char               *clu_rep ;
816       MCW_cluster_array  *clu_list;
817       int                 clu_index;
818       int                 clu_num ;
819       mri_cluster_detail *clu_det ;
820       CLU_threshtable *clu_tabNN1_1sid, *clu_tabNN2_1sid, *clu_tabNN3_1sid ; /* Jan 2015 */
821       CLU_threshtable *clu_tabNN1_2sid, *clu_tabNN2_2sid, *clu_tabNN3_2sid ;
822       CLU_threshtable *clu_tabNN1_bsid, *clu_tabNN2_bsid, *clu_tabNN3_bsid ;
823       byte *clu_mask ;
824       int clu_nnlev ;
825 
826       ICALC_widget_set   *iwid ;       /* 17 Sep 2009 */
827 
828       int do_setup ;                   /* 24 May 2019 */
829 } AFNI_function_widgets ;
830 
831 extern void AFNI_func_autothresh_CB(Widget,XtPointer,XtPointer) ; /* 25 Jul 2007 */
832 extern void AFNI_func_setthresh_CB   (Widget,XtPointer,XtPointer) ; /* 16 Jul 2020 discoraj */
833 extern void AFNI_func_setpval_CB   (Widget,XtPointer,XtPointer) ; /* 03 Dec 2013 */
834 extern void AFNI_func_setqval_CB   (Widget,XtPointer,XtPointer) ; /* 03 Dec 2013 */
835 extern void AFNI_func_thrsign_CB( MCW_arrowval * , XtPointer ) ;  /* 08 Aug 2007 */
836 extern void AFNI_func_alpha_CB  ( MCW_arrowval * , XtPointer ) ;  /* 08 Dec 2014 */
837 extern void AFNI_func_floor_CB  ( MCW_arrowval * , XtPointer ) ;  /* 09 Dec 2014 */
838 extern void AFNI_func_fdr_CB    (Widget,XtPointer,XtPointer) ;    /* 29 Jan 2008 */
839 extern void AFNI_func_thrtop_CB (Widget,XtPointer,XtPointer) ;    /* 02 Nov 2018 */
840 extern void AFNI_func_setpval_001_CB(Widget,XtPointer,XtPointer); /* 05 Nov 2018 */
841 
842 extern void AFNI_set_pval( struct Three_D_View * , float ) ;      /* 27 Feb 2014 */
843 extern void AFNI_set_qval( struct Three_D_View * , float ) ;      /* 27 Feb 2014 */
844 
845 #define PBAR_MODEBUT  0
846 #define PBAR_MODEPOS  (1 << PBAR_MODEBUT)
847 
848 #define RANGE_AUTOBUT 0
849 #define RANGE_AUTOVAL (1 << RANGE_AUTOBUT)
850 
851 #define PERC_AUTOBUT 0  /* ZSS: April 27 2012 */
852 
853 /* fix for a bug on Solaris */
854 
855 #ifdef FIX_SCALE_VALUE_PROBLEM
856 #  define BOXUP_SCALE
857 #  define FIX_SCALE_VALUE(iqqq)                                                    \
858    do { char buf[16] ; float th = (iqqq)->vinfo->func_threshold ;                  \
859         if( ISVALID_3DIM_DATASET((iqqq)->fim_now) &&                               \
860             FUNC_HAVE_THR((iqqq)->fim_now->func_type) ){                           \
861                                                                                    \
862           th *= (iqqq)->vinfo->func_thresh_top ;                                   \
863              if( th <   1.0 ) sprintf(buf,"%4.2f",th) ;                            \
864         else if( th <  10.0 ) sprintf(buf,"%4.1f",th) ;                            \
865         else                  sprintf(buf,"%4.0f",th) ;                            \
866         XtVaSetValues( (iqqq)->vwid->func->thr_label , LABEL_ARG(buf+1) , NULL ) ; \
867         MCW_expose_widget( (iqqq)->vwid->func->thr_label ) ; } } while(0)
868 #else
869 #  define FIX_SCALE_VALUE(iqqq) /* nada */
870 #endif
871 
872 typedef struct {
873       Widget frame , rowcol ;
874 
875       MCW_bbox     * anatmode_bbox , * funcmode_bbox ;
876       MCW_arrowval * anat_resam_av , * resam_vox_av ;
877       MCW_arrowval * func_resam_av ;                   /* moved here 03 Nov 1996 */
878       MCW_arrowval * thr_resam_av ;                    /* 09 Dec 1997 */
879       Widget         write_rowcol , write_anat_pb , write_func_pb , write_many_pb ;
880       Widget         rescan_rowcol , rescan_pb , rescan_all_pb , rescan_timeseries_pb ;
881       Widget         read_rowcol , read_sess_pb , read_1D_pb , read_Web_pb ;
882 
883       Widget         saveas_rowcol, saveas_anat_pb, saveas_func_pb ; /* 18 Oct 2010 */
884 
885       Widget         mbar_rowcol ;
886       MCW_bbox     * lock_bbox ;
887       Widget         lock_enforce_pb , lock_clear_pb , lock_setall_pb ;
888 
889       Widget         misc_voxind_pb ;
890       Widget         misc_hints_pb ;
891       Widget         misc_anat_info_pb , misc_func_info_pb ;
892       Widget         misc_vcheck_pb, misc_purge_pb, misc_tracing_pb,
893                      misc_showmalloc_pb , misc_dumpmalloc_pb ;
894 
895       MCW_bbox     * time_lock_bbox ;    /* 03 Nov 1998 */
896       MCW_bbox     * zoompan_lock_bbox ; /* 10 Dec 2019 */
897 
898       Widget         misc_writeownsize_pb ;   /* 01 Aug 1999 */
899       MCW_bbox     * misc_writeownsize_bbox ;
900 
901       MCW_bbox     * misc_voxind_bbox , * misc_hints_bbox ; /* 01 Aug 1999 */
902 
903 #ifdef ALLOW_PLUGINS
904       Widget         misc_environ_pb ;  /* 20 Jun 2000 */
905       Widget         misc_2dchain_pb ;  /* 03 Jul 2000 */
906       Widget         misc_1dchain_pb ;  /* 07 Aug 2001 */
907 #endif
908 
909       MCW_bbox     * thr_lock_bbox ;    /* 16 Nov 2011 */
910       MCW_bbox     * rng_lock_bbox ;    /* 04 Jun 2014 */
911       MCW_bbox     * pbar_lock_bbox;    /* 04 Jun 2014 */
912       MCW_bbox     * ijk_lock_bbox ;    /* 11 Sep 2000 */
913 
914       Widget         misc_savelayout_pb ; /* 23 Sep 2000 */
915       Widget         misc_license_pb ;    /* 03 Dec 2000 */
916       Widget         misc_plugout_pb ;    /* 07 Nov 2001 */
917       Widget         misc_niml_pb    ;    /* 02 Mar 2002 */
918       Widget         misc_runscript_pb ;  /* 22 Jan 2003 */
919 
920       Widget         misc_readme_env_pb ; /* 05 Aug 2004 */
921       Widget         misc_pvalue_pb ;     /* 06 Mar 2014 */
922 
923       Widget         misc_motd_pb ;       /* 29 Nov 2005 */
924       Widget         misc_hist_pb ;       /* 05 Mar 2008 */
925 
926 } AFNI_datamode_widgets ;
927 
928 /*---*/
929 
930 #define USE_HIDDEN
931 
932 typedef struct {
933    Widget frame , rowcol ;
934 
935    Widget  rc_top , clone_pb , panel_pb ;
936    Widget  rc_bot , button_help_pb , quit_pb ;
937    RwcBoolean quit_first , panel_pb_inverted ;
938 
939 #ifdef USE_HIDDEN
940 
941    /** May 1995: hidden popup widgets **/
942 
943    Widget hidden_menu ,
944             hidden_pts_cbut , hidden_pts_menu ,
945             hidden_readpts_ijk_pb , hidden_readpts_xyz_pb ,
946             hidden_writepts_ijk_pb , hidden_writepts_xyz_pb ,
947             hidden_colorpts_pb ;
948 
949    Widget hidden_sonnet_pb ;
950 
951 #define PTS_READ_IJK   7
952 #define PTS_READ_XYZ   8
953 #define PTS_WRITE_IJK  9
954 #define PTS_WRITE_XYZ 10
955 #define PTS_SET_COLOR 11
956 
957    int    hidden_code ;
958 
959    Widget hidden_mission_pb ;  /* 06 Jun 2001 */
960    Widget hidden_gamberi_pb ;  /* 14 Oct 2003 */
961    Widget hidden_hbmjust_pb ;  /* 05 Jun 2013 */
962    Widget hidden_ranpoem_pb ;  /* 15 Oct 2003 */
963    Widget hidden_speech_pb  ;  /* 25 Nov 2003 */
964    Widget hidden_faces_pb   ;  /* 17 Dec 2004 */
965    Widget hidden_browser_pb ;  /* 22 Apr 2005 */
966    Widget hidden_broutim_pb ;  /* 06 Jun 2005 */
967    Widget hidden_broutext_pb;  /* 21 Dec 2005 */
968    Widget hidden_splashes_pb;  /* 12 Sep 2007 */
969    Widget hidden_uscon_pb   ;  /* 30 Dec 2010 */
970    Widget hidden_usdecl_pb  ;  /* 06 Jan 2011 */
971    Widget hidden_melter_pb  ;  /* 18 Feb 2011 */
972    Widget hidden_sound_pb   ;  /* 20 Aug 2018 */
973    Widget hidden_music_pb   ;  /* 07 Aug 2019 */
974    Widget hidden_pvalue_pb  ;  /* 06 Mar 2014 */
975    Widget hidden_papers_pb  ;  /* 02 May 2014 */
976 
977 #endif  /* USE_HIDDEN */
978 
979 } AFNI_program_widgets ;
980 
981 /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
982 #ifdef USE_HIDDEN
983 
984 extern void AFNI_hidden_CB    ( Widget , XtPointer , XtPointer );
985 extern void AFNI_hidden_EV    ( Widget , XtPointer , XEvent * , RwcBoolean * ) ;
986 extern void AFNI_hidden_pts_CB( Widget , XtPointer , MCW_choose_cbs * ) ;
987 
988 #ifdef USE_SONNETS
989 extern void AFNI_sonnet_CB    ( Widget , XtPointer , XtPointer );
990 #endif
991 
992 #endif  /* USE_HIDDEN*/
993 /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
994 
995 /*---*/
996 
997 struct PLUGIN_interface ; /* incomplete definition */
998 
999 typedef struct {
1000       Widget top_shell , top_form ;
1001       int top_form_height ;               /* 04 Aug 2016 */
1002 
1003       AFNI_imaging_widgets  * imag ;
1004       AFNI_viewing_widgets  * view ;
1005       AFNI_marks_widgets    * marks ;
1006       AFNI_function_widgets * func ;
1007       AFNI_program_widgets  * prog ;
1008       AFNI_datamode_widgets * dmode ;
1009 
1010       Widget picture ;
1011       int    picture_index ;
1012       Widget tips_pb ;                    /* 27 Jun 2011 */
1013       Widget news_pb ;                    /* 15 May 2019 */
1014       Widget forum_pb ;                   /* 17 May 2019 */
1015       Widget phelp_pb ;
1016       Widget ytube_pb ;                   /* youtube 28 Apr 2020 discoraj */
1017 
1018       Widget file_dialog , file_sbox ;
1019       XtCallbackProc file_cb ;
1020       XtPointer      file_cd ;
1021 
1022 #ifdef ALLOW_PLUGINS
1023       int nplugbut ;                      /* 23 Sep 2000 */
1024       Widget * plugbut ;
1025       char ** pluglab ;
1026       struct PLUGIN_interface ** plugint ;
1027 #endif
1028 
1029       /*--- Pointers to other data ---*/
1030 
1031       XtPointer parent ;
1032 
1033       int butx , buty ;        /* 17 May 2005 */
1034 } AFNI_widget_set ;
1035 
1036 /* Macro to reset size of the top_form in AFNI [04 Aug 2016] */
1037 
1038 #define FIX_TOPFORM_HEIGHT(iq)                                       \
1039  do{ if( (iq)->vwid->top_form_height > 99 )                          \
1040        XtVaSetValues( (iq)->vwid->top_form ,                         \
1041                       XmNheight,(iq)->vwid->top_form_height,NULL ) ; \
1042        XtVaSetValues( (iq)->vwid->top_shell ,                        \
1043                       XmNheight,(iq)->vwid->top_form_height+1,NULL); \
1044  } while(0)
1045 
1046 #define SET_TOPFORM_HEIGHT(iq)                               \
1047      MCW_widget_geom( (iq)->vwid->top_form,                  \
1048                       NULL, &((iq)->vwid->top_form_height),  \
1049                       NULL, NULL )
1050 
1051 #define TIPS_PLUS_SHIFT   2
1052 #define TIPS_MINUS_SHIFT -60
1053 #define TIPS_TOTAL_SHIFT -90
1054 
1055 #define SHIFT_TIPS(iq,xx)                                                 \
1056  do{ if( (iq)->vwid->tips_pb != NULL ){                                   \
1057        XtVaSetValues( (iq)->vwid->tips_pb, XmNleftOffset, (xx), NULL ) ;  \
1058        XMapRaised( XtDisplay( (iq)->vwid->tips_pb) ,                      \
1059                     XtWindow( (iq)->vwid->tips_pb)  ) ;                   \
1060      } } while(0)
1061 
1062 #define SHIFT_NEWS(iq,xx)                                                 \
1063  do{ if( (iq)->vwid->news_pb != NULL ){                                   \
1064        XtVaSetValues( (iq)->vwid->news_pb, XmNleftOffset, (xx), NULL ) ;  \
1065        XMapRaised( XtDisplay( (iq)->vwid->news_pb) ,                      \
1066                     XtWindow( (iq)->vwid->news_pb)  ) ;                   \
1067      } } while(0)
1068 
1069 /** picture controls **/
1070 
1071 #define PICTURE_SET(im,px)                                            \
1072    do{ if( (im)->type == AFNI_3DDATA_VIEW )                           \
1073         XtVaSetValues((im)->vwid->picture,XmNlabelPixmap,(px),NULL ); \
1074    } while(0)
1075 
1076 #define PICTURE_ON(im)   PICTURE_SET(im,logo_pixmap)
1077 #define PICTURE_DEAD(im) PICTURE_SET(im,XmUNSPECIFIED_PIXMAP)
1078 #define PICTURE_OFF(im)  PICTURE_SET(im,pict_pixmap[AFNI_controller_index(im)%NPICT])
1079 
1080 /*-----------------------------*/
1081 /*----- Data for FIM-age ------*/
1082 
1083 #define FIM_ALPHA_MASK  1
1084 #define FIM_BEST_MASK   2
1085 #define FIM_PERC_MASK   4
1086 #define FIM_BASE_MASK   8
1087 #define FIM_CORR_MASK  16
1088 #define FIM_PAVE_MASK  32
1089 #define FIM_AVER_MASK  64
1090 
1091 #define FIM_PTOP_MASK 128  /* these 3 added on 03 Jan 2000 */
1092 #define FIM_TOPL_MASK 256
1093 #define FIM_SIGM_MASK 512
1094 
1095 #define FIM_DEFAULT_MASK (1 | 2 | 4 | 16)
1096 
1097 #define FIM_NUM_OPTS   10
1098 
1099 #ifdef MAIN
1100    char * fim_opt_labels[FIM_NUM_OPTS] = {
1101      "Fit Coef" , "Best Index" , "% Change"    , "Baseline" ,
1102                                  "Correlation" ,
1103                                  "% From Ave"  , "Average"  ,
1104                                  "% From Top"  , "Topline"  ,
1105                                  "Sigma Resid"
1106    } ;
1107 #else
1108    extern char * fim_opt_labels[] ;
1109 #endif
1110 
1111 typedef struct {
1112    MRI_IMAGE *        fimref ;
1113    MRI_IMAGE *        fimort ;   /* 12 Nov 1996 */
1114    THD_3dim_dataset * fimdset ;
1115    int                refadd_count ;
1116    int                init_ignore ;
1117    int                polort ;   /* 27 May 1999 */
1118 } AFNI_fimmer_type ;
1119 
1120 #define MAX_POLORT 3
1121 
1122 #define CLEAR_FIMDATA(iq)                            \
1123    ( (iq)->fimdata->fimref       = NULL ,            \
1124      (iq)->fimdata->fimort       = NULL ,            \
1125      (iq)->fimdata->fimdset      = NULL ,            \
1126      (iq)->fimdata->refadd_count = 0 ,               \
1127      (iq)->fimdata->polort       = INIT_fim_polort , \
1128      (iq)->fimdata->init_ignore  = GLOBAL_argopt.ignore )
1129 
1130 #define USABLE_FIMDATA(iq)                                         \
1131   ( IM3D_OPEN(iq) && (iq)->type == AFNI_3DDATA_VIEW              && \
1132     DSET_GRAPHABLE((iq)->fimdata->fimdset)                        && \
1133     (iq)->fimdata->fimref != NULL                                  && \
1134     (iq)->fimdata->fimref->kind == MRI_float                        && \
1135     (iq)->fimdata->fimref->nx >= DSET_NUM_TIMES((iq)->fimdata->fimdset) )
1136 
1137 #ifdef USE_FUNC_FIM
1138 #  define ALLOW_COMPUTE_FIM(iq)                                           \
1139      do{ XmString xstr ; THD_3dim_dataset * ds = (iq)->fimdata->fimdset ; \
1140          int fim_ok = USABLE_FIMDATA(iq) ,                                \
1141              ds_ok  = DSET_GRAPHABLE((iq)->fimdata->fimdset) ;            \
1142          STATUS("** Setting FIM controls") ;                              \
1143          if( ISVALID_3DIM_DATASET(ds) ){                                  \
1144             STATUS("setting fim string to dataset") ;                     \
1145             xstr = XmStringCreateLtoR(ds->dblk->diskptr->filecode,        \
1146                                     XmFONTLIST_DEFAULT_TAG);              \
1147          } else {                                                         \
1148             STATUS("setting fim string to nothing") ;                     \
1149             xstr = XmStringCreateLtoR("[FIM not set up]",                 \
1150                                     XmFONTLIST_DEFAULT_TAG);              \
1151          }                                                                \
1152          STATUS("setting fim label to fim string") ;                      \
1153          XtVaSetValues( (iq)->vwid->func->fim_dset_label ,                \
1154                            XmNlabelString , xstr , NULL ) ;               \
1155          XmStringFree(xstr) ;                                             \
1156          SENSITIZE((iq)->vwid->func->fim_menu->fim_execute_pb,fim_ok);    \
1157          if( ds_ok ) AFNI_fimmer_fix_optmenu(iq) ;                        \
1158          STATUS("** Done setting FIM controls") ;                         \
1159       } while(0)
1160 #else
1161 #  define ALLOW_COMPUTE_FIM(iq) /* nada */
1162 #endif
1163 
1164 /*-----------------------------------------------------------*/
1165 /*------------- define the central data structure -----------*/
1166 
1167 #define AFNI_NODATA_VIEW 100
1168 #define AFNI_IMAGES_VIEW 101
1169 #define AFNI_3DDATA_VIEW 102
1170 
1171 #define IM0D_VALID(ii) ((ii)!=NULL && (ii)->type==AFNI_NODATA_VIEW)
1172 #define IM3D_VALID(ii) ((ii)!=NULL && ((ii)->type==AFNI_IMAGES_VIEW || \
1173                                        (ii)->type==AFNI_3DDATA_VIEW ) )
1174 
1175 #define IM3D_OPEN(ii)  (IM3D_VALID(ii) && (ii)->opened)
1176 
1177 #define IM3D_HAVEIM(ii) ((ii)->s123 != NULL || (ii)->s231 != NULL || (ii)->s312 != NULL)
1178 #define IM3D_HAVEGR(ii) ((ii)->g123 != NULL || (ii)->g231 != NULL || (ii)->g312 != NULL)
1179 #define IM3D_FUNKY(ii)  (IM3D_OPEN(ii) && IM3D_HAVEIM(ii) && (ii)->vinfo->func_visible)
1180 
1181 #define IM3D_SHFT_CTRL_DRAG(iq)                                \
1182  ( ( (iq)->s123 != NULL && (iq)->s123->shft_ctrl_dragged ) ||  \
1183    ( (iq)->s231 != NULL && (iq)->s231->shft_ctrl_dragged ) ||  \
1184    ( (iq)->s312 != NULL && (iq)->s312->shft_ctrl_dragged )   )
1185 
1186 #define ISVALID_IM3D(ii) IM3D_VALID(ii)
1187 
1188 #define AFNI_IGNORE_NOTHING    0
1189 #define AFNI_IGNORE_REDRAWS    1
1190 #define AFNI_IGNORE_EVERYTHING 2
1191 
1192 typedef struct Three_D_View {
1193       int type , opened ;
1194       MCW_DC *dc ;
1195 
1196       THD_session      *ss_now ;   /* session now being viewed */
1197       THD_3dim_dataset *anat_dset[MAX_LAST_VIEW_TYPE+1] ,   /* datasets now */
1198                        *fim_dset [MAX_LAST_VIEW_TYPE+1]  ;  /* being viewed */
1199       THD_3dim_dataset *anat_now , *fim_now ;  /* REALLY now being viewed */
1200 
1201       AFNI_view_info   *vinfo ;  /* information about what's being viewed */
1202 
1203       AFNI_fimmer_type *fimdata ; /* information about fimming */
1204 
1205       FD_brick  *b123_anat , *b231_anat , *b312_anat ; /* anat */
1206       FD_brick  *b123_fim  , *b231_fim  , *b312_fim  ; /* funcs */
1207       FD_brick  *b123_ulay , *b231_ulay , *b312_ulay ; /* underlays */
1208 
1209       MCW_imseq   *s123    , *s231      , *s312 ;      /* viewers */
1210       MCW_grapher *g123    , *g231      , *g312 ;      /* graphs */
1211 
1212       AFNI_widget_set  *vwid ;
1213       char window_title[THD_MAX_NAME] ;
1214       int ignore_seq_callbacks ;
1215 
1216       THD_dataxes *wod_daxes ;                 /* 02 Nov 1996 */
1217       THD_warp *anat_voxwarp , *fim_voxwarp ;
1218       int anat_wod_flag , fim_wod_flag ;
1219 
1220       KILL_list kl ;
1221       XtPointer parent ;
1222 
1223       int brand_new ;                           /* 07 Dec 2001 */
1224 
1225       THD_warp *fim_selfwarp ;                 /* 27 Aug 2002 */
1226 
1227       int dummied ;                             /* 27 Jan 2004 */
1228 
1229       VEDIT_settings vedset ;                   /* 05 Sep 2006 */
1230       char *vedlabel ;                          /* 27 Mar 2007 */
1231       int   vedskip ;
1232       int   vednomask ;                         /* 01 Aug 2011 */
1233 
1234       ICOR_setup   *iset ;                       /* 05 May 2009 */
1235       ICALC_setup  *icalc_setup ;                /* 18 Sep 2009 */
1236       GICOR_setup  *giset ;                      /* 22 Dec 2009 */
1237       /* record previous continuous color settings to reinstate later */
1238       int cont_bbox;
1239       int cont_pos_only ;
1240       int cont_autorange;
1241       float cont_range_fval;
1242       int cont_pbar_index, int_pbar_index;
1243       int first_integral;
1244       int cont_perc_thr;       /* ZSS percentile thresholding. April 26 2012 */
1245 
1246       /* record current threshold and fim statistics as thresholded [12 Jun 2014] */
1247 
1248       float fim_thrbot ;
1249       float fim_thrtop ;
1250       float fim_thresh_min ;
1251       float fim_thresh_max ;
1252       int   fim_thresh_min_ijk ;
1253       int   fim_thresh_max_ijk ;
1254       int   fim_thrindex ;
1255 } Three_D_View ;
1256 
1257 #define IM3D_IS_BIGTHREE(iq) PBAR_IS_BIGTHREE( (iq)->vwid->func->inten_pbar ) /* 19 Jun 2019 */
1258 
1259 #define IM3D_CLEAR_THRSTAT(iq)                                       \
1260   do{ (iq)->fim_thrbot     = 666.0f; (iq)->fim_thrtop     = -666.0f; \
1261       (iq)->fim_thresh_min = 666.0f; (iq)->fim_thresh_max = -666.0f; \
1262       (iq)->fim_thresh_min_ijk = (iq)->fim_thresh_max_ijk = -777   ; \
1263       (iq)->fim_thrindex = -1 ;                                      \
1264   } while(0)
1265 
1266 #define IM3D_ULAY_COHERENT(iq)                                                    \
1267  (( (iq)->b123_ulay == (iq)->b123_anat || (iq)->b123_ulay == (iq)->b123_fim ) &&  \
1268   ( (iq)->b231_ulay == (iq)->b231_anat || (iq)->b231_ulay == (iq)->b231_fim ) &&  \
1269   ( (iq)->b312_ulay == (iq)->b312_anat || (iq)->b312_ulay == (iq)->b312_fim ))
1270 
1271 #define IM3D_CLEAR_TMASK(iq)                                                                   \
1272  do{ CLEAR_TMASK((iq)->b123_anat); CLEAR_TMASK((iq)->b231_anat); CLEAR_TMASK((iq)->b312_anat); \
1273      CLEAR_TMASK((iq)->b123_fim) ; CLEAR_TMASK((iq)->b231_fim) ; CLEAR_TMASK((iq)->b312_fim) ; \
1274      CLEAR_TMASK((iq)->b123_ulay); CLEAR_TMASK((iq)->b231_ulay); CLEAR_TMASK((iq)->b312_ulay); \
1275  } while(0)
1276 
1277 #define STATUS_IM3D_TMASK(iq)                           \
1278  do{ STATUSp     ("b123_anat"      ,(iq)->b123_anat) ;  \
1279      STATUS_TMASK("b123_anat tmask",(iq)->b123_anat) ;  \
1280      STATUSp     ("b231_anat"      ,(iq)->b231_anat) ;  \
1281      STATUS_TMASK("b231_anat tmask",(iq)->b231_anat) ;  \
1282      STATUSp     ("b312_anat"      ,(iq)->b312_anat) ;  \
1283      STATUS_TMASK("b312_anat tmask",(iq)->b312_anat) ;  \
1284      STATUSp     ("b123_fim "      ,(iq)->b123_fim ) ;  \
1285      STATUS_TMASK("b123_fim  tmask",(iq)->b123_fim ) ;  \
1286      STATUSp     ("b231_fim "      ,(iq)->b231_fim ) ;  \
1287      STATUS_TMASK("b231_fim  tmask",(iq)->b231_fim ) ;  \
1288      STATUSp     ("b312_fim "      ,(iq)->b312_fim ) ;  \
1289      STATUS_TMASK("b312_fim  tmask",(iq)->b312_fim ) ;  \
1290      STATUSp     ("b123_ulay"      ,(iq)->b123_ulay) ;  \
1291      STATUS_TMASK("b123_ulay tmask",(iq)->b123_ulay) ;  \
1292      STATUSp     ("b231_ulay"      ,(iq)->b231_ulay) ;  \
1293      STATUS_TMASK("b231_ulay tmask",(iq)->b231_ulay) ;  \
1294      STATUSp     ("b312_ulay"      ,(iq)->b312_ulay) ;  \
1295      STATUS_TMASK("b312_ulay tmask",(iq)->b312_ulay) ; } while(0)
1296 
1297 /*! Force re-volume-editing when this viewer is redisplayed */
1298 
1299 #define IM3D_VEDIT_FORCE(iq) (iq)->vedset.flags=1
1300 
1301 /*! Turn clusterized display off in this viewer */
1302 
1303 #define UNCLUSTERIZE(iq)                                                   \
1304  do{ int redis=0 ;                                                         \
1305      AFNI_vedit_clear((iq)->fim_now); VEDIT_clear_label((iq));             \
1306      AFNI_cluster_dispkill((iq));                                          \
1307      if( (iq)->vwid->func->clu_rep != NULL ){                              \
1308        free((iq)->vwid->func->clu_rep) ;                                   \
1309        (iq)->vwid->func->clu_rep = NULL ; redis++ ;                        \
1310      }                                                                     \
1311      DESTROY_CLARR((iq)->vwid->func->clu_list);                            \
1312      CLU_free_table((iq)->vwid->func->clu_tabNN1_1sid) ;                   \
1313       CLU_free_table((iq)->vwid->func->clu_tabNN2_1sid) ;                  \
1314        CLU_free_table((iq)->vwid->func->clu_tabNN3_1sid) ;                 \
1315      CLU_free_table((iq)->vwid->func->clu_tabNN1_2sid) ;                   \
1316       CLU_free_table((iq)->vwid->func->clu_tabNN2_2sid) ;                  \
1317        CLU_free_table((iq)->vwid->func->clu_tabNN3_2sid) ;                 \
1318      CLU_free_table((iq)->vwid->func->clu_tabNN1_bsid) ;                   \
1319       CLU_free_table((iq)->vwid->func->clu_tabNN2_bsid) ;                  \
1320        CLU_free_table((iq)->vwid->func->clu_tabNN3_bsid) ;                 \
1321      (iq)->vwid->func->clu_tabNN1_1sid = NULL ;                            \
1322       (iq)->vwid->func->clu_tabNN2_1sid = NULL ;                           \
1323        (iq)->vwid->func->clu_tabNN3_1sid = NULL ;                          \
1324      (iq)->vwid->func->clu_tabNN1_2sid = NULL ;                            \
1325       (iq)->vwid->func->clu_tabNN2_2sid = NULL ;                           \
1326        (iq)->vwid->func->clu_tabNN3_2sid = NULL ;                          \
1327      (iq)->vwid->func->clu_tabNN1_bsid = NULL ;                            \
1328       (iq)->vwid->func->clu_tabNN2_bsid = NULL ;                           \
1329        (iq)->vwid->func->clu_tabNN3_bsid = NULL ;                          \
1330      (iq)->vednomask = 0 ;                                                 \
1331      if( (iq)->vedset.code ) redis++ ;                                     \
1332      if( redis ){                                                          \
1333        (iq)->fim_thrbot     = 666.0f; (iq)->fim_thrtop     = -666.0f;      \
1334        (iq)->fim_thresh_min = 666.0f; (iq)->fim_thresh_max = -666.0f;      \
1335      }                                                                     \
1336      (iq)->vedset.flags = (iq)->vedset.code = 0; AFNI_set_thr_pval((iq));  \
1337      if( (iq)->vinfo->func_visible && redis ) AFNI_redisplay_func((iq)) ;  \
1338  } while(0) ;
1339 
1340 extern void CLU_setup_alpha_tables( Three_D_View * ) ; /* Jul 2010 */
1341 
1342 #define STOP_COLOR "#770000"
1343 #define GO_COLOR   "#005500"
1344 #define WORK_COLOR "#888800"
1345 
1346 #define VEDIT_INSTACORR  0
1347 #define VEDIT_INSTACALC  1
1348 #define VEDIT_TSTAT      2
1349 #define VEDIT_GRINCORR   3
1350 #define VEDIT_LAST_VALUE 3
1351 
1352 #define INSTACORR_LABEL_ON(iq)                                          \
1353  do{ MCW_set_widget_label((iq)->vwid->func->icor_label,"** Ready **") ; \
1354      MCW_set_widget_bg   ((iq)->vwid->func->icor_label,GO_COLOR,0   ) ; \
1355  } while(0)
1356 
1357 #define INSTACORR_LABEL_OFF(iq)                                         \
1358  do{ MCW_set_widget_label((iq)->vwid->func->icor_label,"*NOT Ready*") ; \
1359      MCW_set_widget_bg   ((iq)->vwid->func->icor_label,STOP_COLOR,0 ) ; \
1360  } while(0)
1361 
1362 #define INSTACORR_LABEL_WORKING(iq)                                     \
1363  do{ MCW_set_widget_label((iq)->vwid->func->icor_label,"..Working..") ; \
1364      MCW_set_widget_bg   ((iq)->vwid->func->icor_label,WORK_COLOR,0 ) ; \
1365  } while(0)
1366 
1367 /*! Change InstaCorr popup buttons status */
1368 
1369 #define SENSITIZE_INSTACORR_INDIV(iq,bb)                     \
1370  do{ XtSetSensitive((iq)->vwid->imag->pop_instacorr_pb,bb) ; \
1371      XtSetSensitive((iq)->vwid->imag->pop_icorrjump_pb,bb) ; \
1372      XtUnmanageChild((iq)->vwid->imag->pop_icorrapair_pb) ;  \
1373      XtUnmanageChild((iq)->vwid->imag->pop_icorramirr_pb) ;  \
1374  } while(0)
1375 
1376 #define SENSITIZE_INSTACORR_GROUP(iq,bb)                        \
1377  do{ GICOR_setup *gs = (iq)->giset ;                            \
1378      int ap_allow  = GICOR_apair_allow_bit(gs) ;                \
1379      int ap_ready  = GICOR_apair_ready_bit(gs) ;                \
1380      int ap_mirror = GICOR_apair_mirror_bit(gs);                \
1381      int bp = (bb) && (!ap_allow || ap_ready || ap_mirror) ;    \
1382      if( ap_allow ){                                            \
1383        int ba = (bb) && ap_allow && !ap_mirror ;                \
1384        XtManageChild((iq)->vwid->imag->pop_icorrapair_pb) ;     \
1385        XtManageChild((iq)->vwid->imag->pop_icorramirr_pb) ;     \
1386        XtSetSensitive((iq)->vwid->imag->pop_icorrapair_pb,ba) ; \
1387        XtSetSensitive((iq)->vwid->imag->pop_icorramirr_pb,bb) ; \
1388        MCW_set_widget_bg((iq)->vwid->imag->pop_icorramirr_pb,   \
1389                          (ap_mirror) ? "white" : "black" , 0 ); \
1390      } else {                                                   \
1391        XtUnmanageChild((iq)->vwid->imag->pop_icorrapair_pb) ;   \
1392        XtUnmanageChild((iq)->vwid->imag->pop_icorramirr_pb) ;   \
1393      }                                                          \
1394      XtSetSensitive((iq)->vwid->imag->pop_instacorr_pb,bp) ;    \
1395      XtSetSensitive((iq)->vwid->imag->pop_icorrjump_pb,bp) ;    \
1396  } while(0)
1397 
1398 #define SENSITIZE_INSTACORR(iq,bb)                                  \
1399  do{ if( (iq)->giset != NULL ){ SENSITIZE_INSTACORR_GROUP(iq,bb); } \
1400      else                     { SENSITIZE_INSTACORR_INDIV(iq,bb); } \
1401  } while(0)
1402 
1403 /*! Allow InstaCorr in this viewer */
1404 
1405 #define ENABLE_INSTACORR(iq)           \
1406  do{ SENSITIZE_INSTACORR((iq),True) ;  \
1407      INSTACORR_LABEL_ON((iq)) ;        \
1408  } while(0)
1409 
1410 /*! Turn InstaCorr off in this viewer */
1411 
1412 #define DISABLE_INSTACORR(iq)                                                 \
1413  do{ SENSITIZE_INSTACORR((iq),False) ;                                        \
1414      INSTACORR_LABEL_OFF((iq)) ;                                              \
1415      (iq)->vinfo->i1_icor = (iq)->vinfo->j2_icor = (iq)->vinfo->k3_icor = -1; \
1416      AFNI_misc_CB((iq)->vwid->func->icor_pb,(XtPointer)(iq),NULL) ;           \
1417  } while(0)
1418 
1419 /*--- similar stuff for Group InstaCorr [22 Dec 2009] ---*/
1420 
1421 #define ISREADY_ICOR(iq)        ISVALID_ICOR_setup((iq)->iset)
1422 
1423 #define ISREADY_GICOR(iq)       ( (iq)->giset != NULL && (iq)->giset->ready )
1424 
1425 #define ISREADY_EITHER_ICOR(iq) ( ISREADY_ICOR(iq) || ISREADY_GICOR(iq) )
1426 
1427 #define GRPINCORR_LABEL_ON(iq)                                             \
1428  do{ if( (iq)->vwid->func->gicor_rowcol != NULL ){                         \
1429        MCW_set_widget_label((iq)->vwid->func->gicor_label,"*GIC Ready*") ; \
1430        MCW_set_widget_bg   ((iq)->vwid->func->gicor_label,GO_COLOR,0   ) ; \
1431      } } while(0)
1432 
1433 #define GRPINCORR_LABEL_OFF(iq)                                            \
1434  do{ if( (iq)->vwid->func->gicor_rowcol != NULL ){                         \
1435        MCW_set_widget_label((iq)->vwid->func->gicor_label,"*NOT Ready*") ; \
1436        MCW_set_widget_bg   ((iq)->vwid->func->gicor_label,STOP_COLOR,0 ) ; \
1437      } } while(0)
1438 
1439 #define GRPINCORR_LABEL_WORKING(iq)                                        \
1440  do{ if( (iq)->vwid->func->gicor_rowcol != NULL ){                         \
1441        MCW_set_widget_label((iq)->vwid->func->gicor_label,"..Working..") ; \
1442        MCW_set_widget_bg   ((iq)->vwid->func->gicor_label,WORK_COLOR,0 ) ; \
1443        MCW_set_widget_fg   ((iq)->vwid->func->gicor_label,"#000088"    ) ; \
1444      } } while(0)
1445 
1446 #define ENABLE_GRPINCORR(iq)          \
1447  do{ SENSITIZE_INSTACORR((iq),True) ; \
1448      (iq)->giset->ready = 1 ;         \
1449      GRPINCORR_LABEL_ON((iq)) ;       \
1450  } while(0)
1451 
1452 #define DISABLE_GRPINCORR(iq)                                                    \
1453  do{ if( (iq)->vwid->func->gicor_rowcol != NULL ){                               \
1454        SENSITIZE_INSTACORR((iq),False) ;                                         \
1455        if( (iq)->giset != NULL ) (iq)->giset->ready = 0 ;                        \
1456        GRPINCORR_LABEL_OFF((iq)) ;                                               \
1457        (iq)->vinfo->i1_icor = (iq)->vinfo->j2_icor = (iq)->vinfo->k3_icor = -1;  \
1458        AFNI_misc_CB((iq)->vwid->func->gicor_pb,(XtPointer)(iq),NULL) ;           \
1459      }                                                                           \
1460  } while(0)
1461 
1462 #define GRPINCORR_ready(iq) \
1463  (IM3D_OPEN(iq) && (iq)->giset != NULL) ? (iq)->giset->ready : 0
1464 
1465 /** InstaCalc stuff [18 Sep 2009] **/
1466 
1467 #define INSTACALC_LABEL_ON(iq)                                           \
1468  do{ MCW_set_widget_label((iq)->vwid->func->icalc_label,"*Computed!*") ; \
1469      MCW_set_widget_bg   ((iq)->vwid->func->icalc_label,GO_COLOR,0   ) ; \
1470  } while(0)
1471 
1472 #define INSTACALC_LABEL_OFF(iq)                                          \
1473  do{ MCW_set_widget_label((iq)->vwid->func->icalc_label,"*NOT Ready*") ; \
1474      MCW_set_widget_bg   ((iq)->vwid->func->icalc_label,STOP_COLOR,0 ) ; \
1475  } while(0)
1476 
1477 #define DISABLE_INSTACALC(iq)                                            \
1478  do{ INSTACALC_LABEL_OFF(iq) ;                                           \
1479      if( (iq)->icalc_setup != NULL ) (iq)->icalc_setup->is_good = 0 ;    \
1480      if( (iq)->vwid->func->iwid != NULL )                                \
1481        XtUnmapWidget((iq)->vwid->func->iwid->wtop) ;                     \
1482  } while(0)
1483 
1484 /** Tstat stuff [22 Mar 2018] **/
1485 
1486 #define TSTAT_LABEL_ON(iq)                                               \
1487  do{ MCW_set_widget_label((iq)->vwid->func->tstat_label,"*Computed!*") ; \
1488      MCW_set_widget_bg   ((iq)->vwid->func->tstat_label,GO_COLOR,0   ) ; \
1489  } while(0)
1490 
1491 #define TSTAT_LABEL_OFF(iq)                                              \
1492  do{ MCW_set_widget_label((iq)->vwid->func->tstat_label,"*NOT Ready*") ; \
1493      MCW_set_widget_bg   ((iq)->vwid->func->tstat_label,STOP_COLOR,0 ) ; \
1494  } while(0)
1495 
1496 #define DISABLE_TSTAT(iq)                                                \
1497  do{ TSTAT_LABEL_OFF(iq) ;                                               \
1498      if( (iq)->vwid->func->iwid != NULL )                                \
1499        XtUnmapWidget((iq)->vwid->func->iwid->wtop) ;                     \
1500  } while(0)
1501 
1502 /*! Is any image viewer window open? */
1503 
1504 #define IM3D_IMAGIZED(iq) \
1505  ( (iq)->s123 != NULL || (iq)->s231 != NULL || (iq)->s312 != NULL )
1506 
1507 /* Friendlier names for viewers [10 Dec 2019] */
1508 
1509 #define IM3D_AXIALIMAGE(iq)    (iq)->s123
1510 #define IM3D_SAGITTALIMAGE(iq) (iq)->s231
1511 #define IM3D_CORONALIMAGE(iq)  (iq)->s312
1512 
1513 #define IM3D_AXIALGRAPH(iq)    (iq)->g123
1514 #define IM3D_SAGITTALGRAPH(iq) (iq)->g231
1515 #define IM3D_CORONALGRAPH(iq)  (iq)->g312
1516 
1517 /*! Is any graph viewer window open? */
1518 
1519 #define IM3D_GRAPHIZED(iq) \
1520  ( (iq)->g123 != NULL || (iq)->g231 != NULL || (iq)->g312 != NULL )
1521 
1522 /*! Is any image or graph viewer doing a timer thing? [21 Dec 2006] */
1523 
1524 #define IM3D_TIMERIZED(iq)                              \
1525  ( ((iq)->s123 != NULL && (iq)->s123->timer_id > 0) ||  \
1526    ((iq)->s231 != NULL && (iq)->s231->timer_id > 0) ||  \
1527    ((iq)->s312 != NULL && (iq)->s312->timer_id > 0) ||  \
1528    ((iq)->g123 != NULL && (iq)->g123->timer_id > 0) ||  \
1529    ((iq)->g231 != NULL && (iq)->g231->timer_id > 0) ||  \
1530    ((iq)->g312 != NULL && (iq)->g312->timer_id > 0)   )
1531 
1532 /* 02 Nov 1996: macro to load current viewing data into current datasets */
1533 
1534 #define LOAD_ANAT_VIEW(iq)                               \
1535   do{ (iq)->anat_now->wod_daxes = (iq)->wod_daxes ;      \
1536       (iq)->anat_now->wod_flag  = (iq)->anat_wod_flag ;  \
1537       (iq)->anat_now->vox_warp  = (iq)->anat_voxwarp ;   \
1538     } while(0)
1539 
1540 #define LOAD_FUNC_VIEW(iq)                               \
1541   do{ if( ISVALID_3DIM_DATASET((iq)->fim_now) ){         \
1542          (iq)->fim_now->wod_daxes = (iq)->wod_daxes ;    \
1543          (iq)->fim_now->wod_flag  = (iq)->fim_wod_flag ; \
1544          (iq)->fim_now->vox_warp  = (iq)->fim_voxwarp ;  \
1545          (iq)->fim_now->self_warp = (iq)->fim_selfwarp ; \
1546       } } while(0)
1547 
1548 #define LOAD_DSET_VIEWS(iq) \
1549   do{ LOAD_ANAT_VIEW(iq) ; LOAD_FUNC_VIEW(iq) ; } while(0)
1550 
1551 extern int AFNI_count_controllers(void) ;
1552 extern void AFNI_controller_clonify(void) ;
1553 extern Three_D_View * new_AFNI_controller( Widget , MCW_DC * , int ) ;
1554 extern void AFNI_initialize_controller( Three_D_View * ) ;
1555 extern void AFNI_purge_dsets(int) ;
1556 extern void AFNI_purge_unused_dsets(void) ;
1557 extern int AFNI_controller_index( Three_D_View * ) ;
1558 
1559 extern void AFNI_sigfunc_alrm(int sig) ;
1560 #undef  AFexit
1561 #define AFexit AFNI_sigfunc_alrm
1562 
1563 extern void AFNI_inconstancy_check( Three_D_View *, THD_3dim_dataset * ); /* 06 Sep 2006 */
1564 
1565 extern Three_D_View * AFNI_find_open_controller(void) ; /* 05 Mar 2002 */
1566 extern void AFNI_popup_message( char * ) ;
1567 
1568 extern void   AFNI_start_version_check(void) ;   /* 21 Nov 2002 */
1569 extern int    AFNI_version_check      (void) ;
1570 extern char * AFNI_make_update_script (void) ;   /* 20 Nov 2003 */
1571 
1572 extern void   AFNI_start_compile_date_check(void) ;  /* 17 Jun 2014 */
1573 extern int    AFNI_compile_date_check      (void) ;
1574 
1575 extern char * AFNI_get_friend(void) ;      /* 26 Feb 2001 */
1576 extern char * AFNI_get_date_trivia(void) ; /* 25 Nov 2002 */
1577 extern int AFNI_get_todays_trivia( char *** ) ; /* 27 Nov 2007 */
1578 
1579 extern char * julian_date_string(void) ;   /* 29 Oct 2019 */
1580 
1581 #define OPEN_CONTROLLER(iq)                                  \
1582  do{ XtRealizeWidget((iq)->vwid->top_shell) ;                \
1583      while(XtWindow((iq)->vwid->top_shell)==(Window)NULL) ;  \
1584      AFNI_startup_3dview(iq); (iq)->opened = 1;              \
1585      SET_TOPFORM_HEIGHT(iq) ;                                \
1586  } while(0)
1587 
1588 #define CLOSE_CONTROLLER(iq) ( AFNI_closedown_3dview(iq),                \
1589                                XtUnrealizeWidget((iq)->vwid->top_shell), \
1590                                AFNI_clus_popdown(iq) ,                   \
1591                                (iq)->opened = 0 )
1592 
1593 #define PARENTIZE(ds,par) \
1594    if( ISVALID_3DIM_DATASET((ds)) ) (ds)->parent = (XtPointer) (par)
1595 
1596 /* macros to return the analogous grapher given a viewer, and vice-versa */
1597 
1598 #define VIEWER_TO_GRAPHER(iq,ss) (((ss)==(iq)->s123) ? (iq)->g123 :  \
1599                                   ((ss)==(iq)->s231) ? (iq)->g231 :  \
1600                                   ((ss)==(iq)->s312) ? (iq)->g312 : NULL)
1601 
1602 #define GRAPHER_TO_VIEWER(iq,gg)  (((gg)==(iq)->g123) ? (iq)->s123 :  \
1603                                    ((gg)==(iq)->g231) ? (iq)->s231 :  \
1604                                    ((gg)==(iq)->g312) ? (iq)->s312 : NULL)
1605 
1606 #define UNDERLAY_TO_VIEWER(iq,bb) (((bb)==(iq)->b123_ulay) ? (iq)->s123 :  \
1607                                    ((bb)==(iq)->b231_ulay) ? (iq)->s231 :  \
1608                                    ((bb)==(iq)->b312_ulay) ? (iq)->s312 : NULL)
1609 
1610 #define UNDERLAY_TO_GRAPHER(iq,bb) (((bb)==(iq)->b123_ulay) ? (iq)->g123 :  \
1611                                     ((bb)==(iq)->b231_ulay) ? (iq)->g231 :  \
1612                                     ((bb)==(iq)->b312_ulay) ? (iq)->g312 : NULL)
1613 
1614 #define UNDERLAY_TO_OVERLAY(iq,bb) (((bb)==(iq)->b123_ulay) ? (iq)->b123_fim :  \
1615                                     ((bb)==(iq)->b231_ulay) ? (iq)->b231_fim :  \
1616                                     ((bb)==(iq)->b312_ulay) ? (iq)->b312_fim : NULL)
1617 
1618 /*-----------------------------------------------------------------------------*/
1619 /*---------------------------- Global library data ----------------------------*/
1620 
1621 #ifdef  __cplusplus
1622 }
1623 #endif
1624 
1625 #ifdef MAIN
1626 int first_plugin_check = 1 ;     /* 30 Sep 2016 */
1627 #endif
1628 
1629 #include "afni_plugin.h"
1630 
1631 #ifdef  __cplusplus
1632 extern "C" {
1633 #endif
1634 
1635 #ifdef ALLOW_PLUGINS
1636 
1637    /*-- pseudo-plugin functions --*/
1638 
1639    extern PLUGIN_interface * ENV_init(void) ;            /* 20 Jun 2000 */
1640    extern void ENV_add_numeric( char * , char * ,
1641                                 int , int , int , int , generic_func * ) ;
1642    extern void ENV_add_string( char * , char * ,
1643                                int , char ** , generic_func * ) ;
1644    extern void ENV_add_yesno( char * , char * ) ;        /* 08 Aug 2001 */
1645 
1646    extern PLUGIN_interface * F2D_init(void) ;            /* 03 Jul 2000 */
1647    extern PLUGIN_interface * F1D_init(void) ;            /* 08 Aug 2001 */
1648    extern void               F2D_null(void) ;
1649    extern void               F1D_null(void) ;
1650    extern PLUGIN_interface * ICOR_init(char *);          /* 29 Apr 2009 */
1651    extern PLUGIN_interface * GICOR_init(char *);         /* 22 Dec 2009 */
1652    extern PLUGIN_interface * TSTAT_init(char *);         /* 22 Mar 2018 */
1653 #endif
1654 
1655 extern void ENV_globalrange_view( char *vname );
1656 extern void THD_set_image_globalrange_env(int ig);
1657 
1658 extern void GICOR_setup_func(NI_stream, NI_element *) ;        /* 22 Dec 2009 */
1659 extern void GICOR_process_dataset( NI_element *nel, int ct ) ; /* 23 Dec 2009 */
1660 extern void GICOR_process_message( NI_element *nel ) ;            /* Apr 2013 */
1661 extern void process_NIML_textmessage( NI_element * ) ;            /* Apr 2013 */
1662 
1663 extern void ICALC_make_widgets( Three_D_View *im3d ) ;   /* 18 Sep 2009 */
1664 
1665 typedef struct {                /* windows and widgets */
1666    RwcPointer_array *windows ;   /* allowed to interrupt */
1667    RwcPointer_array *widgets ;   /* 'real-time' functions */
1668 } MCW_interruptables ;
1669 
1670 #ifndef MAX_CONTROLLERS
1671 #define MAX_CONTROLLERS 10  /* 12 Nov 2002: increased from 5, per MSB */
1672 #endif
1673 
1674 /*-------------- Here there be global variables.  So shoot me. --------------*/
1675 
1676 #ifdef  __cplusplus
1677 }
1678 #endif
1679 
1680 #include "afni_setup.h"  /* 19 Dec 1997 */
1681 
1682 #ifdef  __cplusplus
1683 extern "C" {
1684 #endif
1685 
1686 typedef struct {
1687    int numchan ;
1688    int status ;
1689    int numdset ;
1690    THD_3dim_dataset **dset ;
1691 } RT_status ;
1692 
1693 #define RT_STARTUP    1  /* status codes [01 Jun 2009] */
1694 #define RT_CONTINUE   2
1695 #define RT_FINISHED   3
1696 
1697 typedef struct {
1698    MCW_DC *dc ;                                  /* display context for everyone */
1699    THD_sessionlist *sslist ;                     /* all sessions viewable */
1700    MRI_IMARR *timeseries ;                       /* all timeseries available */
1701    NI_ELARR  *tcsv_data ;                        /* all *.tsv and *.csv [16 Jun 2020] */
1702    Three_D_View *controllers[MAX_CONTROLLERS] ;  /* all controllers available */
1703    MCW_interruptables interruptables ;           /* windows and widgets */
1704 
1705    MCW_function_list registered_0D ;             /* registered functions */
1706    MCW_function_list registered_1D ;
1707    MCW_function_list registered_2D ;
1708 
1709    int controller_lock , ignore_lock ;
1710    int have_dummy_dataset ;
1711    int sesstrail ;                               /* 23 Oct 1998 */
1712 
1713    THD_coorder cord ;
1714 
1715 #ifdef ALLOW_PLUGINS
1716    struct AFNI_plugin_array *plugins ;           /* plugins */
1717 #endif
1718 
1719    PBAR_palette_table *gpt ;
1720 
1721    int time_lock ;                               /* 03 Nov 1998 */
1722 
1723    int hints_on ;                                /* 01 Aug 1999 */
1724 
1725    float fim_bkthr_perc ;                        /* 02 Jun 1999 */
1726 
1727    MCW_function_list registered_fim ;            /* 30 Jan 2000 */
1728 
1729    int ijk_lock ;                                /* 11 Sep 2000 */
1730    int thr_lock ;
1731    int zoompan_lock ;                            /* 10 Dec 2019 */
1732 
1733    THD_session *session ;                        /* 20 Dec 2001 */
1734 
1735    MCW_function_list registered_slice_proj ;     /* 31 Jan 2002 */
1736 
1737    Htable *warptable ;                           /* 28 Aug 2002 */
1738 
1739    RT_status *realtime_status ;                  /* 01 Jun 2009 */
1740    gen_func  *realtime_callback ;
1741 
1742    int dont_tell_suma ;            /* 1 = won't send SUMA info  */
1743    int dont_overlay_suma ;  /* 1 = won't send SUMA func overlay */
1744    int dont_hear_suma ;     /* 1 = I can't hear you SUMA        */
1745 
1746    int pbar_fullrange ;                          /* 03 Jun 2014 */
1747 
1748    int local_display ;                           /* 20 Aug 2018 */
1749    int have_sox ;                                /* 20 Aug 2018 */
1750    char *sound_player ;                          /* 27 Aug 2018 */
1751 
1752    float autorange_perc ;                        /* 24 May 2019 */
1753 
1754    int opacity_setting ;                         /* 06 Jun 2019 */
1755 
1756 } AFNI_library_type ;
1757 
1758 #define BROWN_COLOR "#553319"
1759 
1760 #ifdef MAIN
1761    AFNI_library_type GLOBAL_library ;
1762    int GLOBAL_num_dsets = 0 ;
1763    char *GLOBAL_motd = NULL ;                     /* 29 Nov 2005 */
1764 #else
1765    extern AFNI_library_type GLOBAL_library ;
1766    extern int GLOBAL_num_dsets ;
1767    extern char *GLOBAL_motd ;
1768 #endif
1769 
1770 extern void AFNI_display_motd( Widget w ) ;       /* 29 Nov 2005 */
1771 extern void AFNI_display_hist( Widget w ) ;       /* 05 Mar 2008 */
1772 
1773 #define FIM_THR          (0.01*GLOBAL_library.fim_bkthr_perc)  /* 02 Jun 1999 */
1774 #define SET_FIM_bkthr(v) (GLOBAL_library.fim_bkthr_perc = (v))
1775 
1776 #define NOT_TELLING_SUMA (GLOBAL_library.dont_tell_suma==1)
1777 #define     TELLING_SUMA (GLOBAL_library.dont_tell_suma==0)
1778 #define DONT_TELL_SUMA  (GLOBAL_library.dont_tell_suma=1)
1779 #define      TELL_SUMA  (GLOBAL_library.dont_tell_suma=0)
1780 
1781 #define NOT_OVERLAYING_SUMA (GLOBAL_library.dont_overlay_suma==1)
1782 #define     OVERLAYING_SUMA (GLOBAL_library.dont_overlay_suma==0)
1783 #define DONT_OVERLAY_SUMA  (GLOBAL_library.dont_overlay_suma=1)
1784 #define      OVERLAY_SUMA  (GLOBAL_library.dont_overlay_suma=0)
1785 
1786 #define NOT_HEARING_SUMA (GLOBAL_library.dont_hear_suma==1)
1787 #define     HEARING_SUMA (GLOBAL_library.dont_hear_suma==0)
1788 #define DONT_HEAR_SUMA  (GLOBAL_library.dont_hear_suma=1)
1789 #define      HEAR_SUMA  (GLOBAL_library.dont_hear_suma=0)
1790 
1791 #define DISABLE_LOCK    (GLOBAL_library.ignore_lock=1)
1792 #define ENABLE_LOCK     (GLOBAL_library.ignore_lock=0)
1793 #define BEEPIT          XBell(GLOBAL_library.dc->display,100)
1794 #define ALLOW_realtime  GLOBAL_argopt.allow_rt
1795 #define ELIDE_quality   GLOBAL_argopt.elide_quality
1796 #define GPT             GLOBAL_library.gpt
1797 #define NO_frivolities  GLOBAL_argopt.no_frivolities
1798 #define SESSTRAIL       GLOBAL_library.sesstrail
1799 #define AFNI_VERBOSE    (!GLOBAL_argopt.quiet)  /* 25 Oct 2001 */
1800 
1801 #define THE_DISPLAY     (GLOBAL_library.dc->display)  /* 02 Aug 2002 */
1802 #define THE_TOPSHELL    (GLOBAL_library.controllers[0]->vwid->top_shell)
1803 #define A_CONTROLLER    (GLOBAL_library.controllers[0])
1804 
1805 # define SUMA_ENABLED   GLOBAL_argopt.enable_suma
1806 
1807 /* 04/06/2020 discoraj */
1808 #define ALL_DSETS_STARTUP  GLOBAL_argopt.all_dsets_startup
1809 
1810 #define DOING_REALTIME_WORK (GLOBAL_library.interruptables.windows != NULL)
1811 
1812 #define PBAR_FULLRANGE  GLOBAL_library.pbar_fullrange
1813 #define AUTORANGE_PERC  GLOBAL_library.autorange_perc
1814 
1815 #define UNDUMMYIZE                                                              \
1816  do { GLOBAL_library.have_dummy_dataset = 0 ;                                   \
1817       XtSetSensitive(GLOBAL_library.controllers[0]->vwid->prog->clone_pb,True); \
1818     } while(0)
1819 
1820 /*-----------------------------------------------------------*/
1821 /*------------------------ prototypes -----------------------*/
1822 
1823 extern int AFNI_vnlist_func_overlay( Three_D_View *,int, SUMA_irgba **,int * ) ;
1824 extern int AFNI_vol2surf_func_overlay( Three_D_View *, SUMA_irgba **,
1825                                        int, int, int, float **, float * );
1826 extern float * AFNI_v2s_node_timeseries(THD_session *, THD_3dim_dataset *,
1827                                 int, int, int, int);  /* 29 Apr 2009 [rickr] */
1828 
1829 extern void AFNI_parse_args( int argc , char * argv[] );
1830 
1831 extern void AFNI_splashup   (void) ;  /* 02 Aug 1999 */
1832 extern void AFNI_splashdown (void) ;
1833 extern void AFNI_splashraise(void) ;  /* 25 Sep 2000 */
1834 extern void AFNI_faceup     (void) ;  /* 17 Dec 2004 */
1835 extern void AFNI_allsplash  (void) ;  /* 12 Sep 2007 */
1836 extern int  AFNI_splash_isopen(void); /* 10 Nov 2005 */
1837 extern void AFNI_broutim_CB (Widget,XtPointer,XtPointer) ; /* 06 Jun 2005 */
1838 extern void AFNI_broutext_CB(Widget,XtPointer,XtPointer) ; /* 21 Dec 2005 */
1839 
1840 extern void AFNI_quit_CB           ( Widget wcall , XtPointer cd , XtPointer cbs );
1841 extern void AFNI_quit_timeout_CB   ( XtPointer , XtIntervalId * ) ;
1842 extern void AFNI_startup_timeout_CB( XtPointer , XtIntervalId * ) ;
1843 extern void AFNI_vcheck_flasher    ( Three_D_View * ) ;
1844 extern void AFNI_tips_CB           ( Widget , XtPointer , XtPointer ) ;
1845 extern void AFNI_news_CB           ( Widget , XtPointer , XtPointer ) ;
1846 extern void AFNI_forum_CB          ( Widget , XtPointer , XtPointer ) ;
1847 extern void AFNI_phelp_CB          ( Widget , XtPointer , XtPointer ) ;
1848 extern void AFNI_ytube_CB          ( Widget , XtPointer , XtPointer ) ;
1849 
1850 extern void AFNI_startup_layout_CB  ( XtPointer, XtIntervalId * ) ;    /* 23 Sep 2000 */
1851 extern void AFNI_save_layout_CB     ( Widget, XtPointer, XtPointer ) ;
1852 extern void AFNI_finalsave_layout_CB( Widget, XtPointer, MCW_choose_cbs * ) ;
1853 extern void AFNI_startup_script_CB  ( XtPointer, XtIntervalId * ) ;    /* 21 Jan 2003 */
1854 extern void AFNI_run_script_CB      ( Widget, XtPointer, XtPointer ) ; /* 22 Jan 2003 */
1855 extern void AFNI_finalrun_script_CB ( Widget, XtPointer, MCW_choose_cbs * ) ;
1856 
1857 #define AFNI_run_script(ss) AFNI_startup_script_CB((XtPointer)(ss),NULL)
1858 
1859 extern void AFNI_decode_geom( char * , int *, int *, int *, int * ) ;
1860 
1861 extern void AFNI_clone_controller_CB( Widget , XtPointer , XtPointer ) ;
1862 extern void AFNI_controller_panel_CB( Widget , XtPointer , XtPointer ) ;
1863 extern void AFNI_make_controller( int ) ;  /* 23 Sep 2000 */
1864 
1865 /* "locks" 04 Nov 1996 */
1866 extern void AFNI_lock_enforce_CB( Widget , XtPointer , XtPointer ) ;
1867 extern void AFNI_lock_change_CB ( Widget , XtPointer , XtPointer ) ;
1868 extern void AFNI_lock_clear_CB  ( Widget , XtPointer , XtPointer ) ;
1869 extern void AFNI_lock_setall_CB ( Widget , XtPointer , XtPointer ) ;
1870 extern void AFNI_space_lock_carryout  ( Three_D_View * ) ; /* (name change) */
1871 
1872 extern void AFNI_all_locks_carryout( Three_D_View *im3d ) ; /* 03 Jul 2014 */
1873 
1874 extern void AFNI_time_lock_carryout( Three_D_View * ) ;     /* 03 Nov 1998 */
1875 extern void AFNI_time_lock_change_CB( Widget , XtPointer , XtPointer ) ;
1876 
1877 extern void AFNI_zoompan_lock_carryout( Three_D_View * ) ;  /* 10 Dec 2019 */
1878 extern void AFNI_zoompan_lock_change_CB( Widget , XtPointer , XtPointer ) ;
1879 
1880 extern void AFNI_thresh_lock_carryout( Three_D_View * ) ; /* 06 Feb 2004 */
1881 extern void AFNI_pbar_lock_carryout  ( Three_D_View * ) ; /* 07 Feb 2004 */
1882 extern void AFNI_equate_pbars        ( Three_D_View *, Three_D_View * ) ;
1883 extern void AFNI_thrdrag_lock_carryout( Three_D_View * ) ;
1884 extern void AFNI_range_lock_carryout( Three_D_View * ) ;  /* 23 Feb 2004 */
1885 
1886 extern void AFNI_ijk_lock_change_CB( Widget , XtPointer , XtPointer ) ;
1887 extern int AFNI_thresh_lock_env_val( void );
1888 extern void AFNI_func_thrlock_change_CB( Widget , XtPointer , XtPointer );
1889 extern void AFNI_set_all_thrlock_bboxes(Three_D_View *im3d, int bval) ;
1890 
1891 extern void AFNI_func_rnglock_change_CB( Widget , XtPointer , XtPointer );
1892 extern void AFNI_set_all_rnglock_bboxes(Three_D_View *im3d, int bval) ;
1893 extern int  AFNI_check_range_lock() ;
1894 
1895 extern void AFNI_func_pbarlock_change_CB( Widget , XtPointer , XtPointer );
1896 extern void AFNI_set_all_pbarlock_bboxes(Three_D_View *im3d, int bval) ;
1897 extern int  AFNI_check_pbar_lock() ;
1898 
1899 extern XtPointer AFNI_brick_to_mri( int n , int type , FD_brick * br );
1900 
1901 extern THD_3dim_dataset * AFNI_read_images( int nf , char * fname[] );
1902 
1903 extern void AFNI_seq_send_CB(MCW_imseq   * seq    ,FD_brick * br,ISQ_cbs * cbs);
1904 extern void AFNI_gra_send_CB(MCW_grapher * grapher,FD_brick * br,GRA_cbs * cbs);
1905 
1906 extern void AFNI_read_inputs   ( int argc, char * argv[] );
1907 extern void AFNI_make_widgets  ( Three_D_View * im3d );
1908 extern void AFNI_closedown_3dview( Three_D_View * im3d );
1909 extern void AFNI_startup_3dview  ( Three_D_View * im3d ); /* 15 Jun 2000 */
1910 extern MRI_IMAGE * AFNI_overlay( int n , FD_brick * br );
1911 extern void AFNI_invert_CB( Widget, XtPointer, XtPointer ) ; /* 02 Feb 2007 */
1912 extern void AFNI_nimlpo_CB( Widget, XtPointer, XtPointer ) ; /* 02 Feb 2007 */
1913 extern void AFNI_process_NIML_data( int , void * , int ) ;   /* 01 Feb 2008 */
1914 
1915 extern int_pair find_reasonable_overlay_indexes( THD_3dim_dataset *dset ) ;
1916 
1917 extern char * AFNI_controller_label( Three_D_View * im3d ); /* 01 Apr 1999 */
1918 extern void AFNI_set_window_titles( Three_D_View * im3d );
1919 
1920 extern void AFNI_crosshair_visible_CB( MCW_arrowval * , XtPointer ) ;
1921 extern void AFNI_view_xyz_CB         ( Widget , XtPointer , XtPointer ) ;
1922 extern void AFNI_marktog_CB          ( Widget , XtPointer , XtPointer ) ;
1923 extern void AFNI_marks_action_CB     ( Widget , XtPointer , XtPointer ) ;
1924 
1925 extern void AFNI_viewbut_EV( Widget, XtPointer, XEvent *, RwcBoolean * ) ;
1926 extern void AFNI_cluster_EV( Widget, XtPointer, XEvent *, RwcBoolean * ) ;
1927 extern void AFNI_clus_update_widgets( Three_D_View *im3d ) ;
1928 extern void AFNI_clus_popdown( Three_D_View *im3d ) ;
1929 extern int AFNI_clus_find_xyz( Three_D_View *im3d , float x,float y,float z ) ;
1930 extern void AFNI_clus_action_CB( Widget w , XtPointer cd , XtPointer cbs ) ;
1931 extern int AFNI_clus_find_xyz_nearest(
1932                                Three_D_View *im3d , float x,float y,float z ) ;
1933 
1934 extern void AFNI_time_index_EV( Widget, XtPointer, XEvent *, RwcBoolean * ) ; /* 24 Feb 2014 */
1935 extern void AFNI_time_index_set_fstep( Three_D_View *im3d , int istep ) ;
1936 
1937 extern void AFNI_update_dataset_viewing( THD_3dim_dataset * ); /* 21 Jul 2009 */
1938 extern void AFNI_alter_wami_text(Three_D_View *im3d, char *utlab);
1939 
1940 #define AFNI_SEE_FUNC_ON(iq) ( MCW_set_bbox( (iq)->vwid->view->see_func_bbox, 1 ), \
1941                                AFNI_see_func_CB( NULL , (XtPointer)(iq) , NULL )  )
1942 
1943 #define AFNI_SEE_FUNC_OFF(iq) ( MCW_set_bbox( (iq)->vwid->view->see_func_bbox, 0), \
1944                                 AFNI_see_func_CB( NULL , (XtPointer)(iq) , NULL ) )
1945 
1946 #define AFNI_SETUP_FUNC_ON(iq)                                \
1947   do{ if( ! (iq)->vinfo->func_visible ){                      \
1948          MCW_set_bbox( (iq)->vwid->view->see_func_bbox, 1 ) ; \
1949          (iq)->vinfo->func_visible = True ;                   \
1950       } } while(0)
1951 
1952 #define AFNI_SWITCH_VIEW(iq,vv)                                    \
1953    do{ if( (iq)->vinfo->view_type != (vv) ){                       \
1954          MCW_set_bbox( (iq)->vwid->view->view_bbox , 1 << (vv) ) ; \
1955          AFNI_switchview_CB( NULL , (XtPointer)(iq) , NULL ) ;     \
1956        } } while(0) ;
1957 
1958 #define AFNI_SETUP_VIEW(iq,vv)                                     \
1959    do{ if( (iq)->vinfo->view_type != (vv) ){                       \
1960          MCW_set_bbox( (iq)->vwid->view->view_bbox , 1 << (vv) ) ; \
1961          (iq)->vinfo->view_type = (vv) ;                           \
1962        } } while(0) ;
1963 
1964 typedef struct {
1965   int ndset , ncode ;
1966   THD_3dim_dataset **dset ;
1967   void (*cb)(Widget , XtPointer , MCW_choose_cbs *) ;
1968   void *parent ;
1969 } AFNI_dataset_choose_stuff ;
1970 
1971 extern void AFNI_switchview_CB        ( Widget , XtPointer , XtPointer ) ;
1972 extern void AFNI_see_marks_CB         ( Widget , XtPointer , XtPointer ) ;
1973 extern void AFNI_see_func_CB          ( Widget , XtPointer , XtPointer ) ;
1974 extern void AFNI_marks_edits_CB       ( Widget , XtPointer , XtPointer ) ;
1975 extern void AFNI_marks_transform_CB   ( Widget , XtPointer , XtPointer ) ;
1976 extern void AFNI_imag_pop_CB          ( Widget , XtPointer , XtPointer ) ;
1977 extern void AFNI_crosshair_pop_CB     ( Widget , XtPointer , XtPointer ) ; /* 01 Aug 2011 */
1978 extern void AFNI_define_CB            ( Widget , XtPointer , XtPointer ) ;
1979 extern void AFNI_underlay_CB          ( Widget , XtPointer , XtPointer ) ;
1980 extern void AFNI_choose_dataset_CB    ( Widget , XtPointer , XtPointer ) ;
1981 extern void AFNI_write_dataset_CB     ( Widget , XtPointer , XtPointer ) ;
1982 extern void AFNI_write_many_dataset_CB( Widget , XtPointer , XtPointer ) ; /* 23 Nov 1996 */
1983 extern void AFNI_anatmode_CB          ( Widget , XtPointer , XtPointer ) ;
1984 extern void AFNI_funcmode_CB          ( Widget , XtPointer , XtPointer ) ;
1985 extern void AFNI_raiseup_CB           ( Widget , XtPointer , XtPointer ) ;
1986 extern void AFNI_assign_ulay_bricks   ( Three_D_View *im3d ) ;             /* 10 Jun 2014 */
1987 
1988 extern void AFNI_saveas_dataset_CB   ( Widget , XtPointer , XtPointer ) ;  /* 18 Oct 2010 */
1989 extern void AFNI_saveas_finalize_CB  ( Widget , XtPointer , MCW_choose_cbs * ) ;
1990 extern void AFNI_writeout_dataset    ( THD_3dim_dataset * , char * ) ;     /* 16 Jun 2014 */
1991 
1992 extern void AFNI_do_many_writes      ( Widget , XtPointer , MCW_choose_cbs * ) ; /* 23 Nov 1996 */
1993 extern void AFNI_finalize_dataset_CB ( Widget , XtPointer , MCW_choose_cbs * ) ;
1994 extern void AFNI_jumpto_CB           ( Widget , XtPointer , MCW_choose_cbs * ) ;
1995 extern int  AFNI_jumpto_dicom        ( Three_D_View * , float, float, float  ) ;
1996 extern int  AFNI_jump_and_seed       ( Three_D_View * , float, float, float  ) ;
1997 extern int  AFNI_creepto_dicom       ( Three_D_View * , float, float, float  ) ;
1998 extern int  AFNI_jumpto_ijk          ( Three_D_View * , int, int, int ) ;
1999 extern void AFNI_jumpto_ijk_CB       ( Widget , XtPointer , MCW_choose_cbs * ) ;
2000 extern int  AFNI_jumpto_ijk_olay     ( Three_D_View * , int, int, int ) ; /* 20 Apr 2016 */
2001 extern void AFNI_jumpto_ijk_olay_CB  ( Widget , XtPointer , MCW_choose_cbs * ) ;
2002 extern void AFNI_sumato_CB           ( Widget , XtPointer , MCW_choose_cbs * ) ;
2003 extern void AFNI_mnito_CB            ( Widget , XtPointer , MCW_choose_cbs * ) ;
2004 extern void AFNI_check_obliquity     ( Widget , THD_3dim_dataset * ,
2005                                                 THD_3dim_dataset * ) ;
2006 extern void AFNI_jumpto_thminmax_CB  ( Widget , XtPointer , XtPointer ) ; /* 21 Jul 2014 */
2007 
2008 extern void AFNI_crosshair_pop_CB    ( Widget , XtPointer , XtPointer ) ; /* 12 Mar 2004 */
2009 extern void AFNI_crosshair_EV        ( Widget , XtPointer , XEvent * , RwcBoolean * ) ;
2010 extern void AFNI_crosshair_relabel   ( Three_D_View * ) ;
2011 
2012 extern void AFNI_fimmer_pickref_CB   ( Widget , XtPointer , MCW_choose_cbs * ) ;
2013 extern void AFNI_fimmer_pickort_CB   ( Widget , XtPointer , MCW_choose_cbs * ) ;
2014 
2015 #ifdef USE_FUNC_FIM
2016 extern void AFNI_fimmer_fix_optmenu( Three_D_View * ) ;
2017 extern void AFNI_fimmer_menu_CB( Widget , XtPointer , XtPointer ) ;
2018 extern void AFNI_fimmer_dset_choose_CB( Widget, XtPointer, MCW_choose_cbs * ) ;
2019 # ifdef USE_OPTMENUS
2020   extern void AFNI_fimmer_ignore_choose_CB( MCW_arrowval *, XtPointer ) ;
2021 # else
2022   extern void AFNI_fimmer_ignore_choose_CB( Widget, XtPointer, MCW_choose_cbs * ) ;
2023 # endif
2024 #endif
2025 
2026 /*------------------------------------------------------------------
2027    31 Jan 2000 - this stuff for user-defined fimfuncs
2028 --------------------------------------------------------------------*/
2029 
2030 typedef struct {
2031    MRI_IMAGE * ref_ts , * ort_ts ;
2032    int nvox , ignore , polort ;
2033 } FIMdata ;
2034 
2035 extern void AFNI_register_fimfunc( char *, int, generic_func *, void * );
2036 extern void spearman_fimfunc( int, float *, void *, int, void * );
2037 extern void quadrant_fimfunc( int, float *, void *, int, void * );
2038 
2039 /*-------------------------------------------------------------------*/
2040 
2041 extern void AFNI_fimmer_setref( Three_D_View * , MRI_IMAGE * ) ;
2042 extern void AFNI_fimmer_setort( Three_D_View * , MRI_IMAGE * ) ;
2043 extern void AFNI_fimmer_setignore( Three_D_View * , int ) ;
2044 extern void AFNI_fimmer_setpolort( Three_D_View * , int ) ;
2045 extern int  AFNI_rescan_session( int ) ;
2046 extern void AFNI_rescan_CB( Widget , XtPointer , XtPointer ) ;
2047 extern void AFNI_rescan_all_CB( Widget , XtPointer , XtPointer ) ;
2048 extern void AFNI_rescan_timeseries_CB( Widget , XtPointer , XtPointer ) ;
2049 
2050 extern void AFNI_block_rescan( int bb ) ;    /* 09 Nov 2005 */
2051 extern void AFNI_rescan_timeout_CB( XtPointer , XtIntervalId * ) ;
2052 
2053 extern void AFNI_read_sess_CB( Widget , XtPointer , XtPointer ) ;
2054 extern void AFNI_finalize_read_sess_CB( Widget , XtPointer , XtPointer ) ;
2055 extern void AFNI_make_file_dialog( Three_D_View * ) ;
2056 extern void AFNI_close_file_dialog_CB( Widget , XtPointer , XtPointer ) ;
2057 extern void AFNI_read_1D_CB( Widget , XtPointer , XtPointer ) ;
2058 extern void AFNI_finalize_read_1D_CB( Widget , XtPointer , XtPointer ) ;
2059 
2060 extern int  DSET_in_global_session( THD_3dim_dataset * ) ;       /* 20 Dec 2001 */
2061 
2062 extern void AFNI_read_Web_CB( Widget, XtPointer, XtPointer );    /* 26 Mar 2001 */
2063 extern void AFNI_finalize_read_Web_CB( Widget, XtPointer, MCW_choose_cbs * );
2064 
2065 extern void AFNI_fimmer_execute( Three_D_View * , int,int ) ;
2066 
2067 extern void AFNI_process_interrupts( Widget ) ;
2068 extern void AFNI_add_interruptable( Widget ) ;
2069 
2070 extern int AFNI_ts_in_library( MRI_IMAGE * tsim ) ;
2071 extern int AFNI_tsname_in_library( char *nam ) ; /* 10 May 2009 */
2072 
2073 extern THD_3dim_dataset * AFNI_fimmer_compute( Three_D_View * ,
2074                                                THD_3dim_dataset * , MRI_IMAGE *,
2075                                                MRI_IMAGE *, THD_session *,
2076                                                int,int ) ;
2077 
2078 extern void AFNI_fimmer_redisplay( int , Three_D_View * , THD_3dim_dataset * ) ;
2079 
2080 extern void AFNI_crosshair_color_CB( MCW_arrowval * , XtPointer ) ;
2081 extern void AFNI_crosshair_gap_CB  ( MCW_arrowval * , XtPointer ) ;
2082 extern void AFNI_time_index_CB     ( MCW_arrowval * , XtPointer ) ;
2083 extern void AFNI_marks_disp_av_CB  ( MCW_arrowval * , XtPointer ) ;
2084 extern void AFNI_resam_vox_av_CB   ( MCW_arrowval * , XtPointer ) ;
2085 extern char * AFNI_resam_texter    ( MCW_arrowval * , XtPointer ) ;
2086 extern void   AFNI_resam_av_CB     ( MCW_arrowval * , XtPointer ) ;
2087 
2088 extern void   AFNI_bucket_CB      ( MCW_arrowval * , XtPointer ) ; /* 30 Nov 1997 */
2089 extern char * AFNI_bucket_label_CB( MCW_arrowval * , XtPointer ) ;
2090 extern void AFNI_force_bucket_label_resize( int ) ;                /* 23 Mar 2018 */
2091 
2092 extern void   AFNI_vedit_CB       ( MCW_arrowval * , XtPointer ) ; /* 05 May 2009 */
2093 extern int    AFNI_icor_setref    ( Three_D_View *im3d ) ;
2094 extern void   AFNI_icor_setref_locked( Three_D_View *im3d ) ;      /* 15 May 2009 */
2095 
2096 extern int    AFNI_icor_setref_anatijk( Three_D_View *, int,int,int ) ;      /* 17 Mar 2010 */
2097 extern int    AFNI_icor_setref_xyz    ( Three_D_View *, float,float,float );
2098 extern int    AFNI_gicor_setref_xyz   ( Three_D_View *, float,float,float ); /* 23 Dec 2009 */
2099 extern void   AFNI_gicor_setapair_xyz ( Three_D_View *, float,float,float );    /* Apr 2013 */
2100 
2101 extern RwcBoolean AFNI_refashion_dataset( Three_D_View * ,
2102                                        THD_3dim_dataset *, THD_dataxes * , int ) ;
2103 
2104 #define REDISPLAY_OPTIONAL 0
2105 #define REDISPLAY_OVERLAY  1
2106 #define REDISPLAY_ALL      2
2107 #define REDISPLAY_FLASH    3
2108 
2109 extern void AFNI_set_viewpoint( Three_D_View * , int,int,int , int ) ;
2110 extern void AFNI_set_index_viewpoint( Three_D_View *, int, int );
2111                                                             /*ZSS July 2010 */
2112 extern void AFNI_redisplay_func( Three_D_View * ) ;          /* 05 Mar 2002 */
2113 extern void AFNI_view_setter( Three_D_View *, MCW_imseq *) ; /* 26 Feb 2003 */
2114 extern void AFNI_range_setter( Three_D_View *, MCW_imseq *); /* 04 Nov 2003 */
2115 extern void AFNI_redisplay_func_ignore( int ) ;              /* 03 Jun 2014 */
2116 extern void AFNI_redisplay_func_all( Three_D_View *im3d ) ;  /* 03 Jul 2014 */
2117 
2118 extern void AFNI_coord_filer_setup( Three_D_View *im3d ) ;   /* 07 May 2010 */
2119 
2120 extern XmString AFNI_crosshair_label( Three_D_View * ) ;
2121 extern XmString AFNI_range_label( Three_D_View * ) ;
2122 extern XmString AFNI_autorange_label( Three_D_View * ) ;
2123 
2124 extern void AFNI_range_bbox_CB( Widget , XtPointer , XtPointer ) ;
2125 extern void AFNI_perc_bbox_CB( Widget , XtPointer , XtPointer ) ;
2126 extern void AFNI_range_av_CB  ( MCW_arrowval * , XtPointer ) ;
2127 extern void AFNI_inten_bbox_CB( Widget , XtPointer , XtPointer ) ;
2128 extern void AFNI_wrap_bbox_CB( Widget , XtPointer , XtPointer ) ;
2129 extern void AFNI_xhall_bbox_CB( Widget , XtPointer , XtPointer ) ;
2130 
2131 extern void AFNI_see_ttatlas_CB( Widget, XtPointer, XtPointer ) ; /* 25 Jul 2001 */
2132 
2133 extern void AFNI_range_rotate_av_CB( MCW_arrowval *, XtPointer ); /* 30 Mar 2001 */
2134 extern void AFNI_hintize_pbar( MCW_pbar * ,  float ) ;            /* 30 Mar 2001 */
2135 
2136 #define AFNI_pbar_topset(iq,val)           \
2137  do{ MCW_choose_cbs cb ;                   \
2138      cb.fval = val ;                       \
2139      AFNI_set_pbar_top_CB(NULL,(iq),&cb) ; \
2140  } while(0)
2141 
2142 #define FIM_RANGE(iq)              \
2143  ( ((iq)->vinfo->fim_range != 0.0) \
2144    ? (iq)->vinfo->fim_range        \
2145    : (iq)->vinfo->fim_autorange )
2146 
2147 #define HINTIZE_pbar(iq)  \
2148   AFNI_hintize_pbar( (iq)->vwid->func->inten_pbar , FIM_RANGE(iq) )
2149 
2150 extern void AFNI_reset_func_range( Three_D_View * ) ;
2151 
2152 extern int AFNI_first_tog( int , Widget * ) ;
2153 extern int AFNI_all_tog  ( int , Widget * ) ;
2154 extern void AFNI_set_tog ( int , int , Widget * ) ;
2155 
2156 extern void AFNI_make_ptmask( int , int , AFNI_ovtemplate * ) ;
2157 extern void AFNI_make_tagmask( int , int , AFNI_ovtemplate * ) ; /* Oct 1998 */
2158 
2159 extern void AFNI_initialize_view( THD_3dim_dataset * , Three_D_View * ) ;
2160 
2161 extern void AFNI_setup_viewing(  Three_D_View * , RwcBoolean ) ;
2162 extern void AFNI_modify_viewing( Three_D_View * , RwcBoolean ) ;
2163 extern void AFNI_set_rinfo_labels( Three_D_View *im3d ) ;      /* 11 Mar 2020 */
2164 
2165 extern void AFNI_setup_thrstat( Three_D_View *im3d , int force ) ; /* 27 Jun 2019 */
2166 
2167 extern THD_warp * AFNI_find_warp( THD_3dim_dataset * ,
2168                                   THD_3dim_dataset *  ) ; /* 28 Aug 2002 */
2169 
2170 extern int AFNI_can_transform_vector( THD_3dim_dataset *, THD_3dim_dataset * );
2171 
2172 extern THD_fvec3 AFNI_transform_vector( THD_3dim_dataset * ,
2173                                         THD_fvec3 , THD_3dim_dataset * ) ;
2174 
2175 extern THD_warp * AFNI_make_warp( Three_D_View * ) ;
2176 
2177 extern RwcBoolean AFNI_marks_quality_check( RwcBoolean , Three_D_View * ) ;
2178 
2179 extern THD_3dim_dataset * AFNI_init_warp( Three_D_View * ,
2180                                           THD_3dim_dataset * ,
2181                                           THD_warp * , float  ) ;
2182 
2183 extern void AFNI_handler( char * ) ;
2184 
2185 extern void AFNI_thr_scale_CB( Widget , XtPointer , XtPointer ) ;
2186 extern void AFNI_set_thr_pval( Three_D_View * im3d ) ;
2187 extern void AFNI_thr_scale_drag_CB( Widget , XtPointer , XtPointer ) ;
2188 
2189 extern float AFNI_get_autothresh( Three_D_View * ) ;        /* 05 Mar 2007 */
2190 extern void AFNI_set_threshold( Three_D_View * , float  ) ;
2191 
2192 extern void AFNI_inten_pbar_CB( MCW_pbar * , XtPointer , int ) ;
2193 extern void AFNI_inten_av_CB( MCW_arrowval * , XtPointer ) ;
2194 extern char * AFNI_inten_av_texter ( MCW_arrowval *, XtPointer ) ; /* 30 Jan 2003 */
2195 
2196 extern void   AFNI_set_thresh_top( Three_D_View * , float ) ;
2197 extern void   AFNI_set_thresh_itop( Three_D_View * , int ) ;
2198 extern char * AFNI_thresh_tlabel_CB( MCW_arrowval * , XtPointer ) ;
2199 extern void   AFNI_thresh_top_CB( MCW_arrowval * , XtPointer ) ;
2200 
2201 extern void AFNI_set_valabel( FD_brick *, int, MRI_IMAGE *, char * ) ;
2202 
2203 extern void AFNI_init_niml( void ) ; /* 28 Feb 2002 */
2204 extern int  AFNI_have_niml( void ) ; /* 02 Feb 2007 */
2205 
2206 extern void AFNI_choose_surface_CB( Widget , XtPointer , XtPointer ) ; /* 19 Aug 2002 */
2207 extern void AFNI_update_surface_widgets( Three_D_View * ) ;
2208 extern void AFNI_update_all_surface_widgets( THD_session * ) ;
2209 
2210 extern void AFNI_init_suma_color( int, char *, char * ) ;   /* 06 Sep 2006 */
2211 extern void AFNI_get_suma_color( int, rgbyte *, rgbyte * ); /* 07 Sep 2006 */
2212 
2213 extern void AFNI_disable_suma_overlay( int ) ;  /* 16 Jun 2003 */
2214 
2215 #ifdef  __cplusplus
2216 }
2217 #endif
2218 
2219 /*-------------------------------------------------------------------
2220   Include prototypes for actual data warping and slicing here.
2221 --------------------------------------------------------------------*/
2222 
2223 #include "afni_warp.h"
2224 
2225 #ifdef  __cplusplus
2226 extern "C" {
2227 #endif
2228 
2229 /*------------------------------------------------------------------*/
2230 
2231 extern THD_3dim_dataset * AFNI_follower_dataset( THD_3dim_dataset * ,
2232                                                  THD_3dim_dataset *  ) ;
2233 
2234 extern void AFNI_make_descendants( THD_sessionlist * ) ;
2235 extern void AFNI_mark_for_death  ( THD_sessionlist * ) ;
2236 extern void AFNI_andersonville   ( THD_sessionlist * , RwcBoolean ) ;
2237 extern void AFNI_force_adoption  ( THD_session * , RwcBoolean ) ;
2238 
2239 extern MRI_IMAGE * AFNI_func_overlay( int , FD_brick * ) ;
2240 
2241 extern MRI_IMAGE * AFNI_newfunc_overlay( MRI_IMAGE *, float,float ,  /* 30 Jan 2003 */
2242                                          MRI_IMAGE *,
2243                                          float,float, rgbyte *, int ) ;
2244 
2245 extern MRI_IMAGE * AFNI_newnewfunc_overlay( MRI_IMAGE *, float,float ,  /* 08 Dec 2014 */
2246                                          MRI_IMAGE *, MRI_IMAGE *,
2247                                          float,float, int,rgbyte *, int ,float,MCW_DC * ) ;
2248 
2249 extern void AFNI_alpha_fade_mri( Three_D_View *im3d , MRI_IMAGE *im ) ;
2250 
2251 extern void AFNI_syntax(void) ;
2252 extern void show_AFNI_version(void) ;  /* 26 Oct 2015 [rickr] */
2253 
2254 #define AFNI_DEFAULT_CURSOR 888
2255 #define AFNI_WAITING_CURSOR 999
2256 
2257 #define SHOW_AFNI_PAUSE AFNI_set_cursor( AFNI_WAITING_CURSOR )
2258 #define SHOW_AFNI_READY AFNI_set_cursor( AFNI_DEFAULT_CURSOR )
2259 
2260 extern void AFNI_set_cursor( int ) ;
2261 extern void AFNI_imseq_clearstat( Three_D_View * ) ;
2262 
2263 extern void AFNI_copy_statistics( THD_3dim_dataset * , THD_3dim_dataset * ) ;
2264 
2265 extern void AFNI_lock_button( Three_D_View * ) ;
2266 extern void AFNI_misc_button( Three_D_View * ) ;
2267 extern void AFNI_misc_CB    ( Widget , XtPointer , XtPointer );
2268 extern void AFNI_editenv_CB ( Widget , XtPointer , XtPointer );
2269 extern void AFNI_pvalue_CB  ( Widget , XtPointer , XtPointer );
2270 
2271 extern void AFNI_papers_CB  ( Widget , XtPointer , XtPointer );
2272 extern void AFNI_list_papers( Widget w ) ; /* 02 May 2014 */
2273 
2274 extern void AFNI_add_timeseries( MRI_IMAGE * ) ;
2275 extern void AFNI_replace_timeseries( MRI_IMAGE * ) ; /* 10 May 2009 */
2276 
2277 /*----------------------------------------------------------------*/
2278 /*----- stuff for dataset drawing, etc. (see afni_receive.c) -----*/
2279 
2280 /* masks for input to AFNI_receive_init */
2281 
2282 #define RECEIVE_DRAWING_MASK     1
2283 #define RECEIVE_VIEWPOINT_MASK   2
2284 #define RECEIVE_OVERLAY_MASK     4    /* not implemented yet */
2285 #define RECEIVE_DRAWNOTICE_MASK  8    /* 30 Mar 1999 */
2286 #define RECEIVE_DSETCHANGE_MASK  16   /* 31 Mar 1999 */
2287 #define RECEIVE_TTATLAS_MASK     32   /* 12 Jul 2001 */
2288 #define RECEIVE_REDISPLAY_MASK   64   /* 04 Mar 2002 */
2289 #define RECEIVE_FUNCDISPLAY_MASK 128  /* 05 Mar 2002 */
2290 #define RECEIVE_TIMEINDEX_MASK   256  /* 29 Jan 2003 */
2291 
2292 #define RECEIVE_ALL_MASK       ( 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128 | 256 )
2293 
2294 /* codes for input to AFNI_receive_control */
2295 
2296 #define DRAWING_LINES           BUTTON2_OPENPOLY
2297 #define DRAWING_FILL            BUTTON2_CLOSEDPOLY
2298 #define DRAWING_POINTS          BUTTON2_POINTS
2299 #define DRAWING_NODRAW          BUTTON2_NODRAW
2300 
2301 #ifdef MAIN
2302   char * DRAWING_strings[] = { "Lines" , "Filled" , "Points" , "No Draw" } ;
2303 #else
2304   extern char * DRAWING_strings[] ;
2305 #endif
2306 
2307 #define DRAWING_OVCINDEX        11
2308 #define DRAWING_X11PIXEL        12
2309 #define DRAWING_STARTUP         18
2310 #define DRAWING_SHUTDOWN        19
2311 #define DRAWING_LINEWIDTH       13   /* 08 Oct 2002 */
2312 
2313 #define VIEWPOINT_STARTUP       28
2314 #define VIEWPOINT_SHUTDOWN      29
2315 
2316 #define REDISPLAY_STARTUP       78   /* 04 Mar 2002 */
2317 #define REDISPLAY_SHUTDOWN      79
2318 
2319 #define FUNCDISPLAY_STARTUP     88   /* 05 Mar 2002 */
2320 #define FUNCDISPLAY_SHUTDOWN    89
2321 
2322 #define OVERLAY_STARTUP         38
2323 #define OVERLAY_SHUTDOWN        39
2324 
2325 #define DRAWNOTICE_STARTUP      48   /* 30 Mar 1999 */
2326 #define DRAWNOTICE_SHUTDOWN     49
2327 
2328 #define DSETCHANGE_STARTUP      58   /* 31 Mar 1999 */
2329 #define DSETCHANGE_SHUTDOWN     59
2330 
2331 #define TTATLAS_STARTUP         68   /* 11 Jul 2001 */
2332 #define TTATLAS_SHUTDOWN        69
2333 
2334 #define TIMEINDEX_STARTUP       98   /* 29 Jan 2003 */
2335 #define TIMEINDEX_SHUTDOWN      99
2336 
2337 #define EVERYTHING_SHUTDOWN    666
2338 
2339 /* modes for the process_drawing routine */
2340 
2341 #define SINGLE_MODE           1000
2342 #define PLANAR_MODE           2000
2343 #define THREED_MODE           3000
2344 #define SPECIAL_MODE        100000
2345 #define UNDO_MODE           102000
2346 #define INCVAL_MODE         103000
2347 #define DECVAL_MODE         104000
2348 
2349 extern void AFNI_toggle_drawing ( Three_D_View * ) ;
2350 extern int AFNI_receive_init    ( Three_D_View *, int, gen_func *, void *, char * ) ;
2351 extern void AFNI_receive_destroy( Three_D_View * ) ;
2352 extern int AFNI_receive_control ( Three_D_View *, int,int, void * ) ;
2353 
2354 extern void AFNI_process_viewpoint  ( Three_D_View * ) ;
2355 extern void AFNI_process_drawnotice ( Three_D_View * ) ;
2356 extern void AFNI_process_dsetchange ( Three_D_View * ) ;
2357 extern void AFNI_process_alteration ( Three_D_View * ) ;
2358 extern void AFNI_process_drawing    ( Three_D_View *, int,int, int *,int *,int * );
2359 extern void AFNI_process_ttatlas    ( Three_D_View * ) ;
2360 extern void AFNI_process_redisplay  ( Three_D_View * ) ; /* 04 Mar 2002 */
2361 extern void AFNI_process_funcdisplay( Three_D_View * ) ; /* 05 Mar 2002 */
2362 extern void AFNI_process_timeindex  ( Three_D_View * ) ; /* 29 Jan 2003 */
2363 
2364 extern void AFNI_do_bkgd_lab( Three_D_View * ) ;         /* 08 Mar 2002 */
2365 
2366 extern MRI_IMAGE * AFNI_ttatlas_overlay(Three_D_View *, int,int,int,int, MRI_IMAGE *) ;
2367 extern void reset_atlas_ovdset(void);
2368 extern THD_3dim_dataset *current_atlas_ovdset(void);
2369 
2370 extern void AFNI_3d_linefill( int  ,int * ,int * ,int * ,
2371                               int *,int **,int **,int ** ) ;
2372 
2373 /*-----------------------------------------------------------*/
2374 /*----------------- data for Talairach To -------------------*/
2375 /*--------- Some tables and some associated variables -------*/
2376 /*--------- have been moved to thd_atlas_query.c and --------*/
2377 /*--------- thd_atlas_query.h and included in libmri.a -------*/
2378 /*--------- ZSS Feb. 06 --------------------------------------*/
2379 
2380 extern void AFNI_talto_CB( Widget, XtPointer, MCW_choose_cbs * ) ;
2381 
2382 #define CAN_TALTO(q3d)                                           \
2383  ( (q3d)->vinfo->view_type == VIEW_TALAIRACH_TYPE ||             \
2384    AFNI_can_transform_vector(                                    \
2385       (q3d)->anat_dset[VIEW_TALAIRACH_TYPE] , (q3d)->anat_now ) )
2386 
2387 extern char * AFNI_ttatlas_query( Three_D_View * ) ; /* 10 Jul 2001 */
2388 extern void AFNI_pop_whereami_kill( Three_D_View * ) ;
2389 
2390 extern void TTRR_popup( Three_D_View * ) ;  /* 12 Jul 2001 */
2391 
2392 typedef struct {
2393    int num , meth , hemi ;
2394    byte *ttbrik ;
2395    short *ttval  ;
2396    byte *ttovc  ;
2397 } TTRR_params ;
2398 
2399 #define TTRR_METH_OFF 0
2400 #define TTRR_METH_GAF 1
2401 #define TTRR_METH_AGF 2
2402 #define TTRR_METH_FGA 3
2403 #define TTRR_METH_FAG 4
2404 
2405 #define TTRR_HEMI_LEFT  0
2406 #define TTRR_HEMI_RIGHT 1
2407 #define TTRR_HEMI_BOTH  2
2408 
2409 extern TTRR_params * TTRR_get_params(void) ;
2410 
2411 
2412 /*-------------------------------------*/
2413 /*--- driving AFNI programmatically ---*/
2414 
2415 extern int AFNI_driver( char *cmd ) ;                    /* 07 Nov 2001 */
2416 extern int AFNI_controller_code_to_index( char *code ) ;
2417 
2418 extern void AFNI_set_thr_index ( Three_D_View * , int ) ; /* 30 Nov 2005 */
2419 extern void AFNI_set_anat_index( Three_D_View * , int ) ;
2420 extern void AFNI_set_fim_index ( Three_D_View * , int ) ;
2421 
2422 extern void AFNI_driver_register( char * , int (*)(char *) ) ;
2423 
2424 /*-------------------------------------------------------*/
2425 /*--------------  registration of functions -------------*/
2426 
2427 /* sample 0D transform functions */
2428 
2429 extern void log10_func( int, float * ) ;
2430 extern void ssqrt_func( int, float * ) ;
2431 extern void absval_func( int, float * ) ;  /* 20 Oct 2020 */
2432 
2433 /* sample 1D transform functions */
2434 
2435 extern void osfilt3_func( int, double,double, float * ) ;
2436 extern void median3_func( int, double,double, float * ) ;
2437 extern void absfft_func ( int, double,double, float * ) ;
2438 extern void ztone_func  ( int, double,double, float * ) ; /* 02 Sep 2009 */
2439 extern void adpt_wt_mn9 ( int, double,double, float * ) ; /* 04 Sep 2009 */
2440 extern void adpt_wt_mn19( int, double,double, float * ) ; /* 29 Sep 2016 */
2441 extern void adpt_wt_mnXX( int, double,double, float * ) ; /* 30 Sep 2016 */
2442 extern void despike7_func  (int, double,double, float *); /* 07 Oct 2010 */
2443 extern void despike9_func  (int, double,double, float *); /* 08 Oct 2010 */
2444 extern void DES_despike25  (int, double,double, float *); /* 18 May 2018 */
2445 extern void hrfdecon_func  (int, double,double, float *); /* 29 Oct 2010 */
2446 
2447 extern void L1normalize_func( int, double,double, float * ) ; /* 03 Sep 2009 */
2448 extern void L2normalize_func( int, double,double, float * ) ; /* 03 Sep 2009 */
2449 
2450 /* 31 Jan 2002: sample slice_proj transform functions */
2451 
2452 extern float max_proj ( int, float * ) ;
2453 extern float min_proj ( int, float * ) ;
2454 extern float mean_proj( int, float * ) ;
2455 
2456 extern float extreme_proj( int, float * ) ;  /* 02 Feb 2002 */
2457 extern float osfilt_proj ( int, float * ) ;  /* 07 Dec 2007 */
2458 extern float mad_proj    ( int, float * ) ;  /* 07 Dec 2007 */
2459 
2460 extern float adaptive_weighted_mean( int , float * ) ;  /* 04 Sep 2009 */
2461 
2462 /* sample 2D transform functions */
2463 
2464 extern void median9_box_func ( int, int, double,double, float * ) ;
2465 extern void winsor9_box_func ( int, int, double,double, float * ) ;
2466 extern void osfilt9_box_func ( int, int, double,double, float * ) ;
2467 extern void fft2D_absfunc    ( int, int, double,double, float * ) ;
2468 extern void fft2D_phasefunc  ( int, int, double,double, float * ) ;
2469 extern void median21_box_func( int, int, double,double, float * ) ;
2470 extern void winsor21_box_func( int, int, double,double, float * ) ;
2471 extern void adapt_mean_21_box_func( int, int, double,double, float * ) ; /* 04 Sep 2009 */
2472 extern void sharpness2D_func( int nx , int ny , double dx, double dy, float *ar ) ;
2473 
2474 extern void AFNI_register_nD_function( int, char *, generic_func *, int ) ;
2475 extern void AFNI_register_nD_func_init( int nd , generic_func *fin ) ;
2476 
2477 #define AFNI_register_0D_function(cc,ff) \
2478    AFNI_register_nD_function(0,(char *)(cc),(generic_func *)(ff),0)
2479 #define AFNI_register_1D_function(cc,ff) \
2480    AFNI_register_nD_function(1,(char *)(cc),(generic_func *)(ff),0)
2481 #define AFNI_register_2D_function(cc,ff) \
2482    AFNI_register_nD_function(2,(char *)(cc),(generic_func *)(ff),0)
2483 
2484 #define AFNI_register_slice_proj(cc,ff)  \
2485    AFNI_register_nD_function(-1,(char *)(cc),(generic_func *)(ff),0)   /* 31 Jan 2002 */
2486 
2487 #define AFNI_register_1D_funcstr(cc,ff)  \
2488    AFNI_register_nD_function(1,(char *)(cc),(generic_func *)(ff),RETURNS_STRING)
2489 
2490 #if 0
2491 extern void AFNI_store_dset_index(int,int) ;  /* 18 May 2000 */
2492 extern int  AFNI_needs_dset_ijk(void) ;
2493 extern int  AFNI_needs_dset_tin(void) ;
2494 #endif
2495 
2496 extern int AFNI_gcd( int m , int n ) ;
2497 extern int AFNI_find_relprime_random( int n ) ;
2498 extern int AFNI_find_relprime_fixed( int n ) ;
2499 extern int AFNI_find_session( char *dname ) ; /* 04/06/2020 discoraj */
2500 
2501 /*-----------------------------------------------------------*/
2502 /*-----------------  initializations  -----------------------*/
2503 
2504 /*** June 1995: modified to allow input via XGetDefault ***/
2505 
2506 #define DEFAULT_NGRAY   80
2507 #define DEFAULT_GAMMA   1.888
2508 
2509 #define DEFAULT_NCOLOVR 40
2510 #define MAX_NCOLOVR     199
2511 
2512 /** color definitions and their labels (for 'choosers') **/
2513 
2514 #define DEFAULT_CROSSHAIR_COLOR  13   /* note indices start at 1! */
2515 #define DEFAULT_PRIMARY_COLOR    17   /* (0 index is "no color")  */
2516 #define DEFAULT_SECONDARY_COLOR  14
2517 
2518 #define DEFAULT_MARK_SIZE     8
2519 #define DEFAULT_MARK_GAP      3
2520 #define DEFAULT_CROSSHAIR_GAP 5
2521 
2522 /** initialization values (static values are used in afni.c only) **/
2523 
2524 void AFNI_load_defaults( Widget w ) ;
2525 
2526 #define RGBCYC_COUNT  20  /* 10 Jun 2002: number in RGB cycle */
2527 #define RGBCYC_FIRST  20  /*              index of first one */
2528 
2529 /** default colors **/  /* Used to be inside #ifdef MAIN */
2530 
2531 extern char * INIT_def_colovr[]; /* now initialized in pbar_color_defs.c */
2532 extern char * INIT_def_labovr[]; /* now initialized in pbar_color_defs.c */
2533 
2534 extern int INIT_ngray           ,
2535            INIT_ncolovr         ,
2536            INIT_crosshair_color ,
2537            INIT_marks1_color    ,
2538            INIT_marks2_color    ,
2539            INIT_marks_size      ,
2540            INIT_marks_gap       ,
2541            INIT_crosshair_gap   ,
2542            INIT_purge           ,
2543            INIT_posfunc         ,
2544            INIT_bigscroll       ,
2545            INIT_resam_anat      ,
2546            INIT_resam_func      ,
2547            INIT_resam_thr        ;
2548 
2549 extern float INIT_gamma         ,
2550              INIT_resam_vox      ;
2551 
2552 extern int INIT_ignore ;
2553 extern int INIT_tlrc_big ;
2554 extern int INIT_montage_periodic ;
2555 
2556 extern int INIT_fim_polort ;
2557 
2558 extern char * INIT_colovr[] ;
2559 extern char * INIT_labovr[] ;
2560 
2561 
2562 /**********************************************/
2563 /***** Setup constants for the color pbar *****/
2564 
2565 extern void AFNI_setup_inten_pbar( MCW_pbar * ) ;
2566 
2567 #define DEFAULT_PANES_POS  8
2568 #define DEFAULT_PANES_SGN  9
2569 #define NPANE_INIT 10
2570 
2571 
2572 extern float INIT_pval_pos[NPANE_MAX+1][NPANE_MAX+1] ;
2573 extern int   INIT_ovin_pos[NPANE_MAX+1][NPANE_MAX+1] ;
2574 
2575 extern float INIT_pval_sgn[NPANE_MAX+1][NPANE_MAX+1] ;
2576 extern int   INIT_ovin_sgn[NPANE_MAX+1][NPANE_MAX+1] ;
2577 extern int INIT_panes_pos , INIT_panes_sgn , INIT_panes_hide ;
2578 
2579 
2580 #ifdef  __cplusplus
2581 }
2582 #endif
2583 
2584 #endif /* _AFNI_HEADER_ */
2585