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