1 /*=========================================================================
4 Module: $RCSfile: TestWrite.cxx,v $
6 Date: $Date: 2005/07/07 17:31:53 $
7 Version: $Revision: 1.21 $
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 f = new gdcmFileHelper(argv[1]);
49 if (!fh->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 //f = new gdcm::File( fileName.c_str() );
71 f = new gdcm::File( );
73 f->SetFileName( fileName );
77 std::cerr << "Sorry, not a Readable DICOM / ACR File" <<std::endl;
82 fh = new gdcm::FileHelper(f);
83 dataSize = fh->GetImageDataSize();
84 imageData= fh->GetImageData();
89 std::cout <<std::endl <<" dataSize " << dataSize << std::endl;
90 int nX,nY,nZ,sPP,planarConfig;
91 std::string pixelType, transferSyntaxName;
95 std::cout << " DIMX=" << nX << " DIMY=" << nY << " DIMZ=" << nZ << std::endl;
97 pixelType = f->GetPixelType();
98 sPP = f->GetSamplesPerPixel();
99 planarConfig = f->GetPlanarConfiguration();
101 std::cout << " pixelType=" << pixelType
102 << " SampleserPixel=" << sPP
103 << " PlanarConfiguration=" << planarConfig
104 << " PhotometricInterpretation="
105 << f->GetEntryValue(0x0028,0x0004)
108 int numberOfScalarComponents=f->GetNumberOfScalarComponents();
109 std::cout << "NumberOfScalarComponents " << numberOfScalarComponents <<std::endl;
110 transferSyntaxName = f->GetTransferSyntaxName();
111 std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl;
114 if ( transferSyntaxName != "Implicit VR - Little Endian"
115 && transferSyntaxName != "Explicit VR - Little Endian"
116 && transferSyntaxName != "Deflated Explicit VR - Little Endian"
117 && transferSyntaxName != "Explicit VR - Big Endian"
118 && transferSyntaxName != "Uncompressed ACR-NEMA" ) {
119 std::cout << std::endl << "==========================================="
121 fh->GetPixelReadConverter()->Print();
122 std::cout << std::endl << "==========================================="
129 // ecriture d'un fichier ACR
130 // à partir d'un dcmFile correct.
132 fileNameToWrite = fileName + ".ACR";
133 std::cout << "WriteACR" << std::endl;
134 fh->WriteAcr(fileNameToWrite);
137 case 'd' : // Not document in the 'usage', because the method is knowed to be bugged.
139 // ecriture d'un fichier DICOM Implicit VR
140 // à partir d'un dcmFile correct.
142 fileNameToWrite = fileName + ".DCM";
143 std::cout << "WriteDCM Implicit VR" << std::endl;
144 fh->WriteDcmImplVR(fileNameToWrite);
148 // ecriture d'un fichier DICOM Explicit VR
149 // à partir d'un dcmFile correct.
151 fileNameToWrite = fileName + ".XDCM";
152 std::cout << "WriteDCM Explicit VR" << std::endl;
153 fh->WriteDcmExplVR(fileNameToWrite);
157 // Ecriture d'un Raw File, a afficher avec
158 // affim filein= dimx= dimy= nbit= signe=
160 fileNameToWrite = fileName + ".RAW";
161 std::cout << "WriteRaw" << std::endl;
162 fh->WriteRawData(fileNameToWrite);
167 if ( fh->GetFile()->GetBitsAllocated() == 8)
169 std::cout << "videoinv for 8 bits" << std::endl;
170 for (int i=0; i<dataSize; i++)
172 ((uint8_t*)imageData)[i] = 255 - ((uint8_t*)imageData)[i];
177 std::cout << "videoinv for 16 bits" << std::endl;
178 for (int i=0; i<dataSize/2; i++)
180 ((uint16_t*)imageData)[i] = 65535 - ((uint16_t*)imageData)[i];
183 fileNameToWrite = fileName + ".VDCM";
184 std::cout << "WriteDCM Explicit VR + VideoInv" << std::endl;
185 fh->WriteDcmExplVR(fileNameToWrite);