1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
/*=========================================================================
Program: GDCM (Grassroots DICOM). A DICOM library
Copyright (c) 2006-2011 Mathieu Malaterre
All rights reserved.
See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/*
* WARNING: This is a dev tool, do not use !
*
* Usage: after a gdcmconv, you would like to know if the conversion process is acceptable
* sometime a vbindiff is acceptable, sometime it is not. In the case of the famous Philips
* Little/Big Endian Explicit Transfer Syntax it is not easy to compare two files. However
* this only impact byte ordering, thus we can compute byte-indenpendant information to still
* compare the files.
*/
#include "gdcmImageReader.h"
#include "gdcmImage.h"
#include "gdcmWriter.h"
#include "gdcmAttribute.h"
#include "gdcmSystem.h"
#include <iostream>
#include <fstream>
int main(int argc, char *argv[])
{
if( argc < 3 )
{
std::cerr << argv[0] << " input1.dcm input2.dcm" << std::endl;
return 1;
}
const char *filename1 = argv[1];
const char *filename2 = argv[2];
gdcm::ImageReader reader1;
reader1.SetFileName( filename1 );
if( !reader1.Read() )
{
std::cerr << "Could not read: " << filename1 << std::endl;
return 1;
}
gdcm::ImageReader reader2;
reader2.SetFileName( filename2 );
if( !reader2.Read() )
{
std::cerr << "Could not read: " << filename2 << std::endl;
return 1;
}
// TODO: need a DataSet== operator implementation
std::cout << "Both files can be read and looks like DICOM" << std::endl;
size_t s1 = gdcm::System::FileSize(filename1);
size_t s2 = gdcm::System::FileSize(filename2);
if( s1 != s2 )
{
std::cout << "Size mismatch: " << s1 << " != " << s2 << std::endl;
return 1;
}
else
{
std::cout << "Size match: " << s1 << " = " << s2 << std::endl;
}
std::ifstream is1( filename1, std::ios::binary );
char *buffer1 = new char[s1];
is1.read(buffer1, s1);
std::ifstream is2( filename2, std::ios::binary );
char *buffer2 = new char[s2];
is2.read(buffer2, s2);
assert( s1 == s2 );
if( memcmp(buffer1, buffer2, s1 ) == 0 )
{
std::cout << "memcmp succeed ! File are bit identical" << std::endl;
}
else
{
std::cout << "memcmp failed!" << std::endl;
}
// Hum...memcmp failed, for big endian/ little endian inversion the histogram of bytes
// should still be the same. So let's compute it
// buffer2[0] = 1; // let's make the test fail
std::multiset<char> set1( buffer1, buffer1 + s1 );
std::multiset<char> set2( buffer2, buffer2 + s2 );
if( set1 == set2 )
{
std::cout << "set1 == set2. Byte histogram seems valid" << std::endl;
}
else
{
std::cout << "set1 != set2" << std::endl;
}
delete[] buffer1;
delete[] buffer2;
return 0;
}
|