]> Creatis software - gdcm.git/blobdiff - Example/exConvert3DplusT.cxx
Typo
[gdcm.git] / Example / exConvert3DplusT.cxx
index a629f743fe80a581155dc9ccfd0a253b05467d87..43db2d2040aa8b05b28fb4bfd428de995414c102 100755 (executable)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: exConvert3DplusT.cxx,v $
   Language:  C++
-  Date:      $Date: 2006/07/26 17:46:02 $
-  Version:   $Revision: 1.2 $
+  Date:      $Date: 2006/09/01 13:42:02 $
+  Version:   $Revision: 1.4 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -176,6 +176,11 @@ int main(int argc, char *argv[])
 
    gdcm::DirList dirList(dirIn,false); // gets (at single level) the file list
    gdcm::DirListType fileList = dirList.GetFilenames();
+   
+   // hope sorting on the filename is enough!
+   // anyway, *no* filed is available to perform anything more clever.
+      
+   std::sort(fileList.begin(), fileList.end() );
 
    // 'Study Instance UID'
    // The user is allowed to create his own Study, 
@@ -188,7 +193,6 @@ int main(int argc, char *argv[])
    else
       strStudyUID = studyUID;
 
-
    // 'Serie Instance UID'
    // The user is allowed to create his own Series, 
    // keeping the same 'Serie Instance UID' for various images
@@ -206,13 +210,12 @@ int main(int argc, char *argv[])
    size_t totalNumberOfPixels =  imageDimX*imageDimY * imagetteLineNumber*imagetteRowNumber;     
    int16_t *imageTable = new int16_t[totalNumberOfPixels]; 
    
-   //std::cout << " imageTable length " << totalNumberOfPixels;
    memset(imageTable, 0, totalNumberOfPixels * imagePixelSize);
              
-   int16_t **tabImageData = new int16_t *[nbOfImagesInVolume];
+   int16_t **tabImageData = new int16_t *[nbOfImagesInVolume];   
+   gdcm::File **f         = new gdcm::File *[nbOfImagesInVolume];
+   gdcm::FileHelper **fh  = new gdcm::FileHelper *[nbOfImagesInVolume];
    
-   gdcm::File *f;
-   gdcm::FileHelper *fh;
    std::string fullFilename, lastFilename;
    float zPositionComponent = 0.0;
       
