]> Creatis software - gdcm.git/commitdiff
Now, TestCopyDicom deals with private Entries
authorjpr <jpr>
Tue, 14 Sep 2004 16:47:08 +0000 (16:47 +0000)
committerjpr <jpr>
Tue, 14 Sep 2004 16:47:08 +0000 (16:47 +0000)
Testing/TestCopyDicom.cxx
src/gdcmDocEntrySet.cxx
src/gdcmDocEntrySet.h
src/gdcmDocument.cxx
src/gdcmDocument.h
src/gdcmHeader.cxx

index bd914c68a9a54ce02d16ab50f358831efec6deed..f5ded1b22abdc9c4853ba11ff975c20ec6253f8a 100644 (file)
@@ -85,23 +85,22 @@ int TestCopyDicom(int , char* [])
       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)
-         if ( d->GetGroup()%2 == 1) // Skip private Entries 
-            continue;
-         if ( gdcmBinEntry* b = dynamic_cast<gdcmBinEntry*>(d) )
-         { 
-           // std::cout << "BinEntry : " 
-           //           << "------------- " << b->GetVR() << " "<< std::hex
-           //           << b->GetGroup() << " " << b->GetElement() << " "
-           //           << " lg=" << b->GetLength()
-           //           << std::endl; 
+         //  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(),
@@ -109,12 +108,23 @@ int TestCopyDicom(int , char* [])
                                  b->GetGroup(), 
                                  b->GetElement() );
             }
