]> Creatis software - creaBruker.git/commitdiff
shorten up Series Description
authorjean-pierre roux <jean-pierre.roux@creatis.insa-lyon.fr>
Wed, 27 May 2009 10:38:38 +0000 (10:38 +0000)
committerjean-pierre roux <jean-pierre.roux@creatis.insa-lyon.fr>
Wed, 27 May 2009 10:38:38 +0000 (10:38 +0000)
lib/src1/bruker2dicom.cxx
lib/src1/bruker2dicom.h

index 710129b778aaac8994e8f5d27330b037def324b2..0473bb3ac3be310019cbbc36da201c6b931604c2 100644 (file)
@@ -3,7 +3,7 @@
 #include <boost/filesystem/operations.hpp>
 
 #ifndef PATH_MAX // If not defined yet : do it 
-       #define PATH_MAX 2048
+   #define PATH_MAX 2048
 #endif 
 
 
@@ -84,35 +84,36 @@ bool Bruker2Dicom::Execute()
 
          BrukerFieldData b_name=br_subject.GetFieldData("SUBJECT_name_string");
          std::string subject_name = b_name.GetStringValue()[0];
-        strPatientName = subject_name;
+         strPatientName = subject_name;
          cleanString(subject_name);
-        
+
          BrukerFieldData b_entry=br_subject.GetFieldData("SUBJECT_entry");
          std::string subject_entry = b_entry.GetStringValue()[0];
          //cleanString(subject_entry);
-        subject_entry = subject_entry.substr(11, subject_entry.size()-11);
-        
+         subject_entry = subject_entry.substr(11, subject_entry.size()-11);
          BrukerFieldData b_position=br_subject.GetFieldData("SUBJECT_position");
          std::string subject_position = b_position.GetStringValue()[0];
          //cleanString(subject_position);
-        subject_position = subject_position.substr(9, subject_position.size()-9);
-                        
+         subject_position = subject_position.substr(9, subject_position.size()-9);
          BrukerFieldData b_date=br_subject.GetFieldData("SUBJECT_date");
          std::string subject_date = b_date.GetStringValue()[0];
-        strStudyTimeDate = subject_date;
+         strStudyTimeDate = subject_date;
          cleanString(subject_date);
-        
          BrukerFieldData b_study_name=br_subject.GetFieldData("SUBJECT_study_name");
          std::string subject_study_name = b_study_name.GetStringValue()[0];
-        subject_study_name = subject_study_name.substr(1, subject_study_name.size()-2);
+         subject_study_name = subject_study_name.substr(1, subject_study_name.size()-2);
          cleanString(subject_date);
-        
-   strStudyDescr = subject_name + "." + subject_study_name + "." + subject_entry + "." + subject_position + "." + subject_date;
+
+   // subject_name is already in 'Patient Name' 
+   strStudyDescr = /*subject_name + "." + */ subject_study_name + "." + subject_entry + "." + subject_position + "." + subject_date;
 
    char outputDirName[(unsigned int) PATH_MAX+2];
 
    strStudyUID =  GDCM_NAME_SPACE::Util::CreateUniqueUID();
-   
+   serieNumber = 0;
    // -----------------------------------------------------
    // Iterate to ALL the objets(files/directories) found in the input directory
    // (this is level ZERO)
@@ -161,29 +162,20 @@ bool Bruker2Dicom::Execute()
          nbSlices =  b_list_size.GetIntValue()[0];
 
          strSerieDescr = GDCM_NAME_SPACE::Util::GetName(*it)
-                         + "." + acqp_protocol_location
+                       /*  + "." + acqp_protocol_location */ // always the same (in each acquisition)
                          + "." + acqp_scan_name
                          + "." + acqp_method.c_str();
 
          sprintf(outputDirName, "%s%c%s", OutputDirName.c_str(), 
                           GDCM_NAME_SPACE::GDCM_FILESEPARATOR,
                           strSerieDescr.c_str() );
-                         
+  
          std::cout << " ================================================================================\n"
-                  << " === [" << GDCM_NAME_SPACE::Util::GetName(*it) << "] -> [" << strSerieDescr << "]\n"
+                   << " === [" << GDCM_NAME_SPACE::Util::GetName(*it) << "] -> [" << strSerieDescr << "]\n"
                    << " ================================================================================"
                    << std::endl;
 
-/*                       
-         std::cout << " ================================================================================\n"
-                  << " ========================= [" << GDCM_NAME_SPACE::Util::GetName(*it).c_str()
-                   << acqp_protocol_location.c_str()
-                   << acqp_scan_name.c_str()
-                   << acqp_method.c_str()
-                   << "]\n"
-                   << " ================================================================================"
-                   << std::endl;
-*/
+
         if (verbose)
            printf ("outputDirName [%s]\n", outputDirName);   
 
