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  

plug_nth_dataset.c File Reference

#include "afni.h"

Go to the source code of this file.


Defines

#define DSETN_VERSION   "Version 1.1 <October, 2002>"
#define NMAX   9

Functions

char * DSETN_main (PLUGIN_interface *)
void DSETN_func (MRI_IMAGE *)
void DSETN_dset_recv (int why, int np, int *ijk, void *aux)
int set_global_dsets_from_ids (void)
void DSETN_func_init (void)
DEFINE_PLUGIN_PROTOTYPE PLUGIN_interface * PLUGIN_init (int ncall)

Variables

char helpstring []
THD_3dim_datasetdset [NMAX]
MCW_idcode g_id [NMAX]
int ovc [NMAX]
int g_dset_recv = -1
int g_valid_data = 0
char * lr [2] = { "Left" , "Right" }
char * ez [2] = { "Extend" , "Zero" }
PLUGIN_interface * plint = NULL

Define Documentation

#define DSETN_VERSION   "Version 1.1 <October, 2002>"
 

Definition at line 7 of file plug_nth_dataset.c.

#define NMAX   9
 

Definition at line 75 of file plug_nth_dataset.c.

Referenced by DSETN_func(), DSETN_main(), PLUGIN_init(), and set_global_dsets_from_ids().


Function Documentation

void DSETN_dset_recv int    why,
int    np,
int *    ijk,
void *    aux
 

Definition at line 233 of file plug_nth_dataset.c.

References AFNI_receive_control(), ENTRY, EVERYTHING_SHUTDOWN, g_dset_recv, g_valid_data, MCW_TIMER_KILL, MCW_USER_KILL, plint, PLUTO_popup_worker(), RECEIVE_ALTERATION, RECEIVE_DSETCHANGE, and set_global_dsets_from_ids().

Referenced by DSETN_main().

00234 {
00235     PLUGIN_interface * plint = (PLUGIN_interface *)aux;
00236 
00237 ENTRY( "DSETN_dset_recv" );
00238 
00239     switch ( why )
00240     {
00241         default:
00242         {
00243             fprintf( stderr, "warning: DSETN_dset_recv() called with invalid "
00244                              "why code, %d\n", why );
00245             EXRETURN;
00246         }
00247 
00248         case RECEIVE_ALTERATION:   /* may take effect before DSETCHANGE */
00249         case RECEIVE_DSETCHANGE:
00250         {
00251             /* start by noting the number of valid data sets */
00252             int num_valid = set_global_dsets_from_ids( );
00253 
00254             if ( g_valid_data != 1 || num_valid <= 0 )
00255             {
00256                 /* shut the plugin down - "he's only _mostly_ dead" */
00257 
00258                 g_valid_data = 0;
00259 
00260                 AFNI_receive_control( plint->im3d, g_dset_recv,
00261                                       EVERYTHING_SHUTDOWN, NULL );
00262                 g_dset_recv = -1;
00263                 PLUTO_popup_worker( plint,
00264                                         "Warning: plugin 'Dataset#N'\n"
00265                                         "has lost its dataset links.\n"
00266                                         "To plot 1-D overlays, please\n"
00267                                         "re-run the plugin.",
00268                                     MCW_USER_KILL | MCW_TIMER_KILL ) ;
00269             }
00270         }
00271     }
00272 
00273     EXRETURN;
00274 }

void DSETN_func MRI_IMAGE  
 

Definition at line 278 of file plug_nth_dataset.c.

References ADDTO_IMARR, AFNI_needs_dset_ijk(), DESTROY_IMARR, ENTRY, FREE_IMARR, g_valid_data, IMARR_COUNT, IMARR_SUBIM, INIT_IMARR, ISVALID_DSET, MAX, mri_add_name(), MRI_FLOAT_PTR, mri_move_guts(), mri_new(), NMAX, MRI_IMAGE::nx, ovc, and THD_extract_series().

Referenced by PLUGIN_init().

