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  

thd_zfillin.c File Reference

#include "mrilib.h"

Go to the source code of this file.


Functions

int THD_zfillin_byte (int nrow, byte *row, int maxstep)
int THD_dataset_zfillin (THD_3dim_dataset *dset, int ival, int dcode, int maxstep)

Function Documentation

int THD_dataset_zfillin THD_3dim_dataset   dset,
int    ival,
int    dcode,
int    maxstep
 

Definition at line 40 of file thd_zfillin.c.

References DSET_BRICK_TYPE, DSET_NVALS, DSET_NX, DSET_NY, DSET_NZ, ENTRY, free, ISVALID_DSET, nz, RETURN, THD_get_dset_row(), THD_get_dset_rowcount(), THD_put_dset_row(), and THD_zfillin_byte().

00041 {
00042    int kind , xx,yy,zz , nrow , nx,ny,nz ;
00043    int xtop,ytop,ztop , nff , nfftot=0 ;
00044 
00045 ENTRY("THD_dataset_rowfillin") ;
00046 
00047    if( !ISVALID_DSET(dset)      ||
00048        ival < 0                 ||
00049        ival >= DSET_NVALS(dset) ||
00050        maxstep < 1                ) RETURN(-1) ;  /* bad things */
00051 
00052    kind = DSET_BRICK_TYPE(dset,ival) ;
00053    if( kind != MRI_byte ) RETURN(-1) ;  /* bad */
00054 
00055    nrow = THD_get_dset_rowcount( dset , dcode ) ;
00056    if( nrow < 1 ) RETURN(-1) ;  /* bad */
00057 
00058    nx = DSET_NX(dset) ;
00059    ny = DSET_NY(dset) ;
00060    nz = DSET_NZ(dset) ;
00061 
00062    xtop = ytop = ztop = 1 ;
00063    switch( dcode ){
00064       case 1: case -1: ytop=ny ; ztop=nz ; break ;
00065       case 2: case -2: xtop=nx ; ztop=nz ; break ;
00066       case 3: case -3: xtop=nx ; ytop=ny ; break ;
00067    }
00068 
00069    switch( kind ){
00070 
00071       case MRI_byte:{
00072          byte * row ;
00073          for( zz=0 ; zz < ztop ; zz++ )
00074           for( yy=0 ; yy < ytop ; yy++ )
00075             for( xx=0 ; xx < xtop ; xx++ ){
00076                row = THD_get_dset_row( dset,ival , dcode,xx,yy,zz ) ;
00077                nff = THD_zfillin_byte( nrow , row , maxstep ) ;
00078                if( nff > 0 ){
00079                   THD_put_dset_row( dset,ival , dcode,xx,yy,zz , row ) ;
00080                   nfftot += nff ;
00081                }
00082                free(row) ;
00083             }
00084       }
00085       break ;
00086 
00087    }
00088 
00089    RETURN(nfftot) ;
00090 }

int THD_zfillin_byte int    nrow,
byte   row,
int    maxstep
[static]
 

Definition at line 8 of file thd_zfillin.c.

References AFREALL.

Referenced by THD_dataset_zfillin().

00009 {
00010    int ii , nfill=0 , jj ;
00011    byte vbot ;
00012    static byte *trow = NULL ; static int ntrow = 0 ;
00013 
00014    if( ntrow != nrow ){
00015      trow = AFREALL(trow , byte, nrow ) ;
00016      ntrow = nrow ;
00017    }
00018    memcpy(trow,row,sizeof(byte)*nrow) ;
00019 
00020    for( ii=0 ; ii < nrow ; ii++ ){
00021       if( row[ii] != 0 ) continue ;  /* skip values already nonzero */
00022 
00023       /* scan up and down for nearest nonzero */
00024 
00025       for( jj=1 ; jj <= maxstep ; jj++ ){
00026          if( ii+jj< nrow && row[ii+jj]!=0 ){trow[ii]=row[ii+jj]; nfill++; break;}
00027          if( ii-jj>= 0   && row[ii-jj]!=0 ){trow[ii]=row[ii-jj]; nfill++; break;}
00028       }
00029    }
00030 
00031    if( nfill > 0 ) memcpy(row,trow,sizeof(byte)*nrow) ;
00032    return nfill;
00033 }
 

Powered by Plone

This site conforms to the following standards: