]> Creatis software - gdcm.git/commitdiff
- now, DicomDir stuff stakes into account the 'new' structure
authorjpr <jpr>
Thu, 26 Aug 2004 15:29:52 +0000 (15:29 +0000)
committerjpr <jpr>
Thu, 26 Aug 2004 15:29:52 +0000 (15:29 +0000)
- gdcmObject is no longer composed of 2 pointers in a chained list, but is an SQItem
- useless gdcmDicomDir::WriteEntries method is removed
- useless gdcmDicomDir::AddObjectToEnd method is removed
- WARNING : BuidUpDicomDir not yet debugged, but I prefer to commit right now.
-> See you tomorow

20 files changed:
src/gdcmDicomDir.cxx
src/gdcmDicomDir.h
src/gdcmDicomDirImage.h
src/gdcmDicomDirMeta.cxx
src/gdcmDicomDirMeta.h
src/gdcmDicomDirPatient.cxx
src/gdcmDicomDirPatient.h
src/gdcmDicomDirSerie.cxx
src/gdcmDicomDirSerie.h
src/gdcmDicomDirStudy.cxx
src/gdcmDicomDirStudy.h
src/gdcmDocEntrySet.cxx
src/gdcmDocEntrySet.h
src/gdcmDocument.cxx
src/gdcmDocument.h
src/gdcmFile.cxx
src/gdcmObject.h
src/gdcmSQItem.cxx
src/gdcmSeqEntry.cxx
src/gdcmSeqEntry.h

index 3959a469bd712cfb07f1f7faa73e5f814cd56ec3..fb5f55595e9b6c02e46af3dd2708d528e5a973ba 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDir.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/08/02 16:42:14 $
-  Version:   $Revision: 1.63 $
+  Date:      $Date: 2004/08/26 15:29:52 $
+  Version:   $Revision: 1.64 $
   
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -52,7 +52,7 @@
 gdcmDicomDir::gdcmDicomDir()
    :gdcmDocument( )
 { 
-   Initialize();
+   Initialize();  // sets all private fields to NULL
 
    std::string pathBidon = "Bidon"; // Sorry, NULL not allowed ...
    SetElement(pathBidon, GDCM_DICOMDIR_META, NULL); // Set the META elements
@@ -77,12 +77,12 @@ gdcmDicomDir::gdcmDicomDir(std::string const & fileName, bool parseDir ):
    // que l'on ai passe un root directory ou un DICOMDIR
    // et quelle que soit la valeur de parseDir,
    // on a deja lance gdcmDocument 
-   Initialize();
+   Initialize();  // sets all private fields to NULL
 
    // gdcmDocument already executed
    // if user passed a root directory, sure we didn't get anything
 
-   if ( TagHT.begin() == TagHT.end() ) 
+   if ( TagHT.begin() == TagHT.end() ) // when user passed a Directory to parse
    {
       dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : entry HT empty");
 
@@ -92,13 +92,14 @@ gdcmDicomDir::gdcmDicomDir(std::string const & fileName, bool parseDir ):
          // we get current directory name
          char* dummy = new char[1000];
          getcwd(dummy, (size_t)1000);
-         std::cout << "Directory to parse : [" << dummy << "]" << std::endl;
          SetFileName( dummy ); // will be converted into a string
          delete[] dummy;       // no longer needed   
       }
 
-      if ( parseDir )
+      if ( parseDir ) // user asked for a recursive parsing of a root directory
       {
+         metaElems = NewMeta();
+
          dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : Parse directory"
                         " and create the DicomDir");
          ParseDirectory();
@@ -110,7 +111,7 @@ gdcmDicomDir::gdcmDicomDir(std::string const & fileName, bool parseDir ):
          // apres le constructeur
       }
    }
-   else
+   else // Only if user passed a DICOMDIR
    {
       // Directory record sequence
       gdcmDocEntry *e = GetDocEntryByNumber(0x0004, 0x1220);
@@ -133,18 +134,16 @@ gdcmDicomDir::~gdcmDicomDir()
    SetStartMethod(NULL);
    SetProgressMethod(NULL);
    SetEndMethod(NULL);
-
-   if ( metaElems )
-   {
-      delete metaElems;
-   }
-   
    for(ListDicomDirPatient::iterator cc = patients.begin();
                                      cc!= patients.end();
                                    ++cc)
    {
       delete *cc;
    }
+   if ( metaElems )
+   {
+      delete metaElems;
+   }
 }
 
 //-----------------------------------------------------------------------------
@@ -341,81 +340,43 @@ void gdcmDicomDir::SetEndMethodArgDelete(gdcmMethod *method)
  */
  
 bool gdcmDicomDir::Write(std::string const & fileName) 
