67 ifstream input_file(a_pathToHeader.c_str(), ios::in);
73 while(!input_file.eof())
75 getline(input_file, line);
85 Cerr(
"***** IntfKeyGetValueFromFile()-> Error : couldn't correctly read interfile key '"<< line <<
"' !" << endl);
96 Cerr(
"***** IntfKeyGetValueFromFile()-> Exception when trying to read tag '" << a_key <<
"' in file '" << a_pathToHeader <<
"'." << endl);
107 Cerr(
"***** IntfKeyGetValueFromFile() -> " << a_nbElts <<
" requested for interfile key " << a_key <<
" , but this key is not an array !" << endl);
115 Cerr(
"***** IntfKeyGetValueFromFile() -> Nb of elements to recover (=" << a_nbElts <<
") does not correspond to the number of elements found in the key '" 123 Cerr(
"***** IntfKeyGetValueFromFile() -> " << a_nbElts <<
" requested for interfile key " << a_key <<
" , but this key is not an array !" << endl);
134 if (a_mandatoryFlag > 0)
136 Cerr(
"***** IntfKeyGetValueFromFile()-> Error when reading Interfile '" << a_pathToHeader <<
"'. Key '" << a_key <<
"' was not found." << endl);
147 Cerr(
"***** IntfKeyGetValueFromFile()-> Couldn't find or read data-file '"<< a_pathToHeader <<
"' !" << endl);
154 template int IntfKeyGetValueFromFile<int>(
const string& a_pathToHeader,
const string& a_key,
int* ap_return,
int a_nbElts,
int a_mandatoryFlag);
156 template int IntfKeyGetValueFromFile<float>(
const string& a_pathToHeader,
const string& a_key,
float* ap_return,
int a_nbElts,
int a_mandatoryFlag);
162 template int IntfKeyGetValueFromFile<bool>(
const string& a_pathToHeader,
const string& a_key,
bool* ap_return,
int a_nbElts,
int a_mandatoryFlag);
184 uint16_t a_nbOccurrences)
186 ifstream input_file(a_pathToHeader.c_str(), ios::in);
188 uint16_t nb_occurences_cur =0;
193 while(!input_file.eof())
195 getline(input_file, line);
205 Cerr(
"***** IntfKeyGetValueFromFile()-> Error : couldn't correctly read interfile key '"<< line <<
"' !" << endl);
216 if(nb_occurences_cur < a_nbOccurrences)
226 Cerr(
"***** IntfKeyGetValueFromFile()-> Exception when trying to read tag '" << a_key <<
"' in file '" << a_pathToHeader <<
"'." << endl);
237 Cerr(
"***** IntfKeyGetValueFromFile() -> " << a_nbElts <<
" requested for interfile key " << a_key <<
" , but this key is not an array !" << endl);
245 Cerr(
"***** IntfKeyGetValueFromFile() -> Nb of elements to recover (=" << a_nbElts <<
") does not correspond to the number of elements found in the key '" 253 Cerr(
"***** IntfKeyGetValueFromFile() -> " << a_nbElts <<
" requested for interfile key " << a_key <<
" , but this key is not an array !" << endl);
264 if (a_mandatoryFlag > 0)
266 Cerr(
"***** IntfKeyGetValueFromFile()-> Error when reading Interfile '" << a_pathToHeader <<
"'. Key '" << a_key <<
"' was not found." << endl);
277 Cerr(
"***** IntfKeyGetValueFromFile()-> Couldn't find or read data-file '"<< a_pathToHeader <<
"' !" << endl);
308 if(vb >= 3)
Cout(
"IntfReadProjectionImage()-> Read Interfile header : "<< a_pathToHeaderFile << endl);
316 Cerr(
"***** IntfReadProjectionImage()-> Error : while trying to read the interfile header '"<< a_pathToHeaderFile <<
"' !" << endl);
323 int nb_tot_pixels = ap_IF->
mtx_size[0]
328 ifstream img_file(ap_IF->
path_to_image.c_str(), ios::binary | ios::in);
339 Cerr(
"***** IntfReadProjectionImage()-> Error occurred while trying to read the image file at the path: '"<< ap_IF->
path_to_image <<
"' !" << endl);
364 Cerr(
"***** IntfCheckDimensionsConsistency() -> Numbers of dimensions are not the same !" << endl);
368 for (
int dim=0; dim<((int)ImgFields1.
nb_dims); dim++)
373 Cerr(
"***** IntfCheckDimensionsConsistency() -> The sizes of the dimension " << dim+1 <<
" are not the same !" << endl);
378 for (
int dim=0; dim<std::min(3,((
int)ImgFields1.
nb_dims)); dim++)
383 Cerr(
"***** IntfCheckDimensionsConsistency() -> Voxel sizes of dimension " << dim+1 <<
" are not the same !" << endl);
390 Cerr(
"***** IntfCheckDimensionsConsistency() -> Slice thicknesses are not the same !" << endl);
406 if (vb>=2)
Cout(
"IntfLoadImageFromScratch() -> Read Interfile image '" << a_pathToHeaderFile <<
"'" << endl);
414 Cerr(
"***** IntfLoadImageFromScratch() -> A problem occurred while trying to read the interfile header '" << a_pathToHeaderFile <<
"' !" << endl);
421 Cerr(
"***** IntfLoadImageFromScratch() -> Cannot handle a number of dimensions higher than 3 !" << endl);
426 for (
int d=0; d<ap_ImgFields->
nb_dims; d++)
if (ap_ImgFields->
mtx_size[d]==0)
428 Cerr(
"***** IntfLoadImageFromScratch() -> Number of voxels for dimension #" << d <<
" is 0, so has not been read correctly in header file '" << a_pathToHeaderFile <<
"' !" << endl);
432 for (
int d=0; d<ap_ImgFields->
nb_dims; d++)
if (ap_ImgFields->
vox_size[d]<=0.)
434 Cerr(
"***** IntfLoadImageFromScratch() -> Voxel size for dimension #" << d <<
" is negative, so has not been read correctly in header file '" << a_pathToHeaderFile <<
"' !" << endl);
445 ifstream img_file(ap_ImgFields->
path_to_image.c_str(), ios::binary | ios::in);
448 Cerr(
"***** IntfLoadImageFromScratch() -> Input image file '" << ap_ImgFields->
path_to_image <<
"' is missing or corrupted !" << endl);
469 if (vb>=2)
Cout(
"IntfWriteImageFromIntfFields() -> Write 3D image with output base name '" << a_pathToImg <<
"'" << endl);
474 Cerr(
"***** IntfWriteImageFromIntfFields() -> Error : while trying to write the interfile header '"<< a_pathToImg <<
"' !" << endl);
479 string path_to_image = a_pathToImg;
480 path_to_image.append(
".img");
488 Cerr(
"***** IntfWriteImageFromIntfFields() -> Error : while trying to write the interfile image '"<< path_to_image <<
"' !" << endl);
508 if (a_verbose>=
VERBOSE_DETAIL)
Cout(
"oInterfileIO::IntfReadImage() -> Read image from interfile header '" << a_pathToHeaderFile <<
"'" << endl);
517 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while trying to read the interfile header '" << a_pathToHeaderFile <<
"' !" << endl);
524 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while checking consistencies between reconstruction parameters and interfile keys from header '" 525 << a_pathToHeaderFile <<
"' !" << endl);
530 FLTNB* pimg_erp = NULL;
535 ifstream img_file(Img_fields.
path_to_image.c_str(), ios::binary | ios::in);
543 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while reading data and eventually interpolating from the IntfGetPixelTypeAndReadData() function !" << endl);
549 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while trying to open the image file '" << Img_fields.
path_to_image <<
"' !" << endl);
551 if (pimg_erp)
delete[] pimg_erp;
556 if (pimg_erp)
delete[] pimg_erp;
567 FLTNB**** a4p_ImgMatrix,
572 if (a_verbose >= 5)
Cout(
"oInterfileIO::IntfReadImage() -> Read image from interfile header '" << a_pathToHeaderFile <<
"'" << endl);
579 vector<string> lpath_to_headers;
583 if (
IntfIsMHD(a_pathToHeaderFile, lpath_to_headers) < 0 )
585 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while trying to read the interfile header '" << a_pathToHeaderFile <<
"' in IntfIsMHD() function !" << endl);
590 if (lpath_to_headers.size() == 1)
595 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while trying to read the interfile header '" << a_pathToHeaderFile <<
"' !" << endl);
601 Cerr(
"***** oInterfileIO::IntfReadImage() -> A error occurred while checking consistencies between reconstruction parameters and interfile keys in the header '" << a_pathToHeaderFile <<
"' !" << endl);
605 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 occurred 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 occurred while trying to read the interfile metaheader '" << a_pathToHeaderFile <<
"' !" << endl);
656 if (lpath_to_headers.size() != (uint32_t)(dims[0]*dims[1]*dims[2]+ap_ID->
GetNbFramesToSkip()))
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;
668 for(
int d2=0 ; d2<dims[1] ; d2++)
669 for(
int d3=0 ; d3<dims[2] ; d3++)
671 int idx_img = d1*dims[1]*dims[2] + d2*dims[2] + d3;
675 if (
IntfReadHeader(lpath_to_headers[idx_img], &Img_fields, a_verbose) )
677 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while trying to read the interfile header '" << lpath_to_headers[idx_img] <<
"' !" << endl);
683 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while checking consistencies between reconstruction parameters and interfile keys in the header '" 684 << lpath_to_headers[idx_img] <<
"' !" << endl);
688 ifstream img_file(Img_fields.
path_to_image.c_str(), ios::binary | ios::in);
696 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while reading data and eventually interpolating from the IntfGetPixelTypeAndReadData() function !" << endl);
698 if (pimg_erp)
delete[] pimg_erp;
704 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while trying to read the image file '"<< Img_fields.
path_to_image <<
"' !" << endl);
706 if (pimg_erp)
delete[] pimg_erp;
711 if (pimg_erp)
delete[] pimg_erp;
734 FLTNB** a2p_ImgMatrix,
740 if (a_verbose >= 5)
Cout(
"IntfReadImgDynCoeffFile" << endl);
747 vector<string> lpath_to_headers;
751 if(
IntfIsMHD(a_pathToHeaderFile, lpath_to_headers) <0)
753 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> an error occurred while trying to read the interfile header '" << a_pathToHeaderFile <<
"' !" << endl);
758 if(lpath_to_headers.size() == 1)
763 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while trying to read the interfile header '" << a_pathToHeaderFile <<
"' !" << endl);
769 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while checking consistencies between reconstruction parameters and interfile keys in the header '" << a_pathToHeaderFile <<
"' !" << endl);
773 FLTNB* pimg_erp = NULL;
776 ifstream img_file(Img_fields.
path_to_image.c_str(), ios::binary | ios::in);
783 for (
int bf=0 ; bf<a_nbFbasis ; bf++)
787 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while reading from file stream and eventually interpolating !" << endl);
789 if (pimg_erp)
delete[] pimg_erp;
796 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while trying to read the image file '" << Img_fields.
path_to_image <<
"' !" << endl);
798 if (pimg_erp)
delete[] pimg_erp;
802 if (pimg_erp)
delete[] pimg_erp;
811 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while trying to read the interfile metaheader '" << a_pathToHeaderFile <<
"' !" << endl);
815 if (lpath_to_headers.size() != (uint32_t)a_nbFbasis)
817 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> Number of interfile images (" << lpath_to_headers.size() <<
818 ") not consistent with the number of parametric images (" << a_nbFbasis<<
") !" << endl);
822 FLTNB* pimg_erp = NULL;
825 for (
int bf=0 ; bf<a_nbFbasis ; bf++)
828 if (
IntfReadHeader(lpath_to_headers[bf], &Img_fields, a_verbose) )
830 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> an error occurred while trying to read interfile header '" << a_pathToHeaderFile <<
"' !" << endl);
832 if (pimg_erp)
delete[] pimg_erp;
838 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while checking consistencies between reconstruction parameters and interfile keys in the header '"<< a_pathToHeaderFile <<
"' !" << endl);
840 if (pimg_erp)
delete[] pimg_erp;
844 ifstream img_file(Img_fields.
path_to_image.c_str(), ios::binary | ios::in);
852 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while reading image stream and eventually interpolating !" << endl);
854 if (pimg_erp)
delete[] pimg_erp;
860 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while trying to read the image file '" << Img_fields.
path_to_image <<
"' !" << endl);
862 if (pimg_erp)
delete[] pimg_erp;
867 if (pimg_erp)
delete[] pimg_erp;
890 uint32_t nb_vox = a_IF.
mtx_size[0] *
895 *a2p_img =
new FLTNB[ nb_vox ];
896 ::memset(*a2p_img, 0,
sizeof(
FLTNB) * nb_vox);
922 if(vb >= 5)
Cout(
"IntfCheckConsistency()" << endl);
929 Cerr(
"***** IntfCheckConsistency()-> Error : some mandatory keys not initialized. Cannot read the interfile image !" << endl);
932 Cerr(
" Error when trying to read path to image data" << endl);
934 Cerr(
" Error when trying to read data voxel type " << endl);
936 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);
944 Cerr(
"***** IntfCheckConsistency()-> WARNING : No information found about voxel size ('scaling factor (mm/pixel)' tags.). Missing voxel sizes will be set to 1mm !" << endl);
978 Cerr(
"***** IntfCheckConsistency()-> Error : Image dimensions don't match reconstructions dimensions/voxel sizes" << endl);
979 Cerr(
" and linear interpolation is disabled (a_lerpFlag is false) !" << endl);
980 Cerr(
"***** Recovered image dimensions (x;y;z): "<< ap_IF->
mtx_size[0] <<
" ; "<< ap_IF->
mtx_size[1] <<
" ; " << ap_IF->
mtx_size[2] << endl);
998 FLTNB* ap_outImgMatrix,
999 FLTNB* ap_inImgMatrix,
1000 uint32_t* ap_offset,
1004 if (a_verbose >= 5)
Cout(
"oInterfileIO::IntfGetPixelTypeAndReadData() " << endl);
1013 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &flt);
1018 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &db);
1024 Cerr(
"***** oInterfileIO::IntfGetPixelTypeAndReadData() -> The long double format is not the same for this image file and for this platform !" << endl);
1028 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &db);
1035 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &s_int);
1040 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &s_int);
1045 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &s_int);
1050 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &s_int);
1058 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &u_int);
1063 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &u_int);
1068 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &u_int);
1073 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &u_int);
1079 Cerr(
"***** oInterfileIO::IntfGetPixelTypeAndReadData() -> An error occurred when trying to read data through the IntfReadData() function !" << endl);
1094 FLTNB* ap_outImgMatrix,
1095 FLTNB* ap_inImgMatrix,
1101 if (a_verbose >= 5)
Cout(
"oInterfileIO::IntfReadData() -> Read data from file stream and eventually interpolate" << endl);
1111 pimg = ap_inImgMatrix;
1116 pimg = ap_outImgMatrix;
1120 bytes = (T*)malloc(nb_vox*
sizeof(T));
1122 ap_iFile->seekg(*a_offset);
1124 ap_iFile->read((
char*)bytes, nb_vox*
sizeof(T));
1126 if (!ap_iFile->good())
1128 if (ap_iFile->eof())
Cerr(
"***** oInterfileIO::IntfReadData() -> Not enough data in the file stream !" << endl);
1129 else Cerr(
"***** oInterfileIO::IntfReadData() -> An error occurred while reading from file stream !" << endl);
1135 for (
int v=0; v<nb_vox; v++)
1151 *a_offset +=
sizeof(T);
1169 Cerr(
"***** oInterfileIO::IntfReadData() -> An error occurred while interpolating the input image to the reconstruction dimensions !" << endl);
1198 const uint32_t ap_iDimVox[3],
const uint32_t ap_oDimVox[3],
1199 const FLTNB ap_iSizeVox[3],
const FLTNB ap_oSizeVox[3],
1200 const FLTNB ap_iOffVox[3],
const FLTNB ap_oOffVox[3] )
1405 FLTNB const posOldImage[] = {-((
FLTNB)(ap_iDimVox[0]))*ap_iSizeVox[0]*((
FLTNB)0.5) ,
1406 -((
FLTNB)(ap_iDimVox[1]))*ap_iSizeVox[1]*((
FLTNB)0.5) ,
1407 -((
FLTNB)(ap_iDimVox[2]))*ap_iSizeVox[2]*((
FLTNB)0.5) };
1409 FLTNB const posNewImage[] = {-((
FLTNB)(ap_oDimVox[0]))*ap_oSizeVox[0]*((
FLTNB)0.5) ,
1410 -((
FLTNB)(ap_oDimVox[1]))*ap_oSizeVox[1]*((
FLTNB)0.5) ,
1411 -((
FLTNB)(ap_oDimVox[2]))*ap_oSizeVox[2]*((
FLTNB)0.5) };
1423 uint32_t
const iDimVoxPad[]
1425 ap_iDimVox[ 0 ] + 2,
1426 ap_iDimVox[ 1 ] + 2,
1430 uint32_t
const nElts = iDimVoxPad[ 0 ] *
1436 ::memset( pPadIData, 0,
sizeof(
FLTNB ) * nElts );
1438 for( uint32_t k = 0; k < ap_iDimVox[ 2 ]; ++k )
1439 for( uint32_t j = 0; j < ap_iDimVox[ 1 ]; ++j )
1440 for( uint32_t i = 0; i < ap_iDimVox[ 0 ]; ++i )
1442 pPadIData[ ( i + 1 ) + ( j + 1 ) * iDimVoxPad[ 0 ]
1443 + ( k + 1 ) * iDimVoxPad[ 0 ] * iDimVoxPad[ 1 ] ] =
1444 ap_iImg[ i + j * ap_iDimVox[ 0 ]
1445 + k * ap_iDimVox[ 0 ] * ap_iDimVox[ 1 ] ];
1450 FLTNB const boundMin[]
1452 posOldImage[ 0 ] - ap_iSizeVox[ 0 ] * ((
FLTNB)0.5),
1453 posOldImage[ 1 ] - ap_iSizeVox[ 1 ] * ((
FLTNB)0.5),
1454 posOldImage[ 2 ] - ap_iSizeVox[ 2 ] * ((
FLTNB)0.5)
1457 FLTNB const boundMax[]
1459 posOldImage[ 0 ] + ((
FLTNB)ap_iDimVox[ 0 ]) * ap_iSizeVox[ 0 ]
1460 + ap_iSizeVox[ 0 ] * ((
FLTNB)0.5),
1461 posOldImage[ 1 ] + ((
FLTNB)ap_iDimVox[ 1 ]) * ap_iSizeVox[ 1 ]
1462 + ap_iSizeVox[ 1 ] * ((
FLTNB)0.5),
1463 posOldImage[ 2 ] + ((
FLTNB)ap_iDimVox[ 2 ]) * ap_iSizeVox[ 2 ]
1464 + ap_iSizeVox[ 2 ] * ((
FLTNB)0.5)
1471 for( uint32_t i = 0; i < 3; ++i )
1473 pOldCoordCenter[ i ] =
new FLTNB[ iDimVoxPad[ i ] ];
1475 for( uint32_t j = 0; j < iDimVoxPad[ i ]; ++j )
1477 pOldCoordCenter[ i ][ j ] = posOldImage[ i ] - ap_iSizeVox[ i ] / 2.0
1478 + j * ap_iSizeVox[ i ];
1485 for( uint32_t i = 0; i < 3; ++i )
1487 pNewCoordCenter[ i ] =
new FLTNB[ ap_oDimVox[ i ] ];
1489 for( uint32_t j = 0; j < ap_oDimVox[ i ]; ++j )
1491 pNewCoordCenter[ i ][ j ] = posNewImage[ i ] + ap_oSizeVox[ i ] / 2.0
1492 + j * ap_oSizeVox[ i ];
1497 FLTNB const invSizeX = 1.0 / ap_iSizeVox[ 0 ];
1498 FLTNB const invSizeY = 1.0 / ap_iSizeVox[ 1 ];
1499 FLTNB const invSizeZ = 1.0 / ap_iSizeVox[ 2 ];
1505 for( uint32_t k = 0; k < ap_oDimVox[ 2 ]; ++k )
1508 FLTNB const z = pNewCoordCenter[ 2 ][ k ];
1509 if( z < boundMin[ 2 ] || z > boundMax[ 2 ] )
continue;
1512 int32_t
const zBin = ( z - boundMin[ 2 ] ) * invSizeZ;
1515 FLTNB const zComposantI0 = invSizeZ * ( pOldCoordCenter[ 2 ][ zBin + 1 ] - z );
1516 FLTNB const zComposantI1 = invSizeZ * ( z - pOldCoordCenter[ 2 ][ zBin ] );
1518 for( uint32_t j = 0; j < ap_oDimVox[ 1 ]; ++j )
1521 FLTNB const y = pNewCoordCenter[ 1 ][ j ];
1522 if( y < boundMin[ 1 ] || y > boundMax[ 1 ] )
continue;
1525 int32_t
const yBin = ( y - boundMin[ 1 ] ) * invSizeY;
1528 FLTNB const yComposantI0 = invSizeY * ( pOldCoordCenter[ 1 ][ yBin + 1 ]
1530 FLTNB const yComposantI1 = invSizeY * ( y
1531 - pOldCoordCenter[ 1 ][ yBin ] );
1533 for( uint32_t i = 0; i < ap_oDimVox[ 0 ]; ++i )
1536 FLTNB const x = pNewCoordCenter[ 0 ][ i ];
1537 if( x < boundMin[ 0 ] || x > boundMax[ 0 ] )
continue;
1540 int32_t
const xBin = ( x - boundMin[ 0 ] ) * invSizeX;
1543 FLTNB const xComposantI0 = invSizeX * (
1544 pOldCoordCenter[ 0 ][ xBin + 1 ] - x );
1545 FLTNB const xComposantI1 = invSizeX * ( x
1546 - pOldCoordCenter[ 0 ][ xBin ] );
1550 for( uint32_t kk = 0; kk < 2; ++kk )
1552 for( uint32_t jj = 0; jj < 2; ++jj )
1554 for( uint32_t ii = 0; ii < 2; ++ii )
1556 pKernelData[ ii + jj * 2 + kk * 2 * 2 ] =
1559 ( yBin + jj ) * iDimVoxPad[ 0 ] +
1560 ( zBin + kk ) * iDimVoxPad[ 0 ] * iDimVoxPad[ 1 ]
1568 FLTNB const xInterpVal0 = pKernelData[ 0 ] * xComposantI0 +
1569 pKernelData[ 1 ] * xComposantI1;
1571 FLTNB const xInterpVal1 = pKernelData[ 2 ] * xComposantI0 +
1572 pKernelData[ 3 ] * xComposantI1;
1574 FLTNB const xInterpVal2 = pKernelData[ 4 ] * xComposantI0 +
1575 pKernelData[ 5 ] * xComposantI1;
1577 FLTNB const xInterpVal3 = pKernelData[ 6 ] * xComposantI0 +
1578 pKernelData[ 7 ] * xComposantI1;
1581 FLTNB const yInterpVal0 = xInterpVal0 * yComposantI0 +
1582 xInterpVal1 * yComposantI1;
1584 FLTNB const yInterpVal1 = xInterpVal2 * yComposantI0 +
1585 xInterpVal3 * yComposantI1;
1588 FLTNB const interpValTot = yInterpVal0 * zComposantI0 +
1589 yInterpVal1 * zComposantI1;
1591 ap_oImg[ i + j * ap_oDimVox[ 0 ]
1592 + k * ap_oDimVox[ 0 ] * ap_oDimVox[ 1 ] ] = interpValTot;
1598 for( uint32_t i = 0; i < 3; ++i )
1600 delete[] pOldCoordCenter[ i ];
1601 delete[] pNewCoordCenter[ i ];
1603 delete[] pOldCoordCenter;
1604 delete[] pNewCoordCenter;
1606 delete[] pKernelData;
1634 if (vb>=3)
Cout(
"IntfWriteImgFile (with Intf_fields)" << endl);
1639 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile header for'"<< a_pathToImg <<
"' !" << endl);
1643 string path_to_image = a_pathToImg;
1644 path_to_image.append(
".img");
1649 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile image '"<< path_to_image <<
"' !" << endl);
1678 if (vb>=3)
Cout(
"IntfWriteImgFile (3D image)" << endl);
1686 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile header for'"<< a_pathToImg <<
"' !" << endl);
1690 string path_to_image = a_pathToImg;
1691 path_to_image.append(
".img");
1696 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile image '"<< path_to_image <<
"' !" << endl);
1728 if (vb>=3)
Cout(
"IntfWriteProjFile ..." << endl);
1731 vector<string> lpath_to_images;
1732 lpath_to_images.push_back(a_pathToImg);
1736 Cerr(
"***** IntfWriteProjFile()-> Error : while trying to write the interfile header for'"<< lpath_to_images[0] <<
"' !" << endl);
1749 Cerr(
"***** IntfWriteFile()-> Error : while trying to write the interfile image '"<< a_pathToImg <<
"' !" << endl);
1783 if (vb>=3)
Cout(
"IntfWriteImgDynCoeffFile ..." << endl);
1795 vector<string> lpath_to_images;
1797 if(p_outputMgr->
MergeDynImages()==
true || a_mergeDynImgFlag==
true)
1799 lpath_to_images.push_back(a_pathToImg);
1800 lpath_to_images[0].append(
"_par");
1804 Cerr(
"***** IntfWriteImgDynCoeffFile()-> Error : while trying to write the interfile header for'"<< lpath_to_images[0] <<
"' !" << endl);
1812 for(
int bf=0 ; bf<a_nbParImgs ; bf++)
1815 lpath_to_images.push_back(a_pathToImg);
1818 stringstream ss; ss << bf + 1;
1819 lpath_to_images[idx_file].append(
"_par").append(ss.str());
1822 string path_to_hdr = lpath_to_images[idx_file] +
".hdr";
1823 string path_to_img = lpath_to_images[idx_file] +
".img";
1827 ifstream fcheck(path_to_hdr.c_str());
1832 string dos_instruction =
"del " + path_to_hdr;
1833 system(dos_instruction.c_str());
1835 remove(path_to_hdr.c_str());
1839 ofstream ofile(path_to_hdr.c_str(), ios::out | ios::app);
1840 ofile << setprecision(std::numeric_limits<FLTNB>::digits10 +1);
1841 ofile <<
"!INTERFILE := " << endl;
1842 ofile <<
"!name of data file := " <<
GetFileFromPath(path_to_img) << endl;
1844 ofile <<
"!data offset in bytes := " << 0 << endl;
1846 ofile <<
"!type of data := Dynamic" << endl;
1850 Cerr(
"***** IntfWriteImgDynCoeffFile()-> Error : while trying to write the interfile header for'"<< lpath_to_images[idx_file] <<
"' !" << endl);
1854 ofile <<
"!END OF INTERFILE := " << endl;
1862 string pathToDynCoeffMHD;
1863 pathToDynCoeffMHD=a_pathToImg.c_str();
1864 pathToDynCoeffMHD.append(
"_par");
1865 if(
IntfWriteMHD(pathToDynCoeffMHD, lpath_to_images, Img_fields, ap_ID, vb) )
1867 Cerr(
"***** IntfWriteImgDynCoeffFile()-> Error : while trying to write the interfile header '"<< a_pathToImg <<
"' !" << endl);
1876 dims[0] = a_nbParImgs;
1881 Cerr(
"***** IntfWriteImgDynCoeffFile()-> Error : while trying to write the interfile image '"<< a_pathToImg <<
"' !" << endl);
1912 if (vb>=3)
Cout(
"IntfWriteImgFile (static/dynamic image) ..." << endl);
1923 vector<string> lpath_to_images;
1927 lpath_to_images.push_back(a_pathToImg);
1931 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile header for'"<< lpath_to_images[0] <<
"' !" << endl);
1947 lpath_to_images.push_back(a_pathToImg);
1952 stringstream ss; ss << fr + 1;
1953 lpath_to_images[idx_file].append(
"_fr").append(ss.str());
1958 stringstream ss; ss << rg + 1;
1959 lpath_to_images[idx_file].append(
"_rg").append(ss.str());
1964 stringstream ss; ss << cg + 1;
1965 lpath_to_images[idx_file].append(
"_cg").append(ss.str());
1969 string path_to_hdr = lpath_to_images[idx_file];
1970 string path_to_img = lpath_to_images[idx_file];
1974 ifstream fcheck(path_to_hdr.append(
".hdr").c_str());
1979 string dos_instruction =
"del " + path_to_hdr;
1980 system(dos_instruction.c_str());
1982 remove(path_to_hdr.c_str());
1986 ofstream ofile(path_to_hdr.c_str(), ios::out | ios::app);
1987 ofile << setprecision(std::numeric_limits<FLTNB>::digits10 +1);
1988 ofile <<
"!INTERFILE := " << endl;
1991 ofile <<
"!name of data file := " <<
GetFileFromPath(path_to_img).append(
".img") << endl;
1993 ofile <<
"!data offset in bytes := " << 0 << endl;
1995 ofile <<
"!type of data := Dynamic" << endl;
1999 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile header for'"<< lpath_to_images[idx_file] <<
"' !" << endl);
2009 ofile <<
"!END OF INTERFILE := " << endl;
2018 if(
IntfWriteMHD(a_pathToImg, lpath_to_images, Img_fields, ap_ID, vb) )
2020 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile header '"<< a_pathToImg <<
"' !" << endl);
2037 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile image '"<< a_pathToImg <<
"' !" << endl);
2055 if (vb>=3)
Cout(
"IntfWriteDynBasisCoefImgFile (dynamic basis coefficients image) ..." << endl);
2061 vector<string> lpath_to_images;
2072 lpath_to_images.push_back(a_pathToImg);
2076 stringstream ss; ss << tbf + 1;
2077 lpath_to_images[idx_file].append(
"_tbf").append(ss.str());
2082 stringstream ss; ss << rbf + 1;
2083 lpath_to_images[idx_file].append(
"_rbf").append(ss.str());
2088 stringstream ss; ss << cbf + 1;
2089 lpath_to_images[idx_file].append(
"_cbf").append(ss.str());
2092 string path_to_hdr = lpath_to_images[idx_file];
2093 string path_to_img = lpath_to_images[idx_file];
2096 ifstream fcheck(path_to_hdr.append(
".hdr").c_str());
2101 string dos_instruction =
"del " + path_to_hdr;
2102 system(dos_instruction.c_str());
2104 remove(path_to_hdr.c_str());
2108 ofstream ofile(path_to_hdr.c_str(), ios::out | ios::app);
2109 ofile << setprecision(std::numeric_limits<FLTNB>::digits10 +1);
2110 ofile <<
"!INTERFILE := " << endl;
2111 ofile <<
"!name of data file := " <<
GetFileFromPath(path_to_img).append(
".img") << endl;
2113 ofile <<
"!data offset in bytes := " << 0 << endl;
2115 ofile <<
"!type of data := Dynamic" << endl;
2118 Cerr(
"***** IntfWriteWholeDynBasisCoeffImgFile()-> Error : while trying to write the interfile header for'"<< lpath_to_images[idx_file] <<
"' !" << endl);
2122 ofile <<
"image duration (sec) := 1" << endl;
2123 ofile <<
"image start time (sec) := 0" << endl;
2124 ofile <<
"!END OF INTERFILE := " << endl;
2139 Cerr(
"***** IntfWriteWholeDynBasisCoeffImgFile()-> Error : while trying to write the interfile image '"<< a_pathToImg <<
"' !" << endl);
2225 int IntfIsMHD(
string a_pathToFile, vector<string> &ap_lPathToImgs)
2228 ifstream hfile(a_pathToFile.c_str(), ios::in);
2236 getline(hfile, line);
2239 if(line.empty())
continue;
2247 Cerr(
"***** IntfIsMHD()-> Error : couldn't correctly read interfile key '"<< line <<
"' !" << endl);
2259 uint16_t nb_datasets = 0;
2262 Cerr(
"***** IntfIsMHD()-> Error when trying to read data from 'total number of data set' key. Recovered value = " << Key.
kvalue << endl);
2270 string file_key =
"";
2271 string file_keyp =
"%";
2272 string file_key_space =
"";
2273 string file_keyp_space =
"%";
2274 file_key_space.append(
"data set [").append(ss.str()).append(
"]");
2275 file_keyp_space.append(
"data set [").append(ss.str()).append(
"]");
2276 file_key.append(
"data set[").append(ss.str()).append(
"]");
2277 file_keyp.append(
"data set[").append(ss.str()).append(
"]");
2284 getline(hfile, line);
2287 if(line.empty())
continue;
2292 Cerr(
"***** IntfIsMHD()-> Error : couldn't correctly read interfile key '"<< line <<
"' !" << endl);
2310 Cerr(
"***** IntfIsMHD()-> Error : when trying to read Interfile array key: '"<< line <<
"' !" << endl);
2313 else if(nb_elts != 3)
2315 Cerr(
"***** IntfIsMHD()-> Error : when trying to read Interfile array key: '"<< line <<
"' !" << endl);
2316 Cerr(
" 3 elements are expected following the format {xxx, path_to_the_img_file, xxx} (xxx = ignored data)" << endl);
2322 Cerr(
"***** IntfIsMHD()-> Error : when trying to read Interfile array key: '"<< line <<
"' !" << endl);
2325 ap_lPathToImgs.at(file_idx).append(elts_str[1]);
2328 ap_lPathToImgs.at(file_idx).append(Key.
kvalue);
2336 file_key.append(
"data set [").append(ss.str()).append(
"]");
2337 file_keyp.append(
"data set [").append(ss.str()).append(
"]");
2343 if(nb_datasets != ap_lPathToImgs.size())
2346 Cerr(
"***** IntfIsMHD()-> The number of recovered file in the metaheader ("<<ap_lPathToImgs.size()<<
")");
2347 Cerr(
"does not correspond to the expected number of datasets ("<<nb_datasets<<
")!"<< endl);
2358 Cerr(
"***** IntfIsMHD()-> Error : couldn't read header file '"<< a_pathToFile <<
"' !" << endl);
2364 ap_lPathToImgs.push_back(a_pathToFile);
2387 const vector<string>& ap_lPathToImgs,
2393 string path_to_mhd_file = a_pathToMhd;
2394 path_to_mhd_file.append(
".mhd");
2395 ofstream ofile(path_to_mhd_file.c_str(), ios::out);
2396 ofile << setprecision(std::numeric_limits<FLTNB>::digits10 +1);
2404 ofile <<
"!INTERFILE := " << endl;
2406 ofile << endl <<
"!GENERAL DATA := " << endl;
2407 ofile <<
"data description:=image" << endl;
2408 ofile <<
"!originating system := " << p_scanMgr->
GetScannerName() << endl;
2411 if (ap_ID->
GetNbBeds()>1) ofile <<
"number of bed positions := " << ap_ID->
GetNbBeds() << endl;
2413 else ofile <<
"horizontal bed relative position (mm) := " << ap_ID->
GetBedPosition(0) << endl;
2415 ofile << endl <<
"%DATA MATRIX DESCRIPTION:=" << endl;
2416 ofile <<
"number of time frames := " << a_IntfF.
nb_time_frames << endl;
2417 ofile <<
"number of time windows := " << a_IntfF.
nb_resp_gates *
2419 ofile <<
"number of respiratory gates := " << a_IntfF.
nb_resp_gates << endl;
2420 ofile <<
"number of cardiac gates := " << a_IntfF.
nb_card_gates << endl;
2422 ofile << endl <<
"%DATA SET DESCRIPTION:="<< endl;
2425 ofile <<
"!total number of data sets:=" << nb_imgs << endl;
2428 if(ap_lPathToImgs.size() != nb_imgs)
2430 Cerr(
"***** IntfWriteMHD()-> Error : nb of provided string inconsistent with the expected number of dynamic images: '"<< nb_imgs <<
"' !" << endl);
2435 for(
int ds=0 ; ds<nb_imgs ; ds++)
2437 string path_to_header = ap_lPathToImgs.at(ds);
2438 ofile <<
"%data set ["<<ds+1<<
"]:={0," <<
GetFileFromPath(path_to_header).append(
".hdr") <<
",UNKNOWN}"<< endl;
2443 Cerr(
"***** IntfWriteMHD()-> Error : couldn't find output Metaheader interfile '"<< path_to_mhd_file <<
"' !" << endl);
2482 Cout(
"--------------------------------------------------------------- " << endl);
2483 Cout(
"IntfReadHeader()-> Start reading header interfile " << a_pathToHeaderFile << endl);
2484 Cout(
"--------------------------------------------------------------- " << endl);
2489 ifstream input_file(a_pathToHeaderFile.c_str(), ios::in);
2495 while(!input_file.eof())
2497 getline(input_file, line);
2509 Cerr(
"***** ReadIntfHeader()-> Error : couldn't correctly read interfile key '"<< line <<
"' !" << endl);
2513 if (vb >=10)
Cout(
"ReadIntfHeader()-> Key " << Key.
kcase << endl);
2532 if ( Key.
kvalue.size()>0 )
2544 string header_file_directory =
GetPathOfFile(a_pathToHeaderFile);
2550 Cerr(
"***** ReadIntfHeader()-> Error : path to interfile image file is empty !" << endl);
2565 if (endianness ==
"littleendian")
2579 Cerr(
"***** ReadIntfHeader()-> Warning : data_offset value was already set to " << ap_IF->
data_offset << endl);
2580 Cerr(
"***** The header may contain both 'data offset in bytes' and 'data starting block' fields " << endl);
2585 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'data starting block' key. Recovered value = " << Key.
kvalue << endl);
2600 Cerr(
"***** ReadIntfHeader()-> Warning : data_offset value was already set to " << ap_IF->
data_offset << endl);
2601 Cerr(
"***** The header may contain both 'data offset in bytes' and 'data starting block' fields " << endl);
2606 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'data offset in bytes' key. Recovered value = " << Key.
kvalue << endl);
2618 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number format' key. Recovered value = " << Key.
kvalue << endl);
2629 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'originating system' key. Recovered value = " << Key.
kvalue << endl);
2640 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'bed relative position (mm)' key. Recovered value = " << Key.
kvalue << endl);
2651 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [1]' key. Recovered value = " << Key.
kvalue << endl);
2662 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [2]' key. Recovered value = " << Key.
kvalue << endl);
2679 Cerr(
"***** ReadIntfHeader()-> Array reading for 'matrix size [3]' key not implemented yet. Single value expected." << endl);
2686 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [3]' key. Recovered value = " << Key.
kvalue << endl);
2708 Cerr(
"***** ReadIntfHeader()-> Array reading for 'matrix size [4]' key not implemented yet. Single value expected." << endl);
2717 Cerr(
"***** ReadIntfHeader()-> WARNING : both 'number of time frames' and 'matrix size [4]' keys have been provided");
2718 Cerr(
" 'number of time frames' selected by default" << endl);
2722 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [4]' key. Recovered value = " << Key.
kvalue << endl);
2741 Cerr(
"***** ReadIntfHeader()-> Array reading for 'matrix size [5]' key not implemented yet. Single value expected." << endl);
2748 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [5]' key. Recovered value = " << Key.
kvalue << endl);
2766 Cerr(
"***** ReadIntfHeader()-> Array reading for 'matrix size [6]' key not implemented yet. Single value expected." << endl);
2773 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [6]' key. Recovered value = " << Key.
kvalue << endl);
2791 Cerr(
"***** ReadIntfHeader()-> Array reading for 'matrix size [7]' key not implemented yet. Single value expected." << endl);
2798 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [7]' key. Recovered value = " << Key.
kvalue << endl);
2812 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'scaling factor (mm/pixel) [1]' key. Recovered value = " << Key.
kvalue << endl);
2824 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'scaling factor (mm/pixel) [2]' key. Recovered value = " << Key.
kvalue << endl);
2837 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'scaling factor (mm/pixel) [3]' key. Recovered value = " << Key.
kvalue << endl);
2851 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from one of the following key :" << endl);
2852 Cerr(
"***** 'first pixel offset (mm) [1]'" << Key.
kvalue << endl);
2853 Cerr(
"***** 'origin (mm) [1]'"<< endl);
2854 Cerr(
"***** 'offset [1]'" << Key.
kvalue << endl);
2855 Cerr(
"***** Recovered value = " << Key.
kvalue << endl);
2869 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from one of the following key :" << endl);
2870 Cerr(
"***** 'first pixel offset (mm) [2]'" << Key.
kvalue << endl);
2871 Cerr(
"***** 'origin (mm) [2]'"<< endl);
2872 Cerr(
"***** 'offset [2]'" << Key.
kvalue << endl);
2873 Cerr(
"***** Recovered value = " << Key.
kvalue << endl);
2887 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from one of the following key :" << endl);
2888 Cerr(
"***** 'first pixel offset (mm) [3]'" << Key.
kvalue << endl);
2889 Cerr(
"***** 'origin (mm) [3]'"<< endl);
2890 Cerr(
"***** 'offset [3]'" << Key.
kvalue << endl);
2891 Cerr(
"***** Recovered value = " << Key.
kvalue << endl);
2904 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'slice thickness (pixels)' key. Recovered value = " << Key.
kvalue << endl);
2916 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'centre-centre slice separation (pixels)' key.");
2917 Cerr(
" Recovered value = " << Key.
kvalue << endl);
2920 Cerr(
"***** ReadIntfHeader()-> WARNING : 'centre-centre slice separation (pixels)' has no use in the current implementation !"<< endl);
2931 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of time frames' or 'number of frame groups' keys.");
2932 Cerr(
"Recovered value = " << Key.
kvalue << endl);
2944 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of respiratory gates' key. Recovered value = " << Key.
kvalue << endl);
2956 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of cardiac gates' key. Recovered value = " << Key.
kvalue << endl);
2967 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'total number of images' key. Recovered value = " << Key.
kvalue << endl);
2978 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of bytes per pixel' key. Recovered value = " << Key.
kvalue << endl);
2988 string slice_orientation;
2991 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'slice orientation' key. Recovered value = " << Key.
kvalue << endl);
2995 if (slice_orientation ==
"transverse")
2997 else if (slice_orientation ==
"sagittal")
2999 else if (slice_orientation ==
"coronal")
3008 string pat_rotation;
3011 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'patient rotation' key. Recovered value = " << Key.
kvalue << endl);
3015 if (pat_rotation ==
"supine")
3017 else if (pat_rotation ==
"prone")
3027 string pat_orientation;
3030 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'patient orientation' key. Recovered value = " << Key.
kvalue << endl);
3034 if (pat_orientation ==
"head_in")
3036 else if (pat_orientation ==
"feet_in")
3049 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'rescale slope' or 'data rescale slope' key. Recovered value = " << Key.
kvalue << endl);
3056 Cerr(
"***** ReadIntfHeader()-> Error : field 'resclale slope' units should be >0!" << endl);
3071 Cerr(
"***** ReadIntfHeader()-> WARNING : Error when trying to read numeric value from 'quantification units' key. Actual value = " << Key.
kvalue << endl);
3072 Cerr(
"***** This key will be ignored" << endl);
3079 Cerr(
"***** ReadIntfHeader()-> Error : field 'quantification units' should be >0!" << endl);
3091 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'rescale intercept' or 'data rescale intercept' key. Recovered value = " << Key.
kvalue << endl);
3097 Cerr(
"***** ReadIntfHeader()-> Error : field 'resclale intercept' units should be >0!" << endl);
3111 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'type of data' key. Recovered value = " << Key.
kvalue << endl);
3125 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'study duration (sec)' key. Recovered value = " << Key.
kvalue << endl);
3139 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'study duration (sec)' key. Recovered value = " << Key.
kvalue << endl);
3155 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'study duration (sec)' key. Recovered value = " << Key.
kvalue << endl);
3168 FLTNB pause_duration;
3171 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'study duration (sec)' key. Recovered value = " << Key.
kvalue << endl);
3185 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of time windows ' key. Recovered value = " << Key.
kvalue << endl);
3198 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'process status' key. Recovered value = " << Key.
kvalue << endl);
3211 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of energy windows' key. Recovered value = " << Key.
kvalue << endl);
3224 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of detector heads' key. Recovered value = " << Key.
kvalue << endl);
3236 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of projections' key. Recovered value = " << Key.
kvalue << endl);
3248 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'extent of rotation' key. Recovered value = " << Key.
kvalue << endl);
3259 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'direction_rotation' key. Recovered value = " << Key.
kvalue << endl);
3272 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'start angle' key. Recovered value = " << Key.
kvalue << endl);
3284 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'projection_angles' key. Recovered value = " << Key.
kvalue << endl);
3296 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'Center of rotation to detector distance' key.");
3297 Cerr(
" Recovered value = " << Key.
kvalue << endl);
3309 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'Radius' key. Recovered value = " << Key.
kvalue << endl);
3319 Cerr(
"***** ReadIntfHeader()-> Error : compressed interfile images not handled by the current implementation !" << endl);
3329 Cerr(
"***** ReadIntfHeader()-> Error : encoded interfile images not handled by the current implementation !" << endl);
3341 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of slices' key. Recovered value = " << Key.
kvalue << endl);
3353 Cerr(
"***** ReadIntfHeader()-> Error : couldn't find or read header interfile '"<< a_pathToHeaderFile <<
"' !" << endl);
3383 Cerr(
"***** ReadIntfHeader()-> Error : nb of recovered frame duration ('"<< ap_IF->
image_duration.size()
3384 <<
") does not match the nb of recovered pauses between frames ('"<< ap_IF->
frame_group_pause.size() <<
") !" << endl);
3412 Cout(
"--------------------------------------------------------------- " << endl);
3413 Cout(
"IntfWriteHeaderMainData()-> Start writing header interfile " << a_path << endl);
3414 Cout(
"--------------------------------------------------------------- " << endl);
3417 string path_to_header, path_to_image;
3418 path_to_header = a_path;
3420 path_to_header.append(
".hdr");
3424 ofstream ofile(path_to_header.c_str(), ios::out);
3425 ofile << setprecision(std::numeric_limits<FLTNB>::digits10 +1);
3431 ofile <<
"!INTERFILE := " << endl;
3434 string imaging_modality;
3436 imaging_modality =
"PET";
3438 imaging_modality =
"SPECT";
3440 imaging_modality =
"CT";
3442 imaging_modality =
"UNKOWN";
3444 ofile <<
"!imaging modality := " << imaging_modality << endl;
3448 ofile <<
"!version of keys := " <<
"3.3" << endl;
3450 ofile <<
"!version of keys := " <<
"CASToRv" <<
CASTOR_VERSION << endl;
3454 ofile << endl <<
"!GENERAL DATA := " << endl;
3455 ofile <<
"!originating system := " << p_scanMgr->
GetScannerName() << endl;
3462 ofile <<
"!data offset in bytes := " << 0 << endl;
3463 ofile <<
"!name of data file := " << path_to_image << endl;
3469 ofile << endl <<
"!GENERAL IMAGE DATA " << endl;
3475 ofile <<
"!type of data := Dynamic" << endl;
3480 ofile <<
"!total number of images := " << nb_imgs << endl;
3488 ofile <<
"number of time frames := " << ap_IntfF.
nb_time_frames << endl;
3489 ofile <<
"!number of frame groups := " << ap_IntfF.
nb_time_frames << endl;
3492 ofile <<
"!number of frame groups :=1 " << endl;
3496 ofile <<
"number of time windows := " << ap_IntfF.
nb_resp_gates *
3499 ofile <<
"number of respiratory gates := " << ap_IntfF.
nb_resp_gates << endl;
3501 ofile <<
"number of cardiac gates := " << ap_IntfF.
nb_card_gates << endl;
3505 ofile <<
"!number of projections := " << ap_IntfF.
nb_projections << endl;
3506 ofile <<
"!extent of rotation := " << ap_IntfF.
extent_rotation << endl;
3508 ofile <<
"process status := " << ap_IntfF.
process_status << endl;
3512 ofile << endl <<
"!DYNAMIC STUDY (General) :=" << endl;
3516 ofile << endl <<
"!GSPECT STUDY (General) :=" << endl;
3519 ofile << endl <<
"!SPECT STUDY (General) :=" << endl;
3520 ofile << endl <<
"!SPECT STUDY ("<< ap_IntfF.
process_status <<
" data) :="<< endl;
3524 ofile << endl <<
"!GATED STUDY (General) :=" << endl;
3526 ofile << endl <<
"!STATIC STUDY (General) :=" << endl;
3539 ofile <<
"!number of frame groups :=" << ap_IntfF.
nb_time_frames << endl;
3546 ofile <<
"!Dynamic Study (each frame group) :=" << endl;
3547 ofile <<
"!frame group number := " << fr+1 << endl;
3555 ofile <<
"!Respiratory Gated Study (each time window) :=" << endl;
3556 ofile <<
"!time window number := " << rg+1 << endl;
3564 ofile <<
"!Cardiac Gated Study (each time window) :=" << endl;
3565 ofile <<
"!time window number := " << cg+1 << endl;
3571 Cerr(
"***** IntfWriteHeaderMainData()-> Error : while trying to write the interfile header '"<< path_to_header <<
"' !" << endl);
3576 ofile <<
"!number of images in this time window :=" 3582 ofile <<
"!number of images in this time window :=" 3590 ofile <<
"!number of images this frame group :=" 3595 ofile <<
"!image duration (sec) := " << ap_IntfF.
image_duration[fr] << endl;
3596 ofile <<
"!image start time (sec) := " << ap_IntfF.
image_start_time[fr] << endl;
3599 ofile <<
"pause between frame groups (sec) " << 0.0 << endl;
3601 ofile <<
"pause between frame groups (sec) " << ap_IntfF.
frame_group_pause[fr] << endl;
3605 ofile <<
"!END OF INTERFILE := " << endl;
3609 Cerr(
"***** IntfWriteHeaderMainData()-> Error : couldn't find output header interfile '"<< a_path <<
"' !" << endl);
3642 ap_ofile <<
"start angle := " << ap_IntfF.
first_angle << endl;
3646 if( ap_IntfF.
radius.find(
"{}") != string::npos )
3647 ap_ofile <<
"Center of rotation to detector distance := " << ap_IntfF.
radius << endl;
3649 ap_ofile <<
"Radius := " << ap_IntfF.
radius << endl;
3651 ap_ofile <<
"!matrix size [1] := " << ap_IntfF.
mtx_size[0] << endl;
3652 ap_ofile <<
"!matrix size [2] := " << ap_IntfF.
mtx_size[1] << endl;
3653 ap_ofile <<
"!number format := " << ap_IntfF.
nb_format << endl;
3654 ap_ofile <<
"!number of bytes per pixel := " <<
sizeof(
FLTNB) << endl;
3655 ap_ofile <<
"scaling factor (mm/pixel) [1] := " << ap_IntfF.
vox_size[0] << endl;
3656 ap_ofile <<
"scaling factor (mm/pixel) [2] := " << ap_IntfF.
vox_size[1] << endl;
3657 ap_ofile <<
"!data offset in bytes := " << 0 << endl;
3661 ap_ofile <<
"number of dimensions := " << 3 << endl;
3662 ap_ofile <<
"!matrix size [1] := " << ap_IntfF.
mtx_size[0] << endl;
3663 ap_ofile <<
"!matrix size [2] := " << ap_IntfF.
mtx_size[1] << endl;
3664 ap_ofile <<
"!matrix size [3] := " << ap_IntfF.
mtx_size[2] << endl;
3665 ap_ofile <<
"!number format := " << ap_IntfF.
nb_format << endl;
3666 ap_ofile <<
"!number of bytes per pixel := " <<
sizeof(
FLTNB) << endl;
3667 ap_ofile <<
"scaling factor (mm/pixel) [1] := " << ap_IntfF.
vox_size[0] << endl;
3668 ap_ofile <<
"scaling factor (mm/pixel) [2] := " << ap_IntfF.
vox_size[1] << endl;
3669 ap_ofile <<
"scaling factor (mm/pixel) [3] := " << ap_IntfF.
vox_size[2] << endl;
3670 ap_ofile <<
"first pixel offset (mm) [1] := " << ap_IntfF.
vox_offset[0] << endl;
3671 ap_ofile <<
"first pixel offset (mm) [2] := " << ap_IntfF.
vox_offset[1] << endl;
3672 ap_ofile <<
"first pixel offset (mm) [3] := " << ap_IntfF.
vox_offset[2] << endl;
3679 ap_ofile <<
"data rescale slope := " << ap_IntfF.
rescale_slope << endl;
3680 ap_ofile <<
"quantification units := " << ap_IntfF.
quant_units << endl;
3700 Cerr(
"***** IntfWriteHeaderImgData()-> Error : couldn't open provided interfile header file !" << endl);
3726 if(vb >= 5)
Cout(
"IntfWriteImage()*" << endl);
3728 ofstream img_file(a_pathToImg.c_str(), ios::binary | ios::out);
3735 Cerr(
"***** IntfWriteImage()-> Error occurred when writing the image file '"<< a_pathToImg <<
"' !" << endl);
3741 Cerr(
"***** IntfWriteImage()-> Error occurred while trying to write the image file '"<< a_pathToImg <<
"' !" << endl);
3767 if(vb >= 5)
Cout(
"IntfWriteImage()**" << endl);
3769 if(ap_pathToImgs.size() == 1)
3773 ifstream fcheck(ap_pathToImgs.at(0).append(
".img").c_str());
3778 string dos_instruction =
"del " + ap_pathToImgs.at(0);
3779 system(dos_instruction.c_str());
3781 remove(ap_pathToImgs.at(0).c_str());
3786 ofstream img_file(ap_pathToImgs.at(0).c_str(), ios::binary | ios::out | ios::app);
3791 for(uint32_t d1=0 ; d1<ap_dim[0] ; d1++)
3792 if(
IntfWriteData(&img_file, a2p_outImgMtx[d1], ap_dim[1], vb) )
3794 Cerr(
"***** IntfWriteImage()-> Error occurred when writing the image file '"<< ap_pathToImgs.at(d1) <<
"' !" << endl);
3800 Cerr(
"***** IntfWriteImage()-> Error occurred while trying to write the image file at the path: '"<< ap_pathToImgs.at(0) <<
"' !" << endl);
3806 if(ap_pathToImgs.size()!=ap_dim[0])
3808 Cerr(
"***** IntfWriteImage()-> Error : number of interfile images ("<< ap_pathToImgs.size() <<
") not consistent with the number of images to load (" << ap_dim[0] <<
") !" << endl);
3812 for(uint32_t d1=0 ; d1<ap_dim[0] ; d1++)
3814 ofstream img_file(ap_pathToImgs.at(d1).append(
".img").c_str(), ios::binary | ios::out);
3819 if(
IntfWriteData(&img_file, a2p_outImgMtx[d1], ap_dim[1], vb) )
3821 Cerr(
"***** IntfWriteImage()-> Error occurred when writing the image file '"<< ap_pathToImgs.at(d1) <<
"' !" << endl);
3827 Cerr(
"***** IntfWriteImage()-> Error occurred while trying to write the image file at the path: '"<< ap_pathToImgs.at(d1) <<
"' !" << endl);
3855 if(vb >= 5)
Cout(
"IntfWriteImage()" << endl);
3857 if(ap_pathToImgs.size() == 1)
3861 ifstream fcheck(ap_pathToImgs.at(0).append(
".img").c_str());
3866 string dos_instruction =
"del " + ap_pathToImgs.at(0);
3867 system(dos_instruction.c_str());
3869 remove(ap_pathToImgs.at(0).c_str());
3874 ofstream img_file(ap_pathToImgs.at(0).c_str(), ios::binary | ios::out | ios::app);
3879 for(uint32_t d1=0 ; d1<ap_dim[0] ; d1++)
3880 for(uint32_t d2=0 ; d2<ap_dim[1] ; d2++)
3881 for(uint32_t d3=0 ; d3<ap_dim[2] ; d3++)
3882 if(
IntfWriteData(&img_file, a4p_outImgMtx[d1][d2][d3], ap_dim[3], vb) )
3884 int idx_img = d1*ap_dim[1]*ap_dim[2] + d2*ap_dim[2] + d3;
3885 Cerr(
"***** IntfWriteImage()-> Error occurred when writing the image file '"<< ap_pathToImgs.at(idx_img) <<
"' !" << endl);
3891 Cerr(
"***** IntfWriteImage()-> Error occurred while trying to write the image file '"<< ap_pathToImgs.at(0) <<
"' !" << endl);
3899 if(ap_pathToImgs.size() != ap_dim[0]*ap_dim[1]*ap_dim[2])
3901 Cerr(
"***** IntfWriteImage()-> Error : number of interfile images (="<< ap_pathToImgs.size()
3902 <<
") not consistent with the number of images to load (=" 3903 << ap_dim[0]*ap_dim[1]*ap_dim[2] <<
") !" << endl);
3907 for(uint32_t d1=0 ; d1<ap_dim[0] ; d1++)
3908 for(uint32_t d2=0 ; d2<ap_dim[1] ; d2++)
3909 for(uint32_t d3=0 ; d3<ap_dim[2] ; d3++)
3911 int idx_img = d1*ap_dim[1]*ap_dim[2] + d2*ap_dim[2] + d3;
3912 ofstream img_file(ap_pathToImgs.at(idx_img).append(
".img").c_str(), ios::binary | ios::out);
3917 if(
IntfWriteData(&img_file, a4p_outImgMtx[d1][d2][d3], ap_dim[3], vb) )
3919 Cerr(
"***** IntfWriteImage()-> Error occurred when writing the image file '"<< ap_pathToImgs.at(idx_img) <<
"' !" << endl);
3925 Cerr(
"***** IntfWriteImage()-> Error occurred while trying to write the image file at the path: '"<< ap_pathToImgs.at(idx_img) <<
"' !" << endl);
3954 if(vb >= 5)
Cout(
"IntfWriteData() " << endl);
3958 if (ap_oFile->write(reinterpret_cast<char*>(ap_outImgMatrix), a_nbVox*
sizeof(
FLTNB)) )
3992 for(
int d=0 ; d<7 ; d++)
3994 for(
int d=0 ; d<3 ; d++)
3996 for(
int d=0 ; d<3 ; d++)
4013 for(
int d=0 ; d<3 ; d++)
4151 Cout(
"// ------ IntfKeyPrintFields ------ // " << endl << endl);
4156 Cout(
"nb_dims : " <<
unsigned(a_IF.
nb_dims) << endl);
4157 for(
int i=0 ; i<7 ; i++)
4158 Cout(
"mtx_size["<<i<<
"] : " << a_IF.
mtx_size[i] << endl);
4159 for(
int i=0 ; i<3 ; i++)
4161 for(
int i=0 ; i<3 ; i++)
4162 Cout(
"vox_size["<<i<<
"] : " << a_IF.
vox_size[i] << endl);
4177 for(
int i=0 ; i<3 ; i++)
4179 for(
int i=0 ; i<3 ; i++)
4181 for(
int i=0 ; i<3 ; i++)
4187 Cout(
"image_duration(fr) : " << endl);
4190 Cout(
"image_start_time(fr) : " << endl);
4193 Cout(
"pause_duration(fr) : " << endl);
4210 Cout(
"// ------ ------------------ ------ // " << endl << endl);
4234 string intf_sep =
":=";
4237 int pos = a_line.find_first_of(
';',0);
4238 ap_Key->
korig = a_line.substr(0, pos);
4241 pos = ap_Key->
korig.find_first_of(intf_sep);
4244 if (ap_Key->
korig.find(intf_sep) == string::npos)
4245 ap_Key->
korig.append(
":=");
4294 string a_copy_of_the_key = ap_Key.
klcase;
4295 string a_copy_of_the_field = a_field;
4296 size_t found_char_at_pos = string::npos;
4298 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,
"");
4300 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,
"");
4304 if (a_copy_of_the_key==a_copy_of_the_field)
return 1;
4324 if(ap_Key.
kvalue.find(
"{") != string::npos &&
4325 ap_Key.
kvalue.find(
"}") != string::npos)
4347 string val_str = a_Key.
kvalue;
4349 size_t pos = val_str.find_first_of(
'{')+1;
4351 while (pos < val_str.length())
4353 size_t pos_c = val_str.find_first_of(
",", pos);
4356 if(pos_c == string::npos)
4358 pos_c = val_str.find_first_of(
"}", pos);
4361 Cerr(
"***** IntfKeyGetArrayNbElts-> Error : closing bracket not found in interfile array key : "<< a_Key.
korig <<
" !" << endl);
4372 Cerr(
"***** IntfKeyGetArrayNbElts-> Error : closing bracket not found in interfile array key : "<< a_Key.
korig <<
" !" << endl);
4392 string val_str = ap_Key.
kvalue;
4393 if (val_str ==
"")
return(max);
4395 size_t pos = val_str.find_first_of(
'{')+1;
4397 while (pos < val_str.length())
4399 size_t pos_c = val_str.find_first_of(
",", pos);
4402 if(pos_c == string::npos) pos_c = val_str.find_first_of(
"}", pos);
4406 Cerr(
"***** IntfKeyGetMaxArrayKey()-> An error occurred when trying to recover the following value from the array key : "<< val_str.substr(pos,pos_c-pos) <<
" !" << endl);
4410 if (value > max) max = value;
4436 string val_str = a_Key.
kvalue;
4441 Cerr(
"***** IntfKeyGetArrayElts-> Error : Problem reading the following interfile array key : "<< a_Key.
korig <<
" !" << endl);
4447 Cerr(
"***** IntfKeyGetArrayElts-> Error : no elements in the array key : "<< a_Key.
korig <<
" !" << endl);
4451 size_t pos = val_str.find_first_of(
'{')+1;
4455 while (pos < val_str.length())
4457 size_t pos_c = val_str.find_first_of(
",", pos);
4460 if(pos_c == string::npos) pos_c = val_str.find_first_of(
"}", pos);
4464 Cerr(
"***** IntfKeyGetMaxArrayKey()-> An error occurred when trying to recover the following value from the array key : "<< val_str.substr(pos,pos_c-pos) <<
" !" << endl);
4494 int dimXY=dimX*dimY;
4497 int z = a_voxId/dimXY;
4498 int y = (a_voxId - z*dimXY) / dimX;
4499 int x = a_voxId - z*dimXY - y*dimX;
4602 a_voxId = X + Y*dimX + Z*dimX*dimY;
4623 if(a_val == 0)
return "BIGENDIAN";
4624 if(a_val == 1)
return "LITTLEENDIAN";
4639 if(a_modalityIdx == 0)
4641 else if(a_modalityIdx == 1)
4668 if (a_str ==
"static")
4670 if (a_str ==
"dynamic")
4672 if (a_str ==
"gated")
4674 if (a_str ==
"tomographic")
4676 if (a_str ==
"gspect")
4736 if (
sizeof(
FLTNB) == 4)
return "short float";
4737 else if (
sizeof(
FLTNB) == 8)
return "long float";
4738 else if (
sizeof(
FLTNB) == 16)
return "long long float";
4741 Cerr(
"***** oInterfileIO::IntfKeyGetPixTypeStr() -> Size of current float type (" <<
sizeof(
FLTNB) <<
") does not correspond to a known type !" << endl);
4858 input_str->erase(0, input_str->find_first_not_of(
" !\t\r\n"));
4859 input_str->erase(input_str->find_last_not_of(
" \t\r\n")+1 , input_str->length());
4877 std::transform(ap_str->begin(), ap_str->end(), ap_str->begin(), ::tolower);
4894 string patient_tag_str =
"";
4899 if(dfName.size() > 1)
4901 patient_tag_str +=
"{ " + dfName[0];
4902 for(
size_t n=1 ; n<dfName.size() ; n++ )
4903 patient_tag_str +=
", " + dfName[n];
4904 patient_tag_str +=
"} ";
4906 else if (dfName.size() == 1)
4907 patient_tag_str += dfName[0];
4909 patient_tag_str +=
"unknown data";
4911 return patient_tag_str;
4930 char *buffer =
reinterpret_cast<char*
>(ap_type);
4931 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)
int GetNbCardBasisFunctions()
Get the number of cardiac basis functions.
#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
int GetNbTimeBasisFunctions()
Get the number of time basis functions.
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
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...
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 IntfWriteImgDynCoeffFile(const string &a_pathToImg, FLTNB **a2p_ImgMatrix, oImageDimensionsAndQuantification *ap_ID, int a_nbParImgs, int vb, bool a_mergeDynImgFlag)
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.
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...
int GetNbRespBasisFunctions()
Get the number of respiratory basis functions.
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