]> Creatis software - gdcm.git/blobdiff - Testing/TestAllReadCompareDicom.cxx
Now TestAllReadCompareDicom.cxx TestReadWriteReadCompare.cxx accept a third
[gdcm.git] / Testing / TestAllReadCompareDicom.cxx
index 53cf29a25db7dec808c37e6f731af81c4955da42..1ac5df48b66e32f8d898eb8e5bee8de3c814ccea 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: TestAllReadCompareDicom.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/04/16 03:50:26 $
-  Version:   $Revision: 1.37 $
+  Date:      $Date: 2005/07/06 09:53:43 $
+  Version:   $Revision: 1.43 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -18,6 +18,9 @@
 #include "gdcmDirList.h"
 #include "gdcmFile.h"
 #include "gdcmFileHelper.h"
+#include "gdcmGlobal.h"
+#include "gdcmTS.h"
+#include "gdcmDebug.h"
 
 #include <iostream>
 
@@ -102,17 +105,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;
@@ -247,7 +251,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);
 }
@@ -293,7 +297,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);
 }
@@ -502,11 +506,34 @@ 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 the first " << MAX_NUMBER_OF_DIFFERENCE
+                   << " pixels differing (pos : test - ref) :" 
                    << std::endl;
+         int i;
+         unsigned int 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;
@@ -523,7 +550,10 @@ int InternalTest(std::string const &filename,
 
 int TestAllReadCompareDicom(int argc, char *argv[]) 
 {
-   if ( argc == 3 )
+   if (argc == 4)
+      gdcm::Debug::DebugOn();
+
+   if ( argc >= 3 )
    {
       // The test is specified a specific filename, use it instead of looping
       // over all images
@@ -531,7 +561,7 @@ int TestAllReadCompareDicom(int argc, char *argv[])
       const std::string reference = argv[2];
       return InternalTest( input, reference );
    }
-   else if ( argc > 3 || argc == 2 )
+   else if ( argc > 4 || argc == 2 )
    {
       std::cerr << "   Usage: " << argv[0]
                 << " (no arguments needed)." << std::endl;
@@ -551,23 +581,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;
@@ -577,7 +602,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) )
       {
@@ -594,6 +619,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 )