00279 {
00280    int id , ny , nxtop=0 , ijk , ii ;
00281    MRI_IMARR *tar ;
00282    MRI_IMAGE *tsim , *zim ;
00283    float *tsar , *dar ;
00284    int ovi[NMAX] ;
00285    char str[16+4*NMAX] ;
00286 
00287 ENTRY( "DSETN_func" );
00288 
00289    if ( g_valid_data != 1 )
00290        EXRETURN ;                                 /* nothing to do */
00291 
00292    INIT_IMARR(tar) ;
00293    ijk = AFNI_needs_dset_ijk() ;          /* voxel index from AFNI */
00294 
00295    for( id=0 ; id < NMAX ; id++ ){
00296      if( ISVALID_DSET(dset[id]) ){
00297        tsim = THD_extract_series( ijk,dset[id], 0 ) ;  /* get data */
00298        if( tsim == NULL ) continue ;
00299        ovi[IMARR_COUNT(tar)] = ovc[id] ;
00300        ADDTO_IMARR(tar,tsim) ;
00301        nxtop = MAX(nxtop,tsim->nx) ;
00302      }
00303    }
00304 
00305    ny = IMARR_COUNT(tar) ;
00306 
00307    if( ny == 0 || nxtop < 2 ){ DESTROY_IMARR(tar); EXRETURN; } /* no data */
00308 
00309    if( ny == 1 ){                                  /* one dataset */
00310      tsim = IMARR_SUBIM(tar,0); FREE_IMARR(tar);
00311      mri_move_guts(qim,tsim);
00312      sprintf(str,"color: %d",ovi[0]) ; mri_add_name(str,qim) ;
00313      EXRETURN;
00314    }
00315                                              /* multiple datasets */
00316 
00317    tsim = mri_new( nxtop , ny , MRI_float ) ;
00318    tsar = MRI_FLOAT_PTR(tsim) ;
00319    strcpy(str,"color:") ;
00320    for( id=0 ; id < ny ; id++ ){
00321       zim = IMARR_SUBIM(tar,id) ;
00322       dar = MRI_FLOAT_PTR(zim) ;
00323       memcpy( tsar , dar , sizeof(float)*zim->nx) ;
00324       if( zim->nx < nxtop ){   /* 18 Mar 2004: fill with infinity */
00325         for( ii=zim->nx ; ii < nxtop ; ii++ ) tsar[ii] = WAY_BIG ;
00326       }
00327       tsar += nxtop ;
00328       sprintf(str+strlen(str)," %d",ovi[id]) ;
00329    }
00330 
00331    DESTROY_IMARR(tar) ;
00332    mri_move_guts(qim,tsim) ; mri_add_name(str,qim) ;
00333    EXRETURN;
00334 }

void DSETN_func_init void    [static]
 

Definition at line 97 of file plug_nth_dataset.c.

References plint, and PLUG_startup_plugin_CB().

Referenced by PLUGIN_init().

00098 {
00099    PLUG_startup_plugin_CB( NULL , (XtPointer)plint , NULL ) ;
00100 }

char * DSETN_main PLUGIN_interface *   
 

Definition at line 155 of file plug_nth_dataset.c.

References AFNI_receive_init(), DSETN_dset_recv(), ENTRY, ez, g_dset_recv, g_valid_data, ISVALID_DSET, lr, NMAX, ovc, plint, PLUTO_find_dset(), PLUTO_force_redisplay(), RECEIVE_DSETCHANGE_MASK, RETURN, and ZERO_IDCODE.

Referenced by PLUGIN_init().

