]> Creatis software - gdcm.git/blobdiff - Testing/TestReadWriteReadCompare.cxx
Hope TestDicomDir will be aware of DicomDir stuff errors ...
[gdcm.git] / Testing / TestReadWriteReadCompare.cxx
index 6d53cda116f23901ea1096871ae9f139e9d41e03..468b8721840febb9fa0087fc72fb81cc8d511422 100644 (file)
@@ -1,5 +1,22 @@
-#include "gdcmHeader.h"
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: TestReadWriteReadCompare.cxx,v $
+  Language:  C++
+  Date:      $Date: 2005/01/21 11:40:54 $
+  Version:   $Revision: 1.20 $
+                                                                                
+  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 "gdcmFile.h"
+#include "gdcmFileHelper.h"
 
 //Generated file:
 #include "gdcmDataImages.h"
@@ -10,7 +27,7 @@ int CompareInternal(std::string const & filename, std::string const & output)
 
    //////////////// Step 1 (see above description):
 
-   gdcm::Header *header = new gdcm::Header( filename );
+   gdcm::File *header = new gdcm::File( filename );
    if( !header->IsReadable() )
    {
       std::cerr << "Test::TestReadWriteReadCompare: Image not gdcm compatible:"
@@ -18,11 +35,11 @@ int CompareInternal(std::string const & filename, std::string const & output)
       delete header;
       return 1;
    }
-   std::cout << "           step 1 ...";
+   std::cout << "           step 1...";
 
    //////////////// Step 2:
 
-   gdcm::File*  file = new gdcm::File( header );
+   gdcm::FileHelper*  file = new gdcm::FileHelper( header );
    int dataSize    = file->GetImageDataSize();
    uint8_t* imageData = file->GetImageData(); //EXTREMELY IMPORTANT
           // Sure, it is : It's up to the user to decide if he wants to
@@ -47,15 +64,17 @@ int CompareInternal(std::string const & filename, std::string const & output)
    
    file->SetImageData(imageData, dataSize);
    
+   file->SetWriteModeToRGB();
    file->WriteDcmExplVR( output );
    std::cout << "2...";
  
    //////////////// Step 3:
 
-   gdcm::File* reread = new gdcm::File( output );
-   if( !reread->GetHeader()->IsReadable() )
+   gdcm::FileHelper* reread = new gdcm::FileHelper( output );
+   if( !reread->GetFile()->IsReadable() )
    {
-     std::cerr << "Test::TestReadWriteReadCompare: Could not reread image "
+     std::cerr << "Failed" << std::endl
+               << "Test::TestReadWriteReadCompare: Could not reread image "
                << "written:" << filename << std::endl;
      delete header;
      delete file;
@@ -68,10 +87,29 @@ int CompareInternal(std::string const & filename, std::string const & output)
    uint8_t* imageDataWritten = reread->GetImageData();
 
    //////////////// Step 4:
+   // Test the image size
+   if (header->GetXSize() != reread->GetFile()->GetXSize() ||
+       header->GetYSize() != reread->GetFile()->GetYSize() ||
+       header->GetZSize() != reread->GetFile()->GetZSize())
+   {
+      std::cout << "Failed" << std::endl
+         << "        X Size differs: "
+         << "X: " << header->GetXSize() << " # " 
+                  << reread->GetFile()->GetXSize() << " | "
+         << "Y: " << header->GetYSize() << " # " 
+                  << reread->GetFile()->GetYSize() << " | "
+         << "Z: " << header->GetZSize() << " # " 
+                  << reread->GetFile()->GetZSize() << std::endl;
+      delete header;
+      delete file;
+      delete reread;
+      return 1;
+   }
 
+   // Test the data size
    if (dataSize != dataSizeWritten)
    {
-      std::cout << std::endl
+      std::cout << "Failed" << std::endl
          << "        Pixel areas lengths differ: "
          << dataSize << " # " << dataSizeWritten << std::endl;
       delete header;
@@ -80,10 +118,11 @@ int CompareInternal(std::string const & filename, std::string const & output)
       return 1;
    }
 
+   // Test the data's content
    if (int res = memcmp(imageData, imageDataWritten, dataSize) !=0)
    {
       (void)res;
-      std::cout << std::endl
+      std::cout << "Failed" << std::endl
          << "        Pixel differ (as expanded in memory)." << std::endl;
       delete header;
       delete file;
@@ -119,7 +158,7 @@ int TestReadWriteReadCompare(int argc, char* argv[])
       std::cout << "   For all images in gdcmData (and not blacklisted in "
                    "Test/CMakeLists.txt)" << std::endl;
       std::cout << "   apply the following multistep test: " << 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(). " << std::endl;
       std::cout << "   step 2: write the corresponding image in DICOM V3 "
                 << "with explicit" << std::endl