]> Creatis software - gdcm.git/commitdiff
* FIX : bug fix in the gdcmDirList for the recursivity in directories
authorregrain <regrain>
Tue, 10 Feb 2004 10:47:54 +0000 (10:47 +0000)
committerregrain <regrain>
Tue, 10 Feb 2004 10:47:54 +0000 (10:47 +0000)
     * FIX : in gdcmDicomDir when the directory is empty
     -- BeNours

ChangeLog
gdcmPython/gdcm.i
src/gdcmDicomDir.cxx
src/gdcmDicomDir.h
src/gdcmDirList.cxx

index 8637425f22966fe6a646363c8c19e72bd4948da1..6d73c866ea2b0929c2f3a80e372467f0c7e6bb4f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,13 @@
+2004-02-10 Benoit Regrain
+     * FIX : bug fix in the gdcmDirList for the recursivity in directories
+     * FIX : in gdcmDicomDir when the directory is empty
+
 2004-02-06 Jean-Pierre Roux
      * ENH : - now gdcmDicomDir::CreateDicomDir() returns also the meta elements
              - GDCM_META added to gdcmDicomDirType
             - class gdcmMeta created
-     * ENH : - A brief summary is now displayed at the beginning of 'testDicomDir'
-            to help disaster magnitude estimation
+     * ENH : - A brief summary is now displayed at the beginning of
+           'testDicomDir' to help disaster magnitude estimation
      * REM  : Now useless Test/explDICOMDIR.cxx
 
 2004-02-05 Benoit Regrain
index 36f117ab34abc4ccc2b6f2bf0d897af32ef10fdc..129a6f4253c81eac478c5c2fe1e346d92bfc7fe3 100644 (file)
@@ -13,6 +13,7 @@
 #include "gdcmObject.h"
 #include "gdcmDicomDir.h"
 #include "gdcmDicomDirElement.h"
+#include "gdcmMeta.h"
 #include "gdcmPatient.h"
 #include "gdcmStudy.h"
 #include "gdcmSerie.h"
@@ -204,6 +205,7 @@ extern gdcmGlobal gdcmGlob;
 %include "gdcmObject.h"
 %include "gdcmDicomDir.h"
 %include "gdcmDicomDirElement.h"
+%include "gdcmMeta.h"
 %include "gdcmPatient.h"
 %include "gdcmStudy.h"
 %include "gdcmSerie.h"
