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_GRAPH_
8 #define _AFNI_HEADER_GRAPH_
9 
10 /*------------------------------------------------------------------------
11    This code is adapted from FD2, which was taken from FD.  It is
12    therefore by RW Cox, A Jesmanowicz, and EC Wong.  It may not be
13    copied or used for any commercial purpose without explicit permission.
14 --------------------------------------------------------------------------*/
15 #include "mrilib.h"
16 #include "coxplot.h"
17 #include "display.h"
18 #include "xutil.h"
19 #include "bbox.h"
20 #include "xim.h"
21 
22 #define WANT_AFNI_BITMAP
23 #ifdef WANT_AFNI_BITMAP
24 # include "logo.h"
25 #endif
26 
27 #if 0
28 # include "overfim.h"
29 # include "pcor.h"
30 #endif
31 
32 #ifdef SPARKY
33 #undef _POSIX_SOURCE
34 #endif
35 
36 #include <sys/types.h>
37 #include <sys/stat.h>
38 
39 #include <X11/X.h>
40 #include <X11/cursorfont.h>
41 #include <X11/Intrinsic.h>
42 
43 #include <Xm/PushB.h>
44 #include <Xm/Label.h>
45 #include <Xm/DrawingA.h>
46 #include <Xm/Protocols.h>
47 #include <Xm/AtomMgr.h>
48 #include <X11/Shell.h>
49 #include <Xm/MwmUtil.h>
50 #include <Xm/RowColumn.h>
51 #include <Xm/CascadeB.h>
52 #include <Xm/Separator.h>
53 
54 #ifdef  __cplusplus
55 extern "C" {
56 #endif
57 
58 #ifndef LABEL_ARG
59 #define LABEL_ARG(str) \
60   XtVaTypedArg , XmNlabelString , XmRString , (str) , strlen(str)+1
61 #endif
62 
63 #ifndef DONT_USE_OPTMENUS
64 #ifndef USE_OPTMENUS
65 #define USE_OPTMENUS
66 #endif
67 #endif
68 
69 #ifndef BE_AFNI_IGNORANT
70 #define BE_AFNI_AWARE
71 #endif
72 
73 #ifdef BE_AFNI_AWARE
74 #undef DONT_MANGLE_XYZ
75 #endif
76 
77 #define EXRONE(g) if( (g)->status->num_series < 2 ) EXRETURN
78 #define RONE(g,v) if( (g)->status->num_series < 2 ) RETURN(v)
79 
80 /***-----------------------------------------------------------------------***/
81 
82 #define GX_MAX    512                  /* Horizontal size of graph window */
83 #define GY_MAX    512                  /* Vertical size of graph window */
84 #define GR_DLX    4                    /* Horizontal delta to right edge */
85 #define GT_DLY    4                    /* Vertical delta to top edge */
86 #define GL_DLX    54                   /* Horizontal delta to left edge */
87 #define GB_DLY    52                   /* Vertical delta to bottom edge */
88 #define MAT_MAX   21                   /* Maximum array size of graphs */
89 #define COL_NUM   5                    /* Number of colors */
90 #define STR_L     256                  /* Max length of string */
91 
92 #define MIN_XSIZE 120
93 #define MIN_YSIZE 120
94 
95 #define XSPACE  8
96 #define YSPACE  20
97 #define MYTXT   14
98 #define MDX1    (GL_DLX + 1)
99 #define MDY1    (GB_DLY + 1)
100 
101 /***-----------------------------------------------------------------------***/
102 typedef struct {
103    Widget fim_menu , fim_cbut ;
104    Widget fim_plot_menu , fim_plot_cbut ,
105           fim_plot_firstref_pb , fim_plot_allrefs_pb ,
106           fim_plot_firstort_pb , fim_plot_allorts_pb  ;
107    Widget fim_editref_menu , fim_editref_cbut ,
108           fim_editref_clear_pb , fim_editref_equals_pb ,
109           fim_editref_add_pb , fim_editref_smooth_pb ,
110           fim_editref_read_pb , fim_editref_write_pb , fim_editref_store_pb ,
111           fim_editref_setshift_pb , fim_editort_clear_pb ,
112           fim_polort_choose_pb , fim_bkthr_choose_pb ;
113    MCW_bbox *fim_editref_winaver_bbox ;  /* 26 Jan 2004 */
114    Widget fim_ignore_menu   , fim_ignore_cbut ,
115           fim_ignore_down_pb, fim_ignore_up_pb , fim_ignore_choose_pb ;
116    Widget fim_pickref_pb , fim_pickort_pb , fim_execute_pb , fim_execfimp_pb ;
117    Widget fimp_setdefault_pb , fimp_setall_pb , fimp_unsetall_pb ;
118    Widget fim_pickdset_pb ;
119 
120    MCW_bbox * fim_opt_bbox , * fimp_opt_bbox ;
121    MCW_bbox * fimp_user_bbox ;
122 
123 #ifdef USE_OPTMENUS
124    MCW_arrowval * fim_ignore_choose_av ;
125    MCW_arrowval * fim_polort_choose_av ;
126 #endif
127 
128    XtCallbackProc cbfunc ;
129    XtPointer      parent ;
130 } FIM_menu ;
131 /***-----------------------------------------------------------------------***/
132 
133 #ifndef HAVE_GET_PTR_TYPEDEF
134 #  define HAVE_GET_PTR_TYPEDEF
135    typedef XtPointer (*get_ptr)() ;  /* function type */
136 #endif
137 
138 typedef struct {
139       int num_total , num_series ;  /* # of images, # in "series" */
140       int nx , ny , nz ;            /* image dimensions */
141 
142       void (* send_CB)() ;   /* callback, if non_NULL */
143 
144       MCW_function_list *transforms0D ;
145       MCW_function_list *transforms1D ;
146 
147       char namecode[32] ;
148 
149       XtPointer parent , aux ;
150 } MCW_grapher_status ;
151 
152 typedef struct {
153      char * wcsuffix ;
154 } GRA_miscellaneous ;
155 
156 #ifdef MAIN
157    GRA_miscellaneous Grapher_Stuff = { NULL } ;
158 #else
159    extern GRA_miscellaneous Grapher_Stuff ;
160 #endif
161 
162 #define MCW_GRAPHER_TYPE 3741
163 
164 #define GRA_VALID(gr) ((gr)!=NULL && (gr)->type==MCW_GRAPHER_TYPE && (gr)->valid>0)
165 #define GRA_REALZ(gr) ((gr)!=NULL && (gr)->type==MCW_GRAPHER_TYPE && (gr)->valid>1)
166 
167 /*--- stuff for changing the graph length: pinning ---*/
168 
169 #define MIN_PIN    2
170 #define MAX_PIN    9999
171 #define MAX_STRIDE 9
172 
173 /* x-axis plotting range is from time index NBOT to NTOP-1 */
174 
175 #define NBOT(gr) ( ((gr)->pin_bot < (gr)->status->num_series) ? (gr)->pin_bot : 0 )
176 
177 #define NTOP(gr) ( ((gr)->pin_top >= MIN_PIN && (gr)->pin_top < (gr)->status->num_series) \
178                   ? (gr)->pin_top : (gr)->status->num_series                              )
179 
180 #define NSTRIDE(gr) ( (gr)->pin_stride )
181 
182 #define NIGNORE(gr) (gr)->init_ignore
183 
184 /* #define NABC(a,b,c) ( (int)ceil( ((b)-(a))/(double)(c) ) ) */
185 #define NABC(a,b,c) ( ((b) - (a) - 1) / (c) + 1 )
186 #define NPTS(gr)    NABC( NBOT(gr) , NTOP(gr) , NSTRIDE(gr) )
187 
188 /* data plotting range is from time index TBOT to TTOP-1 */
189 
190 #define TBOT(gr) NBOT(gr)
191 #define TTOP(gr) NTOP(gr)
192 
193 #define TPTS(gr) (TTOP(gr)-TBOT(gr))   /* number of data points visible in graph */
194 
195 #define ISONE(g) ( TPTS(g) < 2 )       /* if only 1 data point is visible */
196 
197 /*-- 22 Apr 1997:
198      user supplied strings (tuser) for each graph subwindow --*/
199 
200 #define GRA_NULL_tuser(gr)                     \
201    do{ int iq,jq ;                             \
202        for( iq=0 ; iq < MAT_MAX ; iq++ )       \
203           for( jq=0 ; jq < MAT_MAX ; jq++ )    \
204              (gr)->tuser[iq][jq] = NULL ; } while(0)
205 
206 #define GRA_CLEAR_tuser(gr)                    \
207    do{ int iq,jq ;                             \
208        for( iq=0 ; iq < MAT_MAX ; iq++ )       \
209           for( jq=0 ; jq < MAT_MAX ; jq++ )    \
210              myXtFree((gr)->tuser[iq][jq]) ; } while(0)
211 
212 /******** 16 June 1997:  Stuff for choosing colors in the graph ******/
213 
214 #include "pbar_color_defs.h"
215 
216 #define NUM_FIXED_COLORS_SETTING 4
217 #define NUM_COLOR_ITEMS          10
218 #define PMPLOT_INDEX             9    /* 02 Jun 2020 */
219 
220 #define BRIGHTEST_COLOR   -1
221 #define DARKEST_COLOR     -2
222 #define REDDEST_COLOR     -3
223 #define GREENEST_COLOR    -4
224 #define BLUEST_COLOR      -5
225 
226 #define DEFAULT_GR_BOXES_COLOR    DARKEST_COLOR
227 #define DEFAULT_GR_BACKG_COLOR    BRIGHTEST_COLOR
228 #define DEFAULT_GR_GRID_COLOR     COL_yell_oran
229 #define DEFAULT_GR_TEXT_COLOR     DARKEST_COLOR
230 #define DEFAULT_GR_DATA_COLOR     DARKEST_COLOR
231 #define DEFAULT_GR_IDEAL_COLOR    REDDEST_COLOR
232 #define DEFAULT_GR_ORT_COLOR      GREENEST_COLOR
233 #define DEFAULT_GR_IGNORE_COLOR   BLUEST_COLOR
234 #define DEFAULT_GR_DPLOT_COLOR    REDDEST_COLOR
235 #define DEFAULT_GR_PMPLOT_COLOR   COL_cyan    /* 02 Jun 2020 */
236 
237 #define INVERTT_GR_BOXES_COLOR    BRIGHTEST_COLOR
238 #define INVERTT_GR_BACKG_COLOR    DARKEST_COLOR
239 #define INVERTT_GR_GRID_COLOR     COL_gry_bb
240 #define INVERTT_GR_TEXT_COLOR     BRIGHTEST_COLOR
241 #define INVERTT_GR_DATA_COLOR     BRIGHTEST_COLOR
242 #define INVERTT_GR_IDEAL_COLOR    REDDEST_COLOR
243 #define INVERTT_GR_ORT_COLOR      GREENEST_COLOR
244 #define INVERTT_GR_IGNORE_COLOR   BLUEST_COLOR
245 #define INVERTT_GR_DPLOT_COLOR    REDDEST_COLOR
246 #define INVERTT_GR_PMPLOT_COLOR   COL_cyan    /* 02 Jun 2020 */
247 
248 #ifdef MAIN
249 int INIT_GR_boxes_color  = DEFAULT_GR_BOXES_COLOR  ,
250     INIT_GR_backg_color  = DEFAULT_GR_BACKG_COLOR  ,
251     INIT_GR_grid_color   = DEFAULT_GR_GRID_COLOR   ,
252     INIT_GR_text_color   = DEFAULT_GR_TEXT_COLOR   ,
253     INIT_GR_data_color   = DEFAULT_GR_DATA_COLOR   ,
254     INIT_GR_ideal_color  = DEFAULT_GR_IDEAL_COLOR  ,
255     INIT_GR_ort_color    = DEFAULT_GR_ORT_COLOR    ,
256     INIT_GR_ignore_color = DEFAULT_GR_IGNORE_COLOR ,
257     INIT_GR_dplot_color  = DEFAULT_GR_DPLOT_COLOR  ,
258     INIT_GR_pmplot_color = DEFAULT_GR_PMPLOT_COLOR  ;    /* 02 Jun 2020 */
259 
260 int INIT_GR_boxes_thick  = 0 ,  /* if >= 0, then gets a 'Thick Lines' */
261     INIT_GR_grid_thick   = 0 ,  /* and these are initial settings */
262     INIT_GR_data_thick   = 1 ,
263     INIT_GR_ideal_thick  = 1 ,
264     INIT_GR_ort_thick    = 1 ,
265     INIT_GR_dplot_thick  = 1 ,
266     INIT_GR_pmplot_thick = 1  ;
267 
268 int INIT_GR_ggap         = 4 ;  /* 27 May 1999 */
269 int INIT_GR_gthick       = 2 ;  /* 06 Oct 2004 */
270 int INIT_GR_gmat         = 3 ;  /* 10 Feb 2003 */
271 
272 int fixed_colors[NUM_FIXED_COLORS_SETTING][NUM_COLOR_ITEMS] =
273      {
274        { DEFAULT_GR_BOXES_COLOR,
275          DEFAULT_GR_BACKG_COLOR,
276          DEFAULT_GR_GRID_COLOR,
277          DEFAULT_GR_TEXT_COLOR,
278          DEFAULT_GR_DATA_COLOR,
279          DEFAULT_GR_IDEAL_COLOR,
280          DEFAULT_GR_ORT_COLOR,
281          DEFAULT_GR_IGNORE_COLOR,
282          DEFAULT_GR_DPLOT_COLOR,
283          DEFAULT_GR_PMPLOT_COLOR   } ,
284        { INVERTT_GR_BOXES_COLOR,
285          INVERTT_GR_BACKG_COLOR,
286          INVERTT_GR_GRID_COLOR,
287          INVERTT_GR_TEXT_COLOR,
288          INVERTT_GR_DATA_COLOR,
289          INVERTT_GR_IDEAL_COLOR,
290          INVERTT_GR_ORT_COLOR,
291          INVERTT_GR_IGNORE_COLOR,
292          INVERTT_GR_DPLOT_COLOR,
293          INVERTT_GR_PMPLOT_COLOR   } ,
294        { COL_dk_blue ,
295          COL_yellow ,
296          COL_blue_cyan ,
297          COL_dk_blue ,
298          COL_dk_blue ,
299          DEFAULT_GR_IDEAL_COLOR,
300          COL_rbgyr20_07 ,
301          DEFAULT_GR_IGNORE_COLOR,
302          DEFAULT_GR_DPLOT_COLOR,
303          DEFAULT_GR_PMPLOT_COLOR   } ,
304        { COL_yell_oran ,
305          COL_dk_blue ,
306          COL_lt_blue2 ,
307          COL_yellow ,
308          COL_yellow ,
309          COL_hotpink ,
310          COL_green ,
311          COL_blue_cyan ,
312          COL_red,
313          COL_violet                  } ,
314      } ;
315 #else
316 extern int INIT_GR_boxes_color  ,
317            INIT_GR_backg_color  ,
318            INIT_GR_grid_color   ,
319            INIT_GR_text_color   ,
320            INIT_GR_data_color   ,
321            INIT_GR_ideal_color  ,
322            INIT_GR_ort_color    ,
323            INIT_GR_ignore_color ,
324            INIT_GR_dplot_color  ,
325            INIT_GR_pmplot_color  ;
326 
327 extern int INIT_GR_boxes_thick ,
328            INIT_GR_grid_thick  ,
329            INIT_GR_data_thick  ,
330            INIT_GR_ideal_thick ,
331            INIT_GR_ort_thick   ,
332            INIT_GR_dplot_thick ,
333            INIT_GR_pmplot_thick  ;
334 
335 extern int INIT_GR_ggap ;
336 extern int INIT_GR_gthick ;  /* 06 Oct 2004 */
337 extern int INIT_GR_gmat ;
338 extern int fixed_colors[NUM_FIXED_COLORS_SETTING][NUM_COLOR_ITEMS] ;
339 #endif /* MAIN */
340 
341 #define FG_COLOR(gr)     ((gr)->color_index[0])
342 #define BG_COLOR(gr)     ((gr)->color_index[1])
343 #define GRID_COLOR(gr)   ((gr)->color_index[2])
344 #define TEXT_COLOR(gr)   ((gr)->color_index[3])
345 #define DATA_COLOR(gr)   ((gr)->color_index[4])
346 #define IDEAL_COLOR(gr)  ((gr)->color_index[5])
347 #define ORT_COLOR(gr)    ((gr)->color_index[6])
348 #define IGNORE_COLOR(gr) ((gr)->color_index[7])
349 #define DPLOT_COLOR(gr)  ((gr)->color_index[8])
350 #define PMPLOT_COLOR(gr) ((gr)->color_index[9])    /* 02 Jun 2020 */
351 
352 static char *gr_color_label[NUM_COLOR_ITEMS] = {
353   "Boxes " , "BackG " , "Grid  " , "Text  " ,
354   "Data  " , "Ideal " , "Ort   " , "Ignore" , "Dplot " , "PMplot"
355 } ;
356 
357 static char *gr_color_hint[NUM_COLOR_ITEMS] = {
358   "Color for boxes around graphs" ,
359   "Background color"              ,
360   "Vertical Grid color"           ,
361   "Color for Text"                ,
362   "Color for Data graphs"         ,
363   "Color for Ideal overplot graph",
364   "Color for Ort overplot graph"  ,
365   "Color for Ignored timepoints"  ,
366   "Color for Dplot overlay"       ,
367   "Color for PMplot overlay"
368 } ;
369 
370 static int gr_setup_default = 1 ;
371 static int gr_color_default[NUM_COLOR_ITEMS] ;
372 static int gr_thick_default[NUM_COLOR_ITEMS] ;
373 
374 static int gr_points_default[NUM_COLOR_ITEMS] = {
375   -1 , -1 , -1 , -1 ,
376    0 , -1 , -1 , -1 , 0 , 0
377 } ;
378 
379 static int gr_color_start[NUM_COLOR_ITEMS] = {
380   1 , 1 , 0 , 1 ,        /* 0 = start with 'none' */
381   1 , 1 , 1 , 1 , 1 , 1  /* 1 = skip 'none' color */
382 } ;
383 
384 static int gr_unfim[NUM_COLOR_ITEMS] = { 0,0,0,0,0,1,1,1,0,0 } ;  /* Oct 1999 */
385 
386 #define GRA_COLOR(cd)                                              \
387    ( ((cd) == BRIGHTEST_COLOR)  ? (grapher->dc->ovc->ov_brightest) \
388     :((cd) == DARKEST_COLOR  )  ? (grapher->dc->ovc->ov_darkest)   \
389     :((cd) == REDDEST_COLOR   ) ? (grapher->dc->ovc->ov_reddest)   \
390     :((cd) == GREENEST_COLOR )  ? (grapher->dc->ovc->ov_greenest)  \
391     :((cd) == BLUEST_COLOR  )   ? (grapher->dc->ovc->ov_bluest)    \
392     :(cd) )
393 
394 #define FG_THICK(gr)      ((gr)->thick_index[0] * (gr)->gthick)
395 #define BG_THICK(gr)      ((gr)->thick_index[1] * (gr)->gthick)
396 #define GRID_THICK(gr)    ((gr)->thick_index[2] * (gr)->gthick)
397 #define TEXT_THICK(gr)    ((gr)->thick_index[3] * (gr)->gthick)
398 #define DATA_THICK(gr)    ((gr)->thick_index[4] * (gr)->gthick)
399 #define IDEAL_THICK(gr)   ((gr)->thick_index[5] * (gr)->gthick)
400 #define ORT_THICK(gr)     ((gr)->thick_index[6] * (gr)->gthick)
401 #define IGNORE_THICK(gr)  ((gr)->thick_index[7] * (gr)->gthick)
402 #define DPLOT_THICK(gr)   ((gr)->thick_index[8] * (gr)->gthick)
403 #define PMPLOT_THICK(gr)  ((gr)->thick_index[9] * (gr)->gthick)    /* 02 Jun 2020 */
404 
405 #define FG_IS_THICK(gr)     ((gr)->thick_index[0] != 0)
406 #define BG_IS_THICK(gr)     ((gr)->thick_index[1] != 0)
407 #define GRID_IS_THICK(gr)   ((gr)->thick_index[2] != 0)
408 #define TEXT_IS_THICK(gr)   ((gr)->thick_index[3] != 0)
409 #define DATA_IS_THICK(gr)   ((gr)->thick_index[4] != 0)
410 #define IDEAL_IS_THICK(gr)  ((gr)->thick_index[5] != 0)
411 #define ORT_IS_THICK(gr)    ((gr)->thick_index[6] != 0)
412 #define IGNORE_IS_THICK(gr) ((gr)->thick_index[7] != 0)
413 #define DPLOT_IS_THICK(gr)  ((gr)->thick_index[8] != 0)
414 #define PMPLOT_IS_THICK(gr) ((gr)->thick_index[9] != 0)  /* 02 Jun 2020 */
415 
416 #define DO_UPSAM(gr)        ((gr)->do_upsam)             /* 28 May 2020 */
417 
418 /* amount of resampling in plot_graphs                      28 May 2020 */
419 /*   www = width of graph box in pixels                                 */
420 /*   npt = number of time points being plotted                          */
421 /*   result is how many divisions to use for each line segment          */
422 /*   www/npt = pixels per data point, so if we had XUPSAM=www/npt       */
423 /*             we'd have a division for every x pixel;                  */
424 /*             instead, we use a slightly smaller value for XUPSAM      */
425 /* Note that if XUPSAM is returned as <= 1, no upsampling will be done. */
426 
427 #define XUPSAM(www,npt) ( (int)( 0.499f + 0.3456f*(www) / ((npt)+0.5f) ) )
428 
429 /** 01 Aug 1998: redefine _POINTS and add _LINES **/
430 
431 #define FG_POINTS(gr)     ((gr)->points_index[0] != 0)
432 #define BG_POINTS(gr)     ((gr)->points_index[1] != 0)
433 #define GRID_POINTS(gr)   ((gr)->points_index[2] != 0)
434 #define TEXT_POINTS(gr)   ((gr)->points_index[3] != 0)
435 #define DATA_POINTS(gr)   ((gr)->points_index[4] == 1 || (gr)->points_index[4] == 2)
436 #define IDEAL_POINTS(gr)  ((gr)->points_index[5] != 0)
437 #define ORT_POINTS(gr)    ((gr)->points_index[6] != 0)
438 #define IGNORE_POINTS(gr) ((gr)->points_index[7] != 0)
439 #define DPLOT_POINTS(gr)  ((gr)->points_index[8] != 0)
440 #define PMPLOT_POINTS(gr) 0                          /* 02 Jun 2020 */
441 
442 #define PMPLOT_MODE(gr)   ((gr)->points_index[9])    /* 02 Jun 2020 */
443 #define PMPLOT_OFF           1
444 #define PMPLOT_CURVES        2
445 #define PMPLOT_BARS          4
446 #define PMPLOT_FILL          8
447 
448 #define FG_LINES(gr)     ((gr)->points_index[0] != 1)
449 #define BG_LINES(gr)     ((gr)->points_index[1] != 1)
450 #define GRID_LINES(gr)   ((gr)->points_index[2] != 1)
451 #define TEXT_LINES(gr)   ((gr)->points_index[3] != 1)
452 #define DATA_LINES(gr)   ((gr)->points_index[4] == 0 || (gr)->points_index[4] == 2)
453 #define IDEAL_LINES(gr)  ((gr)->points_index[5] != 1)
454 #define ORT_LINES(gr)    ((gr)->points_index[6] != 1)
455 #define IGNORE_LINES(gr) ((gr)->points_index[7] != 1)
456 #define DPLOT_LINES(gr)  ((gr)->points_index[8] != 1)
457 #define DATA_BOXED(gr)   ((gr)->points_index[4] >= 4)  /* 26 Jun 2007 - draw boxes */
458 
459 /* allow for interactive selection of box labeling method [11 Jan 2021] */
460 
461 #define DATA_BOXLAB_CODE(gr)  ( ((gr)->points_index[4] >= 8) * (gr)->points_index[4] )
462 #define DATA_BOXLAB_CODE_UP     8 /* labels at top of sub-graph window */
463 #define DATA_BOXLAB_CODE_ATOP  16 /* labels at top of each data point box */
464 #define DATA_BOXLAB_CODE_BOT   32 /* labels at bot of sub-graph window */
465 
466 /* callbacks for when the color or thickness of lines are changed */
467 
468 extern void GRA_color_CB( MCW_arrowval * , XtPointer ) ;
469 extern void GRA_thick_CB( Widget , XtPointer , XtPointer ) ;
470 
471 /**************************************************************/
472 
473 #define PLOTCODE_AUTOSCALE 1
474 
475 typedef struct {
476    int type , valid ;
477 
478    int gx_max , gy_max ;  /* window sizes */
479    int fWIDE  , fHIGH  ;
480 
481    get_ptr   getser ;
482    XtPointer getaux ;
483    MCW_grapher_status *status ;
484 
485    /* sub-graph stuff */
486 
487    int xorigin[MAT_MAX][MAT_MAX] , yorigin[MAT_MAX][MAT_MAX] ; /* coords of graphs*/
488    float pmin[MAT_MAX][MAT_MAX]  , pmax[MAT_MAX][MAT_MAX] ;    /* plot ranges */
489 
490    float tmean[MAT_MAX][MAT_MAX] , tbot[MAT_MAX][MAT_MAX] ,    /* statistics */
491          ttop[MAT_MAX][MAT_MAX]  , tstd[MAT_MAX][MAT_MAX]  ;
492    float dbot[MAT_MAX][MAT_MAX]  , dtop[MAT_MAX][MAT_MAX]  ;   /* 01 Jun 2020 */
493    float tsnr[MAT_MAX][MAT_MAX] ;                              /* 08 Jan 2021 */
494 
495    char * tuser[MAT_MAX][MAT_MAX] ;                            /* user strings */
496 
497    int mat,mat_max , xpoint,ypoint,zpoint ;
498    int grid_index , grid_spacing , grid_fixed ;
499    int xFD , yFD , gx,gy , xc,yc ;
500    int grid_color , common_base , init_ignore , polort ;
501    float fscale ;
502    int pin_top ;      /* 27 Apr 1997 - top index to show */
503    int pin_bot ;      /* 17 Mar 2004 - bottom index to show */
504    int pin_stride ;   /* 19 Jul 2013 - step thru data */
505    int HorZ ;         /* 05 Jan 1999 - horizontal line at 0? */
506 
507    int key_Nlock , key_lock_sum ;
508    int time_index ;
509 
510    int        ncen_line , nncen ;
511    XPoint    *cen_line ;
512    MRI_IMAGE *cen_tsim ;
513    MRI_IMAGE *xax_tsim ;  /* 09 Jan 1998 */
514    MRI_IMAGE *ave_tsim ;  /* 26 Jan 2004 */
515    void      *xax_dset ;  /* 09 Feb 2015 */
516    void      *xax_fdbr ;
517    MRI_IMAGE *xax_cen  ;  /* 12 Feb 2015 */
518 
519    int xx_text_1 , xx_text_2 , xx_text_2p , xx_text_3 , xx_text_igf ;
520 
521    /* external time-series stuff */
522 
523    MRI_IMARR *ref_ts , *ort_ts ;
524    int ref_ts_color , ort_ts_color ;
525    int ref_ts_plotall , ort_ts_plotall ;
526 
527    /* X11 stuff */
528 
529    Pixmap  fd_pxWind ;   /* graphs are drawn into this for speed's sake */
530    Widget  top_form ;    /* 24 May 2018 */
531    Widget  fdw_graph ;   /* top level widget */
532    Widget  draw_fd ;     /* drawing area */
533    Pixmap  glogo_pixmap ; /* for the corner */
534    int     glogo_width , glogo_height ;
535 
536    Widget option_rowcol ;  /* 29 Sep 2000: removed option_mbar */
537 
538    Widget opt_menu , opt_cbut ;
539    Widget opt_scale_menu    , opt_scale_cbut  ,
540           opt_scale_down_pb , opt_scale_up_pb , opt_scale_choose_pb ,
541           opt_scale_auto_pb , opt_scale_AUTO_pb;
542    Widget opt_mat_menu      , opt_mat_cbut ,
543           opt_mat_down_pb   , opt_mat_up_pb   ;
544    Widget opt_grid_menu     , opt_grid_cbut   ,
545           opt_grid_down_pb  , opt_grid_up_pb  ,
546           opt_grid_choose_pb , opt_pin_choose_pb ;
547    Widget opt_grid_auto_pb ;                      /* 02 Apr 2004 */
548    Widget opt_grid_HorZ_pb ;                      /* 05 Jan 1999 */
549    Widget opt_slice_menu    , opt_slice_cbut  ,
550           opt_slice_down_pb , opt_slice_up_pb ;
551 
552    Widget opt_colors_menu , opt_colors_cbut ;
553    MCW_arrowval * opt_color_av[NUM_COLOR_ITEMS] ;
554    MCW_bbox     * opt_thick_bbox[NUM_COLOR_ITEMS] ;
555    MCW_bbox     * opt_points_bbox[NUM_COLOR_ITEMS] ;
556    int color_index[NUM_COLOR_ITEMS] ;
557    int thick_index[NUM_COLOR_ITEMS] ;
558    int points_index[NUM_COLOR_ITEMS] ;
559    int fixed_colors_setting ;
560 
561    MCW_arrowval *opt_ggap_av ;   /* 12 Jan 1998 */
562    int ggap ;
563    MCW_arrowval *opt_gthick_av ; /* 06 Oct 2004 */
564    int gthick ;
565    MCW_arrowval *opt_upsam_av ;  /* 28 May 2020 */
566    int do_upsam ;
567 
568    Widget opt_color_up_pb   , opt_save_pb ,
569           opt_write_center_pb , opt_write_suffix_pb ;
570    Widget opt_quit_pb ;
571 
572    Widget opt_xaxis_menu , opt_xaxis_cbut ,        /* 09 Jan 1998 */
573           opt_xaxis_pick_pb , opt_xaxis_center_pb ,
574           opt_xaxis_clear_pb , opt_xaxis_dset_pb ;
575 
576    Widget opt_baseline_menu , opt_baseline_cbut ,   /* 07 Aug 2001 */
577           opt_baseline_setglobal_pb ,
578           opt_baseline_global_label  ;
579    float global_base ;
580 
581    MCW_bbox *opt_textgraph_bbox , *opt_baseline_bbox ;    /* 22 Sep 2000 */
582    int textgraph ;
583 
584 #ifdef USE_OPTMENUS
585    MCW_arrowval * opt_mat_choose_av , * opt_slice_choose_av ;
586 #else
587    Widget opt_mat_choose_pb , opt_slice_choose_pb ;
588 #endif
589 
590    MCW_arrowval * transform0D_av ;
591    generic_func * transform0D_func ;
592    int            transform0D_index , transform0D_flags ;
593 
594    MCW_arrowval * transform1D_av ;
595    generic_func * transform1D_func ;
596    int            transform1D_index , transform1D_flags ;
597 
598    Widget opt_dplot_menu , opt_dplot_cbut ;   /* 07 Aug 2001 */
599    MCW_bbox  * opt_dplot_bbox ;
600 
601    FIM_menu * fmenu ;
602 
603    Widget but3_menu , but3_label ;
604 
605    Widget dialog ;
606    MCW_arrowval * setshift_inc_av , * setshift_left_av , * setshift_right_av ;
607    float setshift_inc ;
608    int   setshift_left , setshift_right ;
609 
610    MCW_DC * dc ;
611 
612    int never_drawn ;
613    int button2_enabled ;
614    int mirror ;
615 
616    XtPointer parent ;
617 
618    float tmed[MAT_MAX][MAT_MAX] , tmad[MAT_MAX][MAT_MAX] ;    /* 08 Mar 2001 */
619    int   sbot[MAT_MAX][MAT_MAX] , stop[MAT_MAX][MAT_MAX] ;    /* 19 Mar 2004 */
620    float tbmv[MAT_MAX][MAT_MAX] ;                             /* 16 Oct 2009 */
621 
622    float xax_bot[MAT_MAX][MAT_MAX], xax_top[MAT_MAX][MAT_MAX] ; /* 12 Feb 2015 */
623 
624    XtIntervalId timer_id ;                          /* 04 Dec 2003 */
625    int          timer_func, timer_param, timer_delay ;
626 
627    int dont_setref ;                                /* 27 Jan 2004 */
628    int dont_redraw ;                                /* 27 Jan 2004 */
629    int tschosen ;                                   /* 31 Mar 2004 */
630 
631    MCW_arrowval *detrend_av ;
632    int           detrend ;                          /* 05 Dec 2012 */
633 
634    int           thresh_fade ;                      /* Mar 2013 */
635    MCW_bbox  *opt_tfade_bbox ;
636 
637 } MCW_grapher ;
638 
639 #define GRA_MAX_DETREND      7     /* max order for detrending */
640 
641 #define GRA_TIMERFUNC_INDEX  701
642 #define GRA_TIMERFUNC_BOUNCE 702
643 
644 extern void GRA_timer_CB( XtPointer , XtIntervalId * ) ; /* 04 Dec 2003 */
645 extern void GRA_timer_stop( MCW_grapher * ) ;
646 
647 #define BASELINE_INDIVIDUAL  1  /* 07 Aug 2001 */
648 #define BASELINE_COMMON      2
649 #define BASELINE_GLOBAL      4
650 
651 #define DPLOT_OFF            1  /* 07 Aug 2001 */
652 #define DPLOT_OVERLAY        2
653 #define DPLOT_PLUSMINUS      4
654 
655 static int fd_x    = 0 ;
656 static int fd_y[8] = {100, 130, 160, 190, 220, 250, 280, 310};
657 
658 /*--- "callback" data stuff: info about events in grapher window ---*/
659 
660 typedef struct {
661       int          reason ;              /* graCR_??? defined below */
662       XEvent *     event ;               /* may be NULL */
663       int          xcen,ycen,zcen, mat ; /* new x , new y , new matrix */
664       int          key ;                 /* keyvalue (if keypress type) */
665       XtPointer    userdata ;            /* misc type of data */
666 } GRA_cbs ;
667 
668 /* These codes must be distinct from isqCR_* in imseq.h */
669 
670 #define graCR_getstatus   7701
671 #define graCR_getseries   7702
672 #define graCR_getlabel    7703         /* 18 Apr 2011 */
673 
674 #define graCR_newxyzm     7711
675 #define graCR_keypress    7714
676 
677 #define graCR_pickref            7721
678 #define graCR_pickort            7722
679 #define graCR_clearfim           7723
680 #define graCR_timeseries_library 7724
681 #define graCR_clearort           7725
682 #define graCR_polort             7726  /* 27 May 1999 */
683 #define graCR_winaver            7727  /* 27 Jan 2004 */
684 
685 #define graCR_dofim       7731
686 
687 #define graCR_refequals   7741
688 #define graCR_refadd      7742
689 #define graCR_refsmooth   7745
690 #define graCR_reflibrary  7746
691 
692 #define graCR_setignore   7751
693 #define graCR_setindex    7752
694 
695 #define graCR_destroy        7777
696 #define graCR_raiseupthedead 7778  /* 17 Jun 2011 */
697 
698 #define graCR_button2_points 8801  /* Feb 1998 */
699 
700 /* The following were stolen from imseq.h, then
701    had the serial numbers changed to confuse issue */
702 
703 #define graDR_helptext    101
704 #define graDR_cursor      104
705 #define graDR_unrealize   105
706 #define graDR_realize     106
707 #define graDR_redraw      111
708 #define graDR_newdata     112
709 #define graDR_newlength   113  /* 22 Apr 1997 */
710 #define graDR_title       114
711 #define graDR_icon        118
712 
713 #define graDR_addref_ts   121
714 #define graDR_addort_ts   122
715 #define graDR_setignore   123
716 #define graDR_setindex    124
717 #define graDR_polort      125  /* 27 May 1999 */
718 #define graDR_winaver     126  /* 27 Jan 2004 */
719 
720 #define graDR_setmatrix   130  /* 22 Sep 2000 */
721 #define graDR_setgrid     131
722 #define graDR_setpinnum   graDR_newlength
723 #define graDR_setpintop   graDR_newlength
724 #define graDR_setpinbot   132  /* 17 Mar 2004 */
725 #define graDR_setpins     133  /* 19 Mar 2004 */
726 
727 #define graDR_destroy     666
728 
729 #define graDR_button2_enable  501  /* Feb 1998 */
730 #define graDR_button2_disable 502  /* Feb 1998 */
731 
732 #define graDR_fim_disable     503  /* Oct 1999 */
733 
734 #define graDR_mirror          504  /* Jul 2000 */
735 
736 #define graDR_setglobalbaseline 505 /* 07 Aug 2001 */
737 
738 /***-----------------------------------------------------------------------***/
739 
740 extern MCW_grapher * new_MCW_grapher( MCW_DC * , get_ptr , XtPointer ) ;
741 
742 extern void end_fd_graph_CB(Widget,XtPointer,XtPointer);
743 extern void fd_px_store(MCW_grapher *);
744 extern void plot_fdX(MCW_grapher *,int,int,int);
745 extern void scale_up(MCW_grapher *);
746 extern void scale_down(MCW_grapher *);
747 
748 extern void erase_fdw(MCW_grapher *);
749 extern void fd_txt(MCW_grapher *,int,int,char *);
750 extern void overlay_txt(MCW_grapher *,int,int,char *);
751 extern void plot_graphs(MCW_grapher *, int);
752 extern void draw_grids(MCW_grapher *);
753 extern void init_mat(MCW_grapher *);
754 extern void send_newinfo(MCW_grapher *);
755 extern void mat_down(MCW_grapher *);
756 extern void mat_up(MCW_grapher *);
757 extern void grid_down(MCW_grapher *);
758 extern void grid_up(MCW_grapher *);
759 
760 extern void text_graphs(MCW_grapher *) ;  /* 22 Sep 2000 */
761 
762 extern void redraw_graph( MCW_grapher * , int ) ;
763 extern void init_const( MCW_grapher * ) ;
764 
765 extern void GRA_small_circle( MCW_grapher * , int,int,int ) ;
766 extern void GRA_overlay_circle( MCW_grapher * , int,int,int ) ;
767 
768 extern void GRA_drawing_EV( Widget  , XtPointer , XEvent * , RwcBoolean * ) ;
769 extern void GRA_handle_keypress( MCW_grapher * , char * , XEvent * ) ;
770 extern void GRA_new_pixmap( MCW_grapher * , int,int,int ) ;
771 extern void GRA_opt_CB( Widget , XtPointer , XtPointer ) ;
772 extern void GRA_fim_CB( Widget , XtPointer , XtPointer ) ;
773 extern RwcBoolean drive_MCW_grapher( MCW_grapher * , int , XtPointer ) ;
774 
775 extern void GRA_scale_choose_CB   ( Widget , XtPointer , MCW_choose_cbs * ) ;
776 extern void GRA_grid_choose_CB    ( Widget , XtPointer , MCW_choose_cbs * ) ;
777 extern void GRA_pin_choose_CB     ( Widget , XtPointer , MCW_choose_cbs * ) ;
778 extern void GRA_wcsuffix_choose_CB( Widget , XtPointer , MCW_choose_cbs * ) ;
779 extern void GRA_refread_choose_CB ( Widget , XtPointer , MCW_choose_cbs * ) ;
780 extern void GRA_refwrite_choose_CB( Widget , XtPointer , MCW_choose_cbs * ) ;
781 extern void GRA_refstore_choose_CB( Widget , XtPointer , MCW_choose_cbs * ) ;
782 
783 #ifdef USE_OPTMENUS
784 extern void GRA_mat_choose_CB     ( MCW_arrowval * , XtPointer ) ;
785 extern void GRA_slice_choose_CB   ( MCW_arrowval * , XtPointer ) ;
786 extern void GRA_ignore_choose_CB  ( MCW_arrowval * , XtPointer ) ;
787 extern void GRA_polort_choose_CB  ( MCW_arrowval * , XtPointer ) ;
788 extern void GRA_fmenu_av_CB       ( MCW_arrowval * , XtPointer ) ;
789 extern void GRA_fix_optmenus      ( MCW_grapher * ) ;
790 #else
791 extern void GRA_mat_choose_CB     ( Widget , XtPointer , MCW_choose_cbs * ) ;
792 extern void GRA_slice_choose_CB   ( Widget , XtPointer , MCW_choose_cbs * ) ;
793 extern void GRA_ignore_choose_CB  ( Widget , XtPointer , MCW_choose_cbs * ) ;
794 extern void GRA_polort_choose_CB  ( Widget , XtPointer , MCW_choose_cbs * ) ;
795 #endif
796 extern void GRA_bkthr_choose_CB   ( Widget , XtPointer , MCW_choose_cbs * ) ;
797 
798 extern void GRA_setshift_startup( MCW_grapher * ) ;
799 extern void GRA_doshift( MCW_grapher * ) ;
800 extern void GRA_setshift_action_CB( Widget , XtPointer , XtPointer ) ;
801 
802 extern void GRA_transform_CB     ( MCW_arrowval * , XtPointer ) ;
803 extern char * GRA_transform_label( MCW_arrowval * , XtPointer ) ;
804 
805 extern void GRA_detrend_CB       ( MCW_arrowval * , XtPointer ) ;  /* 05 Dec 2012 */
806 
807 extern void GRA_ggap_CB  ( MCW_arrowval * , XtPointer ) ;
808 extern void GRA_gthick_CB( MCW_arrowval * , XtPointer ) ;  /* 06 Oct 2004 */
809 extern void GRA_upsam_CB ( MCW_arrowval * , XtPointer ) ;  /* 28 May 2020 */
810 
811 extern FIM_menu * AFNI_new_fim_menu( Widget , XtCallbackProc , int ) ;
812 
813 extern void GRA_redraw_overlay( MCW_grapher * ) ;
814 
815 extern void GRA_dplot_change_CB( Widget , XtPointer , XtPointer ) ;
816 
817 extern void GRA_winaver_CB     ( Widget , XtPointer , XtPointer ) ;  /* 27 Jan 2004 */
818 extern void GRA_winaver_setref ( MCW_grapher * ) ;
819 
820 extern void GRA_saver_CB( Widget , XtPointer , MCW_choose_cbs * ) ;
821 extern void GRA_file_pixmap( MCW_grapher * , char * ) ;
822 
823 extern void GRA_fixup_xaxis( MCW_grapher * , MRI_IMAGE * ) ;
824 extern void GRA_pick_xaxis_CB( Widget , XtPointer , MCW_choose_cbs * ) ;
825 
826 extern void GRA_mapmenu_CB( Widget , XtPointer , XtPointer ) ;
827 
828 extern void GRA_textgraph_CB( Widget , XtPointer , XtPointer ) ;  /* 22 Sep 2000 */
829 extern void GRA_baseline_CB ( Widget , XtPointer , XtPointer ) ;  /* 22 Sep 2000 */
830 
831 extern void GRA_tfade_CB( Widget , XtPointer , XtPointer ) ;  /* Mar 2013 */
832 
833  /* 07 Aug 2001 */
834 extern void GRA_finalize_global_baseline_CB( Widget,
835                                              XtPointer, MCW_choose_cbs * );
836 
837  /* 19 Dec 2018 */
838 extern int GRA_find_1D_transform( MCW_grapher *grapher , char *nam ) ;
839 extern void GRA_startup_1D_transform( char *nam ) ;
840 extern void GRA_set_1D_transform( MCW_grapher *grapher , char *nam ) ;
841 
842 /***-----------------------------------------------------------------------***/
843 
844 #ifdef  __cplusplus
845 }
846 #endif
847 
848 #endif
849