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