1 /*=========================================================================
4 Module: $RCSfile: WriteDicom.cxx,v $
6 Date: $Date: 2004/12/03 20:16:55 $
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 =========================================================================*/
18 #include "gdcmHeader.h"
21 // Writting of a DICOM file based on a correct dicom header
22 // and data pixel of another image
24 int main(int argc, char* argv[])
29 std::cerr << "Usage :" << std::endl << argv[0] <<
30 " HeaderFileName DataFileName" << std::endl;
34 const char *first = argv[1];
35 gdcm::File *f1 = new gdcm::File( first );
37 const char *second = argv[2];
38 gdcm::File *f2 = new gdcm::File( second );
40 // We assume that DICOM fields of second file actually exists :
42 std::string nbFrames = f2->GetHeader()->GetEntryByNumber(0x0028, 0x0008);
43 if(nbFrames != "gdcm::Unfound") {
44 f1->GetHeader()->ReplaceOrCreateByNumber( nbFrames, 0x0028, 0x0008);
47 f1->GetHeader()->ReplaceOrCreateByNumber(
48 f2->GetHeader()->GetEntryByNumber(0x0028, 0x0010), 0x0028, 0x0010); // nbLig
49 f1->GetHeader()->ReplaceOrCreateByNumber(
50 f2->GetHeader()->GetEntryByNumber(0x0028, 0x0011), 0x0028, 0x0011); // nbCol
52 // Some other tags should be updated:
54 // TODO : add a default value
55 // TODO : a function which take as input a list of tuple (gr, el)
56 // and that does the job
58 int dataSize = f2->GetImageDataSize();
59 uint8_t* imageData = f2->GetImageData();
61 std::cout << "dataSize :" << dataSize << std::endl;
63 // TODO : Shouldn't we merge those two functions ?
64 f1->SetImageData( imageData, dataSize);
66 f1->GetHeader()->Print();
68 std::string s0 = f2->GetHeader()->GetEntryByNumber(0x7fe0, 0x0000);
69 std::string s10 = f2->GetHeader()->GetEntryByNumber(0x7fe0, 0x0010);
71 std::cout << "lgr 7fe0, 0000 " << s0 << std::endl;
72 std::cout << "lgr 7fe0, 0010 " << s10 << std::endl;
74 std::cout << "WriteDCM" << std::endl;
76 f1->WriteDcmExplVR("WriteDicom.dcm");