]> Creatis software - gdcm.git/blob - Example/Write.cxx
16c6c1395cd4d7caa1544dfba4b2ca12954239d2
[gdcm.git] / Example / Write.cxx
1 #include <iostream>
2 #include <stdio.h>
3 #include "gdcm.h"
4
5 int main(int argc, char* argv[])
6 {  
7    std::string toto;
8    char zozo[200];
9
10    gdcm::Header* e1;
11    gdcm::File  * f1;
12
13    //gdcmDocument * d;  //not used
14    void* imageData;
15    int dataSize;
16
17    if (argc < 3) {
18          std::cerr << "usage: " << std::endl 
19                    << argv[0] << " fileName writtingMode "
20                 << std::endl 
21                    << "(a : ACR, d : DICOM Implicit VR,"
22                    << " x : DICOM Explicit VR,  r : RAW)"
23                 << std::endl;
24          return 0;
25    }
26 /*
27    if (0) {  // Just to keep the code for further use
28       std::cout <<std::endl << "-------- Test gdcmHeader ------" <<std::endl;
29       e1 = new gdcmHeaderHelper(argv[1]);
30       if (!f1->GetHeader()->IsReadable()) {
31          std::cout << "Sorry, not a DICOM / ACR File"  <<std::endl;
32          exit(0);
33       }
34       std::cout << std::endl << "----------------------> after new gdcmHeader"
35                 << std::endl;
36       e1->PrintEntry();
37       std::cout <<std::endl <<"---------------------------------------" 
38                 <<std::endl;
39    }
40 */
41
42    std::cout << std::endl
43              << "--------------------- file :" << argv[1] 
44              << std::endl;
45      
46    toto = argv[1]; 
47
48    e1 = new gdcm::Header( toto.c_str() );
49    if (!e1->IsReadable()) {
50        std::cerr << "Sorry, not a Readable DICOM / ACR File"  <<std::endl;
51        return 0;
52    }
53   // e1->Print(); 
54    
55    f1 = new gdcm::File(e1);
56 // ---     
57
58    dataSize = f1->GetImageDataSize();
59    std::cout <<std::endl <<" dataSize " << dataSize << std::endl;
60    int nX,nY,nZ,sPP,planarConfig;
61    std::string pixelType, transferSyntaxName;
62    nX=e1->GetXSize();
63    nY=e1->GetYSize();
64    nZ=e1->GetZSize();
65    std::cout << " DIMX=" << nX << " DIMY=" << nY << " DIMZ=" << nZ << std::endl;
66
67    pixelType    = e1->GetPixelType();
68    sPP          = e1->GetSamplesPerPixel();
69    planarConfig = e1->GetPlanarConfiguration();
70    
71    std::cout << " pixelType="           << pixelType 
72              << " SampleserPixel="      << sPP
73              << " PlanarConfiguration=" << planarConfig 
74              << " PhotometricInterpretation=" 
75                                 << e1->GetEntryByNumber(0x0028,0x0004) 
76              << std::endl;
77
78    int numberOfScalarComponents=e1->GetNumberOfScalarComponents();
79    std::cout << "NumberOfScalarComponents " << numberOfScalarComponents <<std::endl;
80    transferSyntaxName = e1->GetTransfertSyntaxName();
81    std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl;
82    
83    if (  transferSyntaxName != "Implicit VR - Little Endian"
84       && transferSyntaxName != "Explicit VR - Little Endian"     
85       && transferSyntaxName != "Deflated Explicit VR - Little Endian"      
86       && transferSyntaxName != "Explicit VR - Big Endian"
87       && transferSyntaxName != "Uncompressed ACR-NEMA"     ) {
88       std::cout << std::endl << "==========================================="
89                 << std::endl; 
90       f1->ParsePixelData();
91       std::cout << std::endl << "==========================================="
92                 << std::endl; 
93    }
94    imageData= f1->GetImageData();
95
96    switch (argv[2][0]) {
97    case 'a' :
98             // ecriture d'un fichier ACR 
99             // à partir d'un dcmHeader correct.
100
101       sprintf(zozo, "%s.ACR", toto.c_str());
102       printf ("WriteACR\n");
103       f1->WriteAcr(zozo);
104       break;
105
106    case 'd' :
107            // ecriture d'un fichier DICOM Implicit VR 
108            // à partir d'un dcmHeader correct.
109
110       sprintf(zozo, "%s.DCM", toto.c_str());
111       printf ("WriteDCM Implicit VR\n");
112       f1->WriteDcmImplVR(zozo);
113       break;
114
115    case 'x' :
116               // ecriture d'un fichier DICOM Explicit VR 
117               // à partir d'un dcmHeader correct.
118
119       sprintf(zozo, "%s.XDCM", toto.c_str());
120       std::cout << "WriteDCM Explicit VR" << std::endl;
121       f1->WriteDcmExplVR(zozo);
122       break;
123
124    case 'r' :
125              //  Ecriture d'un Raw File, a afficher avec 
126              // affim filein= dimx= dimy= nbit= signe=
127
128       sprintf(zozo, "%s.RAW", toto.c_str());
129       std::cout << "WriteRaw" << std::endl;
130       f1->WriteRawData(zozo);
131       break;
132
133    }
134   return 0;
135 }
136