]> Creatis software - gdcm.git/commitdiff
JPR
authorjpr <jpr>
Wed, 21 Jul 2004 14:02:10 +0000 (14:02 +0000)
committerjpr <jpr>
Wed, 21 Jul 2004 14:02:10 +0000 (14:02 +0000)
Now, Parsing and Printing a DICOMDIR do work!
( troubles remain in makeDicomDir and BuildUpDicomDir :-(

Example/BuildUpDicomDir.cxx
Example/PrintDicomDir.cxx
Example/makeDicomDir.cxx
src/gdcmDicomDir.cxx
src/gdcmDicomDirSerie.cxx
src/gdcmObject.cxx
src/gdcmSeqEntry.cxx

index 54493a15a01a791764d471a7fad2b1fdadf8d320..c52275f50b00281f90a046ea9b6aaa9e0562c3b1 100644 (file)
@@ -54,6 +54,9 @@ int main(int argc, char* argv[])
    dcmdir=new gdcmDicomDir();
    printf( "BuildUpDicomDir: exiting new DicomDir\n");
 
+   printf( "\n------- BuildUpDicomDir: Test Print Meta only -----\n");
+   ((gdcmDocument *)dcmdir)->Print();
+
    gdcmDicomDirPatient *p1=dcmdir->NewPatient();
    p1->SetEntryByNumber("patientONE",0x0010, 0x0010);
 
index 89ba25c00246e9f7a436814162d2065f83864979..00adffc0e00ebd07350a3ff23705440379d83d12 100644 (file)
@@ -129,12 +129,12 @@ int main(int argc, char* argv[])
    }   
  */  
 
-/*
+
    cout << std::endl << std::endl  
         << " = DICOMDIR full content ==========================================" 
         << std::endl<< std::endl;
    e1->Print();
-*/   
+  
    std::cout<<std::flush;
    delete e1;
 
index 02146feb4caf13e1ae7d82a48d9eadde0fb8fc43..8b0c920847aefc069129fa09344d5c9752413aa9 100644 (file)
@@ -61,12 +61,17 @@ int main(int argc, char* argv[]) {
       dirName = GDCM_DATA_ROOT;
 
    dcmdir=new gdcmDicomDir(dirName);
-      
+   std::cout << "---after constructor; Print as a gdcmDocument ------" << std::endl;
+   ((gdcmDocument *)dcmdir)->Print();
+   std::cout << "---after constructor; Print as a DICOMDIR     ------" << std::endl;
+   dcmdir->Print();
+
    dcmdir->SetStartMethod(StartMethod, (void *) NULL);
    dcmdir->SetEndMethod(EndMethod);
+
     std::cout << "---before ParseDirectory------------------" << std::endl;   
    dcmdir->ParseDirectory();   
-   std::cout << "---after ParseDirectory------------------" << std::endl;
+   std::cout << "---after   ParseDirectory------------------" << std::endl;
    
    ListDicomDirPatient lp = dcmdir->GetDicomDirPatients();
    if (! lp.size() ) 
index b3e0d686bf93b3ec4f00f13ca7ba21c19aff2cee..fa59a3b765139fd27d02be25a2a511383e524319 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDir.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/07/19 03:34:11 $
-  Version:   $Revision: 1.57 $
+  Date:      $Date: 2004/07/21 14:02:10 $
+  Version:   $Revision: 1.58 $
   
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
 //-----------------------------------------------------------------------------
 // Constructor / Destructor
 
-void gdcmDicomDir::Initialize()
-{
-   startMethod             = NULL;
-   progressMethod          = NULL;
-   endMethod               = NULL;
-   startMethodArgDelete    = NULL;
-   progressMethodArgDelete = NULL;
-   endMethodArgDelete      = NULL;
-   startArg                = NULL;
-   progressArg             = NULL;
-   endArg                  = NULL;
-
-   progress = 0.0;
-   abort = false;
+/**
+ * \ingroup gdcmDicomDir
+ * \brief   Constructor : creates an empty gdcmDicomDir
+ * @param   exception_on_error whether we want to throw an exception or not
+ */
+gdcmDicomDir::gdcmDicomDir(bool exception_on_error):                           
+   gdcmDocument( exception_on_error )
+{ 
+   Initialize();
 
-   metaElems = (gdcmDicomDirMeta *)0;   
+   std::string pathBidon = "Bidon"; // Sorry, NULL not allowed ...
+   SetElement(pathBidon, GDCM_DICOMDIR_META, NULL); // Set the META elements
+   AddDicomDirMeta();
 }
 
-
 /**
  * \brief Constructor Parses recursively the directory and creates the DicomDir
  *        or uses an already built DICOMDIR, depending on 'parseDir' value.
@@ -90,21 +86,22 @@ gdcmDicomDir::gdcmDicomDir(std::string const & fileName, bool parseDir,
    // 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() ) 
    {
       dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : entry HT empty");
 
-      if( fileName.size() == 1 && fileName[0] == '.' )
+      if ( fileName.size() == 1 && fileName[0] == '.' )
       {
          // user passed '.' as Name
          // 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   
+         delete[] dummy;       // no longer needed   
       }
 
-      if( parseDir )
+      if ( parseDir )
       {
          dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : Parse directory"
                         " and create the DicomDir");
@@ -113,6 +110,8 @@ gdcmDicomDir::gdcmDicomDir(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
       }
    }
    else
@@ -130,21 +129,6 @@ gdcmDicomDir::gdcmDicomDir(std::string const & fileName, bool parseDir,
    }
 }
 
-/**
- * \ingroup gdcmDicomDir
- * \brief   Constructor : creates an empty gdcmDicomDir
- * @param   exception_on_error whether we want to throw an exception or not
- */
-gdcmDicomDir::gdcmDicomDir(bool exception_on_error):                           
-   gdcmDocument( exception_on_error )
-{ 
-   Initialize();
-
-   std::string pathBidon = "Bidon"; // Sorry, NULL not allowed ...
-   SetElement(pathBidon, GDCM_DICOMDIR_META, NULL); // Set the META elements
-   AddDicomDirMeta();
-}
-
 /**
  * \brief  Canonical destructor 
  */
@@ -154,7 +138,7 @@ gdcmDicomDir::~gdcmDicomDir()
    SetProgressMethod(NULL);
    SetEndMethod(NULL);
 
-   if( metaElems )
+   if ( metaElems )
    {
       delete metaElems;
    }
@@ -216,6 +200,29 @@ bool gdcmDicomDir::IsReadable()
    return true;
 }
 
+/**
+ * \brief Sets all fields to NULL
+ */
+
+void gdcmDicomDir::Initialize()
+{
+   startMethod             = NULL;
+   progressMethod          = NULL;
+   endMethod               = NULL;
+   startMethodArgDelete    = NULL;
+   progressMethodArgDelete = NULL;
+   endMethodArgDelete      = NULL;
+   startArg                = NULL;
+   progressArg             = NULL;
+   endArg                  = NULL;
+
+   progress = 0.0;
+   abort = false;
+
+   metaElems = (gdcmDicomDirMeta *)0;   
+}
+
+
 /**
  * \ingroup gdcmDicomDir
  * \brief  fills the whole structure, starting from a root Directory
@@ -447,7 +454,7 @@ void gdcmDicomDir::CreateDicomDirChainedList(std::string const & path)
 
       header = new gdcmHeader(it->c_str(),false,true);
       if(!header) {
-         std::cout << "echec new Header " << it->c_str() << std::endl; // JPR
+         std::cout << "failure in new Header " << it->c_str() << std::endl; // JPR
       }
       if(header->IsReadable()) {
          list.push_back(header);  // adds the file header to the chained list
@@ -500,16 +507,19 @@ gdcmDicomDirPatient * gdcmDicomDir::NewPatient()
    uint16_t tmpGr,tmpEl;
    gdcmDictEntry *dictEntry;
    gdcmValEntry *entry;
-   
+
+   std::list<gdcmElement> elemList;   
+   elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements(); 
+// Looks nice, but gdcmDicomDir IS NOT a gdcmObject ... 
+//   gdcmDicomDirPatient *p = new gdcmDicomDirPatient(ptagHT);
+//   FillObject(elemList);
+//   patients.push_front( p );
+//   return p;    
+/// \todo TODO : find a trick to use FillObject !!!
+
    gdcmSQItem *s = new gdcmSQItem(0);
-   
-   std::list<gdcmElement> elemList = 
-         gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();  
-   
-   /// \todo TODO : use FillObject !!!
 
-   // for all the DicomDirPatient Elements 
-     
+   // for all the DicomDirPatient Elements      
    for( it = elemList.begin(); it != elemList.end(); ++it ) 
    {
       tmpGr     = it->group;
@@ -567,24 +577,29 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,
    gdcmDictEntry *dictEntry;
    gdcmValEntry *entry;
    std::string val;
-
+   gdcmObject *o;
    switch( type )
    {
-      case GDCM_DICOMDIR_PATIENT:
-         elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
-         break;
-      case GDCM_DICOMDIR_STUDY:
-         elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirStudyElements();
+      case GDCM_DICOMDIR_IMAGE:
+         elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirImageElements();
          break;
+
       case GDCM_DICOMDIR_SERIE:
          elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirSerieElements();
          break;
-      case GDCM_DICOMDIR_IMAGE:
-         elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirImageElements();
+
+      case GDCM_DICOMDIR_STUDY:
+         elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirStudyElements();
          break;
+
+      case GDCM_DICOMDIR_PATIENT:
+         elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
+         break;
+  
       case GDCM_DICOMDIR_META:
          elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirMetaElements();
          break;
+
       default:
          return;
    }
@@ -598,7 +613,8 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,
 
       entry->SetOffset(0); // just to avoid further missprinting
 
-      if( header )
+      if( header ) // NULL when we Build Up (ex nihilo) a DICOMDIR
+                   //   or when we add the META elems
       {
          val = header->GetEntryByNumber(tmpGr, tmpEl);
       }
@@ -646,7 +662,7 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,
       {
          if( dictEntry->GetGroup() == 0xfffe )
          {
-            entry->SetLength( entry->GetValue().length() );
+            entry->SetLength( entry->GetValue().length() ); // FIXME 
          }
          else if( dictEntry->GetVR() == "UL" || dictEntry->GetVR() == "SL" )
          {
@@ -665,8 +681,12 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,
             entry->SetLength( entry->GetValue().length() );
          }
       }
-      //AddDocEntry(entry); // both in H Table and in chained list
-      TagHT[entry->GetKey()] = entry;          // FIXME : use a SEQUENCE !
+      std::cout << " was TagHT[entry->GetKey()] = entry " << std::endl;
+      if ( type == GDCM_DICOMDIR_META ) {
+         std::cout << " special Treatment for GDCM_DICOMDIR_META" << std::endl;
+         
+      }
+      //TagHT[entry->GetKey()] = entry;          // FIXME : use a SEQUENCE !
    }
 }
 
@@ -724,8 +744,6 @@ void gdcmDicomDir::CreateDicomDir()
    //       + we create the object for the precedent tag
    //       + loop to 1 -
 
-   gdcmDicomDirType type = gdcmDicomDir::GDCM_DICOMDIR_META;
-   
    // Directory record sequence
    gdcmDocEntry *e = GetDocEntryByNumber(0x0004, 0x1220);
    if ( !e )
@@ -740,12 +758,14 @@ void gdcmDicomDir::CreateDicomDir()
    if ( !s )
    {
       dbg.Verbose(0, "gdcmDicomDir::CreateDicomDir: no SeqEntry present");
+      // useless : (0x0004,0x1220) IS a Sequence !
       return;
    }
 
+   gdcmDicomDirType type = gdcmDicomDir::GDCM_DICOMDIR_META;
+   metaElems = NewMeta();
+
    ListSQItem listItems = s->GetSQItems();
-   gdcmDicomDirMeta *m  = new gdcmDicomDirMeta(&TagHT);
-   (void)m; //??
    
    gdcmDocEntry * d;
    std::string v;
index ecdb07c29ddcd296011de71cf4b276e388f02732..0b62c553ac2e0b3adc0bb2fecc9e3be63b3afd4a 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirSerie.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/06/20 18:08:47 $
-  Version:   $Revision: 1.10 $
+  Date:      $Date: 2004/07/21 14:02:10 $
+  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
@@ -75,7 +75,7 @@ void gdcmDicomDirSerie::Print(std::ostream &os)
 //-----------------------------------------------------------------------------
 // Public
 /**
- * \brief   adds a new Image to a partially created DICOMDIR
+ * \brief   adds a new Image (with the basic elements) to a partially created DICOMDIR
  */
 gdcmDicomDirImage * gdcmDicomDirSerie::NewImage(void) {
    std::list<gdcmElement> elemList;   
index 331c41073a2369334946ab8d4e6a5bd7c45e946f..953131b2eb84b9d12145a5c5276c80a6d23052b1 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmObject.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/07/17 22:47:01 $
-  Version:   $Revision: 1.22 $
+  Date:      $Date: 2004/07/21 14:02:10 $
+  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
@@ -28,7 +28,7 @@
  *          
  * @param ptagHT pointer to the HTable (gdcmObject needs it 
  *               to build the gdcmDocEntries)
- * @param depth Seaquence depth level
+ * @param depth Sequence depth level
  */
   
 gdcmObject::gdcmObject(TagDocEntryHT *ptagHT, int depth) 
@@ -80,9 +80,7 @@ void gdcmObject::FillObject(std::list<gdcmElement> elemList) {
    uint16_t tmpGr,tmpEl;
    gdcmDictEntry *dictEntry;
    gdcmValEntry *entry;
-   
-   //gdcmSQItem *s = new gdcmSQItem;
-   
+      
    // for all the Elements found in they own part of the DicomDir dict.     
    for(it=elemList.begin();it!=elemList.end();++it)
    {
index 9ba911ee236863df0c045455c90c40b0a668b29a..38793b6045d0c8a0d7aab0e246e533bddf5e8a08 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmSeqEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/07/02 13:55:28 $
-  Version:   $Revision: 1.21 $
+  Date:      $Date: 2004/07/21 14:02:11 $
+  Version:   $Revision: 1.22 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -104,7 +104,7 @@ void gdcmSeqEntry::Write(FILE *fp, FileType 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); 
+   fwrite ( &seq_term_lg, (size_t)4 ,(size_t)1 ,fp); // Heu .....
    }
     //we force the writting of a Sequence Delimitaion item
     // because we wrote the Sequence as a 'no Length' sequence