]> Creatis software - gdcm.git/blob - Example/Write.cxx
* FIX : now, the DocEntries are all deleted in the gdcmElementSet.
[gdcm.git] / Example / Write.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: Write.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/11/16 04:26:18 $
7   Version:   $Revision: 1.9 $
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 <iostream>
19 #include <stdio.h>
20 #include "gdcm.h"
21
22 int main(int argc, char* argv[])
23 {  
24    std::string toto;
25    char zozo[200];
26
27    gdcm::Header* e1;
28    gdcm::File  * 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    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::File(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->GetEntryByNumber(0x0028,0x0004) 
93              << std::endl;
94
95    int numberOfScalarComponents=e1->GetNumberOfScalarComponents();
96    std::cout << "NumberOfScalarComponents " << numberOfScalarComponents <<std::endl;
97    transferSyntaxName = e1->GetTransfertSyntaxName();
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->GetPixelConverter()->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    case 'a' :
116             // ecriture d'un fichier ACR 
117             // à partir d'un dcmHeader correct.
118
119       sprintf(zozo, "%s.ACR", toto.c_str());
120       printf ("WriteACR\n");
121       f1->WriteAcr(zozo);
122       break;
123
124    case 'd' :
125            // ecriture d'un fichier DICOM Implicit VR 
126            // à partir d'un dcmHeader correct.
127
128       sprintf(zozo, "%s.DCM", toto.c_str());
129       printf ("WriteDCM Implicit VR\n");
130       f1->WriteDcmImplVR(zozo);
131       break;
132
133    case 'x' :
134               // ecriture d'un fichier DICOM Explicit VR 
135               // à partir d'un dcmHeader correct.
136
137       sprintf(zozo, "%s.XDCM", toto.c_str());
138       std::cout << "WriteDCM Explicit VR" << std::endl;
139       f1->WriteDcmExplVR(zozo);
140       break;
141
142    case 'r' :
143              //  Ecriture d'un Raw File, a afficher avec 
144              // affim filein= dimx= dimy= nbit= signe=
145
146       sprintf(zozo, "%s.RAW", toto.c_str());
147       std::cout << "WriteRaw" << std::endl;
148       f1->WriteRawData(zozo);
149       break;
150
151    }
152   return 0;
153 }
154