]> Creatis software - creaBruker.git/commitdiff
Create 'Patient' directory + 'Study' directory
authorjean-pierre roux <jean-pierre.roux@creatis.insa-lyon.fr>
Mon, 12 Oct 2009 20:44:55 +0000 (20:44 +0000)
committerjean-pierre roux <jean-pierre.roux@creatis.insa-lyon.fr>
Mon, 12 Oct 2009 20:44:55 +0000 (20:44 +0000)
Deal with strange name '2dseq_Angio'

lib/src1/bruker2dicom.cxx
lib/src1/bruker2dicom.h

index bdf1e4d73aa2b32dbe31c3bfd62061df758d9059..9f61f7a358f9667ba7f835b4b81eb9cda91f7af8 100644 (file)
@@ -11,7 +11,7 @@
 
 bool Bruker2Dicom::Execute()
 {
-   // ----- Check input values -----
+   // ----- Check input directory name -----
 
    bool bigEndian = GDCM_NAME_SPACE::Util::IsCurrentProcessorBigEndian();
  
@@ -27,6 +27,8 @@ bool Bruker2Dicom::Execute()
          std::cout << "OK : [" << InputDirName << "] is a Directory." << std::endl;
    }
 
+   // ----- Check output directory name -----
+    
    std::string strDirNameOut(OutputDirName); 
    bool res=CreateDirectory(strDirNameOut);
    if (!res) {
@@ -84,45 +86,66 @@ bool Bruker2Dicom::Execute()
 
   // get info for 'Study Description'  
 
-         BrukerFieldData b_name=br_subject.GetFieldData("SUBJECT_name_string");
-         std::string subject_name = b_name.GetStringValue()[0];
-         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);
+    BrukerFieldData b_name=br_subject.GetFieldData("SUBJECT_name_string");
+    std::string subject_name = b_name.GetStringValue()[0];
+    strPatientName = subject_name;
+    cleanString(subject_name);
+        
+    // creation directory : 'nom du patient'
+    std::string tempStringPatDir(OutputDirName);
+    tempStringPatDir = tempStringPatDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR + subject_name;
+        
+    res=CreateDirectory(tempStringPatDir);
+    if (!res) {
+       std::cout << "[" << tempStringPatDir << "] Directory creation failure " << std::endl;
+       throw ( BrukerHopelessException ("Patient directory creation failure "));
+    }    
+
+    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);
  
-         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);
+    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);
  
-         BrukerFieldData b_date=br_subject.GetFieldData("SUBJECT_date");
-         std::string subject_date = b_date.GetStringValue()[0];
-         strStudyTimeDate = subject_date;
-         cleanString(subject_date);
+    BrukerFieldData b_date=br_subject.GetFieldData("SUBJECT_date");
+    std::string subject_date = b_date.GetStringValue()[0];
+    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);
-         cleanString(subject_date);
-
-   // subject_name is already in 'Patient Name' 
-   strStudyDescr = /*subject_name + "." + */ subject_study_name + "." + subject_entry + "." + subject_position + "." + 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);
+    cleanString(subject_study_name);
 
+    // subject_name is already in 'Patient Name' 
+    strStudyDescr = /*subject_name + "." + */ subject_study_name + "." + subject_entry + "." + subject_position + "." + subject_date;
+   
+    // creation directory : 'nom de la Study'
+    
+    std::string tempStringStudyDir(OutputDirName);
+    tempStringStudyDir = tempStringPatDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR + strStudyDescr;
+        
+    res=CreateDirectory(tempStringStudyDir);
+    if (!res) {
+       std::cout << "[" << tempStringStudyDir << "] Directory creation failure " << std::endl;
+       throw ( BrukerHopelessException ("Study directory creation failure "));
+    }    
+   
    char outputDirName[(unsigned int) PATH_MAX+2];
 
-   strStudyUID  GDCM_NAME_SPACE::Util::CreateUniqueUID();
-   serieNumber = 0;
+   strStudyUID    = GDCM_NAME_SPACE::Util::CreateUniqueUID();
+   serieNumber    = 0;
    instanceNumber = 0;
    // -----------------------------------------------------
    // Iterate to ALL the objets(files/directories) found in the input directory
    // (this is level ZERO)
    // each Directory (name : 1, 2, 3, ...) will be a Dicom Serie
    // -----------------------------------------------------