index edda84f75da3e456d54322b4a16d68daa8d48526..23f33438381c7bcaba3c3defa3d39e2095ff7e62 100644 (file)
@@ -27,6 +27,8 @@ gdcmDicomDir::gdcmDicomDir(const char *FileName, bool parseDir,
                            bool exception_on_error):
    gdcmParser(FileName,exception_on_error,true)
 {
+   metaElems=NULL;
+
    if( GetListEntry().begin()==GetListEntry().end() ) 
    {
       dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : entry list empty");
@@ -41,26 +43,14 @@ gdcmDicomDir::gdcmDicomDir(const char *FileName, bool parseDir,
       CreateDicomDir();
 }
 
-/*
- * \ingroup gdcmDicomDir
- * \brief   
- * @param   exception_on_error
- */
-/*gdcmDicomDir::gdcmDicomDir(ListTag *l,
-                           bool exception_on_error):                           
-   gdcmParser(exception_on_error )  
-{    
-   listEntries=*l;
-   CreateDicomDir();
-}*/
-
 /*
  * \ingroup gdcmDicomDir
  * \brief  Canonical destructor 
  */
 gdcmDicomDir::~gdcmDicomDir() 
 {
-   delete metaelems;
+   if(metaElems)
+      delete metaElems;
    
    for(ListPatient::iterator cc=patients.begin();cc!=patients.end();++cc)
    {
@@ -76,8 +66,11 @@ gdcmDicomDir::~gdcmDicomDir()
  */
 void gdcmDicomDir::Print(std::ostream &os)
 {
-   (*metaelems).SetPrintLevel(printLevel);
-   (*metaelems).Print(os);   
+   if(metaElems)
+   {
+      metaElems->SetPrintLevel(printLevel);
+      metaElems->Print(os);   
+   }
    
    for(ListPatient::iterator cc=patients.begin();cc!=patients.end();++cc)
    {
@@ -149,6 +142,7 @@ void gdcmDicomDir::NewDicomDir(std::string path)
    for(gdcmDirList::iterator it=fileList.begin(); 
        it!=fileList.end(); ++it) 
    {
+          std::cout<<*it<<std::endl;
       header=new gdcmHeader(it->c_str());
       if(header->IsReadable())
          list.push_back(header);
@@ -196,24 +190,13 @@ void gdcmDicomDir::CreateDicomDir()
    //       + we create the object for the precedent tag
    //       + loop to 1 -
 
-   gdcmDicomDirType type=gdcmDicomDir::GDCM_NONE;
+   gdcmDicomDirType type=gdcmDicomDir::GDCM_META;
    ListTag::iterator begin;
    ListTag::iterator end;
-   ListTag::iterator k;
 
    begin=listEntries.begin();
    end=begin;
-   
-   for(ListTag::iterator j=begin;j !=listEntries.end();++j) 
-   {
-      if((*j)->GetValue()=="PATIENT ") {
-         k = j; 
-         break;
-      }
-   }   
-   AddObjectToEnd(gdcmDicomDir::GDCM_META,begin,k);       
-    
-   for(ListTag::iterator i=k;i !=listEntries.end();++i) 
+   for(ListTag::iterator i=end;i !=listEntries.end();++i) 
    {
       std::string v=(*i)->GetValue();
       if(v=="PATIENT ") 
@@ -253,8 +236,11 @@ void gdcmDicomDir::CreateDicomDir()
       }
    }
 
-   end=GetListEntry().end();
-   AddObjectToEnd(type,begin,end);
+   if(begin!=end)
+   {
+      end=GetListEntry().end();
+      AddObjectToEnd(type,begin,end);
+   }
 }
 /*
  * \ingroup gdcmDicomDir
@@ -288,7 +274,6 @@ void gdcmDicomDir::AddObjectToEnd(gdcmDicomDirType type,ListTag::iterator begin,
    }
 }
 
-
 /*
  * \ingroup gdcmDicomDir
  * \brief Well ... Not realy to end, there is only one occurence  
@@ -297,7 +282,9 @@ void gdcmDicomDir::AddObjectToEnd(gdcmDicomDirType type,ListTag::iterator begin,
 */
 void gdcmDicomDir::AddMetaToEnd(ListTag::iterator begin,ListTag::iterator end)
 {
-   metaelems = new gdcmMeta(begin,end);
+   if(metaElems)
+      delete metaElems;
+   metaElems = new gdcmMeta(begin,end);
 }
 
 /*
index e06fcd1a429a796bef2775fc495fe19e354fa800..e54995e3445a1d927dfbfd382e7d40bd13853e2e 100644 (file)
@@ -35,7 +35,7 @@ public:
    void SetPrintLevel(int level) { printLevel = level; };
    virtual void Print(std::ostream &os = std::cout);
 
-   inline gdcmMeta   *GetMeta()      {return metaelems;};
+   inline gdcmMeta   *GetMeta()      {return metaElems;};
    inline ListPatient &GetPatients() {return patients;};
 
 // Write
@@ -72,7 +72,7 @@ private:
 
    static bool HeaderLessThan(gdcmHeader *header1,gdcmHeader *header2);
 
-   gdcmMeta *metaelems;
+   gdcmMeta *metaElems;
    ListPatient patients;
 };
 
index f8a2d637963b1ea71e1edda1534ac91a9283a1f8..42b3120a05198abac945de184934a7cb1c7290f3 100644 (file)
@@ -101,10 +101,11 @@ void gdcmDirList::Explore(std::string dirName,bool recursive)
    while( (hFile!=INVALID_HANDLE_VALUE) && (found) )
    {
       fileName=fileData.cFileName;
+      std::cout<<fileName<<std::endl;
       if(fileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
       {
          if( (fileName!=".") && (fileName!="..") && (recursive) )
-            Explore(dirName+fileName);
+            Explore(dirName+fileName,recursive);
       }
       else
       {
@@ -124,7 +125,7 @@ void gdcmDirList::Explore(std::string dirName,bool recursive)
       if(namelist[i]->d_type==DT_DIR)
       {
          if( (fileName!=".") && (fileName!="..") && (recursive) )
-            Explore(dirName+fileName);
+            Explore(dirName+fileName,recursive);
       }
       else
       {