1 /*=========================================================================
4 Module: $RCSfile: TestWrite.cxx,v $
6 Date: $Date: 2005/02/02 10:06:32 $
7 Version: $Revision: 1.18 $
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.
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.
17 =========================================================================*/
19 #include "gdcmFileHelper.h"
23 int main(int argc, char *argv[])
25 std::string fileNameToWrite;
34 std::cerr << "usage: " << std::endl
35 << argv[0] << " OriginalFileName writtingMode "
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"
46 if (0) { // Just to keep the code for further use
47 std::cout <<std::endl << "-------- Test gdcmFile ------" <<std::endl;
48 e1 = new gdcmFileHelper(argv[1]);
49 if (!f1->GetFile()->IsReadable()) {
50 std::cout << "Sorry, not a DICOM / ACR File" <<std::endl;
53 std::cout << std::endl << "----------------------> after new gdcmFile"
56 std::cout <<std::endl <<"---------------------------------------"
61 std::cout << std::endl
62 << "--------------------- file :" << argv[1]
65 std::string fileName = argv[1];
66 std::string mode = argv[2];
68 e1 = new gdcm::File( fileName.c_str() );
69 if (!e1->IsReadable())
71 std::cerr << "Sorry, not a Readable DICOM / ACR File" <<std::endl;
76 f1 = new gdcm::FileHelper(e1);
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;
86 std::cout << " DIMX=" << nX << " DIMY=" << nY << " DIMZ=" << nZ << std::endl;
88 pixelType = e1->GetPixelType();
89 sPP = e1->GetSamplesPerPixel();
90 planarConfig = e1->GetPlanarConfiguration();
92 std::cout << " pixelType=" << pixelType
93 << " SampleserPixel=" << sPP
94 << " PlanarConfiguration=" << planarConfig
95 << " PhotometricInterpretation="
96 << e1->GetEntryValue(0x0028,0x0004)
99 int numberOfScalarComponents=e1->GetNumberOfScalarComponents();
100 std::cout << "NumberOfScalarComponents " << numberOfScalarComponents <<std::endl;
101 transferSyntaxName = e1->GetTransferSyntaxName();
102 std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl;
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 << "==========================================="
111 f1->GetPixelReadConverter()->Print();
112 std::cout << std::endl << "==========================================="
115 imageData= f1->GetImageData();
120 // ecriture d'un fichier ACR
121 // à partir d'un dcmFile correct.
123 fileNameToWrite = fileName + ".ACR";
124 std::cout << "WriteACR" << std::endl;
125 f1->WriteAcr(fileNameToWrite);
128 case 'd' : // Not document in the 'usage', because the method is knowed to be bugged.
130 // ecriture d'un fichier DICOM Implicit VR
131 // à partir d'un dcmFile correct.
133 fileNameToWrite = fileName + ".DCM";
134 std::cout << "WriteDCM Implicit VR" << std::endl;
135 f1->WriteDcmImplVR(fileNameToWrite);
139 // ecriture d'un fichier DICOM Explicit VR
140 // à partir d'un dcmFile correct.
142 fileNameToWrite = fileName + ".XDCM";
143 std::cout << "WriteDCM Explicit VR" << std::endl;
144 f1->WriteDcmExplVR(fileNameToWrite);
148 // Ecriture d'un Raw File, a afficher avec
149 // affim filein= dimx= dimy= nbit= signe=
151 fileNameToWrite = fileName + ".RAW";
152 std::cout << "WriteRaw" << std::endl;
153 f1->WriteRawData(fileNameToWrite);
158 if ( f1->GetFile()->GetBitsAllocated() == 8)
160 std::cout << "videoinv for 8 bits" << std::endl;
161 for (int i=0; i<dataSize; i++)
163 ((uint8_t*)imageData)[i] += 127;
168 std::cout << "videoinv for 16 bits" << std::endl;
169 for (int i=0; i<dataSize/2; i++)
171 ((uint16_t*)imageData)[i] += 60000; //32767;
174 fileNameToWrite = fileName + ".VDCM";
175 std::cout << "WriteDCM Explicit VR + VideoInv" << std::endl;
176 f1->WriteDcmExplVR(fileNameToWrite);