-{
-   FILE * fp1 = fopen(fileName.c_str(), "wb");
-   if( !fp1 ) 
+{  
+   uint16_t sq[5] = { 0x0004, 0x1220, 0x0000, 0xffff, 0xffff };
+   uint16_t sqt[3]= { 0xfffe, 0xe0dd, 0x0000 };
+
+   FILE * fp = fopen(fileName.c_str(), "wb");
+   if( !fp ) 
    {
       printf("Failed to open(write) File [%s] \n", fileName.c_str());
       return false;
    }
 
-   char * filePreamble = new char[128];
-   fwrite(filePreamble,128,1,fp1);
-   fwrite("DICM",4,1,fp1);
+   uint8_t* filePreamble = new  uint8_t[128];
+   memset(filePreamble, 0, 128);
+   fwrite(filePreamble,128,1,fp);
+   fwrite("DICM",4,1,fp);
    delete[] filePreamble;
-   UpdateDirectoryRecordSequenceLength();
-   WriteEntries(fp1);
-
-   fclose( fp1 );
+ //  UpdateDirectoryRecordSequenceLength(); // TODO (if *really* usefull)
+   gdcmDicomDirMeta *ptrMeta = GetDicomDirMeta();
+   ptrMeta->Write(fp, gdcmExplicitVR);
+   
+   // force writing 0004|1220 [SQ ], that CANNOT exist within gdcmDicomDirMeta
+   fwrite(&sq[0],4,1,fp);  // 0004 1220 
+   fwrite("SQ"  ,2,1,fp);  // SQ
+   fwrite(&sq[2],6,1,fp);  // 00 ffffffff
+      
+   for(ListDicomDirPatient::iterator cc = patients.begin();cc!=patients.end();++cc)
+   {
+      (*cc)->Write( fp, gdcmExplicitVR );
+   }
+   // force writing Sequence Delimitation Item
+   fwrite(&sqt[0],4,1,fp);  // fffe e0dd 
+   fwrite("UL"   ,2,1,fp);  // UL
+   fwrite(&sqt[2],1,1,fp);  // 00 
+   fclose( fp );
    return true;
 }
 
-/**
- * \brief   Writes in a file using the tree-like structure.
- * @param   _fp already open file pointer
- */
-
-void gdcmDicomDir::WriteEntries(FILE *) //_fp
-{   
-   /// \todo (?) tester les echecs en ecriture 
-   ///          (apres chaque fwrite, dans le WriteEntry)
-
-
-/* TODO : to go on compiling
-
-   gdcmDicomDirMeta *ptrMeta;
-   ListDicomDirPatient::iterator  itPatient;
-   ListDicomDirStudy::iterator    itStudy;
-   ListDicomDirSerie::iterator    itSerie;
-   ListDicomDirImage::iterator    itImage; 
-   ListTag::iterator i; 
-   
-   ptrMeta= GetDicomDirMeta();
-   for(i=ptrMeta->debut();i!=ptrMeta->fin();++i) {
-      WriteEntry(*i,_fp, gdcmExplicitVR);
-   }   
-    
-   itPatient = GetDicomDirPatients().begin(); 
-   while ( itPatient != GetDicomDirPatients().end() ) {
-      for(i=(*itPatient)->debut();i!=(*itPatient)->fin();++i) {
-         WriteEntry(*i,_fp, gdcmExplicitVR);
-      }
-      itStudy = ((*itPatient)->GetDicomDirStudies()).begin();     
-      while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) {
-         for(i=(*itStudy)->debut();i!=(*itStudy)->fin();++i) {
-            WriteEntry(*i,_fp, gdcmExplicitVR);
-         } 
-         itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
-         while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) {
-            for(i=(*itSerie)->debut();i!=(*itSerie)->fin();++i) {
-               WriteEntry(*i,_fp, gdcmExplicitVR);
-            }
-            itImage = ((*itSerie)->GetDicomDirImages()).begin();
-            while (itImage != (*itSerie)->GetDicomDirImages().end() ) {
-               for(i=(*itImage)->debut();i!=(*itImage)->fin();++i) {
-                  WriteEntry(*i,_fp, gdcmExplicitVR);
-               }
-               ++itImage;
-            }
-            ++itSerie;
-         }
-         ++itStudy;
-      } 
-      ++itPatient;     
-   }
-   */
-}   
-   
 //-----------------------------------------------------------------------------
 // Protected
 
@@ -475,8 +436,7 @@ void gdcmDicomDir::CreateDicomDirChainedList(std::string const & path)
    std::string tmp = fileList.GetDirName();
       
    //for each Header of the chained list, add/update the Patient/Study/Serie/Image info
-   SetElements(tmp, list);
-      
+   SetElements(tmp, list);      
    CallEndMethod();
 }
 
@@ -484,18 +444,35 @@ void gdcmDicomDir::CreateDicomDirChainedList(std::string const & path)
  * \ingroup gdcmDicomDir
  * \brief   adds *the* Meta to a partially created DICOMDIR
  */
