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_editdaxes.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 "mrilib.h"
00008 #include "thd.h"
00009 
00010 /*----------------------------------------------------------------
00011    Edit a THD_dataxes structure to allow for resampling to a new
00012    voxel size (resam).
00013 -----------------------------------------------------------------*/
00014 
00015 void THD_edit_dataxes( float resam , THD_dataxes * daxes ,
00016                                      THD_dataxes * wod_daxes )
00017 {
00018    float lxx , lyy , lzz ;
00019    float rex , rey , rez ;
00020 
00021    if( ! ISVALID_DATAXES(daxes) || ! ISVALID_DATAXES(wod_daxes) ) return ;
00022 
00023    *wod_daxes = *daxes ;       /* copy insides, then edit them */
00024 
00025    if( resam <= 0.0 ) return ; /* error */
00026 
00027    rex = (daxes->xxdel > 0) ? resam : -resam ;  /* signed resampled */
00028    rey = (daxes->yydel > 0) ? resam : -resam ;  /* voxel sizes */
00029    rez = (daxes->zzdel > 0) ? resam : -resam ;
00030 
00031    lxx = daxes->nxx * daxes->xxdel ;    /* signed lengths of data box */
00032    lyy = daxes->nyy * daxes->yydel ;
00033    lzz = daxes->nzz * daxes->zzdel ;
00034 
00035    wod_daxes->nxx = (int)( lxx/rex + 0.499 ) ;  /* new dimensions */
00036    wod_daxes->nyy = (int)( lyy/rey + 0.499 ) ;  /* (will be > 0) */
00037    wod_daxes->nzz = (int)( lzz/rez + 0.499 ) ;
00038 
00039    /* go to old middle, then back out to get new edge */
00040 
00041    wod_daxes->xxorg = daxes->xxorg + 0.5*(lxx - daxes->xxdel)
00042                                    - 0.5*(wod_daxes->nxx - 1)*rex ;
00043 
00044    wod_daxes->yyorg = daxes->yyorg + 0.5*(lyy - daxes->yydel)
00045                                    - 0.5*(wod_daxes->nyy - 1)*rey ;
00046 
00047    wod_daxes->zzorg = daxes->zzorg + 0.5*(lzz - daxes->zzdel)
00048                                    - 0.5*(wod_daxes->nzz - 1)*rez ;
00049 
00050    /* new dimensions of the voxels */
00051 
00052    wod_daxes->xxdel = rex ;
00053    wod_daxes->yydel = rey ;
00054    wod_daxes->zzdel = rez ;
00055 
00056    /* do the bounding box thing again */
00057 
00058    wod_daxes->xxmin = wod_daxes->xxorg ;
00059    wod_daxes->xxmax = wod_daxes->xxorg + (wod_daxes->nxx-1)*wod_daxes->xxdel ;
00060    if( wod_daxes->xxmin > wod_daxes->xxmax ){
00061       float temp = wod_daxes->xxmin ;
00062       wod_daxes->xxmin = wod_daxes->xxmax ; wod_daxes->xxmax = temp ;
00063    }
00064 
00065    wod_daxes->yymin = wod_daxes->yyorg ;
00066    wod_daxes->yymax = wod_daxes->yyorg + (wod_daxes->nyy-1)*wod_daxes->yydel ;
00067    if( wod_daxes->yymin > wod_daxes->yymax ){
00068       float temp = wod_daxes->yymin ;
00069       wod_daxes->yymin = wod_daxes->yymax ; wod_daxes->yymax = temp ;
00070    }
00071 
00072    wod_daxes->zzmin = wod_daxes->zzorg ;
00073    wod_daxes->zzmax = wod_daxes->zzorg + (wod_daxes->nzz-1)*wod_daxes->zzdel ;
00074    if( wod_daxes->zzmin > wod_daxes->zzmax ){
00075       float temp = wod_daxes->zzmin ;
00076       wod_daxes->zzmin = wod_daxes->zzmax ; wod_daxes->zzmax = temp ;
00077    }
00078 
00079 #ifdef EXTEND_BBOX
00080    wod_daxes->xxmin -= 0.5 * wod_daxes->xxdel ;
00081    wod_daxes->xxmax += 0.5 * wod_daxes->xxdel ;
00082    wod_daxes->yymin -= 0.5 * wod_daxes->yydel ;
00083    wod_daxes->yymax += 0.5 * wod_daxes->yydel ;
00084    wod_daxes->zzmin -= 0.5 * wod_daxes->zzdel ;
00085    wod_daxes->zzmax += 0.5 * wod_daxes->zzdel ;
00086 #endif
00087 
00088    return ;
00089 }
 

Powered by Plone

This site conforms to the following standards: