1 #include "afni.h"
2
3 static char *abet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
4
5 static FILE *fpc[MAX_CONTROLLERS] ;
6
7 #undef EPS
8 #define EPS 0.01 /* threshold for coordinate changes */
9
10 /*----------------------------------------------------------------------------*/
11
AFNI_filer_viewpoint_CB(int why,int q,void * qq,void * qqq)12 static void AFNI_filer_viewpoint_CB( int why, int q, void *qq, void *qqq )
13 {
14 Three_D_View *im3d = (Three_D_View *)qqq ;
15 int ic , vv , ii,jj,kk ; float xx,yy,zz ;
16 static float xold=-666,yold=-777,zold=-888 ;
17
18 ENTRY("AFNI_filer_viewpoint_CB") ;
19
20 if( !IM3D_OPEN(im3d) ) EXRETURN ;
21 ic = AFNI_controller_index(im3d) ;
22 if( ic < 0 || ic >= MAX_CONTROLLERS || fpc[ic] == NULL ) EXRETURN ;
23
24 xx = im3d->vinfo->xi ; yy = im3d->vinfo->yj ; zz = im3d->vinfo->zk ;
25 ii = im3d->vinfo->i1 ; jj = im3d->vinfo->j2 ; kk = im3d->vinfo->k3 ;
26
27 if( fabs(xx-xold) < EPS &&
28 fabs(yy-yold) < EPS &&
29 fabs(zz-zold) < EPS ) EXRETURN ; /* too close to old point */
30
31 vv = fprintf( fpc[ic] , "%10.4f %10.4f %10.4f %d %d %d\n" ,
32 xx,yy,zz , ii,jj,kk ) ;
33 if( vv < 0 ){
34 ERROR_message("Can't write viewpoint for [%c]",abet[ic]) ;
35 fclose(fpc[ic]) ; fpc[ic] = NULL ;
36 } else {
37 fflush(fpc[ic]) ;
38 }
39
40 EXRETURN ;
41 }
42
43 /*----------------------------------------------------------------------------*/
44
AFNI_coord_filer_setup(Three_D_View * im3d)45 void AFNI_coord_filer_setup( Three_D_View *im3d )
46 {
47 char ename[32] , *eval ; int ic ;
48
49 ENTRY("AFNI_coord_filer_setup") ;
50
51 if( !IM3D_OPEN(im3d) ) EXRETURN ;
52 ic = AFNI_controller_index(im3d) ;
53 if( ic < 0 || ic >= MAX_CONTROLLERS || fpc[ic] != NULL ) EXRETURN ;
54
55 sprintf(ename,"AFNI_FILE_COORDS_%c",abet[ic]) ;
56 eval = my_getenv(ename) ;
57 if( eval == NULL || *eval == '\0' ){ fpc[ic] = NULL ; EXRETURN ; }
58
59 if( strcmp(eval,"-") == 0 || strncmp(eval,"stdout",6) == 0 )
60 fpc[ic] = stdout ;
61 else {
62 fpc[ic] = fopen( eval , "w" ) ;
63 if( fpc[ic] == NULL ){
64 ERROR_message("Unable to open file %s from %s",eval,ename) ;
65 EXRETURN ;
66 }
67 }
68
69 AFNI_receive_init( im3d , RECEIVE_VIEWPOINT_MASK ,
70 AFNI_filer_viewpoint_CB ,
71 im3d , "AFNI_filer_viewpoint_CB" ) ;
72
73 INFO_message("Logging [%c] viewpoint changes to '%s'",abet[ic],eval) ;
74 EXRETURN ;
75 }
76