1 /*=========================================================================
4 Module: $RCSfile: TestAllReadCompareDicom.cxx,v $
6 Date: $Date: 2005/01/31 03:36:59 $
7 Version: $Revision: 1.26 $
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 =========================================================================*/
19 #include "gdcmFileHelper.h"
25 #include "gdcmDataImages.h"
27 int InternalTest(std::string const & filename,
28 std::string const & referenceFileName )
30 std::cout << " Testing: " << filename << std::endl;
34 gdcm::FileHelper* tested = new gdcm::FileHelper( filename );
35 if( !tested->GetFile()->IsReadable() )
37 std::cout << " Failed" << std::endl
38 << " Image not gdcm compatible:"
39 << filename << std::endl;
45 ////// Check for existence of reference baseline dicom file:
48 std::ifstream testFILE( referenceFileName.c_str() );
51 uint8_t* testedImageData = tested->GetImageData(); // Kludge
52 (void)testedImageData;
54 tested->SetWriteModeToRGB();
55 tested->WriteDcmExplVR( referenceFileName );
60 ////// When reference file is not gdcm readable test is failed:
63 gdcm::FileHelper* reference = new gdcm::FileHelper( referenceFileName );
64 if( !reference->GetFile()->IsReadable() )
66 std::cout << " Failed" << std::endl
67 << " reference image "
69 << " is not gdcm compatible." << std::endl;
75 std::string PixelType = reference->GetFile()->GetPixelType();
79 int testedDataSize = tested->GetImageDataSize();
80 uint8_t* testedImageData = tested->GetImageData();
82 int referenceDataSize = reference->GetImageDataSize();
83 uint8_t* referenceImageData = reference->GetImageData();
85 // Test the image size
86 if (tested->GetFile()->GetXSize() != reference->GetFile()->GetXSize() ||
87 tested->GetFile()->GetYSize() != reference->GetFile()->GetYSize() ||
88 tested->GetFile()->GetZSize() != reference->GetFile()->GetZSize())
90 std::cout << "Failed" << std::endl
92 << "X: " << tested->GetFile()->GetXSize() << " # "
93 << reference->GetFile()->GetXSize() << " | "
94 << "Y: " << tested->GetFile()->GetYSize() << " # "
95 << reference->GetFile()->GetYSize() << " | "
96 << "Z: " << tested->GetFile()->GetZSize() << " # "
97 << reference->GetFile()->GetZSize() << std::endl;
103 // Test the data size
104 if (testedDataSize != referenceDataSize)
106 std::cout << " Failed" << std::endl
109 <<") areas lengths differ: "
110 << testedDataSize << " # " << referenceDataSize
117 // Test the data content
118 if (int res = memcmp(testedImageData, referenceImageData,
119 testedDataSize) != 0 )
122 std::cout << " Failed" << std::endl
125 << ") differ (as expanded in memory)."
132 //////////////// Clean up:
136 std::cout << "OK." << std::endl;
141 int TestAllReadCompareDicom(int argc, char* argv[])
145 // The test is specified a specific filename, use it instead of looping
147 const std::string input = argv[1];
148 const std::string reference = argv[2];
149 return InternalTest( input, reference );
151 else if ( argc > 3 || argc == 2 )
153 std::cerr << " Usage: " << argv[0]
154 << " (no arguments needed)." << std::endl;
155 std::cerr << "or Usage: " << argv[0]
156 << " filename.dcm reference.dcm" << std::endl;
161 std::cout << " Description (Test::TestAllReadCompareDicom): "
163 std::cout << " For all images in gdcmData (and not blacklisted in "
164 "Test/CMakeLists.txt)"
166 std::cout << " apply the following to each filename.xxx: "
168 std::cout << " step 1: parse the image (as gdcmFile) and call"
171 std::cout << " step 2: find in GDCM_DATA_ROOT/BaselineDicom/filename.dcm"
173 << " (with format DICOM V3, explicit Value"
176 std::cout << " step 3a: when image NOT found on step 2, write "
178 << " GDCM_DATA_ROOT/BaselineDicom/filename.dcm"
180 << " (with format DICOM V3, explicit Value"
183 std::cout << " step 3b: when image found on step 2, and when IsReadable()"
185 << " compare it (in memory with memcmp) with the"
187 << " image we are testing (the one of step 1). "
188 << std::endl << std::endl;
192 while( gdcmDataImages[i] != 0 )
194 ////// Check for existence of reference baseline directory
196 std::string baseLineDir = GDCM_DATA_ROOT;
197 baseLineDir += "/BaselineDicom/";
199 std::ifstream testDIR(baseLineDir.c_str(), std::ios::in | std::ios::binary);
202 std::cerr << " The reference baseline directory " << std::endl
204 << baseLineDir << std::endl
205 << " couldn't be opened."
211 ////// Step 1 (see above description):
212 std::string filename = GDCM_DATA_ROOT;
214 filename += gdcmDataImages[i];
216 std::string referenceFileName = baseLineDir + gdcmDataImages[i++];
217 std::string::size_type slash_pos = referenceFileName.rfind( "." );
218 if ( slash_pos != std::string::npos )
220 referenceFileName.replace( slash_pos + 1, 3, "dcm" );
223 if( InternalTest( filename, referenceFileName ) != 0 )