- /// \todo FIXME : Heuuuuu ! Il prend les Entries du Document deja parse,
- ///                  il ne fabrique rien !
   
 gdcmDicomDirMeta * gdcmDicomDir::NewMeta()
 {
    gdcmDicomDirMeta *m = new gdcmDicomDirMeta( &TagHT );
-   for ( TagDocEntryHT::iterator cc  = TagHT.begin(); 
-                                 cc != TagHT.end(); ++cc)
-   {
-      m->AddDocEntry( cc->second );
+  
+   if ( TagHT.begin() != TagHT.end() ) // after Document Parsing
+   { 
+      TagDocEntryHT::iterator lastOneButSequence = TagHT.end();
+      lastOneButSequence --;
+      // This works because 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)
+      {
+         m->AddDocEntry( cc->second );
+      }
    }
+   else  // after root directory parsing
+   {
+     //cout << "gdcmDicomDir::NewMeta avec FillObject" << endl;
+     std::list<gdcmElement> elemList;
+     elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirMetaElements();
+     m->FillObject(elemList);
+     // we create the Sequence manually
+     //gdcmSeqEntry *se =NewSeqEntryByNumber(0x0004, 0x1220); // NOT YET!
+     //m->AddEntry(se);
+    }
+   m->SetSQItemNumber(0); // To avoid further missprinting
    return m;  
 }
 
@@ -579,7 +556,7 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,
    gdcmDictEntry *dictEntry;
    gdcmValEntry *entry;
    std::string val;
-   //gdcmObject *o;
+   gdcmSQItem *si = new gdcmSQItem(0); // all the items will be at level 1
    switch( type )
    {
       case GDCM_DICOMDIR_IMAGE:
@@ -600,30 +577,38 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,
   
       case GDCM_DICOMDIR_META:
          elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirMetaElements();
+         // add already done ?
          break;
 
       default:
          return;
    }
+   // removed all the seems-to-be-useless stuff about Referenced Image Sequence
+   // to avoid further troubles
+   // imageElem 0008 1140 "" // Referenced Image Sequence
+   // imageElem fffe e000 "" // 'no length' item : length to be set to 0xffffffff later
+   // imageElem 0008 1150 "" // Referenced SOP Class UID    : to be set/forged later
+   // imageElem 0008 1155 "" // Referenced SOP Instance UID : to be set/forged later
+   // imageElem fffe e00d "" // Item delimitation : length to be set to ZERO later
+   // for all the relevant elements found in their own spot of the DicomDir.dic
+   // FIXME : troubles found when it's a SeqEntry
 
    for( it = elemList.begin(); it != elemList.end(); ++it)
    {
       tmpGr     = it->group;
       tmpEl     = it->elem;
       dictEntry = GetPubDict()->GetDictEntryByNumber(tmpGr, tmpEl);
+
       entry     = new gdcmValEntry( dictEntry ); // Be sure it's never a BinEntry !
 
       entry->SetOffset(0); // just to avoid further missprinting
+      entry->SetLength(0); // just to avoid further missprinting
 
       if( header ) // NULL when we Build Up (ex nihilo) a DICOMDIR
                    //   or when we add the META elems
-      {
          val = header->GetEntryByNumber(tmpGr, tmpEl);
-      }
       else
-      {
          val = GDCM_UNFOUND;
-      }
 
       if( val == GDCM_UNFOUND) 
       {
@@ -641,24 +626,20 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,
                val = header->GetFileName();
             }
             else
-            {
                val = &(header->GetFileName().c_str()[path.length()]);
-            }   
          }
          else
-         {
             val = it->value;
-         }
       }
       else
       {
          if ( header->GetEntryLengthByNumber(tmpGr,tmpEl) == 0 )
-         {
             val = it->value;
-         }
       }
 
-      entry->SetValue( val );
+     // GDCM_UNFOUND or not !
+
+      entry->SetValue( val ); // troubles expected when vr=SQ ...
 
       if( dictEntry )
       {
@@ -683,13 +664,35 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,
             entry->SetLength( entry->GetValue().length() );
          }
       }
-      std::cout << " was TagHT[entry->GetKey()] = entry " << std::endl;
-      if ( type == GDCM_DICOMDIR_META ) {
+
+      if ( type == GDCM_DICOMDIR_META ) // fusible : should never print !
          std::cout << " special Treatment for GDCM_DICOMDIR_META" << std::endl;
-         
-      }
-      //TagHT[entry->GetKey()] = entry;          // FIXME : use a SEQUENCE !
+      si->AddEntry(entry);
    }
