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