]> Creatis software - gdcm.git/blob - Example/WriteDicom.cxx
18d798fd10bc39011fce5a5ff053c8dfff9af4a0
[gdcm.git] / Example / WriteDicom.cxx
1 #include "gdcm.h"
2
3 // Writting of a DICOM file based on a correct dicom header
4 // and data pixel of another image
5
6 int main(int argc, char* argv[])
7 {
8  
9   if (argc < 3) 
10     {
11     std::cerr << "Usage :" << std::endl << argv[0] << 
12       " HeaderFileName DataFileName" << std::endl;
13     return 0;
14     }
15
16   const char *first = argv[1];
17   gdcmFile *f1 = new gdcmFile( first );
18
19   const char *second = argv[2];
20   gdcmFile *f2 = new gdcmFile( second );
21
22   // We assume that DICOM fields of second file actually exists :
23
24   std::string nbFrames = f2->GetHeader()->GetEntryByNumber(0x0028, 0x0008);
25   if(nbFrames != "gdcm::Unfound") {
26       f1->GetHeader()->ReplaceOrCreateByNumber( nbFrames, 0x0028, 0x0008);
27   }
28          
29   f1->GetHeader()->ReplaceOrCreateByNumber(
30     f2->GetHeader()->GetEntryByNumber(0x0028, 0x0010), 0x0028, 0x0010); // nbLig
31   f1->GetHeader()->ReplaceOrCreateByNumber( 
32     f2->GetHeader()->GetEntryByNumber(0x0028, 0x0011), 0x0028, 0x0011); // nbCol
33
34   // Some other tags should be updated:
35
36   // TODO : add a default value
37   // TODO : a function which take as input a list of tuple (gr, el)
38   //        and that does the job
39
40   int dataSize    = f2->GetImageDataSize();
41   uint8_t* imageData = f2->GetImageData();
42
43   std::cout << "dataSize :" << dataSize << std::endl;
44
45   // TODO : Shouldn't we merge those two functions ?
46   f1->SetImageData( imageData, dataSize);
47   f1->GetHeader()->SetImageDataSize( dataSize );
48
49   f1->GetHeader()->Print();
50
51   std::string s0  = f2->GetHeader()->GetEntryByNumber(0x7fe0, 0x0000);
52   std::string s10 = f2->GetHeader()->GetEntryByNumber(0x7fe0, 0x0010);
53
54   std::cout << "lgr 7fe0, 0000 " << s0  << std::endl;
55   std::cout << "lgr 7fe0, 0010 " << s10 << std::endl;
56
57   std::cout << "WriteDCM" << std::endl;
58
59   f1->WriteDcmExplVR("WriteDicom.dcm");
60
61   return 0;
62 }