00156 {
00157    MCW_idcode *idc ;
00158    char *str , *tag ;
00159    int id=0 ;
00160 
00161 ENTRY( "DSETN_main" ) ;
00162 
00163    if( plint == NULL )
00164       RETURN("***********************\n"
00165              "DSETN_main:  NULL input\n"
00166              "***********************") ;
00167 
00168    for( id=0 ; id < NMAX ; id++ ){   /* 18 Mar 2004: renullification */
00169      dset[id] = NULL ;
00170      ZERO_IDCODE(g_id[id]);
00171    }
00172 
00173    id = 0 ;
00174 
00175    while( (tag=PLUTO_get_optiontag(plint)) != NULL ){
00176 
00177       /* Input */
00178 
00179       if( strcmp(tag,"Input") == 0 ){
00180         idc      = PLUTO_get_idcode(plint) ;
00181         dset[id] = PLUTO_find_dset(idc) ;
00182 
00183         if ( ! ISVALID_DSET( dset[id] ) )
00184             RETURN("******************************\n"
00185                    "DSETN_main:  bad input dataset\n"
00186                    "******************************") ;
00187 
00188         g_id[id] = *idc ;
00189         ovc [id] = PLUTO_get_overlaycolor(plint) ;
00190         id++ ; continue ;
00191       }
00192 
00193 #ifdef USE_WHERE
00194       /* Where */
00195 
00196       if( strcmp(tag,"Where") == 0 ){
00197         str = PLUTO_get_string(plint) ;
00198         justify = (strcmp(str,lr[0]) != 0) ;
00199         continue ;
00200       }
00201 
00202       /* How */
00203 
00204       if( strcmp(tag,"How") == 0 ){
00205         str = PLUTO_get_string(plint) ;
00206         fill = (strcmp(str,ez[0]) != 0) ;
00207         continue ;
00208       }
00209 #endif
00210 
00211    }
00212 
00213    if ( id <= 0 )                       /* no data - nothing to do */
00214        RETURN( NULL ) ;
00215 
00216    g_valid_data = 1 ;                   /* valid data, woohooo!    */
00217 
00218    if ( g_dset_recv < 0 )
00219        g_dset_recv = AFNI_receive_init( plint->im3d, RECEIVE_DSETCHANGE_MASK,
00220                                         DSETN_dset_recv, plint ,
00221                                        "DSETN_dset_recv" ) ;
00222    if ( g_dset_recv < 0 )
00223      RETURN("*************************************\n"
00224             "DSETN_main:  failed AFNI_receive_init\n"
00225             "*************************************") ;
00226 
00227    PLUTO_force_redisplay() ;
00228    RETURN( NULL );
00229 }

DEFINE_PLUGIN_PROTOTYPE PLUGIN_interface* PLUGIN_init int    ncall
 

Definition at line 105 of file plug_nth_dataset.c.

References AFNI_register_nD_func_init(), AFNI_register_nD_function(), ANAT_ALL_MASK, DSETN_func(), DSETN_func_init(), DSETN_main(), ENTRY, ez, FUNC_ALL_MASK, generic_func, helpstring, lr, NEEDS_DSET_INDEX, NMAX, plint, PLUTO_add_hint(), PLUTO_set_runlabels(), PLUTO_set_sequence(), PROCESS_MRI_IMAGE, RETURN, and ZERO_IDCODE.

