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