00001
00002
00003
00004
00005
00006
00007 #include "afni.h"
00008
00009
00010
00011
00012
00013 #if defined(NO_FRIVOLITIES) || !defined(ALLOW_PLUGINS)
00014
00015 void AFNI_splashdown (void){ return; }
00016 void AFNI_splashup (void){ return; }
00017 void AFNI_splashraise(void){ return; }
00018 void AFNI_faceup (void){ return; }
00019
00020
00021 void AFNI_broutim_CB(Widget w, XtPointer cd, XtPointer cbs){ return; }
00022 static int AFNI_find_todays_face(void){ return -1; }
00023
00024 #else
00025
00026 #include "afni_splash.h"
00027
00028 static void * SPLASH_popup_image( void * , MRI_IMAGE * ) ;
00029 static MRI_IMAGE * SPLASH_decode26( int , int , int , char ** ) ;
00030 static MRI_IMAGE * SPLASH_decodexx( int , int , int , int ,
00031 byte *, byte *, byte * , char ** ) ;
00032
00033 static MRI_IMAGE *imspl = NULL ;
00034 static void *handle = NULL ;
00035
00036 #define USE_FADING
00037
00038 #define USE_WRITING
00039 static int do_write=2 ;
00040
00041 static int AFNI_find_jpegs( char *, char ***) ;
00042 static int AFNI_find_todays_face(void) ;
00043
00044
00045
00046 void AFNI_splashraise(void)
00047 {
00048 PLUGIN_impopper *ppp = (PLUGIN_impopper *) handle ;
00049
00050 if( ppp != NULL && ISQ_REALZ(ppp->seq) )
00051 XMapRaised( XtDisplay(ppp->seq->wtop) , XtWindow(ppp->seq->wtop) ) ;
00052
00053 return ;
00054 }
00055
00056
00057
00058 void AFNI_splashdown(void)
00059 {
00060 PLUGIN_impopper *ppp = (PLUGIN_impopper *) handle ;
00061
00062 ENTRY("AFNI_splashdown") ;
00063
00064 if( handle != NULL ){
00065 #ifdef USE_FADING
00066 float max_splash = 3.0 ;
00067 char *hh = getenv("AFNI_SPLASHTIME") ;
00068 if( hh != NULL ) max_splash = strtod(hh,NULL) ;
00069 if( max_splash > 0.0 ){
00070 if( imspl != NULL ){
00071 byte *bspl ; int ii , nv , kk ; double et ;
00072 bspl = mri_data_pointer(imspl) ;
00073 nv = (imspl->pixel_size) * (imspl->nvox) ;
00074 et = COX_clock_time() ;
00075 do_write = 0 ;
00076 for( kk=0 ; kk < 10 ; kk++ ){
00077 #if 0
00078 for( ii=0 ; ii < nv ; ii++ ) bspl[ii] *= 0.92 ;
00079 #else
00080 for( ii=0 ; ii < nv ; ii++ ) bspl[ii] = (15*bspl[ii]) >> 4 ;
00081 #endif
00082 SPLASH_popup_image(handle,imspl) ;
00083 drive_MCW_imseq( ppp->seq , isqDR_reimage , (XtPointer) 0 ) ;
00084 if( COX_clock_time()-et > 2.1 ) break ;
00085 }
00086 }
00087 }
00088 #endif
00089 SPLASH_popup_image(handle,NULL); myXtFree(handle) ;
00090 }
00091 mri_free(imspl) ; imspl = NULL ;
00092 do_write = ( (lrand48() >> 8) % 3 == 0 ) ? 2 : 1 ;
00093 EXRETURN ;
00094 }
00095
00096
00097
00098 static int num_splash = 0 ;
00099 static int first_splash = -1 ;
00100 static char **fname_splash = NULL ;
00101
00102 static int num_face = 0 ;
00103 static char **fname_face = NULL ;
00104
00105 void AFNI_splashup(void)
00106 {
00107 PLUGIN_impopper *ppp ;
00108 MRI_IMAGE *imov ;
00109 int dd,ee ;
00110 char bb ;
00111 byte *bspl ;
00112 int sxx,syy ;
00113 char *sen ;
00114 static int ncall=0 , nov , dnov , nm=-1 ;
00115
00116 ENTRY("AFNI_splashup") ;
00117
00118
00119
00120 if( ! PLUTO_popup_open(handle) ){
00121
00122 int nxov,nyov,ff ;
00123
00124
00125
00126 if( ncall == 0 ){
00127 num_face = AFNI_find_jpegs( "face_" , &fname_face ) ;
00128 num_splash = AFNI_find_jpegs( "splash_" , &fname_splash ) ;
00129 if( num_splash > 0 ){
00130 int np ;
00131 for( np=0 ; np < num_splash ; np++ )
00132 if( strstr(fname_splash[np],"sscc") != NULL ) break ;
00133 if( np < num_splash ) first_splash = np ;
00134 #if 0
00135 for( np=0 ; np < num_splash ; np++ )
00136 fprintf(stderr,"SPLASH: %s\n",fname_splash[np]) ;
00137 #endif
00138 }
00139 }
00140
00141
00142
00143 mri_free(imspl) ;
00144 imspl = SPLASH_decodexx( NX_blank, NY_blank, NLINE_blank, NC_blank,
00145 RMAP_blank,GMAP_blank,BMAP_blank, BAR_blank ) ;
00146
00147 if( ncall==0 ){
00148 nov = (lrand48() >> 8) % NOVER ;
00149 dnov = 2*((lrand48() >> 8) % 2) - 1 ;
00150 }
00151
00152
00153
00154
00155 imov = NULL ; ff = 0 ;
00156 if( num_face > 0 ){
00157 static int *dold=NULL, ndold=0 ; int qq ;
00158 dd = AFNI_find_todays_face() ;
00159 if( dd >= 0 ){ ff=-1; goto Have_dd; }
00160 if( ndold == 0 && num_face > 1 ){
00161 ndold = num_face/2 ;
00162 dold = (int *) malloc(sizeof(int)*ndold) ;
00163 for( qq=0 ; qq < ndold ; qq++ ) dold[qq] = -1 ;
00164 }
00165 Retry_dd:
00166 dd = (lrand48() >> 8) % num_face ;
00167 if( num_face > 1 ){
00168 for( qq=0 ; qq < ndold && dold[qq] != dd ; qq++ ) ;
00169 if( qq < ndold ) goto Retry_dd ;
00170 for( qq=1 ; qq < ndold ; qq++ )
00171 dold[qq-1] = dold[qq] ;
00172 dold[ndold-1] = dd ;
00173 }
00174 Have_dd:
00175 imov = mri_read_stuff( fname_face[dd] ) ;
00176 if( imov != NULL && (imov->nx > MAX_XOVER || imov->ny > MAX_YOVER) ){
00177 float xfac=MAX_XOVER/(float)(imov->nx),
00178 yfac=MAX_YOVER/(float)(imov->ny) ;
00179 int nxnew,nynew ; MRI_IMAGE *imq ;
00180 if( xfac > yfac ) xfac = yfac ;
00181 nxnew = (int)(xfac*imov->nx) ; nynew = (int)(xfac*imov->ny) ;
00182 imq = mri_resize( imov , nxnew,nynew ) ;
00183 mri_free(imov); imov = imq;
00184 }
00185 if( ff == 0 && imov != NULL ){
00186 ff = (strstr(fname_face[dd],"_rwcox") != NULL) ? 2 : 1 ;
00187 }
00188 }
00189 if( imov == NULL ){
00190 nov = (nov+dnov+NOVER) % NOVER ;
00191 imov = SPLASH_decode26( xover[nov], yover[nov], lover[nov], bover[nov] ) ;
00192 }
00193 nxov = imov->nx ; nyov = imov->ny ;
00194 dd = IXOVER + (MAX_XOVER-nxov)/2 ;
00195 ee = JYOVER + (MAX_YOVER-nyov)/2 ;
00196 mri_overlay_2D( imspl, imov, dd,ee ); mri_free(imov);
00197 if( ff > 0 ){
00198 imov = SPLASH_decodexx( NX_facetitle,NY_facetitle,NLINE_facetitle,
00199 NC_facetitle,RMAP_facetitle,
00200 RMAP_facetitle,RMAP_facetitle ,
00201 BAR_facetitle ) ;
00202 if( ff == 2 ) mri_invert_inplace( imov ) ;
00203 dd = IXOVER + (MAX_XOVER-imov->nx)/2 ; ee += nyov+1 ;
00204 mri_overlay_2D( imspl, imov, dd,ee ) ; mri_free(imov) ;
00205 }
00206
00207
00208
00209 if( (ncall > 0 || first_splash >= 0) && num_splash > 0 &&
00210 (ncall <= num_splash || ((lrand48() >> 8 ) % 7) != 0) ){
00211
00212 static int np=-1 , dp ;
00213 if( np < 0 ){
00214 np = (first_splash >= 0) ? first_splash
00215 : (lrand48() >> 8) % num_splash ;
00216 dp = 2*((lrand48() >> 8)%2)-1 ;
00217 } else
00218 np = (np+dp+num_splash)%(num_splash) ;
00219 imov = mri_read_stuff( fname_splash[np] ) ;
00220 if( imov != NULL ){
00221 #if 0
00222 reload_DC_colordef( GLOBAL_library.dc ) ;
00223 if( imov->nx != NX_TOPOVER || imov->ny != NY_TOPOVER ){
00224 MRI_IMAGE *imq ;
00225 imq = mri_resize( imov , NX_TOPOVER,NY_TOPOVER ) ;
00226 if( imq != NULL ){ mri_free(imov); imov = imq; }
00227 }
00228 #endif
00229 STATUS("overlaying splash image") ;
00230 mri_overlay_2D( imspl , imov , 0,0 ) ;
00231 mri_free(imov) ;
00232 }
00233
00234 }
00235
00236
00237
00238 handle = SPLASH_popup_image( handle, imspl ) ;
00239 #ifndef USE_FADING
00240 mri_free(imspl) ; imspl = NULL ;
00241 #endif
00242
00243
00244
00245 ppp = (PLUGIN_impopper *) handle ;
00246
00247 if( ncall==0 ){ dd = MWM_DECOR_BORDER ;
00248 ee = 0 ;
00249 } else { dd = MWM_DECOR_BORDER | MWM_DECOR_TITLE | MWM_DECOR_MENU ;
00250 ee = MWM_FUNC_MOVE | MWM_FUNC_CLOSE ;
00251 }
00252
00253
00254
00255 sxx = (GLOBAL_library.dc->width-NX_blank)/2 ;
00256 syy = 100 ;
00257 sen = getenv("AFNI_SPLASH_XY") ;
00258 if( sen != NULL ){
00259 int n,x,y ;
00260 n = sscanf(sen,"%d:%d",&x,&y) ;
00261 if( n == 2 && x >= 0 && x < GLOBAL_library.dc->width &&
00262 y >= 0 && y < GLOBAL_library.dc->height ){
00263
00264 sxx = x ; syy = y ;
00265 }
00266 }
00267
00268 XtVaSetValues( ppp->seq->wtop ,
00269 XmNx , sxx ,
00270 XmNy , syy ,
00271 XmNmwmDecorations , dd ,
00272 XmNmwmFunctions , ee ,
00273
00274 NULL ) ;
00275
00276
00277
00278 drive_MCW_imseq( ppp->seq , isqDR_realize , NULL ) ;
00279 drive_MCW_imseq( ppp->seq , isqDR_onoffwid , (XtPointer) isqDR_offwid ) ;
00280 drive_MCW_imseq( ppp->seq , isqDR_clearstat , NULL ) ;
00281 #if 0
00282 drive_MCW_imseq( ppp->seq , isqDR_reimage , (XtPointer) 0 ) ;
00283 #endif
00284
00285 NORMAL_cursorize( ppp->seq->wimage ) ;
00286
00287
00288
00289 if( ncall==0 ){
00290 drive_MCW_imseq( ppp->seq , isqDR_title , (XtPointer) "AFNI!" ) ;
00291 drive_MCW_imseq( ppp->seq , isqDR_imhelptext,
00292 (XtPointer)
00293 " \n"
00294 " Thou art indeed just, Lord, if I contend\n"
00295 " With thee; but, sir, so what I plead is just.\n"
00296 " Why do sinners' ways prosper? and why must\n"
00297 " Disappointment all I endeavour end?\n"
00298 " Wert thou my enemy, O thou my friend,\n"
00299 " How wouldst thou worse, I wonder, than thou dost\n"
00300 " Defeat, thwart me? Oh, the sots and thralls of lust\n"
00301 " Do in spare hours more thrive than I that spend,\n"
00302 " Sir, life upon thy cause. See, banks and brakes\n"
00303 " Now, leaved how thick! laced they are again\n"
00304 " With fretty chervil, look, and fresh wind shakes\n"
00305 " Them; birds build -- but not I build; no, but strain,\n"
00306 " Time's eunuch, and not breed one work that wakes.\n"
00307 " Mine, O thou lord of life, send my roots rain.\n"
00308 ) ;
00309
00310 #if 0
00311 {
00312 ISQ_options opt ;
00313 drive_MCW_imseq( ppp->seq , isqDR_getoptions , (XtPointer) &opt ) ;
00314 opt.improc_code |= ISQ_IMPROC_SHARP ;
00315 drive_MCW_imseq( ppp->seq , isqDR_options , (XtPointer) &opt ) ;
00316 }
00317 #endif
00318 }
00319
00320
00321
00322 } else {
00323 ppp = (PLUGIN_impopper *) handle ;
00324
00325
00326
00327 if( ISQ_REALZ(ppp->seq) )
00328 XMapRaised( XtDisplay(ppp->seq->wtop) , XtWindow(ppp->seq->wtop) ) ;
00329
00330 AFNI_splashdown() ;
00331 }
00332
00333 ncall++ ; EXRETURN ;
00334 }
00335
00336
00337
00338
00339
00340
00341 static XtPointer SPLASH_imseq_getim( int n, int type, XtPointer handle )
00342 {
00343 PLUGIN_impopper *imp = (PLUGIN_impopper *) handle ;
00344
00345 ENTRY("SPLASH_imseq_getim") ;
00346
00347 if( imp == NULL ) RETURN(NULL) ;
00348
00349
00350
00351 if( type == isqCR_getstatus ){
00352 MCW_imseq_status *stat = myXtNew( MCW_imseq_status ) ;
00353 stat->num_total = 1 ;
00354 stat->num_series = 1 ;
00355 stat->send_CB = PLUGIN_seq_send_CB ;
00356 stat->parent = (XtPointer) imp ;
00357 stat->aux = NULL ;
00358
00359 stat->transforms0D = NULL ;
00360 stat->transforms2D = NULL ;
00361 stat->slice_proj = NULL ;
00362
00363 RETURN((XtPointer) stat) ;
00364 }
00365
00366
00367
00368 if( type == isqCR_getoverlay ) RETURN(NULL) ;
00369
00370
00371
00372
00373 if( type == isqCR_getimage || type == isqCR_getqimage ){
00374 MRI_IMAGE *im = NULL ;
00375 #ifndef USE_WRITING
00376 if( imp->im != NULL ) im = mri_copy( imp->im ) ;
00377 #else
00378 if( imp->im != NULL ){
00379 if( do_write ) im = mri_zeropad_2D( 0,0,0,50 , imp->im ) ;
00380 else im = mri_copy( imp->im ) ;
00381 }
00382 #endif
00383 RETURN((XtPointer) im) ;
00384 }
00385
00386 #ifdef USE_WRITING
00387
00388
00389 if( do_write && type == isqCR_getmemplot ){
00390 int ii ;
00391 ii = create_memplot_surely("SPLASH memplot",1.0) ;
00392 if( ii == 0 ){
00393 MEM_plotdata *mp = get_active_memplot() ;
00394
00395 set_thick_memplot(0.003) ;
00396
00397 if( do_write == 2 || 1 ){
00398 char *sf = AFNI_get_date_trivia() ;
00399 int nn = strlen(sf) , ss=28 ;
00400 if( nn > 37 ) ss = (int)(28.0*37.0/nn) ;
00401 set_color_memplot(1.0,1.0,0.7) ;
00402 plotpak_pwritf( 0.5,0.089 , "Today is:" , 30 , 0 , 0 ) ;
00403 set_color_memplot(1.0,1.0,0.1) ;
00404 plotpak_pwritf( 0.5,0.033 , sf , ss , 0 , 0 ) ;
00405 } else {
00406 char *sf = AFNI_get_friend() ;
00407 char *mf = strstr(sf," for ") ;
00408 int nn = strlen(sf) ;
00409 set_color_memplot(1.0,1.0,0.5) ;
00410 if( nn < 36 || mf == NULL ){
00411 plotpak_pwritf( 0.5,0.060 , sf , 28 , 0 , 0 ) ;
00412 } else {
00413 *mf = '\0' ;
00414 plotpak_pwritf( 0.5,0.089 , sf , 28 , 0 , 0 ) ;
00415 plotpak_pwritf( 0.5,0.033 , mf+1, 28 , 0 , 0 ) ;
00416 }
00417 }
00418 set_thick_memplot(0.0) ;
00419 RETURN((XtPointer)mp) ;
00420 }
00421 }
00422 #endif
00423
00424 RETURN(NULL) ;
00425 }
00426
00427
00428
00429
00430
00431 static void * SPLASH_popup_image( void *handle , MRI_IMAGE *im )
00432 {
00433 PLUGIN_impopper *imp = (PLUGIN_impopper *) handle ;
00434
00435 ENTRY("SPLASH_popup_image") ;
00436
00437
00438
00439 if( im == NULL ){
00440 if( imp != NULL )
00441 drive_MCW_imseq( imp->seq , isqDR_destroy , NULL ) ;
00442
00443 RETURN ((void *) imp) ;
00444 }
00445
00446
00447
00448 if( imp == NULL ){
00449 imp = myXtNew(PLUGIN_impopper) ;
00450 imp->seq = NULL ; imp->im = NULL ;
00451 }
00452
00453
00454
00455 mri_free( imp->im ) ;
00456 imp->im = mri_copy( im ) ;
00457
00458
00459
00460 if( imp->seq == NULL )
00461 imp->seq = open_MCW_imseq( GLOBAL_library.dc ,
00462 SPLASH_imseq_getim , (XtPointer) imp ) ;
00463
00464
00465
00466 RETURN ((void *) imp) ;
00467 }
00468
00469
00470
00471
00472
00473 static byte map26[26] =
00474 { 30, 50, 70, 90, 106, 118, 130, 140, 146, 152, 158, 164, 170,
00475 176, 182, 190, 198, 206, 212, 218, 224, 230, 236, 242, 248, 254 } ;
00476
00477 static MRI_IMAGE * SPLASH_decode26( int nx, int ny , int nl , char ** im26 )
00478 {
00479 return SPLASH_decodexx( nx, ny, nl, 26,map26,map26,map26,im26 ) ;
00480 }
00481
00482
00483
00484
00485
00486 #define MMAX 82
00487 static char alpha[MMAX] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
00488 "abcdefghijklmnopqrstuvwxyz"
00489 ",<.>/?;:'[{]}|=+-_)(*&^%$#@!`~" ;
00490
00491 static MRI_IMAGE * SPLASH_decodexx( int nx, int ny, int nl, int nmap,
00492 byte *rmap, byte *gmap, byte *bmap ,
00493 char ** imxx )
00494 {
00495 MRI_IMAGE *im ;
00496 byte *bim ;
00497 int ii,jj , cc,qq , dd,ee , kk ;
00498 char bb ;
00499 static int first=1 , ainv[256] ;
00500
00501 ENTRY("SPLASH_decodexx") ;
00502
00503 if( nmap == 0 ){
00504 nmap = 26 ;
00505 rmap = bmap = gmap = map26 ;
00506 }
00507
00508 if( nx < 3 || ny < 3 || nl < 3 ||
00509 rmap == NULL || gmap == NULL ||
00510 bmap == NULL || imxx == NULL ) RETURN(NULL) ;
00511
00512 if( first ){
00513 for( ii=0 ; ii < 256 ; ii++ ) ainv[ii] = -1 ;
00514 for( ii=0 ; ii < MMAX ; ii++ ){
00515 bb = alpha[ii] ; ainv[bb] = ii ;
00516 }
00517 first = 0 ;
00518 }
00519
00520 im = mri_new( nx , ny , MRI_rgb ) ;
00521 bim = MRI_RGB_PTR(im) ;
00522
00523
00524
00525 cc = qq = 0 ;
00526 for( ii=0 ; ii < 3*im->nvox && qq < nl ; ){
00527 bb = imxx[qq][cc++] ; if( bb == '\0' ) break ;
00528 jj = ainv[bb] ;
00529 if( jj >= 0 ){
00530 bim[ii++] = rmap[jj]; bim[ii++] = gmap[jj]; bim[ii++] = bmap[jj];
00531 } else {
00532 dd = bb - '0' ;
00533 bb = imxx[qq][cc++] ; if( bb == '\0' ) break ;
00534 jj = ainv[bb] ;
00535 for( ee=0 ; ee < dd && ii < 3*im->nvox ; ee++ ){
00536 bim[ii++] = rmap[jj]; bim[ii++] = gmap[jj]; bim[ii++] = bmap[jj];
00537 }
00538 }
00539 if( imxx[qq][cc] == '\0' ){ cc = 0 ; qq++ ; }
00540 }
00541
00542 RETURN(im) ;
00543 }
00544
00545
00546
00547
00548 int AFNI_find_jpegs( char *prefix , char ***fname )
00549 {
00550 char *epath , *elocal , *eee ;
00551 char edir[THD_MAX_NAME] , *ename ;
00552 int epos , ll , ii , id , nfile , nx,ny , num_file=0 ;
00553 char **ffile , **fflist=NULL ;
00554
00555 ENTRY("AFNI_find_jpegs") ;
00556
00557 if( prefix == NULL || *prefix == '\0' || fname == NULL ) RETURN(-1) ;
00558
00559
00560
00561 epath = getenv("AFNI_PLUGINPATH") ;
00562 if( epath == NULL ) epath = getenv("AFNI_PLUGIN_PATH") ;
00563 if( epath == NULL ) epath = getenv("PATH") ;
00564 if( epath == NULL ) epath = getenv("HOME") ;
00565 if( epath == NULL ){ RETURN(-1) ; }
00566
00567
00568
00569 ll = strlen(epath) ;
00570 elocal = AFMALL( char, sizeof(char) * (ll+2) ) ;
00571
00572
00573
00574 strcpy( elocal , epath ) ; elocal[ll] = ' ' ; elocal[ll+1] = '\0' ;
00575
00576
00577
00578 for( ii=0 ; ii < ll ; ii++ )
00579 if( elocal[ii] == ':' ) elocal[ii] = ' ' ;
00580
00581
00582
00583
00584 ename = (char *) malloc( 2*THD_MAX_NAME+32 ) ;
00585 epos = 0 ;
00586
00587 do{
00588 ii = sscanf( elocal+epos , "%s%n" , edir , &id );
00589 if( ii < 1 ) break ;
00590
00591
00592
00593 eee = strstr( elocal , edir ) ;
00594 if( eee != NULL && (eee-elocal) < epos ){ epos += id ; continue ; }
00595
00596 epos += id ;
00597
00598 ii = strlen(edir) ;
00599 if( edir[ii-1] != '/' ){
00600 edir[ii] = '/' ; edir[ii+1] = '\0' ;
00601 }
00602
00603
00604
00605 sprintf(ename,"%s%s*.jpg %s%s*.JPG" , edir,prefix,edir,prefix ) ;
00606
00607 MCW_wildcards( ename , &nfile , &ffile ) ;
00608 if( nfile <= 0 ) continue ;
00609
00610
00611
00612 fflist = (char **)realloc(fflist,sizeof(char *)*(num_file+nfile));
00613 for( ii=0 ; ii < nfile ; ii++ )
00614 if( strstr(ffile[ii],"face_wildman.jpg") != NULL )
00615 remove(ffile[ii]) ;
00616 else
00617 fflist[num_file++] = strdup(ffile[ii]) ;
00618
00619 MCW_free_wildcards( nfile , ffile ) ;
00620
00621 } while( epos < ll ) ;
00622
00623 free(elocal) ; free(ename) ;
00624
00625 if( num_file == 0 ) num_file = -1 ;
00626 *fname = fflist ;
00627 RETURN(num_file) ;
00628 }
00629
00630
00631
00632 static void *face_phan=NULL ;
00633
00634 void AFNI_facedown( void *kd ){ face_phan = NULL; }
00635
00636 #undef NXY
00637 #define NXY 128
00638
00639 static int gcd( int m , int n ){
00640 while( m > 0 ){
00641 if( n > m ){ int t=m; m=n; n=t; }
00642 m -= n;
00643 }
00644 return n;
00645 }
00646
00647 void AFNI_faceup(void)
00648 {
00649 MRI_IMAGE *im , *fim ;
00650 int ii , nx,ny , nxdown,nxup , nydown,nyup ;
00651 int ctold,ctnew,mmss , ddss ;
00652 int jj , j0,dj=1 ;
00653
00654 ENTRY("AFNI_faceup") ;
00655
00656 if( num_face < 0 ){ BEEPIT; EXRETURN; }
00657 if( num_face == 0 ){
00658 num_face = AFNI_find_jpegs( "face_" , &fname_face ) ;
00659 if( num_face <= 0 ){ BEEPIT; EXRETURN; }
00660 }
00661 if( face_phan != NULL ){
00662 PLUGIN_imseq *ph = (PLUGIN_imseq *)face_phan ;
00663 XMapRaised( XtDisplay(ph->seq->wtop) , XtWindow(ph->seq->wtop) ) ;
00664 EXRETURN ;
00665 }
00666
00667 ctold = NI_clock_time() ;
00668
00669 ddss = num_face + 16449/num_face ; if( ddss > 222 ) ddss = 222 ;
00670
00671 if( num_face > 4 ){
00672 ii = num_face / 2 ;
00673 do{ dj = 1 + lrand48() % ii ; } while( gcd(num_face,dj) > 1 ) ;
00674 }
00675 j0 = lrand48() % num_face ;
00676
00677 for( ii=0 ; ii < num_face ; ii++ ){
00678 jj = (j0 + ii*dj) % num_face ;
00679 im = mri_read_stuff( fname_face[jj] ) ;
00680 if( im == NULL ) continue ;
00681 nx = im->nx ; ny = im->ny ;
00682
00683 nxdown = (NXY-nx) / 2 ; nxup = NXY - nx - nxdown ;
00684 nydown = (NXY-ny) / 2 ; nyup = NXY - ny - nydown ;
00685 if( nxdown != 0 || nydown != 0 || nxup != 0 || nyup != 0 ){
00686 fim = mri_zeropad_2D( nxdown,nxup , nydown,nyup , im ) ;
00687 if( fim != NULL ){ mri_free(im) ; im = fim ; }
00688 }
00689 fim = mri_dup2D(2,im) ; mri_free(im) ;
00690 if( face_phan == NULL ){
00691 int sxx,syy ; char *sen ; PLUGIN_imseq *ph ;
00692
00693 face_phan = PLUTO_imseq_popim( fim,(generic_func *)AFNI_facedown,NULL );
00694 sxx = (GLOBAL_library.dc->width-4*NXY)/2 ; if( sxx < 1 ) sxx = 1 ;
00695 syy = 100 ;
00696 sen = getenv("AFNI_SPLASH_XY") ;
00697 if( sen != NULL ){
00698 int n,x,y ;
00699 n = sscanf(sen,"%d:%d",&x,&y) ;
00700 if( n == 2 && x >= 0 && x < GLOBAL_library.dc->width &&
00701 y >= 0 && y < GLOBAL_library.dc->height ){
00702 sxx = x ; syy = y ;
00703 }
00704 }
00705 ph = (PLUGIN_imseq *)face_phan ;
00706 XtVaSetValues( ph->seq->wtop , XmNx,sxx , XmNy,syy , NULL ) ;
00707 drive_MCW_imseq( ph->seq , isqDR_record_disable , (XtPointer)0 ) ;
00708 drive_MCW_imseq( ph->seq , isqDR_periodicmont , (XtPointer)1 ) ;
00709
00710 } else {
00711 PLUTO_imseq_addto( face_phan , fim ) ;
00712 }
00713 mri_free(fim) ;
00714
00715 ctnew = NI_clock_time() ;
00716 mmss = ddss - (ctnew-ctold) ;
00717 ctold = ctnew ; ddss-- ;
00718 NI_sleep(mmss) ;
00719 }
00720 if( face_phan != NULL ){
00721 PLUTO_imseq_retitle( face_phan , "Faces of AFNI" ) ;
00722 PLUTO_imseq_setim( face_phan , 0 ) ;
00723 } else {
00724 BEEPIT ;
00725 }
00726
00727 EXRETURN ;
00728 }
00729
00730
00731 #include <time.h>
00732 #define JAN 1
00733 #define FEB 2
00734 #define MAR 3
00735 #define APR 4
00736 #define MAY 5
00737 #define JUN 6
00738 #define JUL 7
00739 #define AUG 8
00740 #define SEP 9
00741 #define OCT 10
00742 #define NOV 11
00743 #define DEC 12
00744
00745 typedef struct { int mon,day; char *label; } mday ;
00746 #define NTMAX 9
00747
00748 static mday facials[] = {
00749 {MAR,30,"face_vincent" } ,
00750 {FEB,12,"face_lincoln" } ,
00751 {JAN, 3,"face_tolkien" } ,
00752 {MAR,14,"face_einstein"} ,
00753 {APR,27,"face_grant" } ,
00754 {JUL,22,"face_rbirn" } ,
00755 {SEP, 7,"face_rwcox" } ,
00756 {OCT,16,"face_rwcox" } ,
00757 {NOV,17,"face_brodman" } ,
00758 {0,0,NULL} } ;
00759
00760
00761 static int AFNI_find_todays_face(void)
00762 {
00763 time_t tt ;
00764 struct tm *lt ;
00765 int ii , ntar , dd , tar[NTMAX] ;
00766 static int iold=-1 ;
00767 char *flab ;
00768
00769 if( num_face <= 0 || fname_face == NULL ) return -1 ;
00770 if( num_face == 1 ) return 0 ;
00771
00772
00773
00774 tt = time(NULL) ;
00775 lt = localtime( &tt ) ;
00776 for( ii=0 ; facials[ii].day > 0 ; ii++ )
00777 if( facials[ii].mon == lt->tm_mon+1 && facials[ii].day == lt->tm_mday ) break ;
00778 if( facials[ii].day <= 0 ) return -1 ;
00779
00780
00781
00782 flab = facials[ii].label ;
00783
00784 for( ntar=dd=0 ; ntar < NTMAX && dd < num_face ; dd++ )
00785 if( strstr(fname_face[dd],flab) != NULL ) tar[ntar++] = dd ;
00786
00787 if( ntar == 0 ) return -1 ;
00788 if( ntar == 1 ) return tar[0] ;
00789 ii = (lrand48()>>8) % ntar ;
00790 if( ii == iold ) ii = (ii+1)%ntar ;
00791 iold = ii ; return tar[ii] ;
00792 }
00793
00794
00795
00796 #include "afni_broutim.h"
00797
00798 void AFNI_broutim_CB( Widget w, XtPointer cd, XtPointer cbs )
00799 {
00800 MRI_IMAGE *imbr ;
00801 imbr = SPLASH_decodexx( NX_broutim,NY_broutim,NLINE_broutim,NC_broutim,
00802 RMAP_broutim,GMAP_broutim,BMAP_broutim,BAR_broutim);
00803 (void) PLUTO_popup_image( NULL , imbr ) ;
00804 mri_free(imbr) ; return ;
00805 }
00806
00807 #endif
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817 #define NLBUF 4096
00818 static char *linbuf ;
00819
00820 static int get_linbuf( char *str )
00821 {
00822 int ii=0 , jj ;
00823
00824 if( str == NULL || str[0] == '\0' ){ linbuf[0] = '\0'; return 0; }
00825
00826
00827
00828 SKIP_WHITESPACE:
00829 for( ; str[ii] != '\0' && isspace(str[ii]) ; ii++ ) ;
00830
00831 if( str[ii] == '\0' ){ linbuf[0] = '\0'; return ii; }
00832
00833 if( str[ii] == '!' || (str[ii]=='/' && str[ii+1]=='/') ){
00834 for( ; str[ii] != '\0' && str[ii] != '\n' ; ii++ ) ;
00835 goto SKIP_WHITESPACE ;
00836 }
00837
00838
00839
00840 for( jj=0 ; jj < NLBUF &&
00841 str[ii] != '\0' &&
00842 str[ii] != '\n' &&
00843 str[ii] != '!' &&
00844 !(str[ii]=='/' && str[ii+1]=='/')
00845 ; ii++ , jj++ ) linbuf[jj] = str[ii] ;
00846
00847 linbuf[jj] = '\0' ; return ii ;
00848 }
00849
00850
00851
00852 void AFNI_decode_geom( char *geom , int *ww, int *hh , int *xx, int *yy )
00853 {
00854 int has_x , has_plus ;
00855
00856 *ww = *hh = *xx = *yy = -1 ;
00857 if( geom == NULL || geom[0] == '\0' ) return ;
00858
00859 has_x = strstr(geom,"x") != NULL ;
00860 has_plus = strstr(geom,"+") != NULL ;
00861
00862 if( has_x && has_plus )
00863 sscanf(geom,"%dx%d+%d+%d",ww,hh,xx,yy) ;
00864 else if( has_x )
00865 sscanf(geom,"%dx%d",ww,hh) ;
00866 else if( has_plus )
00867 sscanf(geom,"+%d+%d",xx,yy) ;
00868
00869 return ;
00870 }
00871
00872
00873
00874
00875
00876
00877 #define ISTARRED(s) ( (s)[0]=='*' && (s)[1]=='*' && (s)[2]=='*' )
00878
00879 #define NGMAX 32
00880
00881 #define ACTIVATE_MASK (1)
00882 #define NULL_MASK (0)
00883
00884 #define NWBUF 128
00885
00886 void AFNI_startup_layout_CB( XtPointer client_data , XtIntervalId *id )
00887 {
00888 char *fname = (char *) client_data ;
00889 int nbuf , ii , goslow ;
00890 char *fbuf , *fptr ;
00891 char lword[NWBUF] ;
00892
00893 int controller_mask[MAX_CONTROLLERS] ;
00894 char controller_geom[MAX_CONTROLLERS][NGMAX] ;
00895
00896 int image_mask [MAX_CONTROLLERS][3] ;
00897 char image_geom [MAX_CONTROLLERS][3][NGMAX] ;
00898 float image_ifrac [MAX_CONTROLLERS][3] ;
00899 char image_mont [MAX_CONTROLLERS][3][NGMAX] ;
00900
00901 int graph_mask [MAX_CONTROLLERS][3] ;
00902 char graph_geom [MAX_CONTROLLERS][3][NGMAX] ;
00903 int graph_matrix [MAX_CONTROLLERS][3] ;
00904 int graph_pinnum [MAX_CONTROLLERS][3] ;
00905
00906 int cc,ww , gww,ghh,gxx,gyy ;
00907 char *e_asp ;
00908 int e_turnoff=0 ;
00909
00910 int * plugin_cont = NULL ;
00911 char **plugin_geom = NULL ;
00912 int ipl ;
00913
00914 Three_D_View *im3d = GLOBAL_library.controllers[0] ;
00915
00916 #ifdef ALLOW_PLUGINS
00917 int npbut = im3d->vwid->nplugbut ;
00918 char ** pluglab = im3d->vwid->pluglab ;
00919 PLUGIN_interface ** plugint = im3d->vwid->plugint ;
00920 #endif
00921
00922 ENTRY("AFNI_startup_layout_CB") ;
00923
00924 if( fname == NULL || fname[0] == '\0' ){ AFNI_splashdown(); EXRETURN; }
00925
00926
00927
00928 fbuf = AFNI_suck_file(fname); if( fbuf == NULL ){ AFNI_splashdown(); EXRETURN; }
00929 nbuf = strlen(fbuf) ; if( nbuf == 0 ){ AFNI_splashdown(); EXRETURN; }
00930
00931 fptr = fbuf ; linbuf = (char *) malloc(sizeof(char)*(NLBUF+1)) ;
00932
00933 if(PRINT_TRACING)
00934 { char str[256] ;
00935 sprintf(str,"Reading AFNI layout file = %s (%d bytes)",fname,nbuf) ;
00936 STATUS(str);}
00937
00938
00939
00940 do {
00941 ii = get_linbuf( fptr ) ; fptr += ii ;
00942 if( linbuf[0] == '\0' || fptr-fbuf >= nbuf ){
00943 STATUS("no ***LAYOUT found") ;
00944 fprintf(stderr,"\n*** LAYOUT not found in layout file %s\n",fname);
00945 free(fbuf); free(linbuf); AFNI_splashdown(); EXRETURN;
00946 }
00947 } while( strncmp(linbuf,"***LAYOUT",9) != 0 ) ;
00948
00949 goslow = (strstr(linbuf,"slow") != NULL) ;
00950
00951
00952
00953 for( cc=0 ; cc < MAX_CONTROLLERS ; cc++ ){
00954 controller_geom[cc][0] =
00955 image_geom[cc][0][0] = image_geom[cc][1][0] = image_geom[cc][2][0] =
00956 image_mont[cc][0][0] = image_mont[cc][1][0] = image_mont[cc][2][0] =
00957 graph_geom[cc][0][0] = graph_geom[cc][1][0] = graph_geom[cc][1][0] = '\0' ;
00958
00959 controller_mask[cc] =
00960 image_mask[cc][0] = image_mask[cc][1] = image_mask[cc][2] =
00961 graph_mask[cc][0] = graph_mask[cc][1] = graph_mask[cc][2] = NULL_MASK ;
00962
00963 image_ifrac[cc][0] = image_ifrac[cc][1] = image_ifrac[cc][2] = 0.0 ;
00964
00965 graph_pinnum[cc][0] = graph_pinnum[cc][1] = graph_pinnum[cc][2] =
00966 graph_matrix[cc][0] = graph_matrix[cc][1] = graph_matrix[cc][2] = 0 ;
00967 }
00968
00969
00970
00971 #ifdef ALLOW_PLUGINS
00972 if( npbut > 0 ){
00973 plugin_cont = (int *) malloc(sizeof(int) *npbut) ;
00974 plugin_geom = (char **) malloc(sizeof(char *)*npbut) ;
00975 for( ipl=0 ; ipl < npbut ; ipl++ ){
00976 plugin_cont[ipl] = -1 ;
00977 plugin_geom[ipl] = NULL ;
00978 }
00979 }
00980 #endif
00981
00982
00983
00984 do {
00985 ii = get_linbuf( fptr ) ; fptr += ii ;
00986 if( linbuf[0] == '\0' || ISTARRED(linbuf) ) break ;
00987
00988
00989
00990 cc = linbuf[0] - 'A' ;
00991 if( cc < 0 || cc >= MAX_CONTROLLERS ) continue ;
00992
00993 controller_mask[cc] |= ACTIVATE_MASK ;
00994
00995 if( linbuf[1] == '\0' ) continue;
00996
00997
00998
00999 if( isspace(linbuf[1]) ){
01000
01001 int jj=1 , nn ;
01002
01003 do {
01004 nn = 0 ; lword[0] = '\0' ;
01005 sscanf(linbuf+jj,"%s%n",lword,&nn) ;
01006 if( nn == 0 || lword[0] == '\0' ) break ;
01007 jj += nn ;
01008
01009 if( strncmp(lword,"geom=",5) == 0 ){
01010 strcpy(controller_geom[cc],lword+5) ;
01011 } else {
01012 fprintf(stderr,"\n** Illegal LAYOUT controller option: %s\n",lword) ;
01013 continue ;
01014 }
01015 } while(1) ;
01016
01017
01018
01019 } else if( linbuf[1] == '.' && strncmp(linbuf+1,".plugin.",8) != 0 ){
01020
01021 int jj=2 , nn ;
01022
01023 nn = 0 ; lword[0] = '\0' ;
01024 sscanf(linbuf+jj,"%s%n",lword,&nn) ;
01025 if( nn == 0 || lword[0] == '\0' ) continue ;
01026 jj += nn ;
01027
01028 if( strncmp(lword,"axial" ,5) == 0 ) ww = 0 ;
01029 else if( strncmp(lword,"sagittal",8) == 0 ) ww = 1 ;
01030 else if( strncmp(lword,"coronal" ,7) == 0 ) ww = 2 ;
01031 else {
01032 fprintf(stderr,"\n** Illegal LAYOUT sub-window line: %s\n",linbuf) ;
01033 continue ;
01034 }
01035
01036
01037
01038 if( strstr(lword,"image") != NULL ){
01039
01040 image_mask[cc][ww] |= ACTIVATE_MASK ;
01041
01042 do {
01043 nn = 0 ; lword[0] = '\0' ;
01044 sscanf(linbuf+jj,"%s%n",lword,&nn) ;
01045 if( nn == 0 || lword[0] == '\0' ) break ;
01046 jj += nn ;
01047
01048 if( strncmp(lword,"geom=",5) == 0 ){
01049 strcpy(image_geom[cc][ww],lword+5) ;
01050 } else if( strncmp(lword,"ifrac=",6) == 0 ){
01051 image_ifrac[cc][ww] = strtod( lword+6 , NULL ) ;
01052 } else if( strncmp(lword,"mont=",5) == 0 ){
01053 strcpy(image_mont[cc][ww],lword+5) ;
01054 } else {
01055 fprintf(stderr,"\n** Illegal LAYOUT image option: %s\n",lword) ;
01056 continue ;
01057 }
01058 } while(1) ;
01059
01060
01061
01062 } else if( strstr(lword,"graph") != NULL ){
01063
01064 graph_mask[cc][ww] |= ACTIVATE_MASK ;
01065
01066 do {
01067 nn = 0 ; lword[0] = '\0' ;
01068 sscanf(linbuf+jj,"%s%n",lword,&nn) ;
01069 if( nn == 0 || lword[0] == '\0' ) break ;
01070 jj += nn ;
01071
01072 if( strncmp(lword,"geom=",5) == 0 ){
01073 strcpy(graph_geom[cc][ww],lword+5) ;
01074 } else if( strncmp(lword,"matrix=",7) == 0 ){
01075 graph_matrix[cc][ww] = (int) strtod( lword+7 , NULL ) ;
01076 } else if( strncmp(lword,"pinnum=",7) == 0 ){
01077 graph_pinnum[cc][ww] = (int) strtod( lword+7 , NULL ) ;
01078 } else {
01079 fprintf(stderr,"\n** Illegal LAYOUT image option: %s\n",lword) ;
01080 continue ;
01081 }
01082 } while(1) ;
01083
01084 } else {
01085 fprintf(stderr,"\n** Illegal LAYOUT line: %s\n",linbuf) ;
01086 continue ;
01087 }
01088
01089
01090
01091 } else if( strncmp(linbuf+1,".plugin.",8) == 0 ){
01092
01093 #ifdef ALLOW_PLUGINS
01094 char *pname = linbuf+9 ;
01095 int pl,ll,qq , jj,nn ;
01096
01097
01098
01099
01100 pl = strlen(pname) ;
01101 if( pl < 1 ){
01102 fprintf(stderr,"\n** LAYOUT: unknown plugin line: %s\n",linbuf) ;
01103 continue ;
01104 }
01105
01106 for( ipl=0 ; ipl < npbut ; ipl++ ){
01107 for( ll=strlen(pluglab[ipl]) ;
01108 ll >= 0 && isspace(pluglab[ipl][ll]) ; ll-- ) ;
01109 if( ll < 0 ) continue ;
01110 if( pl < ll ) continue ;
01111 for( qq=0 ; qq < ll ; qq++ )
01112 if( !isspace(pluglab[ipl][qq]) && pname[qq]!=pluglab[ipl][qq] ) break ;
01113 if( qq == ll ) break ;
01114 }
01115 if( ipl >= npbut ){
01116 fprintf(stderr,"\n** LAYOUT: unknown plugin line: %s\n",linbuf) ;
01117
01118 if( strncmp(pname,"RT Options",10) == 0 ||
01119 strncmp(pname,"RT_Options",10) == 0 )
01120 fprintf(stderr,"** [Realtime plugin is not active!]\n") ;
01121
01122 continue ;
01123 }
01124
01125
01126
01127 if( plugin_cont[ipl] >= 0 )
01128 fprintf(stderr,"\n** LAYOUT: 2nd callout for this plugin: %s\n",linbuf) ;
01129
01130 plugin_cont[ipl] = cc ;
01131 if( plugin_geom[ipl] != NULL ){
01132 free(plugin_geom[ipl]) ; plugin_geom[ipl] = NULL ;
01133 }
01134
01135 jj = 9+ll ;
01136 do {
01137 nn = 0 ; lword[0] = '\0' ;
01138 sscanf(linbuf+jj,"%s%n",lword,&nn) ;
01139 if( nn == 0 || lword[0] == '\0' ) break ;
01140 jj += nn ;
01141
01142 if( strncmp(lword,"geom=",5) == 0 ){
01143 plugin_geom[ipl] = strdup(lword+5) ;
01144 } else {
01145 fprintf(stderr,"\n** Illegal LAYOUT .plugin. option: %s\n",lword) ;
01146 continue ;
01147 }
01148 } while(1) ;
01149 #endif
01150
01151
01152
01153 } else {
01154
01155 fprintf(stderr,"\n** Illegal LAYOUT line: %s\n",linbuf) ;
01156 continue ;
01157 }
01158
01159 } while(1) ;
01160
01161 free(fbuf) ; free(linbuf) ;
01162
01163
01164
01165
01166 e_asp = my_getenv("AFNI_ENFORCE_ASPECT") ;
01167 if( !YESSISH(e_asp) ){
01168 putenv("AFNI_ENFORCE_ASPECT=YES") ;
01169 e_turnoff = 1 ;
01170 }
01171
01172
01173
01174 for( cc=0 ; cc < MAX_CONTROLLERS ; cc++ ){
01175
01176 MCW_imseq *isq ;
01177 MCW_grapher *gra ;
01178 int singleton=0 ;
01179
01180
01181
01182 if( (controller_mask[cc] & ACTIVATE_MASK) == 0 ) continue ;
01183
01184 AFNI_make_controller( cc ) ;
01185
01186 if( GLOBAL_library.controllers[cc] == NULL ) continue ;
01187
01188 if(goslow || PRINT_TRACING) sleep(1);
01189
01190
01191
01192 if( controller_geom[cc][0] != '\0' ){
01193 AFNI_decode_geom( controller_geom[cc] , &gww,&ghh,&gxx,&gyy ) ;
01194 if( gxx >= 0 && gyy >= 0 )
01195 XtVaSetValues( GLOBAL_library.controllers[cc]->vwid->top_shell ,
01196 XmNx , gxx , XmNy , gyy , NULL ) ;
01197 }
01198
01199 AFNI_splashraise() ;
01200
01201 if(goslow || PRINT_TRACING) sleep(1);
01202
01203
01204
01205 for( ww=0 ; ww < 3 ; ww++ ){
01206
01207
01208
01209 if( (image_mask[cc][ww] & ACTIVATE_MASK) == 0 ) continue ;
01210
01211
01212
01213 AFNI_view_xyz_CB( (ww == 0) ? GLOBAL_library.controllers[cc]->vwid->imag->image_xyz_pb
01214 :(ww == 1) ? GLOBAL_library.controllers[cc]->vwid->imag->image_yzx_pb
01215 : GLOBAL_library.controllers[cc]->vwid->imag->image_zxy_pb ,
01216 GLOBAL_library.controllers[cc] , NULL ) ;
01217
01218 isq = (ww == 0) ? GLOBAL_library.controllers[cc]->s123
01219 :(ww == 1) ? GLOBAL_library.controllers[cc]->s231
01220 : GLOBAL_library.controllers[cc]->s312 ;
01221
01222 if( isq == NULL ) continue ;
01223
01224 if(goslow || PRINT_TRACING) sleep(1);
01225
01226
01227
01228 if( image_ifrac[cc][ww] >= FRAC_MIN && image_ifrac[cc][ww] <= 1.0 ){
01229
01230 drive_MCW_imseq( isq , isqDR_setifrac , (XtPointer) &(image_ifrac[cc][ww]) ) ;
01231
01232 if(goslow || PRINT_TRACING) sleep(1);
01233 }
01234
01235
01236
01237 if( image_mont[cc][ww][0] != '\0' ){
01238 int mww=-1 , mhh=-1 , msp=-1 , mgap=-1 , nn ;
01239 char mcol[128] = "\0" ;
01240
01241 nn = sscanf( image_mont[cc][ww] , "%dx%d:%d:%d:%s" , &mww,&mhh,&msp,&mgap,mcol ) ;
01242
01243 if( nn >= 2 && mww >= 1 && mww <= MONT_NMAX && mhh >= 1 && mhh <= MONT_NMAX ){
01244 int mp[5] ;
01245 mp[0] = mww ; mp[1] = mhh ; mp[2] = msp ; mp[3] = mgap ;
01246 mp[4] = DC_find_overlay_color(GLOBAL_library.controllers[cc]->dc,mcol);
01247 drive_MCW_imseq( isq , isqDR_setmontage , (XtPointer) mp ) ;
01248
01249 if( msp == 1 ) singleton++ ;
01250
01251 if(goslow || PRINT_TRACING) sleep(1);
01252 }
01253 }
01254
01255
01256
01257 if( image_geom[cc][ww][0] != '\0' ){
01258 AFNI_decode_geom( image_geom[cc][ww] , &gww,&ghh,&gxx,&gyy ) ;
01259 if( gxx >= 0 && gyy >= 0 )
01260 XtVaSetValues( isq->wtop , XmNx , gxx , XmNy , gyy , NULL ) ;
01261 if( gww > 0 && ghh > 0 )
01262 XtVaSetValues( isq->wtop , XmNwidth , gww , XmNheight , ghh , NULL ) ;
01263
01264 if(goslow || PRINT_TRACING) sleep(1);
01265 }
01266
01267 AFNI_splashraise() ;
01268
01269 }
01270
01271
01272
01273 if( singleton ){
01274 AV_assign_ival(
01275 GLOBAL_library.controllers[cc]->vwid->imag->crosshair_av ,
01276 AFNI_XHAIRS_SINGLE ) ;
01277
01278 AFNI_crosshair_visible_CB(
01279 GLOBAL_library.controllers[cc]->vwid->imag->crosshair_av ,
01280 GLOBAL_library.controllers[cc] ) ;
01281 }
01282
01283
01284
01285 for( ww=0 ; ww < 3 ; ww++ ){
01286
01287
01288
01289 if( (graph_mask[cc][ww] & ACTIVATE_MASK) == 0 ) continue ;
01290
01291
01292
01293 AFNI_view_xyz_CB( (ww == 0) ? GLOBAL_library.controllers[cc]->vwid->imag->graph_xyz_pb
01294 :(ww == 1) ? GLOBAL_library.controllers[cc]->vwid->imag->graph_yzx_pb
01295 : GLOBAL_library.controllers[cc]->vwid->imag->graph_zxy_pb ,
01296 GLOBAL_library.controllers[cc] , NULL ) ;
01297
01298 gra = (ww == 0) ? GLOBAL_library.controllers[cc]->g123
01299 :(ww == 1) ? GLOBAL_library.controllers[cc]->g231
01300 : GLOBAL_library.controllers[cc]->g312 ;
01301
01302 if( gra == NULL ) continue ;
01303
01304 if(goslow || PRINT_TRACING) sleep(1);
01305
01306
01307
01308 if( graph_matrix[cc][ww] > 0 ){
01309 drive_MCW_grapher( gra , graDR_setmatrix , (XtPointer) graph_matrix[cc][ww] ) ;
01310 if(goslow || PRINT_TRACING) sleep(1);
01311 }
01312
01313
01314
01315 if( graph_pinnum[cc][ww] > 1 ){
01316 drive_MCW_grapher( gra, graDR_setpinnum, (XtPointer)graph_pinnum[cc][ww] );
01317 if(goslow || PRINT_TRACING) sleep(1);
01318 }
01319
01320
01321
01322 if( graph_geom[cc][ww][0] != '\0' ){
01323 AFNI_decode_geom( graph_geom[cc][ww] , &gww,&ghh,&gxx,&gyy ) ;
01324 if( gxx >= 0 && gyy >= 0 )
01325 XtVaSetValues( gra->fdw_graph , XmNx , gxx , XmNy , gyy , NULL ) ;
01326 if( gww > 0 && ghh > 0 )
01327 XtVaSetValues( gra->fdw_graph , XmNwidth , gww , XmNheight , ghh , NULL ) ;
01328 if(goslow || PRINT_TRACING) sleep(1);
01329 }
01330
01331 AFNI_splashraise() ;
01332
01333 }
01334
01335 #if 0
01336 XmUpdateDisplay( im3d->vwid->top_shell ) ;
01337 #endif
01338
01339 }
01340
01341 #ifdef ALLOW_PLUGINS
01342
01343
01344 for( ipl=0 ; ipl < npbut ; ipl++ ){
01345
01346 cc = plugin_cont[ipl] ; if( cc < 0 ) continue ;
01347
01348 if( GLOBAL_library.controllers[cc] == NULL ) continue ;
01349
01350 PLUG_startup_plugin_CB( GLOBAL_library.controllers[cc]->vwid->plugbut[ipl] ,
01351 GLOBAL_library.controllers[cc]->vwid->plugint[ipl] ,
01352 NULL ) ;
01353
01354 if(goslow || PRINT_TRACING) sleep(1);
01355
01356
01357
01358 if( GLOBAL_library.controllers[cc]->vwid->plugint[ipl]->call_method == PLUGIN_CALL_IMMEDIATELY )
01359 continue ;
01360
01361
01362
01363 if( GLOBAL_library.controllers[cc]->vwid->plugint[ipl]->wid == NULL ||
01364 GLOBAL_library.controllers[cc]->vwid->plugint[ipl]->wid->shell == NULL ){
01365
01366 fprintf(stderr,"\n** LAYOUT: couldn't start plugin %s\n",pluglab[ipl]) ;
01367 continue ;
01368 }
01369
01370
01371
01372 if( plugin_geom[ipl] != NULL ){
01373 AFNI_decode_geom( plugin_geom[ipl] , &gww,&ghh,&gxx,&gyy ) ;
01374 if( gxx >= 0 && gyy >= 0 ){
01375 XtVaSetValues(
01376 GLOBAL_library.controllers[cc]->vwid->plugint[ipl]->wid->shell,
01377 XmNx , gxx , XmNy , gyy , NULL ) ;
01378 if(goslow || PRINT_TRACING) sleep(1);
01379 }
01380 }
01381
01382 AFNI_splashraise() ;
01383
01384 }
01385 #endif
01386
01387
01388
01389 #ifdef ALLOW_PLUGINS
01390 if( npbut > 0 ){
01391 for( ipl=0 ; ipl < npbut ; ipl++ )
01392 if( plugin_geom[ipl] != NULL ) free(plugin_geom[ipl]) ;
01393 free(plugin_cont) ; free(plugin_geom) ;
01394 }
01395 #endif
01396
01397 if( e_turnoff ) putenv("AFNI_ENFORCE_ASPECT=NO") ;
01398
01399 AFNI_splashdown() ; EXRETURN ;
01400 }
01401
01402
01403
01404
01405
01406 void AFNI_save_layout_CB( Widget w , XtPointer cd , XtPointer cbs )
01407 {
01408 Three_D_View *im3d = (Three_D_View *) cd ;
01409
01410 ENTRY("AFNI_save_layout_CB") ;
01411
01412 MCW_choose_string( im3d->vwid->picture ,
01413 "Layout filename [blank => .afni.startup_script]:" ,
01414 NULL , AFNI_finalsave_layout_CB , cd ) ;
01415 EXRETURN ;
01416 }
01417
01418
01419
01420 void AFNI_finalsave_layout_CB( Widget w , XtPointer cd , MCW_choose_cbs *cbs )
01421 {
01422 Three_D_View *im3d = (Three_D_View *) cd ;
01423 int cc,ww , gww,ghh,gxx,gyy ;
01424 FILE *fp , *gp ;
01425 MCW_imseq *isq ;
01426 MCW_grapher *gra ;
01427 float ifrac ;
01428 char mont[128] ;
01429 int matrix , pinnum ;
01430
01431 char *abet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
01432 char *wnam[3] = { "axial" , "sagittal" , "coronal" } ;
01433
01434 int ipl , qq , ll ;
01435 char *plab ;
01436
01437 Three_D_View *qm3d = GLOBAL_library.controllers[0];
01438
01439 #ifdef ALLOW_PLUGINS
01440 int npbut = qm3d->vwid->nplugbut;
01441 char ** pluglab = qm3d->vwid->pluglab;
01442 PLUGIN_interface ** plugint = qm3d->vwid->plugint;
01443 #endif
01444
01445 MCW_DCOV *ovc = GLOBAL_library.dc->ovc ;
01446 Three_D_View *zm3d ;
01447
01448 ENTRY("AFNI_finalsave_layout_CB") ;
01449
01450 if( strcmp(cbs->cval,".afnirc") == 0 ){ BEEPIT; EXRETURN; }
01451
01452
01453
01454 if( THD_filename_ok(cbs->cval) ){
01455 fp = fopen( cbs->cval , "w" ) ;
01456 if( fp == NULL ){ BEEPIT; EXRETURN; }
01457 } else {
01458 fp = NULL ;
01459 }
01460
01461 if( fp != NULL ) fprintf(fp,"\n***LAYOUT\n") ;
01462
01463
01464
01465 if( fp == NULL )
01466 gp = fopen( ".afni.startup_script" , "w" ) ;
01467 else
01468 gp = NULL ;
01469
01470 if( gp != NULL ){
01471
01472 fprintf(gp,"// AFNI startup script, from Datamode->Misc->Save Layout\n") ;
01473
01474
01475
01476 for( qq=DEFAULT_NCOLOVR+1 ; qq < ovc->ncol_ov ; qq++ )
01477 fprintf(gp,"ADD_OVERLAY_COLOR %s %s\n",
01478 ovc->name_ov[qq] , ovc->label_ov[qq] ) ;
01479 } else {
01480 if( fp == NULL ){ BEEPIT; EXRETURN; }
01481 }
01482
01483
01484
01485 for( cc=0 ; cc < MAX_CONTROLLERS ; cc++ ){
01486
01487
01488
01489 zm3d = GLOBAL_library.controllers[cc] ;
01490
01491 if( !IM3D_OPEN(zm3d) ) continue ;
01492
01493
01494
01495 MCW_widget_geom( zm3d->vwid->top_shell ,
01496 NULL,NULL , &gxx,&gyy ) ;
01497
01498 if( fp != NULL ) fprintf(fp," %c geom=+%d+%d\n" , abet[cc] , gxx,gyy ) ;
01499
01500
01501
01502 if( gp != NULL ){
01503 MCW_pbar *pbar = zm3d->vwid->func->inten_pbar ;
01504
01505 fprintf(gp,"OPEN_WINDOW %c geom=+%d+%d\n" , abet[cc] , gxx,gyy ) ;
01506
01507 if( XtIsManaged(zm3d->vwid->func->frame) )
01508 fprintf(gp,"OPEN_PANEL %c.Define_Overlay\n" , abet[cc] ) ;
01509
01510 fprintf(gp,"SET_THRESHOLD %c.%04d %d\n" , abet[cc] ,
01511 (int)(zm3d->vinfo->func_threshold/THR_FACTOR) ,
01512 (int)(log10(zm3d->vinfo->func_thresh_top)+.01) ) ;
01513
01514 if( !pbar->bigmode ){
01515 fprintf(gp,"SET_PBAR_ALL %c.%c%d" , abet[cc] ,
01516 (pbar->mode) ? '+' : '-' , pbar->num_panes ) ;
01517 for( qq=0 ; qq < pbar->num_panes ; qq++ )
01518 fprintf(gp," %s=%s",
01519 AV_uformat_fval(pbar->pval[qq]) ,
01520 ovc->label_ov[pbar->ov_index[qq]] ) ;
01521 fprintf(gp,"\n") ;
01522 } else {
01523 fprintf(gp,"SET_PBAR_ALL %c.%c%d %f %s\n" , abet[cc] ,
01524 (pbar->mode) ? '+' : '-' , 99 ,
01525 pbar->bigtop , PBAR_get_bigmap(pbar) ) ;
01526 }
01527
01528 fprintf(gp,"SET_FUNC_VISIBLE %c.%c\n" , abet[cc] ,
01529 (zm3d->vinfo->func_visible) ? '+' : '-' ) ;
01530
01531 fprintf(gp,"SET_FUNC_RESAM %c.%s.%s\n" , abet[cc] ,
01532 RESAM_shortstr[zm3d->vinfo->func_resam_mode] ,
01533 RESAM_shortstr[zm3d->vinfo->thr_resam_mode] ) ;
01534
01535 if( im3d->vinfo->use_autorange )
01536 fprintf(gp,"SET_FUNC_AUTORANGE %c.+\n" , abet[cc] ) ;
01537 else
01538 fprintf(gp,"SET_FUNC_RANGE %c.%f\n" , abet[cc] ,
01539 im3d->vwid->func->range_av->fval ) ;
01540
01541 }
01542
01543
01544
01545 for( ww=0 ; ww < 3 ; ww++ ){
01546
01547 isq = (ww == 0) ? zm3d->s123
01548 :(ww == 1) ? zm3d->s231
01549 : zm3d->s312 ;
01550
01551 if( isq == NULL ) continue ;
01552
01553
01554
01555 MCW_widget_geom( isq->wtop , &gww,&ghh , &gxx,&gyy ) ;
01556
01557 ifrac = (isq->onoff_state) ? isq->image_frac : 1.0 ;
01558
01559 if( isq->mont_nx > 1 || isq->mont_ny > 1 ){
01560 sprintf(mont,"%dx%d:%d:%d:%s" ,
01561 isq->mont_nx , isq->mont_ny , isq->mont_skip+1 , isq->mont_gap ,
01562 zm3d->dc->ovc->label_ov[isq->mont_gapcolor]);
01563 } else {
01564 mont[0] = '\0' ;
01565 }
01566
01567 if( fp != NULL ){
01568 if( mont[0] == '\0' ){
01569 fprintf(fp, " %c.%simage geom=%dx%d+%d+%d ifrac=%s\n" ,
01570 abet[cc] , wnam[ww] , gww,ghh,gxx,gyy , AV_uformat_fval(ifrac) ) ;
01571 } else {
01572 fprintf(fp, " %c.%simage geom=%dx%d+%d+%d ifrac=%s mont=%s\n" ,
01573 abet[cc] , wnam[ww] , gww,ghh,gxx,gyy , AV_uformat_fval(ifrac) , mont ) ;
01574 }
01575 }
01576
01577
01578
01579 if( gp != NULL ){
01580 int opval=9 ;
01581 drive_MCW_imseq( isq , isqDR_getopacity , &opval ) ;
01582 if( mont[0] == '\0' ){
01583 fprintf(gp, "OPEN_WINDOW %c.%simage geom=+%d+%d ifrac=%s opacity=%d\n" ,
01584 abet[cc] , wnam[ww] , gxx,gyy , AV_uformat_fval(ifrac) , opval ) ;
01585 } else {
01586 fprintf(gp, "OPEN_WINDOW %c.%simage geom=+%d+%d ifrac=%s mont=%s opacity=%d\n" ,
01587 abet[cc] , wnam[ww] , gxx,gyy , AV_uformat_fval(ifrac) , mont , opval ) ;
01588 }
01589 }
01590 }
01591
01592
01593
01594 for( ww=0 ; ww < 3 ; ww++ ){
01595
01596 gra = (ww == 0) ? zm3d->g123
01597 :(ww == 1) ? zm3d->g231
01598 : zm3d->g312 ;
01599
01600 if( gra == NULL ) continue ;
01601
01602 MCW_widget_geom( gra->fdw_graph , &gww,&ghh , &gxx,&gyy ) ;
01603
01604 pinnum = (gra->pin_top < MIN_PIN) ? 0 : gra->pin_top ;
01605 matrix = gra->mat ;
01606
01607 if( fp != NULL ){
01608 if( pinnum > 0 ){
01609 fprintf(fp , " %c.%sgraph geom=%dx%d+%d+%d matrix=%d pinnum=%d\n" ,
01610 abet[cc] , wnam[ww] , gww,ghh,gxx,gyy , matrix,pinnum ) ;
01611 } else {
01612 fprintf(fp , " %c.%sgraph geom=%dx%d+%d+%d matrix=%d\n" ,
01613 abet[cc] , wnam[ww] , gww,ghh,gxx,gyy , matrix ) ;
01614 }
01615 }
01616
01617
01618
01619 if( gp != NULL ){
01620 if( pinnum > 0 ){
01621 fprintf(gp , "OPEN_WINDOW %c.%sgraph geom=%dx%d+%d+%d matrix=%d pinnum=%d\n" ,
01622 abet[cc] , wnam[ww] , gww,ghh,gxx,gyy , matrix,pinnum ) ;
01623 } else {
01624 fprintf(gp , "OPEN_WINDOW %c.%sgraph geom=%dx%d+%d+%d matrix=%d\n" ,
01625 abet[cc] , wnam[ww] , gww,ghh,gxx,gyy , matrix ) ;
01626 }
01627 }
01628 }
01629
01630 }
01631
01632 #ifdef ALLOW_PLUGINS
01633
01634
01635 for( ipl=0 ; ipl < npbut ; ipl++ ){
01636
01637 if( plugint[ipl]->wid == NULL || plugint[ipl]->wid->shell == NULL ) continue ;
01638
01639 cc = AFNI_controller_index( plugint[ipl]->im3d ) ;
01640
01641 if( cc < 0 || cc >= MAX_CONTROLLERS || !IM3D_OPEN(plugint[ipl]->im3d) ) continue ;
01642
01643 if( ! MCW_widget_visible(plugint[ipl]->wid->shell) ) continue ;
01644
01645
01646
01647 MCW_widget_geom( plugint[ipl]->wid->shell , &gww,&ghh , &gxx,&gyy ) ;
01648
01649
01650
01651
01652 plab = strdup( pluglab[ipl] ) ;
01653 for( ll=strlen(plab) ;
01654 ll >= 0 && isspace(plab[ll]) ; ll-- ) plab[ll] = '\0' ;
01655 if( ll < 0 ) continue ;
01656 ll++ ;
01657 for( qq=0 ; qq < ll ; qq++ ) if( isspace(plab[qq]) ) plab[qq] = '_' ;
01658
01659 if( fp != NULL ) fprintf(fp , " %c.plugin.%s geom=+%d+%d\n" ,
01660 abet[cc] , plab , gxx,gyy ) ;
01661 }
01662 #endif
01663
01664
01665
01666 if( fp != NULL ) fclose(fp) ;
01667 if( gp != NULL ) fclose(gp) ;
01668 EXRETURN ;
01669 }
01670
01671
01672
01673
01674 void AFNI_startup_script_CB( XtPointer client_data , XtIntervalId *id )
01675 {
01676 char *fname = (char *)client_data ;
01677 char *fbuf , *fptr ;
01678 int ii , nbuf ;
01679
01680 ENTRY("AFNI_startup_script_CB") ;
01681
01682 if( fname == NULL ) EXRETURN ;
01683
01684 if( strchr(fname,' ') != NULL ){
01685 AFNI_driver(fname) ;
01686 EXRETURN ;
01687 }
01688
01689 fbuf = AFNI_suck_file(fname); if( fbuf == NULL ) EXRETURN ;
01690 nbuf = strlen(fbuf) ; if( nbuf == 0 ) EXRETURN ;
01691
01692 fptr = fbuf ; linbuf = (char *) malloc(sizeof(char)*(NLBUF+1)) ;
01693
01694 GLOBAL_library.ignore_lock = 1 ;
01695
01696 while(1){
01697 ii = get_linbuf( fptr ) ; fptr += ii ;
01698 if( linbuf[0] == '\0' || fptr-fbuf >= nbuf ){ free(linbuf); break; }
01699 AFNI_driver( linbuf ) ;
01700 }
01701
01702 GLOBAL_library.ignore_lock = 0 ; EXRETURN ;
01703 }
01704
01705
01706
01707
01708
01709 void AFNI_run_script_CB( Widget w , XtPointer cd , XtPointer cbs )
01710 {
01711 Three_D_View *im3d = (Three_D_View *) cd ;
01712
01713 ENTRY("AFNI_run_script_CB") ;
01714
01715 MCW_choose_string( im3d->vwid->picture ,
01716 "Enter AFNI script filename:" ,
01717 NULL , AFNI_finalrun_script_CB , cd ) ;
01718 EXRETURN ;
01719 }
01720
01721
01722
01723 void AFNI_finalrun_script_CB( Widget w , XtPointer cd , MCW_choose_cbs *cbs )
01724 {
01725 Three_D_View *im3d = (Three_D_View *) cd ;
01726
01727 ENTRY("AFNI_finalrun_script_CB") ;
01728
01729 AFNI_startup_script_CB( (XtPointer) cbs->cval , NULL ) ;
01730 EXRETURN ;
01731 }
01732