+   switch( type )
+   {
+      case GDCM_DICOMDIR_IMAGE:
+         AddDicomDirImageToEnd(si);
+         break;
+
+      case GDCM_DICOMDIR_SERIE:
+         AddDicomDirSerieToEnd(si);
+         break;
+
+      case GDCM_DICOMDIR_STUDY:
+         AddDicomDirStudyToEnd(si);
+         break;
+
+      case GDCM_DICOMDIR_PATIENT:
+         AddDicomDirPatientToEnd(si);
+         break;
+
+      default:
+         return;
+   }
+   //int count=1;            // find a trick to increment
+   //s->AddEntry(si, count); // Seg Faults 
+
 }
 
 /**
@@ -788,25 +791,21 @@ void gdcmDicomDir::CreateDicomDir()
       if( v == "PATIENT " )
       {
          AddDicomDirPatientToEnd( *i );
-         //AddObjectToEnd(type,*i);
          type = gdcmDicomDir::GDCM_DICOMDIR_PATIENT;
       }
       else if( v == "STUDY " )
       {
          AddDicomDirStudyToEnd( *i );
-        // AddObjectToEnd(type,*i);
          type = gdcmDicomDir::GDCM_DICOMDIR_STUDY;
       }
       else if( v == "SERIES" )
       {
          AddDicomDirSerieToEnd( *i );
-         //  AddObjectToEnd(type,*i);
          type = gdcmDicomDir::GDCM_DICOMDIR_SERIE;
       }
       else if( v == "IMAGE " ) 
       {
          AddDicomDirImageToEnd( *i );
-         //   AddObjectToEnd(type,*i);
          type = gdcmDicomDir::GDCM_DICOMDIR_IMAGE;
       }
       else
@@ -818,46 +817,6 @@ void gdcmDicomDir::CreateDicomDir()
    }
 }
 
-/**
- * \ingroup gdcmDicomDir
- * \brief   AddObjectToEnd
- * @param   type
- * @param   begin iterator on the first DocEntry within the chained List
- * @param   end iterator on the last DocEntry within the chained List
- */
-// now  useless ?
-
-/*void gdcmDicomDir::AddObjectToEnd(gdcmDicomDirType type,gdcmSQItem *s)
-{
-   if(s==NULL) // ??
-      return;
-
-   switch(type)
-   {
-      case gdcmDicomDir::GDCM_DICOMDIR_META:
-         AddDicomDirMeta();
-         break;      
-      case gdcmDicomDir::GDCM_DICOMDIR_PATIENT:
-         AddDicomDirPatientToEnd(s);
-         break;
-      case gdcmDicomDir::GDCM_DICOMDIR_STUDY:
-         AddDicomDirStudyToEnd(s);
-         break;
-      case gdcmDicomDir::GDCM_DICOMDIR_SERIE:
-         AddDicomDirSerieToEnd(s);
-         break;
-      case gdcmDicomDir::GDCM_DICOMDIR_IMAGE:
-         AddDicomDirImageToEnd(s);
-         break;
-      case gdcmDicomDir::GDCM_DICOMDIR_NONE:
-         AddDicomDirImageToEnd(s);        //FIXME
-         break;
-   }
-}
-
-*/
-
 /**
  * \ingroup gdcmDicomDir
  * \brief Well ... there is only one occurence  
@@ -960,7 +919,7 @@ void gdcmDicomDir::SetElements(std::string &path, VectDocument &list)
    std::string studCurInstanceUID, studCurID;
    std::string serCurInstanceUID,  serCurID;
 
-   SetElement( path, GDCM_DICOMDIR_META,NULL);
+   //SetElement( path, GDCM_DICOMDIR_META,NULL); // already done (NewMeta) 
 
    for( VectDocument::iterator it = list.begin();
                               it != list.end(); ++it )
index 1c1af26a8a40d195b8c6c85160f62fc96fe91184..4f80a6236ec69f271a1e2af20308ea5b6e84e252 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDir.h,v $
   Language:  C++
-  Date:      $Date: 2004/08/02 16:42:14 $
-  Version:   $Revision: 1.26 $
+  Date:      $Date: 2004/08/26 15:29:52 $
+  Version:   $Revision: 1.27 $
   
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -84,8 +84,7 @@ public:
    gdcmDicomDirMeta*    NewMeta();
    gdcmDicomDirPatient* NewPatient();
 
-// Write
-   void WriteEntries(FILE *_fp);   
+// Write  
    bool Write(std::string const & fileName);
 
    /// Types of the gdcmObject within the gdcmDicomDir
index 8365f40069f413a5160e5faf952fea5adef980b3..dac05c642ee85fcb4b876ee8b5dde8a8e9ec1ec2 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirImage.h,v $
   Language:  C++
-  Date:      $Date: 2004/08/01 02:39:09 $
-  Version:   $Revision: 1.6 $
+  Date:      $Date: 2004/08/26 15:29:52 $
+  Version:   $Revision: 1.7 $
                                                                                 
   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 @@ public:
 
    ~gdcmDicomDirImage();
 
-   virtual void Print(std::ostream &os = std::cout);      
+   virtual void Print(std::ostream &os = std::cout);
 };
 
 //-----------------------------------------------------------------------------
index 59d411283d0f20ded7ec5d560f78edc2f780c0ae..15bfa8d048644136dccc9aaeb993a0e3e452c7b7 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirMeta.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/08/01 02:39:09 $
-  Version:   $Revision: 1.5 $
+  Date:      $Date: 2004/08/26 15:29:52 $
+  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
@@ -44,9 +44,7 @@ gdcmDicomDirMeta::~gdcmDicomDirMeta()
 //-----------------------------------------------------------------------------
 // Print
 /**
- * \ingroup gdcmDicomDirMeta
  * \brief   Prints the Object
- * @return
  */ 
 void gdcmDicomDirMeta::Print(std::ostream &os)
 {
@@ -54,9 +52,20 @@ void gdcmDicomDirMeta::Print(std::ostream &os)
    gdcmObject::Print(os);
 }
 
+
 //-----------------------------------------------------------------------------
 // Public
 
+
+/**
+ * \brief   Writes the Object
+ * @return
+ */ 
+void gdcmDicomDirMeta::Write(FILE *fp, FileType t)
+{
+   gdcmObject::Write(fp, t);
+}
+
 //-----------------------------------------------------------------------------
 // Protected
 
index fe3de1232c941292ff5c5057f329c62bca3c010b..7f8bd5799b6e9d15dc0cb2509bb31c870f5f157c 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirMeta.h,v $
   Language:  C++
-  Date:      $Date: 2004/08/01 02:39:09 $
-  Version:   $Revision: 1.5 $
+  Date:      $Date: 2004/08/26 15:29:52 $
+  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
@@ -30,6 +30,7 @@ public:
    ~gdcmDicomDirMeta();
 
    virtual void Print(std::ostream &os = std::cout);
