]> Creatis software - gdcm.git/blobdiff - src/gdcmDicomDir.cxx
ENH: Pass 2 at cleaning the JPEG mess. Still some work to do, but things are getting...
[gdcm.git] / src / gdcmDicomDir.cxx
index 568223b8adf19c62672d876485625e13b1f0eaf0..7eb67e4af159aed227c28cecbc381c59cf50bde5 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDir.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/24 16:10:52 $
-  Version:   $Revision: 1.116 $
+  Date:      $Date: 2005/01/29 11:43:05 $
+  Version:   $Revision: 1.122 $
   
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -146,12 +146,7 @@ DicomDir::~DicomDir()
    SetProgressMethod(NULL);
    SetEndMethod(NULL);
 
-   for(ListDicomDirPatient::iterator cc = Patients.begin();
-                                     cc!= Patients.end();
-                                   ++cc)
-   {
-      delete *cc;
-   }
+   ClearPatient();
    if ( MetaElems )
    {
       delete MetaElems;
@@ -336,11 +331,10 @@ DicomDirPatient *DicomDir::GetFirstPatient()
 DicomDirPatient *DicomDir::GetNextPatient()
 {
    gdcmAssertMacro (ItPatient != Patients.end());
-   {
-      ++ItPatient;
-      if ( ItPatient != Patients.end() )
-         return *ItPatient;
-   }
+
+   ++ItPatient;
+   if ( ItPatient != Patients.end() )
+      return *ItPatient;
    return NULL;
 }
 
@@ -467,31 +461,27 @@ void DicomDir::CreateDicomDirChainedList(std::string const & path)
 
 /**
  * \brief   adds *the* Meta to a partially created DICOMDIR
- */
-  
+ */  
 DicomDirMeta *DicomDir::NewMeta()
 {
    if( MetaElems )
       delete MetaElems;
 
- // friend class hunting : we miss GetLastEntry and GetPreviousEntry
- //                  to be able to remove any direct reference to TagHT
-
-   DocEntry *e = GetFirstEntry();
-   if (e)
-   //if ( TagHT.begin() != TagHT.end() ) // after Document Parsing
+   DocEntry *entry = GetFirstEntry();
+   if( entry )
    { 
       MetaElems = new DicomDirMeta(true);
 
-      TagDocEntryHT::iterator lastOneButSequence = TagHT.end();
-      lastOneButSequence --;
-      // ALL the 'out of Sequence' Tags belong to Meta Elems
-      // (we skip 0004|1220 [Directory record sequence] )
-      for ( TagDocEntryHT::iterator cc  = TagHT.begin(); 
-                                    cc != lastOneButSequence;
-                                   ++cc)
+      entry = GetFirstEntry();
+      while( entry )
       {
-         MetaElems->AddEntry( cc->second );
+         if( dynamic_cast<SeqEntry *>(entry) )
+            break;
+
+         RemoveEntryNoDestroy(entry);
+         MetaElems->AddEntry(entry);
+
+         entry = GetFirstEntry();
       }
    }
    else  // after root directory parsing
@@ -503,7 +493,8 @@ DicomDirMeta *DicomDir::NewMeta()
 }
 
 /**
- * \brief   adds a new Patient (with the basic elements) to a partially created DICOMDIR
+ * \brief   adds a new Patient (with the basic elements) to a partially created
+ *          DICOMDIR
  */
 DicomDirPatient *DicomDir::NewPatient()
 {
@@ -512,6 +503,20 @@ DicomDirPatient *DicomDir::NewPatient()
    return p;
 }
 
+/**
+ * \brief   Remove all Patients
+ */
+void DicomDir::ClearPatient()
+{
+   for(ListDicomDirPatient::iterator cc = Patients.begin();
+                                     cc!= Patients.end();
+                                   ++cc)
+   {
+      delete *cc;
+   }
+   Patients.clear();
+}
+
 /**
  * \brief   adds to the HTable 
  *          the Entries (Dicom Elements) corresponding to the given type
@@ -720,7 +725,7 @@ void DicomDir::Initialize()
  */
 void DicomDir::CreateDicomDir()
 {
-   // The list is parsed. 
+   // The SeqEntries of "Directory Record Sequence" are parsed. 
    //  When a DicomDir tag ("PATIENT", "STUDY", "SERIE", "IMAGE") is found :
    //  1 - we save the beginning iterator
    //  2 - we continue to parse
@@ -732,7 +737,7 @@ void DicomDir::CreateDicomDir()
    DocEntry *e = GetDocEntry(0x0004, 0x1220);
    if ( !e )
    {
-      gdcmVerboseMacro( "NO Directory record sequence (0x0004,0x1220)");
+      gdcmVerboseMacro( "No Directory Record Sequence (0004,1220) found");
       /// \todo FIXME: what to do when the parsed file IS NOT a DICOMDIR file ? 
       return;         
    }
@@ -740,8 +745,7 @@ void DicomDir::CreateDicomDir()
    SeqEntry *s = dynamic_cast<SeqEntry *>(e);
    if ( !s )
    {
-      gdcmVerboseMacro( "No SeqEntry present");
-      // useless : (0x0004,0x1220) IS a Sequence !
+      gdcmVerboseMacro( "Element (0004,1220) is not a Sequence ?!?");
       return;
    }
 
@@ -811,13 +815,12 @@ void DicomDir::CreateDicomDir()
          // neither an 'IMAGE' SQItem. Skip to next item.
          continue;
       }
-
       if( si )
          MoveSQItem(si,tmpSI);
+
       tmpSI=s->GetNextSQItem();
    }
-// friend hunting : this one will be difficult to remove !
-   TagHT.clear();
+   ClearEntry();
 }
 
 /**
@@ -863,14 +866,6 @@ bool DicomDir::AddSerieToEnd(DicomDirSerie *dd)
          study->AddSerie(dd);
          return true;
       }
-/*      if( (*itp)->GetDicomDirStudies().size() > 0 )
-      {
-         ListDicomDirStudy::const_iterator itst = 
-            (*itp)->GetDicomDirStudies().end();
-         itst--;
-         (*itst)->AddSerie(dd);
-         return true;
-      }*/
    }
    return false;
 }
@@ -896,20 +891,6 @@ bool DicomDir::AddImageToEnd(DicomDirImage *dd)
             return true;
          }
       }
-/*      if( (*itp)->GetDicomDirStudies().size() > 0 )
-      {
-         ListDicomDirStudy::const_iterator itst = 
-            (*itp)->GetDicomDirStudies().end();
-         itst--;
-
-         if( (*itst)->GetDicomDirSeries().size() > 0 )
-         {
-            ListDicomDirSerie::const_iterator its = (*itst)->GetDicomDirSeries().end();
-            its--;
-            (*its)->AddImage(dd);
-            return true;
-         }
-      }*/
    }
    return false;
 }
@@ -921,8 +902,8 @@ bool DicomDir::AddImageToEnd(DicomDirImage *dd)
  */
 void DicomDir::SetElements(std::string const & path, VectDocument const &list)
 {
-   TagHT.clear();
-   Patients.clear();
+   ClearEntry();
+   ClearPatient();
 
    std::string patPrevName         = "", patPrevID  = "";
    std::string studPrevInstanceUID = "", studPrevID = "";
@@ -985,7 +966,7 @@ void DicomDir::SetElements(std::string const & path, VectDocument const &list)
  * @param dst destination SQItem
  * @param src source SQItem
  */
-void DicomDir::MoveSQItem(SQItem *dst,SQItem *src)
+void DicomDir::MoveSQItem(DocEntrySet *dst,DocEntrySet *src)
 {
    DocEntry *entry;