00001
00006 #ifndef _NIFTI_IO_HEADER_
00007 #define _NIFTI_IO_HEADER_
00008
00009 #include <stdio.h>
00010 #include <stdlib.h>
00011 #include <string.h>
00012 #include <math.h>
00013 #include <ctype.h>
00014
00015 #ifndef DONT_INCLUDE_ANALYZE_STRUCT
00016 #define DONT_INCLUDE_ANALYZE_STRUCT
00017 #endif
00018 #include "nifti1.h"
00019
00020 #include <znzlib.h>
00021
00022
00023 #ifdef __cplusplus
00024 extern "C" {
00025 #endif
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 typedef struct {
00059 float m[4][4] ;
00060 } mat44 ;
00061
00062 typedef struct {
00063 float m[3][3] ;
00064 } mat33 ;
00065
00066
00067
00074 typedef struct {
00076 int ndim ;
00077 int nx ;
00078 int ny ;
00079 int nz ;
00080 int nt ;
00081 int nu ;
00082 int nv ;
00083 int nw ;
00084 int dim[8] ;
00085 int nvox ;
00086 int nbyper ;
00087 int datatype ;
00089 float dx ;
00090 float dy ;
00091 float dz ;
00092 float dt ;
00093 float du ;
00094 float dv ;
00095 float dw ;
00096 float pixdim[8] ;
00098 float scl_slope ;
00099 float scl_inter ;
00101 float cal_min ;
00102 float cal_max ;
00104 int qform_code ;
00105 int sform_code ;
00107 int freq_dim ;
00108 int phase_dim ;
00109 int slice_dim ;
00111 int slice_code ;
00112 int slice_start ;
00113 int slice_end ;
00114 float slice_duration ;
00118 float quatern_b , quatern_c , quatern_d ,
00119 qoffset_x , qoffset_y , qoffset_z ,
00120 qfac ;
00121
00122 mat44 qto_xyz ;
00123 mat44 qto_ijk ;
00125 mat44 sto_xyz ;
00126 mat44 sto_ijk ;
00128 float toffset ;
00130 int xyz_units ;
00131 int time_units ;
00133 int nifti_type ;
00136 int intent_code ;
00137 float intent_p1 ;
00138 float intent_p2 ;
00139 float intent_p3 ;
00140 char intent_name[16] ;
00142 char descrip[80] ;
00143 char aux_file[24] ;
00145 char *fname ;
00146 char *iname ;
00147 int iname_offset ;
00148 int swapsize ;
00149 int byteorder ;
00150 void *data ;
00152 int num_ext ;
00153 nifti1_extension * ext_list ;
00155 } nifti_image ;
00156
00157
00158
00159
00160 typedef struct {
00161 int nbricks;
00162 int bsize;
00163 void ** bricks;
00164 } nifti_brick_list;
00165
00166
00167
00168
00169
00170 char *nifti_datatype_string ( int dt ) ;
00171 char *nifti_units_string ( int uu ) ;
00172 char *nifti_intent_string ( int ii ) ;
00173 char *nifti_xform_string ( int xx ) ;
00174 char *nifti_slice_string ( int ss ) ;
00175 char *nifti_orientation_string( int ii ) ;
00176
00177 int nifti_is_inttype( int dt ) ;
00178
00179 mat44 nifti_mat44_inverse( mat44 R ) ;
00180
00181 mat33 nifti_mat33_inverse( mat33 R ) ;
00182 mat33 nifti_mat33_polar ( mat33 A ) ;
00183 float nifti_mat33_rownorm( mat33 A ) ;
00184 float nifti_mat33_colnorm( mat33 A ) ;
00185 float nifti_mat33_determ ( mat33 R ) ;
00186 mat33 nifti_mat33_mul ( mat33 A , mat33 B ) ;
00187
00188 void nifti_swap_2bytes ( int n , void *ar ) ;
00189 void nifti_swap_4bytes ( int n , void *ar ) ;
00190 void nifti_swap_8bytes ( int n , void *ar ) ;
00191 void nifti_swap_16bytes( int n , void *ar ) ;
00192 void nifti_swap_Nbytes ( int n , int siz , void *ar ) ;
00193
00194 void swap_nifti_header ( struct nifti_1_header *h , int is_nifti ) ;
00195 int nifti_get_filesize( const char *pathname ) ;
00196
00197
00198
00199 nifti_image *nifti_image_read_bricks(const char *hname , int nbricks,
00200 const int *blist, nifti_brick_list * NBL);
00201 int nifti_image_load_bricks(nifti_image *nim , int nbricks,
00202 const int *blist, nifti_brick_list * NBL);
00203 void nifti_free_NBL( nifti_brick_list * NBL );
00204
00205 nifti_image *nifti_image_read ( const char *hname , int read_data ) ;
00206 int nifti_image_load ( nifti_image *nim ) ;
00207 void nifti_image_unload ( nifti_image *nim ) ;
00208 void nifti_image_free ( nifti_image *nim ) ;
00209
00210 int nifti_read_collapsed_image( nifti_image * nim, const int dims [8],
00211 void ** data );
00212
00213 void nifti_image_write ( nifti_image * nim ) ;
00214 void nifti_image_write_bricks(nifti_image * nim,
00215 const nifti_brick_list * NBL);
00216 void nifti_image_infodump( const nifti_image * nim ) ;
00217
00218 void nifti_disp_lib_hist( void ) ;
00219 void nifti_disp_lib_version( void ) ;
00220 int nifti_disp_matrix_orient( const char * mesg, mat44 mat );
00221
00222 char * nifti_image_to_ascii ( const nifti_image * nim ) ;
00223 nifti_image *nifti_image_from_ascii( const char * str, int * bytes_read ) ;
00224
00225 size_t nifti_get_volsize(const nifti_image *nim) ;
00226
00227
00228 int nifti_set_filenames(nifti_image * nim, const char * prefix, int check,
00229 int set_byte_order);
00230 char * nifti_makehdrname (const char * prefix, int nifti_type, int check,
00231 int comp);
00232 char * nifti_makeimgname (const char * prefix, int nifti_type, int check,
00233 int comp);
00234 int is_nifti_file (const char *hname);
00235 char * nifti_find_file_extension(const char * name);
00236 int nifti_is_complete_filename(const char* fname);
00237 int nifti_validfilename(const char* fname);
00238
00239 int disp_nifti_1_header(const char * info, const nifti_1_header * hp ) ;
00240 void nifti_set_debug_level( int level ) ;
00241 void nifti_set_skip_blank_ext( int skip ) ;
00242
00243 int valid_nifti_brick_list(nifti_image * nim , int nbricks,
00244 const int * blist, int disp_error);
00245
00246
00247 znzFile nifti_image_open(const char * hname, char * opts, nifti_image ** nim);
00248 znzFile nifti_image_write_hdr_img(nifti_image *nim, int write_data,
00249 const char* opts);
00250 znzFile nifti_image_write_hdr_img2( nifti_image *nim , int write_opts ,
00251 const char* opts, znzFile imgfile, const nifti_brick_list * NBL);
00252 size_t nifti_read_buffer(znzFile fp, void* datatptr, size_t ntot,
00253 nifti_image *nim);
00254 int nifti_write_all_data(znzFile fp, nifti_image * nim,
00255 const nifti_brick_list * NBL);
00256 size_t nifti_write_buffer(znzFile fp, const void * buffer, size_t numbytes);
00257 nifti_image *nifti_read_ascii_image(znzFile fp, char *fname, int flen,
00258 int read_data);
00259 znzFile nifti_write_ascii_image(nifti_image *nim, const nifti_brick_list * NBL,
00260 const char * opts, int write_data, int leave_open);
00261
00262
00263 void nifti_datatype_sizes( int datatype , int *nbyper, int *swapsize ) ;
00264
00265 void nifti_mat44_to_quatern( mat44 R ,
00266 float *qb, float *qc, float *qd,
00267 float *qx, float *qy, float *qz,
00268 float *dx, float *dy, float *dz, float *qfac ) ;
00269
00270 mat44 nifti_quatern_to_mat44( float qb, float qc, float qd,
00271 float qx, float qy, float qz,
00272 float dx, float dy, float dz, float qfac );
00273
00274 mat44 nifti_make_orthog_mat44( float r11, float r12, float r13 ,
00275 float r21, float r22, float r23 ,
00276 float r31, float r32, float r33 ) ;
00277
00278 int nifti_short_order(void) ;
00279
00280
00281
00282
00283 #define NIFTI_L2R 1
00284 #define NIFTI_R2L 2
00285 #define NIFTI_P2A 3
00286 #define NIFTI_A2P 4
00287 #define NIFTI_I2S 5
00288 #define NIFTI_S2I 6
00289
00290 void nifti_mat44_to_orientation( mat44 R , int *icod, int *jcod, int *kcod ) ;
00291
00292
00293
00294 char * nifti_findhdrname (const char* fname);
00295 char * nifti_findimgname (const char* fname , int nifti_type);
00296 int nifti_is_gzfile (const char* fname);
00297
00298 char * nifti_makebasename(const char* fname);
00299
00300
00301
00302 struct nifti_1_header nifti_convert_nim2nhdr(const nifti_image* nim);
00303 nifti_1_header * nifti_read_header(const char *hname, int *swapped, int check);
00304 nifti_image * nifti_copy_nim_info(const nifti_image * src);
00305 nifti_image * nifti_simple_init_nim(void);
00306 nifti_image * nifti_convert_nhdr2nim(struct nifti_1_header nhdr,
00307 const char * fname);
00308
00309 int nifti_hdr_looks_good (const nifti_1_header * hdr);
00310 int nifti_is_valid_ecode (int ecode);
00311 int nifti_nim_is_valid (nifti_image * nim, int complain);
00312 int nifti_nim_has_valid_dims (nifti_image * nim, int complain);
00313 int is_valid_nifti_type (int nifti_type);
00314 int nifti_type_and_names_match (nifti_image * nim, int show_warn);
00315 int nifti_update_dims_from_array(nifti_image * nim);
00316 void nifti_set_iname_offset (nifti_image *nim);
00317 int nifti_set_type_from_names (nifti_image * nim);
00318 int nifti_add_extension(nifti_image * nim, const char * data, int len,
00319 int ecode );
00320 int nifti_copy_extensions (nifti_image *nim_dest,const nifti_image *nim_src);
00321 int nifti_free_extensions (nifti_image *nim);
00322 int * nifti_get_intlist (int nvals , const char *str);
00323 char * nifti_strdup (const char *str);
00324 int valid_nifti_extensions(const nifti_image *nim);
00325
00326
00327
00328
00329
00330
00331
00332 #define NIFTI_ECODE_IGNORE 0
00333
00334 #define NIFTI_ECODE_DICOM 2
00335
00336 #define NIFTI_ECODE_AFNI 4
00337
00338
00339 #define NIFTI_ECODE_COMMENT 6
00340
00341 #define NIFTI_ECODE_XCEDE 8
00342
00343
00344
00345
00346 #define NIFTI_ECODE_JIMDIMINFO 10
00347
00348
00349
00350 #define NIFTI_ECODE_WORKFLOW_FWDS 12
00351
00352
00353
00354
00355 #define NIFTI_MAX_ECODE 12
00356
00357
00358 #define NIFTI_FTYPE_ANALYZE 0
00359 #define NIFTI_FTYPE_NIFTI1_1 1
00360 #define NIFTI_FTYPE_NIFTI1_2 2
00361 #define NIFTI_FTYPE_ASCII 3
00362 #define NIFTI_MAX_FTYPE 3
00363
00364
00365
00366
00367 #ifdef _NIFTI1_IO_C_
00368
00369 typedef struct {
00370 int debug;
00371 int skip_blank_ext;
00372 } nifti_global_options;
00373
00374 #undef LNI_FERR
00375 #define LNI_FERR(func,msg,file) \
00376 fprintf(stderr,"** ERROR (%s): %s '%s'\n",func,msg,file)
00377
00378 #undef swap_2
00379 #undef swap_4
00380 #define swap_2(s) nifti_swap_2bytes(1,&(s))
00381 #define swap_4(v) nifti_swap_4bytes(1,&(v))
00382
00383
00384
00385
00386 #undef IS_GOOD_FLOAT
00387 #undef FIXED_FLOAT
00388
00389 #ifdef isfinite
00390 # define IS_GOOD_FLOAT(x) isfinite(x)
00391 # define FIXED_FLOAT(x) (isfinite(x) ? (x) : 0)
00392 #else
00393 # define IS_GOOD_FLOAT(x) 1
00394 # define FIXED_FLOAT(x) (x)
00395 #endif
00396
00397 #undef ASSIF
00398 #define ASSIF(p,v) if( (p)!=NULL ) *(p) = (v)
00399
00400 #undef MSB_FIRST
00401 #undef LSB_FIRST
00402 #undef REVERSE_ORDER
00403 #define LSB_FIRST 1
00404 #define MSB_FIRST 2
00405 #define REVERSE_ORDER(x) (3-(x))
00406
00407 #define LNI_MAX_NIA_EXT_LEN 100000
00408
00409 #endif
00410
00411
00412
00413 #ifdef __cplusplus
00414 }
00415 #endif
00416
00417
00418 #endif