1 #include "gdcmHeader.h"
5 #include "gdcmDataImages.h"
7 int TestAllReadCompareDicom(int argc, char* argv[])
11 std::cerr << " Usage: " << argv[0]
12 << " (no arguments needed)." << std::endl;
16 std::cout << " Description (Test::TestAllReadCompareDicom): "
18 std::cout << " For all images in gdcmData (and not blacklisted in "
19 "Test/CMakeLists.txt)"
21 std::cout << " apply the following to each filename.xxx: "
23 std::cout << " step 1: parse the image (as gdcmHeader) and call"
26 std::cout << " step 2: find in GDCM_DATA_ROOT/BaselineDicom/filename.dcm"
28 << " (with format DICOM V3, explicit Value"
31 std::cout << " step 3a: when image NOT found on step 2, write "
33 << " GDCM_DATA_ROOT/BaselineDicom/filename.dcm"
35 << " (with format DICOM V3, explicit Value"
38 std::cout << " step 3b: when image found on step 2, and when IsReadable()"
40 << " compare it (in memory with memcmp) with the"
42 << " image we are testing (the one of step 1). "
43 << std::endl << std::endl;
46 while( gdcmDataImages[i] != 0 )
48 ////// Check for existence of reference baseline directory
50 std::string baseLineDir = GDCM_DATA_ROOT;
51 baseLineDir += "/BaselineDicom/";
53 FILE* testFILE = fopen( baseLineDir.c_str(), "r" );
56 std::cerr << " The reference baseline directory " << std::endl
58 << baseLineDir << std::endl
59 << " couldn't be opened."
66 ////// Step 1 (see above description):
68 std::string filename = GDCM_DATA_ROOT;
69 filename += "/"; //doh!
70 filename += gdcmDataImages[i];
72 std::cout << " Testing: " << filename << std::endl;
74 gdcmFile* tested = new gdcmFile( filename.c_str(), false, true );
75 if( !tested->GetHeader()->IsReadable() )
77 std::cout << " Image not gdcm compatible:"
78 << filename << std::endl;
85 ////// Check for existence of reference baseline dicom file:
87 std::string referenceFileName = baseLineDir + gdcmDataImages[i++];
88 std::string::size_type slash_pos = referenceFileName.rfind( "." );
89 if ( slash_pos != std::string::npos )
91 referenceFileName.replace( slash_pos + 1, 3, "dcm" );
94 testFILE = fopen( referenceFileName.c_str(), "r" );
99 int testedDataSize = tested->GetImageDataSize();
100 void* testedImageData = tested->GetImageData(); // Kludge
101 tested->WriteDcmExplVR( referenceFileName );
102 std::cerr << " Creating reference baseline file :" << std::endl
103 << " " << referenceFileName
106 delete (char*)testedImageData;
112 ////// When reference file is not gdcm readable test is failed:
114 gdcmFile* reference = new gdcmFile( referenceFileName.c_str(),
116 if( !reference->GetHeader()->IsReadable() )
118 std::cout << " Reference image " << std::endl
119 << " " << referenceFileName <<std::endl
120 << " is not gdcm compatible." << std::endl;
128 int testedDataSize = tested->GetImageDataSize();
129 void* testedImageData = tested->GetImageData();
131 int referenceDataSize = reference->GetImageDataSize();
132 void* referenceImageData = reference->GetImageData();
134 if (testedDataSize != referenceDataSize)
136 std::cout << " Pixel areas lengths differ: "
137 << testedDataSize << " # " << referenceDataSize
141 delete (char*)testedImageData;
142 delete (char*)referenceImageData;
146 if (int res = memcmp(testedImageData, referenceImageData,
147 testedDataSize) != 0 )
149 std::cout << " Pixel differ (as expanded in memory)."
153 delete (char*)testedImageData;
154 delete (char*)referenceImageData;
157 std::cout << " Passed." << std::endl ;
159 //////////////// Clean up:
162 delete (char*)testedImageData;
163 delete (char*)referenceImageData;