@@ -223,26 +226,28 @@ int main(int argc, char *argv[])
                                  ++it )
    {
       fullFilename = *it;
-      f = gdcm::File::New( );
-      f->SetLoadMode(loadMode);
-      f->SetFileName( it->c_str() );
+      f[imageNumber] = gdcm::File::New( );
+      f[imageNumber]->SetLoadMode(loadMode);
+      f[imageNumber]->SetFileName( it->c_str() );
 
       if (verbose)
-         std::cout << "file [" << it->c_str() << "]" << std::endl;
-      if ( !f->Load() )
+         std::cout << "file [" << it->c_str() << "], as imageNumber : " << imageNumber << std::endl;
+      if ( !f[imageNumber]->Load() )
       {
          if (verbose)
             std::cout << "fail to load [" << it->c_str() << "]" << std::endl;      
-         f->Delete();
+         f[imageNumber]->Delete();
          continue;
       }
 
       // Load the pixels in RAM.    
       
-      fh = gdcm::FileHelper::New(f); 
+      fh[imageNumber] = gdcm::FileHelper::New(f[imageNumber]); 
       // Don't convert (Gray Pixels + LUT) into (RGB pixels) ?!?
    
-      tabImageData[imageNumber] = (int16_t *)fh->GetImageDataRaw();
+      tabImageData[imageNumber] = (int16_t *)fh[imageNumber]->GetImageDataRaw();
+      
       if (!tabImageData[imageNumber]) 
       {
          std::cout << "fail to read [" << it->c_str() << std::endl;
@@ -251,7 +256,7 @@ int main(int argc, char *argv[])
       int16_t mini=32000;
       int16_t maxi=-32000;
        
-      if (imageNumber == nbOfImagesInVolume)
+      if (imageNumber == nbOfImagesInVolume-1)
       {        
          for(imageNumber=0; imageNumber < nbOfImagesInVolume; imageNumber++)
          {
@@ -273,7 +278,6 @@ int main(int argc, char *argv[])
   
                   imageTable[debLigne + j] = *(tabImageData[imageNumber] + i*imageDimY + j);
                   if (imageTable[debLigne + j] < 0) imageTable[debLigne + j]=0;
-                     if (imageTable[debLigne + j] > 100) imageTable[debLigne + j]=100;
                      //std::cout << debLigne + j << " : " << imageTable[debLigne + j] << std::endl;
   
                      if (*(tabImageData[imageNumber] + i*imageDimY + j) < mini)
@@ -314,17 +318,17 @@ int main(int argc, char *argv[])
          // Set the image size
          str.str("");
          str << imageDimX*imagetteRowNumber;
-         fh->InsertEntryString(str.str(),0x0028,0x0011, "US"); // Columns
+         fh[imageNumber]->InsertEntryString(str.str(),0x0028,0x0011, "US"); // Columns
 
          str.str("");
          str << imageDimY*imagetteLineNumber;
-         fh->InsertEntryString(str.str(),0x0028,0x0010, "US"); // Rows 
+         fh[imageNumber]->InsertEntryString(str.str(),0x0028,0x0010, "US"); // Rows 
 
-         fh->InsertEntryString(strStudyUID,0x0020,0x000d,"UI");      
-         fh->InsertEntryString(strSerieUID,0x0020,0x000e,"UI");
-         fh->InsertEntryString(patName,0x0010,0x0010, "PN");   // Patient's Name
+         fh[imageNumber]->InsertEntryString(strStudyUID,0x0020,0x000d,"UI");      
+         fh[imageNumber]->InsertEntryString(strSerieUID,0x0020,0x000e,"UI");
+         fh[imageNumber]->InsertEntryString(patName,0x0010,0x0010, "PN");   // Patient's Name
 
-         fh->SetImageData((uint8_t *)imageTable, totalNumberOfPixels * imagePixelSize);
+         fh[imageNumber]->SetImageData((uint8_t *)imageTable, totalNumberOfPixels * imagePixelSize);
 
 // ==================================================================================================
 
@@ -340,31 +344,30 @@ int main(int argc, char *argv[])
 // Aware use is free to supply his own one !    
 
 /*    
-         if (! f->CheckIfEntryExist(0x0020,0x0037) ) // 0020 0037 DS 6 Image Orientation (Patient)
+         if (! f[imageNumber]->CheckIfEntryExist(0x0020,0x0037) ) // 0020 0037 DS 6 Image Orientation (Patient)
          {
-            fh->InsertEntryString("1.0\\0.0\\0.0\\0.0\\1.0\\0.0",0x0020,0x0037, "DS"); //[1\0\0\0\1\0] : Axial
+            fh[imageNumber]->InsertEntryString("1.0\\0.0\\0.0\\0.0\\1.0\\0.0",0x0020,0x0037, "DS"); //[1\0\0\0\1\0] : Axial
 
             char charImagePosition[256];
      
             sprintf(charImagePosition,"%f\\0.0\\0.0",zPositionComponent);
             zPositionComponent += zSpacing;
       
-            if (! f->CheckIfEntryExist(0x0020,0x0032) ) //0020 0032 DS 3 Image Position (Patient)
-               fh->InsertEntryString(charImagePosition,0x0020,0x0032, "DS"); 
+            if (! f[imageNumber]->CheckIfEntryExist(0x0020,0x0032) ) //0020 0032 DS 3 Image Position (Patient)
+               fh[imageNumber]->InsertEntryString(charImagePosition,0x0020,0x0032, "DS"); 
     
-            if (! f->CheckIfEntryExist(0x0020,0x1041) ) // 0020 0x1041 DS 1 Slice Location
+            if (! f[imageNumber]->CheckIfEntryExist(0x0020,0x1041) ) // 0020 0x1041 DS 1 Slice Location
             {
                sprintf(charImagePosition,"%f",zPositionComponent);
-               fh->InsertEntryString(charImagePosition,0x0020,0x1041, "DS");
+               fh[imageNumber]->InsertEntryString(charImagePosition,0x0020,0x1041, "DS");
             }    
          } 
-
 */
 
 // ==================================================================================================
 
-         fh->SetWriteTypeToDcmExplVR();               
-         fh->SetContentType(gdcm::UNMODIFIED_PIXELS_IMAGE);
+         fh[imageNumber]->SetWriteTypeToDcmExplVR();               
+         fh[imageNumber]->SetContentType(gdcm::UNMODIFIED_PIXELS_IMAGE);
 
       
          lastFilename =  gdcm::Util::GetName( fullFilename );
@@ -372,18 +375,25 @@ int main(int argc, char *argv[])
                                        + lastFilename;
          if (verbose)
             std::cout << "Write : [" << fullWriteFilename << "]" << std::endl;
-         if (!fh->Write(fullWriteFilename))
+    
+         if (!fh[imageNumber]->Write(fullWriteFilename))
          {
             std::cout << "Fail to write :[" << fullWriteFilename << "]"
                       << std::endl;
          }
-         //break;   
+         for(int k=0; k < nbOfImagesInVolume; k++)
+         {
+            fh[k]->Delete();
+            f[k]->Delete();
+         }
+
       }  // end : 'write the imagette'
-      else
+      
+      else // start a new 'volume'
       {
          imageNumber++;
       }
-      fh->Delete();
-      f->Delete();
+
    }
 }