]> Creatis software - gdcm.git/commitdiff
Code normalization
authorjpr <jpr>
Mon, 1 Oct 2007 09:33:20 +0000 (09:33 +0000)
committerjpr <jpr>
Mon, 1 Oct 2007 09:33:20 +0000 (09:33 +0000)
Example/PrintFile.cxx
Example/exMoveImagesToSingleSerieUID.cxx
Example/exSerieHelper.cxx
Example/exXCoherentFileSet.cxx

index 1da00db2ac3fd11e0d6fc881b9945ea28d06fc0f..fa7050c03b87f76b0a1f3cf2dec8be51c7a5e52a 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: PrintFile.cxx,v $
   Language:  C++
-  Date:      $Date: 2007/09/26 08:07:42 $
-  Version:   $Revision: 1.86 $
+  Date:      $Date: 2007/10/01 09:33:20 $
+  Version:   $Revision: 1.87 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -30,7 +30,7 @@
 #include "gdcmOrientation.h"
 #include <iostream>
 
-// TODO : code factorization, for 'single file' an 'whole directory' processing
+/// \todo : code factorization, for 'single file' an 'whole directory' processing
 
 void ShowLutData(GDCM_NAME_SPACE::File *f);
 
@@ -193,7 +193,7 @@ int main(int argc, char *argv[])
    int forceLoadNb;
    uint16_t *elemsToForceLoad 
                            = am->ArgMgrGetXInt16Enum("forceload", &forceLoadNb);
-   
+
    int nbP =0;
    uint16_t *FourthDimLoc;
    if ( am->ArgMgrDefined("4DLoc") )
@@ -230,14 +230,14 @@ int main(int argc, char *argv[])
 
    // ----------- End Arguments Manager ---------
 
+
    if (ddict)
    {
-      GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->AddDict(dict);   
+      GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->AddDict(dict);
    }
 
    if ( fileName != 0 ) // ====== Deal with a single file ======
-   { 
+   {
       GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
       f->SetLoadMode(loadMode);
       f->SetFileName( fileName );
@@ -245,10 +245,10 @@ int main(int argc, char *argv[])
       for (int ri=0; ri<forceLoadNb; ri++)
       {
          f->AddForceLoadElement((uint32_t)elemsToForceLoad[2*ri], 
-                                (uint32_t)elemsToForceLoad[2*ri+1] ); 
+                                (uint32_t)elemsToForceLoad[2*ri+1] );
       }
 // TODO : find why such a polution
-// To avoid polluting the output with messages 
+// To avoid polluting the output with messages
 // 'Last system error was : No such file or directory'
 
 errno = 0; 
@@ -256,21 +256,21 @@ errno = 0;
 
       bool res = f->Load();
       // GDCM_NAME_SPACE::File::IsReadable() is no usable here, because we deal with
-      // any kind of gdcm-Parsable *document* 
+      // any kind of gdcm-Parsable *document*
       // not only GDCM_NAME_SPACE::File (as opposed to GDCM_NAME_SPACE::DicomDir)
       if ( !res )
       {
          std::cout << "Cannot process file [" << fileName << "]" << std::endl;
-         std::cout << "Either it doesn't exist, or it's read protected " 
+         std::cout << "Either it doesn't exist, or it's read protected "
                    << std::endl;
-         std::cout << "or it's not a Dicom File, or its 'header' is bugged" 
+         std::cout << "or it's not a Dicom File, or its 'header' is bugged"
                    << std::endl;
          std::cout << "use 'PrintFile filein=... debug' to try to guess the pb"
                    << std::endl;
          f->Delete();
          return 0;
       }
-      
+
       if (nbP == 1)
          f->SetFourthDimensionLocation(FourthDimLoc[0],FourthDimLoc[1]);
 
@@ -280,7 +280,7 @@ errno = 0;
 
       fh->Print();
 
-      std::cout << "\n\n" << std::endl; 
+      std::cout << "\n\n" << std::endl;
 
       std::cout <<std::endl;
       std::cout <<" dataSize    " << fh->GetImageDataSize()    << std::endl;
@@ -530,8 +530,9 @@ if (!noex)
       f->Delete();
       fh->Delete();
    }
