]> Creatis software - gdcm.git/blob - Example/WriteDicom.cxx
* Remove some useless methods in gdcm::Document, gdcm::Header and gdcm::File
[gdcm.git] / Example / WriteDicom.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: WriteDicom.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/11/26 10:55:03 $
7   Version:   $Revision: 1.8 $
8                                                                                 
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.
12                                                                                 
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.
16                                                                                 
17 =========================================================================*/
18 #include "gdcm.h"
19
20 // Writting of a DICOM file based on a correct dicom header
21 // and data pixel of another image
22
23 int main(int argc, char* argv[])
24 {
25  
26   if (argc < 3) 
27     {
28     std::cerr << "Usage :" << std::endl << argv[0] << 
29       " HeaderFileName DataFileName" << std::endl;
30     return 0;
31     }
32
33   const char *first = argv[1];
34   gdcm::File *f1 = new gdcm::File( first );
35
36   const char *second = argv[2];
37   gdcm::File *f2 = new gdcm::File( second );
38
39   // We assume that DICOM fields of second file actually exists :
40
41   std::string nbFrames = f2->GetHeader()->GetEntryByNumber(0x0028, 0x0008);
42   if(nbFrames != "gdcm::Unfound") {
43       f1->GetHeader()->ReplaceOrCreateByNumber( nbFrames, 0x0028, 0x0008);
44   }
45          
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
50
51   // Some other tags should be updated:
52
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
56
57   int dataSize    = f2->GetImageDataSize();
58   uint8_t* imageData = f2->GetImageData();
59
60   std::cout << "dataSize :" << dataSize << std::endl;
61
62   // TODO : Shouldn't we merge those two functions ?
63   f1->SetImageData( imageData, dataSize);
64
65   f1->GetHeader()->Print();
66
67   std::string s0  = f2->GetHeader()->GetEntryByNumber(0x7fe0, 0x0000);
68   std::string s10 = f2->GetHeader()->GetEntryByNumber(0x7fe0, 0x0010);
69
70   std::cout << "lgr 7fe0, 0000 " << s0  << std::endl;
71   std::cout << "lgr 7fe0, 0010 " << s10 << std::endl;
72
73   std::cout << "WriteDCM" << std::endl;
74
75   f1->WriteDcmExplVR("WriteDicom.dcm");
76
77   return 0;
78 }