]> Creatis software - gdcm.git/blob - Example/TestWrite.cxx
First stage of name normalisation : gdcm::File replace by gdcm::FileHelper
[gdcm.git] / Example / TestWrite.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestWrite.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/20 16:16:58 $
7   Version:   $Revision: 1.15 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18 #include "gdcmHeader.h"
19 #include "gdcmFileHelper.h"
20
21 #include <iostream>
22
23 int main(int argc, char *argv[])
24 {  
25    std::string zozo;
26
27    gdcm::Header *e1;
28    gdcm::FileHelper *f1;
29
30    void* imageData;
31    int dataSize;
32
33    if (argc < 3) {
34          std::cerr << "usage: " << std::endl 
35                    << argv[0] << " OriginalFileName writtingMode "
36                 << std::endl 
37                    << "(a : ACR, produces a file named OriginalFileName.ACR"
38                    << " x : DICOM Explicit VR, produces a file named OriginalFileName.XDCM"
39                    << " r : RAW, produces a file named OriginalFileName.RAW"
40                    << " v : explicit VR + computes the video inv image --> OriginalFileName.VDCM"
41                 << std::endl;
42
43          return 0;
44    }
45 /*
46    if (0) {  // Just to keep the code for further use
47       std::cout <<std::endl << "-------- Test gdcmHeader ------" <<std::endl;
48       e1 = new gdcmHeaderHelper(argv[1]);
49       if (!f1->GetHeader()->IsReadable()) {
50          std::cout << "Sorry, not a DICOM / ACR File"  <<std::endl;
51          exit(0);
52       }
53       std::cout << std::endl << "----------------------> after new gdcmHeader"
54                 << std::endl;
55       e1->PrintEntry();
56       std::cout <<std::endl <<"---------------------------------------" 
57                 <<std::endl;
58    }
59 */
60
61    std::cout << std::endl
62              << "--------------------- file :" << argv[1] 
63              << std::endl;
64      
65    std::string toto = argv[1]; 
66    std::string mode = argv[2];
67
68    e1 = new gdcm::Header( toto.c_str() );
69    if (!e1->IsReadable())
70    {
71        std::cerr << "Sorry, not a Readable DICOM / ACR File"  <<std::endl;
72        return 0;
73    }
74   // e1->Print(); 
75    
76    f1 = new gdcm::FileHelper(e1);
77 // ---     
78
79    dataSize = f1->GetImageDataSize();
80    std::cout <<std::endl <<" dataSize " << dataSize << std::endl;
81    int nX,nY,nZ,sPP,planarConfig;
82    std::string pixelType, transferSyntaxName;
83    nX=e1->GetXSize();
84    nY=e1->GetYSize();
85    nZ=e1->GetZSize();
86    std::cout << " DIMX=" << nX << " DIMY=" << nY << " DIMZ=" << nZ << std::endl;
87
88    pixelType    = e1->GetPixelType();
89    sPP          = e1->GetSamplesPerPixel();
90    planarConfig = e1->GetPlanarConfiguration();
91    
92    std::cout << " pixelType="           << pixelType 
93              << " SampleserPixel="      << sPP
94              << " PlanarConfiguration=" << planarConfig 
95              << " PhotometricInterpretation=" 
96                                 << e1->GetEntry(0x0028,0x0004) 
97              << std::endl;
98
99    int numberOfScalarComponents=e1->GetNumberOfScalarComponents();
100    std::cout << "NumberOfScalarComponents " << numberOfScalarComponents <<std::endl;
101    transferSyntaxName = e1->GetTransferSyntaxName();
102    std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl;
103    
104 /*   if (  transferSyntaxName != "Implicit VR - Little Endian"
105       && transferSyntaxName != "Explicit VR - Little Endian"     
106       && transferSyntaxName != "Deflated Explicit VR - Little Endian"      
107       && transferSyntaxName != "Explicit VR - Big Endian"
108       && transferSyntaxName != "Uncompressed ACR-NEMA"     ) {
109       std::cout << std::endl << "==========================================="
110                 << std::endl; 
111       f1->GetPixelReadConverter()->Print();
112       std::cout << std::endl << "==========================================="
113                 << std::endl; 
114    }*/
115    imageData= f1->GetImageData();
116
117    switch (mode[0])
118    {
119    case 'a' :
120             // ecriture d'un fichier ACR 
121             // à partir d'un dcmHeader correct.
122
123       zozo = toto + ".ACR";
124       std::cout << "WriteACR" << std::endl;
125       f1->WriteAcr(zozo);
126       break;
127
128    case 'd' :  // Not document in the 'usage', because the method is knowed to be bugged. 
129
130            // ecriture d'un fichier DICOM Implicit VR 
131            // à partir d'un dcmHeader correct.
132
133       zozo = toto + ".DCM";
134       std::cout << "WriteDCM Implicit VR" << std::endl;
135       f1->WriteDcmImplVR(zozo);
136       break;
137
138    case 'x' :
139               // ecriture d'un fichier DICOM Explicit VR 
140               // à partir d'un dcmHeader correct.
141
142       zozo = toto + ".XDCM";
143       std::cout << "WriteDCM Explicit VR" << std::endl;
144       f1->WriteDcmExplVR(zozo);
145       break;
146
147    case 'r' :
148              //  Ecriture d'un Raw File, a afficher avec 
149              // affim filein= dimx= dimy= nbit= signe=
150
151       zozo = toto + ".RAW";
152       std::cout << "WriteRaw" << std::endl;
153       f1->WriteRawData(zozo);
154       break;
155
156    case 'v' :
157
158      if ( f1->GetHeader()->GetBitsAllocated() == 8)
159      {
160         std::cout << "videoinv for 8 bits" << std::endl;
161         for (int i=0; i<dataSize; i++) 
162         {
163            ((uint8_t*)imageData)[i] += 127;
164         }
165      }
166      else
167      {
168         std::cout << "videoinv for 16 bits" << std::endl;    
169         for (int i=0; i<dataSize/2; i++) 
170         {
171            ((uint16_t*)imageData)[i] += 60000; //32767;
172         }
173      }
174      zozo = toto + ".VDCM";
175      std::cout << "WriteDCM Explicit VR + VideoInv" << std::endl;
176      f1->WriteDcmExplVR(zozo);
177      break;
178
179    }
180   return 0;
181 }
182