X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Testing%2FTestAllReadCompareDicom.cxx;h=23563114b754b500921f210be3d6f65b8bc96472;hb=579795c872c065c6218899aa8884138ecc613da7;hp=6f6748410935582f53b1a8ab508d3e4d9b443b07;hpb=0ced3dcc91cb31e52f9756b8bd1f62a3690f883c;p=gdcm.git diff --git a/Testing/TestAllReadCompareDicom.cxx b/Testing/TestAllReadCompareDicom.cxx index 6f674841..23563114 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/03/30 15:30:33 $ - Version: $Revision: 1.31 $ + Date: $Date: 2005/05/02 17:56:44 $ + Version: $Revision: 1.42 $ 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,10 @@ #include "gdcmDirList.h" #include "gdcmFile.h" #include "gdcmFileHelper.h" +#include "gdcmGlobal.h" +#include "gdcmTS.h" #include -#include //Generated file: #include "gdcmDataImages.h" @@ -43,16 +44,16 @@ public: ~TestFile(void); bool IsReadable(void) {return readable;} - unsigned int GetXSize(void) {return sizeX;}; - void SetXSize(unsigned int size) {sizeX = size;}; - unsigned int GetYSize(void) {return sizeY;}; - void SetYSize(unsigned int size) {sizeY = size;}; - unsigned int GetZSize(void) {return sizeZ;}; - void SetZSize(unsigned int size) {sizeZ = size;}; - unsigned int GetScalarSize(void) {return scalarSize;}; - void SetScalarSize(unsigned int size) {scalarSize = size;}; - unsigned int GetNumberOfComponents(void) {return components;}; - void SetNumberOfComponents(unsigned int size) {components = size;}; + int GetXSize(void) {return sizeX;}; + void SetXSize(int size) {sizeX = size;}; + int GetYSize(void) {return sizeY;}; + void SetYSize(int size) {sizeY = size;}; + int GetZSize(void) {return sizeZ;}; + void SetZSize(int size) {sizeZ = size;}; + int GetScalarSize(void) {return scalarSize;}; + void SetScalarSize(int size) {scalarSize = size;}; + int GetNumberOfComponents(void) {return components;}; + void SetNumberOfComponents(int size) {components = size;}; unsigned long GetDataSize(void) {return GetLineSize()*sizeY*sizeZ;} uint8_t *GetData(void) {return data;} @@ -75,30 +76,46 @@ private: bool WriteFileHeader(std::ofstream *fp); bool WriteFileData(std::ofstream *fp); - uint8_t ReadInt8 (std::ifstream *fp); - uint16_t ReadInt16(std::ifstream *fp); - uint32_t ReadInt32(std::ifstream *fp); - void WriteInt8 (std::ofstream *fp,uint8_t data); - void WriteInt16(std::ofstream *fp,uint16_t data); - void WriteInt32(std::ofstream *fp,uint32_t data); + 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); std::string fileName; bool readable; - unsigned int sizeX; - unsigned int sizeY; - unsigned int sizeZ; - unsigned int scalarSize; - unsigned int components; + int sizeX; + int sizeY; + int sizeZ; + 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) | @@ -336,26 +365,26 @@ uint32_t TestFile::ReadInt32(std::ifstream *fp) return g; } -void TestFile::WriteInt8 (std::ofstream *fp,uint8_t data) +void TestFile::WriteInt8 (std::ofstream *fp,uint8_t value) { - fp->write((char*)&data, (size_t)1); + fp->write((char*)&value, (size_t)1); } -void TestFile::WriteInt16(std::ofstream *fp,uint16_t data) +void TestFile::WriteInt16(std::ofstream *fp,uint16_t value) { #if defined(GDCM_WORDS_BIGENDIAN) - data = ( data << 8 | data >> 8 ); + value = ( value << 8 | value >> 8 ); #endif - fp->write((char*)&data, (size_t)2); + fp->write((char*)&value, (size_t)2); } -void TestFile::WriteInt32(std::ofstream *fp,uint32_t data) +void TestFile::WriteInt32(std::ofstream *fp,uint32_t value) { #if defined(GDCM_WORDS_BIGENDIAN) - data = ( (data<<24) | ((data<<8) & 0x00ff0000) | - ( (data>>8) & 0x0000ff00) | (data>>24) ); + value = ( (value<<24) | ((value<<8) & 0x00ff0000) | + ( (value>>8) & 0x0000ff00) | (value>>24) ); #endif - fp->write((char*)&data, (size_t)4); + fp->write((char*)&value, (size_t)4); } int InternalTest(std::string const &filename, @@ -381,11 +410,12 @@ int InternalTest(std::string const &filename, std::cout << "2..."; TestFile *reference = new TestFile(); - reference->Load(referenceFileName); - if(!reference->IsReadable()) + std::ifstream refFile(referenceFileName.c_str(), + std::ios::binary|std::ios::in); + if(!refFile) { std::cout << " Failed" << std::endl - << " Image not BMP compatible:" + << " Image not found:" << referenceFileName << std::endl; reference->SetXSize(tested->GetFile()->GetXSize()); reference->SetYSize(tested->GetFile()->GetYSize()); @@ -395,6 +425,8 @@ int InternalTest(std::string const &filename, reference->SetData(tested->GetImageData()); reference->Write(referenceFileName); } + else + refFile.close(); reference->Load(referenceFileName); if(!reference->IsReadable()) @@ -473,11 +505,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