8 #include "oInterfileIO.hh" 45 ifstream input_file(a_pathToHeader.c_str(), ios::in);
51 while(!input_file.eof())
53 getline(input_file, line);
63 Cerr(
"***** IntfKeyGetValueFromFile()-> Error : couldn't correctly read interfile key '"<< line <<
"' !" << endl);
74 Cerr(
"***** IntfKeyGetValueFromFile()-> Exception when trying to read tag '" << a_key <<
"' in file '" << a_pathToHeader <<
"'." << endl);
85 Cerr(
"***** IntfKeyGetValueFromFile() -> " << a_nbElts <<
" requested for interfile key " << a_key <<
" , but this key is not an array !" << endl);
93 Cerr(
"***** IntfKeyGetValueFromFile() -> Nb of elements to recover (=" << a_nbElts <<
") does not correspond to the number of elements found in the key '" 101 Cerr(
"***** IntfKeyGetValueFromFile() -> " << a_nbElts <<
" requested for interfile key " << a_key <<
" , but this key is not an array !" << endl);
112 if (a_mandatoryFlag > 0)
114 Cerr(
"***** IntfKeyGetValueFromFile()-> Error when reading Interfile '" << a_pathToHeader <<
"'. Key '" << a_key <<
"' was not found." << endl);
125 Cerr(
"***** IntfKeyGetValueFromFile()-> Couldn't find or read data-file '"<< a_pathToHeader <<
"' !" << endl);
132 template int IntfKeyGetValueFromFile<int>(
const string& a_pathToHeader,
const string& a_key,
int* ap_return,
int a_nbElts,
int a_mandatoryFlag);
134 template int IntfKeyGetValueFromFile<float>(
const string& a_pathToHeader,
const string& a_key,
float* ap_return,
int a_nbElts,
int a_mandatoryFlag);
140 template int IntfKeyGetValueFromFile<bool>(
const string& a_pathToHeader,
const string& a_key,
bool* ap_return,
int a_nbElts,
int a_mandatoryFlag);
162 uint16_t a_nbOccurrences)
164 ifstream input_file(a_pathToHeader.c_str(), ios::in);
166 uint16_t nb_occurences_cur =0;
171 while(!input_file.eof())
173 getline(input_file, line);
183 Cerr(
"***** IntfKeyGetValueFromFile()-> Error : couldn't correctly read interfile key '"<< line <<
"' !" << endl);
194 if(nb_occurences_cur < a_nbOccurrences)
204 Cerr(
"***** IntfKeyGetValueFromFile()-> Exception when trying to read tag '" << a_key <<
"' in file '" << a_pathToHeader <<
"'." << endl);
215 Cerr(
"***** IntfKeyGetValueFromFile() -> " << a_nbElts <<
" requested for interfile key " << a_key <<
" , but this key is not an array !" << endl);
223 Cerr(
"***** IntfKeyGetValueFromFile() -> Nb of elements to recover (=" << a_nbElts <<
") does not correspond to the number of elements found in the key '" 231 Cerr(
"***** IntfKeyGetValueFromFile() -> " << a_nbElts <<
" requested for interfile key " << a_key <<
" , but this key is not an array !" << endl);
242 if (a_mandatoryFlag > 0)
244 Cerr(
"***** IntfKeyGetValueFromFile()-> Error when reading Interfile '" << a_pathToHeader <<
"'. Key '" << a_key <<
"' was not found." << endl);
255 Cerr(
"***** IntfKeyGetValueFromFile()-> Couldn't find or read data-file '"<< a_pathToHeader <<
"' !" << endl);
286 if(vb >= 3)
Cout(
"IntfReadProjectionImage()-> Read Interfile header : "<< a_pathToHeaderFile << endl);
294 Cerr(
"***** IntfReadProjectionImage()-> Error : while trying to read the interfile header '"<< a_pathToHeaderFile <<
"' !" << endl);
301 int nb_tot_pixels = ap_IF->
mtx_size[0]
306 ifstream img_file(ap_IF->
path_to_image.c_str(), ios::binary | ios::in);
317 Cerr(
"***** IntfReadProjectionImage()-> Error occurred while trying to read the image file at the path: '"<< ap_IF->
path_to_image <<
"' !" << endl);
342 Cerr(
"***** IntfCheckDimensionsConsistency() -> Numbers of dimensions are not the same !" << endl);
346 for (
int dim=0; dim<((int)ImgFields1.
nb_dims); dim++)
351 Cerr(
"***** IntfCheckDimensionsConsistency() -> The sizes of the dimension " << dim+1 <<
" are not the same !" << endl);
356 for (
int dim=0; dim<std::min(3,((
int)ImgFields1.
nb_dims)); dim++)
361 Cerr(
"***** IntfCheckDimensionsConsistency() -> Voxel sizes of dimension " << dim+1 <<
" are not the same !" << endl);
368 Cerr(
"***** IntfCheckDimensionsConsistency() -> Slice thicknesses are not the same !" << endl);
384 if (vb>=2)
Cout(
"IntfLoadImageFromScratch() -> Read Interfile image '" << a_pathToHeaderFile <<
"'" << endl);
392 Cerr(
"***** IntfLoadImageFromScratch() -> A problem occurred while trying to read the interfile header '" << a_pathToHeaderFile <<
"' !" << endl);
399 Cerr(
"***** IntfLoadImageFromScratch() -> Cannot handle a number of dimensions higher than 3 !" << endl);
404 for (
int d=0; d<ap_ImgFields->
nb_dims; d++)
if (ap_ImgFields->
mtx_size[d]==0)
406 Cerr(
"***** IntfLoadImageFromScratch() -> Number of voxels for dimension #" << d <<
" is 0, so has not been read correctly in header file '" << a_pathToHeaderFile <<
"' !" << endl);
410 for (
int d=0; d<ap_ImgFields->
nb_dims; d++)
if (ap_ImgFields->
vox_size[d]<=0.)
412 Cerr(
"***** IntfLoadImageFromScratch() -> Voxel size for dimension #" << d <<
" is negative, so has not been read correctly in header file '" << a_pathToHeaderFile <<
"' !" << endl);
423 ifstream img_file(ap_ImgFields->
path_to_image.c_str(), ios::binary | ios::in);
426 Cerr(
"***** IntfLoadImageFromScratch() -> Input image file '" << ap_ImgFields->
path_to_image <<
"' is missing or corrupted !" << endl);
447 if (vb>=2)
Cout(
"IntfWriteImageFromIntfFields() -> Write 3D image with output base name '" << a_pathToImg <<
"'" << endl);
452 Cerr(
"***** IntfWriteImageFromIntfFields() -> Error : while trying to write the interfile header '"<< a_pathToImg <<
"' !" << endl);
457 string path_to_image = a_pathToImg;
458 path_to_image.append(
".img");
466 Cerr(
"***** IntfWriteImageFromIntfFields() -> Error : while trying to write the interfile image '"<< path_to_image <<
"' !" << endl);
486 if (a_verbose>=
VERBOSE_DETAIL)
Cout(
"oInterfileIO::IntfReadImage() -> Read image from interfile header '" << a_pathToHeaderFile <<
"'" << endl);
495 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while trying to read the interfile header '" << a_pathToHeaderFile <<
"' !" << endl);
502 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while checking consistencies between reconstruction parameters and interfile keys from header '" 503 << a_pathToHeaderFile <<
"' !" << endl);
508 FLTNB* pimg_erp = NULL;
513 ifstream img_file(Img_fields.
path_to_image.c_str(), ios::binary | ios::in);
521 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while reading data and eventually interpolating from the IntfGetPixelTypeAndReadData() function !" << endl);
527 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while trying to open the image file '" << Img_fields.
path_to_image <<
"' !" << endl);
529 if (pimg_erp)
delete[] pimg_erp;
534 if (pimg_erp)
delete[] pimg_erp;
545 FLTNB**** a4p_ImgMatrix,
550 if (a_verbose >= 5)
Cout(
"oInterfileIO::IntfReadImage() -> Read image from interfile header '" << a_pathToHeaderFile <<
"'" << endl);
557 vector<string> lpath_to_headers;
561 if (
IntfIsMHD(a_pathToHeaderFile, lpath_to_headers) < 0 )
563 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while trying to read the interfile header '" << a_pathToHeaderFile <<
"' in IntfIsMHD() function !" << endl);
568 if (lpath_to_headers.size() == 1)
573 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while trying to read the interfile header '" << a_pathToHeaderFile <<
"' !" << endl);
579 Cerr(
"***** oInterfileIO::IntfReadImage() -> A error occurred while checking consistencies between reconstruction parameters and interfile keys in the header '" << a_pathToHeaderFile <<
"' !" << endl);
583 FLTNB* pimg_erp = NULL;
587 ifstream img_file(Img_fields.
path_to_image.c_str(), ios::binary | ios::in);
601 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while reading data and eventually interpolating from the IntfGetPixelTypeAndReadData() function !" << endl);
603 if (pimg_erp)
delete[] pimg_erp;
610 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while trying to read the image file '"<< Img_fields.
path_to_image <<
"' !" << endl);
612 if (pimg_erp)
delete[] pimg_erp;
616 if (pimg_erp)
delete[] pimg_erp;
625 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while trying to read the interfile metaheader '" << a_pathToHeaderFile <<
"' !" << endl);
634 if (lpath_to_headers.size() != (uint32_t)(dims[0]*dims[1]*dims[2]+ap_ID->
GetNbFramesToSkip()))
636 Cerr(
"***** oInterfileIO::IntfReadImage() -> Number of interfile images (" << lpath_to_headers.size() <<
637 ") not consistent with the number of images to load (" << dims[0]*dims[1]*dims[2]<<
") !" << endl);
641 FLTNB* pimg_erp = NULL;
646 for(
int d2=0 ; d2<dims[1] ; d2++)
647 for(
int d3=0 ; d3<dims[2] ; d3++)
649 int idx_img = d1*dims[1]*dims[2] + d2*dims[2] + d3;
653 if (
IntfReadHeader(lpath_to_headers[idx_img], &Img_fields, a_verbose) )
655 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while trying to read the interfile header '" << lpath_to_headers[idx_img] <<
"' !" << endl);
661 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while checking consistencies between reconstruction parameters and interfile keys in the header '" 662 << lpath_to_headers[idx_img] <<
"' !" << endl);
666 ifstream img_file(Img_fields.
path_to_image.c_str(), ios::binary | ios::in);
674 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while reading data and eventually interpolating from the IntfGetPixelTypeAndReadData() function !" << endl);
676 if (pimg_erp)
delete[] pimg_erp;
682 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while trying to read the image file '"<< Img_fields.
path_to_image <<
"' !" << endl);
684 if (pimg_erp)
delete[] pimg_erp;
689 if (pimg_erp)
delete[] pimg_erp;
714 if (a_verbose>=
VERBOSE_DETAIL)
Cout(
"oInterfileIO::IntfReadAdditionalData() -> Read addtional data from interfile header '" << a_pathToHeaderFile <<
"'" << endl);
723 Cerr(
"***** oInterfileIO::IntfReadAdditionalData() -> An error occurred while trying to read the interfile header '" << a_pathToHeaderFile <<
"' !" << endl);
728 ifstream additional_data_file(Data_fields.
path_to_image.c_str(), ios::binary | ios::in);
729 if (additional_data_file)
734 if (
IntfGetPixelTypeAndReadData(Data_fields, &additional_data_file, ap_DataMatrix, ap_DataMatrix, &offset, a_matrixSize, a_verbose))
736 Cerr(
"***** oInterfileIO::IntfReadAdditionalData() -> An error occurred while reading data and eventually interpolating from the IntfGetPixelTypeAndReadData() function !" << endl);
742 Cerr(
"***** oInterfileIO::IntfReadAdditionalData() -> An error occurred while trying to open the additional data file '" << Data_fields.
path_to_image <<
"' !" << endl);
755 FLTNB** a2p_ImgMatrix,
761 if (a_verbose >= 5)
Cout(
"IntfReadImgDynCoeffFile" << endl);
768 vector<string> lpath_to_headers;
772 if(
IntfIsMHD(a_pathToHeaderFile, lpath_to_headers) <0)
774 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> an error occurred while trying to read the interfile header '" << a_pathToHeaderFile <<
"' !" << endl);
779 if(lpath_to_headers.size() == 1)
784 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while trying to read the interfile header '" << a_pathToHeaderFile <<
"' !" << endl);
790 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while checking consistencies between reconstruction parameters and interfile keys in the header '" << a_pathToHeaderFile <<
"' !" << endl);
794 FLTNB* pimg_erp = NULL;
797 ifstream img_file(Img_fields.
path_to_image.c_str(), ios::binary | ios::in);
804 for (
int bf=0 ; bf<a_nbFbasis ; bf++)
808 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while reading from file stream and eventually interpolating !" << endl);
810 if (pimg_erp)
delete[] pimg_erp;
817 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while trying to read the image file '" << Img_fields.
path_to_image <<
"' !" << endl);
819 if (pimg_erp)
delete[] pimg_erp;
823 if (pimg_erp)
delete[] pimg_erp;
832 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while trying to read the interfile metaheader '" << a_pathToHeaderFile <<
"' !" << endl);
836 if (lpath_to_headers.size() != (uint32_t)a_nbFbasis)
838 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> Number of interfile images (" << lpath_to_headers.size() <<
839 ") not consistent with the number of parametric images (" << a_nbFbasis<<
") !" << endl);
843 FLTNB* pimg_erp = NULL;
846 for (
int bf=0 ; bf<a_nbFbasis ; bf++)
849 if (
IntfReadHeader(lpath_to_headers[bf], &Img_fields, a_verbose) )
851 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> an error occurred while trying to read interfile header '" << a_pathToHeaderFile <<
"' !" << endl);
853 if (pimg_erp)
delete[] pimg_erp;
859 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while checking consistencies between reconstruction parameters and interfile keys in the header '"<< a_pathToHeaderFile <<
"' !" << endl);
861 if (pimg_erp)
delete[] pimg_erp;
865 ifstream img_file(Img_fields.
path_to_image.c_str(), ios::binary | ios::in);
873 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while reading image stream and eventually interpolating !" << endl);
875 if (pimg_erp)
delete[] pimg_erp;
881 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while trying to read the image file '" << Img_fields.
path_to_image <<
"' !" << endl);
883 if (pimg_erp)
delete[] pimg_erp;
888 if (pimg_erp)
delete[] pimg_erp;
911 uint32_t nb_vox = a_IF.
mtx_size[0] *
916 *a2p_img =
new FLTNB[ nb_vox ];
917 ::memset(*a2p_img, 0,
sizeof(
FLTNB) * nb_vox);
943 if(vb >= 5)
Cout(
"IntfCheckConsistency()" << endl);
950 Cerr(
"***** IntfCheckConsistency()-> Error : some mandatory keys not initialized. Cannot read the interfile image !" << endl);
953 Cerr(
" Error when trying to read path to image data" << endl);
955 Cerr(
" Error when trying to read data voxel type " << endl);
957 Cerr(
" Error when trying to read matrix size (image dimensions) : x= " << ap_IF->
mtx_size[0] <<
", y= " << ap_IF->
mtx_size[1] <<
", z= " << ap_IF->
mtx_size[2]<< endl);
965 Cerr(
"***** IntfCheckConsistency()-> WARNING : No information found about voxel size ('scaling factor (mm/pixel)' tags.). Missing voxel sizes will be set to 1mm !" << endl);
999 Cerr(
"***** IntfCheckConsistency()-> Error : Image dimensions don't match reconstructions dimensions/voxel sizes" << endl);
1000 Cerr(
" and linear interpolation is disabled (a_lerpFlag is false) !" << endl);
1001 Cerr(
"***** Recovered image dimensions (x;y;z): "<< ap_IF->
mtx_size[0] <<
" ; "<< ap_IF->
mtx_size[1] <<
" ; " << ap_IF->
mtx_size[2] << endl);
1019 FLTNB* ap_outImgMatrix,
1020 FLTNB* ap_inImgMatrix,
1021 uint32_t* ap_offset,
1026 if (a_verbose >= 5)
Cout(
"oInterfileIO::IntfGetPixelTypeAndReadData() " << endl);
1035 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &flt);
1040 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &db);
1046 Cerr(
"***** oInterfileIO::IntfGetPixelTypeAndReadData() -> The long double format is not the same for this image file and for this platform !" << endl);
1050 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &db);
1057 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &s_int);
1062 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &s_int);
1067 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &s_int);
1072 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &s_int);
1080 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &u_int);
1085 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &u_int);
1090 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &u_int);
1095 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &u_int);
1101 Cerr(
"***** oInterfileIO::IntfGetPixelTypeAndReadData() -> An error occurred when trying to read data through the IntfReadData() function !" << endl);
1116 FLTNB* ap_outImgMatrix,
1117 FLTNB* ap_inImgMatrix,
1124 if (a_verbose >= 5)
Cout(
"oInterfileIO::IntfReadData() -> Read data from file stream and eventually interpolate" << endl);
1135 pimg = ap_inImgMatrix;
1140 pimg = ap_outImgMatrix;
1144 bytes = (T*)malloc(nb_vox*
sizeof(T));
1146 ap_iFile->seekg(*a_offset);
1148 ap_iFile->read((
char*)bytes, nb_vox*
sizeof(T));
1150 if (!ap_iFile->good())
1152 if (ap_iFile->eof())
Cerr(
"***** oInterfileIO::IntfReadData() -> Not enough data in the file stream !" << endl);
1153 else Cerr(
"***** oInterfileIO::IntfReadData() -> An error occurred while reading from file stream !" << endl);
1159 for (
int v=0; v<nb_vox; v++)
1175 *a_offset +=
sizeof(T);
1193 Cerr(
"***** oInterfileIO::IntfReadData() -> An error occurred while interpolating the input image to the reconstruction dimensions !" << endl);
1222 const uint32_t ap_iDimVox[3],
const uint32_t ap_oDimVox[3],
1223 const FLTNB ap_iSizeVox[3],
const FLTNB ap_oSizeVox[3],
1224 const FLTNB ap_iOffVox[3],
const FLTNB ap_oOffVox[3] )
1429 FLTNB const posOldImage[] = {-((
FLTNB)(ap_iDimVox[0]))*ap_iSizeVox[0]*((
FLTNB)0.5) ,
1430 -((
FLTNB)(ap_iDimVox[1]))*ap_iSizeVox[1]*((
FLTNB)0.5) ,
1431 -((
FLTNB)(ap_iDimVox[2]))*ap_iSizeVox[2]*((
FLTNB)0.5) };
1433 FLTNB const posNewImage[] = {-((
FLTNB)(ap_oDimVox[0]))*ap_oSizeVox[0]*((
FLTNB)0.5) ,
1434 -((
FLTNB)(ap_oDimVox[1]))*ap_oSizeVox[1]*((
FLTNB)0.5) ,
1435 -((
FLTNB)(ap_oDimVox[2]))*ap_oSizeVox[2]*((
FLTNB)0.5) };
1447 uint32_t
const iDimVoxPad[]
1449 ap_iDimVox[ 0 ] + 2,
1450 ap_iDimVox[ 1 ] + 2,
1454 uint32_t
const nElts = iDimVoxPad[ 0 ] *
1460 ::memset( pPadIData, 0,
sizeof(
FLTNB ) * nElts );
1462 for( uint32_t k = 0; k < ap_iDimVox[ 2 ]; ++k )
1463 for( uint32_t j = 0; j < ap_iDimVox[ 1 ]; ++j )
1464 for( uint32_t i = 0; i < ap_iDimVox[ 0 ]; ++i )
1466 pPadIData[ ( i + 1 ) + ( j + 1 ) * iDimVoxPad[ 0 ]
1467 + ( k + 1 ) * iDimVoxPad[ 0 ] * iDimVoxPad[ 1 ] ] =
1468 ap_iImg[ i + j * ap_iDimVox[ 0 ]
1469 + k * ap_iDimVox[ 0 ] * ap_iDimVox[ 1 ] ];
1474 FLTNB const boundMin[]
1476 posOldImage[ 0 ] - ap_iSizeVox[ 0 ] * ((
FLTNB)0.5),
1477 posOldImage[ 1 ] - ap_iSizeVox[ 1 ] * ((
FLTNB)0.5),
1478 posOldImage[ 2 ] - ap_iSizeVox[ 2 ] * ((
FLTNB)0.5)
1481 FLTNB const boundMax[]
1483 posOldImage[ 0 ] + ((
FLTNB)ap_iDimVox[ 0 ]) * ap_iSizeVox[ 0 ]
1484 + ap_iSizeVox[ 0 ] * ((
FLTNB)0.5),
1485 posOldImage[ 1 ] + ((
FLTNB)ap_iDimVox[ 1 ]) * ap_iSizeVox[ 1 ]
1486 + ap_iSizeVox[ 1 ] * ((
FLTNB)0.5),
1487 posOldImage[ 2 ] + ((
FLTNB)ap_iDimVox[ 2 ]) * ap_iSizeVox[ 2 ]
1488 + ap_iSizeVox[ 2 ] * ((
FLTNB)0.5)
1495 for( uint32_t i = 0; i < 3; ++i )
1497 pOldCoordCenter[ i ] =
new FLTNB[ iDimVoxPad[ i ] ];
1499 for( uint32_t j = 0; j < iDimVoxPad[ i ]; ++j )
1501 pOldCoordCenter[ i ][ j ] = posOldImage[ i ] - ap_iSizeVox[ i ] / 2.0
1502 + j * ap_iSizeVox[ i ];
1509 for( uint32_t i = 0; i < 3; ++i )
1511 pNewCoordCenter[ i ] =
new FLTNB[ ap_oDimVox[ i ] ];
1513 for( uint32_t j = 0; j < ap_oDimVox[ i ]; ++j )
1515 pNewCoordCenter[ i ][ j ] = posNewImage[ i ] + ap_oSizeVox[ i ] / 2.0
1516 + j * ap_oSizeVox[ i ];
1521 FLTNB const invSizeX = 1.0 / ap_iSizeVox[ 0 ];
1522 FLTNB const invSizeY = 1.0 / ap_iSizeVox[ 1 ];
1523 FLTNB const invSizeZ = 1.0 / ap_iSizeVox[ 2 ];
1529 for( uint32_t k = 0; k < ap_oDimVox[ 2 ]; ++k )
1532 FLTNB const z = pNewCoordCenter[ 2 ][ k ];
1533 if( z < boundMin[ 2 ] || z > boundMax[ 2 ] )
continue;
1536 int32_t
const zBin = ( z - boundMin[ 2 ] ) * invSizeZ;
1539 FLTNB const zComposantI0 = invSizeZ * ( pOldCoordCenter[ 2 ][ zBin + 1 ] - z );
1540 FLTNB const zComposantI1 = invSizeZ * ( z - pOldCoordCenter[ 2 ][ zBin ] );
1542 for( uint32_t j = 0; j < ap_oDimVox[ 1 ]; ++j )
1545 FLTNB const y = pNewCoordCenter[ 1 ][ j ];
1546 if( y < boundMin[ 1 ] || y > boundMax[ 1 ] )
continue;
1549 int32_t
const yBin = ( y - boundMin[ 1 ] ) * invSizeY;
1552 FLTNB const yComposantI0 = invSizeY * ( pOldCoordCenter[ 1 ][ yBin + 1 ]
1554 FLTNB const yComposantI1 = invSizeY * ( y
1555 - pOldCoordCenter[ 1 ][ yBin ] );
1557 for( uint32_t i = 0; i < ap_oDimVox[ 0 ]; ++i )
1560 FLTNB const x = pNewCoordCenter[ 0 ][ i ];
1561 if( x < boundMin[ 0 ] || x > boundMax[ 0 ] )
continue;
1564 int32_t
const xBin = ( x - boundMin[ 0 ] ) * invSizeX;
1567 FLTNB const xComposantI0 = invSizeX * (
1568 pOldCoordCenter[ 0 ][ xBin + 1 ] - x );
1569 FLTNB const xComposantI1 = invSizeX * ( x
1570 - pOldCoordCenter[ 0 ][ xBin ] );
1574 for( uint32_t kk = 0; kk < 2; ++kk )
1576 for( uint32_t jj = 0; jj < 2; ++jj )
1578 for( uint32_t ii = 0; ii < 2; ++ii )
1580 pKernelData[ ii + jj * 2 + kk * 2 * 2 ] =
1583 ( yBin + jj ) * iDimVoxPad[ 0 ] +
1584 ( zBin + kk ) * iDimVoxPad[ 0 ] * iDimVoxPad[ 1 ]
1592 FLTNB const xInterpVal0 = pKernelData[ 0 ] * xComposantI0 +
1593 pKernelData[ 1 ] * xComposantI1;
1595 FLTNB const xInterpVal1 = pKernelData[ 2 ] * xComposantI0 +
1596 pKernelData[ 3 ] * xComposantI1;
1598 FLTNB const xInterpVal2 = pKernelData[ 4 ] * xComposantI0 +
1599 pKernelData[ 5 ] * xComposantI1;
1601 FLTNB const xInterpVal3 = pKernelData[ 6 ] * xComposantI0 +
1602 pKernelData[ 7 ] * xComposantI1;
1605 FLTNB const yInterpVal0 = xInterpVal0 * yComposantI0 +
1606 xInterpVal1 * yComposantI1;
1608 FLTNB const yInterpVal1 = xInterpVal2 * yComposantI0 +
1609 xInterpVal3 * yComposantI1;
1612 FLTNB const interpValTot = yInterpVal0 * zComposantI0 +
1613 yInterpVal1 * zComposantI1;
1615 ap_oImg[ i + j * ap_oDimVox[ 0 ]
1616 + k * ap_oDimVox[ 0 ] * ap_oDimVox[ 1 ] ] = interpValTot;
1622 for( uint32_t i = 0; i < 3; ++i )
1624 delete[] pOldCoordCenter[ i ];
1625 delete[] pNewCoordCenter[ i ];
1627 delete[] pOldCoordCenter;
1628 delete[] pNewCoordCenter;
1630 delete[] pKernelData;
1658 if (vb>=3)
Cout(
"IntfWriteImgFile (with Intf_fields)" << endl);
1663 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile header for'"<< a_pathToImg <<
"' !" << endl);
1667 string path_to_image = a_pathToImg;
1668 path_to_image.append(
".img");
1673 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile image '"<< path_to_image <<
"' !" << endl);
1702 if (vb>=3)
Cout(
"IntfWriteImgFile (3D image)" << endl);
1710 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile header for'"<< a_pathToImg <<
"' !" << endl);
1714 string path_to_image = a_pathToImg;
1715 path_to_image.append(
".img");
1720 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile image '"<< path_to_image <<
"' !" << endl);
1752 if (vb>=3)
Cout(
"IntfWriteProjFile ..." << endl);
1755 vector<string> lpath_to_images;
1756 lpath_to_images.push_back(a_pathToImg);
1760 Cerr(
"***** IntfWriteProjFile()-> Error : while trying to write the interfile header for'"<< lpath_to_images[0] <<
"' !" << endl);
1777 Cerr(
"***** IntfWriteFile()-> Error : while trying to write the interfile image '"<< a_pathToImg <<
"' !" << endl);
1811 if (vb>=3)
Cout(
"IntfWriteImgDynCoeffFile ..." << endl);
1823 vector<string> lpath_to_images;
1825 if(p_outputMgr->
MergeDynImages()==
true || a_mergeDynImgFlag==
true)
1827 lpath_to_images.push_back(a_pathToImg);
1828 lpath_to_images[0].append(
"_par");
1832 Cerr(
"***** IntfWriteImgDynCoeffFile()-> Error : while trying to write the interfile header for'"<< lpath_to_images[0] <<
"' !" << endl);
1840 for(
int bf=0 ; bf<a_nbParImgs ; bf++)
1843 lpath_to_images.push_back(a_pathToImg);
1846 stringstream ss; ss << bf + 1;
1847 lpath_to_images[idx_file].append(
"_par").append(ss.str());
1850 string path_to_hdr = lpath_to_images[idx_file] +
".hdr";
1851 string path_to_img = lpath_to_images[idx_file] +
".img";
1855 ifstream fcheck(path_to_hdr.c_str());
1860 string dos_instruction =
"del " + path_to_hdr;
1861 system(dos_instruction.c_str());
1863 remove(path_to_hdr.c_str());
1867 ofstream ofile(path_to_hdr.c_str(), ios::out | ios::app);
1868 ofile << setprecision(std::numeric_limits<FLTNB>::digits10 +1);
1869 ofile <<
"!INTERFILE := " << endl;
1870 ofile <<
"!name of data file := " <<
GetFileFromPath(path_to_img) << endl;
1872 ofile <<
"!data offset in bytes := " << 0 << endl;
1874 ofile <<
"!type of data := Dynamic" << endl;
1878 Cerr(
"***** IntfWriteImgDynCoeffFile()-> Error : while trying to write the interfile header for'"<< lpath_to_images[idx_file] <<
"' !" << endl);
1882 ofile <<
"!END OF INTERFILE := " << endl;
1890 string pathToDynCoeffMHD;
1891 pathToDynCoeffMHD=a_pathToImg.c_str();
1892 pathToDynCoeffMHD.append(
"_par");
1893 if(
IntfWriteMHD(pathToDynCoeffMHD, lpath_to_images, Img_fields, ap_ID, vb) )
1895 Cerr(
"***** IntfWriteImgDynCoeffFile()-> Error : while trying to write the interfile header '"<< a_pathToImg <<
"' !" << endl);
1904 dims[0] = a_nbParImgs;
1909 Cerr(
"***** IntfWriteImgDynCoeffFile()-> Error : while trying to write the interfile image '"<< a_pathToImg <<
"' !" << endl);
1940 if (vb>=3)
Cout(
"IntfWriteImgFile (static/dynamic image) ..." << endl);
1951 vector<string> lpath_to_images;
1955 lpath_to_images.push_back(a_pathToImg);
1959 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile header for'"<< lpath_to_images[0] <<
"' !" << endl);
1975 lpath_to_images.push_back(a_pathToImg);
1980 stringstream ss; ss << fr + 1;
1981 lpath_to_images[idx_file].append(
"_fr").append(ss.str());
1986 stringstream ss; ss << rg + 1;
1987 lpath_to_images[idx_file].append(
"_rg").append(ss.str());
1992 stringstream ss; ss << cg + 1;
1993 lpath_to_images[idx_file].append(
"_cg").append(ss.str());
1997 string path_to_hdr = lpath_to_images[idx_file];
1998 string path_to_img = lpath_to_images[idx_file];
2002 ifstream fcheck(path_to_hdr.append(
".hdr").c_str());
2007 string dos_instruction =
"del " + path_to_hdr;
2008 system(dos_instruction.c_str());
2010 remove(path_to_hdr.c_str());
2014 ofstream ofile(path_to_hdr.c_str(), ios::out | ios::app);
2015 ofile << setprecision(std::numeric_limits<FLTNB>::digits10 +1);
2016 ofile <<
"!INTERFILE := " << endl;
2019 ofile <<
"!name of data file := " <<
GetFileFromPath(path_to_img).append(
".img") << endl;
2021 ofile <<
"!data offset in bytes := " << 0 << endl;
2023 ofile <<
"!type of data := Dynamic" << endl;
2027 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile header for'"<< lpath_to_images[idx_file] <<
"' !" << endl);
2037 ofile <<
"!END OF INTERFILE := " << endl;
2042 Cerr(
"***** IntfWriteImgFile()-> Error: while copying input data header information into output interfile header '" << path_to_hdr <<
"' !" << endl);
2053 if(
IntfWriteMHD(a_pathToImg, lpath_to_images, Img_fields, ap_ID, vb) )
2055 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile header '"<< a_pathToImg <<
"' !" << endl);
2072 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile image '"<< a_pathToImg <<
"' !" << endl);
2090 if (vb>=3)
Cout(
"IntfWriteDynBasisCoefImgFile (dynamic basis coefficients image) ..." << endl);
2096 vector<string> lpath_to_images;
2107 lpath_to_images.push_back(a_pathToImg);
2111 stringstream ss; ss << tbf + 1;
2112 lpath_to_images[idx_file].append(
"_tbf").append(ss.str());
2117 stringstream ss; ss << rbf + 1;
2118 lpath_to_images[idx_file].append(
"_rbf").append(ss.str());
2123 stringstream ss; ss << cbf + 1;
2124 lpath_to_images[idx_file].append(
"_cbf").append(ss.str());
2127 string path_to_hdr = lpath_to_images[idx_file];
2128 string path_to_img = lpath_to_images[idx_file];
2131 ifstream fcheck(path_to_hdr.append(
".hdr").c_str());
2136 string dos_instruction =
"del " + path_to_hdr;
2137 system(dos_instruction.c_str());
2139 remove(path_to_hdr.c_str());
2143 ofstream ofile(path_to_hdr.c_str(), ios::out | ios::app);
2144 ofile << setprecision(std::numeric_limits<FLTNB>::digits10 +1);
2145 ofile <<
"!INTERFILE := " << endl;
2146 ofile <<
"!name of data file := " <<
GetFileFromPath(path_to_img).append(
".img") << endl;
2148 ofile <<
"!data offset in bytes := " << 0 << endl;
2150 ofile <<
"!type of data := Dynamic" << endl;
2153 Cerr(
"***** IntfWriteWholeDynBasisCoeffImgFile()-> Error : while trying to write the interfile header for'"<< lpath_to_images[idx_file] <<
"' !" << endl);
2157 ofile <<
"image duration (sec) := 1" << endl;
2158 ofile <<
"image start time (sec) := 0" << endl;
2159 ofile <<
"!END OF INTERFILE := " << endl;
2174 Cerr(
"***** IntfWriteWholeDynBasisCoeffImgFile()-> Error : while trying to write the interfile image '"<< a_pathToImg <<
"' !" << endl);
2260 int IntfIsMHD(
string a_pathToFile, vector<string> &ap_lPathToImgs)
2263 ifstream hfile(a_pathToFile.c_str(), ios::in);
2271 getline(hfile, line);
2274 if(line.empty())
continue;
2282 Cerr(
"***** IntfIsMHD()-> Error : couldn't correctly read interfile key '"<< line <<
"' !" << endl);
2294 uint16_t nb_datasets = 0;
2297 Cerr(
"***** IntfIsMHD()-> Error when trying to read data from 'total number of data set' key. Recovered value = " << Key.
kvalue << endl);
2305 string file_key =
"";
2306 string file_keyp =
"%";
2307 string file_key_space =
"";
2308 string file_keyp_space =
"%";
2309 file_key_space.append(
"data set [").append(ss.str()).append(
"]");
2310 file_keyp_space.append(
"data set [").append(ss.str()).append(
"]");
2311 file_key.append(
"data set[").append(ss.str()).append(
"]");
2312 file_keyp.append(
"data set[").append(ss.str()).append(
"]");
2319 getline(hfile, line);
2322 if(line.empty())
continue;
2327 Cerr(
"***** IntfIsMHD()-> Error : couldn't correctly read interfile key '"<< line <<
"' !" << endl);
2345 Cerr(
"***** IntfIsMHD()-> Error : when trying to read Interfile array key: '"<< line <<
"' !" << endl);
2348 else if(nb_elts != 3)
2350 Cerr(
"***** IntfIsMHD()-> Error : when trying to read Interfile array key: '"<< line <<
"' !" << endl);
2351 Cerr(
" 3 elements are expected following the format {xxx, path_to_the_img_file, xxx} (xxx = ignored data)" << endl);
2357 Cerr(
"***** IntfIsMHD()-> Error : when trying to read Interfile array key: '"<< line <<
"' !" << endl);
2360 ap_lPathToImgs.at(file_idx).append(elts_str[1]);
2363 ap_lPathToImgs.at(file_idx).append(Key.
kvalue);
2371 file_key.append(
"data set [").append(ss.str()).append(
"]");
2372 file_keyp.append(
"data set [").append(ss.str()).append(
"]");
2378 if(nb_datasets != ap_lPathToImgs.size())
2381 Cerr(
"***** IntfIsMHD()-> The number of recovered file in the metaheader ("<<ap_lPathToImgs.size()<<
")");
2382 Cerr(
"does not correspond to the expected number of datasets ("<<nb_datasets<<
")!"<< endl);
2393 Cerr(
"***** IntfIsMHD()-> Error : couldn't read header file '"<< a_pathToFile <<
"' !" << endl);
2399 ap_lPathToImgs.push_back(a_pathToFile);
2422 const vector<string>& ap_lPathToImgs,
2428 string path_to_mhd_file = a_pathToMhd;
2429 path_to_mhd_file.append(
".mhd");
2430 ofstream ofile(path_to_mhd_file.c_str(), ios::out);
2431 ofile << setprecision(std::numeric_limits<FLTNB>::digits10 +1);
2439 ofile <<
"!INTERFILE := " << endl;
2441 ofile << endl <<
"!GENERAL DATA := " << endl;
2442 ofile <<
"data description:=image" << endl;
2443 ofile <<
"!originating system := " << p_scanMgr->
GetScannerName() << endl;
2448 ofile <<
"number of bed positions := " << a_IntfF.
nb_bed_positions << endl;
2449 ofile <<
"!study duration (sec) := " << a_IntfF.
study_duration << endl;
2452 else ofile <<
"horizontal bed relative position (mm) := " << ap_ID->
GetBedPosition(0) << endl;
2454 ofile << endl <<
"%DATA MATRIX DESCRIPTION:=" << endl;
2455 ofile <<
"number of time frames := " << a_IntfF.
nb_time_frames << endl;
2456 ofile <<
"number of time windows := " << a_IntfF.
nb_resp_gates *
2458 ofile <<
"number of respiratory gates := " << a_IntfF.
nb_resp_gates << endl;
2459 ofile <<
"number of cardiac gates := " << a_IntfF.
nb_card_gates << endl;
2461 ofile << endl <<
"%DATA SET DESCRIPTION:="<< endl;
2464 ofile <<
"!total number of data sets:=" << nb_imgs << endl;
2467 if(ap_lPathToImgs.size() != nb_imgs)
2469 Cerr(
"***** IntfWriteMHD()-> Error : nb of provided string inconsistent with the expected number of dynamic images: '"<< nb_imgs <<
"' !" << endl);
2474 for(
int ds=0 ; ds<nb_imgs ; ds++)
2476 string path_to_header = ap_lPathToImgs.at(ds);
2477 ofile <<
"%data set ["<<ds+1<<
"]:={0," <<
GetFileFromPath(path_to_header).append(
".hdr") <<
",UNKNOWN}"<< endl;
2482 Cerr(
"***** IntfWriteMHD()-> Error : couldn't find output Metaheader interfile '"<< path_to_mhd_file <<
"' !" << endl);
2521 Cout(
"--------------------------------------------------------------- " << endl);
2522 Cout(
"IntfReadHeader()-> Start reading header interfile " << a_pathToHeaderFile << endl);
2523 Cout(
"--------------------------------------------------------------- " << endl);
2528 ifstream input_file(a_pathToHeaderFile.c_str(), ios::in);
2534 while(!input_file.eof())
2536 getline(input_file, line);
2548 Cerr(
"***** ReadIntfHeader()-> Error : couldn't correctly read interfile key '"<< line <<
"' !" << endl);
2552 if (vb >=10)
Cout(
"ReadIntfHeader()-> Key " << Key.
kcase << endl);
2571 if ( Key.
kvalue.size()>0 )
2583 string header_file_directory =
GetPathOfFile(a_pathToHeaderFile);
2589 Cerr(
"***** ReadIntfHeader()-> Error : path to interfile image file is empty !" << endl);
2604 if (endianness ==
"littleendian")
2618 Cerr(
"***** ReadIntfHeader()-> Warning : data_offset value was already set to " << ap_IF->
data_offset << endl);
2619 Cerr(
"***** The header may contain both 'data offset in bytes' and 'data starting block' fields " << endl);
2624 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'data starting block' key. Recovered value = " << Key.
kvalue << endl);
2639 Cerr(
"***** ReadIntfHeader()-> Warning : data_offset value was already set to " << ap_IF->
data_offset << endl);
2640 Cerr(
"***** The header may contain both 'data offset in bytes' and 'data starting block' fields " << endl);
2645 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'data offset in bytes' key. Recovered value = " << Key.
kvalue << endl);
2657 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number format' key. Recovered value = " << Key.
kvalue << endl);
2668 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'originating system' key. Recovered value = " << Key.
kvalue << endl);
2679 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'bed relative position (mm)' key. Recovered value = " << Key.
kvalue << endl);
2690 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [1]' key. Recovered value = " << Key.
kvalue << endl);
2701 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [2]' key. Recovered value = " << Key.
kvalue << endl);
2718 Cerr(
"***** ReadIntfHeader()-> Array reading for 'matrix size [3]' key not implemented yet. Single value expected." << endl);
2725 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [3]' key. Recovered value = " << Key.
kvalue << endl);
2747 Cerr(
"***** ReadIntfHeader()-> Array reading for 'matrix size [4]' key not implemented yet. Single value expected." << endl);
2756 Cerr(
"***** ReadIntfHeader()-> WARNING : both 'number of time frames' and 'matrix size [4]' keys have been provided");
2757 Cerr(
" 'number of time frames' selected by default" << endl);
2761 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [4]' key. Recovered value = " << Key.
kvalue << endl);
2780 Cerr(
"***** ReadIntfHeader()-> Array reading for 'matrix size [5]' key not implemented yet. Single value expected." << endl);
2787 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [5]' key. Recovered value = " << Key.
kvalue << endl);
2805 Cerr(
"***** ReadIntfHeader()-> Array reading for 'matrix size [6]' key not implemented yet. Single value expected." << endl);
2812 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [6]' key. Recovered value = " << Key.
kvalue << endl);
2830 Cerr(
"***** ReadIntfHeader()-> Array reading for 'matrix size [7]' key not implemented yet. Single value expected." << endl);
2837 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [7]' key. Recovered value = " << Key.
kvalue << endl);
2851 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'scaling factor (mm/pixel) [1]' key. Recovered value = " << Key.
kvalue << endl);
2863 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'scaling factor (mm/pixel) [2]' key. Recovered value = " << Key.
kvalue << endl);
2876 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'scaling factor (mm/pixel) [3]' key. Recovered value = " << Key.
kvalue << endl);
2890 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from one of the following key :" << endl);
2891 Cerr(
"***** 'first pixel offset (mm) [1]'" << Key.
kvalue << endl);
2892 Cerr(
"***** 'origin (mm) [1]'"<< endl);
2893 Cerr(
"***** 'offset [1]'" << Key.
kvalue << endl);
2894 Cerr(
"***** Recovered value = " << Key.
kvalue << endl);
2908 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from one of the following key :" << endl);
2909 Cerr(
"***** 'first pixel offset (mm) [2]'" << Key.
kvalue << endl);
2910 Cerr(
"***** 'origin (mm) [2]'"<< endl);
2911 Cerr(
"***** 'offset [2]'" << Key.
kvalue << endl);
2912 Cerr(
"***** Recovered value = " << Key.
kvalue << endl);
2926 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from one of the following key :" << endl);
2927 Cerr(
"***** 'first pixel offset (mm) [3]'" << Key.
kvalue << endl);
2928 Cerr(
"***** 'origin (mm) [3]'"<< endl);
2929 Cerr(
"***** 'offset [3]'" << Key.
kvalue << endl);
2930 Cerr(
"***** Recovered value = " << Key.
kvalue << endl);
2943 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'slice thickness (pixels)' key. Recovered value = " << Key.
kvalue << endl);
2955 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'centre-centre slice separation (pixels)' key.");
2956 Cerr(
" Recovered value = " << Key.
kvalue << endl);
2959 Cerr(
"***** ReadIntfHeader()-> WARNING : 'centre-centre slice separation (pixels)' has no use in the current implementation !"<< endl);
2970 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of time frames' or 'number of frame groups' keys.");
2971 Cerr(
"Recovered value = " << Key.
kvalue << endl);
2983 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of respiratory gates' key. Recovered value = " << Key.
kvalue << endl);
2995 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of cardiac gates' key. Recovered value = " << Key.
kvalue << endl);
3006 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'total number of images' key. Recovered value = " << Key.
kvalue << endl);
3017 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of bytes per pixel' key. Recovered value = " << Key.
kvalue << endl);
3027 string slice_orientation;
3030 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'slice orientation' key. Recovered value = " << Key.
kvalue << endl);
3034 if (slice_orientation ==
"transverse")
3036 else if (slice_orientation ==
"sagittal")
3038 else if (slice_orientation ==
"coronal")
3047 string pat_rotation;
3050 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'patient rotation' key. Recovered value = " << Key.
kvalue << endl);
3054 if (pat_rotation ==
"supine")
3056 else if (pat_rotation ==
"prone")
3066 string pat_orientation;
3069 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'patient orientation' key. Recovered value = " << Key.
kvalue << endl);
3073 if (pat_orientation ==
"head_in")
3075 else if (pat_orientation ==
"feet_in")
3088 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'rescale slope' or 'data rescale slope' key. Recovered value = " << Key.
kvalue << endl);
3095 Cerr(
"***** ReadIntfHeader()-> Error : field 'resclale slope' units should be >0!" << endl);
3120 Cerr(
"!!!!! ReadIntfHeader()-> WARNING : Error when trying to read numeric value from 'quantification units' key. Actual value = " << Key.
kvalue << endl);
3121 Cerr(
"!!!!! This key will be ignored" << endl);
3128 Cerr(
"***** ReadIntfHeader()-> Error : field 'quantification units' should be >0!" << endl);
3140 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'rescale intercept' or 'data rescale intercept' key. Recovered value = " << Key.
kvalue << endl);
3146 Cerr(
"***** ReadIntfHeader()-> Error : field 'resclale intercept' units should be >0!" << endl);
3160 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'type of data' key. Recovered value = " << Key.
kvalue << endl);
3174 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'study duration (sec)' key. Recovered value = " << Key.
kvalue << endl);
3188 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'study duration (sec)' key. Recovered value = " << Key.
kvalue << endl);
3204 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'study duration (sec)' key. Recovered value = " << Key.
kvalue << endl);
3217 FLTNB pause_duration;
3220 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'study duration (sec)' key. Recovered value = " << Key.
kvalue << endl);
3234 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of time windows ' key. Recovered value = " << Key.
kvalue << endl);
3247 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'process status' key. Recovered value = " << Key.
kvalue << endl);
3260 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of energy windows' key. Recovered value = " << Key.
kvalue << endl);
3273 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of detector heads' key. Recovered value = " << Key.
kvalue << endl);
3285 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of projections' key. Recovered value = " << Key.
kvalue << endl);
3297 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'extent of rotation' key. Recovered value = " << Key.
kvalue << endl);
3308 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'direction_rotation' key. Recovered value = " << Key.
kvalue << endl);
3321 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'start angle' key. Recovered value = " << Key.
kvalue << endl);
3333 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'projection_angles' key. Recovered value = " << Key.
kvalue << endl);
3345 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'Center of rotation to detector distance' key.");
3346 Cerr(
" Recovered value = " << Key.
kvalue << endl);
3358 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'Radius' key. Recovered value = " << Key.
kvalue << endl);
3368 Cerr(
"***** ReadIntfHeader()-> Error : compressed interfile images not handled by the current implementation !" << endl);
3378 Cerr(
"***** ReadIntfHeader()-> Error : encoded interfile images not handled by the current implementation !" << endl);
3390 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of slices' key. Recovered value = " << Key.
kvalue << endl);
3402 Cerr(
"***** ReadIntfHeader()-> Error : couldn't find or read header interfile '"<< a_pathToHeaderFile <<
"' !" << endl);
3432 Cerr(
"***** ReadIntfHeader()-> Error : nb of recovered frame duration ('"<< ap_IF->
image_duration.size()
3433 <<
") does not match the nb of recovered pauses between frames ('"<< ap_IF->
frame_group_pause.size() <<
") !" << endl);
3461 Cout(
"--------------------------------------------------------------- " << endl);
3462 Cout(
"IntfWriteHeaderMainData()-> Start writing header interfile " << a_path << endl);
3463 Cout(
"--------------------------------------------------------------- " << endl);
3466 string path_to_header, path_to_image;
3467 path_to_header = a_path;
3469 path_to_header.append(
".hdr");
3473 ofstream ofile(path_to_header.c_str(), ios::out);
3474 ofile << setprecision(std::numeric_limits<FLTNB>::digits10 +1);
3480 ofile <<
"!INTERFILE := " << endl;
3483 string imaging_modality;
3485 imaging_modality =
"PET";
3487 imaging_modality =
"SPECT";
3489 imaging_modality =
"CT";
3491 imaging_modality =
"UNKOWN";
3493 ofile <<
"!imaging modality := " << imaging_modality << endl;
3497 ofile <<
"!version of keys := " <<
"3.3" << endl;
3499 ofile <<
"!version of keys := " <<
"CASToRv" <<
CASTOR_VERSION << endl;
3503 ofile << endl <<
"!GENERAL DATA := " << endl;
3504 ofile <<
"!originating system := " << p_scanMgr->
GetScannerName() << endl;
3511 ofile <<
"!data offset in bytes := " << 0 << endl;
3512 ofile <<
"!name of data file := " << path_to_image << endl;
3518 ofile << endl <<
"!GENERAL IMAGE DATA " << endl;
3524 ofile <<
"!type of data := Dynamic" << endl;
3529 ofile <<
"!total number of images := " << nb_imgs << endl;
3537 ofile <<
"number of time frames := " << ap_IntfF.
nb_time_frames << endl;
3538 ofile <<
"!number of frame groups := " << ap_IntfF.
nb_time_frames << endl;
3541 ofile <<
"!number of frame groups :=1 " << endl;
3545 ofile <<
"number of time windows := " << ap_IntfF.
nb_resp_gates *
3548 ofile <<
"number of respiratory gates := " << ap_IntfF.
nb_resp_gates << endl;
3550 ofile <<
"number of cardiac gates := " << ap_IntfF.
nb_card_gates << endl;
3554 ofile <<
"!number of projections := " << ap_IntfF.
nb_projections << endl;
3555 ofile <<
"!extent of rotation := " << ap_IntfF.
extent_rotation << endl;
3557 ofile <<
"process status := " << ap_IntfF.
process_status << endl;
3561 ofile <<
"number of bed positions := " << ap_IntfF.
nb_bed_positions << endl;
3562 ofile <<
"!study duration (sec) := " << ap_IntfF.
study_duration << endl;
3566 ofile << endl <<
"!DYNAMIC STUDY (General) :=" << endl;
3570 ofile << endl <<
"!GSPECT STUDY (General) :=" << endl;
3573 ofile << endl <<
"!SPECT STUDY (General) :=" << endl;
3574 ofile << endl <<
"!SPECT STUDY ("<< ap_IntfF.
process_status <<
" data) :="<< endl;
3578 ofile << endl <<
"!GATED STUDY (General) :=" << endl;
3580 ofile << endl <<
"!STATIC STUDY (General) :=" << endl;
3593 ofile <<
"!number of frame groups :=" << ap_IntfF.
nb_time_frames << endl;
3600 ofile <<
"!Dynamic Study (each frame group) :=" << endl;
3601 ofile <<
"!frame group number := " << fr+1 << endl;
3609 ofile <<
"!Respiratory Gated Study (each time window) :=" << endl;
3610 ofile <<
"!time window number := " << rg+1 << endl;
3618 ofile <<
"!Cardiac Gated Study (each time window) :=" << endl;
3619 ofile <<
"!time window number := " << cg+1 << endl;
3625 Cerr(
"***** IntfWriteHeaderMainData()-> Error : while trying to write the interfile header '"<< path_to_header <<
"' !" << endl);
3630 ofile <<
"!number of images in this time window :=" 3636 ofile <<
"!number of images in this time window :=" 3644 ofile <<
"!number of images in this frame group := " 3649 ofile <<
"!image duration (sec) := " << ap_IntfF.
image_duration[fr] << endl;
3650 ofile <<
"!image start time (sec) := " << ap_IntfF.
image_start_time[fr] << endl;
3653 ofile <<
"pause between frame groups (sec) := " << 0.0 << endl;
3655 ofile <<
"pause between frame groups (sec) := " << ap_IntfF.
frame_group_pause[fr] << endl;
3660 ofile <<
"!END OF INTERFILE := " << endl;
3665 Cerr(
"***** IntfWriteHeaderMainData()-> Error: while copying input data header information into output interfile header '" << path_to_header <<
"' !" << endl);
3671 Cerr(
"***** IntfWriteHeaderMainData()-> Error : couldn't find output header interfile '"<< a_path <<
"' !" << endl);
3686 int return_value = 0;
3689 for (
size_t df=0; df<dfName.size(); df++)
3692 ifstream header(dfName[df].c_str());
3695 Cerr(
"***** IntfWriteContentOfInputDataHeaderIntoInterfileHeader() -> Input data header file '" << dfName[df] <<
"' is missing or corrupted !" << endl);
3700 ap_ofile << endl <<
"!COPY OF INPUT HEADER " << df+1 << endl;
3703 getline(header,line);
3704 while (!header.eof())
3706 ap_ofile << line << endl;
3707 getline(header,line);
3712 ap_ofile <<
"!END OF COPY OF INPUT HEADER " << df+1 << endl;
3715 return return_value;
3743 ap_ofile <<
"start angle := " << ap_IntfF.
first_angle << endl;
3747 if( ap_IntfF.
radius.find(
"{}") != string::npos )
3748 ap_ofile <<
"Center of rotation to detector distance := " << ap_IntfF.
radius << endl;
3750 ap_ofile <<
"Radius := " << ap_IntfF.
radius << endl;
3752 ap_ofile <<
"!matrix size [1] := " << ap_IntfF.
mtx_size[0] << endl;
3753 ap_ofile <<
"!matrix size [2] := " << ap_IntfF.
mtx_size[1] << endl;
3754 ap_ofile <<
"!number format := " << ap_IntfF.
nb_format << endl;
3755 ap_ofile <<
"!number of bytes per pixel := " <<
sizeof(
FLTNB) << endl;
3756 ap_ofile <<
"scaling factor (mm/pixel) [1] := " << ap_IntfF.
vox_size[0] << endl;
3757 ap_ofile <<
"scaling factor (mm/pixel) [2] := " << ap_IntfF.
vox_size[1] << endl;
3758 ap_ofile <<
"!data offset in bytes := " << 0 << endl;
3762 ap_ofile <<
"number of dimensions := " << 3 << endl;
3763 ap_ofile <<
"!matrix size [1] := " << ap_IntfF.
mtx_size[0] << endl;
3764 ap_ofile <<
"!matrix size [2] := " << ap_IntfF.
mtx_size[1] << endl;
3765 ap_ofile <<
"!matrix size [3] := " << ap_IntfF.
mtx_size[2] << endl;
3766 ap_ofile <<
"!number format := " << ap_IntfF.
nb_format << endl;
3767 ap_ofile <<
"!number of bytes per pixel := " <<
sizeof(
FLTNB) << endl;
3768 ap_ofile <<
"scaling factor (mm/pixel) [1] := " << ap_IntfF.
vox_size[0] << endl;
3769 ap_ofile <<
"scaling factor (mm/pixel) [2] := " << ap_IntfF.
vox_size[1] << endl;
3770 ap_ofile <<
"scaling factor (mm/pixel) [3] := " << ap_IntfF.
vox_size[2] << endl;
3771 ap_ofile <<
"first pixel offset (mm) [1] := " << ap_IntfF.
vox_offset[0] << endl;
3772 ap_ofile <<
"first pixel offset (mm) [2] := " << ap_IntfF.
vox_offset[1] << endl;
3773 ap_ofile <<
"first pixel offset (mm) [3] := " << ap_IntfF.
vox_offset[2] << endl;
3780 ap_ofile <<
"data rescale slope := " << ap_IntfF.
rescale_slope << endl;
3781 ap_ofile <<
"quantification units := " << ap_IntfF.
quant_units << endl;
3801 Cerr(
"***** IntfWriteHeaderImgData()-> Error : couldn't open provided interfile header file !" << endl);
3827 if(vb >= 5)
Cout(
"IntfWriteImage()*" << endl);
3829 ofstream img_file(a_pathToImg.c_str(), ios::binary | ios::out);
3836 Cerr(
"***** IntfWriteImage()-> Error occurred when writing the image file '"<< a_pathToImg <<
"' !" << endl);
3842 Cerr(
"***** IntfWriteImage()-> Error occurred while trying to write the image file '"<< a_pathToImg <<
"' !" << endl);
3868 if(vb >= 5)
Cout(
"IntfWriteImage()**" << endl);
3870 if(ap_pathToImgs.size() == 1)
3874 ifstream fcheck(ap_pathToImgs.at(0).append(
".img").c_str());
3879 string dos_instruction =
"del " + ap_pathToImgs.at(0);
3880 system(dos_instruction.c_str());
3882 remove(ap_pathToImgs.at(0).c_str());
3887 ofstream img_file(ap_pathToImgs.at(0).c_str(), ios::binary | ios::out | ios::app);
3892 for(uint32_t d1=0 ; d1<ap_dim[0] ; d1++)
3893 if(
IntfWriteData(&img_file, a2p_outImgMtx[d1], ap_dim[1], vb) )
3895 Cerr(
"***** IntfWriteImage()-> Error occurred when writing the image file '"<< ap_pathToImgs.at(d1) <<
"' !" << endl);
3901 Cerr(
"***** IntfWriteImage()-> Error occurred while trying to write the image file at the path: '"<< ap_pathToImgs.at(0) <<
"' !" << endl);
3907 if(ap_pathToImgs.size()!=ap_dim[0])
3909 Cerr(
"***** IntfWriteImage()-> Error : number of interfile images ("<< ap_pathToImgs.size() <<
") not consistent with the number of images to load (" << ap_dim[0] <<
") !" << endl);
3913 for(uint32_t d1=0 ; d1<ap_dim[0] ; d1++)
3915 ofstream img_file(ap_pathToImgs.at(d1).append(
".img").c_str(), ios::binary | ios::out);
3920 if(
IntfWriteData(&img_file, a2p_outImgMtx[d1], ap_dim[1], vb) )
3922 Cerr(
"***** IntfWriteImage()-> Error occurred when writing the image file '"<< ap_pathToImgs.at(d1) <<
"' !" << endl);
3928 Cerr(
"***** IntfWriteImage()-> Error occurred while trying to write the image file at the path: '"<< ap_pathToImgs.at(d1) <<
"' !" << endl);
3956 if(vb >= 5)
Cout(
"IntfWriteImage()" << endl);
3958 if(ap_pathToImgs.size() == 1)
3962 ifstream fcheck(ap_pathToImgs.at(0).append(
".img").c_str());
3967 string dos_instruction =
"del " + ap_pathToImgs.at(0);
3968 system(dos_instruction.c_str());
3970 remove(ap_pathToImgs.at(0).c_str());
3975 ofstream img_file(ap_pathToImgs.at(0).c_str(), ios::binary | ios::out | ios::app);
3980 for(uint32_t d1=0 ; d1<ap_dim[0] ; d1++)
3981 for(uint32_t d2=0 ; d2<ap_dim[1] ; d2++)
3982 for(uint32_t d3=0 ; d3<ap_dim[2] ; d3++)
3983 if(
IntfWriteData(&img_file, a4p_outImgMtx[d1][d2][d3], ap_dim[3], vb) )
3985 int idx_img = d1*ap_dim[1]*ap_dim[2] + d2*ap_dim[2] + d3;
3986 Cerr(
"***** IntfWriteImage()-> Error occurred when writing the image file '"<< ap_pathToImgs.at(idx_img) <<
"' !" << endl);
3992 Cerr(
"***** IntfWriteImage()-> Error occurred while trying to write the image file '"<< ap_pathToImgs.at(0) <<
"' !" << endl);
4000 if(ap_pathToImgs.size() != ap_dim[0]*ap_dim[1]*ap_dim[2])
4002 Cerr(
"***** IntfWriteImage()-> Error : number of interfile images (="<< ap_pathToImgs.size()
4003 <<
") not consistent with the number of images to load (=" 4004 << ap_dim[0]*ap_dim[1]*ap_dim[2] <<
") !" << endl);
4008 for(uint32_t d1=0 ; d1<ap_dim[0] ; d1++)
4009 for(uint32_t d2=0 ; d2<ap_dim[1] ; d2++)
4010 for(uint32_t d3=0 ; d3<ap_dim[2] ; d3++)
4012 int idx_img = d1*ap_dim[1]*ap_dim[2] + d2*ap_dim[2] + d3;
4013 ofstream img_file(ap_pathToImgs.at(idx_img).append(
".img").c_str(), ios::binary | ios::out);
4018 if(
IntfWriteData(&img_file, a4p_outImgMtx[d1][d2][d3], ap_dim[3], vb) )
4020 Cerr(
"***** IntfWriteImage()-> Error occurred when writing the image file '"<< ap_pathToImgs.at(idx_img) <<
"' !" << endl);
4026 Cerr(
"***** IntfWriteImage()-> Error occurred while trying to write the image file at the path: '"<< ap_pathToImgs.at(idx_img) <<
"' !" << endl);
4055 if(vb >= 5)
Cout(
"IntfWriteData() " << endl);
4059 if (ap_oFile->write(reinterpret_cast<char*>(ap_outImgMatrix), a_nbVox*
sizeof(
FLTNB)) )
4093 for(
int d=0 ; d<7 ; d++)
4095 for(
int d=0 ; d<3 ; d++)
4097 for(
int d=0 ; d<3 ; d++)
4114 for(
int d=0 ; d<3 ; d++)
4252 Cout(
"// ------ IntfKeyPrintFields ------ // " << endl << endl);
4257 Cout(
"nb_dims : " <<
unsigned(a_IF.
nb_dims) << endl);
4258 for(
int i=0 ; i<7 ; i++)
4259 Cout(
"mtx_size["<<i<<
"] : " << a_IF.
mtx_size[i] << endl);
4260 for(
int i=0 ; i<3 ; i++)
4262 for(
int i=0 ; i<3 ; i++)
4263 Cout(
"vox_size["<<i<<
"] : " << a_IF.
vox_size[i] << endl);
4278 for(
int i=0 ; i<3 ; i++)
4280 for(
int i=0 ; i<3 ; i++)
4282 for(
int i=0 ; i<3 ; i++)
4288 Cout(
"image_duration(fr) : " << endl);
4291 Cout(
"image_start_time(fr) : " << endl);
4294 Cout(
"pause_duration(fr) : " << endl);
4311 Cout(
"// ------ ------------------ ------ // " << endl << endl);
4335 string intf_sep =
":=";
4338 int pos = a_line.find_first_of(
';',0);
4339 ap_Key->
korig = a_line.substr(0, pos);
4342 pos = ap_Key->
korig.find_first_of(intf_sep);
4345 if (ap_Key->
korig.find(intf_sep) == string::npos)
4346 ap_Key->
korig.append(
":=");
4395 string a_copy_of_the_key = ap_Key.
klcase;
4396 string a_copy_of_the_field = a_field;
4397 size_t found_char_at_pos = string::npos;
4399 while ( (found_char_at_pos=a_copy_of_the_key.find_first_of(
" \t\r\n")) != string::npos) a_copy_of_the_key.replace(found_char_at_pos,1,
"");
4401 while ( (found_char_at_pos=a_copy_of_the_field.find_first_of(
" \t\r\n")) != string::npos) a_copy_of_the_field.replace(found_char_at_pos,1,
"");
4405 if (a_copy_of_the_key==a_copy_of_the_field)
return 1;
4425 if(ap_Key.
kvalue.find(
"{") != string::npos &&
4426 ap_Key.
kvalue.find(
"}") != string::npos)
4448 string val_str = a_Key.
kvalue;
4450 size_t pos = val_str.find_first_of(
'{')+1;
4452 while (pos < val_str.length())
4454 size_t pos_c = val_str.find_first_of(
",", pos);
4457 if(pos_c == string::npos)
4459 pos_c = val_str.find_first_of(
"}", pos);
4462 Cerr(
"***** IntfKeyGetArrayNbElts-> Error : closing bracket not found in interfile array key : "<< a_Key.
korig <<
" !" << endl);
4473 Cerr(
"***** IntfKeyGetArrayNbElts-> Error : closing bracket not found in interfile array key : "<< a_Key.
korig <<
" !" << endl);
4493 string val_str = ap_Key.
kvalue;
4494 if (val_str ==
"")
return(max);
4496 size_t pos = val_str.find_first_of(
'{')+1;
4498 while (pos < val_str.length())
4500 size_t pos_c = val_str.find_first_of(
",", pos);
4503 if(pos_c == string::npos) pos_c = val_str.find_first_of(
"}", pos);
4507 Cerr(
"***** IntfKeyGetMaxArrayKey()-> An error occurred when trying to recover the following value from the array key : "<< val_str.substr(pos,pos_c-pos) <<
" !" << endl);
4511 if (value > max) max = value;
4537 string val_str = a_Key.
kvalue;
4542 Cerr(
"***** IntfKeyGetArrayElts-> Error : Problem reading the following interfile array key : "<< a_Key.
korig <<
" !" << endl);
4548 Cerr(
"***** IntfKeyGetArrayElts-> Error : no elements in the array key : "<< a_Key.
korig <<
" !" << endl);
4552 size_t pos = val_str.find_first_of(
'{')+1;
4556 while (pos < val_str.length())
4558 size_t pos_c = val_str.find_first_of(
",", pos);
4561 if(pos_c == string::npos) pos_c = val_str.find_first_of(
"}", pos);
4565 Cerr(
"***** IntfKeyGetMaxArrayKey()-> An error occurred when trying to recover the following value from the array key : "<< val_str.substr(pos,pos_c-pos) <<
" !" << endl);
4595 int dimXY=dimX*dimY;
4598 int z = a_voxId/dimXY;
4599 int y = (a_voxId - z*dimXY) / dimX;
4600 int x = a_voxId - z*dimXY - y*dimX;
4703 a_voxId = X + Y*dimX + Z*dimX*dimY;
4724 if(a_val == 0)
return "BIGENDIAN";
4725 if(a_val == 1)
return "LITTLEENDIAN";
4740 if(a_modalityIdx == 0)
4742 else if(a_modalityIdx == 1)
4769 if (a_str ==
"static")
4771 if (a_str ==
"dynamic")
4773 if (a_str ==
"gated")
4775 if (a_str ==
"tomographic")
4777 if (a_str ==
"gspect")
4837 if (
sizeof(
FLTNB) == 4)
return "short float";
4838 else if (
sizeof(
FLTNB) == 8)
return "long float";
4839 else if (
sizeof(
FLTNB) == 16)
return "long long float";
4842 Cerr(
"***** oInterfileIO::IntfKeyGetPixTypeStr() -> Size of current float type (" <<
sizeof(
FLTNB) <<
") does not correspond to a known type !" << endl);
4959 input_str->erase(0, input_str->find_first_not_of(
" !\t\r\n"));
4960 input_str->erase(input_str->find_last_not_of(
" \t\r\n")+1 , input_str->length());
4978 std::transform(ap_str->begin(), ap_str->end(), ap_str->begin(), ::tolower);
4995 string patient_tag_str =
"";
5000 if(dfName.size() > 1)
5002 patient_tag_str +=
"{ " + dfName[0];
5003 for(
size_t n=1 ; n<dfName.size() ; n++ )
5004 patient_tag_str +=
", " + dfName[n];
5005 patient_tag_str +=
"} ";
5007 else if (dfName.size() == 1)
5008 patient_tag_str += dfName[0];
5010 patient_tag_str +=
"unknown data";
5012 return patient_tag_str;
5030 char *buffer =
reinterpret_cast<char*
>(ap_type);
5031 std::reverse(buffer, buffer +
sizeof(T));
template int IntfKeyGetRecurringValueFromFile< uint8_t >(const string &a_pathToHeader, const string &a_key, uint8_t *ap_return, int a_nbElts, int a_mandatoryFlag, uint16_t a_nbOccurrences)
int IntfGetPixelTypeAndReadData(Intf_fields a_IF, ifstream *ap_iFile, FLTNB *ap_outImgMatrix, FLTNB *ap_inImgMatrix, uint32_t *ap_offset, int64_t a_nbVox, int a_verbose)
The purpose of this function is to call the templated ReadData() function with the data type correspo...
void GetUserEndianness()
Check user/host computer endianness and write it to the global variable User_Endianness.
template int IntfKeyGetRecurringValueFromFile< long double >(const string &a_pathToHeader, const string &a_key, long double *ap_return, int a_nbElts, int a_mandatoryFlag, uint16_t a_nbOccurrences)
template int IntfKeyGetRecurringValueFromFile< uint16_t >(const string &a_pathToHeader, const string &a_key, uint16_t *ap_return, int a_nbElts, int a_mandatoryFlag, uint16_t a_nbOccurrences)
#define INTF_SUPINE_FEETIN_CORONAL
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...
template int IntfKeyGetValueFromFile< int >(const string &a_pathToHeader, const string &a_key, int *ap_return, int a_nbElts, int a_mandatoryFlag)
static sScannerManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
template int IntfKeyGetValueFromFile< double >(const string &a_pathToHeader, const string &a_key, double *ap_return, int a_nbElts, int a_mandatoryFlag)
string direction_rotation
template int IntfKeyGetRecurringValueFromFile< uint32_t >(const string &a_pathToHeader, const string &a_key, uint32_t *ap_return, int a_nbElts, int a_mandatoryFlag, uint16_t a_nbOccurrences)
string GetPathOfFile(const string &a_pathToFile)
Simply return the path to the directory of a file path string passed in parameter.
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...
int GetNbCardBasisFunctions()
Get the number of cardiac basis functions.
FLTNB GetFrameDurationInSec(int a_bed, int a_frame)
FLTNB GetBedPosition(int a_bedIndex)
#define INTF_PRONE_HEADIN_CORONAL
template int IntfKeyGetValueFromFile< uint8_t >(const string &a_pathToHeader, const string &a_key, uint8_t *ap_return, int a_nbElts, int a_mandatoryFlag)
FLTNB GetVoxSizeX()
Get the voxel's size along the X axis, in mm.
void IntfEraseSpaces(string *input_str)
Erase space, blank characters ((t,r,n)), and '!' before and after the characters in the string passed...
FLTNB GetVoxSizeZ()
Get the voxel's size along the Z axis, in mm.
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...
#define INTF_PRONE_FEETIN_TRANSAXIAL
int IntfWriteHeaderMainData(const string &a_path, const Intf_fields &ap_IntfF, int vb)
#define INTF_PRONE_FEETIN_CORONAL
string IntfKeyGetEndianStr(int a_val)
return the endian string corresponding to the value passed in parameter (see module INTF_ENDIANNESS)...
int IntfReadImage(const string &a_pathToHeaderFile, FLTNB *ap_ImgMatrix, oImageDimensionsAndQuantification *ap_ID, int a_verbose, bool a_lerpFlag)
Main function dedicated to Interfile 3D image loading.
void IntfAllocInterpImg(FLTNB **a2p_img, Intf_fields a_IF)
Allocate memory for an image matrix to recover an image to interpolate.
#define INTF_SUPINE_FEETIN_SAGITTAL
#define INTF_PRONE_FEETIN_SAGITTAL
FLTNB bed_relative_position
int GetNbTimeBasisFunctions()
Get the number of time basis functions.
template int IntfKeyGetValueFromFile< string >(const string &a_pathToHeader, const string &a_key, string *ap_return, int a_nbElts, int a_mandatoryFlag)
bool FLTNBIsEqual(FLTNB a, FLTNB b, FLTNB a_eps)
Comparison of FLTNB numbers.
static sOutputManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
template int IntfKeyGetRecurringValueFromFile< float >(const string &a_pathToHeader, const string &a_key, float *ap_return, int a_nbElts, int a_mandatoryFlag, uint16_t a_nbOccurrences)
FLTNB GetFrameTimeStartInSec(int a_bed, int a_frame)
void SwapBytes(T *ap_type)
vector< FLTNB > frame_group_pause
FLTNB GetFinalTimeStopInSec(int a_bed)
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...
int IntfKeyGetOutputImgDataType(oImageDimensionsAndQuantification *ap_ID)
int IntfWriteImageFromIntfFields(const string &a_pathToImg, FLTNB *ap_ImgMatrix, Intf_fields Img_fields, int vb)
#define KEYWORD_MANDATORY_NOT_FOUND
bool GetProvidedBedPositionFlag()
Say if the bed relative position was provided from the datafile or not.
void IntfKeySetFieldsOutput(Intf_fields *ap_IF, oImageDimensionsAndQuantification *ap_ID)
Init the keys of the Interfile header of an image to be written on disk.
vector< FLTNB > image_start_time
int IntfCheckKeyMatch(Intf_key ap_Key, const string &a_field)
Check if the key matches the string passed in parameter.
FLTNB GetFrameTimeStopInSec(int a_bed, int a_frame)
#define INTF_SUPINE_HEADIN_SAGITTAL
FLTNB GetVoxSizeY()
Get the voxel's size along the Y axis, in mm.
int IntfReadAdditionalData(const string &a_pathToHeaderFile, FLTNB *ap_DataMatrix, int64_t a_matrixSize, int a_verbose)
Main function dedicated to Interfile 3D additional data loading.
int IntfWriteImgDynCoeffFile(const string &a_pathToImg, FLTNB **a2p_ImgMatrix, oImageDimensionsAndQuantification *ap_ID, int a_nbParImgs, int vb, bool a_mergeDynImgFlag)
#define SCANNER_SPECT_CONVERGENT
template int IntfKeyGetRecurringValueFromFile< bool >(const string &a_pathToHeader, const string &a_key, bool *ap_return, int a_nbElts, int a_mandatoryFlag, uint16_t a_nbOccurrences)
template int IntfKeyGetValueFromFile< bool >(const string &a_pathToHeader, const string &a_key, bool *ap_return, int a_nbElts, int a_mandatoryFlag)
template int IntfKeyGetValueFromFile< long double >(const string &a_pathToHeader, const string &a_key, long double *ap_return, int a_nbElts, int a_mandatoryFlag)
int IntfReadImgDynCoeffFile(const string &a_pathToHeaderFile, FLTNB **a2p_ImgMatrix, oImageDimensionsAndQuantification *ap_ID, int a_nbFbasis, int a_verbose, bool a_lerpFlag)
Function dedicated to Interfile image reading for dynamic coefficients images.
template int IntfKeyGetValueFromFile< int64_t >(const string &a_pathToHeader, const string &a_key, int64_t *ap_return, int a_nbElts, int a_mandatoryFlag)
int IntfGetVoxIdxSHTOrientation(Intf_fields a_IF, int a_voxId)
Compute a voxel index corresponding to the default orientation (Sup/Hin/Trans) from the orientation...
Singleton class that manages output writing on disk (images, sinograms, etc). It also manages loggi...
template int IntfKeyGetValueFromFile< uint16_t >(const string &a_pathToHeader, const string &a_key, uint16_t *ap_return, int a_nbElts, int a_mandatoryFlag)
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...
int IntfWriteContentOfInputDataHeaderIntoInterfileHeader(ofstream &ap_ofile, int vb)
FLTNB * IntfLoadImageFromScratch(const string &a_pathToHeaderFile, Intf_fields *ap_ImgFields, int vb)
int GetNbBeds()
Get the number of bed positions.
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], const FLTNB ap_iOffVox[3], const FLTNB ap_oOffVox[3])
Singleton class that Instantiate and initialize the scanner object.
int IntfKeyGetArrayNbElts(Intf_key a_Key)
Return the number of elts in an Interfile array Key.
void IntfToLowerCase(string *ap_str)
Set all characters of the string passed in parameter to lower case.
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.
#define INTF_SUPINE_HEADIN_TRANSAXIAL
template int IntfKeyGetValueFromFile< float >(const string &a_pathToHeader, const string &a_key, float *ap_return, int a_nbElts, int a_mandatoryFlag)
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...
template int IntfKeyGetRecurringValueFromFile< int >(const string &a_pathToHeader, const string &a_key, int *ap_return, int a_nbElts, int a_mandatoryFlag, uint16_t a_nbOccurrences)
int IntfReadData(Intf_fields a_IF, ifstream *ap_iFile, FLTNB *ap_outImgMatrix, FLTNB *ap_inImgMatrix, uint32_t *a_offset, int64_t a_nbVox, int a_verbose, T *bytes)
Templated function which read an image voxel by voxel and store it in the ap_outImgMtx image matrix...
#define INTF_SUPINE_HEADIN_CORONAL
bool bed_position_provided
int IntfWriteWholeDynBasisCoeffImgFile(const string &a_pathToImg, FLTNB ****a4p_ImgMatrix, oImageDimensionsAndQuantification *ap_ID, int vb)
Main function dedicated to Interfile 6D (dynamic dims + 3D ) image writing of basis function coeffici...
string IntfKeyGetPatientNameTag()
Recover datafile name(s) stored in sOutputManager in one string.
FLTNB GetOffsetY()
Get the image offset along the Y axis, in mm.
Interfile key elements. This structure is used to recover and process the elements of an Interfile ...
#define SCANNER_SPECT_PINHOLE
uint16_t ctr_to_ctr_separation
template int IntfKeyGetRecurringValueFromFile< string >(const string &a_pathToHeader, const string &a_key, string *ap_return, int a_nbElts, int a_mandatoryFlag, uint16_t a_nbOccurrences)
int IntfCheckDimensionsConsistency(Intf_fields ImgFields1, Intf_fields ImgFields2)
int IntfKeyGetRecurringValueFromFile(const string &a_pathToHeader, const string &a_key, T *ap_return, int a_nbElts, int a_mandatoryFlag, uint16_t a_nbOccurrences)
int GetNbCardGates()
Get the number of cardiac gates.
#define KEYWORD_OPTIONAL_NOT_FOUND
bool MergeDynImages()
Indicate if a dynamic serie of 3D images should be merged in one file (true) or written on disk as on...
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...
template int IntfKeyGetRecurringValueFromFile< double >(const string &a_pathToHeader, const string &a_key, double *ap_return, int a_nbElts, int a_mandatoryFlag, uint16_t a_nbOccurrences)
Interfile fields. This structure contains all the Interfile keys currently managed by CASToR Decl...
FLTNB GetOffsetZ()
Get the image offset along the Z axis, in mm.
int IntfKeyGetMaxArrayKey(Intf_key ap_Key)
Return the maximum value from an array key (key value contains brackets '{,,}' )
string IntfKeyGetPixTypeStr()
Return the string corresponding to the nb of bytes in the type FLTNB.
vector< string > GetDataFileName()
uint16_t nb_detector_heads
int GetNbTimeFrames()
Get the number of time frames.
int ConvertFromString(const string &a_str, string *a_result)
Copy the 'a_str' string in the position pointed by 'a_result'.
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...
INTNB GetNbVoxXYZ()
Get the total number of voxels.
#define INTF_SUPINE_FEETIN_TRANSAXIAL
vector< FLTNB > image_duration
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...
template int IntfKeyGetValueFromFile< uint32_t >(const string &a_pathToHeader, const string &a_key, uint32_t *ap_return, int a_nbElts, int a_mandatoryFlag)
int IntfKeyIsArray(Intf_key ap_Key)
Check if the key passed in parameter is an array (contains brackets '{' and '}' ) ...
#define INTF_PRONE_HEADIN_SAGITTAL
This class is designed to manage all dimensions and quantification related stuff. ...
int IntfReadHeader(const string &a_pathToHeaderFile, Intf_fields *ap_IF, int vb)
Read an Interfile header.
FLTNB GetOffsetX()
Get the image offset along the X axis, in mm.
INTNB GetNbVoxX()
Get the number of voxels along the X axis.
INTNB GetNbVoxZ()
Get the number of voxels along the Z axis.
template int IntfKeyGetRecurringValueFromFile< int64_t >(const string &a_pathToHeader, const string &a_key, int64_t *ap_return, int a_nbElts, int a_mandatoryFlag, uint16_t a_nbOccurrences)
string IntfKeyGetModalityStr(int a_modalityIdx)
Convert the integer provided in parameter to the string related to the corresponding modality as de...
int GetNbRespGates()
Get the number of respiratory gates.
uint32_t nb_energy_windows
int IntfKeyGetPatOrientation(Intf_fields ap_IF)
Get the complete patient orientation from an Intf_fields structure according to the values of keys 's...
string GetFileFromPath(const string &a_pathToFile)
Simply return the file from a path string passed in parameter.
void IntfKeyInitFields(Intf_fields *ap_IF)
Init the file of an Interfile fields structure passed in parameter to their default values...
int IntfKeyGetInputImgDataType(const string &a_str)
Get the image data type corresponding to the image metadata passed in parameter.
#define INTF_PRONE_HEADIN_TRANSAXIAL
int GetNbRespBasisFunctions()
Get the number of respiratory basis functions.
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 IntfWriteHeaderImgData(ofstream &ap_ofile, const Intf_fields &ap_IntfF, int vb)
INTNB GetNbVoxY()
Get the number of voxels along the Y axis.
bool is_mtx_size_different
string originating_system
int IntfIsMHD(string a_pathToFile, vector< string > &ap_lPathToImgs)
Check if the string in argument contains the path to a Interfile metaheader.