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  

overfim.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 <stdio.h>
00008 #include <math.h>
00009 #include <stdlib.h>
00010 
00011 #include "overfim.h"
00012 
00013 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
00014 
00015 /*** this routine creates a blank overlay ***/
00016 
00017 short * RWC_create_overlay( nxover , nyover )
00018    int nxover , nyover ;
00019 {
00020    short * ov ;
00021    register int ii , npix = nxover * nyover ;
00022 
00023    ov = (short *) malloc( sizeof(short) * npix ) ;
00024 
00025    for( ii=0 ; ii < npix ; ii++ ) ov[ii] = RWC_OVFLAG ;
00026    return ov ;
00027 }
00028 
00029 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
00030 
00031 /*** this routine modifies an array of shorts by
00032      overlaying values that are NOT the flag value ***/
00033 
00034 int RWC_short_overlay( nxim,nyim,image , nxover,nyover ,
00035                        flag,dont_overlay,checker , overlay )
00036   short * image ;
00037   int     nxim,nyim , nxover,nyover , checker ;
00038   short   flag , dont_overlay ;
00039   short * overlay ;
00040 {
00041    int rowsize = nxim ;
00042    static int old_rowsize = -1 ; /* remember last entry */
00043 
00044    int nxdup , nydup ;           /* duplication factors: overlay -> image */
00045    static int old_nxdup = -1 ,
00046               old_nydup = -1 ;   /* remember last time in */
00047 
00048    static int old_checker = -1 ;
00049 
00050    int ir , jc , xx,yy ;        /* various loop indices */
00051    register int jj ;
00052 
00053    static int * jump = NULL ;     /* jump table, for duplicating overlays */
00054    static int   jump_size = -1 ;  /* allocated space for table */
00055    static int   jump_count ;      /* number of actual entries in table */
00056 
00057    short * ovp = overlay ;        /* for scanning through overlay array */
00058 
00059    register short * imbase ;      /* base of points in image to be overlaid */
00060    int     xfac , yfac ;   /* scale factors for mapping overlay to image */
00061 
00062 #ifdef OV_DEBUG1
00063    int nov = 0 ;
00064 #endif
00065 
00066 /*** check if input image satisfies restrictions ***/
00067 
00068 #ifdef OV_DEBUG1
00069    if( jump_size == -1 )
00070      fprintf(stderr,"RWC: overlay called nxim=%d nxover=%d\n",nxim,nxover) ;
00071 #endif
00072 
00073    if( overlay == NULL || image  == NULL ||
00074        nxover  == 0    || nyover == 0      ) return 1 ;
00075 
00076 /*** overlay and image dimensions must conform,
00077   in the sense that the image must be an exact multiple of the overlay ***/
00078 
00079    if( (nxim % nxover) !=0  ||  (nyim % nyover) != 0 ) return 2 ;
00080 
00081    nxdup = nxim / nxover ;  /* duplication factors for each overlay pixel */
00082    nydup = nyim / nyover ;
00083 
00084 #ifdef OV_DEBUG1
00085    if( nxdup != old_nxdup || nydup != old_nydup )
00086      fprintf(stderr,"RWC: overlay nxdup=%d nydup=%d\n",nxdup,nydup) ;
00087 #endif
00088 
00089 /*** create the jump table, if not already present from last call ***/
00090 
00091    if( nxdup * nydup > jump_size ){
00092       if( jump != NULL ) free(jump) ;
00093       jump_size = nxdup * nydup ;
00094       jump      = (int *) malloc( sizeof(int) * jump_size ) ;
00095       if( jump == NULL ){
00096          jump_size = -1 ;
00097          return 3 ;
00098       }
00099    }
00100 
00101    if( rowsize != old_rowsize ||
00102        nxdup   != old_nxdup   || nydup != old_nydup ||
00103        checker != old_checker                         ){
00104 
00105       jj = 0 ;
00106       for( yy=0 ; yy < nydup ; yy++ ){
00107          for( xx=0 ; xx < nxdup ; xx++ ){
00108             if( !checker || (xx+yy)%2 == 0 )    /* checkerboard pattern */
00109                jump[jj++] = ( xx + yy * rowsize ) ;
00110          }
00111       }
00112       jump_count  = jj ;
00113       old_rowsize = rowsize ;  /* remember these for next time */
00114       old_nxdup   = nxdup ;
00115       old_nydup   = nydup ;
00116       old_checker = checker ;
00117 
00118 #ifdef OV_DEBUG1
00119       fprintf(stderr,"RWC_short_overlay: new jump array:\n") ;
00120       for( jj=0 ; jj < jump_size ; jj++ ) fprintf(stderr,"%d ",jump[jj]) ;
00121       fprintf(stderr,"\ncomputed from nxdup=%d nydup=%d rowsize=%d \n",
00122               nxdup,nydup,rowsize ) ;
00123 #endif
00124    }
00125 
00126 /*** scale factors for mapping overlay to image ***/
00127 
00128    xfac = nxdup ;           /* overlay(x,y) --> image(xfac*x,yfac*y) */
00129    yfac = rowsize * nydup ;
00130 
00131    for( jc=0 ; jc < nyover ; jc++ ){    /* loop over all overlay pixels */
00132       for( ir=0 ; ir < nxover ; ir++,ovp++ ){
00133 
00134          if( *ovp != flag ){            /* overlay unless hit flag */
00135 
00136             imbase = &image[ir * xfac + jc * yfac] ; /* start overlay here */
00137             for( jj=0 ; jj < jump_count ; jj++ ){
00138                if( imbase[jump[jj]] != dont_overlay ){
00139 
00140                  imbase[jump[jj]] = *ovp ;
00141 #ifdef OV_DEBUG1
00142                  nov++ ;
00143 #endif
00144                }   /* end if */
00145             }  /* end for jj */
00146          }  /* end if */
00147       }  /* end for ir */
00148    }  /* end for jc */
00149 
00150 #ifdef OV_DEBUG1
00151    fprintf(stderr,"RWC: number points overlaid = %d\n",nov);
00152 #endif
00153    return 0 ;   /* nonzero return codes are an error */
00154 }
 

Powered by Plone

This site conforms to the following standards: