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."
68 ////// Step 1 (see above description):
70 std::string filename = GDCM_DATA_ROOT;
72 filename += gdcmDataImages[i];
74 std::cout << " Testing: " << filename << std::endl;
76 gdcmFile* tested = new gdcmFile( filename, false, true );
77 if( !tested->GetHeader()->IsReadable() )
79 std::cout << " Image not gdcm compatible:"
80 << filename << std::endl;
87 ////// Check for existence of reference baseline dicom file:
89 std::string referenceFileName = baseLineDir + gdcmDataImages[i++];
90 std::string::size_type slash_pos = referenceFileName.rfind( "." );
91 if ( slash_pos != std::string::npos )
93 referenceFileName.replace( slash_pos + 1, 3, "dcm" );
96 testFILE = fopen( referenceFileName.c_str(), "r" );
101 int testedDataSize = tested->GetImageDataSize();
102 (void)testedDataSize;
103 void* testedImageData = tested->GetImageData(); // Kludge
104 tested->WriteDcmExplVR( referenceFileName );
105 std::cerr << " Creating reference baseline file :" << std::endl
106 << " " << referenceFileName
109 delete (char*)testedImageData;
117 ////// When reference file is not gdcm readable test is failed:
119 gdcmFile* reference = new gdcmFile( referenceFileName.c_str(),
121 if( !reference->GetHeader()->IsReadable() )
123 std::cout << " Reference image " << std::endl
124 << " " << referenceFileName <<std::endl
125 << " is not gdcm compatible." << std::endl;
133 int testedDataSize = tested->GetImageDataSize();
134 void* testedImageData = tested->GetImageData();
136 int referenceDataSize = reference->GetImageDataSize();
137 void* referenceImageData = reference->GetImageData();
139 if (testedDataSize != referenceDataSize)
141 std::cout << " Pixel areas lengths differ: "
142 << testedDataSize << " # " << referenceDataSize
146 delete (char*)testedImageData;
147 delete (char*)referenceImageData;
151 if (int res = memcmp(testedImageData, referenceImageData,
152 testedDataSize) != 0 )
155 std::cout << " Pixel differ (as expanded in memory)."
159 delete (char*)testedImageData;
160 delete (char*)referenceImageData;
163 std::cout << " Passed." << std::endl ;
165 //////////////// Clean up:
168 delete (char*)testedImageData;
169 delete (char*)referenceImageData;