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