8 #include "oInterfileIO.hh" 45 ifstream input_file(a_pathToHeader.c_str(), ios::in);
51 while(!input_file.eof())
53 getline(input_file, line);
63 Cerr(
"***** IntfKeyGetValueFromFile()-> Error : couldn't correctly read interfile key '"<< line <<
"' !" << endl);
74 Cerr(
"***** IntfKeyGetValueFromFile()-> Exception when trying to read tag '" << a_key <<
"' in file '" << a_pathToHeader <<
"'." << endl);
85 Cerr(
"***** IntfKeyGetValueFromFile() -> " << a_nbElts <<
" requested for interfile key " << a_key <<
" , but this key is not an array !" << endl);
93 Cerr(
"***** IntfKeyGetValueFromFile() -> Nb of elements to recover (=" << a_nbElts <<
") does not correspond to the number of elements found in the key '" 101 Cerr(
"***** IntfKeyGetValueFromFile() -> " << a_nbElts <<
" requested for interfile key " << a_key <<
" , but this key is not an array !" << endl);
112 if (a_mandatoryFlag > 0)
114 Cerr(
"***** IntfKeyGetValueFromFile()-> Error when reading Interfile '" << a_pathToHeader <<
"'. Key '" << a_key <<
"' was not found." << endl);
125 Cerr(
"***** IntfKeyGetValueFromFile()-> Couldn't find or read data-file '"<< a_pathToHeader <<
"' !" << endl);
132 template int IntfKeyGetValueFromFile<int>(
const string& a_pathToHeader,
const string& a_key,
int* ap_return,
int a_nbElts,
int a_mandatoryFlag);
134 template int IntfKeyGetValueFromFile<float>(
const string& a_pathToHeader,
const string& a_key,
float* ap_return,
int a_nbElts,
int a_mandatoryFlag);
140 template int IntfKeyGetValueFromFile<bool>(
const string& a_pathToHeader,
const string& a_key,
bool* ap_return,
int a_nbElts,
int a_mandatoryFlag);
162 uint16_t a_nbOccurrences)
164 ifstream input_file(a_pathToHeader.c_str(), ios::in);
166 uint16_t nb_occurences_cur =0;
171 while(!input_file.eof())
173 getline(input_file, line);
183 Cerr(
"***** IntfKeyGetValueFromFile()-> Error : couldn't correctly read interfile key '"<< line <<
"' !" << endl);
194 if(nb_occurences_cur < a_nbOccurrences)
204 Cerr(
"***** IntfKeyGetValueFromFile()-> Exception when trying to read tag '" << a_key <<
"' in file '" << a_pathToHeader <<
"'." << endl);
215 Cerr(
"***** IntfKeyGetValueFromFile() -> " << a_nbElts <<
" requested for interfile key " << a_key <<
" , but this key is not an array !" << endl);
223 Cerr(
"***** IntfKeyGetValueFromFile() -> Nb of elements to recover (=" << a_nbElts <<
") does not correspond to the number of elements found in the key '" 231 Cerr(
"***** IntfKeyGetValueFromFile() -> " << a_nbElts <<
" requested for interfile key " << a_key <<
" , but this key is not an array !" << endl);
242 if (a_mandatoryFlag > 0)
244 Cerr(
"***** IntfKeyGetValueFromFile()-> Error when reading Interfile '" << a_pathToHeader <<
"'. Key '" << a_key <<
"' was not found." << endl);
255 Cerr(
"***** IntfKeyGetValueFromFile()-> Couldn't find or read data-file '"<< a_pathToHeader <<
"' !" << endl);
286 if(vb >= 3)
Cout(
"IntfReadProjectionImage()-> Read Interfile header : "<< a_pathToHeaderFile << endl);
294 Cerr(
"***** IntfReadProjectionImage()-> Error : while trying to read the interfile header '"<< a_pathToHeaderFile <<
"' !" << endl);
301 int nb_tot_pixels = ap_IF->
mtx_size[0]
306 ifstream img_file(ap_IF->
path_to_image.c_str(), ios::binary | ios::in);
317 Cerr(
"***** IntfReadProjectionImage()-> Error occurred while trying to read the image file at the path: '"<< ap_IF->
path_to_image <<
"' !" << endl);
342 Cerr(
"***** IntfCheckDimensionsConsistency() -> Numbers of dimensions are not the same !" << endl);
346 for (
int dim=0; dim<((int)ImgFields1.
nb_dims); dim++)
351 Cerr(
"***** IntfCheckDimensionsConsistency() -> The sizes of the dimension " << dim+1 <<
" are not the same !" << endl);
356 for (
int dim=0; dim<std::min(3,((
int)ImgFields1.
nb_dims)); dim++)
361 Cerr(
"***** IntfCheckDimensionsConsistency() -> Voxel sizes of dimension " << dim+1 <<
" are not the same !" << endl);
368 Cerr(
"***** IntfCheckDimensionsConsistency() -> Slice thicknesses are not the same !" << endl);
384 if (vb>=2)
Cout(
"IntfLoadImageFromScratch() -> Read Interfile image '" << a_pathToHeaderFile <<
"'" << endl);
392 Cerr(
"***** IntfLoadImageFromScratch() -> A problem occurred while trying to read the interfile header '" << a_pathToHeaderFile <<
"' !" << endl);
399 Cerr(
"***** IntfLoadImageFromScratch() -> Cannot handle a number of dimensions higher than 3 !" << endl);
404 for (
int d=0; d<ap_ImgFields->
nb_dims; d++)
if (ap_ImgFields->
mtx_size[d]==0)
406 Cerr(
"***** IntfLoadImageFromScratch() -> Number of voxels for dimension #" << d <<
" is 0, so has not been read correctly in header file '" << a_pathToHeaderFile <<
"' !" << endl);
410 for (
int d=0; d<ap_ImgFields->
nb_dims; d++)
if (ap_ImgFields->
vox_size[d]<=0.)
412 Cerr(
"***** IntfLoadImageFromScratch() -> Voxel size for dimension #" << d <<
" is negative, so has not been read correctly in header file '" << a_pathToHeaderFile <<
"' !" << endl);
423 ifstream img_file(ap_ImgFields->
path_to_image.c_str(), ios::binary | ios::in);
426 Cerr(
"***** IntfLoadImageFromScratch() -> Input image file '" << ap_ImgFields->
path_to_image <<
"' is missing or corrupted !" << endl);
447 if (vb>=2)
Cout(
"IntfWriteImageFromIntfFields() -> Write 3D image with output base name '" << a_pathToImg <<
"'" << endl);
452 Cerr(
"***** IntfWriteImageFromIntfFields() -> Error : while trying to write the interfile header '"<< a_pathToImg <<
"' !" << endl);
457 string path_to_image = a_pathToImg;
458 path_to_image.append(
".img");
466 Cerr(
"***** IntfWriteImageFromIntfFields() -> Error : while trying to write the interfile image '"<< path_to_image <<
"' !" << endl);
486 if (a_verbose>=
VERBOSE_DETAIL)
Cout(
"oInterfileIO::IntfReadImage() -> Read image from interfile header '" << a_pathToHeaderFile <<
"'" << endl);
495 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while trying to read the interfile header '" << a_pathToHeaderFile <<
"' !" << endl);
502 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while checking consistencies between reconstruction parameters and interfile keys from header '" 503 << a_pathToHeaderFile <<
"' !" << endl);
508 FLTNB* pimg_erp = NULL;
513 ifstream img_file(Img_fields.
path_to_image.c_str(), ios::binary | ios::in);
521 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while reading data and eventually interpolating from the IntfGetPixelTypeAndReadData() function !" << endl);
527 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while trying to open the image file '" << Img_fields.
path_to_image <<
"' !" << endl);
529 if (pimg_erp)
delete[] pimg_erp;
534 if (pimg_erp)
delete[] pimg_erp;
545 FLTNB**** a4p_ImgMatrix,
550 if (a_verbose >= 5)
Cout(
"oInterfileIO::IntfReadImage() -> Read image from interfile header '" << a_pathToHeaderFile <<
"'" << endl);
557 vector<string> lpath_to_headers;
561 if (
IntfIsMHD(a_pathToHeaderFile, lpath_to_headers) < 0 )
563 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while trying to read the interfile header '" << a_pathToHeaderFile <<
"' in IntfIsMHD() function !" << endl);
568 if (lpath_to_headers.size() == 1)
573 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while trying to read the interfile header '" << a_pathToHeaderFile <<
"' !" << endl);
579 Cerr(
"***** oInterfileIO::IntfReadImage() -> A error occurred while checking consistencies between reconstruction parameters and interfile keys in the header '" << a_pathToHeaderFile <<
"' !" << endl);
583 FLTNB* pimg_erp = NULL;
587 ifstream img_file(Img_fields.
path_to_image.c_str(), ios::binary | ios::in);
601 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while reading data and eventually interpolating from the IntfGetPixelTypeAndReadData() function !" << endl);
603 if (pimg_erp)
delete[] pimg_erp;
610 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while trying to read the image file '"<< Img_fields.
path_to_image <<
"' !" << endl);
612 if (pimg_erp)
delete[] pimg_erp;
616 if (pimg_erp)
delete[] pimg_erp;
625 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while trying to read the interfile metaheader '" << a_pathToHeaderFile <<
"' !" << endl);
634 if (lpath_to_headers.size() != (uint32_t)(dims[0]*dims[1]*dims[2]+ap_ID->
GetNbFramesToSkip()))
636 Cerr(
"***** oInterfileIO::IntfReadImage() -> Number of interfile images (" << lpath_to_headers.size() <<
637 ") not consistent with the number of images to load (" << dims[0]*dims[1]*dims[2]<<
") !" << endl);
641 FLTNB* pimg_erp = NULL;
646 for(
int d2=0 ; d2<dims[1] ; d2++)
647 for(
int d3=0 ; d3<dims[2] ; d3++)
649 int idx_img = d1*dims[1]*dims[2] + d2*dims[2] + d3;
653 if (
IntfReadHeader(lpath_to_headers[idx_img], &Img_fields, a_verbose) )
655 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while trying to read the interfile header '" << lpath_to_headers[idx_img] <<
"' !" << endl);
661 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while checking consistencies between reconstruction parameters and interfile keys in the header '" 662 << lpath_to_headers[idx_img] <<
"' !" << endl);
666 ifstream img_file(Img_fields.
path_to_image.c_str(), ios::binary | ios::in);
674 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while reading data and eventually interpolating from the IntfGetPixelTypeAndReadData() function !" << endl);
676 if (pimg_erp)
delete[] pimg_erp;
682 Cerr(
"***** oInterfileIO::IntfReadImage() -> An error occurred while trying to read the image file '"<< Img_fields.
path_to_image <<
"' !" << endl);
684 if (pimg_erp)
delete[] pimg_erp;
689 if (pimg_erp)
delete[] pimg_erp;
712 FLTNB** a2p_ImgMatrix,
718 if (a_verbose >= 5)
Cout(
"IntfReadImgDynCoeffFile" << endl);
725 vector<string> lpath_to_headers;
729 if(
IntfIsMHD(a_pathToHeaderFile, lpath_to_headers) <0)
731 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> an error occurred while trying to read the interfile header '" << a_pathToHeaderFile <<
"' !" << endl);
736 if(lpath_to_headers.size() == 1)
741 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while trying to read the interfile header '" << a_pathToHeaderFile <<
"' !" << endl);
747 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while checking consistencies between reconstruction parameters and interfile keys in the header '" << a_pathToHeaderFile <<
"' !" << endl);
751 FLTNB* pimg_erp = NULL;
754 ifstream img_file(Img_fields.
path_to_image.c_str(), ios::binary | ios::in);
761 for (
int bf=0 ; bf<a_nbFbasis ; bf++)
765 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while reading from file stream and eventually interpolating !" << endl);
767 if (pimg_erp)
delete[] pimg_erp;
774 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while trying to read the image file '" << Img_fields.
path_to_image <<
"' !" << endl);
776 if (pimg_erp)
delete[] pimg_erp;
780 if (pimg_erp)
delete[] pimg_erp;
789 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while trying to read the interfile metaheader '" << a_pathToHeaderFile <<
"' !" << endl);
793 if (lpath_to_headers.size() != (uint32_t)a_nbFbasis)
795 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> Number of interfile images (" << lpath_to_headers.size() <<
796 ") not consistent with the number of parametric images (" << a_nbFbasis<<
") !" << endl);
800 FLTNB* pimg_erp = NULL;
803 for (
int bf=0 ; bf<a_nbFbasis ; bf++)
806 if (
IntfReadHeader(lpath_to_headers[bf], &Img_fields, a_verbose) )
808 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> an error occurred while trying to read interfile header '" << a_pathToHeaderFile <<
"' !" << endl);
810 if (pimg_erp)
delete[] pimg_erp;
816 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while checking consistencies between reconstruction parameters and interfile keys in the header '"<< a_pathToHeaderFile <<
"' !" << endl);
818 if (pimg_erp)
delete[] pimg_erp;
822 ifstream img_file(Img_fields.
path_to_image.c_str(), ios::binary | ios::in);
830 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while reading image stream and eventually interpolating !" << endl);
832 if (pimg_erp)
delete[] pimg_erp;
838 Cerr(
"***** oInterfileIO::IntfReadImgDynCoeffFile() -> An error occurred while trying to read the image file '" << Img_fields.
path_to_image <<
"' !" << endl);
840 if (pimg_erp)
delete[] pimg_erp;
845 if (pimg_erp)
delete[] pimg_erp;
868 uint32_t nb_vox = a_IF.
mtx_size[0] *
873 *a2p_img =
new FLTNB[ nb_vox ];
874 ::memset(*a2p_img, 0,
sizeof(
FLTNB) * nb_vox);
900 if(vb >= 5)
Cout(
"IntfCheckConsistency()" << endl);
907 Cerr(
"***** IntfCheckConsistency()-> Error : some mandatory keys not initialized. Cannot read the interfile image !" << endl);
910 Cerr(
" Error when trying to read path to image data" << endl);
912 Cerr(
" Error when trying to read data voxel type " << endl);
914 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);
922 Cerr(
"***** IntfCheckConsistency()-> WARNING : No information found about voxel size ('scaling factor (mm/pixel)' tags.). Missing voxel sizes will be set to 1mm !" << endl);
956 Cerr(
"***** IntfCheckConsistency()-> Error : Image dimensions don't match reconstructions dimensions/voxel sizes" << endl);
957 Cerr(
" and linear interpolation is disabled (a_lerpFlag is false) !" << endl);
958 Cerr(
"***** Recovered image dimensions (x;y;z): "<< ap_IF->
mtx_size[0] <<
" ; "<< ap_IF->
mtx_size[1] <<
" ; " << ap_IF->
mtx_size[2] << endl);
976 FLTNB* ap_outImgMatrix,
977 FLTNB* ap_inImgMatrix,
982 if (a_verbose >= 5)
Cout(
"oInterfileIO::IntfGetPixelTypeAndReadData() " << endl);
991 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &flt);
996 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &db);
1002 Cerr(
"***** oInterfileIO::IntfGetPixelTypeAndReadData() -> The long double format is not the same for this image file and for this platform !" << endl);
1006 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &db);
1013 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &s_int);
1018 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &s_int);
1023 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &s_int);
1028 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &s_int);
1036 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &u_int);
1041 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &u_int);
1046 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &u_int);
1051 error =
IntfReadData(a_IF, ap_iFile, ap_outImgMatrix, ap_inImgMatrix, ap_offset, a_nbVox, a_verbose, &u_int);
1057 Cerr(
"***** oInterfileIO::IntfGetPixelTypeAndReadData() -> An error occurred when trying to read data through the IntfReadData() function !" << endl);
1072 FLTNB* ap_outImgMatrix,
1073 FLTNB* ap_inImgMatrix,
1079 if (a_verbose >= 5)
Cout(
"oInterfileIO::IntfReadData() -> Read data from file stream and eventually interpolate" << endl);
1089 pimg = ap_inImgMatrix;
1094 pimg = ap_outImgMatrix;
1098 bytes = (T*)malloc(nb_vox*
sizeof(T));
1100 ap_iFile->seekg(*a_offset);
1102 ap_iFile->read((
char*)bytes, nb_vox*
sizeof(T));
1104 if (!ap_iFile->good())
1106 if (ap_iFile->eof())
Cerr(
"***** oInterfileIO::IntfReadData() -> Not enough data in the file stream !" << endl);
1107 else Cerr(
"***** oInterfileIO::IntfReadData() -> An error occurred while reading from file stream !" << endl);
1113 for (
int v=0; v<nb_vox; v++)
1129 *a_offset +=
sizeof(T);
1147 Cerr(
"***** oInterfileIO::IntfReadData() -> An error occurred while interpolating the input image to the reconstruction dimensions !" << endl);
1176 const uint32_t ap_iDimVox[3],
const uint32_t ap_oDimVox[3],
1177 const FLTNB ap_iSizeVox[3],
const FLTNB ap_oSizeVox[3],
1178 const FLTNB ap_iOffVox[3],
const FLTNB ap_oOffVox[3] )
1383 FLTNB const posOldImage[] = {-((
FLTNB)(ap_iDimVox[0]))*ap_iSizeVox[0]*((
FLTNB)0.5) ,
1384 -((
FLTNB)(ap_iDimVox[1]))*ap_iSizeVox[1]*((
FLTNB)0.5) ,
1385 -((
FLTNB)(ap_iDimVox[2]))*ap_iSizeVox[2]*((
FLTNB)0.5) };
1387 FLTNB const posNewImage[] = {-((
FLTNB)(ap_oDimVox[0]))*ap_oSizeVox[0]*((
FLTNB)0.5) ,
1388 -((
FLTNB)(ap_oDimVox[1]))*ap_oSizeVox[1]*((
FLTNB)0.5) ,
1389 -((
FLTNB)(ap_oDimVox[2]))*ap_oSizeVox[2]*((
FLTNB)0.5) };
1401 uint32_t
const iDimVoxPad[]
1403 ap_iDimVox[ 0 ] + 2,
1404 ap_iDimVox[ 1 ] + 2,
1408 uint32_t
const nElts = iDimVoxPad[ 0 ] *
1414 ::memset( pPadIData, 0,
sizeof(
FLTNB ) * nElts );
1416 for( uint32_t k = 0; k < ap_iDimVox[ 2 ]; ++k )
1417 for( uint32_t j = 0; j < ap_iDimVox[ 1 ]; ++j )
1418 for( uint32_t i = 0; i < ap_iDimVox[ 0 ]; ++i )
1420 pPadIData[ ( i + 1 ) + ( j + 1 ) * iDimVoxPad[ 0 ]
1421 + ( k + 1 ) * iDimVoxPad[ 0 ] * iDimVoxPad[ 1 ] ] =
1422 ap_iImg[ i + j * ap_iDimVox[ 0 ]
1423 + k * ap_iDimVox[ 0 ] * ap_iDimVox[ 1 ] ];
1428 FLTNB const boundMin[]
1430 posOldImage[ 0 ] - ap_iSizeVox[ 0 ] * ((
FLTNB)0.5),
1431 posOldImage[ 1 ] - ap_iSizeVox[ 1 ] * ((
FLTNB)0.5),
1432 posOldImage[ 2 ] - ap_iSizeVox[ 2 ] * ((
FLTNB)0.5)
1435 FLTNB const boundMax[]
1437 posOldImage[ 0 ] + ((
FLTNB)ap_iDimVox[ 0 ]) * ap_iSizeVox[ 0 ]
1438 + ap_iSizeVox[ 0 ] * ((
FLTNB)0.5),
1439 posOldImage[ 1 ] + ((
FLTNB)ap_iDimVox[ 1 ]) * ap_iSizeVox[ 1 ]
1440 + ap_iSizeVox[ 1 ] * ((
FLTNB)0.5),
1441 posOldImage[ 2 ] + ((
FLTNB)ap_iDimVox[ 2 ]) * ap_iSizeVox[ 2 ]
1442 + ap_iSizeVox[ 2 ] * ((
FLTNB)0.5)
1449 for( uint32_t i = 0; i < 3; ++i )
1451 pOldCoordCenter[ i ] =
new FLTNB[ iDimVoxPad[ i ] ];
1453 for( uint32_t j = 0; j < iDimVoxPad[ i ]; ++j )
1455 pOldCoordCenter[ i ][ j ] = posOldImage[ i ] - ap_iSizeVox[ i ] / 2.0
1456 + j * ap_iSizeVox[ i ];
1463 for( uint32_t i = 0; i < 3; ++i )
1465 pNewCoordCenter[ i ] =
new FLTNB[ ap_oDimVox[ i ] ];
1467 for( uint32_t j = 0; j < ap_oDimVox[ i ]; ++j )
1469 pNewCoordCenter[ i ][ j ] = posNewImage[ i ] + ap_oSizeVox[ i ] / 2.0
1470 + j * ap_oSizeVox[ i ];
1475 FLTNB const invSizeX = 1.0 / ap_iSizeVox[ 0 ];
1476 FLTNB const invSizeY = 1.0 / ap_iSizeVox[ 1 ];
1477 FLTNB const invSizeZ = 1.0 / ap_iSizeVox[ 2 ];
1483 for( uint32_t k = 0; k < ap_oDimVox[ 2 ]; ++k )
1486 FLTNB const z = pNewCoordCenter[ 2 ][ k ];
1487 if( z < boundMin[ 2 ] || z > boundMax[ 2 ] )
continue;
1490 int32_t
const zBin = ( z - boundMin[ 2 ] ) * invSizeZ;
1493 FLTNB const zComposantI0 = invSizeZ * ( pOldCoordCenter[ 2 ][ zBin + 1 ] - z );
1494 FLTNB const zComposantI1 = invSizeZ * ( z - pOldCoordCenter[ 2 ][ zBin ] );
1496 for( uint32_t j = 0; j < ap_oDimVox[ 1 ]; ++j )
1499 FLTNB const y = pNewCoordCenter[ 1 ][ j ];
1500 if( y < boundMin[ 1 ] || y > boundMax[ 1 ] )
continue;
1503 int32_t
const yBin = ( y - boundMin[ 1 ] ) * invSizeY;
1506 FLTNB const yComposantI0 = invSizeY * ( pOldCoordCenter[ 1 ][ yBin + 1 ]
1508 FLTNB const yComposantI1 = invSizeY * ( y
1509 - pOldCoordCenter[ 1 ][ yBin ] );
1511 for( uint32_t i = 0; i < ap_oDimVox[ 0 ]; ++i )
1514 FLTNB const x = pNewCoordCenter[ 0 ][ i ];
1515 if( x < boundMin[ 0 ] || x > boundMax[ 0 ] )
continue;
1518 int32_t
const xBin = ( x - boundMin[ 0 ] ) * invSizeX;
1521 FLTNB const xComposantI0 = invSizeX * (
1522 pOldCoordCenter[ 0 ][ xBin + 1 ] - x );
1523 FLTNB const xComposantI1 = invSizeX * ( x
1524 - pOldCoordCenter[ 0 ][ xBin ] );
1528 for( uint32_t kk = 0; kk < 2; ++kk )
1530 for( uint32_t jj = 0; jj < 2; ++jj )
1532 for( uint32_t ii = 0; ii < 2; ++ii )
1534 pKernelData[ ii + jj * 2 + kk * 2 * 2 ] =
1537 ( yBin + jj ) * iDimVoxPad[ 0 ] +
1538 ( zBin + kk ) * iDimVoxPad[ 0 ] * iDimVoxPad[ 1 ]
1546 FLTNB const xInterpVal0 = pKernelData[ 0 ] * xComposantI0 +
1547 pKernelData[ 1 ] * xComposantI1;
1549 FLTNB const xInterpVal1 = pKernelData[ 2 ] * xComposantI0 +
1550 pKernelData[ 3 ] * xComposantI1;
1552 FLTNB const xInterpVal2 = pKernelData[ 4 ] * xComposantI0 +
1553 pKernelData[ 5 ] * xComposantI1;
1555 FLTNB const xInterpVal3 = pKernelData[ 6 ] * xComposantI0 +
1556 pKernelData[ 7 ] * xComposantI1;
1559 FLTNB const yInterpVal0 = xInterpVal0 * yComposantI0 +
1560 xInterpVal1 * yComposantI1;
1562 FLTNB const yInterpVal1 = xInterpVal2 * yComposantI0 +
1563 xInterpVal3 * yComposantI1;
1566 FLTNB const interpValTot = yInterpVal0 * zComposantI0 +
1567 yInterpVal1 * zComposantI1;
1569 ap_oImg[ i + j * ap_oDimVox[ 0 ]
1570 + k * ap_oDimVox[ 0 ] * ap_oDimVox[ 1 ] ] = interpValTot;
1576 for( uint32_t i = 0; i < 3; ++i )
1578 delete[] pOldCoordCenter[ i ];
1579 delete[] pNewCoordCenter[ i ];
1581 delete[] pOldCoordCenter;
1582 delete[] pNewCoordCenter;
1584 delete[] pKernelData;
1612 if (vb>=3)
Cout(
"IntfWriteImgFile (with Intf_fields)" << endl);
1617 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile header for'"<< a_pathToImg <<
"' !" << endl);
1621 string path_to_image = a_pathToImg;
1622 path_to_image.append(
".img");
1627 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile image '"<< path_to_image <<
"' !" << endl);
1656 if (vb>=3)
Cout(
"IntfWriteImgFile (3D image)" << endl);
1664 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile header for'"<< a_pathToImg <<
"' !" << endl);
1668 string path_to_image = a_pathToImg;
1669 path_to_image.append(
".img");
1674 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile image '"<< path_to_image <<
"' !" << endl);
1706 if (vb>=3)
Cout(
"IntfWriteProjFile ..." << endl);
1709 vector<string> lpath_to_images;
1710 lpath_to_images.push_back(a_pathToImg);
1714 Cerr(
"***** IntfWriteProjFile()-> Error : while trying to write the interfile header for'"<< lpath_to_images[0] <<
"' !" << endl);
1731 Cerr(
"***** IntfWriteFile()-> Error : while trying to write the interfile image '"<< a_pathToImg <<
"' !" << endl);
1765 if (vb>=3)
Cout(
"IntfWriteImgDynCoeffFile ..." << endl);
1777 vector<string> lpath_to_images;
1779 if(p_outputMgr->
MergeDynImages()==
true || a_mergeDynImgFlag==
true)
1781 lpath_to_images.push_back(a_pathToImg);
1782 lpath_to_images[0].append(
"_par");
1786 Cerr(
"***** IntfWriteImgDynCoeffFile()-> Error : while trying to write the interfile header for'"<< lpath_to_images[0] <<
"' !" << endl);
1794 for(
int bf=0 ; bf<a_nbParImgs ; bf++)
1797 lpath_to_images.push_back(a_pathToImg);
1800 stringstream ss; ss << bf + 1;
1801 lpath_to_images[idx_file].append(
"_par").append(ss.str());
1804 string path_to_hdr = lpath_to_images[idx_file] +
".hdr";
1805 string path_to_img = lpath_to_images[idx_file] +
".img";
1809 ifstream fcheck(path_to_hdr.c_str());
1814 string dos_instruction =
"del " + path_to_hdr;
1815 system(dos_instruction.c_str());
1817 remove(path_to_hdr.c_str());
1821 ofstream ofile(path_to_hdr.c_str(), ios::out | ios::app);
1822 ofile << setprecision(std::numeric_limits<FLTNB>::digits10 +1);
1823 ofile <<
"!INTERFILE := " << endl;
1824 ofile <<
"!name of data file := " <<
GetFileFromPath(path_to_img) << endl;
1826 ofile <<
"!data offset in bytes := " << 0 << endl;
1828 ofile <<
"!type of data := Dynamic" << endl;
1832 Cerr(
"***** IntfWriteImgDynCoeffFile()-> Error : while trying to write the interfile header for'"<< lpath_to_images[idx_file] <<
"' !" << endl);
1836 ofile <<
"!END OF INTERFILE := " << endl;
1844 string pathToDynCoeffMHD;
1845 pathToDynCoeffMHD=a_pathToImg.c_str();
1846 pathToDynCoeffMHD.append(
"_par");
1847 if(
IntfWriteMHD(pathToDynCoeffMHD, lpath_to_images, Img_fields, ap_ID, vb) )
1849 Cerr(
"***** IntfWriteImgDynCoeffFile()-> Error : while trying to write the interfile header '"<< a_pathToImg <<
"' !" << endl);
1858 dims[0] = a_nbParImgs;
1863 Cerr(
"***** IntfWriteImgDynCoeffFile()-> Error : while trying to write the interfile image '"<< a_pathToImg <<
"' !" << endl);
1894 if (vb>=3)
Cout(
"IntfWriteImgFile (static/dynamic image) ..." << endl);
1905 vector<string> lpath_to_images;
1909 lpath_to_images.push_back(a_pathToImg);
1913 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile header for'"<< lpath_to_images[0] <<
"' !" << endl);
1929 lpath_to_images.push_back(a_pathToImg);
1934 stringstream ss; ss << fr + 1;
1935 lpath_to_images[idx_file].append(
"_fr").append(ss.str());
1940 stringstream ss; ss << rg + 1;
1941 lpath_to_images[idx_file].append(
"_rg").append(ss.str());
1946 stringstream ss; ss << cg + 1;
1947 lpath_to_images[idx_file].append(
"_cg").append(ss.str());
1951 string path_to_hdr = lpath_to_images[idx_file];
1952 string path_to_img = lpath_to_images[idx_file];
1956 ifstream fcheck(path_to_hdr.append(
".hdr").c_str());
1961 string dos_instruction =
"del " + path_to_hdr;
1962 system(dos_instruction.c_str());
1964 remove(path_to_hdr.c_str());
1968 ofstream ofile(path_to_hdr.c_str(), ios::out | ios::app);
1969 ofile << setprecision(std::numeric_limits<FLTNB>::digits10 +1);
1970 ofile <<
"!INTERFILE := " << endl;
1973 ofile <<
"!name of data file := " <<
GetFileFromPath(path_to_img).append(
".img") << endl;
1975 ofile <<
"!data offset in bytes := " << 0 << endl;
1977 ofile <<
"!type of data := Dynamic" << endl;
1981 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile header for'"<< lpath_to_images[idx_file] <<
"' !" << endl);
1991 ofile <<
"!END OF INTERFILE := " << endl;
1996 Cerr(
"***** IntfWriteImgFile()-> Error: while copying input data header information into output interfile header '" << path_to_hdr <<
"' !" << endl);
2007 if(
IntfWriteMHD(a_pathToImg, lpath_to_images, Img_fields, ap_ID, vb) )
2009 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile header '"<< a_pathToImg <<
"' !" << endl);
2026 Cerr(
"***** IntfWriteImgFile()-> Error : while trying to write the interfile image '"<< a_pathToImg <<
"' !" << endl);
2044 if (vb>=3)
Cout(
"IntfWriteDynBasisCoefImgFile (dynamic basis coefficients image) ..." << endl);
2050 vector<string> lpath_to_images;
2061 lpath_to_images.push_back(a_pathToImg);
2065 stringstream ss; ss << tbf + 1;
2066 lpath_to_images[idx_file].append(
"_tbf").append(ss.str());
2071 stringstream ss; ss << rbf + 1;
2072 lpath_to_images[idx_file].append(
"_rbf").append(ss.str());
2077 stringstream ss; ss << cbf + 1;
2078 lpath_to_images[idx_file].append(
"_cbf").append(ss.str());
2081 string path_to_hdr = lpath_to_images[idx_file];
2082 string path_to_img = lpath_to_images[idx_file];
2085 ifstream fcheck(path_to_hdr.append(
".hdr").c_str());
2090 string dos_instruction =
"del " + path_to_hdr;
2091 system(dos_instruction.c_str());
2093 remove(path_to_hdr.c_str());
2097 ofstream ofile(path_to_hdr.c_str(), ios::out | ios::app);
2098 ofile << setprecision(std::numeric_limits<FLTNB>::digits10 +1);
2099 ofile <<
"!INTERFILE := " << endl;
2100 ofile <<
"!name of data file := " <<
GetFileFromPath(path_to_img).append(
".img") << endl;
2102 ofile <<
"!data offset in bytes := " << 0 << endl;
2104 ofile <<
"!type of data := Dynamic" << endl;
2107 Cerr(
"***** IntfWriteWholeDynBasisCoeffImgFile()-> Error : while trying to write the interfile header for'"<< lpath_to_images[idx_file] <<
"' !" << endl);
2111 ofile <<
"image duration (sec) := 1" << endl;
2112 ofile <<
"image start time (sec) := 0" << endl;
2113 ofile <<
"!END OF INTERFILE := " << endl;
2128 Cerr(
"***** IntfWriteWholeDynBasisCoeffImgFile()-> Error : while trying to write the interfile image '"<< a_pathToImg <<
"' !" << endl);
2214 int IntfIsMHD(
string a_pathToFile, vector<string> &ap_lPathToImgs)
2217 ifstream hfile(a_pathToFile.c_str(), ios::in);
2225 getline(hfile, line);
2228 if(line.empty())
continue;
2236 Cerr(
"***** IntfIsMHD()-> Error : couldn't correctly read interfile key '"<< line <<
"' !" << endl);
2248 uint16_t nb_datasets = 0;
2251 Cerr(
"***** IntfIsMHD()-> Error when trying to read data from 'total number of data set' key. Recovered value = " << Key.
kvalue << endl);
2259 string file_key =
"";
2260 string file_keyp =
"%";
2261 string file_key_space =
"";
2262 string file_keyp_space =
"%";
2263 file_key_space.append(
"data set [").append(ss.str()).append(
"]");
2264 file_keyp_space.append(
"data set [").append(ss.str()).append(
"]");
2265 file_key.append(
"data set[").append(ss.str()).append(
"]");
2266 file_keyp.append(
"data set[").append(ss.str()).append(
"]");
2273 getline(hfile, line);
2276 if(line.empty())
continue;
2281 Cerr(
"***** IntfIsMHD()-> Error : couldn't correctly read interfile key '"<< line <<
"' !" << endl);
2299 Cerr(
"***** IntfIsMHD()-> Error : when trying to read Interfile array key: '"<< line <<
"' !" << endl);
2302 else if(nb_elts != 3)
2304 Cerr(
"***** IntfIsMHD()-> Error : when trying to read Interfile array key: '"<< line <<
"' !" << endl);
2305 Cerr(
" 3 elements are expected following the format {xxx, path_to_the_img_file, xxx} (xxx = ignored data)" << endl);
2311 Cerr(
"***** IntfIsMHD()-> Error : when trying to read Interfile array key: '"<< line <<
"' !" << endl);
2314 ap_lPathToImgs.at(file_idx).append(elts_str[1]);
2317 ap_lPathToImgs.at(file_idx).append(Key.
kvalue);
2325 file_key.append(
"data set [").append(ss.str()).append(
"]");
2326 file_keyp.append(
"data set [").append(ss.str()).append(
"]");
2332 if(nb_datasets != ap_lPathToImgs.size())
2335 Cerr(
"***** IntfIsMHD()-> The number of recovered file in the metaheader ("<<ap_lPathToImgs.size()<<
")");
2336 Cerr(
"does not correspond to the expected number of datasets ("<<nb_datasets<<
")!"<< endl);
2347 Cerr(
"***** IntfIsMHD()-> Error : couldn't read header file '"<< a_pathToFile <<
"' !" << endl);
2353 ap_lPathToImgs.push_back(a_pathToFile);
2376 const vector<string>& ap_lPathToImgs,
2382 string path_to_mhd_file = a_pathToMhd;
2383 path_to_mhd_file.append(
".mhd");
2384 ofstream ofile(path_to_mhd_file.c_str(), ios::out);
2385 ofile << setprecision(std::numeric_limits<FLTNB>::digits10 +1);
2393 ofile <<
"!INTERFILE := " << endl;
2395 ofile << endl <<
"!GENERAL DATA := " << endl;
2396 ofile <<
"data description:=image" << endl;
2397 ofile <<
"!originating system := " << p_scanMgr->
GetScannerName() << endl;
2402 ofile <<
"number of bed positions := " << a_IntfF.
nb_bed_positions << endl;
2403 ofile <<
"!study duration (sec) := " << a_IntfF.
study_duration << endl;
2406 else ofile <<
"horizontal bed relative position (mm) := " << ap_ID->
GetBedPosition(0) << endl;
2408 ofile << endl <<
"%DATA MATRIX DESCRIPTION:=" << endl;
2409 ofile <<
"number of time frames := " << a_IntfF.
nb_time_frames << endl;
2410 ofile <<
"number of time windows := " << a_IntfF.
nb_resp_gates *
2412 ofile <<
"number of respiratory gates := " << a_IntfF.
nb_resp_gates << endl;
2413 ofile <<
"number of cardiac gates := " << a_IntfF.
nb_card_gates << endl;
2415 ofile << endl <<
"%DATA SET DESCRIPTION:="<< endl;
2418 ofile <<
"!total number of data sets:=" << nb_imgs << endl;
2421 if(ap_lPathToImgs.size() != nb_imgs)
2423 Cerr(
"***** IntfWriteMHD()-> Error : nb of provided string inconsistent with the expected number of dynamic images: '"<< nb_imgs <<
"' !" << endl);
2428 for(
int ds=0 ; ds<nb_imgs ; ds++)
2430 string path_to_header = ap_lPathToImgs.at(ds);
2431 ofile <<
"%data set ["<<ds+1<<
"]:={0," <<
GetFileFromPath(path_to_header).append(
".hdr") <<
",UNKNOWN}"<< endl;
2436 Cerr(
"***** IntfWriteMHD()-> Error : couldn't find output Metaheader interfile '"<< path_to_mhd_file <<
"' !" << endl);
2475 Cout(
"--------------------------------------------------------------- " << endl);
2476 Cout(
"IntfReadHeader()-> Start reading header interfile " << a_pathToHeaderFile << endl);
2477 Cout(
"--------------------------------------------------------------- " << endl);
2482 ifstream input_file(a_pathToHeaderFile.c_str(), ios::in);
2488 while(!input_file.eof())
2490 getline(input_file, line);
2502 Cerr(
"***** ReadIntfHeader()-> Error : couldn't correctly read interfile key '"<< line <<
"' !" << endl);
2506 if (vb >=10)
Cout(
"ReadIntfHeader()-> Key " << Key.
kcase << endl);
2525 if ( Key.
kvalue.size()>0 )
2537 string header_file_directory =
GetPathOfFile(a_pathToHeaderFile);
2543 Cerr(
"***** ReadIntfHeader()-> Error : path to interfile image file is empty !" << endl);
2558 if (endianness ==
"littleendian")
2572 Cerr(
"***** ReadIntfHeader()-> Warning : data_offset value was already set to " << ap_IF->
data_offset << endl);
2573 Cerr(
"***** The header may contain both 'data offset in bytes' and 'data starting block' fields " << endl);
2578 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'data starting block' key. Recovered value = " << Key.
kvalue << endl);
2593 Cerr(
"***** ReadIntfHeader()-> Warning : data_offset value was already set to " << ap_IF->
data_offset << endl);
2594 Cerr(
"***** The header may contain both 'data offset in bytes' and 'data starting block' fields " << endl);
2599 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'data offset in bytes' key. Recovered value = " << Key.
kvalue << endl);
2611 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number format' key. Recovered value = " << Key.
kvalue << endl);
2622 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'originating system' key. Recovered value = " << Key.
kvalue << endl);
2633 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'bed relative position (mm)' key. Recovered value = " << Key.
kvalue << endl);
2644 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [1]' key. Recovered value = " << Key.
kvalue << endl);
2655 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [2]' key. Recovered value = " << Key.
kvalue << endl);
2672 Cerr(
"***** ReadIntfHeader()-> Array reading for 'matrix size [3]' key not implemented yet. Single value expected." << endl);
2679 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [3]' key. Recovered value = " << Key.
kvalue << endl);
2701 Cerr(
"***** ReadIntfHeader()-> Array reading for 'matrix size [4]' key not implemented yet. Single value expected." << endl);
2710 Cerr(
"***** ReadIntfHeader()-> WARNING : both 'number of time frames' and 'matrix size [4]' keys have been provided");
2711 Cerr(
" 'number of time frames' selected by default" << endl);
2715 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [4]' key. Recovered value = " << Key.
kvalue << endl);
2734 Cerr(
"***** ReadIntfHeader()-> Array reading for 'matrix size [5]' key not implemented yet. Single value expected." << endl);
2741 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [5]' key. Recovered value = " << Key.
kvalue << endl);
2759 Cerr(
"***** ReadIntfHeader()-> Array reading for 'matrix size [6]' key not implemented yet. Single value expected." << endl);
2766 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [6]' key. Recovered value = " << Key.
kvalue << endl);
2784 Cerr(
"***** ReadIntfHeader()-> Array reading for 'matrix size [7]' key not implemented yet. Single value expected." << endl);
2791 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'matrix size [7]' key. Recovered value = " << Key.
kvalue << endl);
2805 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'scaling factor (mm/pixel) [1]' key. Recovered value = " << Key.
kvalue << endl);
2817 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'scaling factor (mm/pixel) [2]' key. Recovered value = " << Key.
kvalue << endl);
2830 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'scaling factor (mm/pixel) [3]' key. Recovered value = " << Key.
kvalue << endl);
2844 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from one of the following key :" << endl);
2845 Cerr(
"***** 'first pixel offset (mm) [1]'" << Key.
kvalue << endl);
2846 Cerr(
"***** 'origin (mm) [1]'"<< endl);
2847 Cerr(
"***** 'offset [1]'" << Key.
kvalue << endl);
2848 Cerr(
"***** Recovered value = " << Key.
kvalue << endl);
2862 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from one of the following key :" << endl);
2863 Cerr(
"***** 'first pixel offset (mm) [2]'" << Key.
kvalue << endl);
2864 Cerr(
"***** 'origin (mm) [2]'"<< endl);
2865 Cerr(
"***** 'offset [2]'" << Key.
kvalue << endl);
2866 Cerr(
"***** Recovered value = " << Key.
kvalue << endl);
2880 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from one of the following key :" << endl);
2881 Cerr(
"***** 'first pixel offset (mm) [3]'" << Key.
kvalue << endl);
2882 Cerr(
"***** 'origin (mm) [3]'"<< endl);
2883 Cerr(
"***** 'offset [3]'" << Key.
kvalue << endl);
2884 Cerr(
"***** Recovered value = " << Key.
kvalue << endl);
2897 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'slice thickness (pixels)' key. Recovered value = " << Key.
kvalue << endl);
2909 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'centre-centre slice separation (pixels)' key.");
2910 Cerr(
" Recovered value = " << Key.
kvalue << endl);
2913 Cerr(
"***** ReadIntfHeader()-> WARNING : 'centre-centre slice separation (pixels)' has no use in the current implementation !"<< endl);
2924 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of time frames' or 'number of frame groups' keys.");
2925 Cerr(
"Recovered value = " << Key.
kvalue << endl);
2937 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of respiratory gates' key. Recovered value = " << Key.
kvalue << endl);
2949 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of cardiac gates' key. Recovered value = " << Key.
kvalue << endl);
2960 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'total number of images' key. Recovered value = " << Key.
kvalue << endl);
2971 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of bytes per pixel' key. Recovered value = " << Key.
kvalue << endl);
2981 string slice_orientation;
2984 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'slice orientation' key. Recovered value = " << Key.
kvalue << endl);
2988 if (slice_orientation ==
"transverse")
2990 else if (slice_orientation ==
"sagittal")
2992 else if (slice_orientation ==
"coronal")
3001 string pat_rotation;
3004 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'patient rotation' key. Recovered value = " << Key.
kvalue << endl);
3008 if (pat_rotation ==
"supine")
3010 else if (pat_rotation ==
"prone")
3020 string pat_orientation;
3023 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'patient orientation' key. Recovered value = " << Key.
kvalue << endl);
3027 if (pat_orientation ==
"head_in")
3029 else if (pat_orientation ==
"feet_in")
3042 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'rescale slope' or 'data rescale slope' key. Recovered value = " << Key.
kvalue << endl);
3049 Cerr(
"***** ReadIntfHeader()-> Error : field 'resclale slope' units should be >0!" << endl);
3064 Cerr(
"***** ReadIntfHeader()-> WARNING : Error when trying to read numeric value from 'quantification units' key. Actual value = " << Key.
kvalue << endl);
3065 Cerr(
"***** This key will be ignored" << endl);
3072 Cerr(
"***** ReadIntfHeader()-> Error : field 'quantification units' should be >0!" << endl);
3084 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'rescale intercept' or 'data rescale intercept' key. Recovered value = " << Key.
kvalue << endl);
3090 Cerr(
"***** ReadIntfHeader()-> Error : field 'resclale intercept' units should be >0!" << endl);
3104 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'type of data' key. Recovered value = " << Key.
kvalue << endl);
3118 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'study duration (sec)' key. Recovered value = " << Key.
kvalue << endl);
3132 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'study duration (sec)' key. Recovered value = " << Key.
kvalue << endl);
3148 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'study duration (sec)' key. Recovered value = " << Key.
kvalue << endl);
3161 FLTNB pause_duration;
3164 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'study duration (sec)' key. Recovered value = " << Key.
kvalue << endl);
3178 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of time windows ' key. Recovered value = " << Key.
kvalue << endl);
3191 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'process status' key. Recovered value = " << Key.
kvalue << endl);
3204 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of energy windows' key. Recovered value = " << Key.
kvalue << endl);
3217 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of detector heads' key. Recovered value = " << Key.
kvalue << endl);
3229 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of projections' key. Recovered value = " << Key.
kvalue << endl);
3241 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'extent of rotation' key. Recovered value = " << Key.
kvalue << endl);
3252 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'direction_rotation' key. Recovered value = " << Key.
kvalue << endl);
3265 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'start angle' key. Recovered value = " << Key.
kvalue << endl);
3277 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'projection_angles' key. Recovered value = " << Key.
kvalue << endl);
3289 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'Center of rotation to detector distance' key.");
3290 Cerr(
" Recovered value = " << Key.
kvalue << endl);
3302 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'Radius' key. Recovered value = " << Key.
kvalue << endl);
3312 Cerr(
"***** ReadIntfHeader()-> Error : compressed interfile images not handled by the current implementation !" << endl);
3322 Cerr(
"***** ReadIntfHeader()-> Error : encoded interfile images not handled by the current implementation !" << endl);
3334 Cerr(
"***** ReadIntfHeader()-> Error when trying to read data from 'number of slices' key. Recovered value = " << Key.
kvalue << endl);
3346 Cerr(
"***** ReadIntfHeader()-> Error : couldn't find or read header interfile '"<< a_pathToHeaderFile <<
"' !" << endl);
3376 Cerr(
"***** ReadIntfHeader()-> Error : nb of recovered frame duration ('"<< ap_IF->
image_duration.size()
3377 <<
") does not match the nb of recovered pauses between frames ('"<< ap_IF->
frame_group_pause.size() <<
") !" << endl);
3405 Cout(
"--------------------------------------------------------------- " << endl);
3406 Cout(
"IntfWriteHeaderMainData()-> Start writing header interfile " << a_path << endl);
3407 Cout(
"--------------------------------------------------------------- " << endl);
3410 string path_to_header, path_to_image;
3411 path_to_header = a_path;
3413 path_to_header.append(
".hdr");
3417 ofstream ofile(path_to_header.c_str(), ios::out);
3418 ofile << setprecision(std::numeric_limits<FLTNB>::digits10 +1);
3424 ofile <<
"!INTERFILE := " << endl;
3427 string imaging_modality;
3429 imaging_modality =
"PET";
3431 imaging_modality =
"SPECT";
3433 imaging_modality =
"CT";
3435 imaging_modality =
"UNKOWN";
3437 ofile <<
"!imaging modality := " << imaging_modality << endl;
3441 ofile <<
"!version of keys := " <<
"3.3" << endl;
3443 ofile <<
"!version of keys := " <<
"CASToRv" <<
CASTOR_VERSION << endl;
3447 ofile << endl <<
"!GENERAL DATA := " << endl;
3448 ofile <<
"!originating system := " << p_scanMgr->
GetScannerName() << endl;
3455 ofile <<
"!data offset in bytes := " << 0 << endl;
3456 ofile <<
"!name of data file := " << path_to_image << endl;
3462 ofile << endl <<
"!GENERAL IMAGE DATA " << endl;
3468 ofile <<
"!type of data := Dynamic" << endl;
3473 ofile <<
"!total number of images := " << nb_imgs << endl;
3481 ofile <<
"number of time frames := " << ap_IntfF.
nb_time_frames << endl;
3482 ofile <<
"!number of frame groups := " << ap_IntfF.
nb_time_frames << endl;
3485 ofile <<
"!number of frame groups :=1 " << endl;
3489 ofile <<
"number of time windows := " << ap_IntfF.
nb_resp_gates *
3492 ofile <<
"number of respiratory gates := " << ap_IntfF.
nb_resp_gates << endl;
3494 ofile <<
"number of cardiac gates := " << ap_IntfF.
nb_card_gates << endl;
3498 ofile <<
"!number of projections := " << ap_IntfF.
nb_projections << endl;
3499 ofile <<
"!extent of rotation := " << ap_IntfF.
extent_rotation << endl;
3501 ofile <<
"process status := " << ap_IntfF.
process_status << endl;
3505 ofile <<
"number of bed positions := " << ap_IntfF.
nb_bed_positions << endl;
3506 ofile <<
"!study duration (sec) := " << ap_IntfF.
study_duration << endl;
3510 ofile << endl <<
"!DYNAMIC STUDY (General) :=" << endl;
3514 ofile << endl <<
"!GSPECT STUDY (General) :=" << endl;
3517 ofile << endl <<
"!SPECT STUDY (General) :=" << endl;
3518 ofile << endl <<
"!SPECT STUDY ("<< ap_IntfF.
process_status <<
" data) :="<< endl;
3522 ofile << endl <<
"!GATED STUDY (General) :=" << endl;
3524 ofile << endl <<
"!STATIC STUDY (General) :=" << endl;
3537 ofile <<
"!number of frame groups :=" << ap_IntfF.
nb_time_frames << endl;
3544 ofile <<
"!Dynamic Study (each frame group) :=" << endl;
3545 ofile <<
"!frame group number := " << fr+1 << endl;
3553 ofile <<
"!Respiratory Gated Study (each time window) :=" << endl;
3554 ofile <<
"!time window number := " << rg+1 << endl;
3562 ofile <<
"!Cardiac Gated Study (each time window) :=" << endl;
3563 ofile <<
"!time window number := " << cg+1 << endl;
3569 Cerr(
"***** IntfWriteHeaderMainData()-> Error : while trying to write the interfile header '"<< path_to_header <<
"' !" << endl);
3574 ofile <<
"!number of images in this time window :=" 3580 ofile <<
"!number of images in this time window :=" 3588 ofile <<
"!number of images in this frame group := " 3593 ofile <<
"!image duration (sec) := " << ap_IntfF.
image_duration[fr] << endl;
3594 ofile <<
"!image start time (sec) := " << ap_IntfF.
image_start_time[fr] << endl;
3597 ofile <<
"pause between frame groups (sec) := " << 0.0 << endl;
3599 ofile <<
"pause between frame groups (sec) := " << ap_IntfF.
frame_group_pause[fr] << endl;
3604 ofile <<
"!END OF INTERFILE := " << endl;
3609 Cerr(
"***** IntfWriteHeaderMainData()-> Error: while copying input data header information into output interfile header '" << path_to_header <<
"' !" << endl);
3615 Cerr(
"***** IntfWriteHeaderMainData()-> Error : couldn't find output header interfile '"<< a_path <<
"' !" << endl);
3630 int return_value = 0;
3633 for (
size_t df=0; df<dfName.size(); df++)
3636 ifstream header(dfName[df].c_str());
3639 Cerr(
"***** IntfWriteContentOfInputDataHeaderIntoInterfileHeader() -> Input data header file '" << dfName[df] <<
"' is missing or corrupted !" << endl);
3644 ap_ofile << endl <<
"!COPY OF INPUT HEADER " << df+1 << endl;
3647 getline(header,line);
3648 while (!header.eof())
3650 ap_ofile << line << endl;
3651 getline(header,line);
3656 ap_ofile <<
"!END OF COPY OF INPUT HEADER " << df+1 << endl;
3659 return return_value;
3687 ap_ofile <<
"start angle := " << ap_IntfF.
first_angle << endl;
3691 if( ap_IntfF.
radius.find(
"{}") != string::npos )
3692 ap_ofile <<
"Center of rotation to detector distance := " << ap_IntfF.
radius << endl;
3694 ap_ofile <<
"Radius := " << ap_IntfF.
radius << endl;
3696 ap_ofile <<
"!matrix size [1] := " << ap_IntfF.
mtx_size[0] << endl;
3697 ap_ofile <<
"!matrix size [2] := " << ap_IntfF.
mtx_size[1] << endl;
3698 ap_ofile <<
"!number format := " << ap_IntfF.
nb_format << endl;
3699 ap_ofile <<
"!number of bytes per pixel := " <<
sizeof(
FLTNB) << endl;
3700 ap_ofile <<
"scaling factor (mm/pixel) [1] := " << ap_IntfF.
vox_size[0] << endl;
3701 ap_ofile <<
"scaling factor (mm/pixel) [2] := " << ap_IntfF.
vox_size[1] << endl;
3702 ap_ofile <<
"!data offset in bytes := " << 0 << endl;
3706 ap_ofile <<
"number of dimensions := " << 3 << endl;
3707 ap_ofile <<
"!matrix size [1] := " << ap_IntfF.
mtx_size[0] << endl;
3708 ap_ofile <<
"!matrix size [2] := " << ap_IntfF.
mtx_size[1] << endl;
3709 ap_ofile <<
"!matrix size [3] := " << ap_IntfF.
mtx_size[2] << endl;
3710 ap_ofile <<
"!number format := " << ap_IntfF.
nb_format << endl;
3711 ap_ofile <<
"!number of bytes per pixel := " <<
sizeof(
FLTNB) << endl;
3712 ap_ofile <<
"scaling factor (mm/pixel) [1] := " << ap_IntfF.
vox_size[0] << endl;
3713 ap_ofile <<
"scaling factor (mm/pixel) [2] := " << ap_IntfF.
vox_size[1] << endl;
3714 ap_ofile <<
"scaling factor (mm/pixel) [3] := " << ap_IntfF.
vox_size[2] << endl;
3715 ap_ofile <<
"first pixel offset (mm) [1] := " << ap_IntfF.
vox_offset[0] << endl;
3716 ap_ofile <<
"first pixel offset (mm) [2] := " << ap_IntfF.
vox_offset[1] << endl;
3717 ap_ofile <<
"first pixel offset (mm) [3] := " << ap_IntfF.
vox_offset[2] << endl;
3724 ap_ofile <<
"data rescale slope := " << ap_IntfF.
rescale_slope << endl;
3725 ap_ofile <<
"quantification units := " << ap_IntfF.
quant_units << endl;
3745 Cerr(
"***** IntfWriteHeaderImgData()-> Error : couldn't open provided interfile header file !" << endl);
3771 if(vb >= 5)
Cout(
"IntfWriteImage()*" << endl);
3773 ofstream img_file(a_pathToImg.c_str(), ios::binary | ios::out);
3780 Cerr(
"***** IntfWriteImage()-> Error occurred when writing the image file '"<< a_pathToImg <<
"' !" << endl);
3786 Cerr(
"***** IntfWriteImage()-> Error occurred while trying to write the image file '"<< a_pathToImg <<
"' !" << endl);
3812 if(vb >= 5)
Cout(
"IntfWriteImage()**" << endl);
3814 if(ap_pathToImgs.size() == 1)
3818 ifstream fcheck(ap_pathToImgs.at(0).append(
".img").c_str());
3823 string dos_instruction =
"del " + ap_pathToImgs.at(0);
3824 system(dos_instruction.c_str());
3826 remove(ap_pathToImgs.at(0).c_str());
3831 ofstream img_file(ap_pathToImgs.at(0).c_str(), ios::binary | ios::out | ios::app);
3836 for(uint32_t d1=0 ; d1<ap_dim[0] ; d1++)
3837 if(
IntfWriteData(&img_file, a2p_outImgMtx[d1], ap_dim[1], vb) )
3839 Cerr(
"***** IntfWriteImage()-> Error occurred when writing the image file '"<< ap_pathToImgs.at(d1) <<
"' !" << endl);
3845 Cerr(
"***** IntfWriteImage()-> Error occurred while trying to write the image file at the path: '"<< ap_pathToImgs.at(0) <<
"' !" << endl);
3851 if(ap_pathToImgs.size()!=ap_dim[0])
3853 Cerr(
"***** IntfWriteImage()-> Error : number of interfile images ("<< ap_pathToImgs.size() <<
") not consistent with the number of images to load (" << ap_dim[0] <<
") !" << endl);
3857 for(uint32_t d1=0 ; d1<ap_dim[0] ; d1++)
3859 ofstream img_file(ap_pathToImgs.at(d1).append(
".img").c_str(), ios::binary | ios::out);
3864 if(
IntfWriteData(&img_file, a2p_outImgMtx[d1], ap_dim[1], vb) )
3866 Cerr(
"***** IntfWriteImage()-> Error occurred when writing the image file '"<< ap_pathToImgs.at(d1) <<
"' !" << endl);
3872 Cerr(
"***** IntfWriteImage()-> Error occurred while trying to write the image file at the path: '"<< ap_pathToImgs.at(d1) <<
"' !" << endl);
3900 if(vb >= 5)
Cout(
"IntfWriteImage()" << endl);
3902 if(ap_pathToImgs.size() == 1)
3906 ifstream fcheck(ap_pathToImgs.at(0).append(
".img").c_str());
3911 string dos_instruction =
"del " + ap_pathToImgs.at(0);
3912 system(dos_instruction.c_str());
3914 remove(ap_pathToImgs.at(0).c_str());
3919 ofstream img_file(ap_pathToImgs.at(0).c_str(), ios::binary | ios::out | ios::app);
3924 for(uint32_t d1=0 ; d1<ap_dim[0] ; d1++)
3925 for(uint32_t d2=0 ; d2<ap_dim[1] ; d2++)
3926 for(uint32_t d3=0 ; d3<ap_dim[2] ; d3++)
3927 if(
IntfWriteData(&img_file, a4p_outImgMtx[d1][d2][d3], ap_dim[3], vb) )
3929 int idx_img = d1*ap_dim[1]*ap_dim[2] + d2*ap_dim[2] + d3;
3930 Cerr(
"***** IntfWriteImage()-> Error occurred when writing the image file '"<< ap_pathToImgs.at(idx_img) <<
"' !" << endl);
3936 Cerr(
"***** IntfWriteImage()-> Error occurred while trying to write the image file '"<< ap_pathToImgs.at(0) <<
"' !" << endl);
3944 if(ap_pathToImgs.size() != ap_dim[0]*ap_dim[1]*ap_dim[2])
3946 Cerr(
"***** IntfWriteImage()-> Error : number of interfile images (="<< ap_pathToImgs.size()
3947 <<
") not consistent with the number of images to load (=" 3948 << ap_dim[0]*ap_dim[1]*ap_dim[2] <<
") !" << endl);
3952 for(uint32_t d1=0 ; d1<ap_dim[0] ; d1++)
3953 for(uint32_t d2=0 ; d2<ap_dim[1] ; d2++)
3954 for(uint32_t d3=0 ; d3<ap_dim[2] ; d3++)
3956 int idx_img = d1*ap_dim[1]*ap_dim[2] + d2*ap_dim[2] + d3;
3957 ofstream img_file(ap_pathToImgs.at(idx_img).append(
".img").c_str(), ios::binary | ios::out);
3962 if(
IntfWriteData(&img_file, a4p_outImgMtx[d1][d2][d3], ap_dim[3], vb) )
3964 Cerr(
"***** IntfWriteImage()-> Error occurred when writing the image file '"<< ap_pathToImgs.at(idx_img) <<
"' !" << endl);
3970 Cerr(
"***** IntfWriteImage()-> Error occurred while trying to write the image file at the path: '"<< ap_pathToImgs.at(idx_img) <<
"' !" << endl);
3999 if(vb >= 5)
Cout(
"IntfWriteData() " << endl);
4003 if (ap_oFile->write(reinterpret_cast<char*>(ap_outImgMatrix), a_nbVox*
sizeof(
FLTNB)) )
4037 for(
int d=0 ; d<7 ; d++)
4039 for(
int d=0 ; d<3 ; d++)
4041 for(
int d=0 ; d<3 ; d++)
4058 for(
int d=0 ; d<3 ; d++)
4196 Cout(
"// ------ IntfKeyPrintFields ------ // " << endl << endl);
4201 Cout(
"nb_dims : " <<
unsigned(a_IF.
nb_dims) << endl);
4202 for(
int i=0 ; i<7 ; i++)
4203 Cout(
"mtx_size["<<i<<
"] : " << a_IF.
mtx_size[i] << endl);
4204 for(
int i=0 ; i<3 ; i++)
4206 for(
int i=0 ; i<3 ; i++)
4207 Cout(
"vox_size["<<i<<
"] : " << a_IF.
vox_size[i] << endl);
4222 for(
int i=0 ; i<3 ; i++)
4224 for(
int i=0 ; i<3 ; i++)
4226 for(
int i=0 ; i<3 ; i++)
4232 Cout(
"image_duration(fr) : " << endl);
4235 Cout(
"image_start_time(fr) : " << endl);
4238 Cout(
"pause_duration(fr) : " << endl);
4255 Cout(
"// ------ ------------------ ------ // " << endl << endl);
4279 string intf_sep =
":=";
4282 int pos = a_line.find_first_of(
';',0);
4283 ap_Key->
korig = a_line.substr(0, pos);
4286 pos = ap_Key->
korig.find_first_of(intf_sep);
4289 if (ap_Key->
korig.find(intf_sep) == string::npos)
4290 ap_Key->
korig.append(
":=");
4339 string a_copy_of_the_key = ap_Key.
klcase;
4340 string a_copy_of_the_field = a_field;
4341 size_t found_char_at_pos = string::npos;
4343 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,
"");
4345 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,
"");
4349 if (a_copy_of_the_key==a_copy_of_the_field)
return 1;
4369 if(ap_Key.
kvalue.find(
"{") != string::npos &&
4370 ap_Key.
kvalue.find(
"}") != string::npos)
4392 string val_str = a_Key.
kvalue;
4394 size_t pos = val_str.find_first_of(
'{')+1;
4396 while (pos < val_str.length())
4398 size_t pos_c = val_str.find_first_of(
",", pos);
4401 if(pos_c == string::npos)
4403 pos_c = val_str.find_first_of(
"}", pos);
4406 Cerr(
"***** IntfKeyGetArrayNbElts-> Error : closing bracket not found in interfile array key : "<< a_Key.
korig <<
" !" << endl);
4417 Cerr(
"***** IntfKeyGetArrayNbElts-> Error : closing bracket not found in interfile array key : "<< a_Key.
korig <<
" !" << endl);
4437 string val_str = ap_Key.
kvalue;
4438 if (val_str ==
"")
return(max);
4440 size_t pos = val_str.find_first_of(
'{')+1;
4442 while (pos < val_str.length())
4444 size_t pos_c = val_str.find_first_of(
",", pos);
4447 if(pos_c == string::npos) pos_c = val_str.find_first_of(
"}", pos);
4451 Cerr(
"***** IntfKeyGetMaxArrayKey()-> An error occurred when trying to recover the following value from the array key : "<< val_str.substr(pos,pos_c-pos) <<
" !" << endl);
4455 if (value > max) max = value;
4481 string val_str = a_Key.
kvalue;
4486 Cerr(
"***** IntfKeyGetArrayElts-> Error : Problem reading the following interfile array key : "<< a_Key.
korig <<
" !" << endl);
4492 Cerr(
"***** IntfKeyGetArrayElts-> Error : no elements in the array key : "<< a_Key.
korig <<
" !" << endl);
4496 size_t pos = val_str.find_first_of(
'{')+1;
4500 while (pos < val_str.length())
4502 size_t pos_c = val_str.find_first_of(
",", pos);
4505 if(pos_c == string::npos) pos_c = val_str.find_first_of(
"}", pos);
4509 Cerr(
"***** IntfKeyGetMaxArrayKey()-> An error occurred when trying to recover the following value from the array key : "<< val_str.substr(pos,pos_c-pos) <<
" !" << endl);
4539 int dimXY=dimX*dimY;
4542 int z = a_voxId/dimXY;
4543 int y = (a_voxId - z*dimXY) / dimX;
4544 int x = a_voxId - z*dimXY - y*dimX;
4647 a_voxId = X + Y*dimX + Z*dimX*dimY;
4668 if(a_val == 0)
return "BIGENDIAN";
4669 if(a_val == 1)
return "LITTLEENDIAN";
4684 if(a_modalityIdx == 0)
4686 else if(a_modalityIdx == 1)
4713 if (a_str ==
"static")
4715 if (a_str ==
"dynamic")
4717 if (a_str ==
"gated")
4719 if (a_str ==
"tomographic")
4721 if (a_str ==
"gspect")
4781 if (
sizeof(
FLTNB) == 4)
return "short float";
4782 else if (
sizeof(
FLTNB) == 8)
return "long float";
4783 else if (
sizeof(
FLTNB) == 16)
return "long long float";
4786 Cerr(
"***** oInterfileIO::IntfKeyGetPixTypeStr() -> Size of current float type (" <<
sizeof(
FLTNB) <<
") does not correspond to a known type !" << endl);
4903 input_str->erase(0, input_str->find_first_not_of(
" !\t\r\n"));
4904 input_str->erase(input_str->find_last_not_of(
" \t\r\n")+1 , input_str->length());
4922 std::transform(ap_str->begin(), ap_str->end(), ap_str->begin(), ::tolower);
4939 string patient_tag_str =
"";
4944 if(dfName.size() > 1)
4946 patient_tag_str +=
"{ " + dfName[0];
4947 for(
size_t n=1 ; n<dfName.size() ; n++ )
4948 patient_tag_str +=
", " + dfName[n];
4949 patient_tag_str +=
"} ";
4951 else if (dfName.size() == 1)
4952 patient_tag_str += dfName[0];
4954 patient_tag_str +=
"unknown data";
4956 return patient_tag_str;
4974 char *buffer =
reinterpret_cast<char*
>(ap_type);
4975 std::reverse(buffer, buffer +
sizeof(T));
template int IntfKeyGetValueFromFile< uint16_t >(const string &a_pathToHeader, const string &a_key, uint16_t *ap_return, int a_nbElts, int a_mandatoryFlag)
#define INTF_SUPINE_FEETIN_CORONAL
void SwapBytes(T *ap_type)
static sScannerManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
void GetUserEndianness()
Check user/host computer endianness and write it to the global variable User_Endianness.
string direction_rotation
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...
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...
void IntfKeySetFieldsOutput(Intf_fields *ap_IF, oImageDimensionsAndQuantification *ap_ID)
Init the keys of the Interfile header of an image to be written on disk.
int IntfIsMHD(string a_pathToFile, vector< string > &ap_lPathToImgs)
Check if the string in argument contains the path to a Interfile metaheader.
int IntfCheckDimensionsConsistency(Intf_fields ImgFields1, Intf_fields ImgFields2)
string GetPathOfFile(const string &a_pathToFile)
Simply return the path to the directory of a file path string passed in parameter.
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)
int GetNbCardBasisFunctions()
Get the number of cardiac basis functions.
FLTNB GetFrameDurationInSec(int a_bed, int a_frame)
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...
template int IntfKeyGetValueFromFile< uint32_t >(const string &a_pathToHeader, const string &a_key, uint32_t *ap_return, int a_nbElts, int a_mandatoryFlag)
FLTNB GetBedPosition(int a_bedIndex)
#define INTF_PRONE_HEADIN_CORONAL
FLTNB GetVoxSizeX()
Get the voxel's size along the X axis, in mm.
int IntfWriteContentOfInputDataHeaderIntoInterfileHeader(ofstream &ap_ofile, int vb)
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 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...
string IntfKeyGetPatientNameTag()
Recover datafile name(s) stored in sOutputManager in one string.
template int IntfKeyGetValueFromFile< double >(const string &a_pathToHeader, const string &a_key, double *ap_return, int a_nbElts, int a_mandatoryFlag)
FLTNB GetVoxSizeZ()
Get the voxel's size along the Z axis, in mm.
int IntfWriteImageFromIntfFields(const string &a_pathToImg, FLTNB *ap_ImgMatrix, Intf_fields Img_fields, int vb)
#define INTF_PRONE_FEETIN_TRANSAXIAL
void IntfKeyInitFields(Intf_fields *ap_IF)
Init the file of an Interfile fields structure passed in parameter to their default values...
#define INTF_PRONE_FEETIN_CORONAL
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 IntfKeyGetPixTypeStr()
Return the string corresponding to the nb of bytes in the type FLTNB.
#define INTF_SUPINE_FEETIN_SAGITTAL
int IntfKeyGetInputImgDataType(const string &a_str)
Get the image data type corresponding to the image metadata passed in parameter.
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)
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)
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...
#define INTF_PRONE_FEETIN_SAGITTAL
FLTNB bed_relative_position
int GetNbTimeBasisFunctions()
Get the number of time basis functions.
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 IntfReadHeader(const string &a_pathToHeaderFile, Intf_fields *ap_IF, int vb)
Read an Interfile header.
bool FLTNBIsEqual(FLTNB a, FLTNB b, FLTNB a_eps)
Comparison of FLTNB numbers.
static sOutputManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
FLTNB GetFrameTimeStartInSec(int a_bed, int a_frame)
template int IntfKeyGetValueFromFile< int64_t >(const string &a_pathToHeader, const string &a_key, int64_t *ap_return, int a_nbElts, int a_mandatoryFlag)
vector< FLTNB > frame_group_pause
FLTNB GetFinalTimeStopInSec(int a_bed)
template int IntfKeyGetValueFromFile< long double >(const string &a_pathToHeader, const string &a_key, long double *ap_return, int a_nbElts, int a_mandatoryFlag)
#define KEYWORD_MANDATORY_NOT_FOUND
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)
bool GetProvidedBedPositionFlag()
Say if the bed relative position was provided from the datafile or not.
int IntfWriteImgDynCoeffFile(const string &a_pathToImg, FLTNB **a2p_ImgMatrix, oImageDimensionsAndQuantification *ap_ID, int a_nbParImgs, int vb, bool a_mergeDynImgFlag)
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.
template int IntfKeyGetRecurringValueFromFile< uint8_t >(const string &a_pathToHeader, const string &a_key, uint8_t *ap_return, int a_nbElts, int a_mandatoryFlag, uint16_t a_nbOccurrences)
int IntfKeyGetPatOrientation(Intf_fields ap_IF)
Get the complete patient orientation from an Intf_fields structure according to the values of keys 's...
vector< FLTNB > image_start_time
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.
FLTNB GetFrameTimeStopInSec(int a_bed, int a_frame)
#define INTF_SUPINE_HEADIN_SAGITTAL
FLTNB GetVoxSizeY()
Get the voxel's size along the Y axis, in mm.
#define SCANNER_SPECT_CONVERGENT
int IntfGetVoxIdxSHTOrientation(Intf_fields a_IF, int a_voxId)
Compute a voxel index corresponding to the default orientation (Sup/Hin/Trans) from the orientation...
template int IntfKeyGetValueFromFile< float >(const string &a_pathToHeader, const string &a_key, float *ap_return, int a_nbElts, int a_mandatoryFlag)
int IntfKeyGetOutputImgDataType(oImageDimensionsAndQuantification *ap_ID)
Singleton class that manages output writing on disk (images, sinograms, etc). It also manages loggi...
template int IntfKeyGetValueFromFile< string >(const string &a_pathToHeader, const string &a_key, string *ap_return, int a_nbElts, int a_mandatoryFlag)
int GetNbBeds()
Get the number of bed positions.
void IntfAllocInterpImg(FLTNB **a2p_img, Intf_fields a_IF)
Allocate memory for an image matrix to recover an image to interpolate.
Singleton class that Instantiate and initialize the scanner object.
FLTNB * IntfLoadImageFromScratch(const string &a_pathToHeaderFile, Intf_fields *ap_ImgFields, int vb)
void IntfToLowerCase(string *ap_str)
Set all characters of the string passed in parameter to lower case.
int IntfKeyGetRecurringValueFromFile(const string &a_pathToHeader, const string &a_key, T *ap_return, int a_nbElts, int a_mandatoryFlag, uint16_t a_nbOccurrences)
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 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])
#define INTF_SUPINE_HEADIN_TRANSAXIAL
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 IntfCheckKeyMatch(Intf_key ap_Key, const string &a_field)
Check if the key matches the string passed in parameter.
#define INTF_SUPINE_HEADIN_CORONAL
bool bed_position_provided
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...
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 IntfKeyGetValueFromFile< int >(const string &a_pathToHeader, const string &a_key, int *ap_return, int a_nbElts, int a_mandatoryFlag)
int IntfKeyIsArray(Intf_key ap_Key)
Check if the key passed in parameter is an array (contains brackets '{' and '}' ) ...
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)
FLTNB GetOffsetY()
Get the image offset along the Y axis, in mm.
Interfile key elements. This structure is used to recover and process the elements of an Interfile ...
#define SCANNER_SPECT_PINHOLE
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...
uint16_t ctr_to_ctr_separation
int IntfWriteHeaderImgData(ofstream &ap_ofile, const Intf_fields &ap_IntfF, int vb)
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 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...
string IntfKeyGetEndianStr(int a_val)
return the endian string corresponding to the value passed in parameter (see module INTF_ENDIANNESS)...
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.
template int IntfKeyGetValueFromFile< uint8_t >(const string &a_pathToHeader, const string &a_key, uint8_t *ap_return, int a_nbElts, int a_mandatoryFlag)
vector< string > GetDataFileName()
uint16_t nb_detector_heads
int GetNbTimeFrames()
Get the number of time frames.
int ConvertFromString(const string &a_str, string *a_result)
Copy the 'a_str' string in the position pointed by 'a_result'.
INTNB GetNbVoxXYZ()
Get the total number of voxels.
#define INTF_SUPINE_FEETIN_TRANSAXIAL
vector< FLTNB > image_duration
template int IntfKeyGetRecurringValueFromFile< long double >(const string &a_pathToHeader, const string &a_key, long double *ap_return, int a_nbElts, int a_mandatoryFlag, uint16_t a_nbOccurrences)
template int IntfKeyGetRecurringValueFromFile< float >(const string &a_pathToHeader, const string &a_key, float *ap_return, int a_nbElts, int a_mandatoryFlag, uint16_t a_nbOccurrences)
#define INTF_PRONE_HEADIN_SAGITTAL
This class is designed to manage all dimensions and quantification related stuff. ...
string IntfKeyGetModalityStr(int a_modalityIdx)
Convert the integer provided in parameter to the string related to the corresponding modality as de...
FLTNB GetOffsetX()
Get the image offset along the X axis, in mm.
INTNB GetNbVoxX()
Get the number of voxels along the X axis.
INTNB GetNbVoxZ()
Get the number of voxels along the Z axis.
int GetNbRespGates()
Get the number of respiratory gates.
uint32_t nb_energy_windows
int IntfKeyGetArrayNbElts(Intf_key a_Key)
Return the number of elts in an Interfile array Key.
string GetFileFromPath(const string &a_pathToFile)
Simply return the file from a path string passed in parameter.
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)
int IntfWriteHeaderMainData(const string &a_path, const Intf_fields &ap_IntfF, int vb)
int IntfKeyGetMaxArrayKey(Intf_key ap_Key)
Return the maximum value from an array key (key value contains brackets '{,,}' )
#define INTF_PRONE_HEADIN_TRANSAXIAL
int GetNbRespBasisFunctions()
Get the number of respiratory basis functions.
void IntfEraseSpaces(string *input_str)
Erase space, blank characters ((t,r,n)), and '!' before and after the characters in the string passed...
INTNB GetNbVoxY()
Get the number of voxels along the Y axis.
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...
bool is_mtx_size_different
template int IntfKeyGetValueFromFile< bool >(const string &a_pathToHeader, const string &a_key, bool *ap_return, int a_nbElts, int a_mandatoryFlag)
string originating_system