]> Creatis software - gdcm.git/blobdiff - Testing/TestAllReadCompareDicom.cxx
ENH: Set a maximum of difference to avoid generating a log bigger than mem size of...
[gdcm.git] / Testing / TestAllReadCompareDicom.cxx
index 6d6bf11d0018e669073f8df01bb201f0d053a737..f00906cfcfe53abca96129974ed0a4fd297c4f9b 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: TestAllReadCompareDicom.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/03/31 08:06:21 $
-  Version:   $Revision: 1.33 $
+  Date:      $Date: 2005/05/02 17:51:57 $
+  Version:   $Revision: 1.41 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
 #include "gdcmDirList.h"
 #include "gdcmFile.h"
 #include "gdcmFileHelper.h"
+#include "gdcmGlobal.h"
+#include "gdcmTS.h"
 
 #include <iostream>
-#include <fstream>
 
 //Generated file:
 #include "gdcmDataImages.h"
@@ -75,9 +76,24 @@ private:
    bool WriteFileHeader(std::ofstream *fp);
    bool WriteFileData(std::ofstream *fp);
 
-   uint8_t  ReadInt8 (std::ifstream *fp) throw( std::ios::failure );
-   uint16_t ReadInt16(std::ifstream *fp) throw( std::ios::failure );
-   uint32_t ReadInt32(std::ifstream *fp) throw( std::ios::failure );
+   uint8_t  ReadInt8 (std::ifstream *fp)
+#if !(__GNUC__==2  && __GNUC_MINOR__<=96)
+ throw( std::ios::failure );
+#else
+ ;
+#endif
+   uint16_t ReadInt16(std::ifstream *fp)
+#if !(__GNUC__==2  && __GNUC_MINOR__<=96)
+  throw( std::ios::failure );
+#else
+ ;
+#endif
+   uint32_t ReadInt32(std::ifstream *fp)
+#if !(__GNUC__==2  && __GNUC_MINOR__<=96)
+  throw( std::ios::failure );
+#else
+ ;
+#endif
    void WriteInt8 (std::ofstream *fp,uint8_t  value);
    void WriteInt16(std::ofstream *fp,uint16_t value);
    void WriteInt32(std::ofstream *fp,uint32_t value);
@@ -88,17 +104,18 @@ private:
    int sizeX;
    int sizeY;
    int sizeZ;
-   int scalarSize;
-   int components;
+   uint16_t scalarSize;
+   uint16_t components;
    uint8_t *data;
    int swapCode;
 
    static const unsigned int HEADER_SIZE;
 };
 
+const unsigned int MAX_NUMBER_OF_DIFFERENCE = 10;
 const unsigned int TestFile::HEADER_SIZE = 20;
 
-TestFile::TestFile(void)
+TestFile::TestFile()
 {
    fileName = "";
    readable=false;
@@ -233,7 +250,7 @@ bool TestFile::ReadFileHeader(std::ifstream *fp)
    sizeY = ReadInt32(fp); // Size Y
    sizeZ = ReadInt32(fp); // Size Z
    scalarSize = ReadInt16(fp)/8; // bits per scalar
-   components = ReadInt16(fp); // Number of components
+   components = ReadInt16(fp);   // Number of components
 
    return(true);
 }
@@ -279,7 +296,7 @@ bool TestFile::WriteFileHeader(std::ofstream *fp)
    WriteInt32(fp,sizeY); // Size Y
    WriteInt32(fp,sizeZ); // Size Z
    WriteInt16(fp,scalarSize*8); // bits per scalar
-   WriteInt16(fp,components); // number of components
+   WriteInt16(fp,components);   // number of components
 
    return(true);
 }
@@ -292,26 +309,34 @@ bool TestFile::WriteFileData(std::ofstream *fp)
 }
 
 uint8_t  TestFile::ReadInt8 (std::ifstream *fp)
+#if !(__GNUC__==2  && __GNUC_MINOR__<=96)
    throw( std::ios::failure )
+#endif
 {
    uint8_t g;
    fp->read ((char*)&g, (size_t)1);
+#if !(__GNUC__==2  && __GNUC_MINOR__<=96)
    if ( fp->fail() )
       throw std::ios::failure( "TestFile::ReadInt8() - file error." );
    if( fp->eof() )
       throw std::ios::failure( "TestFile::ReadInt8() - EOF." );
+#endif
    return g;
 }
 
 uint16_t TestFile::ReadInt16(std::ifstream *fp)
+#if !(__GNUC__==2  && __GNUC_MINOR__<=96)
    throw( std::ios::failure )
