]> Creatis software - gdcm.git/blob - Example/WriteRead.cxx
First stage of name normalisation : gdcm::File replace by gdcm::FileHelper
[gdcm.git] / Example / WriteRead.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: WriteRead.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/20 16:16:58 $
7   Version:   $Revision: 1.10 $
8                                                                                 
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.
12                                                                                 
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.
16                                                                                 
17 =========================================================================*/
18 #include "gdcmHeader.h"
19 #include "gdcmFile.h"
20
21 #include <iostream>
22
23 int main(int argc, char* argv[])
24 {  
25    std::string zozo;
26
27    gdcm::Header* e1, *e2;
28    gdcm::FileHelper  * f1, *f2;
29
30    uint8_t* imageData, *imageData2;
31    int dataSize, dataSize2;
32      
33    if( argc < 2 )
34     {
35     std::cerr << "Usage " << argv[0] << " image.dcm" << std::endl;
36     return 1;
37     }
38
39    std::string toto = argv[1];
40
41 // --------------------- we read the input image
42
43    std::cout << argv[1] << std::endl;
44
45    e1 = new gdcm::Header( toto );
46    if (!e1->IsReadable()) {
47        std::cerr << "Sorry, " << toto <<"  not a Readable DICOM / ACR File"
48                  <<std::endl;
49        return 0;
50    }
51    
52    f1 = new gdcm::FileHelper(e1);
53    imageData= f1->GetImageData();
54    dataSize = f1->GetImageDataSize();
55
56 // --------------------- we write it as an Explicit VR DICOM file
57
58       zozo = "temp.XDCM";
59       std::cout << "WriteDCM Explicit VR" << std::endl;
60       f1->WriteDcmExplVR(zozo);
61
62 // --------------------- we read the written image
63       
64    e2 = new gdcm::Header( zozo );
65    if (!e2->IsReadable()) {
66        std::cerr << "Sorry, " << zozo << " not a Readable DICOM / ACR File"  
67                  <<std::endl;
68        return 0;
69    }
70    f2 = new gdcm::FileHelper(e2);
71    imageData2= f2->GetImageData();
72    dataSize2 = f2->GetImageDataSize();
73
74 // --------------------- we compare the pixel areas
75
76   if (dataSize != dataSize2) {
77      std::cout << " ----------------------------------------- " 
78           << "Bad shot! Lengthes are different : " 
79           << dataSize << " # " << dataSize2
80           << " for file : " << toto << std::endl;
81
82      return 0;
83   }
84   if (int res=memcmp(imageData,imageData2,dataSize) !=0) {
85      std::cout << " ----------------------------------------- " 
86           << "Bad shot! Pixels are different : " 
87           << " for file : " << toto << std::endl;
88      std::cout << "memcmp(imageData,imageData2,dataSize) = " << res << std::endl;
89      return 1;
90   }
91   
92   //If we reach here everything is fine, return 0 then:
93   return 0;
94 }
95