Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

afni_receive.c

Go to the documentation of this file.
00001 /*****************************************************************************
00002    Major portions of this software are copyrighted by the Medical College
00003    of Wisconsin, 1994-2000, and are released under the Gnu General Public
00004    License, Version 2.  See the file README.Copyright for details.
00005 ******************************************************************************/
00006 
00007 #undef MAIN
00008 
00009 #include "afni.h"
00010 
00011 /*-------------------------------------------------------------------*/
00012 /*! Set up to have AFNI send data to a receiver:
00013 
00014      rmask = bitwise OR (|) mask of RECEIVE_*_MASK (cf. afni.h)
00015 
00016      cb    = callback function to receive data; will be called like
00017                cb( int why , int np , void * vp , void * cb_data )
00018              where why = a RECEIVE_* code (cf. below)
00019                    np  = count of data in vp (may be 0)
00020                    vp  = pointer to data being sent (may be NULL)
00021                cb_data = pointer passed into this routine
00022 
00023      cbname = string to identify callback func (for debugging)
00024 
00025      why = RECEIVE_VIEWPOINT --> np = 3, vp = int *, pointing to
00026                                  array of dataset voxel indices just
00027                                  jumped to; vp[0] = x index, etc.
00028 
00029      why = RECEIVE_REDISPLAY --> the user did something to cause
00030                                  an image redisplay besides changing
00031                                  the viewpoint. For this call, np and
00032                                  vp are unused.
00033 
00034      why = RECEIVE_FUNCDISPLAY --> the user did something to cause
00035                                    the function display to change.
00036                                    For this call, np and vp are unused.
00037 
00038      why = RECEIVE_POINTS --> np = number of points drawn
00039                               vp = int **, pointer to array of arrays
00040                                    of dataset voxel indices:
00041                                     vp[0][i] = x index of point i
00042                                     vp[1][i] = y index of point i
00043                                     vp[2][i] = z index of point i,
00044                                     vp[3][0] = sending mode
00045                                    for i=0..np-1
00046 
00047      why = RECEIVE_DRAWNOTICE --> the user drew something and that
00048                                   information was sent to a receiver.
00049                                   This call will occur AFTER all the
00050                                   RECEIVE_POINTS calls have been done.
00051                                   If no RECEIVE_POINTS calls are made,
00052                                   then no RECEIVE_DRAWNOTICE calls will
00053                                   be made either.  For this call,
00054                                   np and vp are unused.
00055 
00056      why = RECEIVE_DSETCHANGE --> the user did something (like rescan
00057                                   a session) that may have changed
00058                                   dataset pointers.  The receiving
00059                                   routine should use dataset idcodes
00060                                   to re-find the correct dataset
00061                                   pointers.  For this call, np and vp
00062                                   are unused.
00063 
00064      why = RECEIVE_CLOSURE --> the user closed the controller window,
00065                                which means that no more data will
00066                                be coming from it -- even if it is
00067                                reopened, AFNI_receive_init must be
00068                                called again.  For this call, np and
00069                                vp are unused.
00070 
00071      why = RECEIVE_ALTERATION --> the user changed something in the
00072                                   controller -- the dataset, the
00073                                   time index, the resampling, ....
00074                                   This is basically a warning
00075                                   message.  For this call, np and
00076                                   vp are unused.
00077 
00078      why = RECEIVE_TIMEINDEX --> the time index changed in im3d;
00079                                  for this call, np,vp are unused.
00080                                  The new time index is in
00081                                    im3d->vinfo->time_index
00082 
00083    This function returns a non-negative int if all is OK -- this
00084    value is the "key" that is used in calls to AFNI_receive_control
00085    when you want to manipulate the status of this connection.
00086 
00087    This function returns -1 if an error occurs.
00088 
00089    Modified 29 Mar 1999 to allow for multiple receivers
00090    (but drawing can only be done in one mode).
00091 ---------------------------------------------------------------------*/
00092 
00093 int AFNI_receive_init( Three_D_View * im3d , int rmask ,
00094                        gen_func * cb , void * cb_data  , char * cbname )
00095 {
00096    int ir ;
00097 
00098 ENTRY("AFNI_receive_init") ;
00099 
00100    /* check for invalid entries */
00101 
00102    if( ! IM3D_VALID(im3d)            ||               /* no good? */
00103        cb == NULL                    ||               /* no receiver? */
00104        (rmask & RECEIVE_ALL_MASK) == 0 ) RETURN(-1) ; /* no action? */
00105 
00106    for( ir=0 ; ir < im3d->vinfo->num_receiver ; ir++ )
00107       if( im3d->vinfo->receiver[ir] == NULL ) break ;
00108 
00109    if( ir == im3d->vinfo->num_receiver ){
00110 #if 0
00111 fprintf(stderr,"AFNI_receive_init AFREALL() with ir=%d num_receiver=%d\n",
00112         ir,im3d->vinfo->num_receiver ) ;
00113 #endif
00114       im3d->vinfo->receiver = AFREALL( im3d->vinfo->receiver, AFNI_receiver *, ir+1 );
00115       im3d->vinfo->num_receiver ++ ;
00116    }
00117    im3d->vinfo->receiver[ir] = AFMALL( AFNI_receiver, sizeof(AFNI_receiver)) ;
00118 
00119    im3d->vinfo->receiver[ir]->receiver_func = cb ;
00120    im3d->vinfo->receiver[ir]->receiver_mask = rmask ;
00121    im3d->vinfo->receiver[ir]->receiver_data = cb_data ;
00122 
00123    im3d->vinfo->receiver[ir]->receiver_funcname =
00124      strdup( (cbname != NULL) ? cbname : "[unknown func]" ) ;
00125 
00126    AFNI_toggle_drawing( im3d ) ;
00127 
00128    RETURN(ir) ;  /* 15 Jun 1999: used to return 0, which is not correct! */
00129 }
00130 
00131 /*-------------------------------------------------------------------------*/
00132 /*! Turn off all reception for this viewer.
00133 ---------------------------------------------------------------------------*/
00134 
00135 void AFNI_receive_destroy( Three_D_View * im3d )
00136 {
00137    int ir ;
00138 
00139 ENTRY("AFNI_receive_destroy") ;
00140 
00141    if( !IM3D_VALID(im3d) ) EXRETURN ;
00142 
00143    if( im3d->vinfo->receiver != NULL && im3d->vinfo->num_receiver > 0 ){
00144 
00145       for( ir=0 ; ir < im3d->vinfo->num_receiver ; ir++ ){
00146 
00147          if( im3d->vinfo->receiver[ir] != NULL ){
00148 #if 0
00149             im3d->vinfo->receiver[ir]->receiver_func(
00150                    RECEIVE_CLOSURE , 0 , NULL ,
00151                    im3d->vinfo->receiver[ir]->receiver_data ) ;
00152 #else
00153             AFNI_CALL_VOID_4ARG( im3d->vinfo->receiver[ir]->receiver_func ,
00154                                  int,RECEIVE_CLOSURE , int,0 ,
00155                                  void *,NULL ,
00156                                  void *,im3d->vinfo->receiver[ir]->receiver_data ) ;
00157 #endif
00158 
00159             if( im3d->vinfo->receiver[ir]->receiver_funcname != NULL )
00160               free( im3d->vinfo->receiver[ir]->receiver_funcname ) ;
00161             free( im3d->vinfo->receiver[ir] ) ;
00162             im3d->vinfo->receiver[ir] = NULL ;
00163          }
00164       }
00165 
00166       im3d->vinfo->num_receiver    = 0 ;
00167       im3d->vinfo->drawing_enabled = 0 ;
00168       im3d->vinfo->drawing_mode    = DRAWING_LINES ;  /* default */
00169    }
00170 
00171    EXRETURN ;
00172 }
00173 
00174 /*-------------------------------------------------------------------*/
00175 /*! Control how the receiver works:
00176     - code = indicates what action is
00177     - arg  = extra information, if code needs it
00178 
00179   This function returns 0 if all is OK, and returns -1 if an error
00180   occurs.
00181 ---------------------------------------------------------------------*/
00182 
00183 int AFNI_receive_control( Three_D_View *im3d, int key, int code, void *arg )
00184 {
00185 ENTRY("AFNI_receive_control") ;
00186 
00187    /* check input for OK-osity */
00188 
00189    if( ! IM3D_VALID(im3d) || im3d->vinfo->receiver == NULL ) RETURN(-1) ;
00190    if( key < 0 || key >= im3d->vinfo->num_receiver )         RETURN(-1) ;
00191    if( im3d->vinfo->receiver[key] == NULL )                  RETURN(-1) ;
00192 
00193    /* take appropriate actions */
00194 
00195    switch( code ){
00196 
00197       default: RETURN(-1) ;
00198 
00199       case DRAWNOTICE_STARTUP:{    /* 30 Mar 1999 */
00200          im3d->vinfo->receiver[key]->receiver_mask |= RECEIVE_DRAWNOTICE_MASK ;
00201       }
00202       break ;
00203 
00204       case DRAWNOTICE_SHUTDOWN:{   /* 30 Mar 1999 */
00205          im3d->vinfo->receiver[key]->receiver_mask &= (RECEIVE_ALL_MASK - RECEIVE_DRAWNOTICE_MASK) ;
00206       }
00207       break ;
00208 
00209       case DSETCHANGE_STARTUP:{    /* 31 Mar 1999 */
00210          im3d->vinfo->receiver[key]->receiver_mask |= RECEIVE_DSETCHANGE_MASK ;
00211       }
00212       break ;
00213 
00214       case DSETCHANGE_SHUTDOWN:{   /* 30 Mar 1999 */
00215          im3d->vinfo->receiver[key]->receiver_mask &= (RECEIVE_ALL_MASK - RECEIVE_DSETCHANGE_MASK) ;
00216       }
00217       break ;
00218 
00219       case DRAWING_STARTUP:{
00220          im3d->vinfo->receiver[key]->receiver_mask |= RECEIVE_DRAWING_MASK ;
00221          AFNI_toggle_drawing( im3d ) ;
00222       }
00223       break ;
00224 
00225       case DRAWING_SHUTDOWN:{
00226          im3d->vinfo->receiver[key]->receiver_mask &= (RECEIVE_ALL_MASK - RECEIVE_DRAWING_MASK) ;
00227          AFNI_toggle_drawing( im3d ) ;
00228       }
00229       break ;
00230 
00231       case DRAWING_OVCINDEX:{
00232          int ind = (int) arg ;
00233 
00234          if( ind <= 0 || ind >= im3d->dc->ovc->ncol_ov ){
00235             RETURN(-1) ;
00236          } else {
00237             Pixel ppp = im3d->dc->ovc->pix_ov[ind] ;
00238             drive_MCW_imseq( im3d->s123, isqDR_button2_pixel, (XtPointer)ppp ) ;
00239             drive_MCW_imseq( im3d->s231, isqDR_button2_pixel, (XtPointer)ppp ) ;
00240             drive_MCW_imseq( im3d->s312, isqDR_button2_pixel, (XtPointer)ppp ) ;
00241             im3d->vinfo->drawing_pixel = ppp ;
00242          }
00243       }
00244       break ;
00245 
00246       case DRAWING_X11PIXEL:{
00247          Pixel ppp = (Pixel) arg ;
00248          drive_MCW_imseq( im3d->s123, isqDR_button2_pixel, (XtPointer)ppp ) ;
00249          drive_MCW_imseq( im3d->s231, isqDR_button2_pixel, (XtPointer)ppp ) ;
00250          drive_MCW_imseq( im3d->s312, isqDR_button2_pixel, (XtPointer)ppp ) ;
00251          im3d->vinfo->drawing_pixel = ppp ;
00252       }
00253       break ;
00254 
00255       case DRAWING_LINES:
00256       case DRAWING_FILL:
00257       case DRAWING_POINTS:
00258       case DRAWING_NODRAW:{
00259          im3d->vinfo->drawing_mode = code ;
00260          drive_MCW_imseq( im3d->s123, isqDR_button2_mode, (XtPointer)code ) ;
00261          drive_MCW_imseq( im3d->s231, isqDR_button2_mode, (XtPointer)code ) ;
00262          drive_MCW_imseq( im3d->s312, isqDR_button2_mode, (XtPointer)code ) ;
00263       }
00264       break ;
00265 
00266       case DRAWING_LINEWIDTH:{    /* 08 Oct 2002 */
00267         int ww = (int) arg ;
00268         if( ww >= 0 ){
00269           drive_MCW_imseq( im3d->s123, isqDR_button2_width, (XtPointer)ww ) ;
00270           drive_MCW_imseq( im3d->s231, isqDR_button2_width, (XtPointer)ww ) ;
00271           drive_MCW_imseq( im3d->s312, isqDR_button2_width, (XtPointer)ww ) ;
00272         }
00273       }
00274       break ;
00275 
00276       case VIEWPOINT_STARTUP:{
00277          im3d->vinfo->receiver[key]->receiver_mask |= RECEIVE_VIEWPOINT_MASK ;
00278       }
00279       break ;
00280 
00281       case VIEWPOINT_SHUTDOWN:{
00282          im3d->vinfo->receiver[key]->receiver_mask &= (RECEIVE_ALL_MASK - RECEIVE_VIEWPOINT_MASK) ;
00283       }
00284       break ;
00285 
00286       case REDISPLAY_STARTUP:{
00287          im3d->vinfo->receiver[key]->receiver_mask |= RECEIVE_REDISPLAY_MASK ;
00288       }
00289       break ;
00290 
00291       case REDISPLAY_SHUTDOWN:{
00292          im3d->vinfo->receiver[key]->receiver_mask &= (RECEIVE_ALL_MASK - RECEIVE_REDISPLAY_MASK) ;
00293       }
00294       break ;
00295 
00296       case FUNCDISPLAY_STARTUP:{
00297          im3d->vinfo->receiver[key]->receiver_mask |= RECEIVE_FUNCDISPLAY_MASK ;
00298       }
00299       break ;
00300 
00301       case FUNCDISPLAY_SHUTDOWN:{
00302          im3d->vinfo->receiver[key]->receiver_mask &= (RECEIVE_ALL_MASK - RECEIVE_FUNCDISPLAY_MASK) ;
00303       }
00304       break ;
00305 
00306       case OVERLAY_STARTUP:{
00307          im3d->vinfo->receiver[key]->receiver_mask |= RECEIVE_OVERLAY_MASK ;
00308       }
00309       break ;
00310 
00311       case OVERLAY_SHUTDOWN:{
00312          im3d->vinfo->receiver[key]->receiver_mask &= (RECEIVE_ALL_MASK - RECEIVE_OVERLAY_MASK) ;
00313       }
00314       break ;
00315 
00316       case TIMEINDEX_STARTUP:{
00317          im3d->vinfo->receiver[key]->receiver_mask |= RECEIVE_TIMEINDEX_MASK ;
00318       }
00319       break ;
00320 
00321       case TIMEINDEX_SHUTDOWN:{
00322          im3d->vinfo->receiver[key]->receiver_mask &= (RECEIVE_ALL_MASK - RECEIVE_TIMEINDEX_MASK) ;
00323       }
00324       break ;
00325 
00326       case EVERYTHING_SHUTDOWN:{
00327          im3d->vinfo->receiver[key]->receiver_mask = 0 ;
00328          AFNI_toggle_drawing( im3d ) ;
00329       }
00330       break ;
00331 
00332    } /* end of switch on codes */
00333 
00334    /* possibly remove this receiver, and maybe even all receivers */
00335 
00336    if( im3d->vinfo->receiver[key]->receiver_mask == 0 ){   /* receiving nothing at all? */
00337       int ir , nn=0 ;
00338 
00339       if( im3d->vinfo->receiver[key]->receiver_funcname != NULL )
00340         free( im3d->vinfo->receiver[key]->receiver_funcname ) ;
00341 
00342       free( im3d->vinfo->receiver[key] ) ;                 /* toss this one fer shur */
00343       im3d->vinfo->receiver[key] = NULL ;
00344 
00345       for( ir=0 ; ir < im3d->vinfo->num_receiver ; ir++ )  /* see if any are left */
00346          if( im3d->vinfo->receiver[ir] != NULL ) nn++ ;
00347 
00348       if( nn == 0 ) im3d->vinfo->num_receiver = 0 ;        /* if not, toss them all */
00349    }
00350 
00351    RETURN(0) ;
00352 }
00353 
00354 /*-------------------------------------------------------------------
00355    Turn the drawing on or off for the given controller
00356 ---------------------------------------------------------------------*/
00357 
00358 void AFNI_toggle_drawing( Three_D_View * im3d )
00359 {
00360    int turn_on = 0 ;
00361 
00362 ENTRY("AFNI_toggle_drawing") ;
00363 
00364    if( ! IM3D_OPEN(im3d) ) EXRETURN ;
00365 
00366    /* count up how many receivers want the drawing */
00367 
00368    if( im3d->vinfo->receiver != NULL ){
00369       int ir ;
00370       for( ir=0 ; ir < im3d->vinfo->num_receiver ; ir++ )
00371          if( im3d->vinfo->receiver[ir] != NULL &&
00372              (im3d->vinfo->receiver[ir]->receiver_mask & RECEIVE_DRAWING_MASK) )
00373             turn_on++ ;
00374    }
00375    im3d->vinfo->drawing_enabled = (turn_on != 0) ;
00376 
00377    if( ! im3d->vinfo->drawing_enabled ){
00378 
00379    /*-- quench the flames --*/
00380 
00381       drive_MCW_imseq( im3d->s123 , isqDR_button2_disable , NULL ) ;
00382       drive_MCW_imseq( im3d->s231 , isqDR_button2_disable , NULL ) ;
00383       drive_MCW_imseq( im3d->s312 , isqDR_button2_disable , NULL ) ;
00384 
00385       drive_MCW_grapher( im3d->g123 , graDR_button2_disable , NULL ) ;
00386       drive_MCW_grapher( im3d->g231 , graDR_button2_disable , NULL ) ;
00387       drive_MCW_grapher( im3d->g312 , graDR_button2_disable , NULL ) ;
00388 
00389    } else {
00390 
00391    /*-- come on baby, light my fire --*/
00392 
00393       drive_MCW_imseq( im3d->s123 , isqDR_button2_enable , NULL ) ;
00394       drive_MCW_imseq( im3d->s231 , isqDR_button2_enable , NULL ) ;
00395       drive_MCW_imseq( im3d->s312 , isqDR_button2_enable , NULL ) ;
00396 
00397       if( im3d->vinfo->drawing_pixel > 0 ){
00398          drive_MCW_imseq( im3d->s123, isqDR_button2_pixel,
00399                           (XtPointer)im3d->vinfo->drawing_pixel ) ;
00400          drive_MCW_imseq( im3d->s231, isqDR_button2_pixel,
00401                           (XtPointer)im3d->vinfo->drawing_pixel ) ;
00402          drive_MCW_imseq( im3d->s312, isqDR_button2_pixel,
00403                           (XtPointer)im3d->vinfo->drawing_pixel ) ;
00404       }
00405 
00406       drive_MCW_imseq( im3d->s123, isqDR_button2_mode,
00407                        (XtPointer)im3d->vinfo->drawing_mode ) ;
00408       drive_MCW_imseq( im3d->s231, isqDR_button2_mode,
00409                        (XtPointer)im3d->vinfo->drawing_mode ) ;
00410       drive_MCW_imseq( im3d->s312, isqDR_button2_mode,
00411                        (XtPointer)im3d->vinfo->drawing_mode ) ;
00412 
00413       drive_MCW_grapher( im3d->g123 , graDR_button2_enable , NULL ) ;
00414       drive_MCW_grapher( im3d->g231 , graDR_button2_enable , NULL ) ;
00415       drive_MCW_grapher( im3d->g312 , graDR_button2_enable , NULL ) ;
00416 
00417    }
00418 
00419    EXRETURN ;
00420 }
00421 
00422 /*-------------------------------------------------------------------
00423    Send alteration message to all receivers
00424    (they don't have to register for this information)
00425 ---------------------------------------------------------------------*/
00426 
00427 void AFNI_process_alteration( Three_D_View * im3d )
00428 {
00429    int ir ;
00430 
00431 ENTRY("AFNI_process_alteration") ;
00432 
00433    if( !IM3D_VALID(im3d) || im3d->vinfo->receiver == NULL  ||
00434                             im3d->vinfo->num_receiver == 0   ) EXRETURN ;
00435 
00436    for( ir=0 ; ir < im3d->vinfo->num_receiver ; ir++ ){
00437       if( im3d->vinfo->receiver[ir] != NULL ){
00438 STATUS(im3d->vinfo->receiver[ir]->receiver_funcname) ;
00439 #if 0
00440          im3d->vinfo->receiver[ir]->receiver_func(
00441                    RECEIVE_ALTERATION , 0 , NULL ,
00442                    im3d->vinfo->receiver[ir]->receiver_data ) ;
00443 #else
00444          AFNI_CALL_VOID_4ARG( im3d->vinfo->receiver[ir]->receiver_func ,
00445                               int,RECEIVE_ALTERATION , int,0 ,
00446                               void *,NULL ,
00447                               void *,im3d->vinfo->receiver[ir]->receiver_data ) ;
00448 #endif
00449       }
00450    }
00451 
00452    EXRETURN ;
00453 }
00454 
00455 /*-------------------------------------------------------------------
00456    Send drawing notices to interested receivers
00457 ---------------------------------------------------------------------*/
00458 
00459 void AFNI_process_drawnotice( Three_D_View * im3d )
00460 {
00461    int ir ;
00462 
00463 ENTRY("AFNI_process_drawnotice") ;
00464 
00465    if( !IM3D_VALID(im3d) || im3d->vinfo->receiver == NULL  ||
00466                             im3d->vinfo->num_receiver == 0   ) EXRETURN ;
00467 
00468    for( ir=0 ; ir < im3d->vinfo->num_receiver ; ir++ ){
00469 
00470       if( im3d->vinfo->receiver[ir] != NULL &&
00471           (im3d->vinfo->receiver[ir]->receiver_mask & RECEIVE_DRAWNOTICE_MASK) ){
00472 
00473 STATUS(im3d->vinfo->receiver[ir]->receiver_funcname) ;
00474 #if 0
00475          im3d->vinfo->receiver[ir]->receiver_func(
00476                    RECEIVE_DRAWNOTICE , 0 , NULL ,
00477                    im3d->vinfo->receiver[ir]->receiver_data ) ;
00478 #else
00479          AFNI_CALL_VOID_4ARG( im3d->vinfo->receiver[ir]->receiver_func ,
00480                               int,RECEIVE_DRAWNOTICE , int,0 ,
00481                               void *,NULL ,
00482                               void *,im3d->vinfo->receiver[ir]->receiver_data ) ;
00483 #endif
00484       }
00485    }
00486 
00487    EXRETURN ;
00488 }
00489 
00490 /*-------------------------------------------------------------------
00491    Send dset change notices to interested receivers
00492 ---------------------------------------------------------------------*/
00493 
00494 void AFNI_process_dsetchange( Three_D_View * im3d )
00495 {
00496    int ir ;
00497 
00498 ENTRY("AFNI_process_dsetchange") ;
00499 
00500    if( !IM3D_VALID(im3d) || im3d->vinfo->receiver == NULL  ||
00501                             im3d->vinfo->num_receiver == 0   ) EXRETURN ;
00502 
00503    for( ir=0 ; ir < im3d->vinfo->num_receiver ; ir++ ){
00504 
00505       if( im3d->vinfo->receiver[ir] != NULL &&
00506           (im3d->vinfo->receiver[ir]->receiver_mask & RECEIVE_DSETCHANGE_MASK) ){
00507 
00508 STATUS(im3d->vinfo->receiver[ir]->receiver_funcname) ;
00509 #if 0
00510          im3d->vinfo->receiver[ir]->receiver_func(
00511                    RECEIVE_DSETCHANGE , 0 , NULL ,
00512                    im3d->vinfo->receiver[ir]->receiver_data ) ;
00513 #else
00514          AFNI_CALL_VOID_4ARG( im3d->vinfo->receiver[ir]->receiver_func ,
00515                               int,RECEIVE_DSETCHANGE , int,0 ,
00516                               void *,NULL ,
00517                               void *,im3d->vinfo->receiver[ir]->receiver_data ) ;
00518 #endif
00519       }
00520    }
00521 
00522    EXRETURN ;
00523 }
00524 
00525 /*-------------------------------------------------------------------
00526    Send new (i,j,k) coordinates to all receivers that care
00527 ---------------------------------------------------------------------*/
00528 
00529 void AFNI_process_viewpoint( Three_D_View * im3d )
00530 {
00531    int ir , ijk[3] ;
00532 
00533 ENTRY("AFNI_process_viewpoint") ;
00534 
00535    if( !IM3D_VALID(im3d) || im3d->vinfo->receiver == NULL  ||
00536                             im3d->vinfo->num_receiver == 0   ) EXRETURN ;
00537 
00538    ijk[0] = im3d->vinfo->i1 ;
00539    ijk[1] = im3d->vinfo->j2 ;
00540    ijk[2] = im3d->vinfo->k3 ;
00541 
00542    for( ir=0 ; ir < im3d->vinfo->num_receiver ; ir++ ){
00543       if( im3d->vinfo->receiver[ir] != NULL &&
00544           (im3d->vinfo->receiver[ir]->receiver_mask & RECEIVE_VIEWPOINT_MASK) ){
00545 
00546 STATUS(im3d->vinfo->receiver[ir]->receiver_funcname) ;
00547 #if 0
00548          im3d->vinfo->receiver[ir]->receiver_func(
00549                    RECEIVE_VIEWPOINT , 3 , ijk ,
00550                    im3d->vinfo->receiver[ir]->receiver_data ) ;
00551 #else
00552          AFNI_CALL_VOID_4ARG( im3d->vinfo->receiver[ir]->receiver_func ,
00553                               int,RECEIVE_VIEWPOINT , int,3 ,
00554                               void *,ijk ,
00555                               void *,im3d->vinfo->receiver[ir]->receiver_data ) ;
00556 #endif
00557       }
00558    }
00559 
00560    EXRETURN ;
00561 }
00562 
00563 /*-------------------------------------------------------------------*/
00564 /*! Send time index change notice to receivers that care [29 Jan 2003]
00565 ---------------------------------------------------------------------*/
00566 
00567 void AFNI_process_timeindex( Three_D_View * im3d )
00568 {
00569    int ir ;
00570 
00571 ENTRY("AFNI_process_timeindex") ;
00572 
00573    if( !IM3D_VALID(im3d) || im3d->vinfo->receiver == NULL  ||
00574                             im3d->vinfo->num_receiver == 0   ) EXRETURN ;
00575 
00576    for( ir=0 ; ir < im3d->vinfo->num_receiver ; ir++ ){
00577       if( im3d->vinfo->receiver[ir] != NULL &&
00578           (im3d->vinfo->receiver[ir]->receiver_mask & RECEIVE_TIMEINDEX_MASK) ){
00579 
00580 STATUS(im3d->vinfo->receiver[ir]->receiver_funcname) ;
00581 #if 0
00582          im3d->vinfo->receiver[ir]->receiver_func(
00583                    RECEIVE_TIMEINDEX , 0 , NULL ,
00584                    im3d->vinfo->receiver[ir]->receiver_data ) ;
00585 #else
00586          AFNI_CALL_VOID_4ARG( im3d->vinfo->receiver[ir]->receiver_func ,
00587                               int,RECEIVE_TIMEINDEX , int,0 ,
00588                               void *,NULL ,
00589                               void *,im3d->vinfo->receiver[ir]->receiver_data ) ;
00590 #endif
00591       }
00592    }
00593 
00594    EXRETURN ;
00595 }
00596 
00597 /*-------------------------------------------------------------------*/
00598 /*! Send redisplay notification to receivers that care [04 Mar 2002].
00599 ---------------------------------------------------------------------*/
00600 
00601 void AFNI_process_redisplay( Three_D_View * im3d )
00602 {
00603    int ir ;
00604 
00605 ENTRY("AFNI_process_redisplay") ;
00606 
00607    if( !IM3D_VALID(im3d) || im3d->vinfo->receiver == NULL  ||
00608                             im3d->vinfo->num_receiver == 0   ) EXRETURN ;
00609 
00610    for( ir=0 ; ir < im3d->vinfo->num_receiver ; ir++ ){
00611       if( im3d->vinfo->receiver[ir] != NULL &&
00612           (im3d->vinfo->receiver[ir]->receiver_mask & RECEIVE_REDISPLAY_MASK) ){
00613 
00614 STATUS(im3d->vinfo->receiver[ir]->receiver_funcname) ;
00615 #if 0
00616          im3d->vinfo->receiver[ir]->receiver_func(
00617                    RECEIVE_REDISPLAY , 0 , NULL ,
00618                    im3d->vinfo->receiver[ir]->receiver_data ) ;
00619 #else
00620          AFNI_CALL_VOID_4ARG( im3d->vinfo->receiver[ir]->receiver_func ,
00621                               int,RECEIVE_REDISPLAY , int,0 ,
00622                               void *,NULL ,
00623                               void *,im3d->vinfo->receiver[ir]->receiver_data ) ;
00624 #endif
00625       }
00626    }
00627 
00628    EXRETURN ;
00629 }
00630 
00631 /*-------------------------------------------------------------------*/
00632 /*! Send funcdisplay notification to receivers that care [05 Mar 2002].
00633 ---------------------------------------------------------------------*/
00634 
00635 void AFNI_process_funcdisplay( Three_D_View * im3d )
00636 {
00637    int ir ;
00638 
00639 ENTRY("AFNI_process_funcdisplay") ;
00640 
00641    if( !IM3D_VALID(im3d) || im3d->vinfo->receiver == NULL  ||
00642                             im3d->vinfo->num_receiver == 0   ) EXRETURN ;
00643 
00644    for( ir=0 ; ir < im3d->vinfo->num_receiver ; ir++ ){
00645       if( im3d->vinfo->receiver[ir] != NULL &&
00646           (im3d->vinfo->receiver[ir]->receiver_mask & RECEIVE_FUNCDISPLAY_MASK) ){
00647 
00648 STATUS(im3d->vinfo->receiver[ir]->receiver_funcname) ;
00649 #if 0
00650          im3d->vinfo->receiver[ir]->receiver_func(
00651                    RECEIVE_FUNCDISPLAY , 0 , NULL ,
00652                    im3d->vinfo->receiver[ir]->receiver_data ) ;
00653 #else
00654          AFNI_CALL_VOID_4ARG( im3d->vinfo->receiver[ir]->receiver_func ,
00655                               int,RECEIVE_FUNCDISPLAY , int,0 ,
00656                               void *,NULL ,
00657                               void *,im3d->vinfo->receiver[ir]->receiver_data ) ;
00658 #endif
00659       }
00660    }
00661 
00662    EXRETURN ;
00663 }
00664 
00665 /*-------------------------------------------------------------------*/
00666 /*! Process drawn points:
00667     - npts  = number of points sent in
00668     - mode  = type of points to follow:
00669               - PLANAR_MODE + zz ==> axis zz is fixed, for zz=1,2,3
00670               - SINGLE_MODE + zz ==> one point only, clicked in a
00671                                       window with zz fixed
00672               - THREED_MODE      ==> points are in 3D (not planar)
00673                                       (not currently possible)
00674               - UNDO_MODE        ==> undo last drawing action
00675 
00676     - xd[i] = x index of point i, for i=0..npts-1
00677     - yd[i] = y index of point i, for i=0..npts-1
00678     - zd[i] = z index of point i, for i=0..npts-1
00679 
00680    These indices are with respect to the dataset brick axes.
00681 ---------------------------------------------------------------------*/
00682 
00683 void AFNI_process_drawing( Three_D_View *im3d , int mode ,
00684                            int npts , int *xd , int *yd , int *zd )
00685 {
00686    int ii , nn , ir , nsent ;
00687    int *vp[4] , *xn=NULL , *yn=NULL , *zn=NULL ;
00688 
00689 ENTRY("AFNI_process_drawing") ;
00690 
00691    if( !IM3D_VALID(im3d) || im3d->vinfo->receiver == NULL  ||
00692                             im3d->vinfo->num_receiver == 0 ||
00693        npts < 0          || im3d->vinfo->drawing_enabled == 0 ) EXRETURN ;
00694 
00695 if(PRINT_TRACING){
00696   char str[256] ; sprintf(str,"received %d points",npts) ; STATUS(str) ;
00697 }
00698 
00699    /*-- if no further treatment is needed,
00700         just flag input data to be set to receiver --*/
00701 
00702    if( im3d->vinfo->drawing_mode == DRAWING_POINTS ||
00703        im3d->vinfo->drawing_mode == DRAWING_NODRAW || npts <= 1 ){
00704 
00705       xn = xd ; yn = yd ; zn = zd ; nn = npts ;
00706    }
00707 
00708    /*-- must fill in the lines:
00709         create arrays xn, yn, zn of length nn --*/
00710 
00711    else if( im3d->vinfo->drawing_mode == DRAWING_LINES ){
00712 
00713       AFNI_3d_linefill( npts , xd,yd,zd , &nn , &xn , &yn , &zn ) ;
00714    }
00715 
00716    /*-- must fill in the polygon --*/
00717 
00718    else if( im3d->vinfo->drawing_mode == DRAWING_FILL ){
00719 
00720       /* this just fills the lines like above --
00721          need to write a real polygon filling routine? */
00722 
00723       AFNI_3d_linefill( npts , xd,yd,zd , &nn , &xn , &yn , &zn ) ;
00724    }
00725 
00726    /*-- send data to receivers that want it --*/
00727 
00728 #if 0
00729 fprintf(stderr,"Sending %d points to receiver\n",nn) ;
00730 #endif
00731 
00732    vp[3] = &mode ;                        /* how the points are arranged */
00733 
00734    vp[0] = xn ; vp[1] = yn ; vp[2] = zn ;
00735 
00736    for( nsent=ir=0 ; ir < im3d->vinfo->num_receiver ; ir++ ){
00737 
00738       if( im3d->vinfo->receiver[ir] != NULL &&
00739           (im3d->vinfo->receiver[ir]->receiver_mask & RECEIVE_DRAWING_MASK) ){
00740 
00741 STATUS(im3d->vinfo->receiver[ir]->receiver_funcname) ;
00742 #if 0
00743          im3d->vinfo->receiver[ir]->receiver_func(
00744                    RECEIVE_POINTS , nn ,
00745                    (void *) vp , im3d->vinfo->receiver[ir]->receiver_data ) ;
00746 #else
00747          AFNI_CALL_VOID_4ARG( im3d->vinfo->receiver[ir]->receiver_func ,
00748                               int,RECEIVE_POINTS , int,nn ,
00749                               void *,vp ,
00750                               void *,im3d->vinfo->receiver[ir]->receiver_data ) ;
00751 #endif
00752          nsent++ ;
00753       }
00754    }
00755 
00756    /* 30 Mar 1999: also send DRAWNOTICE to receivers that like this stuff */
00757 
00758    if( nsent > 0 ) AFNI_process_drawnotice( im3d ) ;
00759 
00760    /*-- free any created arrays --*/
00761 
00762    if( xn != xd ){ free(xn); free(yn); free(zn); }
00763    EXRETURN ;
00764 }
00765 
00766 /*--------------------------------------------------------------------
00767    3D line filler-inner -- quick and dirty.
00768    The output arrays (*xout, *yout, *zout) should be freed when
00769    their usefulness is over.
00770 ----------------------------------------------------------------------*/
00771 
00772 void AFNI_3d_linefill( int   nin  , int *  xin  , int *  yin  , int *  zin ,
00773                        int * nout , int ** xout , int ** yout , int ** zout )
00774 {
00775    int * xut , * yut , * zut ;
00776    int   nut , iin , jout , nall ;
00777    int   x1,y1,z1 , x2,y2,z2 , dx,dy,dz , adx,ady,adz , xlast,ylast,zlast ;
00778    float fdxyz , fdx,fdy,fdz , fx,fy,fz ;
00779 
00780 ENTRY("AFNI_3d_linefill") ;
00781 
00782    /* sanity check */
00783 
00784    if( nin <= 0 || xin == NULL || yin == NULL || zin == NULL ){
00785       *nout = 0 ; *xout = *yout = *zout = NULL ; EXRETURN ;
00786    }
00787 
00788    /* trivial case */
00789 
00790    if( nin == 1 ){
00791       nut = 1 ;                                             *nout = nut ;
00792       xut = (int *) malloc(sizeof(int)) ; xut[0] = xin[0] ; *xout = xut ;
00793       yut = (int *) malloc(sizeof(int)) ; yut[0] = yin[0] ; *yout = yut ;
00794       zut = (int *) malloc(sizeof(int)) ; zut[0] = zin[0] ; *zout = zut ;
00795       EXRETURN ;
00796    }
00797 
00798    /* setup to scan through lines */
00799 
00800    nall = nin ;
00801    xut  = (int *) malloc( sizeof(int) * nall ) ;
00802    yut  = (int *) malloc( sizeof(int) * nall ) ;
00803    zut  = (int *) malloc( sizeof(int) * nall ) ;
00804    nut  = 0 ;
00805 
00806 #undef  ADDPT
00807 #define ADDPT(i,j,k)                                          \
00808   do{ if( nut == nall ){                                      \
00809          nall += 128 ;                                        \
00810          xut = (int *) realloc( xut , sizeof(int) * nall ) ;  \
00811          yut = (int *) realloc( yut , sizeof(int) * nall ) ;  \
00812          zut = (int *) realloc( zut , sizeof(int) * nall ) ;  \
00813       }                                                       \
00814       xut[nut] = xlast = (i) ;                                \
00815       yut[nut] = ylast = (j) ;                                \
00816       zut[nut] = zlast = (k) ; nut++ ; } while(0)
00817 
00818    /* draw line from point #iin to #iin+1 */
00819 
00820    x2 = xin[0] ; y2 = yin[0] ; z2 = zin[0] ;
00821    for( iin=0 ; iin < nin-1 ; iin++ ){
00822       x1  = x2         ; y1  = y2         ; z1  = z2 ;
00823       x2  = xin[iin+1] ; y2  = yin[iin+1] ; z2  = zin[iin+1] ;
00824       dx  = x2 - x1    ; dy  = y2 - y1    ; dz  = z2 - z1 ;
00825       adx = abs(dx)    ; ady = abs(dy)    ; adz = abs(dz) ;
00826 
00827       /* add start point to list */
00828 
00829       ADDPT(x1,y1,z1) ;
00830 
00831       /* special case: neighbors ==> skip to next line */
00832 
00833       if( adx <= 1 && ady <= 1 && adz <= 1 ) continue ;
00834 
00835       /* OK, we have to do work (moan) */
00836 
00837 #define SFRAC 0.495
00838 
00839       fdxyz = adx + ady + adz ;                /* Manhattan distance */
00840       fdx   = SFRAC * dx / fdxyz ;             /* steps */
00841       fdy   = SFRAC * dy / fdxyz ;
00842       fdz   = SFRAC * dz / fdxyz ;
00843 
00844       /* step thru in small increments,
00845          adding new integer points, and stopping at line's end */
00846 
00847 #if 0
00848 fprintf(stderr,"linefill: from %d %d %d to %d %d %d\n",
00849         x1,y1,z1 , x2,y2,z2 ) ;
00850 #endif
00851 
00852       fx = x1+fdx+0.499 ; fy = y1+fdy+0.499 ; fz = z1+fdz+0.499 ;
00853       do {
00854          fx = fx + fdx ; fy = fy + fdy ; fz = fz + fdz ;
00855          x1 = (int) fx ; y1 = (int) fy ; z1 = (int) fz ;
00856 
00857 #if 0
00858 fprintf(stderr,"   at %d %d %d\n",x1,y1,z1) ;
00859 #endif
00860 
00861          if( x1 == x2    && y1 == y2    && z1 == z2    ) break ;
00862 
00863          if( x1 != xlast || y1 != ylast || z1 != zlast ) ADDPT(x1,y1,z1) ;
00864       } while(1) ;
00865 
00866    } /* end of loop over lines */
00867 
00868    ADDPT(x2,y2,z2) ;  /* add last point */
00869 
00870    *nout = nut ; *xout = xut ; *yout = yut ; *zout = zut ;
00871    EXRETURN ;
00872 }
00873 
00874 /*********************************************************************
00875    Coordinate inter-conversion routines.
00876 **********************************************************************/
00877 
00878 void AFNI_ijk_to_xyz( THD_3dim_dataset * dset ,
00879                       int ii , int jj , int kk ,
00880                       float * xx , float * yy , float * zz )
00881 {
00882    THD_fvec3 fv ;
00883 
00884    if( ! ISVALID_DSET(dset) ) return ;
00885 
00886    fv  = THD_3dind_to_3dmm( dset , TEMP_IVEC3(ii,jj,kk) ) ;
00887    *xx = fv.xyz[0] ;
00888    *yy = fv.xyz[1] ;
00889    *zz = fv.xyz[2] ;
00890    return ;
00891 }
00892 
00893 void AFNI_xyz_to_ijk( THD_3dim_dataset * dset ,
00894                       float xx , float yy , float zz ,
00895                       int * ii , int * jj , int * kk  )
00896 {
00897    THD_ivec3 iv ;
00898 
00899    if( ! ISVALID_DSET(dset) ) return ;
00900 
00901    iv  = THD_3dmm_to_3dind ( dset , TEMP_FVEC3(xx,yy,zz) ) ;
00902    *ii = iv.ijk[0] ;
00903    *jj = iv.ijk[1] ;
00904    *kk = iv.ijk[2] ;
00905    return ;
00906 }
00907 
00908 void AFNI_xyz_to_dicomm( THD_3dim_dataset * dset ,
00909                          float xx , float yy , float zz ,
00910                          float * xd , float * yd , float * zd )
00911 {
00912    THD_fvec3 fv ;
00913 
00914    if( ! ISVALID_DSET(dset) ) return ;
00915 
00916    fv  = THD_3dmm_to_dicomm( dset , TEMP_FVEC3(xx,yy,zz) ) ;
00917    *xd = fv.xyz[0] ;
00918    *yd = fv.xyz[1] ;
00919    *zd = fv.xyz[2] ;
00920    return ;
00921 }
00922 
00923 void AFNI_dicomm_to_xyz( THD_3dim_dataset * dset ,
00924                          float xd , float yd , float zd ,
00925                          float * xx , float * yy , float * zz )
00926 {
00927    THD_fvec3 fv ;
00928 
00929    if( ! ISVALID_DSET(dset) ) return ;
00930 
00931    fv  = THD_3dmm_to_dicomm( dset , TEMP_FVEC3(xd,yd,zd) ) ;
00932    *xx = fv.xyz[0] ;
00933    *yy = fv.xyz[1] ;
00934    *zz = fv.xyz[2] ;
00935    return ;
00936 }
 

Powered by Plone

This site conforms to the following standards: