1 /*=========================================================================
4 Module: $RCSfile: TestWrite.cxx,v $
6 Date: $Date: 2004/12/03 20:16:55 $
7 Version: $Revision: 1.12 $
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 =========================================================================*/
18 #include "gdcmHeader.h"
23 int main(int argc, char* argv[])
30 //gdcmDocument * d; //not used
35 std::cerr << "usage: " << std::endl
36 << argv[0] << " OriginalFileName writtingMode "
38 << "(a : ACR, produces a file named OriginalFileName.ACR"
39 << " x : DICOM Explicit VR, produces a file named OriginalFileName.XDCM"
40 << " r : RAW, produces a file named OriginalFileName.RAW"
41 << " v : explicit VR + computes the video inv image --> OriginalFileName.VDCM"
47 if (0) { // Just to keep the code for further use
48 std::cout <<std::endl << "-------- Test gdcmHeader ------" <<std::endl;
49 e1 = new gdcmHeaderHelper(argv[1]);
50 if (!f1->GetHeader()->IsReadable()) {
51 std::cout << "Sorry, not a DICOM / ACR File" <<std::endl;
54 std::cout << std::endl << "----------------------> after new gdcmHeader"
57 std::cout <<std::endl <<"---------------------------------------"
62 std::cout << std::endl
63 << "--------------------- file :" << argv[1]
66 std::string toto = argv[1];
67 std::string mode = argv[2];
69 e1 = new gdcm::Header( toto.c_str() );
70 if (!e1->IsReadable())
72 std::cerr << "Sorry, not a Readable DICOM / ACR File" <<std::endl;
77 f1 = new gdcm::File(e1);
80 dataSize = f1->GetImageDataSize();
81 std::cout <<std::endl <<" dataSize " << dataSize << std::endl;
82 int nX,nY,nZ,sPP,planarConfig;
83 std::string pixelType, transferSyntaxName;
87 std::cout << " DIMX=" << nX << " DIMY=" << nY << " DIMZ=" << nZ << std::endl;
89 pixelType = e1->GetPixelType();
90 sPP = e1->GetSamplesPerPixel();
91 planarConfig = e1->GetPlanarConfiguration();
93 std::cout << " pixelType=" << pixelType
94 << " SampleserPixel=" << sPP
95 << " PlanarConfiguration=" << planarConfig
96 << " PhotometricInterpretation="
97 << e1->GetEntryByNumber(0x0028,0x0004)
100 int numberOfScalarComponents=e1->GetNumberOfScalarComponents();
101 std::cout << "NumberOfScalarComponents " << numberOfScalarComponents <<std::endl;
102 transferSyntaxName = e1->GetTransfertSyntaxName();
103 std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl;
105 /* if ( transferSyntaxName != "Implicit VR - Little Endian"
106 && transferSyntaxName != "Explicit VR - Little Endian"
107 && transferSyntaxName != "Deflated Explicit VR - Little Endian"
108 && transferSyntaxName != "Explicit VR - Big Endian"
109 && transferSyntaxName != "Uncompressed ACR-NEMA" ) {
110 std::cout << std::endl << "==========================================="
112 f1->GetPixelReadConverter()->Print();
113 std::cout << std::endl << "==========================================="
116 imageData= f1->GetImageData();
121 // ecriture d'un fichier ACR
122 // à partir d'un dcmHeader correct.
124 zozo = toto + ".ACR";
125 std::cout << "WriteACR" << std::endl;
129 case 'd' : // Not document in the 'usage', because the method is knowed to be bugged.
131 // ecriture d'un fichier DICOM Implicit VR
132 // à partir d'un dcmHeader correct.
134 zozo = toto + ".DCM";
135 std::cout << "WriteDCM Implicit VR" << std::endl;
136 f1->WriteDcmImplVR(zozo);
140 // ecriture d'un fichier DICOM Explicit VR
141 // à partir d'un dcmHeader correct.
143 zozo = toto + ".XDCM";
144 std::cout << "WriteDCM Explicit VR" << std::endl;
145 f1->WriteDcmExplVR(zozo);
149 // Ecriture d'un Raw File, a afficher avec
150 // affim filein= dimx= dimy= nbit= signe=
152 zozo = toto + ".RAW";
153 std::cout << "WriteRaw" << std::endl;
154 f1->WriteRawData(zozo);
159 if ( f1->GetHeader()->GetBitsAllocated() == 8)
161 std::cout << "videoinv for 8 bits" << std::endl;
162 for (int i=0; i<dataSize; i++)
164 ((uint8_t*)imageData)[i] += 127;
169 std::cout << "videoinv for 16 bits" << std::endl;
170 for (int i=0; i<dataSize/2; i++)
172 ((uint16_t*)imageData)[i] += 60000; //32767;
175 zozo = toto + ".VDCM";
176 std::cout << "WriteDCM Explicit VR + VideoInv" << std::endl;
177 f1->WriteDcmExplVR(zozo);