1 #undef MAIN
2 #include "afni.h"
3 #include <Xm/XmAll.h>
4
5 #define NUM_AV_FIRST 20 /* number of colormenus to create on first pass */
6
7 /*-- internal data structure --*/
8
9 typedef struct {
10 int reg_num , av_invert ;
11 MCW_arrowval **reg_av ; /* colormenus */
12 char **reg_label ; /* labels for menus */
13 short *reg_tto ; /* index into afni.h TTO_list */
14 short *reg_ttbrik ; /* which sub-brick in TTatlas+tlrc */
15 short *reg_ttval ; /* what value in TTatlas+tlrc */
16 short *reg_ttovc ; /* saved value of colormenu */
17
18 Widget shell , scrollw , workwin ;
19 MCW_arrowval *meth_av , *hemi_av ;
20
21 Three_D_View * im3d ;
22 MCW_DC *dc ;
23 } TTRR_controls ;
24
25 static TTRR_controls *ttc = NULL ;
26
27 /*-- prototypes for internal functions --*/
28 static void TTRR_setup_widgets( MCW_DC * dc );
29 static void TTRR_action_CB ( Widget, XtPointer, XtPointer ) ;
30 static void TTRR_delete_window_CB( Widget, XtPointer, XtPointer ) ;
31 static void TTRR_av_CB ( MCW_arrowval * , XtPointer ) ;
32
33 static void TTRR_load_file( char * ) ; /* 08 Aug 2002 */
34 static void TTRR_save_CB ( Widget , XtPointer , MCW_choose_cbs * ) ;
35 static void TTRR_load_CB ( Widget , XtPointer , MCW_choose_cbs * ) ;
36 static void fill_str(char * instr, char ch, int maxlength);
37 /*----------------------------------------------------------------------------
38 Routine to create widgets for the TT atlas rendering controls
39 ------------------------------------------------------------------------------*/
40
41 /***** definitions for the action area controls *****/
42
43 #define TTRR_clear_label "Clear"
44 #define TTRR_load_label "Load"
45 #define TTRR_save_label "Save"
46 #define TTRR_redraw_label "Redraw"
47 #define TTRR_done_label "Done"
48 #define TTRR_help_label "Help"
49
50 #define TTRR_clear_hint "Set all colors to 'none'"
51 #define TTRR_load_hint "Load colors from a file"
52 #define TTRR_save_hint "Save colors to a file"
53 #define TTRR_redraw_hint "Redraw using current colors"
54 #define TTRR_done_hint "Close this window"
55
56 #define NUM_TTRR_ACT 6
57
58 static MCW_action_item TTRR_act[] = {
59 { TTRR_clear_label , TTRR_action_CB, NULL,NULL, TTRR_clear_hint , 0 } ,
60 { TTRR_load_label , TTRR_action_CB, NULL,NULL, TTRR_load_hint , 0 } ,
61 { TTRR_save_label , TTRR_action_CB, NULL,NULL, TTRR_save_hint , 0 } ,
62 { TTRR_redraw_label, TTRR_action_CB, NULL,NULL, TTRR_redraw_hint,-1 } ,
63 { TTRR_done_label , TTRR_action_CB, NULL,NULL, TTRR_done_hint , 1 } ,
64 { TTRR_help_label , TTRR_action_CB, NULL,NULL, NULL , 0 }
65 } ;
66
67 #define NMETHOD 5
68 #define METHOD_OFF "Off"
69 #define METHOD_GAF "First atlas then Overlay"
70 #define METHOD_AGF "Last atlas then Overlay"
71 #define METHOD_FGA "Overlay then first atlas"
72 #define METHOD_FAG "Overlay then last atlas"
73
74 static char *METHOD_strings[NMETHOD] = {
75 METHOD_OFF , METHOD_GAF , METHOD_AGF , METHOD_FGA , METHOD_FAG
76 } ;
77
78 #define NHEMI 3
79 #define HEMI_LEFT "Left only"
80 #define HEMI_RIGHT "Right only"
81 #define HEMI_BOTH "Both"
82
83 static char *HEMI_strings[NHEMI] = { HEMI_LEFT , HEMI_RIGHT , HEMI_BOTH } ;
84
85 static char helpstring[] =
86 "The default list includes the original Talairach Daemon database\n"
87 "(kindly provided by Jack Lancaster and Peter Fox of RIC UTHSCSA,\n"
88 "the cytoarchitectonic and macrolabel atlases provided by Simon\n"
89 "Eickhoff and Karl Zilles, and the probabilistic atlases provided\n"
90 "Rutvik Desai.\n"
91 "\n"
92 "In the database, voxels may have multiple labels for a particular\n"
93 "atlas. For example, the voxels may a larger scale 'gyral' [G] name\n"
94 "and a finer scale 'area' [A] name. A list of all the labels for the\n"
95 "principal default atlas is presented here or from the command\n"
96 "line program, 'whereami -show_atlas_code', for any atlas.\n"
97 "\n"
98 "Method:\n"
99 " To enable display of the selected regions, you must choose the\n"
100 " Method to be something other than 'Off'. The other Method choices\n"
101 " determine the order in which color overlays take place. At this\n"
102 " time, there is no way to blend the colors from overlapping results.\n"
103 "\n"
104 "Hemisphere(s):\n"
105 " Use this to control which side(s) of the brain will have brain\n"
106 " region overlays. At this time, this option only affects the volume\n"
107 " rendering and has no effect on the 2D image viewers, in which\n"
108 " regions from both hemispheres will be rendered, regardless.\n"
109 "\n"
110 "The regional controls are to set the overlay colors; if a region's\n"
111 "color is set to 'none', then it will not be overlaid.\n"
112 "\n"
113 "* To change all overlay colors to 'none', use the Clear button.\n"
114 "* To save the color settings to a file, use the Save button.\n"
115 "* To read saved color settings from a file, use the Load button.\n"
116 "* Set environment variable AFNI_TTRR_SETUP to the name of a Save\n"
117 " color file, and it will be loaded when you first create this\n"
118 " control panel. See README.environment for more details.\n"
119 "* The Done button closes the control panel, but doesn't change colors.\n"
120 "\n"
121 "NOTES:\n"
122 " * At this time, the Redraw button has no functionality;\n"
123 " after you change the color settings in this window, you must\n"
124 " force an image redisplay to see the changes. In the 2D image\n"
125 " viewers, you can do this by turning 'See TT Atlas Regions'\n"
126 " off and on; in the volume renderer, you must press the 'Reload'\n"
127 " button to force the proper redisplay ('Draw' isn't enough).\n"
128 " * The region rendering only works if the dataset being drawn in the\n"
129 " 2D image viewers and/or Render Dataset plugin is in the +tlrc\n"
130 " coordinates sytem. The atlas regions are resample to the underlay\n"
131 " resolution.\n"
132 " * The atlas is only useful as a ROUGH guide to determining where you\n"
133 " are in any individual brain. Do not rely exclusively on the Atlas\n"
134 " for brain region labeling: you must use your knowledge, skills,\n"
135 " and abilities as well.\n"
136 "\n"
137 "-- RWCox - July 2001\n"
138 ;
139
140 /*----------------------------------------------------------------------------*/
New_TTRR_controls(char * atname)141 TTRR_controls * New_TTRR_controls(char *atname)
142 {
143 TTRR_controls * ttlc = NULL;
144 int i = 0, tto_count = 0;
145
146 if (!atname) return(ttlc);
147 if ((tto_count = atlas_n_points(atname)) <= 0) return(ttlc);
148
149 ttlc = myXtNew(TTRR_controls) ;
150 memset(ttlc, 0, sizeof(TTRR_controls));
151
152 ttlc->reg_av = (MCW_arrowval **)calloc(tto_count,sizeof(MCW_arrowval *));
153 ttlc->reg_label = (char **)calloc(tto_count,sizeof(char *));
154 ttlc->reg_tto = (short *)calloc(tto_count,sizeof(short));
155 ttlc->reg_ttbrik = (short *)calloc(tto_count,sizeof(short));
156 ttlc->reg_ttval = (short *)calloc(tto_count,sizeof(short));
157 ttlc->reg_ttovc = (short *)calloc(tto_count,sizeof(short));
158 return(ttlc);
159 }
160
Free_TTRR_controls(TTRR_controls * ttlc)161 void Free_TTRR_controls(TTRR_controls *ttlc)
162 {
163 if(!ttlc) return;
164 free(ttlc->reg_av);
165 free(ttlc->reg_label);
166 free(ttlc->reg_tto);
167 free(ttlc->reg_ttbrik);
168 free(ttlc->reg_ttval);
169 free(ttlc->reg_ttovc);
170 free(ttlc);
171 }
172
173
TTRR_resetup()174 void TTRR_resetup()
175 {
176 MCW_DC *dc;
177 if(!ttc) return; /* hasn't been setup yet, just wait for setup */
178 dc= ttc->dc;
179 Free_TTRR_controls(ttc);
180 ttc = NULL;
181 /* TTRR_setup_widgets(dc);*/
182 }
183
184
TTRR_setup_widgets(MCW_DC * dc)185 static void TTRR_setup_widgets( MCW_DC * dc )
186 {
187 XmString xstr ;
188 char lbuf[256] , *ept, TTRR_title[256] ;
189 Widget toprc , bar=NULL , actar , frame , separator , label ;
190 int ww,hh,bww , ii, n_points, maxlength, levelmark ;
191 ATLAS_POINT *tto_list=NULL;
192
193 ENTRY("TTRR_setup_widgets") ;
194
195 /**** sanity checks ****/
196
197 if( dc == NULL || ttc != NULL ) EXRETURN ; /* might be better to check ttc->dc */
198
199 SHOW_AFNI_PAUSE ;
200
201 if (!(tto_list = atlas_points(Current_Atlas_Default_Name()))) {
202 ERROR_message("No atlas points!");
203 EXRETURN ;
204 }
205
206 /**** create output structure ****/
207
208 ttc = New_TTRR_controls(Current_Atlas_Default_Name()); /* will live forever */
209
210 ttc->dc = dc ;
211
212 /* if this is YES, inverts the whole line that contains the structure */
213 ttc->av_invert = AFNI_yesenv( "AFNI_TTRR_INVERT" ) ;
214
215 /**** create Shell that can be opened up later ****/
216
217 ttc->shell =
218 XtVaAppCreateShell(
219 "AFNI" , "AFNI" , topLevelShellWidgetClass , dc->display ,
220
221 XmNtitle , "TT Atlas Rendering" , /* top of window */
222 XmNiconName , "TT Atlas" , /* label on icon */
223 #if 0
224 XmNmappedWhenManaged , False , /* must map it manually */
225 #endif
226 XmNdeleteResponse , XmDO_NOTHING , /* deletion handled below */
227 XmNallowShellResize , False , /* let code resize shell? */
228 XmNinitialResourcesPersistent , False ,
229 XmNkeyboardFocusPolicy , XmEXPLICIT ,
230 NULL ) ;
231
232 DC_yokify( ttc->shell , dc ) ;
233
234 if( afni48_good )
235 XtVaSetValues( ttc->shell ,
236 XmNiconPixmap , afni48_pixmap ,
237 NULL ) ;
238
239 XmAddWMProtocolCallback( /* make "Close" window menu work */
240 ttc->shell ,
241 XmInternAtom( dc->display , "WM_DELETE_WINDOW" , False ) ,
242 TTRR_delete_window_CB , (XtPointer) ttc ) ;
243
244 /**** create Form to hold all widgets ****/
245
246 toprc = XtVaCreateWidget(
247 "AFNI" , xmFormWidgetClass , ttc->shell ,
248 XmNborderWidth , 0 ,
249 XmNborderColor , 0 ,
250 XmNtraversalOn , True ,
251 XmNinitialResourcesPersistent , False ,
252 NULL ) ;
253
254 /**** Label to inform the cretinous user what he's looking at ****/
255 sprintf(TTRR_title, "-- Control atlas: %s colors --",Current_Atlas_Default_Name());
256
257 xstr = XmStringCreateLtoR( TTRR_title, XmFONTLIST_DEFAULT_TAG ) ;
258 label = XtVaCreateManagedWidget(
259 "AFNI" , xmLabelWidgetClass , toprc ,
260 XmNlabelString , xstr ,
261 XmNalignment , XmALIGNMENT_CENTER ,
262
263 XmNleftAttachment , XmATTACH_FORM ,
264 XmNrightAttachment, XmATTACH_FORM ,
265 XmNtopAttachment , XmATTACH_FORM ,
266 XmNtopOffset , 3 ,
267 XmNinitialResourcesPersistent , False ,
268 NULL ) ;
269 XmStringFree( xstr ) ;
270
271 MCW_widget_geom( label , &ww , &hh , NULL , NULL ) ; /* temporary */
272 XtVaSetValues( ttc->shell ,
273 XmNminWidth , ww+3 ,
274 XmNminHeight , 11*hh ,
275 NULL ) ;
276
277 separator = XtVaCreateManagedWidget(
278 "AFNI" , xmSeparatorWidgetClass , toprc ,
279 XmNseparatorType , XmSHADOW_ETCHED_IN ,
280 XmNshadowThickness, 2 ,
281 XmNleftAttachment , XmATTACH_FORM ,
282 XmNrightAttachment, XmATTACH_FORM ,
283 XmNtopAttachment , XmATTACH_WIDGET ,
284 XmNtopWidget , label ,
285 XmNtopOffset , 1 ,
286 NULL ) ;
287
288 /**** create an action area to hold user control buttons ****/
289
290 for( ii=0 ; ii < NUM_TTRR_ACT ; ii++ )
291 TTRR_act[ii].data = (XtPointer) ttc ;
292
293 actar = MCW_action_area( toprc , TTRR_act , NUM_TTRR_ACT ) ;
294
295 XtVaSetValues( actar ,
296 XmNleftAttachment , XmATTACH_FORM ,
297 XmNrightAttachment, XmATTACH_FORM ,
298 XmNtopAttachment , XmATTACH_WIDGET ,
299 XmNtopWidget , separator ,
300 XmNtopOffset , 3 ,
301 NULL ) ;
302
303 separator = XtVaCreateManagedWidget(
304 "AFNI" , xmSeparatorWidgetClass , toprc ,
305 XmNseparatorType , XmSHADOW_ETCHED_IN ,
306 XmNshadowThickness, 2 ,
307 XmNleftAttachment , XmATTACH_FORM ,
308 XmNrightAttachment, XmATTACH_FORM ,
309 XmNtopAttachment , XmATTACH_WIDGET ,
310 XmNtopWidget , actar ,
311 XmNtopOffset , 1 ,
312 NULL ) ;
313
314 /**** a couple of buttons to control operational settings ****/
315
316 ttc->meth_av = new_MCW_optmenu( toprc , "Method" ,
317 0 , NMETHOD-1 , 1 , 0 ,
318 NULL,NULL ,
319 MCW_av_substring_CB, METHOD_strings ) ;
320
321 XtVaSetValues( ttc->meth_av->wrowcol ,
322 XmNleftAttachment , XmATTACH_FORM ,
323 XmNtopAttachment , XmATTACH_WIDGET ,
324 XmNtopWidget , separator ,
325 XmNtopOffset , 3 ,
326 XmNleftOffset , 3 ,
327 NULL ) ;
328
329 ttc->hemi_av = new_MCW_optmenu( toprc , "Hemisphere(s)" ,
330 0 , NHEMI-1 , NHEMI-1 , 0 ,
331 NULL,NULL ,
332 MCW_av_substring_CB, HEMI_strings ) ;
333
334 XtVaSetValues( ttc->hemi_av->wrowcol ,
335 XmNrightAttachment, XmATTACH_FORM ,
336 XmNtopAttachment , XmATTACH_WIDGET ,
337 XmNtopWidget , separator ,
338 XmNtopOffset , 3 ,
339 XmNrightOffset , 3 ,
340 NULL ) ;
341
342 separator = XtVaCreateManagedWidget(
343 "AFNI" , xmSeparatorWidgetClass , toprc ,
344 XmNseparatorType , XmSHADOW_ETCHED_IN ,
345 XmNshadowThickness, 2 ,
346 XmNleftAttachment , XmATTACH_FORM ,
347 XmNrightAttachment, XmATTACH_FORM ,
348 XmNtopAttachment , XmATTACH_WIDGET ,
349 XmNtopWidget , ttc->meth_av->wrowcol ,
350 XmNtopOffset , 1 ,
351 NULL ) ;
352
353 /**** create a Scrolled Window and Form to hold colormenus ****/
354
355 ttc->scrollw =
356 XtVaCreateWidget(
357 "AFNI" , xmScrolledWindowWidgetClass , toprc ,
358 XmNscrollingPolicy , XmAUTOMATIC ,
359 XmNwidth , ww+2*hh , /* temporary */
360 XmNheight , 3*hh , /* ditto */
361 XmNleftAttachment , XmATTACH_FORM ,
362 XmNrightAttachment , XmATTACH_FORM ,
363 XmNtopAttachment , XmATTACH_WIDGET ,
364 XmNbottomAttachment, XmATTACH_FORM ,
365 XmNtopWidget , separator ,
366 XmNtopOffset , 3 ,
367 XmNtraversalOn , True ,
368 XmNinitialResourcesPersistent , False ,
369 NULL ) ;
370
371 frame =
372 XtVaCreateWidget(
373 "AFNI" , xmFrameWidgetClass , ttc->scrollw ,
374 XmNshadowType , XmSHADOW_ETCHED_IN ,
375 XmNshadowThickness , 5 ,
376 XmNtraversalOn , True ,
377 XmNinitialResourcesPersistent , False ,
378 NULL ) ;
379
380 ttc->workwin =
381 XtVaCreateWidget(
382 "AFNI" , xmFormWidgetClass , frame ,
383 XmNborderWidth , 0 ,
384 XmNborderColor , 0 ,
385 XmNtraversalOn , True ,
386 XmNinitialResourcesPersistent , False ,
387 NULL ) ;
388
389 /** compute information about regions **/
390 n_points = atlas_n_points(Current_Atlas_Default_Name());
391 maxlength = atlas_max_label_length(tto_list, n_points); /*maximum length of name */
392 levelmark = atlas_level(tto_list, n_points); /* any structures marked with a level */
393 if(levelmark)
394 maxlength = maxlength+4; /*allow for [G] or [A] in string */
395
396 if(maxlength<20) maxlength = 20; /* looks better with some trailing ....*/
397
398 ttc->reg_num = 0 ;
399 for( ii=0 ; ii < n_points ; ii++ ){
400 /*if( tto_list[ii].tdval == 0 ) continue ; */ /* skip */
401
402 if( tto_list[ii].tdlev == 2 ) strcpy(lbuf,"[G] ") ;
403 else if( tto_list[ii].tdlev == 4 ) strcpy(lbuf,"[A] ") ;
404 if((tto_list[ii].tdlev == 2)||(tto_list[ii].tdlev == 4)) {
405 strcat(lbuf,Atlas_name_choice(&tto_list[ii]));
406 }
407 else {
408 strcpy(lbuf,Atlas_name_choice(&tto_list[ii]));
409 }
410
411 fill_str(lbuf,'.', maxlength); /* add periods up to a length of maxlength*/
412
413 ttc->reg_label [ttc->reg_num] = strdup(lbuf) ;
414 ttc->reg_tto [ttc->reg_num] = ii ;
415 ttc->reg_ttbrik[ttc->reg_num] = (tto_list[ii].tdlev==2) ? 0 : 1 ;
416 ttc->reg_ttval [ttc->reg_num] = tto_list[ii].tdval ;
417 ttc->reg_ttovc [ttc->reg_num] = 0 ;
418
419 /* only create a few colormenu widgets first,
420 because XtRealizeWidget() is so slow with many widgets,
421 and the impatient user is likely to be unhappy with us */
422
423 if( ttc->reg_num < NUM_AV_FIRST ){
424 ttc->reg_av[ttc->reg_num] =
425 new_MCW_colormenu(
426 ttc->workwin , /* parent */
427 ttc->reg_label[ttc->reg_num] , /* label */
428 dc , /* display context */
429 0 , /* first color */
430 dc->ovc->ncol_ov - 1 , /* last color */
431 0 , /* initial color */
432 TTRR_av_CB,NULL /* callback func,data */
433 ) ;
434
435 XtVaSetValues( ttc->reg_av[ttc->reg_num]->wrowcol ,
436 XmNleftAttachment , XmATTACH_FORM ,
437 XmNtopAttachment , (ttc->reg_num==0)
438 ? XmATTACH_FORM /* 1st row */
439 : XmATTACH_WIDGET , /* 2nd+ row */
440 XmNtopWidget , (ttc->reg_num==0)
441 ? NULL
442 : ttc->reg_av[ttc->reg_num-1]->wrowcol ,
443 XmNrightAttachment , XmATTACH_FORM ,
444 NULL ) ;
445 }
446
447 ttc->reg_num++ ;
448 }
449
450 /* manage the managers */
451
452 XtManageChild( ttc->workwin ) ;
453 XtManageChild( frame ) ;
454 XtManageChild( ttc->scrollw ) ;
455 XtManageChild( toprc ) ;
456 XtRealizeWidget( ttc->shell ) ; NI_sleep(5) ;
457
458 WATCH_cursorize( ttc->shell ) ;
459 XmUpdateDisplay( ttc->shell ) ;
460
461 /*** set size ***/
462
463 #define LUCK 5 /* we all need some */
464 #define CMMAX 17 /* vertical size = CMMAX colormenus high */
465 MCW_widget_geom( ttc->reg_av[0]->wrowcol , &ww , &hh , NULL,NULL ) ;
466
467 XtVaGetValues( ttc->scrollw , XmNverticalScrollBar , &bar , NULL ) ;
468 MCW_widget_geom( bar , &bww , NULL,NULL,NULL ) ;
469
470 hh = CMMAX*hh + LUCK ;
471 ww += bww + 5*LUCK ;
472
473 /* but make sure window is at least wide
474 enough for the Method and Hemisphere(s) widgets */
475 MCW_widget_geom( ttc->meth_av->wrowcol , &ii , NULL,NULL,NULL ) ;
476 MCW_widget_geom( ttc->hemi_av->wrowcol , &bww , NULL,NULL,NULL ) ;
477 bww += ii + LUCK ;
478 if( ww < bww ) ww = bww ;
479
480 XtVaSetValues( ttc->shell , XmNwidth , ww , XmNheight , hh , NULL ) ;
481 XmUpdateDisplay( ttc->shell ) ;
482
483 /*** create rest of colormenu widgets now
484 -- this provides some visual feedback, and keeps the user happy ***/
485
486 for( ii=NUM_AV_FIRST ; ii < ttc->reg_num ; ii++ ){
487 ttc->reg_av[ii] =
488 new_MCW_colormenu(
489 ttc->workwin , /* parent */
490 ttc->reg_label[ii] , /* label */
491 dc , /* display context */
492 0 , /* first color */
493 dc->ovc->ncol_ov - 1 , /* last color */
494 0 , /* initial color */
495 NULL,NULL /* callback func,data */
496 ) ;
497
498 XtVaSetValues( ttc->reg_av[ii]->wrowcol ,
499 XmNleftAttachment , XmATTACH_FORM ,
500 XmNtopAttachment , XmATTACH_WIDGET ,
501 XmNtopWidget , ttc->reg_av[ii-1]->wrowcol ,
502 XmNrightAttachment , XmATTACH_FORM ,
503 NULL ) ;
504
505 XtRealizeWidget( ttc->reg_av[ii]->wrowcol ) ; NI_sleep(1) ;
506
507 if( ii%NUM_AV_FIRST == 0 ) /* show something occasionally */
508 XmUpdateDisplay( ttc->shell ) ;
509 }
510
511 PLUTO_cursorize( ttc->shell ) ;
512
513 /* 08 Aug 2002: read initial colors */
514
515 ept = getenv( "AFNI_TTRR_SETUP" ) ;
516 if( ept != NULL ) TTRR_load_file( ept ) ;
517
518 /*** done!!! ***/
519 SHOW_AFNI_READY ; EXRETURN ;
520 }
521
522 /*-----------------------------------------------------------------------
523 Called to actually see the damn thing
524 -------------------------------------------------------------------------*/
525
TTRR_popup(Three_D_View * im3d)526 void TTRR_popup( Three_D_View * im3d )
527 {
528 ENTRY("TTRR_popup") ;
529
530 if( ttc == NULL ) TTRR_setup_widgets( im3d->dc ) ;
531
532 ttc->im3d = im3d ;
533 XtMapWidget( ttc->shell ) ;
534
535 EXRETURN ;
536 }
537
538 /*------------------------------------------------------------------------
539 What happens when a colormenu item is selected
540 --------------------------------------------------------------------------*/
541
TTRR_av_CB(MCW_arrowval * av,XtPointer cd)542 static void TTRR_av_CB( MCW_arrowval * av , XtPointer cd )
543 {
544 if( !ttc->av_invert || av == NULL || av->ival == av->old_ival ) return ;
545
546 if( av->ival == 0 ||
547 (av->ival != 0 && av->old_ival == 0) ) MCW_invert_widget(av->wrowcol);
548
549 return ;
550 }
551
552 /*------------------------------------------------------------------------
553 What happens when an action button is pressed
554 --------------------------------------------------------------------------*/
555
TTRR_action_CB(Widget w,XtPointer cd,XtPointer cbs)556 static void TTRR_action_CB( Widget w , XtPointer cd , XtPointer cbs )
557 {
558 char * wname = XtName(w) ;
559 int ii ;
560
561 ENTRY("TTRR_action_CB") ;
562
563 if( strcmp(wname,TTRR_help_label) == 0 ){
564
565 new_MCW_textwin( w , helpstring , TEXT_READONLY ) ;
566
567 } else if( strcmp(wname,TTRR_done_label) == 0 ){
568
569 TTRR_delete_window_CB(NULL,NULL,NULL) ;
570
571 } else if( strcmp(wname,TTRR_clear_label) == 0 ){
572
573 /* restore colormenus to 'none' status */
574
575 for( ii=0 ; ii < ttc->reg_num ; ii++ ){
576 if( ttc->reg_av[ii]->ival != 0 ){
577 AV_assign_ival( ttc->reg_av[ii] , 0 ) ;
578
579 if( ttc->av_invert && ttc->reg_av[ii]->old_ival != 0 )
580 MCW_invert_widget(ttc->reg_av[ii]->wrowcol);
581 }
582 }
583
584 } else if( strcmp(wname,TTRR_redraw_label) == 0 ){
585
586 BEEPIT ;
587
588 } else if( strcmp(wname,TTRR_load_label) == 0 ){
589
590 MCW_choose_string( w , "Filename to load" , NULL ,
591 TTRR_load_CB , NULL ) ;
592
593 } else if( strcmp(wname,TTRR_save_label) == 0 ){
594
595 MCW_choose_string( w , "Filename to save" , NULL ,
596 TTRR_save_CB , NULL ) ;
597 }
598
599 EXRETURN ;
600 }
601
602 /*------------------------------------------------------------------------
603 What happens when the user selects "Close" from the window
604 menu in a plugin interface menu window
605 --------------------------------------------------------------------------*/
606
TTRR_delete_window_CB(Widget w,XtPointer cd,XtPointer cbs)607 static void TTRR_delete_window_CB( Widget w , XtPointer cd , XtPointer cbs )
608 {
609 ENTRY("TTRR_delete_window_CB") ;
610
611 if( ttc != NULL ){
612 XtUnmapWidget(ttc->shell) ; /* just hide the window */
613 XmUpdateDisplay(ttc->shell) ; /* (it's too hard to re-create) */
614 }
615 EXRETURN ;
616 }
617
618 /*------------------------------------------------------------------------
619 Return the current state of the TT atlas colors in a static
620 struct (i.e., do NOT free() this!).
621 --------------------------------------------------------------------------*/
622
623 static TTRR_params *ttp = NULL ;
624
TTRR_get_params(void)625 TTRR_params * TTRR_get_params(void)
626 {
627 int ii,jj ;
628
629 ENTRY("TTRR_get_params") ;
630
631 if( ttc == NULL ) RETURN(NULL) ; /* report nothing */
632
633 if( ttc->meth_av->ival == TTRR_METH_OFF ) RETURN(NULL) ;
634
635 /* 1st time in: make reporting struct */
636
637 if( ttp == NULL ){
638 ttp = myXtNew(TTRR_params) ;
639 ttp->ttbrik = (byte *) malloc(sizeof(byte)*ttc->reg_num) ;
640 ttp->ttval = (short *) malloc(sizeof(short)*ttc->reg_num) ;
641 ttp->ttovc = (byte *) malloc(sizeof(byte)*ttc->reg_num) ;
642 }
643
644 /* set method codes */
645
646 ttp->meth = ttc->meth_av->ival ;
647 ttp->hemi = ttc->hemi_av->ival ; /* hemisphere */
648
649 /* make list of all 'on' regions */
650
651 for( ii=jj=0 ; ii < ttc->reg_num ; ii++ ){
652 ttc->reg_ttovc[ii] = ttc->reg_av[ii]->ival ;
653 if( ttc->reg_ttovc[ii] > 0 ){
654 ttp->ttbrik[jj] = (byte) ttc->reg_ttbrik[ii] ;
655 ttp->ttval [jj] = (short) ttc->reg_ttval [ii] ;
656 ttp->ttovc [jj] = (byte) ttc->reg_ttovc [ii] ;
657 jj++ ;
658 }
659 }
660
661 ttp->num = jj ; /* number of 'on' regions */
662 RETURN(ttp) ;
663 }
664
665 /*----------------------------------------------------------------------*/
666
TTRR_load_file(char * fname)667 static void TTRR_load_file( char * fname ) /* 08 Aug 2002 */
668 {
669 FILE *fp = fopen(fname,"r") ;
670
671 #define NLBUF 1024
672 if( fp != NULL ){
673 char lbuf[NLBUF], **stok , *name, *color, *ept ;
674 int ns , ic , ii ;
675
676 while(1){
677 ept = afni_fgets( lbuf , NLBUF , fp ) ; /* get line */
678 if( ept == NULL ) break ; /* end of file */
679 stok = NULL ;
680 ns = breakup_string( lbuf , &stok ) ; /* break it up */
681 if( ns <= 0 || stok == NULL ) continue ; /* skip */
682 if( ns == 1 ){ freeup_strings(ns,stok); continue; } /* skip */
683 if( stok[0][0] == '#' ||
684 (stok[0][0] == '/' && stok[0][1] == '/') )
685 { freeup_strings(ns,stok); continue; } /* skip */
686 name = stok[0] ; /* region name */
687 if( ns == 2 ) color = stok[1] ; /* overlay color name */
688 else color = stok[2] ;
689 ic = DC_find_closest_overlay_color( ttc->dc , color ) ;
690 if( ic < 0 ){ freeup_strings(ns,stok); continue; } /* skip */
691
692 /* find region name in list; assign color to menu */
693
694 for( ii=0 ; ii < ttc->reg_num ; ii++ ){
695 if( ig_strstr( ttc->reg_label[ii], name, "._ " ) != NULL ){
696 AV_assign_ival( ttc->reg_av[ii] , ic ) ;
697 }
698 }
699
700 freeup_strings(ns,stok) ;
701 }
702
703 fclose(fp) ; /* done with file */
704 }
705
706 return ;
707 }
708
709 /*------------------------------------------------------------------*/
710
711
TTRR_load_CB(Widget w,XtPointer cd,MCW_choose_cbs * cbs)712 static void TTRR_load_CB( Widget w , XtPointer cd , MCW_choose_cbs * cbs )
713 {
714 if( cbs->reason != mcwCR_string ||
715 cbs->cval == NULL || strlen(cbs->cval) == 0 ){
716
717 PLUTO_beep() ; return ;
718 }
719
720 if( !THD_is_file(cbs->cval) ){ PLUTO_beep(); return; }
721
722 TTRR_load_file( cbs->cval ) ; return ;
723 }
724
725 /*------------------------------------------------------------------*/
726
TTRR_save_CB(Widget w,XtPointer cd,MCW_choose_cbs * cbs)727 static void TTRR_save_CB( Widget w , XtPointer cd , MCW_choose_cbs * cbs )
728 {
729 int ii , qq , jj ;
730 FILE *fp ;
731 char name[128] , *color ;
732
733 if( cbs->reason != mcwCR_string ||
734 cbs->cval == NULL || strlen(cbs->cval) == 0 ){
735
736 PLUTO_beep() ; return ;
737 }
738
739 fp = fopen( cbs->cval , "w" ) ;
740 if( fp == NULL ){ PLUTO_beep(); return; }
741
742 for( ii=0 ; ii < ttc->reg_num ; ii++ ){
743 color = ttc->dc->ovc->label_ov[ttc->reg_av[ii]->ival] ;
744 qq = (ttc->reg_label[ii][0] == '[') ? 4 : 0 ;
745 strcpy(name,ttc->reg_label[ii]+qq) ;
746 qq = strlen(name) ;
747 for( jj=0 ; jj < qq ; jj++ ){
748 if( name[jj] == '.' ) name[jj] = ' ' ;
749 else if( name[jj] == ' ' ) name[jj] = '_' ;
750 }
751 fprintf(fp, "%s = %s\n",name,color) ;
752 }
753 fclose(fp) ; return ;
754 }
755
756 /* add periods up to a length of maxlength*/
757 static void
fill_str(char * instr,char ch,int maxlength)758 fill_str(char * instr, char ch, int maxlength)
759 {
760 int i;
761
762 for(i=strlen(instr); i<maxlength;i++)
763 instr[i] = ch; /* replace characters in place in original string */
764 instr[maxlength] = '\0';
765 }
766