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_funcs.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 #include "afni.h"
00008 
00009 #ifndef ALLOW_PLUGINS
00010 #  error "Plugins not properly set up -- see machdep.h"
00011 #endif
00012 
00013 /***********************************************************************
00014   Plugin to serve as a home for transformation functions
00015 ************************************************************************/
00016 
00017 char * JUNK_main( PLUGIN_interface * plint ) ;
00018 void lacy9_box_func( int nx , int ny , double dx, double dy, float * ar ) ;
00019 void outer9_box_func( int nx , int ny , double dx, double dy, float * ar ) ;
00020 
00021 /***********************************************************************
00022    Set up the interface to the user: NONE.
00023 ************************************************************************/
00024 
00025 
00026 DEFINE_PLUGIN_PROTOTYPE
00027 
00028 PLUGIN_interface * PLUGIN_init( int ncall )
00029 {
00030    PLUGIN_interface * plint ;     /* will be the output of this routine */
00031 
00032    if( ncall > 0 ) return NULL ;  /* only one interface */
00033 
00034    /*---------------- set titles and call point ----------------*/
00035 
00036    plint = PLUTO_new_interface( "PlaceHolder" , "PlaceHolder" , NULL ,
00037                                 PLUGIN_CALL_IMMEDIATELY , JUNK_main ) ;
00038 
00039    PLUTO_set_sequence( plint , "A:funcs:junk" ) ;
00040 
00041    AFNI_register_2D_function( "Lacy9"   , lacy9_box_func  ) ;
00042    AFNI_register_2D_function( "Outer9"  , outer9_box_func ) ;
00043 
00044    return plint ;
00045 }
00046 
00047 /***************************************************************************
00048   Main routine for this plugin (will be called from AFNI).
00049 ****************************************************************************/
00050 
00051 char * JUNK_main( PLUGIN_interface * plint ){ return NULL ; }
00052 
00053 /*----------------------- Sample 2D transformations --------------------*/
00054 
00055 static float * atemp = NULL ;
00056 static int    natemp = -666 ;
00057 
00058 #define MAKE_ATEMP(nvox)                     \
00059   do{ if( natemp < (nvox) ){                 \
00060          if( atemp != NULL ) free(atemp) ;   \
00061          natemp = (nvox) ;                   \
00062          atemp  = (float *) malloc( sizeof(float) * natemp ) ; } } while(0)
00063 
00064 #define AT(i,j) atemp[(i)+(j)*nx]
00065 #define AR(i,j) ar[(i)+(j)*nx]
00066 
00067 void lacy9_box_func( int nx , int ny , double dx, double dy, float * ar )
00068 {
00069    int ii , jj , nxy , isp , nnn , qqq , imid,jmid ;
00070    float val ;
00071 
00072    if( nx < 3 || ny < 3 ) return ;
00073 
00074    osfilt9_box_func( nx,ny,dx,dy,ar ) ;  /* smooth */
00075 
00076    /** make space and copy input into it **/
00077 
00078    nxy = nx * ny ;
00079    MAKE_ATEMP(nxy) ; if( atemp == NULL ) return ;
00080    for( ii=0 ; ii < nxy ; ii++ ) atemp[ii] = ar[ii] ;
00081 
00082    /** process copy of input back into the input array **/
00083 
00084 #undef Z
00085 #undef ZZ
00086 #define Z(x,y)    ( ((x)>(y)) ? 0 : ((x)==(y)) ? 1 : 2 )
00087 #define ZZ(a,b,c) ( Z((a),(b))+Z((c),(b)) >= 3 )
00088 
00089    for( ii=0 ; ii < nxy ; ii++ ) ar[ii] = 0.0 ;
00090 
00091    imid = nx/2 ; jmid = ny/2 ;
00092 
00093    for( jj=1 ; jj < ny-1 ; jj++ ){       /* find local peaks */
00094      for( ii=1 ; ii < nx-1 ; ii++ ){     /* in each 3x3 cell */
00095 
00096        val = AT(ii,jj) ;
00097 
00098 #if 0
00099        isp =    ZZ( AT(ii-1,jj  ) , val , AT(ii+1,jj  ) )
00100              || ZZ( AT(ii-1,jj-1) , val , AT(ii+1,jj+1) )
00101              || ZZ( AT(ii-1,jj+1) , val , AT(ii+1,jj-1) )
00102              || ZZ( AT(ii  ,jj+1) , val , AT(ii  ,jj-1) ) ;
00103 #else
00104        if( abs(ii-imid) <= abs(jj-jmid) ){
00105           isp =    ZZ( AT(ii-1,jj-1) , val , AT(ii+1,jj+1) )
00106                 || ZZ( AT(ii-1,jj+1) , val , AT(ii+1,jj-1) )
00107                 || ZZ( AT(ii  ,jj+1) , val , AT(ii  ,jj-1) ) ;
00108        } else {
00109           isp =    ZZ( AT(ii-1,jj  ) , val , AT(ii+1,jj  ) )
00110                 || ZZ( AT(ii-1,jj-1) , val , AT(ii+1,jj+1) )
00111                 || ZZ( AT(ii-1,jj+1) , val , AT(ii+1,jj-1) ) ;
00112        }
00113 #endif
00114 
00115        if( isp ) ar[ii+jj*nx] = val ;
00116      }
00117    }
00118 
00119 #define QQQMAX 1
00120 #if QQQMAX > 0
00121    qqq = 0 ;
00122    do {
00123       nnn = 0 ;
00124       for( ii=0 ; ii < nxy ; ii++ ) atemp[ii] = ar[ii] ;
00125       for( jj=1 ; jj < ny-1 ; jj++ ){     /* clip off those that */
00126         for( ii=1 ; ii < nx-1 ; ii++ ){   /* are too isolated    */
00127 
00128            if( AT(ii,jj) != 0.0 ){
00129               isp =  (AT(ii-1,jj  ) != 0.0) + (AT(ii+1,jj  ) != 0.0)
00130                    + (AT(ii-1,jj+1) != 0.0) + (AT(ii+1,jj+1) != 0.0)
00131                    + (AT(ii-1,jj-1) != 0.0) + (AT(ii+1,jj-1) != 0.0)
00132                    + (AT(ii  ,jj-1) != 0.0) + (AT(ii  ,jj-1) != 0.0) ;
00133 
00134               if( isp < 2 ){ ar[ii+jj*nx] = 0.0 ; nnn++ ; }
00135            }
00136         }
00137       }
00138       qqq++ ;
00139    } while( qqq < QQQMAX && nnn > 0 ) ;
00140 #endif
00141 
00142    for( jj=1 ; jj < ny-1 ; jj++ ){       /* remove isolas */
00143      for( ii=1 ; ii < nx-1 ; ii++ ){
00144 
00145           if(   (AR(ii-1,jj  ) == 0.0) && (AR(ii+1,jj  ) == 0.0)
00146              && (AR(ii-1,jj+1) == 0.0) && (AR(ii+1,jj+1) == 0.0)
00147              && (AR(ii-1,jj-1) == 0.0) && (AR(ii+1,jj-1) == 0.0)
00148              && (AR(ii  ,jj-1) == 0.0) && (AR(ii  ,jj-1) == 0.0) ) AR(ii,jj) = 0.0 ;
00149      }
00150    }
00151 
00152    return ;
00153 }
00154 
00155 /*------------------------------------------------------------------------*/
00156 
00157 void outer9_box_func( int nx , int ny , double dx, double dy, float * ar )
00158 {
00159    int ii , jj , nxy , nnn , imid,jmid , ib,jb ;
00160    float xx , yy ;
00161 
00162    if( nx < 3 || ny < 3 ) return ;
00163 
00164    lacy9_box_func( nx,ny,dx,dy,ar ) ;  /* find local peaks */
00165 
00166    /** make space and copy input into it **/
00167 
00168    nxy = nx * ny ;
00169    MAKE_ATEMP(nxy) ; if( atemp == NULL ) return ;
00170    for( ii=0 ; ii < nxy ; ii++ ) atemp[ii] = ar[ii] ;
00171    for( ii=0 ; ii < nxy ; ii++ ) ar[ii] = 0.0 ;
00172 
00173    imid = nx/2 ; jmid = ny/2 ;
00174 
00175 #define NRAD 1800
00176 #define DRAD (2.0*PI/NRAD)
00177 #define DD   0.47
00178 
00179    for( nnn=0 ; nnn < NRAD ; nnn++ ){
00180       dx = DD*cos(nnn*DRAD) ; dy = DD*sin(nnn*DRAD) ;
00181       xx = imid + 10*dx ; yy = jmid + 10*dy ;
00182       ib = -1 ; jb = -1 ;
00183 
00184       do { xx += dx ; yy += dy ;
00185            ii  = xx ; jj  = yy ;
00186            if( ii < 0 || ii >= nx || jj < 0 || jj > ny ) break ;
00187 
00188            if( AT(ii,jj) != 0.0 ){ ib = ii ; jb = jj ;  AR(ii,jj) = 1.0 ;  }
00189       } while( 1 ) ;
00190 
00191       if( ib >= 0 && jb >= 0 ) AR(ib,jb) = 2.0 ;
00192    }
00193 
00194    for( jj=1 ; jj < ny-1 ; jj++ ){       /* remove isolas */
00195      for( ii=1 ; ii < nx-1 ; ii++ ){
00196 
00197           if(   (AR(ii-1,jj  ) == 0.0) && (AR(ii+1,jj  ) == 0.0)
00198              && (AR(ii-1,jj+1) == 0.0) && (AR(ii+1,jj+1) == 0.0)
00199              && (AR(ii-1,jj-1) == 0.0) && (AR(ii+1,jj-1) == 0.0)
00200              && (AR(ii  ,jj-1) == 0.0) && (AR(ii  ,jj-1) == 0.0) ) AR(ii,jj) = 0.0 ;
00201      }
00202    }
00203 
00204    return ;
00205 }
 

Powered by Plone

This site conforms to the following standards: