]> Creatis software - gdcm.git/blob - Example/Write.cxx
Name normalization
[gdcm.git] / Example / Write.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: Write.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/02/02 10:06:32 $
7   Version:   $Revision: 1.19 $
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 #include <iostream>
22
23 int main(int argc, char *argv[])
24 {  
25    std::string FileNameToWrite;
26
27    gdcm::File *e1;
28    gdcm::FileHelper *f1;
29
30    uint8_t *imageData;
31    int dataSize;
32
33    if (argc < 3) {
34          std::cerr << "usage: " << std::endl 
35                    << argv[0] << " fileName writtingMode "
36                 << std::endl 
37                    << "(a : ACR, d : DICOM Implicit VR,"
38                    << " x : DICOM Explicit VR,  r : RAW)"
39                 << std::endl;
40          return 0;
41    }
42 /*
43    if (0) {  // Just to keep the code for further use
44       std::cout <<std::endl << "-------- Test gdcmFile ------" <<std::endl;
45       e1 = new gdcmFileHelper(argv[1]);
46       if (!f1->GetFile()->IsReadable()) {
47          std::cout << "Sorry, not a DICOM / ACR File"  <<std::endl;
48          exit(0);
49       }
50       std::cout << std::endl << "----------------------> after new gdcmFile"
51                 << std::endl;
52       e1->PrintEntry();
53       std::cout <<std::endl <<"---------------------------------------" 
54                 <<std::endl;
55    }
56 */
57
58    std::cout << std::endl
59              << "--------------------- file :" << argv[1] 
60              << std::endl;
61      
62    std::string FileName = argv[1]; 
63
64    e1 = new gdcm::File( FileName.c_str() );
65    if (!e1->IsReadable()) {
66        std::cerr << "Sorry, not a Readable DICOM / ACR File"  <<std::endl;
67        return 0;
68    }
69   // e1->Print(); 
70    
71    f1 = new gdcm::FileHelper(e1);
72 // ---     
73
74    dataSize = f1->GetImageDataSize();
75    std::cout <<std::endl <<" dataSize " << dataSize << std::endl;
76    int nX,nY,nZ,sPP,planarConfig;
77    std::string pixelType, transferSyntaxName;
78    nX=e1->GetXSize();
79    nY=e1->GetYSize();
80    nZ=e1->GetZSize();
81    std::cout << " DIMX=" << nX << " DIMY=" << nY << " DIMZ=" << nZ << std::endl;
82
83    pixelType    = e1->GetPixelType();
84    sPP          = e1->GetSamplesPerPixel();
85    planarConfig = e1->GetPlanarConfiguration();
86    
87    std::cout << " pixelType="           << pixelType
88              << " SampleserPixel="      << sPP
89              << " PlanarConfiguration=" << planarConfig 
90              << " PhotometricInterpretation=" 
91                                 << e1->GetEntryValue(0x0028,0x0004) 
92              << std::endl;
93
94    int numberOfScalarComponents=e1->GetNumberOfScalarComponents();
95    std::cout << "NumberOfScalarComponents " << numberOfScalarComponents <<std::endl;
96    transferSyntaxName = e1->GetTransferSyntaxName();
97    std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl;
98    
99 /*   if (  transferSyntaxName != "Implicit VR - Little Endian"
100       && transferSyntaxName != "Explicit VR - Little Endian"     
101       && transferSyntaxName != "Deflated Explicit VR - Little Endian"      
102       && transferSyntaxName != "Explicit VR - Big Endian"
103       && transferSyntaxName != "Uncompressed ACR-NEMA"     ) {
104       std::cout << std::endl << "==========================================="
105                 << std::endl; 
106       f1->GetPixelReadConverter()->Print();
107       std::cout << std::endl << "==========================================="
108                 << std::endl; 
109    }*/
110    imageData= f1->GetImageData();
111    (void)imageData;  // to avoid warnings
112
113    switch (argv[2][0])
114    {
115    case 'a' :
116             // ecriture d'un fichier ACR 
117             // à partir d'un dcmFile correct.
118
119       FileNameToWrite = FileName + ".ACR";
120       std::cout << "WriteACR" << std::endl;
121       f1->WriteAcr(FileNameToWrite);
122       break;
123
124    case 'd' :
125            // ecriture d'un fichier DICOM Implicit VR 
126            // à partir d'un dcmFile correct.
127
128       FileNameToWrite = FileName + ".DCM";
129       std::cout << "WriteDCM Implicit VR" << std::endl;
130       f1->WriteDcmImplVR(FileNameToWrite);
131       break;
132
133    case 'x' :
134               // ecriture d'un fichier DICOM Explicit VR 
135               // à partir d'un dcmFile correct.
136
137       FileNameToWrite = FileName + ".DCM";
138       std::cout << "WriteDCM Implicit VR" << std::endl;
139       f1->WriteDcmExplVR(FileNameToWrite);
140       break;
141
142    case 'r' :
143              //  Ecriture d'un Raw File, a afficher avec 
144              // affim filein= dimx= dimy= nbit= signe=
145
146       FileNameToWrite = FileName + ".RAW";
147       std::cout << "WriteRaw" << std::endl;
148       f1->WriteRawData(FileNameToWrite);
149       break;
150
151    }
152   return 0;
153 }
154