00106 {
00107    int id ;
00108 
00109 ENTRY("PLUGIN_init - Dataset#N") ;
00110 
00111    if( ncall > 0 ) RETURN( NULL );  /* only one interface */
00112 
00113    AFNI_register_nD_function ( 1 , "Dataset#N" , (generic_func *)DSETN_func ,
00114                                NEEDS_DSET_INDEX|PROCESS_MRI_IMAGE ) ;
00115    AFNI_register_nD_func_init( 1 , (generic_func *) DSETN_func_init ) ;  /* 21 Jul 2003 */
00116 
00117    plint = PLUTO_new_interface( "Dataset#N", "Controls 1D function Dataset#N",
00118                                  helpstring, PLUGIN_CALL_VIA_MENU, DSETN_main  ) ;
00119 
00120    PLUTO_add_hint( plint , "Controls 1D function Dataset#N" ) ;
00121 
00122    PLUTO_set_sequence( plint , "A:funcs:dataset#N" ) ;
00123 
00124    PLUTO_set_runlabels( plint , "Set+Keep" , "Set+Close" ) ;  /* 04 Nov 2003 */
00125 
00126    for( id=0 ; id < NMAX ; id++ ){
00127      PLUTO_add_option( plint , "Input" , "Input" , FALSE ) ;
00128      PLUTO_add_dataset(plint , "Dataset" ,
00129                                       ANAT_ALL_MASK , FUNC_ALL_MASK ,
00130                                       DIMEN_4D_MASK | BRICK_ALLREAL_MASK ) ;
00131      PLUTO_add_overlaycolor( plint , "Color" ) ;
00132    }
00133 
00134 #ifdef USE_WHERE
00135    PLUTO_add_option( plint , "Where" , "Where" , FALSE ) ;
00136    PLUTO_add_string( plint, "Justify", 2, lr, justify ) ;
00137 
00138    PLUTO_add_option( plint , "How" , "How" , FALSE ) ;
00139    PLUTO_add_string( plint, "Fill", 2, ez, fill ) ;
00140 #endif
00141 
00142    /* init the global lists */
00143    for ( id=0 ; id < NMAX ; id++ ){
00144         dset[id] = NULL;
00145         ZERO_IDCODE(g_id[id]);
00146    }
00147 
00148    RETURN( plint ) ;
00149 }

int set_global_dsets_from_ids void    [static]
 

Definition at line 336 of file plug_nth_dataset.c.

References dptr, ENTRY, ISVALID_DSET, ISZERO_IDCODE, NMAX, PLUTO_find_dset(), RETURN, and ZERO_IDCODE.

Referenced by DSETN_dset_recv().

00337 {
00338     THD_3dim_dataset * dptr;
00339     int idcount, num_valid = 0;
00340 
00341 ENTRY( "set_global_dsets_from_ids" );
00342 
00343     for ( idcount = 0; idcount < NMAX; idcount++ )
00344     {
00345         if ( ! ISZERO_IDCODE( g_id[idcount] ) )
00346         {
00347             dptr = PLUTO_find_dset( &g_id[idcount] );
00348             if ( ! ISVALID_DSET( dptr ) )
00349             {
00350                 dptr = NULL;
00351                 ZERO_IDCODE( g_id[idcount] );   /* lost dataset    */
00352             }
00353             else                                /* a good one      */
00354                 num_valid++;
00355         }
00356         else                                    /* just being safe */
00357             dptr = NULL;
00358 
00359         dset[idcount] = dptr;
00360     }
00361 
00362     RETURN( num_valid );
00363 }

Variable Documentation

THD_3dim_dataset* dset[NMAX] [static]
 

Definition at line 77 of file plug_nth_dataset.c.

char* ez[2] = { "Extend" , "Zero" } [static]
 

Definition at line 93 of file plug_nth_dataset.c.

Referenced by DSETN_main(), and PLUGIN_init().

int g_dset_recv = -1 [static]
 

Definition at line 80 of file plug_nth_dataset.c.

Referenced by DSETN_dset_recv(), and DSETN_main().

MCW_idcode g_id[NMAX] [static]
 

Definition at line 78 of file plug_nth_dataset.c.

int g_valid_data = 0 [static]
 

Definition at line 81 of file plug_nth_dataset.c.

Referenced by DSETN_dset_recv(), DSETN_func(), and DSETN_main().

char helpstring[] [static]
 

Definition at line 29 of file plug_nth_dataset.c.

Referenced by PLUGIN_init().

char* lr[2] = { "Left" , "Right" } [static]
 

Definition at line 92 of file plug_nth_dataset.c.

Referenced by DSETN_main(), and PLUGIN_init().

int ovc[NMAX] [static]
 

Definition at line 79 of file plug_nth_dataset.c.

Referenced by DSETN_func(), and DSETN_main().

PLUGIN_interface* plint = NULL [static]
 

Definition at line 95 of file plug_nth_dataset.c.

Referenced by DSETN_dset_recv(), DSETN_func_init(), DSETN_main(), and PLUGIN_init().

 

Powered by Plone

This site conforms to the following standards: