69 ifstream input_file(a_pathToHeader.c_str(), ios::in);
75 while(!input_file.eof())
77 getline(input_file, line);
87 Cerr(
"***** IntfKeyGetValueFromFile()-> Error : couldn't correctly read interfile key '"<< line <<
"' !" << endl);
98 Cerr(
"***** IntfKeyGetValueFromFile()-> Exception when trying to read tag '" << a_key <<
"' in file '" << a_pathToHeader <<
"'." << endl);
109 Cerr(
"***** IntfKeyGetValueFromFile() -> " << a_nbElts <<
" requested for interfile key " << a_key <<
" , but this key is not an array !" << endl);
117 Cerr(
"***** IntfKeyGetValueFromFile() -> Nb of elements to recover (=" << a_nbElts <<
") does not correspond to the number of elements found in the key '"
125 Cerr(
"***** IntfKeyGetValueFromFile() -> " << a_nbElts <<
" requested for interfile key " << a_key <<
" , but this key is not an array !" << endl);
136 if (a_mandatoryFlag > 0)
138 Cerr(
"***** IntfKeyGetValueFromFile()-> Error when reading Interfile '" << a_pathToHeader <<
"'. Key '" << a_key <<
"' was not found." << endl);
149 Cerr(
"***** IntfKeyGetValueFromFile()-> Couldn't find or read data-file '"<< a_pathToHeader <<
"' !" << endl);
156 template int IntfKeyGetValueFromFile<int>(
const string& a_pathToHeader,
const string& a_key,
int* ap_return,
int a_nbElts,
int a_mandatoryFlag);
158 template int IntfKeyGetValueFromFile<float>(
const string& a_pathToHeader,
const string& a_key,
float* ap_return,
int a_nbElts,
int a_mandatoryFlag);
164 template int IntfKeyGetValueFromFile<bool>(
const string& a_pathToHeader,
const string& a_key,
bool* ap_return,
int a_nbElts,
int a_mandatoryFlag);
186 uint16_t a_nbOccurrences)
188 ifstream input_file(a_pathToHeader.c_str(), ios::in);
190 uint16_t nb_occurences_cur =0;
195 while(!input_file.eof())
197 getline(input_file, line);
207 Cerr(
"***** IntfKeyGetValueFromFile()-> Error : couldn't correctly read interfile key '"<< line <<
"' !" << endl);
218 if(nb_occurences_cur < a_nbOccurrences)
228 Cerr(
"***** IntfKeyGetValueFromFile()-> Exception when trying to read tag '" << a_key <<
"' in file '" << a_pathToHeader <<
"'." << endl);
239 Cerr(
"***** IntfKeyGetValueFromFile() -> " << a_nbElts <<
" requested for interfile key " << a_key <<
" , but this key is not an array !" << endl);
247 Cerr(
"***** IntfKeyGetValueFromFile() -> Nb of elements to recover (=" << a_nbElts <<
") does not correspond to the number of elements found in the key '"
255 Cerr(
"***** IntfKeyGetValueFromFile() -> " << a_nbElts <<
" requested for interfile key " << a_key <<
" , but this key is not an array !" << endl);
266 if (a_mandatoryFlag > 0)
268 Cerr(
"***** IntfKeyGetValueFromFile()-> Error when reading Interfile '" << a_pathToHeader <<
"'. Key '" << a_key <<
"' was not found." << endl);
279 Cerr(
"***** IntfKeyGetValueFromFile()-> Couldn't find or read data-file '"<< a_pathToHeader <<
"' !" << endl);
310 if(vb >= 3)
Cout(
"IntfReadProjectionImage()-> Read Interfile header : "<< a_pathToHeaderFile << endl);
318 Cerr(
"***** IntfReadProjectionImage()-> Error : while trying to read the interfile header '"<< a_pathToHeaderFile <<
"' !" << endl);
325 int nb_tot_pixels = ap_IF->
mtx_size[0]
330 ifstream img_file(ap_IF->
path_to_image.c_str(), ios::binary | ios::in);
341 Cerr(
"***** IntfReadProjectionImage()-> Error occurred while trying to read the image file at the path: '"<< ap_IF->
path_to_image <<
"' !" << endl);
366 Cerr(
"***** IntfCheckDimensionsConsistency() -> Numbers of dimensions are not the same !" << endl);
370 for (
int dim=0; dim<((int)ImgFields1.
nb_dims); dim++)
375 Cerr(
"***** IntfCheckDimensionsConsistency() -> The sizes of the dimension " << dim+1 <<
" are not the same !" << endl);
380 for (
int dim=0; dim<std::min(3,((
int)ImgFields1.
nb_dims)); dim++)
385 Cerr(
"***** IntfCheckDimensionsConsistency() -> Voxel sizes of dimension " << dim+1 <<
" are not the same !" << endl);
392 Cerr(
"***** IntfCheckDimensionsConsistency() -> Slice thicknesses are not the same !" << endl);
408 if (vb>=2)
Cout(
"IntfLoadImageFromScratch() -> Read Interfile image '" << a_pathToHeaderFile <<
"'" << endl);
416 Cerr(
"***** IntfLoadImageFromScratch() -> A problem occured while trying to read the interfile header '" << a_pathToHeaderFile <<
"' !" << endl);
423 Cerr(
"***** IntfLoadImageFromScratch() -> Cannot handle a number of dimensions higher than 3 !" << endl);
428 for (
int d=0; d<ap_ImgFields->
nb_dims; d++)
if (ap_ImgFields->
mtx_size[d]==0)
430 Cerr(
"***** IntfLoadImageFromScratch() -> Number of voxels for dimension #" << d <<
" is 0, so has not been read correctly in header file '" << a_pathToHeaderFile <<
"' !" << endl);
434 for (
int d=0; d<ap_ImgFields->
nb_dims; d++)
if (ap_ImgFields->
vox_size[d]<=0.)
436 Cerr(
"***** IntfLoadImageFromScratch() -> Voxel size for dimension #" << d <<
" is negative, so has not been read correctly in header file '" << a_pathToHeaderFile <<
"' !" << endl);
447 ifstream img_file(ap_ImgFields->
path_to_image.c_str(), ios::binary | ios::in);
450 Cerr(
"***** IntfLoadImageFromScratch() -> Input image file '" << ap_ImgFields->
path_to_image <<
"' is missing or corrupted !" << endl);
471 if (vb>=2)
Cout(
"IntfWriteImageFromIntfFields() -> Write 3D image with output base name '" << a_pathToImg <<
"'" << endl);
476 Cerr(
"***** IntfWriteImageFromIntfFields() -> Error : while trying to write the interfile header '"<< a_pathToImg <<
"' !" << endl);
481 string path_to_image = a_pathToImg;
482 path_to_image.append(
".img");
490 Cerr(
"***** IntfWriteImageFromIntfFields() -> Error : while trying to write the interfile image '"<< path_to_image <<
"' !" << endl);
510 if (a_verbose>=
VERBOSE_DETAIL)
Cout(
"oInterfileIO::IntfReadImage() -> Read image from interfile header '" << a_pathToHeaderFile <<
"'" << endl);
519 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occured while trying to read the interfile header '" << a_pathToHeaderFile <<
"' !" << endl);
526 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occured while checking consistencies between reconstruction parameters and interfile keys from header '"
527 << a_pathToHeaderFile <<
"' !" << endl);
532 FLTNB* pimg_erp = NULL;
536 ifstream img_file(Img_fields.
path_to_image.c_str(), ios::binary | ios::in);
544 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occured while reading data and eventually interpolating from the IntfGetPixelTypeAndReadData() function !" << endl);
550 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while trying to open the image file '" << Img_fields.
path_to_image <<
"' !" << endl);
552 if (pimg_erp)
delete[] pimg_erp;
557 if (pimg_erp)
delete[] pimg_erp;
568 FLTNB**** a4p_ImgMatrix,
573 if (a_verbose >= 5)
Cout(
"oInterfileIO::IntfReadImage() -> Read image from interfile header '" << a_pathToHeaderFile <<
"'" << endl);
580 vector<string> lpath_to_headers;
584 if (
IntfIsMHD(a_pathToHeaderFile, lpath_to_headers) < 0 )
586 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occured while trying to read the interfile header '" << a_pathToHeaderFile <<
"' in IntfIsMHD() function !" << endl);
591 if (lpath_to_headers.size() == 1)
596 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occured while trying to read the interfile header '" << a_pathToHeaderFile <<
"' !" << endl);
602 Cerr(
"***** oInterfileIO::IntfReadImage() -> A error occured while checking consistencies between reconstruction parameters and interfile keys in the header '" << a_pathToHeaderFile <<
"' !" << endl);
606 FLTNB* pimg_erp = NULL;
609 ifstream img_file(Img_fields.
path_to_image.c_str(), ios::binary | ios::in);
623 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occured while reading data and eventually interpolating from the IntfGetPixelTypeAndReadData() function !" << endl);
625 if (pimg_erp)
delete[] pimg_erp;
632 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while trying to read the image file '"<< Img_fields.
path_to_image <<
"' !" << endl);
634 if (pimg_erp)
delete[] pimg_erp;
638 if (pimg_erp)
delete[] pimg_erp;
647 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occured while trying to read the interfile metaheader '" << a_pathToHeaderFile <<
"' !" << endl);
656 if (lpath_to_headers.size() != (uint32_t)(dims[0]*dims[1]*dims[2]))
658 Cerr(
"***** oInterfileIO::IntfReadImage() -> Number of interfile images (" << lpath_to_headers.size() <<
659 ") not consistent with the number of images to load (" << dims[0]*dims[1]*dims[2]<<
") !" << endl);
663 FLTNB* pimg_erp = NULL;
666 for(
int d1=0 ; d1<dims[0] ; d1++)
667 for(
int d2=0 ; d2<dims[1] ; d2++)
668 for(
int d3=0 ; d3<dims[2] ; d3++)
670 int idx_img = d1*dims[1]*dims[2] + d2*dims[2] + d3;
674 if (
IntfReadHeader(lpath_to_headers[idx_img], &Img_fields, a_verbose) )
676 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occured while trying to read the interfile header '" << lpath_to_headers[idx_img] <<
"' !" << endl);
682 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occured while checking consistencies between reconstruction parameters and interfile keys in the header '"
683 << lpath_to_headers[idx_img] <<
"' !" << endl);
687 ifstream img_file(Img_fields.
path_to_image.c_str(), ios::binary | ios::in);
695 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occured while reading data and eventually interpolating from the IntfGetPixelTypeAndReadData() function !" << endl);
697 if (pimg_erp)
delete[] pimg_erp;
703 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while trying to read the image file '"<< Img_fields.
path_to_image <<
"' !" << endl);
705 if (pimg_erp)
delete[] pimg_erp;
710 if (pimg_erp)
delete[] pimg_erp;
733 FLTNB** a2p_ImgMatrix,
739 if (a_verbose >= 5)
Cout(
"IntfReadImgDynCoeffFile" << endl);
746 vector<string> lpath_to_headers;
750 if(
IntfIsMHD(a_pathToHeaderFile, lpath_to_headers) <0)
752 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> an error occured while trying to read the interfile header '" << a_pathToHeaderFile <<
"' !" << endl);
757 if(lpath_to_headers.size() == 1)
762 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occured while trying to read the interfile header '" << a_pathToHeaderFile <<
"' !" << endl);
768 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occured while checking consistencies between reconstruction parameters and interfile keys in the header '" << a_pathToHeaderFile <<
"' !" << endl);
772 FLTNB* pimg_erp = NULL;
775 ifstream img_file(Img_fields.
path_to_image.c_str(), ios::binary | ios::in);
782 for (
int bf=0 ; bf<a_nbFbasis ; bf++)
786 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occured while reading from file stream and eventually interpolating !" << endl);
788 if (pimg_erp)
delete[] pimg_erp;
795 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while trying to read the image file '" << Img_fields.
path_to_image <<
"' !" << endl);
797 if (pimg_erp)
delete[] pimg_erp;
801 if (pimg_erp)
delete[] pimg_erp;
810 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occured while trying to read the interfile metaheader '" << a_pathToHeaderFile <<
"' !" << endl);
814 if (lpath_to_headers.size() != (uint32_t)a_nbFbasis)
816 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> Number of interfile images (" << lpath_to_headers.size() <<
817 ") not consistent with the number of parametric images (" << a_nbFbasis<<
") !" << endl);
821 FLTNB* pimg_erp = NULL;
824 for (
int bf=0 ; bf<a_nbFbasis ; bf++)
827 if (
IntfReadHeader(lpath_to_headers[bf], &Img_fields, a_verbose) )
829 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> an error occured while trying to read interfile header '" << a_pathToHeaderFile <<
"' !" << endl);
831 if (pimg_erp)
delete[] pimg_erp;
837 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occured while checking consistencies between reconstruction parameters and interfile keys in the header '"<< a_pathToHeaderFile <<
"' !" << endl);
839 if (pimg_erp)
delete[] pimg_erp;
843 ifstream img_file(Img_fields.
path_to_image.c_str(), ios::binary | ios::in);
851 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occured while reading image stream and eventually interpolating !" << endl);
853 if (pimg_erp)
delete[] pimg_erp;
859 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while trying to read the image file '" << Img_fields.
path_to_image <<
"' !" << endl);
861 if (pimg_erp)
delete[] pimg_erp;
866 if (pimg_erp)
delete[] pimg_erp;
889 uint32_t nb_vox = a_IF.
mtx_size[0] *
894 *a2p_img =
new FLTNB[ nb_vox ];
895 ::memset(*a2p_img, 0,
sizeof(
FLTNB) * nb_vox);
921 if(vb >= 5)
Cout(
"IntfCheckConsistency()" << endl);
928 Cerr(
"***** IntfCheckConsistency()-> Error : some mandatory keys not initialized. Cannot read the interfile image !" << endl);
931 Cerr(
" Error when trying to read path to image data" << endl);
933 Cerr(
" Error when trying to read data voxel type " << endl);
935 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);
943 Cerr(
"***** IntfCheckConsistency()-> WARNING : No information found about voxel size ('scaling factor (mm/pixel)' tags.). Missing voxel sizes will be set to 1mm !" << endl);
977 Cerr(
"***** IntfCheckConsistency()-> Error : Image dimensions don't match reconstructions dimensions/voxel sizes" << endl);
978 Cerr(
" and linear interpolation is disabled (a_lerpFlag is false) !" << endl);
979 Cerr(
"***** Recovered image dimensions (x;y;z): "<< ap_IF->
mtx_size[0] <<
" ; "<< ap_IF->
mtx_size[1] <<
" ; " << ap_IF->
mtx_size[2] << endl);
997 FLTNB* ap_outImgMatrix,
998 FLTNB* ap_inImgMatrix,
1003 if (a_verbose >= 5)
Cout(
"oInterfileIO::IntfGetPixelTypeAndReadData() " << endl);
1012 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &flt);
1017 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &db);
1023 Cerr(
"***** oInterfileIO::IntfGetPixelTypeAndReadData() -> The long double format is not the same for this image file and for this platform !" << endl);
1027 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &db);
1034 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &s_int);
1039 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &s_int);
1044 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &s_int);
1049 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &s_int);
1057 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &u_int);
1062 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &u_int);
1067 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &u_int);
1072 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &u_int);
1078 Cerr(
"***** oInterfileIO::IntfGetPixelTypeAndReadData() -> An error occurred when trying to read data through the IntfReadData() function !" << endl);
1093 FLTNB* ap_outImgMatrix,
1094 FLTNB* ap_inImgMatrix,
1100 if (a_verbose >= 5)
Cout(
"oInterfileIO::IntfReadData() -> Read data from file stream and eventually interpolate" << endl);
1110 pimg = ap_inImgMatrix;
1115 pimg = ap_outImgMatrix;
1119 bytes = (T*)malloc(nb_vox*
sizeof(T));
1121 ap_iFile->seekg(*a_offset);
1123 ap_iFile->read((
char*)bytes, nb_vox*
sizeof(T));
1125 if (!ap_iFile->good())
1127 if (ap_iFile->eof())
Cerr(
"***** oInterfileIO::IntfReadData() -> Not enough data in the file stream !" << endl);
1128 else Cerr(
"***** oInterfileIO::IntfReadData() -> An error occured while reading from file stream !" << endl);
1134 for (
int v=0; v<nb_vox; v++)
1150 *a_offset +=
sizeof(T);
1168 Cerr(
"***** oInterfileIO::IntfReadData() -> An error occurred while interpolating the input image to the reconstruction dimensions !" << endl);
1197 const uint32_t ap_iDimVox[3],
const uint32_t ap_oDimVox[3],
1198 const FLTNB ap_iSizeVox[3],
const FLTNB ap_oSizeVox[3],
1199 const FLTNB ap_iOffVox[3],
const FLTNB ap_oOffVox[3] )
1404 FLTNB const posOldImage[] = {-((
FLTNB)(ap_iDimVox[0]))*ap_iSizeVox[0]*((
FLTNB)0.5) ,
1405 -((
FLTNB)(ap_iDimVox[1]))*ap_iSizeVox[1]*((
FLTNB)0.5) ,
1406 -((
FLTNB)(ap_iDimVox[2]))*ap_iSizeVox[2]*((
FLTNB)0.5) };
1408 FLTNB const posNewImage[] = {-((
FLTNB)(ap_oDimVox[0]))*ap_oSizeVox[0]*((
FLTNB)0.5) ,
1409 -((
FLTNB)(ap_oDimVox[1]))*ap_oSizeVox[1]*((
FLTNB)0.5) ,
1410 -((
FLTNB)(ap_oDimVox[2]))*ap_oSizeVox[2]*((
FLTNB)0.5) };
1422 uint32_t
const iDimVoxPad[]
1424 ap_iDimVox[ 0 ] + 2,
1425 ap_iDimVox[ 1 ] + 2,
1429 uint32_t
const nElts = iDimVoxPad[ 0 ] *
1435 ::memset( pPadIData, 0,
sizeof(
FLTNB ) * nElts );
1437 for( uint32_t k = 0; k < ap_iDimVox[ 2 ]; ++k )
1438 for( uint32_t j = 0; j < ap_iDimVox[ 1 ]; ++j )
1439 for( uint32_t i = 0; i < ap_iDimVox[ 0 ]; ++i )
1441 pPadIData[ ( i + 1 ) + ( j + 1 ) * iDimVoxPad[ 0 ]
1442 + ( k + 1 ) * iDimVoxPad[ 0 ] * iDimVoxPad[ 1 ] ] =
1443 ap_iImg[ i + j * ap_iDimVox[ 0 ]
1444 + k * ap_iDimVox[ 0 ] * ap_iDimVox[ 1 ] ];
1449 FLTNB const boundMin[]
1451 posOldImage[ 0 ] - ap_iSizeVox[ 0 ] * ((
FLTNB)0.5),
1452 posOldImage[ 1 ] - ap_iSizeVox[ 1 ] * ((
FLTNB)0.5),
1453 posOldImage[ 2 ] - ap_iSizeVox[ 2 ] * ((
FLTNB)0.5)
1456 FLTNB const boundMax[]
1458 posOldImage[ 0 ] + ((
FLTNB)ap_iDimVox[ 0 ]) * ap_iSizeVox[ 0 ]
1459 + ap_iSizeVox[ 0 ] * ((
FLTNB)0.5),
1460 posOldImage[ 1 ] + ((
FLTNB)ap_iDimVox[ 1 ]) * ap_iSizeVox[ 1 ]
1461 + ap_iSizeVox[ 1 ] * ((
FLTNB)0.5),
1462 posOldImage[ 2 ] + ((
FLTNB)ap_iDimVox[ 2 ]) * ap_iSizeVox[ 2 ]
1463 + ap_iSizeVox[ 2 ] * ((
FLTNB)0.5)
1470 for( uint32_t i = 0; i < 3; ++i )
1472 pOldCoordCenter[ i ] =
new FLTNB[ iDimVoxPad[ i ] ];
1474 for( uint32_t j = 0; j < iDimVoxPad[ i ]; ++j )
1476 pOldCoordCenter[ i ][ j ] = posOldImage[ i ] - ap_iSizeVox[ i ] / 2.0
1477 + j * ap_iSizeVox[ i ];
1484 for( uint32_t i = 0; i < 3; ++i )
1486 pNewCoordCenter[ i ] =
new FLTNB[ ap_oDimVox[ i ] ];
1488 for( uint32_t j = 0; j < ap_oDimVox[ i ]; ++j )
1490 pNewCoordCenter[ i ][ j ] = posNewImage[ i ] + ap_oSizeVox[ i ] / 2.0
1491 + j * ap_oSizeVox[ i ];
1496 FLTNB const invSizeX = 1.0 / ap_iSizeVox[ 0 ];
1497 FLTNB const invSizeY = 1.0 / ap_iSizeVox[ 1 ];
1498 FLTNB const invSizeZ = 1.0 / ap_iSizeVox[ 2 ];
1504 for( uint32_t k = 0; k < ap_oDimVox[ 2 ]; ++k )
1507 FLTNB const z = pNewCoordCenter[ 2 ][ k ];
1508 if( z < boundMin[ 2 ] || z > boundMax[ 2 ] )
continue;
1511 int32_t
const zBin = ( z - boundMin[ 2 ] ) * invSizeZ;
1514 FLTNB const zComposantI0 = invSizeZ * ( pOldCoordCenter[ 2 ][ zBin + 1 ] - z );
1515 FLTNB const zComposantI1 = invSizeZ * ( z - pOldCoordCenter[ 2 ][ zBin ] );
1517 for( uint32_t j = 0; j < ap_oDimVox[ 1 ]; ++j )
1520 FLTNB const y = pNewCoordCenter[ 1 ][ j ];
1521 if( y < boundMin[ 1 ] || y > boundMax[ 1 ] )
continue;
1524 int32_t
const yBin = ( y - boundMin[ 1 ] ) * invSizeY;
1527 FLTNB const yComposantI0 = invSizeY * ( pOldCoordCenter[ 1 ][ yBin + 1 ]
1529 FLTNB const yComposantI1 = invSizeY * ( y
1530 - pOldCoordCenter[ 1 ][ yBin ] );
1532 for( uint32_t i = 0; i < ap_oDimVox[ 0 ]; ++i )
1535 FLTNB const x = pNewCoordCenter[ 0 ][ i ];
1536 if( x < boundMin[ 0 ] || x > boundMax[ 0 ] )
continue;
1539 int32_t
const xBin = ( x - boundMin[ 0 ] ) * invSizeX;
1542 FLTNB const xComposantI0 = invSizeX * (
1543 pOldCoordCenter[ 0 ][ xBin + 1 ] - x );
1544 FLTNB const xComposantI1 = invSizeX * ( x
1545 - pOldCoordCenter[ 0 ][ xBin ] );
1549 for( uint32_t kk = 0; kk < 2; ++kk )
1551 for( uint32_t jj = 0; jj < 2; ++jj )
1553 for( uint32_t ii = 0; ii < 2; ++ii )
1555 pKernelData[ ii + jj * 2 + kk * 2 * 2 ] =
1558 ( yBin + jj ) * iDimVoxPad[ 0 ] +
1559 ( zBin + kk ) * iDimVoxPad[ 0 ] * iDimVoxPad[ 1 ]
1567 FLTNB const xInterpVal0 = pKernelData[ 0 ] * xComposantI0 +
1568 pKernelData[ 1 ] * xComposantI1;
1570 FLTNB const xInterpVal1 = pKernelData[ 2 ] * xComposantI0 +
1571 pKernelData[ 3 ] * xComposantI1;
1573 FLTNB const xInterpVal2 = pKernelData[ 4 ] * xComposantI0 +
1574 pKernelData[ 5 ] * xComposantI1;
1576 FLTNB const xInterpVal3 = pKernelData[ 6 ] * xComposantI0 +
1577 pKernelData[ 7 ] * xComposantI1;
1580 FLTNB const yInterpVal0 = xInterpVal0 * yComposantI0 +
1581 xInterpVal1 * yComposantI1;
1583 FLTNB const yInterpVal1 = xInterpVal2 * yComposantI0 +
1584 xInterpVal3 * yComposantI1;
1587 FLTNB const interpValTot = yInterpVal0 * zComposantI0 +
1588 yInterpVal1 * zComposantI1;
1590 ap_oImg[ i + j * ap_oDimVox[ 0 ]
1591 + k * ap_oDimVox[ 0 ] * ap_oDimVox[ 1 ] ] = interpValTot;
1597 for( uint32_t i = 0; i < 3; ++i )
1599 delete[] pOldCoordCenter[ i ];
1600 delete[] pNewCoordCenter[ i ];
1602 delete[] pOldCoordCenter;
1603 delete[] pNewCoordCenter;
1605 delete[] pKernelData;
1633 if (vb>=3)
Cout(
"IntfWriteImgFile (with Intf_fields)" << endl);
1638 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile header for'"<< a_pathToImg <<
"' !" << endl);
1642 string path_to_image = a_pathToImg;
1643 path_to_image.append(
".img");
1648 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile image '"<< path_to_image <<
"' !" << endl);
1677 if (vb>=3)
Cout(
"IntfWriteImgFile (3D image)" << endl);
1685 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile header for'"<< a_pathToImg <<
"' !" << endl);
1689 string path_to_image = a_pathToImg;
1690 path_to_image.append(
".img");
1695 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile image '"<< path_to_image <<
"' !" << endl);
1727 if (vb>=3)
Cout(
"IntfWriteProjFile ..." << endl);
1730 vector<string> lpath_to_images;
1731 lpath_to_images.push_back(a_pathToImg);
1735 Cerr(
"***** IntfWriteProjFile()-> Error : while trying to write the interfile header for'"<< lpath_to_images[0] <<
"' !" << endl);
1748 Cerr(
"***** IntfWriteFile()-> Error : while trying to write the interfile image '"<< a_pathToImg <<
"' !" << endl);
1781 if (vb>=3)
Cout(
"IntfWriteImgDynCoeffFile ..." << endl);
1793 vector<string> lpath_to_images;
1797 lpath_to_images.push_back(a_pathToImg);
1801 Cerr(
"***** IntfWriteImgDynCoeffFile()-> Error : while trying to write the interfile header for'"<< lpath_to_images[0] <<
"' !" << endl);
1809 for(
int bf=0 ; bf<a_nbParImgs ; bf++)
1812 lpath_to_images.push_back(a_pathToImg);
1815 stringstream ss; ss << bf + 1;
1816 lpath_to_images[idx_file].append(
"_par").append(ss.str());
1819 string path_to_hdr = lpath_to_images[idx_file] +
".hdr";
1820 string path_to_img = lpath_to_images[idx_file] +
".img";
1824 ifstream fcheck(path_to_hdr.c_str());
1829 string dos_instruction =
"del " + path_to_hdr;
1830 system(dos_instruction.c_str());
1832 remove(path_to_hdr.c_str());
1836 ofstream ofile(path_to_hdr.c_str(), ios::out | ios::app);
1837 ofile << setprecision(std::numeric_limits<FLTNB>::digits10 +1);
1838 ofile <<
"!INTERFILE := " << endl;
1839 ofile <<
"!name of data file := " <<
GetFileFromPath(path_to_img) << endl;
1841 ofile <<
"!data offset in bytes := " << 0 << endl;
1843 ofile <<
"!type of data := Dynamic" << endl;
1847 Cerr(
"***** IntfWriteImgDynCoeffFile()-> Error : while trying to write the interfile header for'"<< lpath_to_images[idx_file] <<
"' !" << endl);
1851 ofile <<
"!END OF INTERFILE := " << endl;
1858 if(
IntfWriteMHD(a_pathToImg, lpath_to_images, Img_fields, ap_ID, vb) )
1860 Cerr(
"***** IntfWriteImgDynCoeffFile()-> Error : while trying to write the interfile header '"<< a_pathToImg <<
"' !" << endl);
1869 dims[0] = a_nbParImgs;
1874 Cerr(
"***** IntfWriteImgDynCoeffFile()-> Error : while trying to write the interfile image '"<< a_pathToImg <<
"' !" << endl);
1905 if (vb>=3)
Cout(
"IntfWriteImgFile (static/dynamic image) ..." << endl);
1916 vector<string> lpath_to_images;
1920 lpath_to_images.push_back(a_pathToImg);
1924 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile header for'"<< lpath_to_images[0] <<
"' !" << endl);
1940 lpath_to_images.push_back(a_pathToImg);
1945 stringstream ss; ss << fr + 1;
1946 lpath_to_images[idx_file].append(
"_fr").append(ss.str());
1952 stringstream ss; ss << rg + 1;
1953 lpath_to_images[idx_file].append(
"_rg").append(ss.str());
1958 stringstream ss; ss << cg + 1;
1959 lpath_to_images[idx_file].append(
"_cg").append(ss.str());
1963 string path_to_hdr = lpath_to_images[idx_file];
1964 string path_to_img = lpath_to_images[idx_file];
1968 ifstream fcheck(path_to_hdr.append(
".hdr").c_str());
1973 string dos_instruction =
"del " + path_to_hdr;
1974 system(dos_instruction.c_str());
1976 remove(path_to_hdr.c_str());
1980 ofstream ofile(path_to_hdr.c_str(), ios::out | ios::app);
1981 ofile << setprecision(std::numeric_limits<FLTNB>::digits10 +1);
1982 ofile <<
"!INTERFILE := " << endl;
1985 ofile <<
"!name of data file := " <<
GetFileFromPath(path_to_img).append(
".img") << endl;
1987 ofile <<
"!data offset in bytes := " << 0 << endl;
1989 ofile <<
"!type of data := Dynamic" << endl;
1993 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile header for'"<< lpath_to_images[idx_file] <<
"' !" << endl);
2003 ofile <<
"!END OF INTERFILE := " << endl;
2012 if(
IntfWriteMHD(a_pathToImg, lpath_to_images, Img_fields, ap_ID, vb) )
2014 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile header '"<< a_pathToImg <<
"' !" << endl);
2031 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile image '"<< a_pathToImg <<
"' !" << endl);
2120 int IntfIsMHD(
string a_pathToFile, vector<string> &ap_lPathToImgs)
2123 ifstream hfile(a_pathToFile.c_str(), ios::in);
2131 getline(hfile, line);
2134 if(line.empty())
continue;
2142 Cerr(
"***** IntfIsMHD()-> Error : couldn't correctly read interfile key '"<< line <<
"' !" << endl);
2154 uint16_t nb_datasets = 0;
2157 Cerr(
"***** IntfIsMHD()-> Error when trying to read data from 'total number of data set' key. Recovered value = " << Key.
kvalue << endl);
2165 string file_key =
"";
2166 string file_keyp =
"%";
2167 string file_key_space =
"";
2168 string file_keyp_space =
"%";
2169 file_key_space.append(
"data set [").append(ss.str()).append(
"]");
2170 file_keyp_space.append(
"data set [").append(ss.str()).append(
"]");
2171 file_key.append(
"data set[").append(ss.str()).append(
"]");
2172 file_keyp.append(
"data set[").append(ss.str()).append(
"]");
2179 getline(hfile, line);
2182 if(line.empty())
continue;
2187 Cerr(
"***** IntfIsMHD()-> Error : couldn't correctly read interfile key '"<< line <<
"' !" << endl);
2205 Cerr(
"***** IntfIsMHD()-> Error : when trying to read Interfile array key: '"<< line <<
"' !" << endl);
2208 else if(nb_elts != 3)
2210 Cerr(
"***** IntfIsMHD()-> Error : when trying to read Interfile array key: '"<< line <<
"' !" << endl);
2211 Cerr(
" 3 elements are expected following the format {xxx, path_to_the_img_file, xxx} (xxx = ignored data)" << endl);
2217 Cerr(
"***** IntfIsMHD()-> Error : when trying to read Interfile array key: '"<< line <<
"' !" << endl);
2220 ap_lPathToImgs.at(file_idx).append(elts_str[1]);
2223 ap_lPathToImgs.at(file_idx).append(Key.
kvalue);
2231 file_key.append(
"data set [").append(ss.str()).append(
"]");
2232 file_keyp.append(
"data set [").append(ss.str()).append(
"]");
2238 if(nb_datasets != ap_lPathToImgs.size())
2241 Cerr(
"***** IntfIsMHD()-> The number of recovered file in the metaheader ("<<ap_lPathToImgs.size()<<
")");
2242 Cerr(
"does not correspond to the expected number of datasets ("<<nb_datasets<<
")!"<< endl);
2253 Cerr(
"***** IntfIsMHD()-> Error : couldn't read header file '"<< a_pathToFile <<
"' !" << endl);
2259 ap_lPathToImgs.push_back(a_pathToFile);
2282 const vector<string>& ap_lPathToImgs,
2288 string path_to_mhd_file = a_pathToMhd;
2289 path_to_mhd_file.append(
".mhd");
2290 ofstream ofile(path_to_mhd_file.c_str(), ios::out);
2291 ofile << setprecision(std::numeric_limits<FLTNB>::digits10 +1);
2299 ofile <<
"!INTERFILE := " << endl;
2301 ofile << endl <<
"!GENERAL DATA := " << endl;
2302 ofile <<
"data description:=image" << endl;
2303 ofile <<
"!originating system := " << p_scanMgr->
GetScannerName() << endl;
2306 if (ap_ID->
GetNbBeds()>1) ofile <<
"number of bed positions := " << ap_ID->
GetNbBeds() << endl;
2308 else ofile <<
"horizontal bed relative position (mm) := " << ap_ID->
GetBedPosition(0) << endl;
2310 ofile << endl <<
"%DATA MATRIX DESCRIPTION:=" << endl;
2311 ofile <<
"number of time frames := " << a_IntfF.
nb_time_frames << endl;
2312 ofile <<
"number of time windows := " << a_IntfF.
nb_resp_gates *
2314 ofile <<
"number of respiratory gates := " << a_IntfF.
nb_resp_gates << endl;
2315 ofile <<
"number of cardiac gates := " << a_IntfF.
nb_card_gates << endl;
2317 ofile << endl <<
"%DATA SET DESCRIPTION:="<< endl;
2320 ofile <<
"!total number of data sets:=" << nb_imgs << endl;
2323 if(ap_lPathToImgs.size() != nb_imgs)
2325 Cerr(
"***** IntfWriteMHD()-> Error : nb of provided string inconsistent with the expected number of dynamic images: '"<< nb_imgs <<
"' !" << endl);
2330 for(
int ds=0 ; ds<nb_imgs ; ds++)
2332 string path_to_header = ap_lPathToImgs.at(ds);
2333 ofile <<
"%data set ["<<ds+1<<
"]:={0," <<
GetFileFromPath(path_to_header).append(
".hdr") <<
",UNKNOWN}"<< endl;
2338 Cerr(
"***** IntfWriteMHD()-> Error : couldn't find output Metaheader interfile '"<< path_to_mhd_file <<
"' !" << endl);
2377 Cout(
"--------------------------------------------------------------- " << endl);
2378 Cout(
"IntfReadHeader()-> Start reading header interfile " << a_pathToHeaderFile << endl);
2379 Cout(
"--------------------------------------------------------------- " << endl);
2384 ifstream input_file(a_pathToHeaderFile.c_str(), ios::in);
2390 while(!input_file.eof())
2392 getline(input_file, line);
2404 Cerr(
"***** ReadIntfHeader()-> Error : couldn't correctly read interfile key '"<< line <<
"' !" << endl);
2408 if (vb >=10)
Cout(
"ReadIntfHeader()-> Key " << Key.
kcase << endl);
2427 if ( Key.
kvalue.size()>0 )
2439 string header_file_directory =
GetPathOfFile(a_pathToHeaderFile);
2445 Cerr(
"***** ReadIntfHeader()-> Error : path to interfile image file is empty !" << endl);
2460 if (endianness ==
"littleendian")
2474 Cerr(
"***** ReadIntfHeader()-> Warning : data_offset value was already set to " << ap_IF->
data_offset << endl);
2475 Cerr(
"***** The header may contain both 'data offset in bytes' and 'data starting block' fields " << endl);
2480 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'data starting block' key. Recovered value = " << Key.
kvalue << endl);
2495 Cerr(
"***** ReadIntfHeader()-> Warning : data_offset value was already set to " << ap_IF->
data_offset << endl);
2496 Cerr(
"***** The header may contain both 'data offset in bytes' and 'data starting block' fields " << endl);
2501 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'data offset in bytes' key. Recovered value = " << Key.
kvalue << endl);
2513 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number format' key. Recovered value = " << Key.
kvalue << endl);
2524 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'originating system' key. Recovered value = " << Key.
kvalue << endl);
2535 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'bed relative position (mm)' key. Recovered value = " << Key.
kvalue << endl);
2546 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [1]' key. Recovered value = " << Key.
kvalue << endl);
2557 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [2]' key. Recovered value = " << Key.
kvalue << endl);
2574 Cerr(
"***** ReadIntfHeader()-> Array reading for 'matrix size [3]' key not implemented yet. Single value expected." << endl);
2581 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [3]' key. Recovered value = " << Key.
kvalue << endl);
2603 Cerr(
"***** ReadIntfHeader()-> Array reading for 'matrix size [4]' key not implemented yet. Single value expected." << endl);
2612 Cerr(
"***** ReadIntfHeader()-> WARNING : both 'number of time frames' and 'matrix size [4]' keys have been provided");
2613 Cerr(
" 'number of time frames' selected by default" << endl);
2617 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [4]' key. Recovered value = " << Key.
kvalue << endl);
2636 Cerr(
"***** ReadIntfHeader()-> Array reading for 'matrix size [5]' key not implemented yet. Single value expected." << endl);
2643 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [5]' key. Recovered value = " << Key.
kvalue << endl);
2661 Cerr(
"***** ReadIntfHeader()-> Array reading for 'matrix size [6]' key not implemented yet. Single value expected." << endl);
2668 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [6]' key. Recovered value = " << Key.
kvalue << endl);
2686 Cerr(
"***** ReadIntfHeader()-> Array reading for 'matrix size [7]' key not implemented yet. Single value expected." << endl);
2693 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [7]' key. Recovered value = " << Key.
kvalue << endl);
2707 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'scaling factor (mm/pixel) [1]' key. Recovered value = " << Key.
kvalue << endl);
2719 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'scaling factor (mm/pixel) [2]' key. Recovered value = " << Key.
kvalue << endl);
2732 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'scaling factor (mm/pixel) [3]' key. Recovered value = " << Key.
kvalue << endl);
2746 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from one of the following key :" << endl);
2747 Cerr(
"***** 'first pixel offset (mm) [1]'" << Key.
kvalue << endl);
2748 Cerr(
"***** 'origin (mm) [1]'"<< endl);
2749 Cerr(
"***** 'offset [1]'" << Key.
kvalue << endl);
2750 Cerr(
"***** Recovered value = " << Key.
kvalue << endl);
2764 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from one of the following key :" << endl);
2765 Cerr(
"***** 'first pixel offset (mm) [2]'" << Key.
kvalue << endl);
2766 Cerr(
"***** 'origin (mm) [2]'"<< endl);
2767 Cerr(
"***** 'offset [2]'" << Key.
kvalue << endl);
2768 Cerr(
"***** Recovered value = " << Key.
kvalue << endl);
2782 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from one of the following key :" << endl);
2783 Cerr(
"***** 'first pixel offset (mm) [3]'" << Key.
kvalue << endl);
2784 Cerr(
"***** 'origin (mm) [3]'"<< endl);
2785 Cerr(
"***** 'offset [3]'" << Key.
kvalue << endl);
2786 Cerr(
"***** Recovered value = " << Key.
kvalue << endl);
2799 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'slice thickness (pixels)' key. Recovered value = " << Key.
kvalue << endl);
2811 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'centre-centre slice separation (pixels)' key.");
2812 Cerr(
" Recovered value = " << Key.
kvalue << endl);
2815 Cerr(
"***** ReadIntfHeader()-> WARNING : 'centre-centre slice separation (pixels)' has no use in the current implementation !"<< endl);
2826 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of time frames' or 'number of frame groups' keys.");
2827 Cerr(
"Recovered value = " << Key.
kvalue << endl);
2839 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of respiratory gates' key. Recovered value = " << Key.
kvalue << endl);
2851 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of cardiac gates' key. Recovered value = " << Key.
kvalue << endl);
2862 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'total number of images' key. Recovered value = " << Key.
kvalue << endl);
2873 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of bytes per pixel' key. Recovered value = " << Key.
kvalue << endl);
2883 string slice_orientation;
2886 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'slice orientation' key. Recovered value = " << Key.
kvalue << endl);
2890 if (slice_orientation ==
"transverse")
2892 else if (slice_orientation ==
"sagittal")
2894 else if (slice_orientation ==
"coronal")
2903 string pat_rotation;
2906 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'patient rotation' key. Recovered value = " << Key.
kvalue << endl);
2910 if (pat_rotation ==
"supine")
2912 else if (pat_rotation ==
"prone")
2922 string pat_orientation;
2925 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'patient orientation' key. Recovered value = " << Key.
kvalue << endl);
2929 if (pat_orientation ==
"head_in")
2931 else if (pat_orientation ==
"feet_in")
2944 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'rescale slope' or 'data rescale slope' key. Recovered value = " << Key.
kvalue << endl);
2951 Cerr(
"***** ReadIntfHeader()-> Error : field 'resclale slope' units should be >0!" << endl);
2966 Cerr(
"***** ReadIntfHeader()-> WARNING : Error when trying to read numeric value from 'quantification units' key. Actual value = " << Key.
kvalue << endl);
2967 Cerr(
"***** This key will be ignored" << endl);
2974 Cerr(
"***** ReadIntfHeader()-> Error : field 'quantification units' should be >0!" << endl);
2986 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'rescale intercept' or 'data rescale intercept' key. Recovered value = " << Key.
kvalue << endl);
2992 Cerr(
"***** ReadIntfHeader()-> Error : field 'resclale intercept' units should be >0!" << endl);
3006 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'type of data' key. Recovered value = " << Key.
kvalue << endl);
3020 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'study duration (sec)' key. Recovered value = " << Key.
kvalue << endl);
3034 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'study duration (sec)' key. Recovered value = " << Key.
kvalue << endl);
3050 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'study duration (sec)' key. Recovered value = " << Key.
kvalue << endl);
3063 FLTNB pause_duration;
3066 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'study duration (sec)' key. Recovered value = " << Key.
kvalue << endl);
3080 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of time windows ' key. Recovered value = " << Key.
kvalue << endl);
3083 Cerr(
"***** ReadIntfHeader()-> WARNING : 'number of time windows' has no use in the current implementation !"<< endl);
3093 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'process status' key. Recovered value = " << Key.
kvalue << endl);
3106 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of energy windows' key. Recovered value = " << Key.
kvalue << endl);
3119 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of detector heads' key. Recovered value = " << Key.
kvalue << endl);
3131 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of projections' key. Recovered value = " << Key.
kvalue << endl);
3143 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'extent of rotation' key. Recovered value = " << Key.
kvalue << endl);
3154 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'direction_rotation' key. Recovered value = " << Key.
kvalue << endl);
3167 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'start angle' key. Recovered value = " << Key.
kvalue << endl);
3179 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'projection_angles' key. Recovered value = " << Key.
kvalue << endl);
3191 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'Center of rotation to detector distance' key.");
3192 Cerr(
" Recovered value = " << Key.
kvalue << endl);
3204 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'Radius' key. Recovered value = " << Key.
kvalue << endl);
3214 Cerr(
"***** ReadIntfHeader()-> Error : compressed interfile images not handled by the current implementation !" << endl);
3224 Cerr(
"***** ReadIntfHeader()-> Error : encoded interfile images not handled by the current implementation !" << endl);
3236 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of slices' key. Recovered value = " << Key.
kvalue << endl);
3248 Cerr(
"***** ReadIntfHeader()-> Error : couldn't find or read header interfile '"<< a_pathToHeaderFile <<
"' !" << endl);
3278 Cerr(
"***** ReadIntfHeader()-> Error : nb of recovered frame duration ('"<< ap_IF->
image_duration.size()
3279 <<
") does not match the nb of recovered pauses between frames ('"<< ap_IF->
frame_group_pause.size() <<
") !" << endl);
3307 Cout(
"--------------------------------------------------------------- " << endl);
3308 Cout(
"IntfWriteHeaderMainData()-> Start writing header interfile " << a_path << endl);
3309 Cout(
"--------------------------------------------------------------- " << endl);
3312 string path_to_header, path_to_image;
3313 path_to_header = a_path;
3315 path_to_header.append(
".hdr");
3319 ofstream ofile(path_to_header.c_str(), ios::out);
3320 ofile << setprecision(std::numeric_limits<FLTNB>::digits10 +1);
3326 ofile <<
"!INTERFILE := " << endl;
3329 string imaging_modality;
3331 imaging_modality =
"PET";
3333 imaging_modality =
"SPECT";
3335 imaging_modality =
"CT";
3337 imaging_modality =
"UNKOWN";
3339 ofile <<
"!imaging modality := " << imaging_modality << endl;
3343 ofile <<
"!version of keys := " <<
"3.3" << endl;
3345 ofile <<
"!version of keys := " <<
"CASToRv" <<
CASTOR_VERSION << endl;
3349 ofile << endl <<
"!GENERAL DATA := " << endl;
3350 ofile <<
"!originating system := " << p_scanMgr->
GetScannerName() << endl;
3357 ofile <<
"!data offset in bytes := " << 0 << endl;
3358 ofile <<
"!name of data file := " << path_to_image << endl;
3364 ofile << endl <<
"!GENERAL IMAGE DATA " << endl;
3370 ofile <<
"!type of data := Dynamic" << endl;
3375 ofile <<
"!total number of images := " << nb_imgs << endl;
3383 ofile <<
"number of time frames := " << ap_IntfF.
nb_time_frames << endl;
3384 ofile <<
"!number of frame groups := " << ap_IntfF.
nb_time_frames << endl;
3387 ofile <<
"!number of frame groups :=1 " << endl;
3391 ofile <<
"number of time windows := " << ap_IntfF.
nb_resp_gates *
3394 ofile <<
"number of respiratory gates := " << ap_IntfF.
nb_resp_gates << endl;
3396 ofile <<
"number of cardiac gates := " << ap_IntfF.
nb_card_gates << endl;
3400 ofile <<
"!number of projections := " << ap_IntfF.
nb_projections << endl;
3401 ofile <<
"!extent of rotation := " << ap_IntfF.
extent_rotation << endl;
3403 ofile <<
"process status := " << ap_IntfF.
process_status << endl;
3407 ofile << endl <<
"!DYNAMIC STUDY (General) :=" << endl;
3411 ofile << endl <<
"!GSPECT STUDY (General) :=" << endl;
3414 ofile << endl <<
"!SPECT STUDY (General) :=" << endl;
3415 ofile << endl <<
"!SPECT STUDY ("<< ap_IntfF.
process_status <<
" data) :="<< endl;
3419 ofile << endl <<
"!GATED STUDY (General) :=" << endl;
3421 ofile << endl <<
"!STATIC STUDY (General) :=" << endl;
3434 ofile <<
"!number of frame groups :=" << ap_IntfF.
nb_time_frames << endl;
3441 ofile <<
"!Dynamic Study (each frame group) :=" << endl;
3442 ofile <<
"!frame group number := " << fr+1 << endl;
3450 ofile <<
"!Respiratory Gated Study (each time window) :=" << endl;
3451 ofile <<
"!time window number := " << rg+1 << endl;
3459 ofile <<
"!Cardiac Gated Study (each time window) :=" << endl;
3460 ofile <<
"!time window number := " << cg+1 << endl;
3466 Cerr(
"***** IntfWriteHeaderMainData()-> Error : while trying to write the interfile header '"<< path_to_header <<
"' !" << endl);
3471 ofile <<
"!number of images in this time window :="
3477 ofile <<
"!number of images in this time window :="
3485 ofile <<
"!number of images this frame group :="
3490 ofile <<
"!image duration (sec) := " << ap_IntfF.
image_duration[fr] << endl;
3492 ofile <<
"pause between frame groups (sec) " << 0.0 << endl;
3494 ofile <<
"pause between frame groups (sec) " << ap_IntfF.
frame_group_pause[fr] << endl;
3498 ofile <<
"!END OF INTERFILE := " << endl;
3502 Cerr(
"***** IntfWriteHeaderMainData()-> Error : couldn't find output header interfile '"<< a_path <<
"' !" << endl);
3535 ap_ofile <<
"start angle := " << ap_IntfF.
first_angle << endl;
3539 if( ap_IntfF.
radius.find(
"{}") != string::npos )
3540 ap_ofile <<
"Center of rotation to detector distance := " << ap_IntfF.
radius << endl;
3542 ap_ofile <<
"Radius := " << ap_IntfF.
radius << endl;
3544 ap_ofile <<
"!matrix size [1] := " << ap_IntfF.
mtx_size[0] << endl;
3545 ap_ofile <<
"!matrix size [2] := " << ap_IntfF.
mtx_size[1] << endl;
3546 ap_ofile <<
"!number format := " << ap_IntfF.
nb_format << endl;
3547 ap_ofile <<
"!number of bytes per pixel := " <<
sizeof(
FLTNB) << endl;
3548 ap_ofile <<
"scaling factor (mm/pixel) [1] := " << ap_IntfF.
vox_size[0] << endl;
3549 ap_ofile <<
"scaling factor (mm/pixel) [2] := " << ap_IntfF.
vox_size[1] << endl;
3550 ap_ofile <<
"!data offset in bytes := " << 0 << endl;
3554 ap_ofile <<
"number of dimensions := " << 3 << endl;
3555 ap_ofile <<
"!matrix size [1] := " << ap_IntfF.
mtx_size[0] << endl;
3556 ap_ofile <<
"!matrix size [2] := " << ap_IntfF.
mtx_size[1] << endl;
3557 ap_ofile <<
"!matrix size [3] := " << ap_IntfF.
mtx_size[2] << endl;
3558 ap_ofile <<
"!number format := " << ap_IntfF.
nb_format << endl;
3559 ap_ofile <<
"!number of bytes per pixel := " <<
sizeof(
FLTNB) << endl;
3560 ap_ofile <<
"scaling factor (mm/pixel) [1] := " << ap_IntfF.
vox_size[0] << endl;
3561 ap_ofile <<
"scaling factor (mm/pixel) [2] := " << ap_IntfF.
vox_size[1] << endl;
3562 ap_ofile <<
"scaling factor (mm/pixel) [3] := " << ap_IntfF.
vox_size[2] << endl;
3563 ap_ofile <<
"first pixel offset (mm) [1] := " << ap_IntfF.
vox_offset[0] << endl;
3564 ap_ofile <<
"first pixel offset (mm) [2] := " << ap_IntfF.
vox_offset[1] << endl;
3565 ap_ofile <<
"first pixel offset (mm) [3] := " << ap_IntfF.
vox_offset[2] << endl;
3572 ap_ofile <<
"data rescale slope := " << ap_IntfF.
rescale_slope << endl;
3573 ap_ofile <<
"quantification units := " << ap_IntfF.
quant_units << endl;
3593 Cerr(
"***** IntfWriteHeaderImgData()-> Error : couldn't open provided interfile header file !" << endl);
3619 if(vb >= 5)
Cout(
"IntfWriteImage()*" << endl);
3621 ofstream img_file(a_pathToImg.c_str(), ios::binary | ios::out);
3628 Cerr(
"***** IntfWriteImage()-> Error occurred when writing the image file '"<< a_pathToImg <<
"' !" << endl);
3634 Cerr(
"***** IntfWriteImage()-> Error occurred while trying to write the image file '"<< a_pathToImg <<
"' !" << endl);
3660 if(vb >= 5)
Cout(
"IntfWriteImage()**" << endl);
3662 if(ap_pathToImgs.size() == 1)
3666 ifstream fcheck(ap_pathToImgs.at(0).append(
".img").c_str());
3671 string dos_instruction =
"del " + ap_pathToImgs.at(0);
3672 system(dos_instruction.c_str());
3674 remove(ap_pathToImgs.at(0).c_str());
3679 ofstream img_file(ap_pathToImgs.at(0).c_str(), ios::binary | ios::out | ios::app);
3684 for(uint32_t d1=0 ; d1<ap_dim[0] ; d1++)
3685 if(
IntfWriteData(&img_file, a2p_outImgMtx[d1], ap_dim[1], vb) )
3687 Cerr(
"***** IntfWriteImage()-> Error occurred when writing the image file '"<< ap_pathToImgs.at(d1) <<
"' !" << endl);
3693 Cerr(
"***** IntfWriteImage()-> Error occurred while trying to write the image file at the path: '"<< ap_pathToImgs.at(0) <<
"' !" << endl);
3699 if(ap_pathToImgs.size()!=ap_dim[0])
3701 Cerr(
"***** IntfWriteImage()-> Error : number of interfile images ("<< ap_pathToImgs.size() <<
") not consistent with the number of images to load (" << ap_dim[0] <<
") !" << endl);
3705 for(uint32_t d1=0 ; d1<ap_dim[0] ; d1++)
3707 ofstream img_file(ap_pathToImgs.at(d1).append(
".img").c_str(), ios::binary | ios::out);
3712 if(
IntfWriteData(&img_file, a2p_outImgMtx[d1], ap_dim[1], vb) )
3714 Cerr(
"***** IntfWriteImage()-> Error occurred when writing the image file '"<< ap_pathToImgs.at(d1) <<
"' !" << endl);
3720 Cerr(
"***** IntfWriteImage()-> Error occurred while trying to write the image file at the path: '"<< ap_pathToImgs.at(d1) <<
"' !" << endl);
3748 if(vb >= 5)
Cout(
"IntfWriteImage()" << endl);
3750 if(ap_pathToImgs.size() == 1)
3754 ifstream fcheck(ap_pathToImgs.at(0).append(
".img").c_str());
3759 string dos_instruction =
"del " + ap_pathToImgs.at(0);
3760 system(dos_instruction.c_str());
3762 remove(ap_pathToImgs.at(0).c_str());
3767 ofstream img_file(ap_pathToImgs.at(0).c_str(), ios::binary | ios::out | ios::app);
3772 for(uint32_t d1=0 ; d1<ap_dim[0] ; d1++)
3773 for(uint32_t d2=0 ; d2<ap_dim[1] ; d2++)
3774 for(uint32_t d3=0 ; d3<ap_dim[2] ; d3++)
3775 if(
IntfWriteData(&img_file, a4p_outImgMtx[d1][d2][d3], ap_dim[3], vb) )
3777 int idx_img = d1*ap_dim[1]*ap_dim[2] + d2*ap_dim[2] + d3;
3778 Cerr(
"***** IntfWriteImage()-> Error occurred when writing the image file '"<< ap_pathToImgs.at(idx_img) <<
"' !" << endl);
3784 Cerr(
"***** IntfWriteImage()-> Error occurred while trying to write the image file '"<< ap_pathToImgs.at(0) <<
"' !" << endl);
3792 if(ap_pathToImgs.size() != ap_dim[0]*ap_dim[1]*ap_dim[2])
3794 Cerr(
"***** IntfWriteImage()-> Error : number of interfile images (="<< ap_pathToImgs.size()
3795 <<
") not consistent with the number of images to load (="
3796 << ap_dim[0]*ap_dim[1]*ap_dim[2] <<
") !" << endl);
3800 for(uint32_t d1=0 ; d1<ap_dim[0] ; d1++)
3801 for(uint32_t d2=0 ; d2<ap_dim[1] ; d2++)
3802 for(uint32_t d3=0 ; d3<ap_dim[2] ; d3++)
3804 int idx_img = d1*ap_dim[1]*ap_dim[2] + d2*ap_dim[2] + d3;
3805 ofstream img_file(ap_pathToImgs.at(idx_img).append(
".img").c_str(), ios::binary | ios::out);
3810 if(
IntfWriteData(&img_file, a4p_outImgMtx[d1][d2][d3], ap_dim[3], vb) )
3812 Cerr(
"***** IntfWriteImage()-> Error occurred when writing the image file '"<< ap_pathToImgs.at(idx_img) <<
"' !" << endl);
3818 Cerr(
"***** IntfWriteImage()-> Error occurred while trying to write the image file at the path: '"<< ap_pathToImgs.at(idx_img) <<
"' !" << endl);
3847 if(vb >= 5)
Cout(
"IntfWriteData() " << endl);
3851 if (ap_oFile->write(reinterpret_cast<char*>(ap_outImgMatrix), a_nbVox*
sizeof(
FLTNB)) )
3885 for(
int d=0 ; d<7 ; d++)
3887 for(
int d=0 ; d<3 ; d++)
3889 for(
int d=0 ; d<3 ; d++)
3906 for(
int d=0 ; d<3 ; d++)
4043 Cout(
"// ------ IntfKeyPrintFields ------ // " << endl << endl);
4048 Cout(
"nb_dims : " <<
unsigned(a_IF.
nb_dims) << endl);
4049 for(
int i=0 ; i<7 ; i++)
4050 Cout(
"mtx_size["<<i<<
"] : " << a_IF.
mtx_size[i] << endl);
4051 for(
int i=0 ; i<3 ; i++)
4053 for(
int i=0 ; i<3 ; i++)
4054 Cout(
"vox_size["<<i<<
"] : " << a_IF.
vox_size[i] << endl);
4069 for(
int i=0 ; i<3 ; i++)
4071 for(
int i=0 ; i<3 ; i++)
4073 for(
int i=0 ; i<3 ; i++)
4079 Cout(
"image_duration(fr) : " << endl);
4082 Cout(
"image_start_time(fr) : " << endl);
4085 Cout(
"pause_duration(fr) : " << endl);
4102 Cout(
"// ------ ------------------ ------ // " << endl << endl);
4126 string intf_sep =
":=";
4129 int pos = a_line.find_first_of(
';',0);
4130 ap_Key->
korig = a_line.substr(0, pos);
4133 pos = ap_Key->
korig.find_first_of(intf_sep);
4136 if (ap_Key->
korig.find(intf_sep) == string::npos)
4137 ap_Key->
korig.append(
":=");
4186 string a_copy_of_the_key = ap_Key.
klcase;
4187 string a_copy_of_the_field = a_field;
4188 size_t found_char_at_pos = string::npos;
4190 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,
"");
4192 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,
"");
4196 if (a_copy_of_the_key==a_copy_of_the_field)
return 1;
4216 if(ap_Key.
kvalue.find(
"{") != string::npos &&
4217 ap_Key.
kvalue.find(
"}") != string::npos)
4239 string val_str = a_Key.
kvalue;
4241 size_t pos = val_str.find_first_of(
'{')+1;
4243 while (pos < val_str.length())
4245 size_t pos_c = val_str.find_first_of(
",", pos);
4248 if(pos_c == string::npos)
4250 pos_c = val_str.find_first_of(
"}", pos);
4253 Cerr(
"***** IntfKeyGetArrayNbElts-> Error : closing bracket not found in interfile array key : "<< a_Key.
korig <<
" !" << endl);
4264 Cerr(
"***** IntfKeyGetArrayNbElts-> Error : closing bracket not found in interfile array key : "<< a_Key.
korig <<
" !" << endl);
4284 string val_str = ap_Key.
kvalue;
4285 if (val_str ==
"")
return(max);
4287 size_t pos = val_str.find_first_of(
'{')+1;
4289 while (pos < val_str.length())
4291 size_t pos_c = val_str.find_first_of(
",", pos);
4294 if(pos_c == string::npos) pos_c = val_str.find_first_of(
"}", pos);
4298 Cerr(
"***** IntfKeyGetMaxArrayKey()-> An error occured when trying to recover the following value from the array key : "<< val_str.substr(pos,pos_c-pos) <<
" !" << endl);
4302 if (value > max) max = value;
4328 string val_str = a_Key.
kvalue;
4333 Cerr(
"***** IntfKeyGetArrayElts-> Error : Problem reading the following interfile array key : "<< a_Key.
korig <<
" !" << endl);
4339 Cerr(
"***** IntfKeyGetArrayElts-> Error : no elements in the array key : "<< a_Key.
korig <<
" !" << endl);
4343 size_t pos = val_str.find_first_of(
'{')+1;
4347 while (pos < val_str.length())
4349 size_t pos_c = val_str.find_first_of(
",", pos);
4352 if(pos_c == string::npos) pos_c = val_str.find_first_of(
"}", pos);
4356 Cerr(
"***** IntfKeyGetMaxArrayKey()-> An error occured when trying to recover the following value from the array key : "<< val_str.substr(pos,pos_c-pos) <<
" !" << endl);
4386 int dimXY=dimX*dimY;
4389 int z = a_voxId/dimXY;
4390 int y = (a_voxId - z*dimXY) / dimX;
4391 int x = a_voxId - z*dimXY - y*dimX;
4494 a_voxId = X + Y*dimX + Z*dimX*dimY;
4515 if(a_val == 0)
return "BIGENDIAN";
4516 if(a_val == 1)
return "LITTLEENDIAN";
4531 if(a_modalityIdx == 0)
4533 else if(a_modalityIdx == 1)
4560 if (a_str ==
"static")
4562 if (a_str ==
"dynamic")
4564 if (a_str ==
"gated")
4566 if (a_str ==
"tomographic")
4568 if (a_str ==
"gspect")
4628 if (
sizeof(
FLTNB) == 4)
return "short float";
4629 else if (
sizeof(
FLTNB) == 8)
return "long float";
4630 else if (
sizeof(
FLTNB) == 16)
return "long long float";
4633 Cerr(
"***** oInterfileIO::IntfKeyGetPixTypeStr() -> Size of current float type (" <<
sizeof(
FLTNB) <<
") does not correspond to a known type !" << endl);
4750 input_str->erase(0, input_str->find_first_not_of(
" !\t\r\n"));
4751 input_str->erase(input_str->find_last_not_of(
" \t\r\n")+1 , input_str->length());
4769 std::transform(ap_str->begin(), ap_str->end(), ap_str->begin(), ::tolower);
4786 string patient_tag_str =
"";
4791 if(dfName.size() > 1)
4793 patient_tag_str +=
"{ " + dfName[0];
4794 for(
size_t n=1 ; n<dfName.size() ; n++ )
4795 patient_tag_str +=
", " + dfName[n];
4796 patient_tag_str +=
"} ";
4798 else if (dfName.size() == 1)
4799 patient_tag_str += dfName[0];
4801 patient_tag_str +=
"unknown data";
4803 return patient_tag_str;
4822 char *buffer =
reinterpret_cast<char*
>(ap_type);
4823 std::reverse(buffer, buffer +
sizeof(T));
vector< FLTNB > image_start_time
#define INTF_SUPINE_FEETIN_CORONAL
static sScannerManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
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)
FLTNB GetFrameTimeStartInSec(int a_bed, int a_frame)
Get the frame time start for the given bed, in seconds as a FLTNB.
void IntfKeyInitFields(Intf_fields *ap_IF)
Init the file of an Interfile fields structure passed in parameter to their default values...
template int IntfKeyGetValueFromFile< int >(const string &a_pathToHeader, const string &a_key, int *ap_return, int a_nbElts, int a_mandatoryFlag)
#define INTF_PRONE_HEADIN_CORONAL
FLTNB GetVoxSizeX()
Get the voxel's size along the X axis, in mm.
FLTNB * IntfLoadImageFromScratch(const string &a_pathToHeaderFile, Intf_fields *ap_ImgFields, int vb)
int IntfCheckDimensionsConsistency(Intf_fields ImgFields1, Intf_fields ImgFields2)
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...
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)
FLTNB GetBedPosition(int a_bedIndex)
Get the bed position associated to a bed index.
void GetUserEndianness()
Check user/host computer endianness and write it to the global variable User_Endianness.
void IntfKeySetFieldsOutput(Intf_fields *ap_IF, oImageDimensionsAndQuantification *ap_ID)
Init the keys of the Interfile header of an image to be written on disk.
FLTNB GetVoxSizeZ()
Get the voxel's size along the Z axis, in mm.
#define INTF_PRONE_FEETIN_TRANSAXIAL
string IntfKeyGetModalityStr(int a_modalityIdx)
Convert the integer provided in parameter to the string related to the corresponding modality as de...
#define INTF_PRONE_FEETIN_CORONAL
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)
template int IntfKeyGetValueFromFile< float >(const string &a_pathToHeader, const string &a_key, float *ap_return, int a_nbElts, int a_mandatoryFlag)
#define INTF_SUPINE_FEETIN_SAGITTAL
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.
int IntfKeyGetPatOrientation(Intf_fields ap_IF)
Get the complete patient orientation from an Intf_fields structure according to the values of keys 's...
#define INTF_PRONE_FEETIN_SAGITTAL
FLTNB bed_relative_position
template int IntfKeyGetValueFromFile< long double >(const string &a_pathToHeader, const string &a_key, long double *ap_return, int a_nbElts, int a_mandatoryFlag)
vector< FLTNB > frame_group_pause
static sOutputManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
int IntfKeyGetRecurringValueFromFile(const string &a_pathToHeader, const string &a_key, T *ap_return, int a_nbElts, int a_mandatoryFlag, uint16_t a_nbOccurrences)
int IntfReadHeader(const string &a_pathToHeaderFile, Intf_fields *ap_IF, int vb)
Read an Interfile header.
template int IntfKeyGetValueFromFile< uint8_t >(const string &a_pathToHeader, const string &a_key, uint8_t *ap_return, int a_nbElts, int a_mandatoryFlag)
template int IntfKeyGetValueFromFile< bool >(const string &a_pathToHeader, const string &a_key, bool *ap_return, int a_nbElts, int a_mandatoryFlag)
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...
string GetFileFromPath(const string &a_pathToFile)
Simply return the file from a path string passed in parameter.
#define KEYWORD_MANDATORY_NOT_FOUND
bool GetProvidedBedPositionFlag()
Say if the bed relative position was provided from the datafile or not.
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 IntfWriteImageFromIntfFields(const string &a_pathToImg, FLTNB *ap_ImgMatrix, Intf_fields Img_fields, int vb)
int ConvertFromString(const string &a_str, string *a_result)
Copy the 'a_str' string in the position pointed by 'a_result'.
#define INTF_SUPINE_HEADIN_SAGITTAL
FLTNB GetVoxSizeY()
Get the voxel's size along the Y axis, in mm.
string IntfKeyGetEndianStr(int a_val)
return the endian string corresponding to the value passed in parameter (see module INTF_ENDIANNESS)...
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.
#define SCANNER_SPECT_CONVERGENT
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...
int IntfKeyGetOutputImgDataType(oImageDimensionsAndQuantification *ap_ID)
int IntfReadData(Intf_fields a_IF, ifstream *ap_iFile, FLTNB *ap_outImgMatrix, FLTNB *ap_inImgMatrix, uint32_t *a_offset, int 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...
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.
Singleton class that manages output writing on disk (images, sinograms, etc). It also manages loggi...
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)
int IntfKeyGetInputImgDataType(const string &a_str)
Get the image data type corresponding to the image metadata passed in parameter.
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)
int GetNbBeds()
Get the number of bed positions.
Singleton class that Instantiate and initialize the scanner object.
FLTNB GetFinalTimeStopInSec(int a_bed)
Get the last frame time stop for the given bed, in seconds as a FLTNB.
int IntfKeyIsArray(Intf_key ap_Key)
Check if the key passed in parameter is an array (contains brackets '{' and '}' ) ...
#define INTF_SUPINE_HEADIN_TRANSAXIAL
int IntfWriteHeaderMainData(const string &a_path, const Intf_fields &ap_IntfF, int vb)
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 IntfCheckKeyMatch(Intf_key ap_Key, const string &a_field)
Check if the key matches the string passed in parameter.
#define INTF_SUPINE_HEADIN_CORONAL
int IntfKeyGetArrayNbElts(Intf_key a_Key)
Return the number of elts in an Interfile array Key.
vector< FLTNB > image_duration
bool bed_position_provided
template int IntfKeyGetValueFromFile< uint32_t >(const string &a_pathToHeader, const string &a_key, uint32_t *ap_return, int a_nbElts, int a_mandatoryFlag)
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)
void SwapBytes(T *ap_type)
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 ...
template int IntfKeyGetValueFromFile< string >(const string &a_pathToHeader, const string &a_key, string *ap_return, int a_nbElts, int a_mandatoryFlag)
#define SCANNER_SPECT_PINHOLE
uint16_t ctr_to_ctr_separation
int IntfIsMHD(string a_pathToFile, vector< string > &ap_lPathToImgs)
Check if the string in argument contains the path to a Interfile metaheader.
string GetPathOfFile(const string &a_pathToFile)
Simply return the path to the directory of a file path string passed in parameter.
string IntfKeyGetPatientNameTag()
Recover datafile name(s) stored in sOutputManager in one string.
int IntfGetVoxIdxSHTOrientation(Intf_fields a_IF, int a_voxId)
Compute a voxel index corresponding to the default orientation (Sup/Hin/Trans) from the orientation...
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...
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 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...
vector< string > GetDataFileName()
string IntfKeyGetPixTypeStr()
Return the string corresponding to the nb of bytes in the type FLTNB.
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.
uint16_t nb_detector_heads
FLTNB GetFrameTimeStopInSec(int a_bed, int a_frame)
Get the frame time stop for the given bed, in seconds as a FLTNB.
int IntfWriteHeaderImgData(ofstream &ap_ofile, const Intf_fields &ap_IntfF, int vb)
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 GetNbTimeFrames()
Get the number of time frames.
INTNB GetNbVoxXYZ()
Get the total number of voxels.
#define INTF_SUPINE_FEETIN_TRANSAXIAL
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])
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...
#define INTF_PRONE_HEADIN_SAGITTAL
This class is designed to manage all dimensions and quantification related stuff. ...
void IntfToLowerCase(string *ap_str)
Set all characters of the string passed in parameter to lower case.
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...
FLTNB GetOffsetX()
Get the image offset along the X axis, in mm.
INTNB GetNbVoxX()
Get the number of voxels along the X axis.
int IntfGetPixelTypeAndReadData(Intf_fields a_IF, ifstream *ap_iFile, FLTNB *ap_outImgMatrix, FLTNB *ap_inImgMatrix, uint32_t *ap_offset, int a_nbVox, int a_verbose)
The purpose of this function is to call the templated ReadData() function with the data type correspo...
This group of functions manages Interfile image file format.
INTNB GetNbVoxZ()
Get the number of voxels along the Z axis.
template int IntfKeyGetValueFromFile< double >(const string &a_pathToHeader, const string &a_key, double *ap_return, int a_nbElts, int a_mandatoryFlag)
int GetNbRespGates()
Get the number of respiratory gates.
uint32_t nb_energy_windows
void IntfEraseSpaces(string *input_str)
Erase space, blank characters ((t,r,n)), and '!' before and after the characters in the string passed...
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)
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)
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)
FLTNB GetFrameDurationInSec(int a_bed, int a_frame)
Get the frame duration for the given bed, in seconds as a FLTNB.
#define INTF_PRONE_HEADIN_TRANSAXIAL
int IntfKeyGetMaxArrayKey(Intf_key ap_Key)
Return the maximum value from an array key (key value contains brackets '{,,}' )
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)
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< int64_t >(const string &a_pathToHeader, const string &a_key, int64_t *ap_return, int a_nbElts, int a_mandatoryFlag)
INTNB GetNbVoxY()
Get the number of voxels along the Y axis.
bool FLTNBIsEqual(FLTNB a, FLTNB b, FLTNB a_eps)
Comparison of FLTNB numbers.
void IntfAllocInterpImg(FLTNB **a2p_img, Intf_fields a_IF)
Allocate memory for an image matrix to recover an image to interpolate.
bool is_mtx_size_different
string originating_system