+   virtual void Write(FILE * fp, FileType t);
 };
 
 //-----------------------------------------------------------------------------
index 3cc33bc7e98ddddfc8203582c7258948952e878c..625adecb4a40c80cd5865951f492da12852d7cd3 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirPatient.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/08/01 02:39:09 $
-  Version:   $Revision: 1.10 $
+  Date:      $Date: 2004/08/26 15:29:52 $
+  Version:   $Revision: 1.11 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -23,7 +23,6 @@
 //-----------------------------------------------------------------------------
 // Constructor / Destructor
 /**
- * \ingroup gdcmDicomDirPatient
  * \brief   Constructor
  * @param  s SQ Item holding the elements related to this "PATIENT" part
  * @param ptagHT pointer to the HTable (gdcmObject needs it 
@@ -35,7 +34,6 @@ gdcmDicomDirPatient::gdcmDicomDirPatient(gdcmSQItem *s, TagDocEntryHT *ptagHT):
    docEntries = s->GetDocEntries();
 }
 /**
- * \ingroup gdcmDicomDirPatient
  * \brief   Constructor
  * @param ptagHT pointer to the HTable (gdcmObject needs it 
  *               to build the gdcmHeaderEntries)
@@ -45,7 +43,6 @@ gdcmDicomDirPatient::gdcmDicomDirPatient(TagDocEntryHT *ptagHT):
 {
 }
 /**
- * \ingroup gdcmDicomDirPatient
  * \brief   Canonical destructor.
  */
 gdcmDicomDirPatient::~gdcmDicomDirPatient() 
@@ -60,7 +57,6 @@ gdcmDicomDirPatient::~gdcmDicomDirPatient()
 //-----------------------------------------------------------------------------
 // Print
 /**
- * \ingroup gdcmDicomDirPatient
  * \brief   Prints the Object
  * @return
  */ 
@@ -77,11 +73,23 @@ void gdcmDicomDirPatient::Print(std::ostream &os)
    }
 }
 
+/**
+ * \brief   Writes the Object
+ * @return
+ */ 
+void gdcmDicomDirPatient::Write(FILE *fp, FileType t)
+{
+   gdcmObject::Write(fp, t);
+
+   for(ListDicomDirStudy::iterator cc = studies.begin();cc!=studies.end();++cc)
+   {
+      (*cc)->Write( fp, t );
+   }
+}
 //-----------------------------------------------------------------------------
 // Public
 
 /**
- * \ingroup gdcmDicomDir
  * \brief   adds a new Patient at the begining of the PatientList
  *          of a partially created DICOMDIR
  */
index f4cc06e8837e380e1ff1db4c839f998d274278bc..eb3e7bde343056ea731ce390aeec2805e829ba2a 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirPatient.h,v $
   Language:  C++
-  Date:      $Date: 2004/08/01 02:39:09 $
-  Version:   $Revision: 1.6 $
+  Date:      $Date: 2004/08/26 15:29:52 $
+  Version:   $Revision: 1.7 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -35,7 +35,7 @@ public:
    ~gdcmDicomDirPatient();
 
    virtual void Print(std::ostream &os = std::cout);
-
+   virtual void Write(FILE *fp, FileType t);
    /// Returns the STUDY chained List for this PATIENT.
    ListDicomDirStudy &GetDicomDirStudies() { return studies; };
 
index 146d1c06ee771e0454d45450c2ac5823073fec1a..22f4b4d43ef63c539432154fa012416bc8c0b279 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirSerie.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/08/01 00:59:21 $
-  Version:   $Revision: 1.12 $
+  Date:      $Date: 2004/08/26 15:29:52 $
+  Version:   $Revision: 1.13 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -78,6 +78,21 @@ void gdcmDicomDirSerie::Print(std::ostream &os)
 
 //-----------------------------------------------------------------------------
 // Public
+
+/**
+ * \brief   Writes the Object
+ * @return
+ */ 
+void gdcmDicomDirSerie::Write(FILE *fp, FileType t)
+{
+   gdcmObject::Write(fp, t);
+
+   for(ListDicomDirImage::iterator cc = images.begin();cc!=images.end();++cc)
+   {
+      (*cc)->Write( fp, t );
+   }
+}
+
 /**
  * \brief   adds a new Image (with the basic elements) to a partially created DICOMDIR
  */
index 6305de8691ed12de74828b48bdde8c9384f02afc..ae419146850584f0423711beea49e674ccb5c4b3 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirSerie.h,v $
   Language:  C++
-  Date:      $Date: 2004/08/01 02:39:09 $
-  Version:   $Revision: 1.6 $
+  Date:      $Date: 2004/08/26 15:29:52 $
+  Version:   $Revision: 1.7 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -35,6 +35,7 @@ public:
    ~gdcmDicomDirSerie();
 
    virtual void Print(std::ostream &os = std::cout);
