]> Creatis software - gdcm.git/blobdiff - src/gdcmDicomDir.cxx
Fix typo
[gdcm.git] / src / gdcmDicomDir.cxx
index 1ef0feab48d1fa64c560a61a5194a753e16a280b..cc41e96dd951fbe7bb27058dcc6448bd4ef11642 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDir.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/08 15:03:59 $
-  Version:   $Revision: 1.97 $
+  Date:      $Date: 2005/01/19 08:57:14 $
+  Version:   $Revision: 1.106 $
   
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -57,7 +57,6 @@ namespace gdcm
 // Constructor / Destructor
 
 /**
- * \ingroup DicomDir
  * \brief   Constructor : creates an empty DicomDir
  */
 DicomDir::DicomDir()
@@ -82,16 +81,21 @@ DicomDir::DicomDir()
 DicomDir::DicomDir(std::string const &fileName, bool parseDir ):
    Document( fileName )
 {
-   // Whatever user passed (a root directory or a DICOMDIR)
-   // and whatever the value of parseDir was,
-   // Document is already executed
+   // At this step, Document constructor is already executed,
+   // whatever user passed (a root directory or a DICOMDIR)
+   // and whatever the value of parseDir was.
+   // (nothing is cheked in Document constructor, to avoid overhead)
+
    Initialize();  // sets all private fields to NULL
 
    // if user passed a root directory, sure we didn't get anything
    if ( TagHT.begin() == TagHT.end() ) // when user passed a Directory to parse
    {
-      gdcmVerboseMacro( "Entry HT empty");
+      if (!parseDir)
+         gdcmVerboseMacro( "Entry HT empty for file: "<<fileName);
 
+   // Only if user passed a root directory
+   // ------------------------------------
       if ( fileName == "." )
       {
          // user passed '.' as Name
@@ -111,17 +115,19 @@ DicomDir::DicomDir(std::string const &fileName, bool parseDir ):
       else
       {
          /// \todo if parseDir == false, it should be tagged as an error
-         // NON ! il suffit d'appeler ParseDirectory() 
-         // apres le constructeur
+         // NO ! user may just call ParseDirectory() *after* constructor
       }
    }
-   else // Only if user passed a DICOMDIR
+   // Only if user passed a DICOMDIR
+   // ------------------------------
+   else 
    {
       // Directory record sequence
       DocEntry *e = GetDocEntry(0x0004, 0x1220);
       if ( !e )
       {
-         gdcmVerboseMacro( "NO Directory record sequence (0x0004,0x1220)");
+         gdcmVerboseMacro( "NO 'Directory record sequence' (0x0004,0x1220)"
+                          << " in file " << fileName);
          /// \todo FIXME : what do we do when the parsed file IS NOT a
          ///       DICOMDIR file ?         
       }
@@ -156,7 +162,7 @@ DicomDir::~DicomDir()
 /**
  * \brief  Canonical Printer 
  */
-void DicomDir::Print(std::ostream &os)
+void DicomDir::Print(std::ostream &os, std::string const & )
 {
    if( MetaElems )
    {
@@ -184,16 +190,19 @@ void DicomDir::Print(std::ostream &os)
  */
 bool DicomDir::IsReadable()
 {
-   if( !Document::IsReadable() )
+   if( Filetype == Unknown)
    {
+      gdcmVerboseMacro( "Wrong filetype");
       return false;
    }
    if( !MetaElems )
    {
+      gdcmVerboseMacro( "Meta Elements missing in DicomDir");
       return false;
    }
    if( Patients.size() <= 0 )
    {
+      gdcmVerboseMacro( "NO Patient in DicomDir");
       return false;
    }
 
@@ -224,7 +233,6 @@ void DicomDir::Initialize()
 
 
 /**
- * \ingroup DicomDir
  * \brief  fills the whole structure, starting from a root Directory
  */
 void DicomDir::ParseDirectory()
@@ -234,7 +242,6 @@ void DicomDir::ParseDirectory()
 }
 
 /**
- * \ingroup DicomDir
  * \brief   Set the start method to call when the parsing of the
  *          directory starts.
  * @param   method Method to call
@@ -256,7 +263,6 @@ void DicomDir::SetStartMethod( DicomDir::Method *method, void *arg,
 }
 
 /**
- * \ingroup DicomDir
  * \brief   Set the method to delete the argument
  *          The argument is destroyed when the method is changed or when the
  *          class is destroyed
@@ -268,7 +274,6 @@ void DicomDir::SetStartMethodArgDelete( DicomDir::Method *method )
 }
 
 /**
- * \ingroup DicomDir
  * \brief   Set the progress method to call when the parsing of the
  *          directory progress
  * @param   method Method to call
@@ -290,7 +295,6 @@ void DicomDir::SetProgressMethod( DicomDir::Method *method, void *arg,
 }
 
 /**
- * \ingroup DicomDir
  * \brief   Set the method to delete the argument
  *          The argument is destroyed when the method is changed or when the 
  *          class is destroyed          
@@ -302,7 +306,6 @@ void DicomDir::SetProgressMethodArgDelete( DicomDir::Method *method )
 }
 
 /**
- * \ingroup DicomDir
  * \brief   Set the end method to call when the parsing of the directory ends
  * @param   method Method to call
  * @param   arg    Argument to pass to the method
@@ -323,7 +326,6 @@ void DicomDir::SetEndMethod( DicomDir::Method *method, void *arg,
 }
 
 /**
- * \ingroup DicomDir
  * \brief   Set the method to delete the argument
  *          The argument is destroyed when the method is changed or when
  *          the class is destroyed
@@ -335,7 +337,6 @@ void DicomDir::SetEndMethodArgDelete( DicomDir::Method *method )
 }
 
 /**
- * \ingroup DicomDir
  * \brief    writes on disc a DICOMDIR
  * \ warning does NOT add the missing elements in the header :
  *           it's up to the user doing it !
@@ -397,19 +398,20 @@ bool DicomDir::WriteDicomDir(std::string const &fileName)
 // Protected
 
 /**
- * \ingroup DicomDir
  * \brief create a Document-like chained list from a root Directory 
  * @param path entry point of the tree-like structure
  */
 void DicomDir::CreateDicomDirChainedList(std::string const & path)
 {
    CallStartMethod();
-   DirList fileList(path,1); // gets recursively the file list
+   DirList dirList(path,1); // gets recursively the file list
    unsigned int count = 0;
    VectDocument list;
    Header *header;
 
-   for( DirList::iterator it  = fileList.begin();
+   DirListType fileList = dirList.GetFilenames();
+
+   for( DirListType::iterator it  = fileList.begin();
                               it != fileList.end();
                               ++it )
    {
@@ -442,7 +444,7 @@ void DicomDir::CreateDicomDirChainedList(std::string const & path)
    // sorts Patient/Study/Serie/
    std::sort(list.begin(), list.end(), DicomDir::HeaderLessThan );
    
-   std::string tmp = fileList.GetDirName();      
+   std::string tmp = dirList.GetDirName();      
    //for each Header of the chained list, add/update the Patient/Study/Serie/Image info
    SetElements(tmp, list);
    CallEndMethod();
@@ -456,7 +458,6 @@ void DicomDir::CreateDicomDirChainedList(std::string const & path)
 }
 
 /**
- * \ingroup DicomDir
  * \brief   adds *the* Meta to a partially created DICOMDIR
  */
   
@@ -673,7 +674,6 @@ void DicomDir::CallStartMethod()
 
 //-----------------------------------------------------------------------------
 /**
- * \ingroup DicomDir
  * \brief   CallProgressMethod
  */
 void DicomDir::CallProgressMethod()
@@ -686,7 +686,6 @@ void DicomDir::CallProgressMethod()
 
 //-----------------------------------------------------------------------------
 /**
- * \ingroup DicomDir
  * \brief   CallEndMethod
  */
 void DicomDir::CallEndMethod()
@@ -701,7 +700,6 @@ void DicomDir::CallEndMethod()
 //-----------------------------------------------------------------------------
 // Private
 /**
- * \ingroup DicomDir
  * \brief create a 'DicomDir' from a DICOMDIR Header 
  */
 void DicomDir::CreateDicomDir()
@@ -731,7 +729,6 @@ void DicomDir::CreateDicomDir()
       return;
    }
 
-   DicomDirType type; // = DicomDir::GDCM_DICOMDIR_META;
    MetaElems = NewMeta();
 
    ListSQItem listItems = s->GetSQItems();
@@ -757,25 +754,21 @@ void DicomDir::CreateDicomDir()
       {
          si = new DicomDirPatient();
          AddDicomDirPatientToEnd( static_cast<DicomDirPatient *>(si) );
-         type = DicomDir::GDCM_DICOMDIR_PATIENT;
       }
       else if( v == "STUDY " )
       {
          si = new DicomDirStudy();
          AddDicomDirStudyToEnd( static_cast<DicomDirStudy *>(si) );
-         type = DicomDir::GDCM_DICOMDIR_STUDY;
       }
       else if( v == "SERIES" )
       {
          si = new DicomDirSerie();
          AddDicomDirSerieToEnd( static_cast<DicomDirSerie *>(si) );
-         type = DicomDir::GDCM_DICOMDIR_SERIE;
       }
       else if( v == "IMAGE " ) 
       {
          si = new DicomDirImage();
          AddDicomDirImageToEnd( static_cast<DicomDirImage *>(si) );
-         type = DicomDir::GDCM_DICOMDIR_IMAGE;
       }
       else
       {
@@ -789,7 +782,6 @@ void DicomDir::CreateDicomDir()
 }
 
 /**
- * \ingroup DicomDir
  * \brief Well ... there is only one occurence  
  */
 bool DicomDir::AddDicomDirMeta()
@@ -803,7 +795,6 @@ bool DicomDir::AddDicomDirMeta()
 }
 
 /**
- * \ingroup DicomDir
  * \brief  AddDicomDirPatientToEnd 
  * @param   dd SQ Item to enqueue to the DicomPatient chained List
  */
@@ -814,7 +805,6 @@ bool DicomDir::AddDicomDirPatientToEnd(DicomDirPatient *dd)
 }
 
 /**
- * \ingroup DicomDir
  * \brief  AddDicomDirStudyToEnd 
  * @param   dd SQ Item to enqueue to the DicomDirStudy chained List
  */
@@ -831,7 +821,6 @@ bool DicomDir::AddDicomDirStudyToEnd(DicomDirStudy *dd)
 }
 
 /**
- * \ingroup DicomDir
  * \brief  AddDicomDirSerieToEnd 
  * @param   dd SQ Item to enqueue to the DicomDirSerie chained List
  */
@@ -855,7 +844,6 @@ bool DicomDir::AddDicomDirSerieToEnd(DicomDirSerie *dd)
 }
 
 /**
- * \ingroup DicomDir
  * \brief   AddDicomDirImageToEnd
  * @param   dd SQ Item to enqueue to the DicomDirImage chained List
  */
@@ -885,7 +873,6 @@ bool DicomDir::AddDicomDirImageToEnd(DicomDirImage *dd)
 }
 
 /**
- * \ingroup DicomDir
  * \brief  for each Header of the chained list, add/update the Patient/Study/Serie/Image info 
  * @param   path path of the root directory
  * @param   list chained list of Headers
@@ -951,35 +938,62 @@ void DicomDir::SetElements(std::string const & path, VectDocument const &list)
 }
 
 /**
- * \ingroup DicomDir
- * \brief   Move the content of the src SQItem to the dst SQItem
+ * \brief   Move the content of the source SQItem to the destination SQItem
  *          Only DocEntry's are moved
- * 
+ * @param dst destination SQItem
+ * @param src source SQItem
  */
 void DicomDir::MoveSQItem(SQItem *dst,SQItem *src)
 {
    DocEntry *entry;
 
-   src->Initialize();
-   entry = src->GetNextEntry();
+   entry = src->GetFirstEntry();
    while(entry)
    {
       src->RemoveEntryNoDestroy(entry);
       dst->AddEntry(entry);
-
-      src->Initialize();
       entry = src->GetNextEntry();
    }
 }
 
 /**
- * \ingroup DicomDir
  * \brief   compares two dgcmHeaders
  */
 bool DicomDir::HeaderLessThan(Document *header1, Document *header2)
 {
    return *header1 < *header2;
 }
+
+
+/**
+ * \brief   Get the first entry while visiting the DicomDirPatients
+ * \return  The first DicomDirPatient if found, otherwhise NULL
+ */ 
+DicomDirPatient *DicomDir::GetFirstEntry()
+{
+   ItDicomDirPatient = Patients.begin();
+   if ( ItDicomDirPatient != Patients.end() )
+      return *ItDicomDirPatient;
+   return NULL;
+}
+
+/**
+ * \brief   Get the next entry while visiting the DicomDirPatients
+ * \note : meaningfull only if GetFirstEntry already called
+ * \return  The next DicomDirPatient if found, otherwhise NULL
+ */
+DicomDirPatient *DicomDir::GetNextEntry()
+{
+   gdcmAssertMacro (ItDicomDirPatient != Patients.end());
+   {
+      ++ItDicomDirPatient;
+      if ( ItDicomDirPatient != Patients.end() )
+         return *ItDicomDirPatient;
+   }
+   return NULL;
+}
+
+
 } // end namespace gdcm
 
 //-----------------------------------------------------------------------------