1 /*=========================================================================
4 Module: $RCSfile: TestAllReadCompareDicom.cxx,v $
6 Date: $Date: 2005/02/03 10:00:06 $
7 Version: $Revision: 1.30 $
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 "gdcmDirList.h"
20 #include "gdcmFileHelper.h"
26 #include "gdcmDataImages.h"
28 int InternalTest(std::string const &filename,
29 std::string const &referenceFileName )
31 std::cout << " Testing: " << filename << std::endl;
35 gdcm::FileHelper *tested = new gdcm::FileHelper( filename );
36 if( !tested->GetFile()->IsReadable() )
38 std::cout << " Failed" << std::endl
39 << " Image not gdcm compatible:"
40 << filename << std::endl;
46 ////// Check for existence of reference baseline dicom file:
49 std::ifstream testFILE( referenceFileName.c_str() );
52 uint8_t *testedImageData = tested->GetImageData(); // Kludge
53 (void)testedImageData;
55 tested->SetWriteModeToRGB();
56 tested->WriteDcmExplVR( referenceFileName );
61 ////// When reference file is not gdcm readable test is failed:
64 gdcm::FileHelper *reference = new gdcm::FileHelper( referenceFileName );
65 if( !reference->GetFile()->IsReadable() )
67 std::cout << " Failed" << std::endl
68 << " reference image "
70 << " is not gdcm compatible." << std::endl;
76 std::string PixelType = reference->GetFile()->GetPixelType();
80 int testedDataSize = tested->GetImageDataSize();
81 uint8_t *testedImageData = tested->GetImageData();
83 int referenceDataSize = reference->GetImageDataSize();
84 uint8_t *referenceImageData = reference->GetImageData();
86 // Test the image size
87 if (tested->GetFile()->GetXSize() != reference->GetFile()->GetXSize() ||
88 tested->GetFile()->GetYSize() != reference->GetFile()->GetYSize() ||
89 tested->GetFile()->GetZSize() != reference->GetFile()->GetZSize())
91 std::cout << "Failed" << std::endl
93 << "X: " << tested->GetFile()->GetXSize() << " # "
94 << reference->GetFile()->GetXSize() << " | "
95 << "Y: " << tested->GetFile()->GetYSize() << " # "
96 << reference->GetFile()->GetYSize() << " | "
97 << "Z: " << tested->GetFile()->GetZSize() << " # "
98 << reference->GetFile()->GetZSize() << std::endl;
104 // Test the data size
105 if (testedDataSize != referenceDataSize)
107 std::cout << " Failed" << std::endl
110 <<") areas lengths differ: "
111 << testedDataSize << " # " << referenceDataSize
118 // Test the data content
119 if (int res = memcmp(testedImageData, referenceImageData,
120 testedDataSize) != 0 )
123 std::cout << " Failed" << std::endl
126 << ") differ (as expanded in memory)."
133 //////////////// Clean up:
137 std::cout << "OK." << std::endl;
142 int TestAllReadCompareDicom(int argc, char *argv[])
146 // The test is specified a specific filename, use it instead of looping
148 const std::string input = argv[1];
149 const std::string reference = argv[2];
150 return InternalTest( input, reference );
152 else if ( argc > 3 || argc == 2 )
154 std::cerr << " Usage: " << argv[0]
155 << " (no arguments needed)." << std::endl;
156 std::cerr << "or Usage: " << argv[0]
157 << " filename.dcm reference.dcm" << std::endl;
162 std::cout << " Description (Test::TestAllReadCompareDicom): "
164 std::cout << " For all images in gdcmData (and not blacklisted in "
165 "Test/CMakeLists.txt)"
167 std::cout << " apply the following to each filename.xxx: "
169 std::cout << " step 1: parse the image (as gdcmFile) and call"
172 std::cout << " step 2: find in GDCM_DATA_ROOT/BaselineDicom/filename.dcm"
174 << " (with format DICOM V3, explicit Value"
177 std::cout << " step 3a: when image NOT found on step 2, write "
179 << " GDCM_DATA_ROOT/BaselineDicom/filename.dcm"
181 << " (with format DICOM V3, explicit Value"
184 std::cout << " step 3b: when image found on step 2, and when IsReadable()"
186 << " compare it (in memory with memcmp) with the"
188 << " image we are testing (the one of step 1). "
189 << std::endl << std::endl;
193 while( gdcmDataImages[i] != 0 )
195 ////// Check for existence of reference baseline directory
197 std::string baseLineDir = GDCM_DATA_ROOT;
198 baseLineDir += "/BaselineDicom/";
200 if( !gdcm::DirList::IsDirectory(baseLineDir) )
202 std::cerr << " The reference baseline directory " << std::endl
204 << baseLineDir << std::endl
205 << " couldn't be opened."
210 ////// Step 1 (see above description):
211 std::string filename = GDCM_DATA_ROOT;
213 filename += gdcmDataImages[i];
215 std::string referenceFileName = baseLineDir + gdcmDataImages[i++];
216 std::string::size_type slash_pos = referenceFileName.rfind( "." );
217 if( slash_pos != std::string::npos )
219 referenceFileName.replace( slash_pos + 1, 3, "dcm" );
222 if( InternalTest( filename, referenceFileName ) != 0 )