]> Creatis software - gdcm.git/blobdiff - src/gdcmDicomDir.cxx
2004-02-06 Jean-Pierre Roux
[gdcm.git] / src / gdcmDicomDir.cxx
index 92cdc6f8702234cf7474e1132bf527ec82ede3d0..3592304d18afef30f1d13df0f2723c2d0d9a685a 100644 (file)
@@ -17,7 +17,7 @@
 // Constructor / Destructor
 /*
  * \ingroup gdcmDicomDir
- * \brief   
+ * \brief   Constructor
  * @param   Filename
  * @param   exception_on_error
  */
@@ -58,6 +58,8 @@ gdcmDicomDir::gdcmDicomDir(const char *FileName, bool parseDir,
  */
 gdcmDicomDir::~gdcmDicomDir() 
 {
+   delete metaelems;
+   
    for(ListPatient::iterator cc=patients.begin();cc!=patients.end();++cc)
    {
       delete *cc;
@@ -66,8 +68,15 @@ gdcmDicomDir::~gdcmDicomDir()
 
 //-----------------------------------------------------------------------------
 // Print
+/*
+ * \ingroup gdcmDicomDir
+ * \brief  Canonical Printer 
+ */
 void gdcmDicomDir::Print(std::ostream &os)
 {
+   (*metaelems).SetPrintLevel(printLevel);
+   (*metaelems).Print(os);   
+   
    for(ListPatient::iterator cc=patients.begin();cc!=patients.end();++cc)
    {
      (*cc)->SetPrintLevel(printLevel);
@@ -81,9 +90,9 @@ void gdcmDicomDir::Print(std::ostream &os)
  * \ingroup gdcmDicomDir
  * \brief   writes on disc a DICOMDIR
  * \ warning does NOT add the missing elements in the header :
- * \         it's up to the user doing it !
+ *           it's up to the user doing it !
  * @param  fileName file to be written to 
- * @return
+ * @return false only when fail to open
  */
 bool gdcmDicomDir::Write(std::string fileName) 
 {
@@ -109,6 +118,10 @@ bool gdcmDicomDir::Write(std::string fileName)
    return true;
 }
 
+/*
+ * \ingroup gdcmDicomDir
+ * \brief  fills whole the structure
+ */
 void gdcmDicomDir::ParseDirectory(void)
 {
    NewDicomDir(GetPath());
@@ -119,8 +132,8 @@ void gdcmDicomDir::ParseDirectory(void)
 // Protected
 /*
  * \ingroup gdcmDicomDir
- * \brief   
- * @param   
+ * \brief create a gdcmDicomDir from a root Directory 
+ * @param path entry point of the stree-like structure
  */
 void gdcmDicomDir::NewDicomDir(std::string path)
 {
@@ -143,12 +156,13 @@ void gdcmDicomDir::NewDicomDir(std::string path)
 
    std::sort(list.begin(),list.end(),gdcmDicomDir::HeaderLessThan);
 
-   SetElements(path,list);
+   std::string tmp=fileList.GetDirName();
+   SetElements(tmp,list);
 }
 
 /*
  * \ingroup gdcmDicomDir
- * \brief   Get the dicom dir path
+ * \brief   Get the DicomDir path
  * @param   
  */
 std::string gdcmDicomDir::GetPath(void)
@@ -169,8 +183,7 @@ std::string gdcmDicomDir::GetPath(void)
 // Private
 /*
  * \ingroup gdcmDicomDir
- * \brief   
- * @param   
+ * \brief create a 'gdcmDicomDir' from a DICOMDIR gdcmHeader 
  */
 void gdcmDicomDir::CreateDicomDir()
 {
@@ -184,10 +197,21 @@ void gdcmDicomDir::CreateDicomDir()
    gdcmDicomDirType type=gdcmDicomDir::GDCM_NONE;
    ListTag::iterator begin;
    ListTag::iterator end;
+   ListTag::iterator k;
 
    begin=listEntries.begin();
    end=begin;
-   for(ListTag::iterator i=listEntries.begin();i !=listEntries.end();++i) 
+   
+   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) 
    {
       std::string v=(*i)->GetValue();
       if(v=="PATIENT ") 
@@ -233,7 +257,9 @@ void gdcmDicomDir::CreateDicomDir()
 /*
  * \ingroup gdcmDicomDir
  * \brief   
- * @param   
+ * @param   type
+ * @param   begin
+ * @param   end
  */
 void gdcmDicomDir::AddObjectToEnd(gdcmDicomDirType type,ListTag::iterator begin,ListTag::iterator end)
 {
@@ -242,6 +268,9 @@ void gdcmDicomDir::AddObjectToEnd(gdcmDicomDirType type,ListTag::iterator begin,
 
    switch(type)
    {
+      case gdcmDicomDir::GDCM_META:
+         AddMetaToEnd(begin,end);
+         break;      
       case gdcmDicomDir::GDCM_PATIENT:
          AddPatientToEnd(begin,end);
          break;
@@ -257,11 +286,24 @@ void gdcmDicomDir::AddObjectToEnd(gdcmDicomDirType type,ListTag::iterator begin,
    }
 }
 
+
+/*
+ * \ingroup gdcmDicomDir
+ * \brief Well ... Not realy to end, there is only one occurence  
+ * @param   begin
+ * @param   end
+*/
+void gdcmDicomDir::AddMetaToEnd(ListTag::iterator begin,ListTag::iterator end)
+{
+   metaelems = new gdcmMeta(begin,end);
+}
+
 /*
  * \ingroup gdcmDicomDir
  * \brief   
- * @param   
- */
+ * @param   begin
+ * @param   end
+*/
 void gdcmDicomDir::AddPatientToEnd(ListTag::iterator begin,ListTag::iterator end)
 {
    patients.push_back(new gdcmPatient(begin,end));
@@ -270,7 +312,8 @@ void gdcmDicomDir::AddPatientToEnd(ListTag::iterator begin,ListTag::iterator end
 /*
  * \ingroup gdcmDicomDir
  * \brief   
- * @param   
+ * @param   begin
+ * @param   end
  */
  void gdcmDicomDir::AddStudyToEnd(ListTag::iterator begin,ListTag::iterator end)
 {
@@ -284,7 +327,8 @@ void gdcmDicomDir::AddPatientToEnd(ListTag::iterator begin,ListTag::iterator end
 /*
  * \ingroup gdcmDicomDir
  * \brief   
- * @param   
+ * @param   begin
+ * @param   end
  */
 void gdcmDicomDir::AddSerieToEnd(ListTag::iterator begin,ListTag::iterator end)
 {
@@ -304,7 +348,8 @@ void gdcmDicomDir::AddSerieToEnd(ListTag::iterator begin,ListTag::iterator end)
 
 /*
  * \ingroup gdcmDicomDir
- * \brief   
+ * @param   begin
+ * @param   end
  * @param   
  */
  void gdcmDicomDir::AddImageToEnd(ListTag::iterator begin,ListTag::iterator end)
@@ -332,7 +377,8 @@ void gdcmDicomDir::AddSerieToEnd(ListTag::iterator begin,ListTag::iterator end)
 /*
  * \ingroup gdcmDicomDir
  * \brief   
- * @param   
+ * @param   path
+ * @param   list
  */
 void gdcmDicomDir::SetElements(std::string &path,ListHeader &list)
 {
@@ -366,9 +412,7 @@ void gdcmDicomDir::SetElements(std::string &path,ListHeader &list)
 
       // if new Serie Deal with 'SERIE' Elements   
       if(serCurInstanceUID!=serPrevInstanceUID || serCurID!=serPrevID) 
-      {
          SetElement(path,GDCM_SERIE,*it);
-      } 
       
       // Always Deal with 'IMAGE' Elements  
       SetElement(path,GDCM_IMAGE,*it);
@@ -385,7 +429,9 @@ void gdcmDicomDir::SetElements(std::string &path,ListHeader &list)
 /*
  * \ingroup gdcmDicomDir
  * \brief   
- * @param   
+ * @param   path
+ * @param   type
+ * @param   header
  */
 void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,gdcmHeader *header)
 {