]> Creatis software - gdcm.git/blobdiff - Testing/TestReadWriteReadCompare.cxx
* gdcmPython/gdcm.i : bug fix. Now string are correctly converted in python
[gdcm.git] / Testing / TestReadWriteReadCompare.cxx
index 23dc39f981b423be96b5da2dcc2c720b97612265..8a821950e4fbbf870fe1283a0f9fb75c39a5f4c9 100644 (file)
@@ -1,5 +1,22 @@
-#include "gdcmHeader.h"
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: TestReadWriteReadCompare.cxx,v $
+  Language:  C++
+  Date:      $Date: 2005/02/02 10:05:26 $
+  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
+  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,21 +27,21 @@ int CompareInternal(std::string const & filename, std::string const & output)
 
    //////////////// Step 1 (see above description):
 
-   gdcm::Header *header = new gdcm::Header( filename );
-   if( !header->IsReadable() )
+   gdcm::File *file = new gdcm::File( filename );
+   if( !file->IsReadable() )
    {
       std::cerr << "Test::TestReadWriteReadCompare: Image not gdcm compatible:"
                 << filename << std::endl;
-      delete header;
+      delete file;
       return 1;
    }
-   std::cout << "           step 1 ...";
+   std::cout << "           step 1...";
 
    //////////////// Step 2:
 
-   gdcm::File*  file = new gdcm::File( header );
-   int dataSize    = file->GetImageDataSize();
-   uint8_t* imageData = file->GetImageData(); //EXTREMELY IMPORTANT
+   gdcm::FileHelper *filehelper = new gdcm::FileHelper( file );
+   int dataSize    = filehelper->GetImageDataSize();
+   uint8_t *imageData = filehelper->GetImageData(); //EXTREMELY IMPORTANT
           // Sure, it is : It's up to the user to decide if he wants to
           // GetImageData or if he wants to GetImageDataRaw
           // (even if we do it by setting a flag, he will have to decide) 
@@ -45,68 +62,83 @@ int CompareInternal(std::string const & filename, std::string const & output)
    
    // --> I did. ctest doesn't break. But ... is it enought to say it's OK ?
    
-   file->SetImageData(imageData, dataSize);
+   filehelper->SetImageData(imageData, dataSize);
    
-   file->WriteDcmExplVR( output );
+   filehelper->SetWriteModeToRGB();
+   filehelper->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;
+     delete filehelper;
      delete reread;
      return 1;
    }
    std::cout << "3...";
    // For the next step:
    int    dataSizeWritten = reread->GetImageDataSize();
-   void* imageDataWritten = reread->GetImageData();
+   uint8_t *imageDataWritten = reread->GetImageData();
 
    //////////////// Step 4:
+   // Test the image size
+   if (file->GetXSize() != reread->GetFile()->GetXSize() ||
+       file->GetYSize() != reread->GetFile()->GetYSize() ||
+       file->GetZSize() != reread->GetFile()->GetZSize())
+   {
+      std::cout << "Failed" << std::endl
+         << "        X Size differs: "
+         << "X: " << file->GetXSize() << " # " 
+                  << reread->GetFile()->GetXSize() << " | "
+         << "Y: " << file->GetYSize() << " # " 
+                  << reread->GetFile()->GetYSize() << " | "
+         << "Z: " << file->GetZSize() << " # " 
+                  << reread->GetFile()->GetZSize() << std::endl;
+      delete file;
+      delete filehelper;
+      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 (char*)imageData;
-      delete (char*)imageDataWritten;
-      delete header;
       delete file;
+      delete filehelper;
       delete reread;
       return 1;
    }
 
-   if (int res = memcmp(imageData, imageDataWritten, dataSize) !=0)
+   // Test the data's content
+   if (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 (char*)imageData;
-      delete (char*)imageDataWritten;
-      delete header;
       delete file;
+      delete filehelper;
       delete reread;
       return 1;
    }
    std::cout << "4...OK." << std::endl ;
 
    //////////////// Clean up:
-   delete (char*)imageData;
-   delete (char*)imageDataWritten;
-   delete header;
    delete file;
+   delete filehelper;
    delete reread;
 
    return 0;
 }
 
-int TestReadWriteReadCompare(int argc, charargv[]) 
+int TestReadWriteReadCompare(int argc, char *argv[]) 
 {
    int result = 0;
    if (argc == 3)
@@ -125,7 +157,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