X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Testing%2FTestAllReadCompareDicom.cxx;h=bb428fd0903b006f0668f019cf88ece83c7c53fe;hb=4cf608c37695b2385eebeb1426ca8cc87f1c8108;hp=e5de6788260dca50e2d4dd1a4c2e81ec3caa1d64;hpb=ccd312d24ac6ea6536d7bbea5c9c96a57fe66385;p=gdcm.git diff --git a/Testing/TestAllReadCompareDicom.cxx b/Testing/TestAllReadCompareDicom.cxx index e5de6788..bb428fd0 100644 --- a/Testing/TestAllReadCompareDicom.cxx +++ b/Testing/TestAllReadCompareDicom.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestAllReadCompareDicom.cxx,v $ Language: C++ - Date: $Date: 2005/04/15 21:46:06 $ - Version: $Revision: 1.36 $ + Date: $Date: 2005/10/18 08:35:46 $ + Version: $Revision: 1.48 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -18,9 +18,11 @@ #include "gdcmDirList.h" #include "gdcmFile.h" #include "gdcmFileHelper.h" +#include "gdcmGlobal.h" +#include "gdcmTS.h" +#include "gdcmDebug.h" #include -#include //Generated file: #include "gdcmDataImages.h" @@ -76,19 +78,19 @@ private: bool WriteFileData(std::ofstream *fp); uint8_t ReadInt8 (std::ifstream *fp) -#ifndef __GNUC__ - throw( std::ofstream::failure ); +#if !(__GNUC__==2 && __GNUC_MINOR__<=96) + throw( std::ios::failure ); #else ; #endif uint16_t ReadInt16(std::ifstream *fp) -#ifndef __GNUC__ +#if !(__GNUC__==2 && __GNUC_MINOR__<=96) throw( std::ios::failure ); #else ; #endif uint32_t ReadInt32(std::ifstream *fp) -#ifndef __GNUC__ +#if !(__GNUC__==2 && __GNUC_MINOR__<=96) throw( std::ios::failure ); #else ; @@ -103,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; @@ -248,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); } @@ -294,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); } @@ -307,13 +310,13 @@ bool TestFile::WriteFileData(std::ofstream *fp) } uint8_t TestFile::ReadInt8 (std::ifstream *fp) -#ifndef __GNUC__ +#if !(__GNUC__==2 && __GNUC_MINOR__<=96) throw( std::ios::failure ) #endif { uint8_t g; fp->read ((char*)&g, (size_t)1); -#ifndef __GNUC__ +#if !(__GNUC__==2 && __GNUC_MINOR__<=96) if ( fp->fail() ) throw std::ios::failure( "TestFile::ReadInt8() - file error." ); if( fp->eof() ) @@ -323,13 +326,13 @@ uint8_t TestFile::ReadInt8 (std::ifstream *fp) } uint16_t TestFile::ReadInt16(std::ifstream *fp) -#ifndef __GNUC__ +#if !(__GNUC__==2 && __GNUC_MINOR__<=96) throw( std::ios::failure ) #endif { uint16_t g; fp->read ((char*)&g, (size_t)2); -#ifndef __GNUC__ +#if !(__GNUC__==2 && __GNUC_MINOR__<=96) if ( fp->fail() ) throw std::ios::failure( "TestFile::ReadInt16() - file error." ); if( fp->eof() ) @@ -343,13 +346,13 @@ uint16_t TestFile::ReadInt16(std::ifstream *fp) } uint32_t TestFile::ReadInt32(std::ifstream *fp) -#ifndef __GNUC__ +#if !(__GNUC__==2 && __GNUC_MINOR__<=96) throw( std::ios::failure ) #endif { uint32_t g; fp->read ((char*)&g, (size_t)4); -#ifndef __GNUC__ +#if !(__GNUC__==2 && __GNUC_MINOR__<=96) if ( fp->fail() ) throw std::ios::failure( "TestFile::ReadInt32() - file error." ); if( fp->eof() ) @@ -393,16 +396,23 @@ int InternalTest(std::string const &filename, ////// Step 1: std::cout << "1..."; - gdcm::FileHelper *tested = new gdcm::FileHelper( filename ); - if( !tested->GetFile()->IsReadable() ) + + // new style + gdcm::File *f = new gdcm::File(); + f->SetLoadMode ( gdcm::LD_ALL ); // Load everything + f->SetFileName( filename ); + f->Load(); + + if( !f->IsReadable() ) { std::cout << " Failed" << std::endl << " Image not gdcm compatible:" << filename << std::endl; - delete tested; + delete f; return 1; } - + gdcm::FileHelper *tested = new gdcm::FileHelper( f ); + ////// Step 2: ////// Check for existence of reference baseline dicom file: std::cout << "2..."; @@ -434,6 +444,7 @@ int InternalTest(std::string const &filename, << filename << std::endl; delete reference; delete tested; + delete f; return 1; } @@ -461,6 +472,7 @@ int InternalTest(std::string const &filename, << reference->GetZSize() << std::endl; delete reference; delete tested; + delete f; return 1; } @@ -473,9 +485,11 @@ int InternalTest(std::string const &filename, << " Scalar size: " << tested->GetFile()->GetPixelSize() << " # " << reference->GetScalarSize() << std::endl << " Number of scalar: " << tested->GetFile()->GetNumberOfScalarComponents() << " # " - << reference->GetNumberOfComponents() << std::endl; + << reference->GetNumberOfComponents() << std::endl + << " Pixel type: " << tested->GetFile()->GetPixelType() << std::endl; delete reference; delete tested; + delete f; return 1; } @@ -495,6 +509,7 @@ int InternalTest(std::string const &filename, << std::endl; delete tested; delete reference; + delete f; return 1; } @@ -503,19 +518,44 @@ 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= 3 ) { // The test is specified a specific filename, use it instead of looping // over all images @@ -532,7 +575,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; @@ -552,23 +595,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;