1 /*=========================================================================
4 Module: $RCSfile: WriteDicom.cxx,v $
6 Date: $Date: 2004/11/16 04:26:18 $
7 Version: $Revision: 1.7 $
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 =========================================================================*/
20 // Writting of a DICOM file based on a correct dicom header
21 // and data pixel of another image
23 int main(int argc, char* argv[])
28 std::cerr << "Usage :" << std::endl << argv[0] <<
29 " HeaderFileName DataFileName" << std::endl;
33 const char *first = argv[1];
34 gdcm::File *f1 = new gdcm::File( first );
36 const char *second = argv[2];
37 gdcm::File *f2 = new gdcm::File( second );
39 // We assume that DICOM fields of second file actually exists :
41 std::string nbFrames = f2->GetHeader()->GetEntryByNumber(0x0028, 0x0008);
42 if(nbFrames != "gdcm::Unfound") {
43 f1->GetHeader()->ReplaceOrCreateByNumber( nbFrames, 0x0028, 0x0008);
46 f1->GetHeader()->ReplaceOrCreateByNumber(
47 f2->GetHeader()->GetEntryByNumber(0x0028, 0x0010), 0x0028, 0x0010); // nbLig
48 f1->GetHeader()->ReplaceOrCreateByNumber(
49 f2->GetHeader()->GetEntryByNumber(0x0028, 0x0011), 0x0028, 0x0011); // nbCol
51 // Some other tags should be updated:
53 // TODO : add a default value
54 // TODO : a function which take as input a list of tuple (gr, el)
55 // and that does the job
57 int dataSize = f2->GetImageDataSize();
58 uint8_t* imageData = f2->GetImageData();
60 std::cout << "dataSize :" << dataSize << std::endl;
62 // TODO : Shouldn't we merge those two functions ?
63 f1->SetImageData( imageData, dataSize);
64 f1->GetHeader()->SetImageDataSize( 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");