]> Creatis software - gdcm.git/commitdiff
gdcmDocument::ReplaceOrCreateByNumber has now an extra parameter,
authorjpr <jpr>
Thu, 16 Sep 2004 06:47:59 +0000 (06:47 +0000)
committerjpr <jpr>
Thu, 16 Sep 2004 06:47:59 +0000 (06:47 +0000)
 std::string VR (default value : "unkn"), that makes
 TestCopyDicom code much lighter .

Testing/TestCopyDicom.cxx
src/gdcmDocument.cxx
src/gdcmDocument.h

index e0478850e864cf7251975eb8829e4c6a696fff2c..5b35c48bd57c22bf2cc8dc365f98fa28d81a4b01 100644 (file)
@@ -41,7 +41,7 @@ bool RemoveFile(const char* source)
 // Here we load a gdcmFile and then try to create from scratch a copy of it,
 // copying field by field the dicom image
 
-int TestCopyDicom(int , char* [])
+int TestCopyDicom(int argc, char* argv[])
 {
    int i =0;
    int retVal = 0;  //by default this is an error
@@ -75,66 +75,37 @@ int TestCopyDicom(int , char* [])
       // It was commented out by Mathieu, that was a *good* idea
       // (the user does NOT have to know the way we implemented the Header !)
       // Waiting for a 'clean' solution, I keep the method ...JPRx
-    
-      TagNameHT & nameHt = original->GetHeader()->GetPubDict()->GetEntriesByName();
-      (void)nameHt; //not used ?
 
-      //gdcmValEntry* v;
-      //gdcmBinEntry* b;
       gdcmDocEntry* d;
 
       for (TagDocEntryHT::iterator tag = Ht.begin(); tag != Ht.end(); ++tag)
       {
          d = tag->second;
          if ( gdcmBinEntry* b = dynamic_cast<gdcmBinEntry*>(d) )
-         { 
-         // for private elements, the gdcmDictEntry is unknown
-         // and it's VR is unpredictable ...
-         // ( In *this* case ReplaceOrCreateByNumber 
-         //  should have a knowledge of the virtual dictionary 
-         //  gdcmDictSet::VirtualEntry ) 
-         // ReplaceOrCreateByNumber may now receive the VR of the source Entry
-         // as a extra parameter
-         //
-            //if ( d->GetGroup()%2 == 1) // Skip private Entries 
-            //   continue;
-
-           // TODO :write ReplaceOrCreateByNumber with VR, 
-           //       for BinEntries as well!
-             
+         {              
             copy->GetHeader()->ReplaceOrCreateByNumber( 
                                  b->GetVoidArea(),
                                  b->GetLength(),
                                  b->GetGroup(), 
-                                 b->GetElement() );
+                                 b->GetElement(),
+                                 b->GetVR() );
             }
             else  if ( gdcmValEntry* v = dynamic_cast<gdcmValEntry*>(d) )
-            {
-               if ( d->GetGroup()%2 != 1)
-               {
-                  copy->GetHeader()->ReplaceOrCreateByNumber( 
-                                 v->GetValue(),
-                                 v->GetGroup(), 
-                                 v->GetElement() );
-                }
-                else
-                {
-                  copy->GetHeader()->ReplaceOrCreateByNumber( 
+            {   
+               copy->GetHeader()->ReplaceOrCreateByNumber( 
                                  v->GetValue(),
                                  v->GetGroup(), 
                                  v->GetElement(),
                                  v->GetVR() ); 
-                }
-         }
-         else
-         {
+           }
+           else
+           {
           // We skip pb of SQ recursive exploration
           //std::cout << "Skipped Sequence " 
           //          << "------------- " << d->GetVR() << " "<< std::hex
           //          << d->GetGroup() << " " << d->GetElement()
           //  << std::endl;    
-         }
+           }
       }
 
       size_t dataSize = original->GetImageDataSize();
index 4f066856bf08417e41d9e88954427a4b730bbdd5..37be3f68b76d7ba93d77ad6c15daeb07f6e0bb41 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/09/15 03:50:48 $
-  Version:   $Revision: 1.78 $
+  Date:      $Date: 2004/09/16 06:48:00 $
+  Version:   $Revision: 1.79 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -598,7 +598,8 @@ void gdcmDocument::Write(FILE* fp,FileType filetype)
  * \return  pointer to the modified/created Header Entry (NULL when creation
  *          failed).
  */
-  
+
+/*  
 gdcmValEntry * gdcmDocument::ReplaceOrCreateByNumber(
                                          std::string const & value, 
                                          uint16_t group, 
@@ -652,6 +653,7 @@ gdcmValEntry * gdcmDocument::ReplaceOrCreateByNumber(
 
    return valEntry;
 }   
+*/
 
 /**
  * \brief   Modifies the value of a given Header Entry (Dicom Element)
@@ -751,26 +753,70 @@ gdcmBinEntry * gdcmDocument::ReplaceOrCreateByNumber(
                                          void *voidArea,
                                          int lgth, 
                                          uint16_t group, 
-                                         uint16_t elem)
+                                         uint16_t elem,
+                                         std::string const & VR )
 {
-   gdcmBinEntry* b = 0;
-   gdcmDocEntry* a = GetDocEntryByNumber( group, elem);
-   if (!a)
+   gdcmBinEntry* binEntry = 0;
+   gdcmDocEntry* currentEntry = GetDocEntryByNumber( group, elem);
+   if (!currentEntry)
    {
-      a = NewBinEntryByNumber(group, elem);
-      if (!a)
+
+      // check if (group,element) DictEntry exists
+      // if it doesn't, create an entry in gdcmDictSet::VirtualEntry
+      // and use it
+
+   // Find out if the tag we received is in the dictionaries:
+      gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
+      gdcmDictEntry *dictEntry = pubDict->GetDictEntryByNumber(group, elem);
+
+      if (!dictEntry)
       {
-         return 0;
+         currentEntry = NewDocEntryByNumber(group, elem,VR);
       }
-
-      b = new gdcmBinEntry(a);
-      AddEntry(b);
-      b->SetVoidArea(voidArea);
-   } 
+      else
+      {
+         currentEntry = NewDocEntryByNumber(group, elem);
+      }
+      if (!currentEntry)
+      {
+         dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: call to"
+                        " NewDocEntryByNumber failed.");
+         return NULL;
+      }
+      binEntry = new gdcmBinEntry(currentEntry);
+      if ( !AddEntry(binEntry))
+      {
+         dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: AddEntry"
+                        " failed allthough this is a creation.");
+      }
+   }
+   else
+   {
+      binEntry = dynamic_cast< gdcmBinEntry* >(currentEntry);
+      if ( !binEntry ) // Euuuuh? It wasn't a BinEntry
+                       // then we change it to a BinEntry ?
+                       // Shouldn't it be considered as an error ?
+      {
+         // We need to promote the gdcmDocEntry to a gdcmBinEntry:
+         binEntry = new gdcmBinEntry(currentEntry);
+         if (!RemoveEntry(currentEntry))
+         {
+            dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: removal"
+                           " of previous DocEntry failed.");
+            return NULL;
+         }
+         if ( !AddEntry(binEntry))
+         {
+            dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: adding"
+                           " promoted BinEntry failed.");
+            return NULL;
+         }
+      }
+   }
 
    SetEntryByNumber(voidArea, lgth, group, elem);
 
-   return b;
+   return binEntry;
 }  
 
 
index 7c2ef447404ac2fd449a0237b733751c85d2aa42..8e63544c14e2ee9cfad262d5a8239b4b03239b5b 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.h,v $
   Language:  C++
-  Date:      $Date: 2004/09/14 16:47:08 $
-  Version:   $Revision: 1.36 $
+  Date:      $Date: 2004/09/16 06:48:00 $
+  Version:   $Revision: 1.37 $
  
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -132,15 +132,13 @@ public:
 
    void Write(FILE* fp, FileType type);
 
-   gdcmValEntry* ReplaceOrCreateByNumber(std::string const & value,
-                                         uint16_t group, uint16_t elem);
-
    gdcmValEntry* ReplaceOrCreateByNumber(std::string const & value,
                                          uint16_t group, uint16_t elem,
-                                         std::string const & VR);
+                                         std::string const & VR ="unkn");
    
    gdcmBinEntry* ReplaceOrCreateByNumber(void *voidArea, int lgth,
-                                         uint16_t group, uint16_t elem);
+                                         uint16_t group, uint16_t elem,
+                                         std::string const & VR="unkn");
 
    gdcmSeqEntry* ReplaceOrCreateByNumber(uint16_t group, uint16_t elem);