From: jpr Date: Fri, 28 Mar 2008 15:36:57 +0000 (+0000) Subject: Allow user to create mutiframes X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=d93bdc3a545dc713354ab0c8ad9558ee11dfe0e9;p=gdcm.git Allow user to create mutiframes --- diff --git a/Example/Dense2007ToDicom.cxx b/Example/Dense2007ToDicom.cxx index afeb9b5b..bf76dcee 100755 --- a/Example/Dense2007ToDicom.cxx +++ b/Example/Dense2007ToDicom.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: Dense2007ToDicom.cxx,v $ Language: C++ - Date: $Date: 2008/03/17 13:16:10 $ - Version: $Revision: 1.6 $ + Date: $Date: 2008/03/28 15:36:57 $ + Version: $Revision: 1.7 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -28,7 +28,7 @@ #include "gdcmFileHelper.h" #include "gdcmDebug.h" #include "gdcmDirList.h" - +#include "gdcmUtil.h" #include "gdcmArgMgr.h" /** @@ -37,12 +37,12 @@ * Hope they don't change soon! */ +void LoadPeakStrain(std::ifstream &from, std::string imageName, const char * patientname, std::string studyUID); +void LoadStrain(std::ifstream &from, std::string imageName, const char * patientname, bool createMultiFrame, std::string studyUID); +void MakeDicomImage(float *tabVal, float *X, float *Y, float *Z, int NP, std::string dcmImageName, + const char * patientname, int nbFrames, std::string studyUID, std::string serieUID); -void LoadPeakStrain(std::ifstream &from, std::string imageName); -void LoadStrain(std::ifstream &from, std::string imageName); -void MakeDicomImage(float *tabVal, float *X, float *Y, float *Z, int NP, std::string dcmImageName); - -int verbose; +bool verbose; int main(int argc, char *argv[]) { @@ -51,6 +51,8 @@ int main(int argc, char *argv[]) " Converts the '.txt' files into 16 bits Dicom Files, ", " usage: ", " Dense2007ToDicom strain=...strain.txt peak_strain=...peak_strain.txt ", + " [patientname = Patient's name] ", + " [m]ultiframe ", " [verbose] [debug] ", " ", " verbose : user wants to run the program in 'verbose mode' ", @@ -81,11 +83,15 @@ int main(int argc, char *argv[]) const char *strain = am->ArgMgrWantString("strain",usage); const char *peak_strain = am->ArgMgrWantString("peak_strain",usage); + + const char *patientName = am->ArgMgrGetString("patientname"); + bool createMultiFrame = (am->ArgMgrDefined("m") != 0); + if (am->ArgMgrDefined("debug")) GDCM_NAME_SPACE::Debug::DebugOn(); - verbose = am->ArgMgrDefined("verbose"); + verbose = ( 0 != am->ArgMgrDefined("verbose") ); // if unused Param we give up if ( am->ArgMgrPrintUnusedLabels() ) @@ -98,34 +104,35 @@ int main(int argc, char *argv[]) // ----- Begin Processing ----- - std::ifstream fromPeakStrain( peak_strain ); if ( !fromPeakStrain ) { - std::cout << "Can't open file" << peak_strain << std::endl; + std::cout << "Can't open file [" << peak_strain << "]" << std::endl; exit(0); } std::ifstream fromStrain( strain ); if ( !fromStrain ) { - std::cout << "Can't open file" << strain << std::endl; + std::cout << "Can't open file [" << strain << "]" << std::endl; exit(0); - } + } + + std::string strStudyUID = GDCM_NAME_SPACE::Util::CreateUniqueUID(); - std::cout << "Success in open file" << peak_strain << std::endl; - LoadPeakStrain(fromPeakStrain, peak_strain); + std::cout << "Success in open file [" << peak_strain << "]" << std::endl; + LoadPeakStrain(fromPeakStrain, peak_strain, patientName,strStudyUID); fromPeakStrain.close(); - std::cout << "Success in open file" << strain << std::endl; - LoadStrain(fromStrain, strain); + std::cout << "Success in open file [" << strain << "]" << std::endl; + LoadStrain(fromStrain, strain, patientName, createMultiFrame, strStudyUID); fromStrain.close(); return 1; } // ===================================================================================================================== -void LoadPeakStrain(std::ifstream &from, std::string textFileName) +void LoadPeakStrain(std::ifstream &from, std::string textFileName, const char * patientname,std::string studyUID) { // in sax_base_slice0_peak_strain.txt : @@ -162,7 +169,7 @@ followed by their Peak E22 strain, an array of NP elements, from >> str1; from >> str1; from >> NP; - + std::cout << "NP : " << NP << std::endl; //Origin of (readout, phase enc, slice sel) coordinates in 3D = 87.3243 3.19392 88.2381 @@ -177,27 +184,27 @@ followed by their Peak E22 strain, an array of NP elements, from >> str1; from >> str1; from >> str1; - + float readout, phase_enc, slice_sel; from >> readout; from >> phase_enc; from >> slice_sel; std::cout << " readout " << readout << " phase_enc " << phase_enc << " slice_sel " << slice_sel << std::endl; - + // Readout direction in 3D = -0.162314 -0.0771294 -0.983720 - + from >> str1; from >> str1; from >> str1; from >> str1; from >> str1; - + float readoutX, readoutY, readoutZ; from >> readoutX; from >> readoutY; from >> readoutZ; std::cout << " readoutX " << readoutX << " readoutY " << readoutY << " readoutZ " << readoutZ << std::endl; - + // Phase Enc. direction in 3D = -0.540606 -0.827052 0.154046 from >> str1; @@ -206,7 +213,7 @@ followed by their Peak E22 strain, an array of NP elements, from >> str1; from >> str1; from >> str1; - + float phase_encX, phase_encY, phase_encZ; from >> phase_encX; from >> phase_encY; @@ -220,7 +227,7 @@ followed by their Peak E22 strain, an array of NP elements, from >> str1; from >> str1; from >> str1; - + float slice_selX, slice_selY, slice_selZ; from >> slice_selX; from >> slice_selY; @@ -228,7 +235,6 @@ followed by their Peak E22 strain, an array of NP elements, std::cout << " slice_selX " << slice_selX << " slice_selY " << slice_selY << " slice_selZ " << slice_selZ << std::endl; - // Skip 5 lines : /* The following are the (readout, phase enc, slice sel) coordinates (mm) of the grid points for which strains are calculated, @@ -257,15 +263,15 @@ std::cout << "------------start skipping 1 line---------------- " << std::endl; std::getline(from, str1); std::cout << "[" << str1 << "]" << std::endl; std::cout << "------------stop skipping ---------------- " << std::endl; - + float *X = new float[NP]; float *Y = new float[NP]; float *Z = new float[NP]; - + char c; int i; for (i=0; i> X[i]; for (;;) { if (!from.get(c)) @@ -275,8 +281,8 @@ std::cout << "------------stop skipping ---------------- " << std::endl; break; } } - - from >> Y[i]; + + from >> Y[i]; for (;;) { if (!from.get(c)) break; @@ -284,65 +290,74 @@ std::cout << "------------stop skipping ---------------- " << std::endl; from.putback(c); break; } - } + } from >> Z[i]; - + } // end for i> ecc_strain[i]; - if (verbose) - std::cout << ecc_strain[i] << std::endl; + from >> ecc_strain[i]; + if (verbose) + std::cout << ecc_strain[i] << std::endl; } + delete []ecc_strain; std::cout << "--------------- Err_strain ------------------" << std::endl; float *err_strain = new float[NP]; for (i=0; i> err_strain[i]; - if (verbose) - std::cout << err_strain[i] << std::endl; + from >> err_strain[i]; + if (verbose) + std::cout << err_strain[i] << std::endl; } - + delete []err_strain; + std::cout << "--------------- E11_strain ------------------" << std::endl; float *e11_strain = new float[NP]; for (i=0; i> e11_strain[i]; - if (verbose) - std::cout << e11_strain[i] << std::endl; + from >> e11_strain[i]; + if (verbose) + std::cout << e11_strain[i] << std::endl; } - + delete []e11_strain; + std::cout << "--------------- E22_strain ------------------" << std::endl; float *e22_strain = new float[NP]; for (i=0; i> e22_strain[i]; - if (verbose) - std::cout << e22_strain[i] << std::endl; + from >> e22_strain[i]; + if (verbose) + std::cout << e22_strain[i] << std::endl; } - - std::string dcmImageName; + delete []e22_strain; + std::string dcmImageName; + std::string serieUID; + //followed by their peak Ecc strain, an array of NP elements, + serieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID(); dcmImageName = textFileName + "_peak_Ecc_strain.dcm"; - MakeDicomImage(ecc_strain, X, Y, Z, NP, dcmImageName); + MakeDicomImage(ecc_strain, X, Y, Z, NP, dcmImageName, patientname, 1, studyUID, serieUID); //followed by their peak Err strain, an array of NP elements, + serieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID(); dcmImageName = textFileName + "_peak_Err_strain.dcm"; - MakeDicomImage(err_strain, X, Y, Z, NP, dcmImageName); - + MakeDicomImage(err_strain, X, Y, Z, NP, dcmImageName, patientname, 1, studyUID, serieUID); + //followed by their peak E11 strain, an array of NP elements, + serieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID(); dcmImageName = textFileName + "_peak_E11_strain.dcm"; - MakeDicomImage(e11_strain, X, Y, Z, NP, dcmImageName); - + MakeDicomImage(e11_strain, X, Y, Z, NP, dcmImageName, patientname, 1, studyUID, serieUID); + //followed by their Peak E22 strain, an array of NP elements, + serieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID(); dcmImageName = textFileName + "_peak_E22_strain.dcm"; - MakeDicomImage(e22_strain, X, Y, Z, NP, dcmImageName); + MakeDicomImage(e22_strain, X, Y, Z, NP, dcmImageName, patientname, 1, studyUID, serieUID); } // ===================================================================================================================== -void LoadStrain(std::ifstream &from, std::string textFileName) +void LoadStrain(std::ifstream &from, std::string textFileName, const char * patientname, bool createMultiFrame, std::string studyUID) { // in sax_base_slice0_strain.txt : @@ -372,11 +387,11 @@ Note that RV Err, E11 and E22 strains are not calculated due to the small thickn return; std::string str1; - int NP; // Number of Pints + int NP; // Number of Points int NCF; // Number of cine frames float TR; // Temporal resolution float FFS; // First frame starts - + // Number of cine frames = 18 from >> str1; from >> str1; @@ -408,7 +423,7 @@ Note that RV Err, E11 and E22 strains are not calculated due to the small thickn from >> str1; from >> str1; from >> NP; - + std::cout << "NP : " << NP << std::endl; //Origin of (readout, phase enc, slice sel) coordinates in 3D = 87.324341 3.193918 88.238113 @@ -423,27 +438,27 @@ Note that RV Err, E11 and E22 strains are not calculated due to the small thickn from >> str1; from >> str1; from >> str1; - + float readout, phase_enc, slice_sel; from >> readout; from >> phase_enc; from >> slice_sel; std::cout << " readout " << readout << " phase_enc " << phase_enc << " slice_sel " << slice_sel << std::endl; - + // Readout direction in 3D = -0.162314 -0.0771294 -0.983720 - + from >> str1; from >> str1; from >> str1; from >> str1; from >> str1; - + float readoutX, readoutY, readoutZ; from >> readoutX; from >> readoutY; from >> readoutZ; std::cout << " readoutX " << readoutX << " readoutY " << readoutY << " readoutZ " << readoutZ << std::endl; - + // Phase Enc. direction in 3D = -0.540606 -0.827052 0.154046 from >> str1; @@ -452,7 +467,7 @@ Note that RV Err, E11 and E22 strains are not calculated due to the small thickn from >> str1; from >> str1; from >> str1; - + float phase_encX, phase_encY, phase_encZ; from >> phase_encX; from >> phase_encY; @@ -536,64 +551,164 @@ std::cout << "------------stop skipping ---------------- " << std::endl; from >> Z[i]; } +char frame[10]; +std::string dcmImageName; +std::string serieUID; + +std::cout << "=======================================================================================" << createMultiFrame << std::endl; +if(!createMultiFrame) { // One image per file here (single frame) + +serieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID(); +float *ecc_strain = new float[NP]; +for (int nbr_of_frames=0; nbr_of_frames < NCF; nbr_of_frames++) +{ +sprintf(frame, "_%d", nbr_of_frames); + std::cout << "--------------- Ecc_strain ------------------" << std::endl; - float *ecc_strain = new float[NP]; for (i=0; i> ecc_strain[i]; if (verbose) std::cout << ecc_strain[i] << std::endl; } - +//followed by their Ecc strain, an array of NP elements, + dcmImageName = textFileName + frame + "_Ecc_strain.dcm"; + std::cout << "Try to make image :[" << dcmImageName << "]" << std::endl; + MakeDicomImage(ecc_strain, X, Y, Z, NP, dcmImageName, patientname, 1, studyUID, serieUID); +}// end for nbr_of_frames +delete []ecc_strain; + +serieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID(); +float *err_strain = new float[NP]; +for (int nbr_of_frames=0; nbr_of_frames < NCF; nbr_of_frames++) +{ +sprintf(frame, "_%d", nbr_of_frames); std::cout << "--------------- Err_strain ------------------" << std::endl; - float *err_strain = new float[NP]; for (i=0; i> err_strain[i]; if (verbose) std::cout << err_strain[i] << std::endl; } - +//followed by their Err strain, an array of NP elements, + dcmImageName = textFileName + frame + "_Err_strain.dcm"; + std::cout << "Try to make image :[" << dcmImageName << "]" << std::endl; + MakeDicomImage(err_strain, X, Y, Z, NP, dcmImageName, patientname, 1, studyUID, serieUID); +}// end for nbr_of_frames +delete []err_strain; + +serieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID(); +float *e11_strain = new float[NP]; +for (int nbr_of_frames=0; nbr_of_frames < NCF; nbr_of_frames++) +{ +sprintf(frame, "_%d", nbr_of_frames); std::cout << "--------------- E11_strain ------------------" << std::endl; - float *e11_strain = new float[NP]; for (i=0; i> e11_strain[i]; if (verbose) std::cout << e11_strain[i] << std::endl; } - +//followed by their E11 strain, an array of NP elements, + dcmImageName = textFileName + frame + "_E11_strain.dcm"; + std::cout << "Try to make image :[" << dcmImageName << "]" << std::endl; + MakeDicomImage(e11_strain, X, Y, Z, NP, dcmImageName, patientname, 1, studyUID, serieUID); +}// end for nbr_of_frames +delete []e11_strain; + +serieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID(); +float *e22_strain = new float[NP]; +for (int nbr_of_frames=0; nbr_of_frames < NCF; nbr_of_frames++) +{ +sprintf(frame, "_%d", nbr_of_frames); std::cout << "--------------- E22_strain ------------------" << std::endl; - float *e22_strain = new float[NP]; for (i=0; i> e22_strain[i]; if (verbose) std::cout << e22_strain[i] << std::endl; - } + } +//followed by their E22 strain, an array of NP elements, + dcmImageName = textFileName + frame + "_E22_strain.dcm"; + std::cout << "Try to make image :[" << dcmImageName << "]" << std::endl; + MakeDicomImage(e22_strain, X, Y, Z, NP, dcmImageName, patientname, 1, studyUID, serieUID); +} // end for nbr_of_frames +delete [] e22_strain; + +} // end of single frame + + +else // generate Multiframe files +{ - std::string dcmImageName; +serieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID(); +float *ecc_strain = new float[NP*NCF]; + std::cout << "--------------- Ecc_strain ------------------" << std::endl; + for (i=0; i> ecc_strain[i]; + if (verbose) + std::cout << ecc_strain[i] << std::endl; + } //followed by their Ecc strain, an array of NP elements, dcmImageName = textFileName + "_Ecc_strain.dcm"; - MakeDicomImage(ecc_strain, X, Y, Z, NP, dcmImageName); + std::cout << "Try to make image :[" << dcmImageName << "]" << std::endl; + MakeDicomImage(ecc_strain, X, Y, Z, NP, dcmImageName, patientname, NCF, studyUID, serieUID); +delete []ecc_strain; -//followed by their Err strain, an array of NP elements, + + +float *err_strain = new float[NP*NCF]; + std::cout << "--------------- Err_strain ------------------" << std::endl; + for (i=0; i> err_strain[i]; + if (verbose) + std::cout << err_strain[i] << std::endl; + } +//followed by their Ecc strain, an array of NP elements, dcmImageName = textFileName + "_Err_strain.dcm"; - MakeDicomImage(err_strain, X, Y, Z, NP, dcmImageName); - -//followed by their E11 strain, an array of NP elements, + std::cout << "Try to make image :[" << dcmImageName << "]" << std::endl; + MakeDicomImage(err_strain, X, Y, Z, NP, dcmImageName, patientname, NCF, studyUID, serieUID); +delete []err_strain; + + + +float *e11_strain = new float[NP*NCF]; + std::cout << "--------------- E11_strain ------------------" << std::endl; + for (i=0; i> e11_strain[i]; + if (verbose) + std::cout << e11_strain[i] << std::endl; + } +//followed by their Ecc strain, an array of NP elements, dcmImageName = textFileName + "_E11_strain.dcm"; - MakeDicomImage(e11_strain, X, Y, Z, NP, dcmImageName); - -//followed by their E22 strain, an array of NP elements, + std::cout << "Try to make image :[" << dcmImageName << "]" << std::endl; + MakeDicomImage(e11_strain, X, Y, Z, NP, dcmImageName, patientname, NCF, studyUID, serieUID); +delete []e11_strain; + + + +float *e22_strain = new float[NP*NCF]; + std::cout << "--------------- E22_strain ------------------" << std::endl; + for (i=0; i> e22_strain[i]; + if (verbose) + std::cout << e22_strain[i] << std::endl; + } +//followed by their Ecc strain, an array of NP elements, dcmImageName = textFileName + "_E22_strain.dcm"; - MakeDicomImage(e22_strain, X, Y, Z, NP, dcmImageName); - + std::cout << "Try to make image :[" << dcmImageName << "]" << std::endl; + MakeDicomImage(e22_strain, X, Y, Z, NP, dcmImageName, patientname, NCF, studyUID, serieUID); +delete []e22_strain; + +} // end of Multiframe } // ===================================================================================================================== -void MakeDicomImage(float *tabVal, float *X, float *Y, float *Z, int NP, std::string dcmImageName) +void MakeDicomImage(float *tabVal, float *X, float *Y, float *Z, int NP, std::string dcmImageName, const char * patientName, int nbFrames, std::string studyUID, std::string serieUID) { + +std::cout << "==============================================================================" + << "enter MakeDicomImage [" << dcmImageName << "] [" << patientName << "]" << std::endl; float minX = 99999., minY = 99999., minZ = 99999.; float maxX = 0., maxY = 0., maxZ = 0.; int i; @@ -618,36 +733,33 @@ void MakeDicomImage(float *tabVal, float *X, float *Y, float *Z, int NP, std::st std::cout << "Max X,Y,Z " << maxX << " " << maxY << " " << maxZ << std::endl; std::cout << "Size X,Y,Z " << maxX-minX << " " << maxY-minY << " " << maxZ-minZ << std::endl; -// uint16_t *img = new uint16_t[int(maxX+0.5)*int(maxY+0.5)]; - uint16_t *img = new uint16_t[int(maxX*4.)*int(maxY*4.)]; - - // Set whole image to 0 - for(int i3=0;i3InsertEntryString(str.str(),0x0028,0x0010,"US"); // Rows - + // Set the pixel type // 16; //8, 16, 32 file->InsertEntryString("16",0x0028,0x0100,"US"); // Bits Allocated @@ -669,6 +781,30 @@ void MakeDicomImage(float *tabVal, float *X, float *Y, float *Z, int NP, std::st // Set the samples per pixel // 1:Grey level, 3:RGB file->InsertEntryString("1",0x0028,0x0002, "US"); // Samples per Pixel + if (nbFrames != 1) + { + str.str(""); + str << nbFrames; + file->InsertEntryString(str.str(),0x0028,0x0008,"IS"); // Number of Frames + } + + if (strlen(patientName) != 0) + file->InsertEntryString(patientName,0x0010,0x0010, "PN"); // Patient's Name + + file->InsertEntryString(studyUID, 0x0020, 0x000d, "UI"); + file->InsertEntryString(serieUID, 0x0020, 0x000e, "UI"); + + int pos = 0; // get the usefull part of the name +/* + for(i=0, pos=0; posInsertEntryString(&(dcmImageName.c_str()[pos]),0x0008,0x103e, "LO"); // Series Description /* // Set Rescale Intercept str.str(""); @@ -685,7 +821,8 @@ void MakeDicomImage(float *tabVal, float *X, float *Y, float *Z, int NP, std::st fileH = GDCM_NAME_SPACE::FileHelper::New(file); // cast is just to avoid warnings (*no* conversion) //fileH->SetImageData((uint8_t *)img,int(maxX*maxY)*sizeof(uint16_t)); // troubles when maxX, mayY are *actually* float! - fileH->SetImageData((uint8_t *)img,int(maxX*4.)*int(maxY*4.)*sizeof(uint16_t)); + + fileH->SetImageData((uint8_t *)img,int(maxX*4.)*int(maxY*4.)*nbFrames*sizeof(uint16_t)); fileH->SetWriteModeToRaw(); fileH->SetWriteTypeToDcmExplVR();