img.h
Go to the documentation of this file.
00001 /*
00002   Copyright (c)  2002-2009 by Turku PET Centre
00003 
00004   img.h - definitions for img.c
00005 
00006   Version:
00007   2002-01-05 Vesa Oikonen
00008   2002-03-28 VO
00009     sampleDistance included in IMG structure.
00010   2002-08-23 VO
00011     _dataType included in IMG structure.
00012   2002-12-01 VO
00013     imgDecayCorrection() can be used also to remove decay correction.
00014   2002-12-03 VO
00015     imgCopyhdr() included.
00016   2002-12-23 VO
00017     patientName included in IMG structure.
00018     imgIsotope() included.
00019     decayCorrFactor[] included in IMG structure.
00020   2003-09-04 VO
00021     _fileFormat and its definitions included in IMG structure.
00022   2003-10-04 VO
00023     One more _fileFormat definition added (Analyze little endian byte order).
00024   2003-12-14 VO
00025     Memory for all pixels is allocated in one chunk;
00026     pointers are changed accordingly.
00027     (Patient) orientation included in IMG structure.
00028     Scanner (type) included in IMG structure.
00029     Scanner type definitions moved here from imgproc.h.
00030   2003-12-18 VO
00031     Added struct IMG_PIXEL and IMG_RANGE.
00032     Defined function imgExtractRange().
00033   2004-05-23 VO
00034     Added comments.
00035   2004-07-26 VO
00036     More comments.
00037   2004-08-23 VO
00038     MAX_STUDYNR_LEN applied.
00039   2006-10-30 VO
00040   2007-01-28 VO
00041     Definitions for library version 1.2.0:
00042     Added defines for NIfTI-1 file formats.
00043     Additional scanner types defined.
00044     Added definitions for error status messages.
00045     Additions in IMG structure:
00046     patientID, userProcessCode, studyDescription,
00047     gapx, gapy, gapz,
00048     resolutionx, resolutiony, resolutionz,
00049     prompts and randoms.
00050   2007-02-11 VO
00051     Added errstatus in IMG struct.
00052   2007-02-27 VO
00053     Added STATUS_WRONGFILETYPE and STATUS_CANNOTERASE.
00054   2007-03-13 VO
00055     Added STATUS_CANNOTREAD and STATUS_CANNOTWRITE.
00056   2007-03-26 VO
00057     Added variables for polar map in IMG struct.
00058   2008-07-14 VO
00059     Added imgAllocateWithHeader().
00060   2009-02-16 VO
00061     Added definitions for scanner and image type.
00062 
00063 
00064 */
00065 #ifndef _IMG_H
00066 #define _IMG_H
00067 /*===========================================================================*/
00068 #include "studynr.h"
00069 /*===========================================================================*/
00071 #define IMG_STATUS_UNINITIALIZED 0
00072 #define IMG_STATUS_INITIALIZED   1
00073 #define IMG_STATUS_OCCUPIED      2
00074 #define IMG_STATUS_ERROR         3
00075 
00076 #define IMG_ERR_OK      0
00077 #define IMG_ERR_CALLING 1
00078 #define IMG_ERR_OOM     2
00079 
00080 #define IMG_TYPE_IMAGE    1
00081 #define IMG_TYPE_RAW      2
00082 #define IMG_TYPE_POLARMAP 3
00083 
00084 #define IMG_UNKNOWN   0
00085 #define IMG_E63       1
00086 #define IMG_E7        2
00087 #define IMG_E7_2D     3
00088 #define IMG_POLARMAP  9
00089 #define IMG_ANA       11
00090 #define IMG_ANA_L     12 /* little endian variant */
00091 #define IMG_INTERFILE 21
00092 #define IMG_NIFTI_1D  31 /* dual file format */   
00093 #define IMG_NIFTI_1S  32 /* single file format */
00094 #define IMG_MICROPET  41
00095 
00096 #define SCANNER_UNKNOWN 0
00097 #define SCANNER_ECAT931 12
00098 #define SCANNER_ADVANCE 12096
00099 #define SCANNER_HRPLUS 3
00100 #define SCANNER_HRRT 4
00101 /* these may change later */
00102 #define SCANNER_MRI 5
00103 #define SCANNER_STEVCT_PET 6
00104 #define SCANNER_STEVCT_CT 7
00105 /* Concorde/MicropET scanners */
00106 #define SCANNER_PRIMATE 2000
00107 #define SCANNER_RODENT 2001
00108 #define SCANNER_MICROPET2 2002
00109 #define SCANNER_FOCUS_220 2500
00110 #define SCANNER_FOCUS_120 2501
00111 #define SCANNER_INVEON_DEDICATED_PET 5000
00112 #define SCANNER_INVEON_MM_PET 5500
00113 #define SCANNER_MR_PET_HEAD_INSERT 6000
00114 #define SCANNER_TUEBINGEN_PET_MR 8000
00115 
00116 #define MAX_POLARMAP_NUM_RINGS 32
00117 
00118 enum {STATUS_OK,STATUS_FAULT,STATUS_NOMEMORY,STATUS_NOFILE,STATUS_UNKNOWNFORMAT,
00119     STATUS_UNSUPPORTED,STATUS_MISSINGMATRIX,STATUS_NOWRITEPERM,STATUS_DISKFULL,
00120     STATUS_NOMATLIST,STATUS_INVALIDMATLIST,STATUS_VARMATSIZE,STATUS_NOMAINHEADER,
00121     STATUS_NOSUBHEADER, STATUS_NOMATRIX, STATUS_UNSUPPORTEDAXIALCOMP,
00122     STATUS_NOIMGDATAFILE, STATUS_NOHEADERFILE, STATUS_INVALIDHEADER,
00123     STATUS_NOIMGDATA, STATUS_NOSIFDATA, STATUS_WRONGSIFDATA, 
00124     STATUS_CANTWRITEIMGFILE, STATUS_CANTWRITEHEADERFILE, STATUS_WRONGFILETYPE, 
00125     STATUS_CANNOTERASE, STATUS_CANNOTREAD, STATUS_CANNOTWRITE,
00126     STATUS_UNSUPPORTEDPOLARMAP, STATUS_INVALIDPOLARMAP};
00127 /*===========================================================================*/
00128 int IMG_TEST;
00129 /*===========================================================================*/
00130 typedef struct {
00132   int x;
00134   int y;
00136   int z;
00138   int f;
00139 } IMG_PIXEL;
00140 typedef struct {
00142   int x1, x2;
00144   int y1, y2;
00146   int z1, z2;
00148   int f1, f2;
00149 } IMG_RANGE;
00150 /*===========================================================================*/
00151   
00152 /*===========================================================================*/
00156 typedef struct {
00157 
00158   /*
00159    *  State of image
00160    */
00164   char status;
00166   const char *statmsg;
00167 
00168   /*
00169    *  Information on the study
00170    */
00172   char unit;
00174   char studyNr[MAX_STUDYNR_LEN+1];
00176   char patientName[32];
00178   char patientID[16];
00180   char radiopharmaceutical[32];
00182   float isotopeHalflife;
00184   char decayCorrected;
00186   time_t scanStart;
00188   int orientation;
00190   char userProcessCode[11];
00192   char studyDescription[32];
00193 
00194   /*
00195    *  Information on the image
00196    */
00198   char type;
00200   float zoom;
00202   float axialFOV;
00204   float transaxialFOV;
00206   float sampleDistance;
00208   float sizex;
00210   float sizey;
00212   float sizez;
00214   float gapx;
00216   float gapy;
00218   float gapz;
00220   float resolutionx;
00222   float resolutiony;
00224   float resolutionz;
00226   int _dataType;
00229   int _fileFormat;
00231   int scanner;
00232 
00233   /*
00234    *  Definitions for polar map
00235    */
00239   int polarmap_num_rings;
00244   int polarmap_sectors_per_ring[MAX_POLARMAP_NUM_RINGS];
00247   float polarmap_ring_position[MAX_POLARMAP_NUM_RINGS];
00250   short int polarmap_ring_angle[MAX_POLARMAP_NUM_RINGS];
00252   short int polarmap_start_angle;
00253 
00254   /*
00255    *  Image data
00256    */
00257   /* Dimensions */
00259   unsigned short int dimt;
00261   unsigned short int dimx;
00263   unsigned short int dimy;
00265   unsigned short int dimz;
00267   float *_pxl;
00268   float **_col;
00269   float ***_row;
00270   float ****_pln;
00271   float *_header;
00272   /* Pointers for data to be used */
00274   float ****m;
00276   float ****plane;
00278   float ***row;
00280   float **column;
00282   float *pixel;
00284   int *planeNumber;
00285 
00286   /*
00287    *  Frame times
00288    */
00290   float *start;
00292   float *end;
00294   float *mid;
00295 
00296   /*
00297    *  Frame weights
00298    */
00300   char isWeight;
00302   float *weight;
00304   float *sd;
00306   float *prompts;
00308   float *randoms;
00309   
00310   /*
00311    *  Decay correction factors for each frame
00312    */
00314   float *decayCorrFactor;
00315 
00317   int errstatus;         
00318 
00319 } IMG;
00320 /*===========================================================================*/
00321 
00322 /*===========================================================================*/
00323 /*
00324  *  Function definitions
00325  */
00326 /* Initialization and memory handling of img data */
00327 extern void imgInit(IMG *image);
00328 extern void imgEmpty(IMG *image);
00329 extern int imgAllocate(IMG *image, int planes, int rows, int columns, int frames);
00330 extern int imgAllocateWithHeader(
00331   IMG *image, int planes, int rows, int columns, int frames, IMG *image_from);
00332 /* Retrieving image information */
00333 extern char *imgStatus(int status_index);
00334 extern void imgSetStatus(IMG *img, int status_index);
00335 extern void imgInfo(IMG *image);
00336 extern int imgCopyhdr(IMG *image1, IMG *image2);
00337 extern int imgExtractRange(IMG *img1, IMG_RANGE r, IMG *img2);
00338 /*===========================================================================*/
00339 
00340 /*===========================================================================*/
00341 #endif /* _IMG_H */
00342