]> Creatis software - gdcm.git/blobdiff - Testing/TestCopyRescaleDicom.cxx
methods ReplaceOrCreate renamed as Insert
[gdcm.git] / Testing / TestCopyRescaleDicom.cxx
index e566dda4f02424f8607c15f84876b79fa08747f4..eaff8b4c891e5678c8118a40243e90d0d98758df 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: TestCopyRescaleDicom.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/18 07:56:21 $
-  Version:   $Revision: 1.6 $
+  Date:      $Date: 2005/01/24 16:44:54 $
+  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
@@ -15,8 +15,8 @@
      PURPOSE.  See the above copyright notices for more information.
                                                                                 
 =========================================================================*/
-#include "gdcmHeader.h"
 #include "gdcmFile.h"
+#include "gdcmFileHelper.h"
 #include "gdcmValEntry.h"
 #include "gdcmBinEntry.h"
 
@@ -43,17 +43,11 @@ int CopyRescaleDicom(std::string const & filename,
 
    //////////////// Step 1:
    std::cout << "      1...";
-   gdcm::Header *originalH = new gdcm::Header( filename );
-   gdcm::Header *copyH     = new gdcm::Header( );
+   gdcm::File *originalH = new gdcm::File( filename );
+   gdcm::File *copyH     = new gdcm::File( );
 
    //First of all copy the header field by field
 
-   // Warning :Accessor gdcmElementSet::GetEntry() should not exist 
-   // 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
-
-
    //////////////// Step 2:
    std::cout << "2...";
    // Copy of the header content
@@ -62,7 +56,7 @@ int CopyRescaleDicom(std::string const & filename,
    {
       if ( gdcm::BinEntry* b = dynamic_cast<gdcm::BinEntry*>(d) )
       {
-         copyH->ReplaceOrCreate
+         copyH->Insert
                               b->GetBinArea(),
                               b->GetLength(),
                               b->GetGroup(), 
@@ -71,7 +65,7 @@ int CopyRescaleDicom(std::string const & filename,
       }
       else if ( gdcm::ValEntry* v = dynamic_cast<gdcm::ValEntry*>(d) )
       {   
-          copyH->ReplaceOrCreate
+          copyH->Insert
                               v->GetValue(),
                               v->GetGroup(), 
                               v->GetElement(),
@@ -85,22 +79,22 @@ int CopyRescaleDicom(std::string const & filename,
       d=originalH->GetNextEntry();
    }
 
-   gdcm::File *original = new gdcm::File( originalH );
-   gdcm::File *copy     = new gdcm::File( copyH );
+   gdcm::FileHelper *original = new gdcm::FileHelper( originalH );
+   gdcm::FileHelper *copy     = new gdcm::FileHelper( copyH );
 
    size_t dataSize = original->GetImageDataSize();
 
    size_t rescaleSize;
    uint8_t *rescaleImage;
 
-   const std::string & bitsStored    = originalH->GetEntry(0x0028,0x0101);
+   const std::string & bitsStored    = originalH->GetEntryValue(0x0028,0x0101);
    if( bitsStored == "16" )
    {
       std::cout << "Rescale...";
-      copyH->ReplaceOrCreate( "8", 0x0028, 0x0100); // BitsAllocated
-      copyH->ReplaceOrCreate( "8", 0x0028, 0x0101); // BitsStored
-      copyH->ReplaceOrCreate( "7", 0x0028, 0x0102); // HighBit
-      copyH->ReplaceOrCreate( "0", 0x0028, 0x0103); //Pixel Representation
+      copyH->Insert( "8", 0x0028, 0x0100); // BitsAllocated
+      copyH->Insert( "8", 0x0028, 0x0101); // BitsStored
+      copyH->Insert( "7", 0x0028, 0x0102); // HighBit
+      copyH->Insert( "0", 0x0028, 0x0103); //Pixel Representation
  
       // We assume the value were from 0 to uint16_t max
       rescaleSize = dataSize / 2;
@@ -144,10 +138,10 @@ int CopyRescaleDicom(std::string const & filename,
 
    //////////////// Step 4:
    std::cout << "4...";
-   copy = new gdcm::File( output );
+   copy = new gdcm::FileHelper( output );
 
    //Is the file written still gdcm parsable ?
-   if ( !copy->GetHeader()->IsReadable() )
+   if ( !copy->GetFile()->IsReadable() )
    { 
       std::cout << " Failed" << std::endl
                 << "        " << output << " not readable" << std::endl;
@@ -164,18 +158,18 @@ int CopyRescaleDicom(std::string const & filename,
    size_t    dataSizeWritten = copy->GetImageDataSize();
    uint8_t* imageDataWritten = copy->GetImageData();
 
-   if (originalH->GetXSize() != copy->GetHeader()->GetXSize() ||
-       originalH->GetYSize() != copy->GetHeader()->GetYSize() ||
-       originalH->GetZSize() != copy->GetHeader()->GetZSize())
+   if (originalH->GetXSize() != copy->GetFile()->GetXSize() ||
+       originalH->GetYSize() != copy->GetFile()->GetYSize() ||
+       originalH->GetZSize() != copy->GetFile()->GetZSize())
    {
       std::cout << "Failed" << std::endl
          << "        X Size differs: "
          << "X: " << originalH->GetXSize() << " # " 
-                  << copy->GetHeader()->GetXSize() << " | "
+                  << copy->GetFile()->GetXSize() << " | "
          << "Y: " << originalH->GetYSize() << " # " 
-                  << copy->GetHeader()->GetYSize() << " | "
+                  << copy->GetFile()->GetYSize() << " | "
          << "Z: " << originalH->GetZSize() << " # " 
-                  << copy->GetHeader()->GetZSize() << std::endl;
+                  << copy->GetFile()->GetZSize() << std::endl;
       delete original;
       delete copy;
       delete originalH;
@@ -251,7 +245,7 @@ int TestCopyRescaleDicom(int argc, char* argv[])
              << std::endl;
    std::cout << "   apply the following to each filename.xxx: "
              << std::endl;
-   std::cout << "   step 1: parse the image (as gdcmHeader) and call"
+   std::cout << "   step 1: parse the image (as gdcmFile) and call"
              << " IsReadable(). After that, call GetImageData() and "
              << "GetImageDataSize() "
              << std::endl;