-           else  if ( gdcmValEntry* v = dynamic_cast<gdcmValEntry*>(d) )
+            else  if ( gdcmValEntry* v = dynamic_cast<gdcmValEntry*>(d) )
             {
-            copy->GetHeader()->ReplaceOrCreateByNumber( 
+               if ( d->GetGroup()%2 != 1)
+               {
+                  copy->GetHeader()->ReplaceOrCreateByNumber( 
                                  v->GetValue(),
                                  v->GetGroup(), 
                                  v->GetElement() );
+                }
+                else
+                {
+                  copy->GetHeader()->ReplaceOrCreateByNumber( 
+                                 v->GetValue(),
+                                 v->GetGroup(), 
+                                 v->GetElement(),
+                                 v->GetVR() ); 
+                }
          }
          else
          {
index b187140b4beb75c6ca65e4ded676b4e783127c4f..ce1c25bf1128b8c8b58b9021670b3629ec55c893 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocEntrySet.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/09/10 14:32:04 $
-  Version:   $Revision: 1.20 $
+  Date:      $Date: 2004/09/14 16:47:08 $
+  Version:   $Revision: 1.21 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -217,6 +217,35 @@ gdcmDocEntry* gdcmDocEntrySet::NewDocEntryByNumber(uint16_t group,
    return newEntry;
 }
 
+
+/** \brief 
+ * Creates a new DocEntry (without any 'value' ...)
+ * @param   group     group  number of the underlying DictEntry
+ * @param   elem  elem number of the underlying DictEntry 
+ * @param   VR   V(alue) R(epresentation) of the Entry -if private Entry- 
+
+ */
+gdcmDocEntry* gdcmDocEntrySet::NewDocEntryByNumber(uint16_t group,
+                                                   uint16_t elem,
+                                                   std::string const &VR)
+{
+   // Find out if the tag we encountered is in the dictionaries:
+   gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
+   gdcmDictEntry *dictEntry = pubDict->GetDictEntryByNumber(group, elem);
+   if (!dictEntry)
+   {
+      dictEntry = NewVirtualDictEntry(group, elem, VR);
+   }
+
+   gdcmDocEntry *newEntry = new gdcmDocEntry(dictEntry);
+   if (!newEntry) 
+   {
+      dbg.Verbose(1, "gdcmSQItem::NewDocEntryByNumber",
+                  "failed to allocate gdcmDocEntry");
+      return 0;
+   }
+   return newEntry;
+}
 /* \brief
  * Probabely move, as is, to gdcmDocEntrySet, as a non virtual method
  * an remove gdcmDocument::NewDocEntryByName
index 982e02862d21f1983e7e7d974d4e9a936d668037..c77756822e43a9a5f09d89004a4ba2c49f43d2d3 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocEntrySet.h,v $
   Language:  C++
-  Date:      $Date: 2004/09/13 12:10:53 $
-  Version:   $Revision: 1.16 $
+  Date:      $Date: 2004/09/14 16:47:08 $
+  Version:   $Revision: 1.17 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -72,6 +72,9 @@ protected:
                                      uint16_t element);
    gdcmDocEntry* NewDocEntryByNumber(uint16_t group, 
                                      uint16_t element); 
+   gdcmDocEntry* NewDocEntryByNumber(uint16_t group, 
+                                     uint16_t element,
+                                     std::string const & VR); 
    gdcmDocEntry* NewDocEntryByName  (std::string const & name);
    gdcmSeqEntry* NewSeqEntryByNumber(uint16_t group, 
                                      uint16_t element);
index 9976959e156995dc10708b731ed4b5cd920a26ac..54787ed8afbcb5e999f816f069d20af25d72682a 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/09/13 12:10:53 $
-  Version:   $Revision: 1.76 $
+  Date:      $Date: 2004/09/14 16:47:08 $
+  Version:   $Revision: 1.77 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -653,6 +653,91 @@ gdcmValEntry * gdcmDocument::ReplaceOrCreateByNumber(
    return valEntry;
 }   
 
+/**
+ * \brief   Modifies the value of a given Header Entry (Dicom Element)
+ *          when it exists. Create it with the given value when unexistant.
+ * @param   value (string) Value to be set
+ * @param   group   Group number of the Entry 
+ * @param   elem  Element number of the Entry
+ * @param   VR  V(alue) R(epresentation) of the Entry -if private Entry-
+ * \return  pointer to the modified/created Header Entry (NULL when creation
+ *          failed).
+ */
+ // TODO : write something clever, using default value for VR
+ //        to avoid code duplication
+ //        (I don't know how to tell NewDocEntryByNumber
+ //         that ReplaceOrCreateByNumber  was called with a default value)
+gdcmValEntry * gdcmDocument::ReplaceOrCreateByNumber(
+                                         std::string const & value, 
+                                         uint16_t group, 
+                                         uint16_t elem,
+                                         std::string const & VR )
+{
+   gdcmValEntry* valEntry = 0;
+   gdcmDocEntry* currentEntry = GetDocEntryByNumber( group, elem);
+   
+   if (!currentEntry)
+   {
+      // 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)
+      {
+         currentEntry = NewDocEntryByNumber(group, elem,VR);
+      }
+      else
+      {
+         currentEntry = NewDocEntryByNumber(group, elem);
+      }
+
+      if (!currentEntry)
+      {
+         dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: call to"
+                        " NewDocEntryByNumber failed.");
+         return NULL;
+      }
+      valEntry = new gdcmValEntry(currentEntry);
+      if ( !AddEntry(valEntry))
+      {
+         dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: AddEntry"
+                        " failed allthough this is a creation.");
+      }
+   }
+   else
+   {
+      valEntry = dynamic_cast< gdcmValEntry* >(currentEntry);
+      if ( !valEntry ) // Euuuuh? It wasn't a ValEntry
+                       // then we change it to a ValEntry ?
+                       // Shouldn't it be considered as an error ?
+      {
+         // We need to promote the gdcmDocEntry to a gdcmValEntry:
+         valEntry = new gdcmValEntry(currentEntry);
+         if (!RemoveEntry(currentEntry))
+         {
+            dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: removal"
+                           " of previous DocEntry failed.");
+            return NULL;
+         }
+         if ( !AddEntry(valEntry))
+         {
+            dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: adding"
+                           " promoted ValEntry failed.");
+            return NULL;
+         }
+      }
+   }
+
+   SetEntryByNumber(value, group, elem);
+
+   return valEntry;
+}   
+
 /*
  * \brief   Modifies the value of a given Header Entry (Dicom Element)
  *          when it exists. Create it with the given value when unexistant.
@@ -684,7 +769,6 @@ gdcmBinEntry * gdcmDocument::ReplaceOrCreateByNumber(
    } 
 
    SetEntryByNumber(voidArea, lgth, group, elem);
-   //b->SetVoidArea(voidArea);  //what if b == 0 !!
 
    return b;
 }  
index 0ddfb468f8203c49f0e692f79a3cbd01a32f1c37..7c2ef447404ac2fd449a0237b733751c85d2aa42 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.h,v $
   Language:  C++
-  Date:      $Date: 2004/09/03 15:11:35 $
-  Version:   $Revision: 1.35 $
+  Date:      $Date: 2004/09/14 16:47:08 $
+  Version:   $Revision: 1.36 $
  
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -135,9 +135,15 @@ public:
    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);
+   
    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 );
index 6eb2f39b96e20f84ee8295e6b4509f41778fddf8..5ecbbc981585d0cd70d2bb03e2154c381bbdb15c 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmHeader.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/09/10 18:54:39 $
-  Version:   $Revision: 1.185 $
+  Date:      $Date: 2004/09/14 16:47:08 $
+  Version:   $Revision: 1.186 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -1259,13 +1259,14 @@ void gdcmHeader::SetImageDataSize(size_t ImageDataSize)
  */
 bool gdcmHeader::AnonymizeHeader()
 {
-   gdcmDocEntry* patientNameHE = GetDocEntryByNumber (0x0010, 0x0010);
+   // If exist, replace by spaces
+   SetEntryByNumber ("  ",0x0010, 0x2154); // Telephone   
+   SetEntryByNumber ("  ",0x0010, 0x1040); // Adress
+   SetEntryByNumber ("  ",0x0010, 0x0020); // Patient ID
 
-   ReplaceIfExistByNumber ("  ",0x0010, 0x2154); // Telephone   
-   ReplaceIfExistByNumber ("  ",0x0010, 0x1040); // Adress
-   ReplaceIfExistByNumber ("  ",0x0010, 0x0020); // Patient ID
+   gdcmDocEntry* patientNameHE = GetDocEntryByNumber (0x0010, 0x0010);
   
-   if ( patientNameHE )
+   if ( patientNameHE ) // we replace it by Study Instance UID (why not)
    {
       std::string studyInstanceUID =  GetEntryByNumber (0x0020, 0x000d);
       if ( studyInstanceUID != GDCM_UNFOUND )