+   virtual void Write(FILE *fp, FileType t);
 /**
  * \ingroup gdcmDicomDirSerie
  * \brief   returns the IMAGE chained List for this SERIE.
index d1a66ff9f130be4cd616447c5a47428dd6ff7a38..cd3b07c60445c98d4b142c8ea5707e2f2b4bd6d9 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirStudy.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/08/01 02:39:09 $
-  Version:   $Revision: 1.9 $
+  Date:      $Date: 2004/08/26 15:29:52 $
+  Version:   $Revision: 1.10 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -80,6 +80,20 @@ void gdcmDicomDirStudy::Print(std::ostream &os)
 //-----------------------------------------------------------------------------
 // Public
 
+/**
+ * \brief   Writes the Object
+ * @return
+ */ 
+void gdcmDicomDirStudy::Write(FILE *fp, FileType t)
+{
+   gdcmObject::Write(fp, t);
+
+   for(ListDicomDirSerie::iterator cc = series.begin();cc!=series.end();++cc)
+   {
+      (*cc)->Write( fp, t );
+   }
+}
+
 /**
  * \ingroup gdcmDicomStudy
  * \brief   adds a new Serie at the begining of the SerieList
index bf57e91d052966c1fc604377b26f3c9344317fc0..8c3c8d3e4fa2919fe38b3a237ab39c15d3cdaeb1 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirStudy.h,v $
   Language:  C++
-  Date:      $Date: 2004/08/01 02:39:09 $
-  Version:   $Revision: 1.6 $
+  Date:      $Date: 2004/08/26 15:29:52 $
+  Version:   $Revision: 1.7 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -35,6 +35,7 @@ public:
    ~gdcmDicomDirStudy();
 
    virtual void Print(std::ostream &os = std::cout);
+   virtual void Write(FILE *fp, FileType t);
 /**
  * \ingroup gdcmDicomDirStudy
  * \brief   returns the SERIE chained List for this STUDY.
index e33a0cbc06dbcf060661c8b820800e154df9640b..ba497b5ff54e5333a8a5329c546dcd0f042faf90 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocEntrySet.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/08/01 03:20:23 $
-  Version:   $Revision: 1.15 $
+  Date:      $Date: 2004/08/26 15:29:52 $
+  Version:   $Revision: 1.16 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -56,7 +56,7 @@ gdcmDocEntrySet::~gdcmDocEntrySet()
 
 
 /**
- * \brief   Build a new Element Value from all the low level arguments. 
+ * \brief   Build a new Val Entry from all the low level arguments. 
  *          Check for existence of dictionary entry, and build
  *          a default one when absent.
  * @param   Group group   number of the underlying DictEntry
@@ -84,7 +84,7 @@ gdcmValEntry *gdcmDocEntrySet::NewValEntryByNumber(uint16_t group,
 
 
 /**
- * \brief   Build a new Element Value from all the low level arguments. 
+ * \brief   Build a new Bin Entry from all the low level arguments. 
  *          Check for existence of dictionary entry, and build
  *          a default one when absent.
  * @param   Group group   number of the underlying DictEntry
@@ -109,6 +109,31 @@ gdcmBinEntry *gdcmDocEntrySet::NewBinEntryByNumber(uint16_t group,
    }
    return newEntry;
 }
+
+/**
+ * \brief   Build a new Seq Entry from all the low level arguments. 
+ *          Check for existence of dictionary entry, and build
+ *          a default one when absent.
+ * @param   Group group   number of the underlying DictEntry
+ * @param   Elem  element number of the underlying DictEntry
+ */
+gdcmSeqEntry *gdcmDocEntrySet::NewSeqEntryByNumber(uint16_t Group,
+                                                   uint16_t Elem) 
+{
+   // Find out if the tag we encountered is in the dictionaries:
+   gdcmDictEntry *DictEntry = GetDictEntryByNumber(Group, Elem);
+   if (!DictEntry)
+      DictEntry = NewVirtualDictEntry(Group, Elem);
+
+   gdcmSeqEntry *NewEntry = new gdcmSeqEntry(DictEntry, 1); // FIXME : 1
+   if (!NewEntry) 
+   {
+      dbg.Verbose(1, "gdcmDocument::NewSeqEntryByNumber",
+                  "failed to allocate gdcmSeqEntry");
+      return NULL;
+   }
+   return NewEntry;
+}
 //-----------------------------------------------------------------------------
 // Protected
 
index e3af97b3cbb4998ff58a706f47b218f6d434a2a8..26fd1269a2f10101cb739999c41df4ff795aa95d 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocEntrySet.h,v $
   Language:  C++
-  Date:      $Date: 2004/08/01 03:20:23 $
-  Version:   $Revision: 1.14 $
+  Date:      $Date: 2004/08/26 15:29:52 $
+  Version:   $Revision: 1.15 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -69,6 +69,8 @@ protected:
    gdcmDocEntry* NewDocEntryByNumber(uint16_t group, 
                                      uint16_t element); 
    gdcmDocEntry* NewDocEntryByName  (std::string const & name);
+   gdcmSeqEntry* NewSeqEntryByNumber(uint16_t group, 
+                                     uint16_t element);
 
 // DictEntry  related utilities
    gdcmDictEntry *GetDictEntryByName  (std::string const & name);
index b61275492c3fd049074daf3b40f2b38925064a48..37966499bb038759d5d188a47fce182a6a0f29ab 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/08/16 04:34:56 $
-  Version:   $Revision: 1.67 $
+  Date:      $Date: 2004/08/26 15:29:53 $
+  Version:   $Revision: 1.68 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -94,7 +94,7 @@ gdcmDocument::gdcmDocument( std::string const & filename )
    {
       return;
    }