-   else  // ====== Deal with a Directory ======
-   {
+         // ===========================================================================
+   else  // =============================== Deal with a Directory =====================
+   {     // ===========================================================================
       std::cout << "dirName [" << dirName << "]" << std::endl;
       
       GDCM_NAME_SPACE::DirList dirList(dirName,rec); // gets recursively (or not) the file list
@@ -539,6 +540,11 @@ if (!noex)
       GDCM_NAME_SPACE::File *f;
       bool res;
 
+      if (fileList.size() == 0)
+      {
+         std::cout << "No file found in : [" << dirName << "]" << std::endl;
+      }
+      
       for( GDCM_NAME_SPACE::DirListType::iterator it  = fileList.begin();
                                  it != fileList.end();
                                  ++it )
index 8e35c7970f3ab87684271df027fad9fa161b3810..18cbc35321d469822dc7625b85873296766958ca 100755 (executable)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: exMoveImagesToSingleSerieUID.cxx,v $
   Language:  C++
-  Date:      $Date: 2007/05/23 14:18:05 $
-  Version:   $Revision: 1.5 $
+  Date:      $Date: 2007/10/01 09:33:20 $
+  Version:   $Revision: 1.6 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -114,20 +114,22 @@ int main(int argc, char *argv[])
    }
 
    if (am->ArgMgrDefined("debug"))
-      GDCM_NAME_SPACE::Debug::DebugOn(); 
-   int verbose  = am->ArgMgrDefined("verbose");
+      GDCM_NAME_SPACE::Debug::DebugOn();
+
+   bool verbose = ( 0 != am->ArgMgrDefined("verbose") );
    
    std::string patName = am->ArgMgrGetString("patname", "g^PatientName");
    float zSpacing = am->ArgMgrGetFloat("zSpacing", 1.0);
       
-   const char *dirIn  = am->ArgMgrGetString("dirin");
+   const char *dirIn   = am->ArgMgrGetString("dirin");
    const char *dirOut  = am->ArgMgrGetString("dirout");
-   
-   int userDefinedStudy = am->ArgMgrDefined("studyUID");
+
+   bool userDefinedStudy = ( 0 != am->ArgMgrDefined("userDefinedStudy") );
    const char *studyUID  = am->ArgMgrGetString("studyUID");
 
 // not described *on purpose* in the Usage ! 
-   int userDefinedSerie = am->ArgMgrDefined("serieUID");   
+   bool userDefinedSerie = ( 0 != am->ArgMgrDefined("userDefinedSerie") );
+  
    const char *serieUID  = am->ArgMgrGetString("serieUID");      
  
    int loadMode = GDCM_NAME_SPACE::LD_ALL;
@@ -208,19 +210,18 @@ 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
    // The user shouldn't add any image to a 'Manufacturer Serie'
    // but there is no way no to prevent him for doing that
-   
+
    std::string strSerieUID; 
    if ( !userDefinedSerie)   
       strSerieUID =  GDCM_NAME_SPACE::Util::CreateUniqueUID();
    else      
       strSerieUID = serieUID;
-        
+
    GDCM_NAME_SPACE::File *f;
    GDCM_NAME_SPACE::FileHelper *fh;
    std::string fullFilename, lastFilename;
@@ -240,14 +241,15 @@ int main(int argc, char *argv[])
       if ( !f->Load() )
       {
          if (verbose)
-            std::cout << "fail to load [" << it->c_str() << "]" << std::endl;      
+            std::cout << "fail to load [" << it->c_str() << "]" << std::endl;   
          f->Delete();
          continue;
       }
 
-      // Load the pixels in RAM.    
-      
-      fh = GDCM_NAME_SPACE::FileHelper::New(f);     
+      // Load the pixels in RAM.
+   
+      fh = GDCM_NAME_SPACE::FileHelper::New(f);
+      fh->SetKeepOverlays( true );
       uint8_t *imageData = fh->GetImageDataRaw(); // Don't convert (Gray Pixels + LUT) into (RGB pixels) ?!?
       if (!imageData)
          std::cout << "fail to read [" << it->c_str() << std::endl;
index 9922486ef7580a21109f1ad12d170c1db1aa95bb..c92a7b6f941cb7569d62408f142a389c8aad0c0c 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: exSerieHelper.cxx,v $
   Language:  C++
-  Date:      $Date: 2007/06/22 11:01:57 $
-  Version:   $Revision: 1.13 $
+  Date:      $Date: 2007/10/01 09:33:20 $
+  Version:   $Revision: 1.14 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -39,7 +39,7 @@ int main(int argc, char *argv[])
   
    std::cout << "Dir Name :[" << dirName << "]" << std::endl;
    //   
-   // Something, using only SerieHelper is not enought !
+   // Sometimes using only SerieHelper is not enought !
    // See also exXcoherentFileSet
    //
 
index 4e60070acbcaec76a84733b149c1b6ae45230aee..b8f2ea09d90fc935b0e85642c0c13d1f7639a3b2 100755 (executable)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: exXCoherentFileSet.cxx,v $
   Language:  C++
-  Date:      $Date: 2007/09/28 14:08:08 $
-  Version:   $Revision: 1.11 $
+  Date:      $Date: 2007/10/01 09:33:20 $
+  Version:   $Revision: 1.12 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
 
 #include "gdcmArgMgr.h"
 
-void removeSpecChar(std::string &s);
-
-void removeSpecChar(std::string &s) {
-      unsigned int s_size = s.size();
-      for(unsigned int i=0; i<s_size; i++)
-      {
-          if (
-         /*while(i<s_size
-               && */!( s[i] == '.' || s[i] == '%' || s[i] == '_'
-                 || (s[i] >= '+' && s[i] <= '-')       
-                 || (s[i] >= 'a' && s[i] <= 'z')
-                 || (s[i] >= '0' && s[i] <= '9')
-                 || (s[i] >= 'A' && s[i] <= 'Z')))
-         {
-            s.replace(i, 1, "_");  // ImagePositionPatient related stuff will be more human readable
-         }
-      }
-
-      // deal with Dicom strings trailing '\0' 
-      if(s[s_size-1] == '_')
-         s.erase(s_size-1, 1);
-
-}
      
 int main(int argc, char *argv[])
 {  
@@ -238,8 +215,9 @@ int main(int argc, char *argv[])
    std::string xCoherentName = "";     
    std::string serieDirectory;
    std::string lastFilename;
-   
-   int controlCount = 0;    
+   std::string rep("_");   
+   int controlCount = 0;
+  
    while (l) // for each 'Single SerieUID FileSet'
    { 
       nbFiles = l->size() ;
@@ -247,7 +225,7 @@ int main(int argc, char *argv[])
                            // Why not ? Just an example, for testing!
       {
           serieUID = s->GetCurrentSerieUIDFileSetUID();
-          removeSpecChar(serieUID);
+          GDCM_NAME_SPACE::Util::ReplaceSpecChar(serieUID, rep);
  
           // --- for write
           if (write)
@@ -279,8 +257,9 @@ int main(int argc, char *argv[])
             xcm = s->SplitOnOrientation(l);
          else if (pos)
             xcm = s->SplitOnPosition(l);
-         else if (groupelem != 0)
+         else if (groupelem != 0) {
             xcm = s->SplitOnTagValue(l, groupelem[0],groupelem[1] );
+         }
 
          for (GDCM_NAME_SPACE::XCoherentFileSetmap::iterator i = xcm.begin(); 
                                                   i != xcm.end();
@@ -289,7 +268,7 @@ int main(int argc, char *argv[])
              xCoherentName = (*i).first;
             if (verbose)
                std::cout << "xCoherentName = " << xCoherentName << std::endl;
-             removeSpecChar(xCoherentName);
+            GDCM_NAME_SPACE::Util::ReplaceSpecChar(serieUID, rep);
              // --- for write
              if (write)
              { 
@@ -299,7 +278,7 @@ int main(int argc, char *argv[])
                    systemCommand   = "mkdir " + xCoherentWriteDir;
                    system( systemCommand.c_str());
                    if (verbose)
-                      std::cout << "2 " << systemCommand << std::endl;       
+                      std::cout << systemCommand << std::endl;       
                 }
             } 
             // --- end for write