![]() |
CASToR
1.0
Tomographic Reconstruction (PET/SPECT)
|
00001 00009 #ifndef OINTERFILEIO_HH 00010 #define OINTERFILEIO_HH 1 00011 00012 #include "oImageDimensionsAndQuantification.hh" 00013 #include "sScannerManager.hh" 00014 00015 00016 // --------------------------------------------------------------------- 00033 #define INTF_BIG_ENDIAN 0 00034 00035 #define INTF_LITTLE_ENDIAN 1 00036 00046 #define INTF_IMG_STATIC 0 00047 00048 #define INTF_IMG_DYNAMIC 1 00049 00050 #define INTF_IMG_PET 2 00051 00052 #define INTF_IMG_SPECT 3 00053 00054 #define INTF_IMG_GATED 4 00055 00056 #define INTF_IMG_GSPECT 5 00057 00058 #define INTF_IMG_UNKNOWN 6 00059 00074 #define INTF_LERP_DISABLED false 00075 00076 #define INTF_LERP_ENABLED true 00077 00089 #define BIT_str "bit" 00090 00091 #define UINT32_str "unsigned integer" 00092 00093 #define INT32_str "signed integer" 00094 00095 #define FLT32_str "short float" 00096 00097 #define FLT64_str "long float" 00098 00099 #define ASCII_str "ASCII" 00100 00111 #define INTF_SUPINE_HEADIN_TRANSAXIAL 0 00112 00113 #define INTF_SUPINE_HEADIN_SAGITTAL 1 00114 00115 #define INTF_SUPINE_HEADIN_CORONAL 2 00116 00117 #define INTF_SUPINE_FEETIN_TRANSAXIAL 3 00118 00119 #define INTF_SUPINE_FEETIN_SAGITTAL 4 00120 00121 #define INTF_SUPINE_FEETIN_CORONAL 5 00122 00123 #define INTF_PRONE_HEADIN_TRANSAXIAL 6 00124 00125 #define INTF_PRONE_HEADIN_SAGITTAL 7 00126 00127 #define INTF_PRONE_HEADIN_CORONAL 8 00128 00129 #define INTF_PRONE_FEETIN_TRANSAXIAL 9 00130 00131 #define INTF_PRONE_FEETIN_SAGITTAL 10 00132 00133 #define INTF_PRONE_FEETIN_CORONAL 11 00134 00147 #define INTF_TRANSVERSE 0 00148 00149 #define INTF_CORONAL 1 00150 00151 #define INTF_SAGITTAL 2 00152 00153 #define INTF_OTHER 3 00154 00167 #define INTF_SUPINE 0 00168 00169 #define INTF_PRONE 1 00170 00183 #define INTF_HEADIN 0 00184 00185 #define INTF_FEETIN 1 00186 00197 struct Intf_key 00198 { 00199 string korig; 00200 string kcase; 00201 string klcase; 00202 string kvalue; 00203 }; 00207 // --------------------------------------------------------------------- 00214 struct Intf_fields 00215 { 00216 string path_to_image; 00219 uint8_t endianness; 00222 uint32_t data_offset; 00225 string nb_format; 00228 uint8_t nb_dims; 00231 uint32_t mtx_size[7]; 00235 // float vox_size[3]; /*!< Voxel dimensions in mm.\n 00236 FLTNB vox_size[3]; 00239 // float slice_thickness_mm ; /*!< Read from the key 'slice thickness (pixels)'.\n 00240 FLTNB slice_thickness_mm ; 00243 uint16_t ctr_to_ctr_separation; 00246 uint16_t nb_time_frames ; 00249 uint16_t nb_resp_gates ; 00252 uint16_t nb_card_gates ; 00255 uint32_t nb_total_imgs; 00258 uint8_t nb_bytes_pixel; 00261 int8_t slice_orientation; 00265 int8_t pat_rotation; 00269 int8_t pat_orientation; 00273 // float rescale_slope; /*!< multiplicative calibration values. Initialized from 'quantification units' and/or 'rescale slope'.\n 00274 FLTNB rescale_slope; 00277 // float rescale_intercept; /*!< additive (intercept) calibration values.\n 00278 FLTNB rescale_intercept; 00281 uint32_t cmtx_size[3]; 00284 // float cvox_size[3]; /*!< (C)astor voxel size of the reconstructed images (x,y,z).\n 00285 FLTNB cvox_size[3]; 00288 bool is_mtx_size_different; 00291 int data_type; 00295 // float study_duration; /*!< Acquisition duration.\n 00296 FLTNB study_duration; 00299 vector<FLTNB> image_duration; 00303 uint32_t nb_time_windows; 00308 string process_status; 00311 // --- Fields related to an image in a group --- // // todo 00312 00313 uint32_t nb_img_in_frame_groups; 00316 // float image_pause; /*!< Pause between time windows ?\n 00317 //FLTNB image_pause; 00323 vector<FLTNB> frame_group_pause; 00326 // --- SPECT and projection related data --- // 00327 uint16_t nb_detector_heads; 00330 uint32_t nb_energy_windows; 00333 uint16_t nb_projections; 00336 // float extent_rotation; /*!< Angular span ex: 180, 360.\n 00337 FLTNB extent_rotation; 00340 string direction_rotation; 00343 // float first_angle; /*!< Angle of the first view.\n 00344 FLTNB first_angle; 00347 string projection_angles; 00350 string radius; 00352 }; 00357 #include "gVariables.hh" 00358 #include "sOutputManager.hh" 00359 #include "gOptions.hh" 00360 00361 // ------------------------------------------------------------------- 00362 // ----- "PUBLIC" FUNCTIONS WHICH COULD AND SHOULD BE ANYWHERE IN THE CODE WHERE INTERFILE IS REQUIRED ----- 00363 00376 template <typename T> int IntfKeyGetValueFromFile(const string& a_pathToHeader, const string& a_key, T* ap_return, int a_nbElts, int a_mandatoryFlag); 00377 00392 template <typename T> int IntfKeyGetRecurringValueFromFile(const string& a_pathToHeader, const string& a_key, T* ap_return, int a_nbElts, int a_mandatoryFlag, uint16_t a_nbOccurrences); 00393 00405 int IntfReadProjectionImage( const string& a_pathToHeaderFile, 00406 FLTNB* ap_ImgMatrix, 00407 Intf_fields* ap_IF, 00408 int vb, 00409 bool a_lerpFlag); 00410 00411 00423 int IntfReadImage( const string& a_pathToHeaderFile, 00424 FLTNB* ap_ImgMatrix, 00425 oImageDimensionsAndQuantification* ap_ID, 00426 int vb, 00427 bool a_lerpFlag); 00428 00443 int IntfReadImage( const string& a_pathToHeaderFile, 00444 FLTNB**** a4p_ImgMatrix, 00445 oImageDimensionsAndQuantification* ap_ID, 00446 int vb, 00447 bool a_lerpFlag); 00448 00463 int IntfReadImgDynCoeffFile(const string& a_pathToHeaderFile, 00464 FLTNB** a2p_ImgMatrix, 00465 oImageDimensionsAndQuantification* ap_ID, 00466 int a_nbFbases, 00467 int vb, 00468 bool a_lerpFlag); 00469 00470 00471 // ------------------------------------------------------------------- 00472 // ----- FUNCTIONS DEDICATED TO IMAGE DATA READING/WRITING ----- 00473 00487 int IntfCheckConsistency(Intf_fields* ap_IF, oImageDimensionsAndQuantification* ap_ID, int vb, int a_lerpFlag); 00488 00503 int IntfGetPixelTypeAndReadData(Intf_fields a_IF, 00504 ifstream* ap_iFile, 00505 FLTNB* ap_outImgMatrix, 00506 FLTNB* ap_inImgMatrix, 00507 uint32_t* a_offset, 00508 int a_nbVox, 00509 int vb); 00510 00528 template <class T> 00529 int IntfReadData(Intf_fields a_IF, 00530 ifstream* ap_iFile, 00531 FLTNB* ap_outImgMatrix, 00532 FLTNB* ap_inImgMatrix, 00533 uint32_t* a_offset, 00534 int a_nbVox, 00535 int vb, 00536 T* bytes); 00537 00550 int ImageInterpolation(FLTNB *ap_iImg, FLTNB *ap_oImg, 00551 const uint32_t ap_iDimVox[3], const uint32_t ap_oDimVox[3], 00552 const FLTNB ap_iSizeVox[3], const FLTNB ap_oSizeVox[3]); 00553 00554 00555 00568 int IntfWriteImgFile(const string& a_pathToImg, FLTNB* ap_ImgMatrix, const Intf_fields& ap_IntfF, int vb); 00569 00583 int IntfWriteImgFile(const string& a_pathToImg, FLTNB* ap_ImgMatrix, oImageDimensionsAndQuantification* ap_ID, int vb); 00584 00601 int IntfWriteProjFile(const string& a_pathToImg, FLTNB** a2p_ImgMatrix, oImageDimensionsAndQuantification* ap_ID, Intf_fields a_Imgfields, int vb); 00602 00620 int IntfWriteImgDynCoeffFile(const string& a_pathToImg, FLTNB** a2p_ImgMatrix, oImageDimensionsAndQuantification* ap_ID, int a_nbFbases, int vb); 00621 00637 int IntfWriteImgFile(const string& a_pathToImg, FLTNB**** a4p_ImgMatrix, oImageDimensionsAndQuantification* ap_ID, int vb); 00638 00649 int IntfWriteImage(const string& a_pathToImg, FLTNB* ap_outImgMtx, uint32_t a_dim, int vb); 00650 00661 int IntfWriteImage(vector<string> ap_pathToImgs, FLTNB** a2p_outImgMtx, uint32_t ap_dim[2], int vb); 00662 00673 int IntfWriteImage(vector<string> ap_pathToImgs, FLTNB**** a4p_outImgMtx, uint32_t ap_dim[4], int vb); 00674 00686 int IntfWriteData(ofstream* ap_oFile, FLTNB* ap_outImgMatrix, int a_nbVox, int vb); 00687 00688 00689 // ------------------------------------------------------------------- 00690 // ----- FUNCTIONS DEDICATED TO INTERFILE HEADER KEYs DECODING/PARSING/READING ----- 00691 00704 int IntfIsMHD(string a_pathToFile, vector<string> &ap_lPathToImgs); 00705 00717 int IntfWriteMHD(const string& a_pathToMhd, const vector<string> &ap_lPathToImgs, Intf_fields a_IntfF, oImageDimensionsAndQuantification* ap_ID, int vb); 00718 00736 int IntfReadHeader(const string& a_pathToHeaderFile, Intf_fields* ap_IntfFields, int vb); 00737 00749 int IntfWriteHeaderMainData(const string& a_path, const Intf_fields& ap_IntfF, int vb); 00750 00761 int IntfWriteHeaderImgData(ofstream &ap_ofile, const Intf_fields& ap_IntfF, int vb); 00762 00768 void IntfKeyInitFields(Intf_fields* ap_IF); 00769 00778 void IntfKeySetFieldsOutput(Intf_fields* ap_IF, oImageDimensionsAndQuantification* ap_ID); 00779 00785 void IntfKeyPrintFields(Intf_fields a_IF); 00786 00799 int IntfRecoverKey(Intf_key* ap_Key, const string& a_line); 00800 00809 int IntfCheckKeyMatch(Intf_key a_Key, const string& a_field); 00810 00817 int IntfKeyIsArray(Intf_key ap_Key); 00818 00825 int IntfKeyGetArrayNbElts(Intf_key ap_Key); 00826 00833 int IntfKeyGetMaxArrayKey(Intf_key ap_Key); 00834 00843 template <typename T> int IntfKeyGetArrayElts(Intf_key a_Key, T* ap_return); 00844 00853 string IntfKeyGetEndianStr(int a_val); 00854 00863 string IntfKeyGetModalityStr(int a_modalityIdx); 00864 00871 int IntfKeyGetInputImgDataType(const string& a_str); 00872 00879 int IntfKeyGetOutputImgDataType(oImageDimensionsAndQuantification* ap_ID); 00880 00886 string IntfKeyGetPixTypeStr(); 00887 00888 00889 // ------------------------------------------------------------------- 00890 // ----- NOT IMPLEMENTED KEY FUNCTION ----- 00891 00900 int IntfKeyGetPatOrientation(Intf_fields ap_IF); 00901 00911 int IntfGetVoxIdxSHTOrientation(Intf_fields a_IF, int a_voxId); 00912 00913 00914 // ------------------------------------------------------------------- 00915 // ----- SOME UTILITY FUNCTIONS ----- 00916 00923 void IntfAllocInterpImg(FLTNB** a2p_img, Intf_fields a_IF); 00924 00931 void GetUserEndianness(); 00932 00938 void IntfEraseSpaces(string* input_str); 00939 00946 void IntfToLowerCase(string* ap_str); 00947 00954 template <class Type> void SwapBytes(Type *ap_type); 00955 00956 #endif