1 /*=========================================================================
4 Module: $RCSfile: TestWrite.cxx,v $
6 Date: $Date: 2004/11/16 04:26:18 $
7 Version: $Revision: 1.9 $
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 =========================================================================*/
22 int main(int argc, char* argv[])
31 //gdcmDocument * d; //not used
36 std::cerr << "usage: " << std::endl
37 << argv[0] << " OriginalFileName writtingMode "
39 << "(a : ACR, produces a file named OriginalFileName.ACR"
40 << " x : DICOM Explicit VR, produces a file named OriginalFileName.XDCM"
41 << " r : RAW, produces a file named OriginalFileName.RAW"
42 << " v : explicit VR + computes the video inv image --> OriginalFileName.VDCM"
48 if (0) { // Just to keep the code for further use
49 std::cout <<std::endl << "-------- Test gdcmHeader ------" <<std::endl;
50 e1 = new gdcmHeaderHelper(argv[1]);
51 if (!f1->GetHeader()->IsReadable()) {
52 std::cout << "Sorry, not a DICOM / ACR File" <<std::endl;
55 std::cout << std::endl << "----------------------> after new gdcmHeader"
58 std::cout <<std::endl <<"---------------------------------------"
63 std::cout << std::endl
64 << "--------------------- file :" << argv[1]
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->GetPixelConverter()->Print();
113 std::cout << std::endl << "==========================================="
116 imageData= f1->GetImageData();
118 switch (argv[2][0]) {
120 // ecriture d'un fichier ACR
121 // à partir d'un dcmHeader correct.
123 sprintf(zozo, "%s.ACR", toto.c_str());
124 printf ("WriteACR\n");
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 dcmHeader correct.
133 sprintf(zozo, "%s.DCM", toto.c_str());
134 printf ("WriteDCM Implicit VR\n");
135 f1->WriteDcmImplVR(zozo);
139 // ecriture d'un fichier DICOM Explicit VR
140 // à partir d'un dcmHeader correct.
142 sprintf(zozo, "%s.XDCM", toto.c_str());
143 std::cout << "WriteDCM Explicit VR" << std::endl;
144 f1->WriteDcmExplVR(zozo);
148 // Ecriture d'un Raw File, a afficher avec
149 // affim filein= dimx= dimy= nbit= signe=
151 sprintf(zozo, "%s.RAW", toto.c_str());
152 std::cout << "WriteRaw" << std::endl;
153 f1->WriteRawData(zozo);
158 if ( f1->GetHeader()->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 sprintf(zozo, "%s.VDCM", toto.c_str());
175 printf ("WriteDCM Explicit VR + VideoInv\n");
176 f1->WriteDcmExplVR(zozo);