]> Creatis software - gdcm.git/blob - Example/exPrintWritePrint.cxx
" This program allows to see at a glance"
[gdcm.git] / Example / exPrintWritePrint.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: exPrintWritePrint.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/05/03 11:06:22 $
7   Version:   $Revision: 1.1 $
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 "gdcmFile.h"
19 #include "gdcmFileHelper.h"
20 #include "gdcmValEntry.h"
21 #include "gdcmBinEntry.h"
22
23
24 int main(int argc, char *argv[])
25 {  
26    gdcm::File *e1;
27    gdcm::FileHelper *f1;
28    std::string fileNameToWrite;
29    void *imageData;
30    int dataSize;
31
32    std::cout << " This program allows to see at a glance" << std::endl;
33    std::cout << " if the gdcm::File remains unimpaired"   << std::endl;
34    std::cout << " after a Write"                          << std::endl;
35    std::cout << " In a future step, we could move it to"  << std::endl;
36    std::cout << " gdcm Testing, for a systematic checking"<< std::endl;
37    std::cout << " of  the entire dataset"                 << std::endl;
38    std::cout << " Later ..."                              << std::endl;
39
40
41    if (argc < 3) {
42          std::cerr << "usage: " << std::endl 
43                    << argv[0] << " OriginalFileName writtingMode "
44                    << std::endl 
45                    << " a : ACR, produces a file named OriginalFileName.ACR"
46                    << " x : DICOM Explicit VR, produces a file named OriginalFileName.XDCM"
47                    << " d : DICOM Implicit VR, produces a file named OriginalFileName.DCM"
48                    << "                  WARNING : bugggggggg on shadow SQ with endianness change !"
49                    << " r : RAW, produces a file named OriginalFileName.RAW"
50                    << std::endl;
51          return 0;
52    }
53
54    std::cout << std::endl
55              << "--------------------- file :" << argv[1] 
56              << std::endl;
57      
58    std::string fileName = argv[1]; 
59    std::string mode = argv[2];
60
61    e1 = new gdcm::File( );
62    e1->SetLoadMode( NO_SEQ );
63    e1->Load(  fileName.c_str() );
64
65    if (!e1->IsReadable())
66    {
67        std::cerr << "Sorry, not a Readable DICOM / ACR File"  <<std::endl;
68        return 0;
69    }
70    
71    f1 = new gdcm::FileHelper(e1);
72   // ---     
73
74    e1->Print();
75
76    imageData= f1->GetImageData();
77    dataSize = f1->GetImageDataSize();
78
79    f1->SetWriteModeToRGB();
80
81    switch (mode[0])
82    {
83    case 'a' :
84             // ecriture d'un fichier ACR 
85             // à partir d'un dcmFile correct.
86
87       fileNameToWrite = fileName + ".ACR";
88       std::cout << "WriteACR" << std::endl;
89       f1->WriteAcr(fileNameToWrite);
90       break;
91
92    case 'd' : 
93
94            // ecriture d'un fichier DICOM Implicit VR 
95            // à partir d'un dcmFile correct.
96
97       fileNameToWrite = fileName + ".DCM";
98       std::cout << "WriteDCM Implicit VR" << std::endl;
99       f1->WriteDcmImplVR(fileNameToWrite);
100       break;
101
102    case 'x' :
103               // ecriture d'un fichier DICOM Explicit VR 
104               // à partir d'un dcmFile correct.
105
106       fileNameToWrite = fileName + ".XDCM";
107       std::cout << "WriteDCM Explicit VR" << std::endl;
108       f1->WriteDcmExplVR(fileNameToWrite);
109       break;
110
111    case 'r' :
112              //  Ecriture d'un Raw File, a afficher avec 
113              // affim filein= dimx= dimy= nbit= signe=
114
115       fileNameToWrite = fileName + ".RAW";
116       std::cout << "WriteRaw" << std::endl;
117       f1->WriteRawData(fileNameToWrite);
118       break;
119    }
120
121    std::cout << "-----------------------------------------------------------------" 
122           << std::endl;
123    e1->Print();
124    delete e1;
125    delete f1;
126    return 0;
127 }
128