Doxygen Source Code Documentation
edt_volpad.c File Reference
#include "mrilib.h"
Go to the source code of this file.
Defines | |
#define | SNEW(i, j, k) ((i+nxbot)+(j+nybot)*nxnew+(k+nzbot)*nxynew) |
#define | SOLD(i, j, k) (i+j*nxold+k*nxyold) |
Functions | |
void * | EDIT_volpad (int nxbot, int nxtop, int nybot, int nytop, int nzbot, int nztop, int nx, int ny, int nz, int ftype, void *fim) |
MRI_IMAGE * | mri_zeropad_3D (int nxbot, int nxtop, int nybot, int nytop, int nzbot, int nztop, MRI_IMAGE *im) |
Define Documentation
|
|
|
|
Function Documentation
|
Definition at line 13 of file edt_volpad.c. References calloc, ENTRY, fim, free, malloc, MAX, MIN, mri_datum_size(), nz, and RETURN. Referenced by mri_zeropad_3D().
00017 { 00018 int nxold,nyold,nzold , nxnew,nynew,nznew , nxyold,nxynew ; 00019 int ii,jj,kk , iv , iibot,iitop , jjbot,jjtop , kkbot,kktop ; 00020 void * vnew ; 00021 00022 ENTRY("EDIT_volpad") ; 00023 00024 /*- check for user stupidity -*/ 00025 00026 if( nx <= 0 || ny <= 0 || nz <= 0 || fim == NULL ) RETURN(NULL) ; 00027 00028 /*- special case: just copy input -*/ 00029 00030 if( nxbot == 0 && nybot == 0 && nzbot == 0 && 00031 nxtop == 0 && nytop == 0 && nztop == 0 ){ 00032 00033 vnew = malloc( mri_datum_size(ftype) * nx*ny*nz ) ; 00034 memcpy( vnew , fim , mri_datum_size(ftype) * nx*ny*nz ) ; 00035 RETURN(vnew) ; 00036 } 00037 00038 nxold = nx ; nxnew = nxold + nxbot + nxtop ; /* dimensions */ 00039 nyold = ny ; nynew = nyold + nybot + nytop ; 00040 nzold = nz ; nznew = nzold + nzbot + nztop ; 00041 00042 nxyold = nxold * nyold ; /* for computing 3D subscripts */ 00043 nxynew = nxnew * nynew ; 00044 00045 iibot = MAX(0,-nxbot) ; iitop = MIN(nxold,nxold+nxtop) ; /* range of data */ 00046 jjbot = MAX(0,-nybot) ; jjtop = MIN(nyold,nyold+nytop) ; /* in old dataset */ 00047 kkbot = MAX(0,-nzbot) ; kktop = MIN(nzold,nzold+nztop) ; /* to copy to new */ 00048 00049 if( nxnew < 2 || iibot >= iitop || /* check for reasonable sizes */ 00050 nynew < 2 || jjbot >= jjtop || /* and ranges of dataset */ 00051 nznew < 2 || kkbot >= kktop ){ 00052 00053 fprintf(stderr,"*** EDIT_volpad: can't cut volume down to nothing!\n") ; 00054 RETURN(NULL) ; 00055 } 00056 00057 vnew = calloc( nxnew*nynew*nznew , mri_datum_size(ftype) ) ; /* new brick */ 00058 if( vnew == NULL ){ 00059 fprintf(stderr, "*** EDIT_volpad: Can't malloc space for new array\n") ; 00060 RETURN(NULL) ; 00061 } 00062 00063 /* macros for computing 1D subscripts from 3D indices */ 00064 00065 #undef SNEW /* in case was defined in some stupid .h file */ 00066 #undef SOLD 00067 #define SNEW(i,j,k) ((i+nxbot)+(j+nybot)*nxnew+(k+nzbot)*nxynew) 00068 #define SOLD(i,j,k) (i+j*nxold+k*nxyold) 00069 00070 switch( ftype ){ /* copy rows of old into new */ 00071 00072 default: 00073 fprintf(stderr,"*** EDIT_volpad: unknown input datum=%d\n",ftype) ; 00074 free(vnew) ; 00075 RETURN(NULL) ; 00076 00077 case MRI_byte:{ 00078 byte * bnew = (byte *) vnew, * bold = (byte *) fim ; 00079 for( kk=kkbot ; kk < kktop ; kk++ ) 00080 for( jj=jjbot ; jj < jjtop ; jj++ ) 00081 for( ii=iibot ; ii < iitop ; ii++ ) 00082 bnew[SNEW(ii,jj,kk)] = bold[SOLD(ii,jj,kk)] ; 00083 } 00084 break ; 00085 00086 case MRI_rgb:{ 00087 byte * bnew = (byte *) vnew, * bold = (byte *) fim ; 00088 for( kk=kkbot ; kk < kktop ; kk++ ) 00089 for( jj=jjbot ; jj < jjtop ; jj++ ) 00090 for( ii=iibot ; ii < iitop ; ii++ ){ 00091 bnew[3*SNEW(ii,jj,kk) ] = bold[3*SOLD(ii,jj,kk) ] ; 00092 bnew[3*SNEW(ii,jj,kk)+1] = bold[3*SOLD(ii,jj,kk)+1] ; 00093 bnew[3*SNEW(ii,jj,kk)+2] = bold[3*SOLD(ii,jj,kk)+2] ; 00094 } 00095 } 00096 break ; 00097 00098 case MRI_short:{ 00099 short * bnew = (short *) vnew, * bold = (short *) fim ; 00100 for( kk=kkbot ; kk < kktop ; kk++ ) 00101 for( jj=jjbot ; jj < jjtop ; jj++ ) 00102 for( ii=iibot ; ii < iitop ; ii++ ) 00103 bnew[SNEW(ii,jj,kk)] = bold[SOLD(ii,jj,kk)] ; 00104 } 00105 break ; 00106 00107 case MRI_int:{ 00108 int * bnew = (int *) vnew, * bold = (int *) fim ; 00109 for( kk=kkbot ; kk < kktop ; kk++ ) 00110 for( jj=jjbot ; jj < jjtop ; jj++ ) 00111 for( ii=iibot ; ii < iitop ; ii++ ) 00112 bnew[SNEW(ii,jj,kk)] = bold[SOLD(ii,jj,kk)] ; 00113 } 00114 break ; 00115 00116 case MRI_float:{ 00117 float * bnew = (float *) vnew, * bold = (float *) fim ; 00118 for( kk=kkbot ; kk < kktop ; kk++ ) 00119 for( jj=jjbot ; jj < jjtop ; jj++ ) 00120 for( ii=iibot ; ii < iitop ; ii++ ) 00121 bnew[SNEW(ii,jj,kk)] = bold[SOLD(ii,jj,kk)] ; 00122 } 00123 break ; 00124 00125 case MRI_double:{ 00126 double * bnew = (double *) vnew, * bold = (double *) fim ; 00127 for( kk=kkbot ; kk < kktop ; kk++ ) 00128 for( jj=jjbot ; jj < jjtop ; jj++ ) 00129 for( ii=iibot ; ii < iitop ; ii++ ) 00130 bnew[SNEW(ii,jj,kk)] = bold[SOLD(ii,jj,kk)] ; 00131 } 00132 break ; 00133 00134 case MRI_complex:{ 00135 complex * bnew = (complex *) vnew, * bold = (complex *) fim ; 00136 for( kk=kkbot ; kk < kktop ; kk++ ) 00137 for( jj=jjbot ; jj < jjtop ; jj++ ) 00138 for( ii=iibot ; ii < iitop ; ii++ ) 00139 bnew[SNEW(ii,jj,kk)] = bold[SOLD(ii,jj,kk)] ; 00140 } 00141 break ; 00142 00143 } /* end of switch on datum type */ 00144 00145 RETURN(vnew) ; 00146 } |
|
Definition at line 152 of file edt_volpad.c. References EDIT_volpad(), ENTRY, MRI_IMAGE::kind, MRI_COPY_AUX, mri_fix_data_pointer(), MRI_IS_3D, mri_new_vol_empty(), MRI_IMAGE::nx, MRI_IMAGE::ny, MRI_IMAGE::nz, RETURN, and var.
00155 { 00156 MRI_IMAGE * jm ; 00157 void * var ; 00158 00159 ENTRY("mri_zeropad_3D") ; 00160 00161 if( im == NULL || !MRI_IS_3D(im) ) RETURN(NULL) ; /* bad */ 00162 00163 /* do the padding work */ 00164 00165 var = EDIT_volpad( nxbot,nxtop,nybot,nytop,nzbot,nztop , 00166 im->nx , im->ny , im->nz , 00167 im->kind , mri_data_pointer(im) ) ; 00168 00169 if( var == NULL ) RETURN(NULL) ; /* bad */ 00170 00171 /* put padded data into new image */ 00172 00173 jm = mri_new_vol_empty( im->nx+nxbot+nybot , 00174 im->ny+nybot+nytop , 00175 im->nz+nzbot+nztop , im->kind ) ; 00176 MRI_COPY_AUX(jm,im) ; 00177 mri_fix_data_pointer( var , jm ) ; 00178 RETURN( jm ); 00179 } |