]> Creatis software - gdcm.git/blob - Example/Write.cxx
* src/gdcmFile.cxx : now delete the PixelConvert instance.
[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    uint8_t* 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->GetPixelConverter()->Print();
91       std::cout << std::endl << "==========================================="
92                 << std::endl; 
93    }
94    imageData= f1->GetImageData();
95    (void)imageData;  // to avoid warnings
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