X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Testing%2FTestAllReadCompareDicom.cxx;h=6819123c71bbbfae56ca4636e7a30771032949b8;hb=bef512a69f6a9c53b2d1e6eef1c54babe4daa19e;hp=ef51a8c1e479508505ba01cc7869e33e08cb5171;hpb=79a9384ed191f8bf60c726bbd992e8f8b3bea48f;p=gdcm.git diff --git a/Testing/TestAllReadCompareDicom.cxx b/Testing/TestAllReadCompareDicom.cxx index ef51a8c1..6819123c 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/11/03 14:07:12 $ - Version: $Revision: 1.51 $ + Date: $Date: 2007/06/21 14:59:05 $ + Version: $Revision: 1.60 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -21,6 +21,7 @@ #include "gdcmGlobal.h" #include "gdcmTS.h" #include "gdcmDebug.h" +#include "gdcmUtil.h" #include @@ -137,7 +138,7 @@ TestFile::TestFile() Components = 0; Data = NULL; - SwapCode = 1234; + //SwapCode = 1234; } TestFile::~TestFile() @@ -167,7 +168,14 @@ void TestFile::Write(const std::string &filename) int TestFile::ComputeSwapCode(uint32_t tag) { +// FIXME : 100 % useless method ! +// "gdcm" was written on disc byte per byte. +// when you fread it, you'll get *always* "gdcm" +// whatever the processor indianess is ! + int swap = 0; + //std::cout << std::hex << "0x(" << tag << ")" << std::dec << std::endl; + for(int i=0;i<4;i++) { switch(tag&0x000000FF) @@ -189,6 +197,7 @@ int TestFile::ComputeSwapCode(uint32_t tag) } tag >>= 8; } + //std::cout << std::hex << "0x(" << tag << ")" << std::dec << tag << std::endl; return swap; } @@ -252,6 +261,7 @@ bool TestFile::ReadFileHeader(std::ifstream *fp) SwapCode = ComputeSwapCode(tag); if( SwapCode == 0 ) { + // We shall *never* come here! std::cout << "TestFile: Bad tag - Must be 'gdcm'" << std::endl; return(false); } @@ -259,7 +269,7 @@ bool TestFile::ReadFileHeader(std::ifstream *fp) SizeX = ReadInt32(fp); // Size X SizeY = ReadInt32(fp); // Size Y SizeZ = ReadInt32(fp); // Size Z - ScalarSize = ReadInt16(fp)/8; // bits per scalar + ScalarSize = ReadInt16(fp)/8; // bytes per scalar Components = ReadInt16(fp); // Number of components return(true); @@ -274,25 +284,33 @@ bool TestFile::ReadFileData(std::ifstream *fp) if( !Data ) return(false); - // Read data + // Read data Note : .tst images are *always* created + // on little endian processor ! fp->read((char *)Data,GetDataSize()); - - if (GetScalarSize() == 1 || GetSwapCode() == 1234) + + // Track BigEndian troubles + std::cout << " ScalarSize : " << GetScalarSize() + << " IsCurrentProcessorBigEndian:" + << GDCM_NAME_SPACE::Util::IsCurrentProcessorBigEndian() + << std::endl; + + //if (GetScalarSize() == 1 || GetSwapCode() == 1234) + if (GetScalarSize() == 1 || !GDCM_NAME_SPACE::Util::IsCurrentProcessorBigEndian() ) { return true; } // We *know* the .tst files are written in 'Little Endian' format. // We *know* DataSize may be 1 or 2 ! - uint16_t g; + uint16_t g; + + std::cout << " Let's swap Pixels" <> 8 ); ((uint16_t *)Data)[i] = g; } - - - return(true); } @@ -318,6 +336,11 @@ bool TestFile::WriteFileHeader(std::ofstream *fp) WriteInt8(fp,'d'); // Bitmap tag - must be 'd' WriteInt8(fp,'c'); // Bitmap tag - must be 'c' WriteInt8(fp,'m'); // Bitmap tag - must be 'm' + + // FIXME : Think of writting an int32, better ! + // (('g' << 8 + 'd') << 8 + 'c') + 'm' + // if you want to use it to check the endianess. + // (and upload again *all* the .tst files ...) WriteInt32(fp,SizeX); // Size X WriteInt32(fp,SizeY); // Size Y WriteInt32(fp,SizeZ); // Size Z @@ -423,8 +446,8 @@ int InternalTest(std::string const &filename, std::cout << "1..."; // new style - gdcm::File *f = gdcm::File::New(); - f->SetLoadMode ( gdcm::LD_ALL ); // Load everything + GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New(); + f->SetLoadMode ( GDCM_NAME_SPACE::LD_ALL ); // Load everything f->SetFileName( filename ); f->Load(); @@ -436,7 +459,7 @@ int InternalTest(std::string const &filename, f->Delete(); return 1; } - gdcm::FileHelper *tested = gdcm::FileHelper::New( f ); + GDCM_NAME_SPACE::FileHelper *tested = GDCM_NAME_SPACE::FileHelper::New( f ); ////// Step 2: ////// Check for existence of reference baseline dicom file: @@ -550,7 +573,7 @@ int InternalTest(std::string const &filename, << ") differ (as expanded in memory)." << std::endl << " compression : " - << gdcm::Global::GetTS()->GetValue(ts) << std::endl; + << GDCM_NAME_SPACE::Global::GetTS()->GetValue(ts) << std::endl; std::cout << " list of the first " << MAX_NUMBER_OF_DIFFERENCE << " pixels differing (pos : test - ref) :" @@ -588,8 +611,11 @@ int InternalTest(std::string const &filename, int TestAllReadCompareDicom(int argc, char *argv[]) { +// Temporarily added, to track BigEndian troubles +GDCM_NAME_SPACE::Debug::WarningOn(); + if (argc == 4) - gdcm::Debug::DebugOn(); + GDCM_NAME_SPACE::Debug::DebugOn(); if ( argc >= 3 ) { @@ -642,7 +668,7 @@ int TestAllReadCompareDicom(int argc, char *argv[]) std::string baseLineDir = GDCM_DATA_ROOT; baseLineDir += "/BaselineDicom"; - if( !gdcm::DirList::IsDirectory(baseLineDir) ) + if( !GDCM_NAME_SPACE::DirList::IsDirectory(baseLineDir) ) { std::cerr << " The reference baseline directory " << std::endl << " " @@ -652,6 +678,11 @@ int TestAllReadCompareDicom(int argc, char *argv[]) return 1; } +//if (gdcmDataImages[i] == "D_CLUNIE_CT2_RLE.dcm") +// gdcm::Debug::DebugOn(); // track pb on BigEndian Proc +//else + GDCM_NAME_SPACE::Debug::DebugOff(); + ////// Step 1 (see above description): std::string filename = GDCM_DATA_ROOT; filename += "/";