-           
    GDCM_NAME_SPACE::DirListType::iterator it;
 
    for (it = fileNames.begin();
@@ -169,7 +192,7 @@ bool Bruker2Dicom::Execute()
                          + "." + acqp_scan_name
                          + "." + acqp_method.c_str();
 
-         sprintf(outputDirName, "%s%c%s", OutputDirName.c_str(), 
+         sprintf(outputDirName, "%s%c%s", tempStringStudyDir.c_str(),                //OutputDirName.c_str(), 
                           GDCM_NAME_SPACE::GDCM_FILESEPARATOR,
                           strSerieDescr.c_str() );
   
@@ -443,6 +466,7 @@ void Bruker2Dicom::DealWithNiveau3(std::string level3Directory, std::string curr
    fileNames = dirList.GetFilenames();
 
    char original2dseqName       [(unsigned int) PATH_MAX+2];
+   char original2dseqName_XXX   [(unsigned int) PATH_MAX+2];   
    char currentOutputMhdDirName [(unsigned int) PATH_MAX+2];
 
    char outputMhdFileName       [(unsigned int) PATH_MAX+2];
@@ -605,9 +629,17 @@ void Bruker2Dicom::DealWithNiveau3(std::string level3Directory, std::string curr
    fp = fopen(original2dseqName, "rb");
    if (!fp) 
    {
-      std::cout << "Cannot open [" << original2dseqName << "] for reading" << std::endl;
-      throw ( BrukerHopelessException ("Hopeless! Cannot open '2dseq'"));
-      //exit (0);
+      // try 2dseq_Angio2D ?!?
+
+      sprintf( original2dseqName_XXX, "%s%s", original2dseqName, "_Angio2D");
+      fp = fopen(original2dseqName_XXX, "rb");
+      if (!fp)
+      {
+         std::cout << "Cannot open [" << original2dseqName << "] nor [" <<  original2dseqName_XXX << "] for reading" << std::endl;
+         fclose(fp);    
+         throw ( BrukerHopelessException ("Hopeless! Cannot open '2dseq'"));
+         //exit (0);
+      }
    }
    
    unsigned char *buffer_2dseq = new unsigned char[NX*NY*pixelSize*nbSlices*nbInstants];   
@@ -654,7 +686,7 @@ void Bruker2Dicom::DealWithNiveau3(std::string level3Directory, std::string curr
                fprintf(fp, "DimSize = %d %d %d\n", NX, NY, nbSlices );
                fprintf(fp, "HeaderSize = %d\n", 0);
                //fprintf(fp, "ElementSpacing = %lf %lf %lf\n",fovX/NY, fovY/NY, sliceDistance );
-              fprintf(fp, "ElementSpacing = %lf %lf %lf\n", spatResolX, spatResolX, sliceDistance );
+              fprintf(fp, "ElementSpacing = %lf %lf %lf\n", spatResolX, spatResolY, sliceDistance );
                fprintf(fp, "Position = 0 0 %d\n", 0 );
                fprintf(fp, "Offset = 0 0 0\n" );
                fprintf(fp, "CenterOfRotation = 0 0 0\n" );
@@ -691,7 +723,7 @@ void Bruker2Dicom::DealWithNiveau3(std::string level3Directory, std::string curr
                nbFrames,
                pixelSize,
                //fovX/NY, fovY/NY, sliceDistance,
-              spatResolX, spatResolX, sliceDistance,
+              spatResolX, spatResolY, sliceDistance,
                output2dseqSliceFileName,
                strPatientName,
                day,
@@ -741,7 +773,7 @@ void Bruker2Dicom::DealWithNiveau3(std::string level3Directory, std::string curr
                    fprintf(fp, "DimSize = %d %d %d\n", NX, NY, nbInstants);  
                    fprintf(fp, "HeaderSize = %d\n", 0); 
                    //fprintf(fp, "ElementSpacing = %lf %lf %lf\n",fovX/NY, fovY/NY, 1.0 ); // 
-                   fprintf(fp, "ElementSpacing = %lf %lf %lf\n",spatResolX, spatResolX, 1.0 ); //slice distance : no meaning for temporal serie
+                   fprintf(fp, "ElementSpacing = %lf %lf %lf\n",spatResolX, spatResolY, 1.0 ); //slice distance : no meaning for temporal serie
                   fprintf(fp, "Position = 0 0 %d\n", sliceNb );  
                    fprintf(fp, "Offset = 0 0 0\n" );  
                    fprintf(fp, "CenterOfRotation = 0 0 0\n" );
index 0199ec02cc804e9c4515f70b49d5b9c0ad79c3f8..7e54ce36565e20acd0be0786a06016ce4017beb7 100644 (file)
@@ -30,10 +30,10 @@ public:
 */
   ~Bruker2Dicom (){};
 
-  void SetInputDirectory (const std::string &i) { InputDirName  = i;  }
-  void SetOutputDirectory(const std::string &o) { OutputDirName = o;  }
-  void SetConvertModeToDicom()                  { dicom = 1; mhd  = 0;}
-  void SetConvertModeToMhd()                    { dicom = 0; mhd  = 1;}  
+  void SetInputDirectory (const std::string &i) { InputDirName   = i;}
+  void SetOutputDirectory(const std::string &o) { OutputDirName  = o;}
+  void SetConvertModeToDicom()                  { dicom = 1; mhd = 0;}
+  void SetConvertModeToMhd()                    { dicom = 0; mhd = 1;}  
   bool Execute();
   
   /*