1 /*=========================================================================
4 Module: $RCSfile: TestAllReadCompareDicom.cxx,v $
6 Date: $Date: 2004/11/24 16:39:18 $
7 Version: $Revision: 1.18 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
18 #include "gdcmHeader.h"
23 #include "gdcmDataImages.h"
25 int InternalTest(std::string const & filename,
26 std::string const & referenceFileName )
28 std::cout << " Testing: " << filename << std::endl;
32 gdcm::File* tested = new gdcm::File( filename );
33 if( !tested->GetHeader()->IsReadable() )
35 std::cout << " Failed" << std::endl
36 << " Image not gdcm compatible:"
37 << filename << std::endl;
43 ////// Check for existence of reference baseline dicom file:
46 FILE* testFILE = fopen( referenceFileName.c_str(), "r" );
49 uint8_t* testedImageData = tested->GetImageDataRaw(); // Kludge
50 (void)testedImageData;
52 tested->WriteDcmExplVR( referenceFileName );
60 ////// When reference file is not gdcm readable test is failed:
63 gdcm::File* reference = new gdcm::File( referenceFileName );
64 if( !reference->GetHeader()->IsReadable() )
66 std::cout << " Failed" << std::endl
67 << " reference image "
69 << " is not gdcm compatible." << std::endl;
77 int testedDataSize = tested->GetImageDataSizeRaw();
78 uint8_t* testedImageData = tested->GetImageDataRaw();
80 int referenceDataSize = reference->GetImageDataSizeRaw();
81 uint8_t* referenceImageData = reference->GetImageDataRaw();
83 if (testedDataSize != referenceDataSize)
85 std::cout << " Failed" << std::endl
86 << " pixel areas lengths differ: "
87 << testedDataSize << " # " << referenceDataSize
94 if (int res = memcmp(testedImageData, referenceImageData,
95 testedDataSize) != 0 )
98 std::cout << " Failed" << std::endl
99 << " pixel differ (as expanded in memory)."
106 //////////////// Clean up:
110 std::cout << "OK." << std::endl;
115 int TestAllReadCompareDicom(int argc, char* argv[])
119 // The test is specified a specific filename, use it instead of looping
121 const std::string input = argv[1];
122 const std::string reference = argv[2];
123 return InternalTest( input, reference );
125 else if ( argc > 3 || argc == 2 )
127 std::cerr << " Usage: " << argv[0]
128 << " (no arguments needed)." << std::endl;
129 std::cerr << "or Usage: " << argv[0]
130 << " filename.dcm reference.dcm" << std::endl;
135 std::cout << " Description (Test::TestAllReadCompareDicom): "
137 std::cout << " For all images in gdcmData (and not blacklisted in "
138 "Test/CMakeLists.txt)"
140 std::cout << " apply the following to each filename.xxx: "
142 std::cout << " step 1: parse the image (as gdcmHeader) and call"
145 std::cout << " step 2: find in GDCM_DATA_ROOT/BaselineDicom/filename.dcm"
147 << " (with format DICOM V3, explicit Value"
150 std::cout << " step 3a: when image NOT found on step 2, write "
152 << " GDCM_DATA_ROOT/BaselineDicom/filename.dcm"
154 << " (with format DICOM V3, explicit Value"
157 std::cout << " step 3b: when image found on step 2, and when IsReadable()"
159 << " compare it (in memory with memcmp) with the"
161 << " image we are testing (the one of step 1). "
162 << std::endl << std::endl;
166 while( gdcmDataImages[i] != 0 )
168 ////// Check for existence of reference baseline directory
170 std::string baseLineDir = GDCM_DATA_ROOT;
171 baseLineDir += "/BaselineDicom/";
173 std::ifstream* testDIR = new std::ifstream(baseLineDir.c_str(), std::ios::in | std::ios::binary);
176 std::cerr << " The reference baseline directory " << std::endl
178 << baseLineDir << std::endl
179 << " couldn't be opened."
188 ////// Step 1 (see above description):
189 std::string filename = GDCM_DATA_ROOT;
191 filename += gdcmDataImages[i];
193 std::string referenceFileName = baseLineDir + gdcmDataImages[i++];
194 std::string::size_type slash_pos = referenceFileName.rfind( "." );
195 if ( slash_pos != std::string::npos )
197 referenceFileName.replace( slash_pos + 1, 3, "dcm" );
200 if( InternalTest( filename, referenceFileName ) != 0 )