1 /*=========================================================================
4 Module: $RCSfile: WriteRead.cxx,v $
6 Date: $Date: 2005/02/02 10:06:32 $
7 Version: $Revision: 1.13 $
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"
23 int main(int argc, char *argv[])
25 std::string fileNameToWrite;
31 uint8_t* imageData, *imageData2;
32 int dataSize, dataSize2;
36 std::cerr << "Usage " << argv[0] << " image.dcm" << std::endl;
40 std::string fileName = argv[1];
42 // --------------------- we read the input image
44 std::cout << argv[1] << std::endl;
46 e1 = new gdcm::File( fileName );
47 if (!e1->IsReadable()) {
48 std::cerr << "Sorry, " << fileName <<" not a Readable DICOM / ACR File"
53 f1 = new gdcm::FileHelper(e1);
54 imageData= f1->GetImageData();
55 dataSize = f1->GetImageDataSize();
57 // --------------------- we write it as an Explicit VR DICOM file
59 fileNameToWrite = "temp.XDCM";
60 std::cout << "WriteDCM Explicit VR" << std::endl;
61 f1->WriteDcmExplVR(fileNameToWrite);
63 // --------------------- we read the written image
65 e2 = new gdcm::File( fileNameToWrite );
66 if (!e2->IsReadable()) {
67 std::cerr << "Sorry, " << fileNameToWrite << " not a Readable DICOM / ACR File"
71 f2 = new gdcm::FileHelper(e2);
72 imageData2= f2->GetImageData();
73 dataSize2 = f2->GetImageDataSize();
75 // --------------------- we compare the pixel areas
77 if (dataSize != dataSize2) {
78 std::cout << " ----------------------------------------- "
79 << "Bad shot! Lengthes are different : "
80 << dataSize << " # " << dataSize2
81 << " for file : " << fileName << std::endl;
85 if (int res=memcmp(imageData,imageData2,dataSize) !=0) {
86 std::cout << " ----------------------------------------- "
87 << "Bad shot! Pixels are different : "
88 << " for file : " << fileName << std::endl;
89 std::cout << "memcmp(imageData,imageData2,dataSize) = " << res << std::endl;
93 //If we reach here everything is fine, return 0 then: