1 /*=========================================================================
4 Module: $RCSfile: WriteRead.cxx,v $
6 Date: $Date: 2007/05/23 14:18:05 $
7 Version: $Revision: 1.16 $
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;
27 GDCM_NAME_SPACE::File *e1;
28 GDCM_NAME_SPACE::File *e2;
29 GDCM_NAME_SPACE::FileHelper *f1;
30 GDCM_NAME_SPACE::FileHelper *f2;
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;
45 e1 = GDCM_NAME_SPACE::File::New( );
46 e1->SetFileName( fileName );
48 if (!e1->IsReadable())
50 std::cerr << "Sorry, " << fileName <<" not a Readable DICOM / ACR File"
56 f1 = GDCM_NAME_SPACE::FileHelper::New(e1);
57 imageData= f1->GetImageData();
58 dataSize = f1->GetImageDataSize();
60 // --------------------- we write it as an Explicit VR DICOM file
62 fileNameToWrite = "temp.XDCM";
63 std::cout << "WriteDCM Explicit VR" << std::endl;
64 f1->WriteDcmExplVR(fileNameToWrite);
66 // --------------------- we read the written image
67 e2 = GDCM_NAME_SPACE::File::New( );
68 e2->SetFileName( fileNameToWrite );
70 if (!e2->IsReadable())
72 std::cerr << "Sorry, " << fileNameToWrite << " not a Readable DICOM / ACR File"
79 f2 = GDCM_NAME_SPACE::FileHelper::New(e2);
80 imageData2= f2->GetImageData();
81 dataSize2 = f2->GetImageDataSize();
83 // --------------------- we compare the pixel areas
85 if (dataSize != dataSize2)
87 std::cout << " ----------------------------------------- "
88 << "Bad shot! Lengthes are different : "
89 << dataSize << " # " << dataSize2
90 << " for file : " << fileName << std::endl;
98 if (int res=memcmp(imageData,imageData2,dataSize) !=0)
100 std::cout << " ----------------------------------------- "
101 << "Bad shot! Pixels are different : "
102 << " for file : " << fileName << std::endl;
103 std::cout << "memcmp(imageData,imageData2,dataSize) = " << res << std::endl;