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