]> Creatis software - gdcm.git/blobdiff - Testing/TestCopyDicom.cxx
* FIX : now, the DocEntries are all deleted in the gdcmElementSet.
[gdcm.git] / Testing / TestCopyDicom.cxx
index e0478850e864cf7251975eb8829e4c6a696fff2c..70284c3a36aaa2be2a27d049c7b94184cd0591a5 100644 (file)
@@ -1,3 +1,20 @@
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: TestCopyDicom.cxx,v $
+  Language:  C++
+  Date:      $Date: 2004/11/16 04:28:20 $
+  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
+  http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
+                                                                                
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+                                                                                
+=========================================================================*/
 #include "gdcmHeader.h"
 #include "gdcmFile.h"
 #include "gdcmDocument.h"
@@ -9,6 +26,8 @@
 
 #ifndef _WIN32
 #include <unistd.h> //for access, unlink
+#else
+#include <io.h> //for _access on Win32
 #endif
 
 // return true if the file exists
@@ -64,10 +83,13 @@ int TestCopyDicom(int , char* [])
          }
       }
 
-      gdcmFile *original = new gdcmFile( filename );
-      gdcmFile *copy = new gdcmFile( output );
+      gdcm::File *original = new gdcm::File( filename );
+      gdcm::File *copy = new gdcm::File( output );
 
-      TagDocEntryHT & Ht = original->GetHeader()->GetEntry(); 
+      const gdcm::TagDocEntryHT & Ht = original->GetHeader()->GetTagHT();
+
+      size_t dataSize = original->GetImageDataSize();
+      uint8_t* imageData = original->GetImageData();
 
       //First of all copy the header field by field
   
@@ -75,57 +97,28 @@ 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;
+      gdcm::DocEntry* d;
 
-      for (TagDocEntryHT::iterator tag = Ht.begin(); tag != Ht.end(); ++tag)
+      for (gdcm::TagDocEntryHT::const_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!
-             
+         if ( gdcm::BinEntry* b = dynamic_cast<gdcm::BinEntry*>(d) )
+         {              
             copy->GetHeader()->ReplaceOrCreateByNumber( 
-                                 b->GetVoidArea(),
+                                 b->GetBinArea(),
                                  b->GetLength(),
                                  b->GetGroup(), 
-                                 b->GetElement() );
-            }
-            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( 
+                                 b->GetElement(),
+                                 b->GetVR() );
+         }
+         else if ( gdcm::ValEntry* v = dynamic_cast<gdcm::ValEntry*>(d) )
+         {   
+             copy->GetHeader()->ReplaceOrCreateByNumber( 
                                  v->GetValue(),
                                  v->GetGroup(), 
                                  v->GetElement(),
                                  v->GetVR() ); 
-                }
          }
          else
          {
@@ -137,9 +130,6 @@ int TestCopyDicom(int , char* [])
          }
       }
 
-      size_t dataSize = original->GetImageDataSize();
-      void *imageData = original->GetImageData();
-
       copy->SetImageData(imageData, dataSize);
       original->GetHeader()->SetImageDataSize(dataSize);
 
@@ -148,7 +138,7 @@ int TestCopyDicom(int , char* [])
       delete original;
       delete copy;
 
-      copy = new gdcmFile( output );
+      copy = new gdcm::File( output );
 
       //Is the file written still gdcm parsable ?
       if ( !copy->GetHeader()->IsReadable() )