]> Creatis software - creaBruker.git/commitdiff
Rectangular pixels
authorjean-pierre roux <jean-pierre.roux@creatis.insa-lyon.fr>
Mon, 12 Oct 2009 14:45:54 +0000 (14:45 +0000)
committerjean-pierre roux <jean-pierre.roux@creatis.insa-lyon.fr>
Mon, 12 Oct 2009 14:45:54 +0000 (14:45 +0000)
lib/src1/bruker2dicom.cxx

index c2366e64bad6db9ed035aa2bcef69cf88e38da0b..bdf1e4d73aa2b32dbe31c3bfd62061df758d9059 100644 (file)
@@ -555,6 +555,13 @@ void Bruker2Dicom::DealWithNiveau3(std::string level3Directory, std::string curr
    double fovY = fov.GetDoubleValue()[1];
    if (verbose)
       std::cout << "FOV (ds method) " << fovX << " " << fovY << std::endl;
+      
+   BrukerFieldData spatResol = br_method.GetFieldData("PVM_SpatResol");
+   double spatResolX = spatResol.GetDoubleValue()[0];
+   double spatResolY = spatResol.GetDoubleValue()[1];
+   if (verbose)
+      std::cout << "SpatResol (ds method) " << spatResolX << " " << spatResolY << std::endl;
+
 
    /// \TODO probabely a more sophisticated accessor will be necessary :
    ///  (cf : non contiguous slices, overlapping, slice thickness, space between slices, etc)
@@ -646,7 +653,8 @@ void Bruker2Dicom::DealWithNiveau3(std::string level3Directory, std::string curr
                fprintf(fp, "BinaryDataByteOrderMSB = False\n" );
                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",fovX/NY, fovY/NY, sliceDistance );
+              fprintf(fp, "ElementSpacing = %lf %lf %lf\n", spatResolX, spatResolX, sliceDistance );
                fprintf(fp, "Position = 0 0 %d\n", 0 );
                fprintf(fp, "Offset = 0 0 0\n" );
                fprintf(fp, "CenterOfRotation = 0 0 0\n" );
@@ -682,7 +690,8 @@ void Bruker2Dicom::DealWithNiveau3(std::string level3Directory, std::string curr
                NY,
                nbFrames,
                pixelSize,
-               fovX/NY, fovY/NY, sliceDistance,
+               //fovX/NY, fovY/NY, sliceDistance,
+              spatResolX, spatResolX, sliceDistance,
                output2dseqSliceFileName,
                strPatientName,
                day,
@@ -731,8 +740,9 @@ void Bruker2Dicom::DealWithNiveau3(std::string level3Directory, std::string curr
                    fprintf(fp, "BinaryDataByteOrderMSB = False\n" );    
                    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 ); // slice distance : no meaning for temporal serie
-                   fprintf(fp, "Position = 0 0 %d\n", sliceNb );  
+                   //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, "Position = 0 0 %d\n", sliceNb );  
                    fprintf(fp, "Offset = 0 0 0\n" );  
                    fprintf(fp, "CenterOfRotation = 0 0 0\n" );
                    fprintf(fp, "ElementNumberOfChannels = 1\n" );  
@@ -815,7 +825,8 @@ void Bruker2Dicom::DealWithNiveau3(std::string level3Directory, std::string curr
                   NY,
                   nbInstants,
                   pixelSize,
-                  fovX/NY, fovY/NY, sliceDistance,
+                 spatResolX, spatResolY, sliceDistance,
+                  //fovX/NY, fovY/NY, sliceDistance,
                   output2dseqSliceFileName,
                   strPatientName,
                   day,
@@ -844,7 +855,7 @@ void Bruker2Dicom::DealWithNiveau3(std::string level3Directory, std::string curr
    //  deal with MatLab-generated Carto file.
    // -----------------------------------------------------
    
-   dealWithCarto(fileNames,  NX,  NY,  nbSlices, fovX, fovY, sliceDistance,
+   dealWithCarto(fileNames,  NX,  NY,  nbSlices, /*fovX, fovY,*/ spatResolX, spatResolY, sliceDistance,
                    copyFile, currentOutputDirName, outputMhdFileName, output2dseqCartoName);
 }
 
@@ -852,7 +863,8 @@ 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,
+                                 /*double fovX, double fovY, */
+                                double spatResolX, double spatResolY, double sliceDistance,
                                  char *copyFile, std::string &currentOutputDirName, 
                                  char *outputMhdFileName, char *output2dseqCartoName)
 {
@@ -879,10 +891,10 @@ void Bruker2Dicom::dealWithCarto(GDCM_NAME_SPACE::DirListType &fileNames, int NX
          if (verbose)
             std::cout << "--- [" << *it << "] is a file..." << std::endl;
 
-         icode = 0;
-         iseparator = 0;
+         icode      = 0;
          while (code[icode][0] != 0)
-         {         
+         { 
+        iseparator = 0;       
         while (separator[iseparator][0] != 0)
          {
             sprintf(file_name_ident, "2dseq%s%s",separator[iseparator],code[icode]); // e.g  "2dseq_ADC"
@@ -902,9 +914,10 @@ void Bruker2Dicom::dealWithCarto(GDCM_NAME_SPACE::DirListType &fileNames, int NX
                }
                fread(buffer_carto, NX*NY*sizeof(double), nbSlices, fp);
 
+                    // ?!?  sprintf(copyFile, "cp %s %s%c%s", (*it).c_str() ,
                std::cout << "Deal with Carto file :[" <<*it << "], computed length : "
                          << NX*NY*sizeof(double)*nbSlices << std::endl;
-                  std::string lastFileName = GDCM_NAME_SPACE::Util::GetName((*it).c_str());
+               std::string lastFileName = GDCM_NAME_SPACE::Util::GetName((*it).c_str());
                if (mhd)
                {
                   // Copy the data file in the new directory
@@ -912,7 +925,7 @@ void Bruker2Dicom::dealWithCarto(GDCM_NAME_SPACE::DirListType &fileNames, int NX
                             currentOutputDirName.c_str(),GDCM_NAME_SPACE::GDCM_FILESEPARATOR, lastFileName.c_str()); 
                   system(copyFile);
                   sprintf(outputMhdFileName, "%s%c%s%s",
-                                       currentOutputDirName.c_str(),GDCM_NAME_SPACE::GDCM_FILESEPARATOR, lastFileName.c_str(), ".mhd" );
+                                         currentOutputDirName.c_str(),GDCM_NAME_SPACE::GDCM_FILESEPARATOR, lastFileName.c_str(), ".mhd" );
                   if (verbose)
                     std::cout << "--- Output Carto MHD file [" << outputMhdFileName << "]" << std::endl;
  
@@ -929,9 +942,8 @@ void Bruker2Dicom::dealWithCarto(GDCM_NAME_SPACE::DirListType &fileNames, int NX
                      fprintf(fp, "BinaryData = True \n" );
                      fprintf(fp, "BinaryDataByteOrderMSB = False\n" );
                      fprintf(fp, "DimSize = %d %d %d\n", NX, NY, nbSlices);
-                     fprintf(fp, "ElementSpacing = %lf %lf %lf\n",fovX/NY, fovY/NY, sliceDistance );
                      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, spatResolY, sliceDistance );
                      fprintf(fp, "Position = 0 0 0\n" );
                      fprintf(fp, "Offset = 0 0 0\n" );
                      fprintf(fp, "CenterOfRotation = 0 0 0\n" );
@@ -961,7 +973,8 @@ void Bruker2Dicom::dealWithCarto(GDCM_NAME_SPACE::DirListType &fileNames, int NX
                      NY,
                      nbSlices,
                      8, // pixelSize
-                     fovX/NY, fovY/NY, sliceDistance,
+                     //fovX/NY, fovY/NY, sliceDistance,
+                     spatResolX, spatResolY, sliceDistance,
                      output2dseqCartoName,
                      strPatientName,
                      day,
@@ -979,14 +992,15 @@ void Bruker2Dicom::dealWithCarto(GDCM_NAME_SPACE::DirListType &fileNames, int NX
                if (verbose) 
                   std::cout << "--- End writing Carto DICOM file [" << output2dseqCartoName << "]" << std::endl;
                break; // don't check for more ident on same file name!
-           }
-           iseparator ++;
-           }
-            icode++;
-         } 
-      }
-   } // end iterate on files
-}
+           
+            }  // end deal with _ADC, -adc, etc
+          iseparator ++;
+          }  // end iterate speparators
+          icode++;
+          } // end iterate code
+      } // end boost::filesystem::is_regular(*it)
+   } // end iterate on all objects (files, dir, etc)
+} // end method
 
 
 // ==========================================================================================================
@@ -1021,7 +1035,7 @@ bool Bruker2Dicom::CreateDirectory(std::string OutputDirName)
    else
    {
        if (verbose)
-          std::cout << "Output Directory [" << OutputDirName << "] already exists; Used as is." << std::endl;
+            std::cout << "Output Directory [" << OutputDirName << "] already exists; Used as is." << std::endl;
    }
    
    return 1;
@@ -1361,8 +1375,8 @@ std::cout << "charImageOrientation  " <<
       fileH->Delete();                 
       throw ( BrukerHopelessException ("Level 1 Unable to write Dicom file "));
    }
-   if (verbose)
-      file->Print();
+   //if (verbose)
+   //   file->Print();
 
    file->Delete();
    fileH->Delete();