]> Creatis software - gdcm.git/blob - Example/exPrintWritePrint.cxx
26e7ef528aa269adcedc07143a7020008d3f0915
[gdcm.git] / Example / exPrintWritePrint.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: exPrintWritePrint.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/07/08 12:02:02 $
7   Version:   $Revision: 1.2 $
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 *f;
27    gdcm::FileHelper *fh;
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    f = new gdcm::File( );
62    f->SetLoadMode( NO_SEQ );
63    f->SetFileName( fileName );
64    f->Load( );
65
66    if (!f->IsReadable())
67    {
68        std::cerr << "Sorry, not a Readable DICOM / ACR File"  <<std::endl;
69        return 0;
70    }
71    
72    fh = new gdcm::FileHelper(f);
73   // ---     
74
75    f->Print();
76
77    imageData= fh->GetImageData();
78    dataSize = fh->GetImageDataSize();
79
80    fh->SetWriteModeToRGB();
81
82    switch (mode[0])
83    {
84    case 'a' :
85             // ecriture d'un fichier ACR 
86             // à partir d'un dcmFile correct.
87
88       fileNameToWrite = fileName + ".ACR";
89       std::cout << "WriteACR" << std::endl;
90       fh->WriteAcr(fileNameToWrite);
91       break;
92
93    case 'd' : 
94
95            // ecriture d'un fichier DICOM Implicit VR 
96            // à partir d'un dcmFile correct.
97
98       fileNameToWrite = fileName + ".DCM";
99       std::cout << "WriteDCM Implicit VR" << std::endl;
100       fh->WriteDcmImplVR(fileNameToWrite);
101       break;
102
103    case 'x' :
104               // ecriture d'un fichier DICOM Explicit VR 
105               // à partir d'un dcmFile correct.
106
107       fileNameToWrite = fileName + ".XDCM";
108       std::cout << "WriteDCM Explicit VR" << std::endl;
109       fh->WriteDcmExplVR(fileNameToWrite);
110       break;
111
112    case 'r' :
113              //  Ecriture d'un Raw File, a afficher avec 
114              // affim filein= dimx= dimy= nbit= signe=
115
116       fileNameToWrite = fileName + ".RAW";
117       std::cout << "WriteRaw" << std::endl;
118       fh->WriteRawData(fileNameToWrite);
119       break;
120    }
121
122    std::cout << "-----------------------------------------------------------------" 
123           << std::endl;
124    f->Print();
125    delete f;
126    delete fh;
127    return 0;
128 }
129