+#endif
 {
    uint16_t g;
    fp->read ((char*)&g, (size_t)2);
+#if !(__GNUC__==2  && __GNUC_MINOR__<=96)
    if ( fp->fail() )
       throw std::ios::failure( "TestFile::ReadInt16() - file error." );
    if( fp->eof() )
       throw std::ios::failure( "TestFile::ReadInt16() - EOF." );
+#endif
 
 #if defined(GDCM_WORDS_BIGENDIAN)
    g = ( g << 8 |  g >> 8  );
@@ -320,14 +345,18 @@ uint16_t TestFile::ReadInt16(std::ifstream *fp)
 }
 
 uint32_t TestFile::ReadInt32(std::ifstream *fp)
+#if !(__GNUC__==2  && __GNUC_MINOR__<=96)
    throw( std::ios::failure )
+#endif
 {
    uint32_t g;
    fp->read ((char*)&g, (size_t)4);
+#if !(__GNUC__==2  && __GNUC_MINOR__<=96)
    if ( fp->fail() )
       throw std::ios::failure( "TestFile::ReadInt32() - file error." );
    if( fp->eof() )
       throw std::ios::failure( "TestFile::ReadInt32() - EOF." );
+#endif
 
 #if defined(GDCM_WORDS_BIGENDIAN)
    g = (  (g<<24)               | ((g<<8)  & 0x00ff0000) | 
@@ -476,11 +505,32 @@ int InternalTest(std::string const &filename,
                            testedDataSize) != 0 )
       {
          (void)res;
+         std::string ts  = tested->GetFile()->GetTransferSyntax();
+
          std::cout << " Failed" << std::endl
                    << "        pixel (" 
                    << PixelType
                    << ") differ (as expanded in memory)."
+                   << std::endl
+                   << "        compression : " 
+                   << gdcm::Global::GetTS()->GetValue(ts) << std::endl;
+
+         std::cout << "        list of pixels differing (pos : test - ref) :" 
                    << std::endl;
+         int i,j;
+         for(i=0, j=0;i<testedDataSize && j<MAX_NUMBER_OF_DIFFERENCE;i++)
+         {
+            if(testedImageData[i]!=referenceImageData[i])
+              {
+               std::cout << std::hex << "(" << i << " : " 
+                         << std::hex << (int)(testedImageData[i]) << " - "
+                         << std::hex << (int)(referenceImageData[i]) << ") "
+                         << std::dec;
+               ++j;
+              }
+         }
+         std::cout << std::endl;
+
          delete tested;
          delete reference;
          return 1;
@@ -525,23 +575,18 @@ int TestAllReadCompareDicom(int argc, char *argv[])
    std::cout << "   step 1: parse the image (as gdcmFile) and call"
              << " IsReadable(). "
              << std::endl;
-   std::cout << "   step 2: find in GDCM_DATA_ROOT/BaselineDicom/filename.dcm"
-             << std::endl
-             << "           (with format DICOM V3, explicit Value"
-             << "Representation)"
-             << std::endl;
-   std::cout << "   step 3a: when image NOT found on step 2, write "
+   std::cout << "   step 2: find in GDCM_DATA_ROOT/BaselineDicom/filename.tst"
              << std::endl
-             << "            GDCM_DATA_ROOT/BaselineDicom/filename.dcm"
+             << "           special internal file format containing the"
              << std::endl
-             << "           (with format DICOM V3, explicit Value"
-             << "Representation)"
+             << "           caracteristic of the image and the pixel datas "
+             << "(uncompressed). This file is written if it's not found."
              << std::endl;
-   std::cout << "   step 3b: when image found on step 2, and when IsReadable()"
+   std::cout << "   step 3: compare the DICOM image with the reference image"
              << std::endl
-             << "            compare it (in memory with memcmp) with the"
+             << "           (.tst file). The test is made on the caracteristics"
              << std::endl
-             << "            image we are testing (the one of step 1). "
+             << "           of the image and the pixel datas"
              << std::endl << std::endl;
 
    int i = 0;
@@ -551,7 +596,7 @@ int TestAllReadCompareDicom(int argc, char *argv[])
       ////// Check for existence of reference baseline directory
 
       std::string baseLineDir = GDCM_DATA_ROOT;
-      baseLineDir += "/BaselineDicom/";
+      baseLineDir += "/BaselineDicom";
 
       if( !gdcm::DirList::IsDirectory(baseLineDir) )
       {
@@ -568,6 +613,7 @@ int TestAllReadCompareDicom(int argc, char *argv[])
       filename += "/";
       filename += gdcmDataImages[i];
       
+      baseLineDir += '/';
       std::string referenceFileName = baseLineDir + gdcmDataImages[i++];
       std::string::size_type slash_pos = referenceFileName.rfind( "." );
       if( slash_pos != std::string::npos )