-   
+
    dbg.Verbose(0, "gdcmDocument::gdcmDocument: starting parsing of file: ",
                   Filename.c_str());
    rewind(Fp);
@@ -260,8 +260,6 @@ bool gdcmDocument::IsReadable()
 {
    if( Filetype == gdcmUnknown)
    {
-      std::cout << " gdcmDocument::IsReadable: Filetype " << Filetype
-               << " " << "gdcmUnknown " << gdcmUnknown << std::endl; //JPR
       dbg.Verbose(0, "gdcmDocument::IsReadable: wrong filetype");
       return false;
    }
@@ -671,6 +669,35 @@ gdcmBinEntry * gdcmDocument::ReplaceOrCreateByNumber(
    return b;
 }  
 
+
+/*
+ * \brief   Modifies the value of a given Header Entry (Dicom Element)
+ *          when it exists. Create it when unexistant.
+ * @param   Group   Group number of the Entry 
+ * @param   Elem  Element number of the Entry
+ * \return  pointer to the modified/created SeqEntry (NULL when creation
+ *          failed).
+ */
+gdcmSeqEntry * gdcmDocument::ReplaceOrCreateByNumber(
+                                         uint16_t group, 
+                                         uint16_t elem)
+{
+   gdcmSeqEntry* b = 0;
+   gdcmDocEntry* a = GetDocEntryByNumber( group, elem);
+   if (!a)
+   {
+      a = NewSeqEntryByNumber(group, elem);
+      if (!a)
+      {
+         return 0;
+      }
+
+      b = new gdcmSeqEntry(a, 1); // FIXME : 1 (Depth)
+      AddEntry(b);
+   }   
+   return b;
+} 
 /**
  * \brief Set a new value if the invoked element exists
  *        Seems to be useless !!!
@@ -1207,7 +1234,7 @@ uint32_t gdcmDocument::SwapLong(uint32_t a)
          a=( ((a<< 8) & 0xff00ff00) | ((a>>8) & 0x00ff00ff)  );
          break;
       default :
-         std::cout << "swapCode= " << SwapCode << std::endl;
+         //std::cout << "swapCode= " << SwapCode << std::endl;
          dbg.Error(" gdcmDocument::SwapLong : unset swap code");
          a = 0;
    }
@@ -1372,7 +1399,6 @@ long gdcmDocument::ParseDES(gdcmDocEntrySet *set,
       }
       delete newDocEntry;
    }
-
    return l; // Probably useless 
 }
 
@@ -1613,8 +1639,7 @@ void gdcmDocument::FindDocEntryLength( gdcmDocEntry *entry )
 {
    uint16_t element = entry->GetElement();
    std::string  vr  = entry->GetVR();
-   uint16_t length16;
-       
+   uint16_t length16;       
    
    if ( Filetype == gdcmExplicitVR && !entry->IsImplicitVR() ) 
    {
index 24e1cd2ef666bd9b124abfaae6d2c6f89066ad06..d43a644e27442d85efca94ba544219a8f26c194c 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.h,v $
   Language:  C++
-  Date:      $Date: 2004/08/02 16:42:14 $
-  Version:   $Revision: 1.30 $
+  Date:      $Date: 2004/08/26 15:29:53 $
+  Version:   $Revision: 1.31 $
  
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -141,6 +141,7 @@ public:
 
    gdcmBinEntry* ReplaceOrCreateByNumber(void *voidArea, int lgth,
                                          uint16_t group, uint16_t elem);
+   gdcmSeqEntry* ReplaceOrCreateByNumber(uint16_t group, uint16_t elem);
    bool ReplaceIfExistByNumber ( std::string const & value,
                                  uint16_t group,
                                  uint16_t elem );
@@ -199,8 +200,8 @@ protected:
 
 private:
    // Read
-   long ParseDES(gdcmDocEntrySet *set, long offset, long l_max,bool delim_mode);
-   long ParseSQ (gdcmSeqEntry *seq, long offset, long l_max, bool delim_mode); 
+   long ParseDES(gdcmDocEntrySet *set,long offset, long l_max, bool delim_mode);
+   long ParseSQ (gdcmSeqEntry *seq,   long offset, long l_max, bool delim_mode); 
    
    void LoadDocEntry      (gdcmDocEntry *);
    void FindDocEntryLength(gdcmDocEntry *) throw ( gdcmFormatError );
index b016e992e73844f3288e61104e8c91904706f456..484cc6909b771923839065f92c52f157918b63ee 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/08/02 16:42:14 $
-  Version:   $Revision: 1.120 $
+  Date:      $Date: 2004/08/26 15:29:53 $
+  Version:   $Revision: 1.121 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -22,7 +22,7 @@
 
 typedef std::pair<TagDocEntryHT::iterator,TagDocEntryHT::iterator> IterHT;
 
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
 // Constructor / Destructor
 /**
  * \ingroup   gdcmFile
index 2f4317fade93a769d2bfc5199783d881d44bd7ee..04363a85a1341179f5ad7e47df3f824b1f848278 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmObject.h,v $
   Language:  C++
-  Date:      $Date: 2004/08/01 00:59:21 $
-  Version:   $Revision: 1.18 $
+  Date:      $Date: 2004/08/26 15:29:53 $
+  Version:   $Revision: 1.19 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -39,6 +39,9 @@ typedef std::list<gdcmObject *> ListContent;
 class GDCM_EXPORT gdcmObject : public gdcmSQItem
 {
 public:
+
+   gdcmObject(TagDocEntryHT *ptagHT, int depth = 0);
+   virtual ~gdcmObject();
    /**
     * \brief   Sets the print level for the Dicom Header 
     * \note    0 for Light Print; 1 for 'medium' Print, 2 for Heavy
@@ -51,9 +54,8 @@ public:
 protected:
 
    // Constructor and destructor are protected to avoid end user to
-   // instanciate from this class.
-   gdcmObject(TagDocEntryHT *ptagHT, int depth = 0);
-   virtual ~gdcmObject();
+   // instanciate from this class. 
+   // NO ! gdcmDicomDir needs to instanciate it!
 
 // Members :
    ///\brief detail level to be printed 
index b861e9d98364aa2af6fdf94e871145bd078d171f..7d61d3cce28c878c633614ee0561903aa5fcc2ff 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmSQItem.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/08/01 03:20:23 $
-  Version:   $Revision: 1.23 $
+  Date:      $Date: 2004/08/26 15:29:53 $
+  Version:   $Revision: 1.24 $
   
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -78,7 +78,7 @@ gdcmSQItem::~gdcmSQItem()
 
       os << s.str();
       Entry->SetPrintLevel(2);
-      Entry->Print(os);   
+      Entry->Print(os); 
       if ( gdcmSeqEntry* SeqEntry = dynamic_cast<gdcmSeqEntry*>(Entry) )
       {
          (void)SeqEntry;  //not used
index 38793b6045d0c8a0d7aab0e246e533bddf5e8a08..5ee43c7754ac1272155b85ad50b53278fc31a865 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmSeqEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/07/21 14:02:11 $
-  Version:   $Revision: 1.22 $
+  Date:      $Date: 2004/08/26 15:29:53 $
+  Version:   $Revision: 1.23 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -36,8 +36,23 @@ gdcmSeqEntry::gdcmSeqEntry(gdcmDictEntry* e, int depth)
    delimitor_mode = false;
    seq_term  = NULL;
    SQDepthLevel = depth;
+   UsableLength = 0;
+   ReadLength = 0xffffffff;
 }
 
+/**
+ * \brief   Constructor from a given gdcmSeqEntry
+ * @param   e Pointer to existing Doc entry
+ */
+gdcmSeqEntry::gdcmSeqEntry(gdcmDocEntry* e, int depth) : gdcmDocEntry(e->GetDictEntry())
+{
+   this->UsableLength = 0;
+   this->ReadLength   = 0xffffffff;
+   this->ImplicitVR   = e->IsImplicitVR();
+   this->Offset       = e->GetOffset();
+   //this->printLevel   = e->GetPrintLevel(); // no longer exists ?!?
+   this->SQDepthLevel = e->GetDepthLevel();
+}
 /**
  * \brief   Canonical destructor.
  */
@@ -101,12 +116,15 @@ void gdcmSeqEntry::Write(FILE *fp, FileType filetype)
                           ++cc)
    {
       (*cc)->Write(fp, filetype);
-
-   fwrite ( &item_term_gr,(size_t)2 ,(size_t)1 ,fp);
-   fwrite ( &item_term_el,(size_t)2 ,(size_t)1 ,fp);   
-   fwrite ( &seq_term_lg, (size_t)4 ,(size_t)1 ,fp); // Heu .....
+      
+    //we force the writting of an Item Delimitation item
+    // because we wrote the Item as a 'no Length' item
+      fwrite ( &item_term_gr,(size_t)2 ,(size_t)1 ,fp);
+      fwrite ( &item_term_el,(size_t)2 ,(size_t)1 ,fp);   
+      fwrite ( &seq_term_lg, (size_t)4 ,(size_t)1 ,fp); // Heu .....
    }
-    //we force the writting of a Sequence Delimitaion item
+   
+    //we force the writting of a Sequence Delimitation item
     // because we wrote the Sequence as a 'no Length' sequence
    fwrite ( &seq_term_gr,(size_t)2 ,(size_t)1 ,fp);
    fwrite ( &seq_term_el,(size_t)2 ,(size_t)1 ,fp);
index 6eed4cb1857f04b1ed912e213f3624f3c798152f..61c7d8b6b1ac4b6f16157f5d008be357efb267ee 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmSeqEntry.h,v $
   Language:  C++
-  Date:      $Date: 2004/07/02 13:55:28 $
-  Version:   $Revision: 1.14 $
+  Date:      $Date: 2004/08/26 15:29:53 $
+  Version:   $Revision: 1.15 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -32,6 +32,7 @@ class GDCM_EXPORT gdcmSeqEntry : public gdcmDocEntry
 {
 public:
    gdcmSeqEntry(gdcmDictEntry* e, int depth);
+   gdcmSeqEntry(gdcmDocEntry* d,  int depth);
    virtual ~gdcmSeqEntry();
    
    virtual void Print(std::ostream &os = std::cout);