@@ -571,6 +563,7 @@ void Bruker2Dicom::DealWithNiveau3(std::string level3Directory, std::string curr
    // ---------------------------
    imageSet = CreateImageSet ( );
    
+   serieNumber++;
    strSerieUID =  GDCM_NAME_SPACE::Util::CreateUniqueUID();
    if (nbInstants==1) // creer un seul fichier .mhd  pour toutes les Slices! (images natives)
    {
@@ -614,6 +607,7 @@ void Bruker2Dicom::DealWithNiveau3(std::string level3Directory, std::string curr
                 fwrite( buffer_2dseq, NX*NY*pixelSize, nbSlices, fp);     
              }
              fclose(fp);
+             serieNumber ++;
              strSerieUID =  GDCM_NAME_SPACE::Util::CreateUniqueUID();
        }  // end if mhd
        if (dicom)
@@ -633,9 +627,9 @@ void Bruker2Dicom::DealWithNiveau3(std::string level3Directory, std::string curr
                day,
                strStudyUID,
                strSerieUID,
-              strStudyDescr,
+               strStudyDescr,
                strSerieDescr,
-              strStudyTimeDate,
+               strStudyTimeDate,
                0,// index frame number
                GDCM_NAME_SPACE::UNMODIFIED_PIXELS_IMAGE
              );
@@ -652,8 +646,8 @@ void Bruker2Dicom::DealWithNiveau3(std::string level3Directory, std::string curr
          k = 0;
          for (sliceNb=0; sliceNb<nbSlices; sliceNb++)
          {
-           if (mhd)
-           {
+            if (mhd)
+            {
                sprintf(outputMhdFileName, "%s%cMhdData_%03d.mhd", currentOutputMhdDirName, 
                                         GDCM_NAME_SPACE::GDCM_FILESEPARATOR, k  );
                if (verbose)
@@ -704,11 +698,11 @@ void Bruker2Dicom::DealWithNiveau3(std::string level3Directory, std::string curr
                fclose(fp);
 // std::cout << "end writting[" << output2dseqSliceFileName << "]" << std::endl;
             }  // end if mhd
-           
-           if (dicom)
-           {
+   
+            if (dicom)
+            {
                // desperate try !
-              /* 
+             /* 
                sprintf(output2dseqSliceFileName, "%sdummy_buffer", 
                                                  currentOutputDirName.c_str(), GDCM_NAME_SPACE::GDCM_FILESEPARATOR);
                fp=fopen(output2dseqSliceFileName, "wb");
@@ -726,23 +720,23 @@ void Bruker2Dicom::DealWithNiveau3(std::string level3Directory, std::string curr
                             1, fp);
                }
                fclose(fp);
-              
+       
                fp=fopen(output2dseqSliceFileName, "rb");
                if (!fp)
                {     
                    std::cout << "Cannot open [" << output2dseqSliceFileName << "] for reading" << std::endl;
                    exit (0);
-               }              
+               }       
                fread( pixelsForCurrentSlice,
                             frameSize*nbInstants,
                             1, fp);
                fclose(fp);
               // end of desperate try !
-              */
+              */
 
                /* ----------- Write Dicom Image  ---------------*/
-              
-              int frameSize = NX*NY*pixelSize;
+       
+               int frameSize = NX*NY*pixelSize;
                for (instantNb=0; instantNb<nbInstants; instantNb++)
                {
                   memcpy(pixelsForCurrentSlice + frameSize*instantNb, buffer_2dseq +(nbSlices*instantNb + sliceNb)*frameSize, frameSize);
@@ -764,16 +758,16 @@ void Bruker2Dicom::DealWithNiveau3(std::string level3Directory, std::string curr
                   day,
                   strStudyUID,
                   strSerieUID,
-                 strStudyDescr,
+                  strStudyDescr,
                   strSerieDescr,
-                 strStudyTimeDate,
+                  strStudyTimeDate,
                   sliceNb*nbInstants,
                   GDCM_NAME_SPACE::UNMODIFIED_PIXELS_IMAGE
                );
                if (verbose)
                   std::cout << "--- Output DCM file [" << output2dseqSliceFileName << "]" << std::endl;      
 
-           } // en if dicom
+           } // en if dicom
 
         k++;
         }
@@ -797,7 +791,7 @@ void Bruker2Dicom::DealWithNiveau3(std::string level3Directory, std::string curr
 void Bruker2Dicom::dealWithCarto(GDCM_NAME_SPACE::DirListType &fileNames, int NX, int NY, int nbSlices, 
                                  double fovX, double fovY, double sliceDistance,
                                  char *copyFile, std::string &currentOutputDirName, 
-                                char *outputMhdFileName, char *output2dseqCartoName)
+                                 char *outputMhdFileName, char *output2dseqCartoName)
 {
    // -----------------------------------------------------
    //  deal with MatLab-generated Carto file.
@@ -843,7 +837,7 @@ void Bruker2Dicom::dealWithCarto(GDCM_NAME_SPACE::DirListType &fileNames, int NX
                          << NX*NY*sizeof(double)*nbSlices << std::endl;
                   std::string lastFileName = GDCM_NAME_SPACE::Util::GetName((*it).c_str());
                if (mhd)
-              {
+               {
                   // Copy the data file in the new directory
                   sprintf(copyFile, "cp %s %s%c%s", (*it).c_str() ,
                             currentOutputDirName.c_str(),GDCM_NAME_SPACE::GDCM_FILESEPARATOR, lastFileName.c_str()); 
@@ -879,17 +873,17 @@ void Bruker2Dicom::dealWithCarto(GDCM_NAME_SPACE::DirListType &fileNames, int NX
                      fclose(fp);
                   }
                   if (verbose)
-                    std::cout << "--- end write Carto MHD file [" << outputMhdFileName << "]" << std::endl;
+                     std::cout << "--- end write Carto MHD file [" << outputMhdFileName << "]" << std::endl;
                }  // end if mhd
 
             // ----------- Write Dicom Image  ---------------
 
                if (dicom)
-              {
+               {
                   sprintf(output2dseqCartoName, "%s%c%s%s",
                                        currentOutputDirName.c_str(),GDCM_NAME_SPACE::GDCM_FILESEPARATOR, lastFileName.c_str(), ".dcm" );
                   if (verbose)
-                    std::cout << "--- end create name output2dseqCartoName file [" << output2dseqCartoName << "]" << std::endl;
+                     std::cout << "--- end create name output2dseqCartoName file [" << output2dseqCartoName << "]" << std::endl;
 
                   strSerieUID =  GDCM_NAME_SPACE::Util::CreateUniqueUID(); //New SerieUID for each carto.
                   std::string strNewSerieDescr(strSerieDescr+ "_" +GDCM_NAME_SPACE::Util::GetName((*it).c_str()));
@@ -904,9 +898,9 @@ void Bruker2Dicom::dealWithCarto(GDCM_NAME_SPACE::DirListType &fileNames, int NX
                      day,
                      strStudyUID,
                      strSerieUID,
-                    strStudyDescr,
+                     strStudyDescr,
                      strNewSerieDescr,
-                    strStudyTimeDate,
+                     strStudyTimeDate,
                      0,
                      GDCM_NAME_SPACE::CREATED_IMAGE
                   );
@@ -914,10 +908,10 @@ void Bruker2Dicom::dealWithCarto(GDCM_NAME_SPACE::DirListType &fileNames, int NX
 
                delete [] buffer_carto;
                if (verbose) 
-                    std::cout << "--- End writing Carto DICOM file [" << output2dseqCartoName << "]" << std::endl;
+                  std::cout << "--- End writing Carto DICOM file [" << output2dseqCartoName << "]" << std::endl;
                break; // don't check for more ident on same file name!
 
-           }
+            }
             icode++;
          } 
       }
@@ -933,7 +927,7 @@ bool Bruker2Dicom::CreateDirectory(std::string OutputDirName)
    
    if (verbose)
       std::cout << "Check for output directory :[" << OutputDirName << "]."
-                <<std::endl;           
+                <<std::endl;
    if ( ! boost::filesystem::is_directory(OutputDirName) )    // dirout not found
    {
       std::string strDirNameout(OutputDirName);        // to please gcc 4
@@ -1125,7 +1119,7 @@ void Bruker2Dicom::MakeDicomImage(unsigned char *tabPixels,
               std::string &serieUID,
               std::string &studyDescr,
               std::string &serieDescr,
-             std::string &strStudyTimeDate,
+              std::string &strStudyTimeDate,
               int imgNum,
               GDCM_NAME_SPACE::ImageContentType contentType 
       )
index 71ff5dbe827e893e9b18268c7f52d532b3fb63ff..85e821252476af894436ae6b1f2d79990ba55f57 100644 (file)
@@ -116,7 +116,9 @@ private :
    std::string strStudyDescr; 
    std::string strSerieDescr;
    std::string strStudyTimeDate;
-   std::string strPatientName;      
+   std::string strPatientName;
+   
+   int serieNumber;      
 };