CASToR  1.1
Tomographic Reconstruction (PET/SPECT)
 All Classes Files Functions Variables Typedefs Macros Groups Pages
oInterfileIO.hh
Go to the documentation of this file.
1 
9 #ifndef OINTERFILEIO_HH
10 #define OINTERFILEIO_HH 1
11 
13 #include "sScannerManager.hh"
14 
15 
16 // ---------------------------------------------------------------------
34 #define INTF_BIG_ENDIAN 0
35 
36 #define INTF_LITTLE_ENDIAN 1
37 
47 #define INTF_IMG_STATIC 0
48 
49 #define INTF_IMG_DYNAMIC 1
50 
51 #define INTF_IMG_PET 2
52 
53 #define INTF_IMG_SPECT 3
54 
55 #define INTF_IMG_GATED 4
56 
57 #define INTF_IMG_GSPECT 5
58 
59 #define INTF_IMG_UNKNOWN 6
60 
75 #define INTF_LERP_DISABLED false
76 
77 #define INTF_LERP_ENABLED true
78 
90 #define BIT_str "bit"
91 
92 #define UINT32_str "unsigned integer"
93 
94 #define INT32_str "signed integer"
95 
96 #define FLT32_str "short float"
97 #define FLT32_str2 "float"
98 
99 #define FLT64_str "long float"
100 
101 #define ASCII_str "ASCII"
102 
113 #define INTF_SUPINE_HEADIN_TRANSAXIAL 0
114 
115 #define INTF_SUPINE_HEADIN_SAGITTAL 1
116 
117 #define INTF_SUPINE_HEADIN_CORONAL 2
118 
119 #define INTF_SUPINE_FEETIN_TRANSAXIAL 3
120 
121 #define INTF_SUPINE_FEETIN_SAGITTAL 4
122 
123 #define INTF_SUPINE_FEETIN_CORONAL 5
124 
125 #define INTF_PRONE_HEADIN_TRANSAXIAL 6
126 
127 #define INTF_PRONE_HEADIN_SAGITTAL 7
128 
129 #define INTF_PRONE_HEADIN_CORONAL 8
130 
131 #define INTF_PRONE_FEETIN_TRANSAXIAL 9
132 
133 #define INTF_PRONE_FEETIN_SAGITTAL 10
134 
135 #define INTF_PRONE_FEETIN_CORONAL 11
136 
149 #define INTF_TRANSVERSE 0
150 
151 #define INTF_CORONAL 1
152 
153 #define INTF_SAGITTAL 2
154 
155 #define INTF_OTHER 3
156 
169 #define INTF_SUPINE 0
170 
171 #define INTF_PRONE 1
172 
185 #define INTF_HEADIN 0
186 
187 #define INTF_FEETIN 1
188 
199 struct Intf_key
200 {
201  string korig;
202  string kcase;
203  string klcase;
204  string kvalue;
205 };
209 // ---------------------------------------------------------------------
217 {
218  string path_to_image;
224  uint8_t endianness;
227  uint32_t data_offset;
230  string nb_format;
233  uint8_t nb_dims;
236  uint32_t mtx_size[7];
240 // float vox_size[3]; /*!< Voxel dimensions in mm.\n
244 // float slice_thickness_mm ; /*!< Read from the key 'slice thickness (pixels)'.\n
253  uint16_t nb_time_frames ;
256  uint16_t nb_resp_gates ;
259  uint16_t nb_card_gates ;
262  uint32_t nb_total_imgs;
265  uint8_t nb_bytes_pixel;
272  int8_t pat_rotation;
280 // float rescale_slope; /*!< multiplicative calibration values. Initialized from 'quantification units' and/or 'rescale slope'.\n
284 // float rescale_intercept; /*!< additive (intercept) calibration values.\n
288  uint32_t cmtx_size[3];
291 // float cvox_size[3]; /*!< (C)astor voxel size of the reconstructed images (x,y,z).\n
298  int data_type;
302 // float study_duration; /*!< Acquisition duration.\n
306  vector<FLTNB> image_duration;
310  uint32_t nb_time_windows;
315  string process_status;
318  // --- Fields related to an image in a group --- // // todo
319 
323 // float image_pause; /*!< Pause between time windows ?\n
324  //FLTNB image_pause;
330  vector<FLTNB> frame_group_pause;
333  // --- SPECT and projection related data --- //
334  uint16_t nb_detector_heads;
337  uint32_t nb_energy_windows;
340  uint16_t nb_projections;
343 // float extent_rotation; /*!< Angular span ex: 180, 360.\n
350 // float first_angle; /*!< Angle of the first view.\n
357  string radius;
359 };
364 #include "gVariables.hh"
365 #include "sOutputManager.hh"
366 #include "gOptions.hh"
367 
368  // -------------------------------------------------------------------
369  // ----- "PUBLIC" FUNCTIONS WHICH COULD AND SHOULD BE ANYWHERE IN THE CODE WHERE INTERFILE IS REQUIRED -----
370 
383  template <typename T> int IntfKeyGetValueFromFile(const string& a_pathToHeader, const string& a_key, T* ap_return, int a_nbElts, int a_mandatoryFlag);
384 
399  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);
400 
412  int IntfReadProjectionImage( const string& a_pathToHeaderFile,
413  FLTNB* ap_ImgMatrix,
414  Intf_fields* ap_IF,
415  int vb,
416  bool a_lerpFlag);
417 
426  int IntfCheckDimensionsConsistency(Intf_fields ImgFields1, Intf_fields ImgFields2);
427 
437  FLTNB* IntfLoadImageFromScratch( const string& a_pathToHeaderFile,
438  Intf_fields* ap_ImgFields,
439  int vb );
450  int IntfWriteImageFromIntfFields( const string& a_pathToImg,
451  FLTNB* ap_ImgMatrix,
452  Intf_fields Img_fields,
453  int vb );
454 
466  int IntfReadImage( const string& a_pathToHeaderFile,
467  FLTNB* ap_ImgMatrix,
469  int vb,
470  bool a_lerpFlag);
471 
486  int IntfReadImage( const string& a_pathToHeaderFile,
487  FLTNB**** a4p_ImgMatrix,
489  int vb,
490  bool a_lerpFlag);
491 
506  int IntfReadImgDynCoeffFile(const string& a_pathToHeaderFile,
507  FLTNB** a2p_ImgMatrix,
509  int a_nbFbases,
510  int vb,
511  bool a_lerpFlag);
512 
513 
514  // -------------------------------------------------------------------
515  // ----- FUNCTIONS DEDICATED TO IMAGE DATA READING/WRITING -----
516 
530  int IntfCheckConsistency(Intf_fields* ap_IF, oImageDimensionsAndQuantification* ap_ID, int vb, int a_lerpFlag);
531 
547  ifstream* ap_iFile,
548  FLTNB* ap_outImgMatrix,
549  FLTNB* ap_inImgMatrix,
550  uint32_t* a_offset,
551  int a_nbVox,
552  int vb);
553 
571  template <class T>
572  int IntfReadData(Intf_fields a_IF,
573  ifstream* ap_iFile,
574  FLTNB* ap_outImgMatrix,
575  FLTNB* ap_inImgMatrix,
576  uint32_t* a_offset,
577  int a_nbVox,
578  int vb,
579  T* bytes);
580 
593  int ImageInterpolation(FLTNB *ap_iImg, FLTNB *ap_oImg,
594  const uint32_t ap_iDimVox[3], const uint32_t ap_oDimVox[3],
595  const FLTNB ap_iSizeVox[3], const FLTNB ap_oSizeVox[3]);
596 
597 
598 
611  int IntfWriteImgFile(const string& a_pathToImg, FLTNB* ap_ImgMatrix, const Intf_fields& ap_IntfF, int vb);
612 
626  int IntfWriteImgFile(const string& a_pathToImg, FLTNB* ap_ImgMatrix, oImageDimensionsAndQuantification* ap_ID, int vb);
627 
644  int IntfWriteProjFile(const string& a_pathToImg, FLTNB** a2p_ImgMatrix, oImageDimensionsAndQuantification* ap_ID, Intf_fields a_Imgfields, int vb);
645 
663  int IntfWriteImgDynCoeffFile(const string& a_pathToImg, FLTNB** a2p_ImgMatrix, oImageDimensionsAndQuantification* ap_ID, int a_nbParImgs, int vb);
664 
680  int IntfWriteImgFile(const string& a_pathToImg, FLTNB**** a4p_ImgMatrix, oImageDimensionsAndQuantification* ap_ID, int vb);
681 
692  int IntfWriteImage(const string& a_pathToImg, FLTNB* ap_outImgMtx, uint32_t a_dim, int vb);
693 
704  int IntfWriteImage(vector<string> ap_pathToImgs, FLTNB** a2p_outImgMtx, uint32_t ap_dim[2], int vb);
705 
716  int IntfWriteImage(vector<string> ap_pathToImgs, FLTNB**** a4p_outImgMtx, uint32_t ap_dim[4], int vb);
717 
729  int IntfWriteData(ofstream* ap_oFile, FLTNB* ap_outImgMatrix, int a_nbVox, int vb);
730 
731 
732  // -------------------------------------------------------------------
733  // ----- FUNCTIONS DEDICATED TO INTERFILE HEADER KEYs DECODING/PARSING/READING -----
734 
747  int IntfIsMHD(string a_pathToFile, vector<string> &ap_lPathToImgs);
748 
760  int IntfWriteMHD(const string& a_pathToMhd, const vector<string> &ap_lPathToImgs, Intf_fields a_IntfF, oImageDimensionsAndQuantification* ap_ID, int vb);
761 
779  int IntfReadHeader(const string& a_pathToHeaderFile, Intf_fields* ap_IntfFields, int vb);
780 
792  int IntfWriteHeaderMainData(const string& a_path, const Intf_fields& ap_IntfF, int vb);
793 
804  int IntfWriteHeaderImgData(ofstream &ap_ofile, const Intf_fields& ap_IntfF, int vb);
805 
811  void IntfKeyInitFields(Intf_fields* ap_IF);
812 
822 
828  void IntfKeyPrintFields(Intf_fields a_IF);
829 
842  int IntfRecoverKey(Intf_key* ap_Key, const string& a_line);
843 
852  int IntfCheckKeyMatch(Intf_key a_Key, const string& a_field);
853 
860  int IntfKeyIsArray(Intf_key ap_Key);
861 
868  int IntfKeyGetArrayNbElts(Intf_key ap_Key);
869 
876  int IntfKeyGetMaxArrayKey(Intf_key ap_Key);
877 
886  template <typename T> int IntfKeyGetArrayElts(Intf_key a_Key, T* ap_return);
887 
896  string IntfKeyGetEndianStr(int a_val);
897 
906  string IntfKeyGetModalityStr(int a_modalityIdx);
907 
914  int IntfKeyGetInputImgDataType(const string& a_str);
915 
923 
929  string IntfKeyGetPixTypeStr();
930 
931 
932  // -------------------------------------------------------------------
933  // ----- NOT IMPLEMENTED KEY FUNCTION -----
934 
944 
954  int IntfGetVoxIdxSHTOrientation(Intf_fields a_IF, int a_voxId);
955 
956 
957  // -------------------------------------------------------------------
958  // ----- SOME UTILITY FUNCTIONS -----
959 
966  void IntfAllocInterpImg(FLTNB** a2p_img, Intf_fields a_IF);
967 
974  void GetUserEndianness();
975 
981  void IntfEraseSpaces(string* input_str);
982 
989  void IntfToLowerCase(string* ap_str);
990 
997  template <class Type> void SwapBytes(Type *ap_type);
998 
999 #endif
This header file is mainly used to declare some macro definitions and all includes needed from the st...
int IntfCheckKeyMatch(Intf_key a_Key, const string &a_field)
Check if the key matches the string passed in parameter.
FLTNB first_angle
Declaration of class oImageDimensionsAndQuantification.
string direction_rotation
string path_to_image
uint8_t nb_bytes_pixel
FLTNB vox_size[3]
#define FLTNB
Definition: gVariables.hh:55
int IntfWriteData(ofstream *ap_oFile, FLTNB *ap_outImgMatrix, int a_nbVox, int vb)
Write the content of the image matrix in the file pointed by ofstream.
int IntfKeyGetRecurringValueFromFile(const string &a_pathToHeader, const string &a_key, T *ap_return, int a_nbElts, int a_mandatoryFlag, uint16_t a_nbOccurrences)
uint32_t nb_total_imgs
string IntfKeyGetModalityStr(int a_modalityIdx)
Convert the integer provided in parameter to the string related to the corresponding modality as de...
int IntfReadData(Intf_fields a_IF, ifstream *ap_iFile, FLTNB *ap_outImgMatrix, FLTNB *ap_inImgMatrix, uint32_t *a_offset, int a_nbVox, int vb, T *bytes)
Templated function which read an image voxel by voxel and store it in the ap_outImgMtx image matrix...
FLTNB rescale_intercept
int8_t pat_rotation
string IntfKeyGetEndianStr(int a_val)
return the endian string corresponding to the value passed in parameter (see module INTF_ENDIANNESS)...
FLTNB extent_rotation
void IntfKeyPrintFields(Intf_fields a_IF)
Print all the keys of the Intf_fields structure passed in parameter, as well as their values for debu...
string kcase
uint8_t nb_dims
int IntfKeyGetValueFromFile(const string &a_pathToHeader, const string &a_key, T *ap_return, int a_nbElts, int a_mandatoryFlag)
Look for "a_nbElts" elts in the "a_pathToHeader" interfile header matching the "a_keyword" key passed...
Definition: oInterfileIO.cc:52
int IntfCheckDimensionsConsistency(Intf_fields ImgFields1, Intf_fields ImgFields2)
vector< FLTNB > frame_group_pause
void IntfEraseSpaces(string *input_str)
Erase space, blank characters ((t,r,n)), and '!' before and after the characters in the string passed...
uint32_t cmtx_size[3]
string nb_format
void IntfToLowerCase(string *ap_str)
Set all characters of the string passed in parameter to lower case.
int IntfGetVoxIdxSHTOrientation(Intf_fields a_IF, int a_voxId)
Compute a voxel index corresponding to the default orientation (Sup/Hin/Trans) from the orientation...
uint16_t nb_resp_gates
uint16_t nb_card_gates
int IntfReadHeader(const string &a_pathToHeaderFile, Intf_fields *ap_IntfFields, int vb)
Read an Interfile header.
int8_t pat_orientation
int IntfIsMHD(string a_pathToFile, vector< string > &ap_lPathToImgs)
Check if the string in argument contains the path to a Interfile metaheader.
uint8_t endianness
int IntfKeyIsArray(Intf_key ap_Key)
Check if the key passed in parameter is an array (contains brackets '{' and '}' ) ...
int IntfWriteImage(const string &a_pathToImg, FLTNB *ap_outImgMtx, uint32_t a_dim, int vb)
Write Interfile raw data whose path is provided in parameter, using image matrix provided in paramete...
FLTNB rescale_slope
int8_t slice_orientation
int IntfKeyGetInputImgDataType(const string &a_str)
Get the image data type corresponding to the image metadata passed in parameter.
int IntfReadProjectionImage(const string &a_pathToHeaderFile, FLTNB *ap_ImgMatrix, Intf_fields *ap_IF, int vb, bool a_lerpFlag)
Main function which reads a projection Interfile 3D projection image and store its content in the pro...
FLTNB * IntfLoadImageFromScratch(const string &a_pathToHeaderFile, Intf_fields *ap_ImgFields, int vb)
int IntfWriteHeaderImgData(ofstream &ap_ofile, const Intf_fields &ap_IntfF, int vb)
Declaration of class sScannerManager.
int IntfKeyGetArrayNbElts(Intf_key ap_Key)
Return the number of elts in an Interfile array Key.
void IntfKeyInitFields(Intf_fields *ap_IF)
Init the file of an Interfile fields structure passed in parameter to their default values...
vector< FLTNB > image_duration
uint32_t mtx_size[7]
string korig
void IntfAllocInterpImg(FLTNB **a2p_img, Intf_fields a_IF)
Allocate memory for an image matrix to recover an image to interpolate.
uint16_t nb_projections
int IntfKeyGetPatOrientation(Intf_fields ap_IF)
Get the complete patient orientation from an Intf_fields structure according to the values of keys 's...
uint32_t data_offset
string klcase
uint16_t nb_time_frames
Interfile key elements. This structure is used to recover and process the elements of an Interfile ...
uint16_t ctr_to_ctr_separation
int IntfKeyGetArrayElts(Intf_key a_Key, T *ap_return)
Get all the elements in an array key in a templated array passed in parameter. It assumes the retur...
int IntfGetPixelTypeAndReadData(Intf_fields a_IF, ifstream *ap_iFile, FLTNB *ap_outImgMatrix, FLTNB *ap_inImgMatrix, uint32_t *a_offset, int a_nbVox, int vb)
The purpose of this function is to call the templated ReadData() function with the data type correspo...
int IntfWriteProjFile(const string &a_pathToImg, FLTNB **a2p_ImgMatrix, oImageDimensionsAndQuantification *ap_ID, Intf_fields a_Imgfields, int vb)
Function dedicated to Interfile image writing for projected data.
int IntfWriteImgDynCoeffFile(const string &a_pathToImg, FLTNB **a2p_ImgMatrix, oImageDimensionsAndQuantification *ap_ID, int a_nbParImgs, int vb)
Function dedicated to Interfile image writing for dynamic coefficients images.
uint32_t nb_time_windows
Interfile fields. This structure contains all the Interfile keys currently managed by CASToR Decl...
FLTNB multiple_bed_displacement
Declaration of class sOutputManager.
uint16_t nb_detector_heads
string kvalue
FLTNB cvox_size[3]
int IntfWriteMHD(const string &a_pathToMhd, const vector< string > &ap_lPathToImgs, Intf_fields a_IntfF, oImageDimensionsAndQuantification *ap_ID, int vb)
Write an Interfile meta header at the path provided in parameter, using the field stack provided in p...
This class is designed to manage all dimensions and quantification related stuff. ...
FLTNB study_duration
This file is used for all kind of different functions designed for options parsing and ASCII file rea...
void IntfKeySetFieldsOutput(Intf_fields *ap_IF, oImageDimensionsAndQuantification *ap_ID)
Init the keys of the Interfile header of an image to be written on disk.
string projection_angles
int IntfRecoverKey(Intf_key *ap_Key, const string &a_line)
Process the line passed in parameter and write the key information in the ap_Key Intf_key member stru...
string process_status
uint32_t nb_energy_windows
int IntfKeyGetMaxArrayKey(Intf_key ap_Key)
Return the maximum value from an array key (key value contains brackets '{,,}' )
int IntfKeyGetOutputImgDataType(oImageDimensionsAndQuantification *ap_ID)
uint32_t nb_img_in_frame_groups
int IntfWriteHeaderMainData(const string &a_path, const Intf_fields &ap_IntfF, int vb)
void SwapBytes(Type *ap_type)
Use std::reverse to swap the bits of a variable of any type.
int IntfReadImgDynCoeffFile(const string &a_pathToHeaderFile, FLTNB **a2p_ImgMatrix, oImageDimensionsAndQuantification *ap_ID, int a_nbFbases, int vb, bool a_lerpFlag)
Function dedicated to Interfile image reading for dynamic coefficients images.
string IntfKeyGetPixTypeStr()
Return the string corresponding to the nb of bytes in the type FLTNB.
int IntfReadImage(const string &a_pathToHeaderFile, FLTNB *ap_ImgMatrix, oImageDimensionsAndQuantification *ap_ID, int vb, bool a_lerpFlag)
Main function dedicated to Interfile 3D image loading.
int IntfWriteImgFile(const string &a_pathToImg, FLTNB *ap_ImgMatrix, const Intf_fields &ap_IntfF, int vb)
Main function dedicated to Interfile 3D image writing. Recover image information from a provided In...
void GetUserEndianness()
Check user/host computer endianness and write it to the global variable User_Endianness.
FLTNB slice_thickness_mm
int ImageInterpolation(FLTNB *ap_iImg, FLTNB *ap_oImg, const uint32_t ap_iDimVox[3], const uint32_t ap_oDimVox[3], const FLTNB ap_iSizeVox[3], const FLTNB ap_oSizeVox[3])
Trilinear interpolation.
bool is_mtx_size_different
string originating_system
int IntfCheckConsistency(Intf_fields *ap_IF, oImageDimensionsAndQuantification *ap_ID, int vb, int a_lerpFlag)
Check if the mandatory fields have been initialize in the ap_IF structure, and check consistencies wi...
int IntfWriteImageFromIntfFields(const string &a_pathToImg, FLTNB *ap_ImgMatrix, Intf_fields Img_fields, int vb)