]> Creatis software - gdcm.git/blob - Example/WriteDicom.cxx
ENH: Add Example stuff with real main:
[gdcm.git] / Example / WriteDicom.cxx
1 #include "gdcmHeader.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         // f1->PrintPubElVal();
24         
25   // We assume that DICOM fields of second file actually exists :
26         
27   std::string nbFrames = f2->GetHeader()->GetEntryByNumber(0x0028, 0x0008);
28   if(nbFrames != "gdcm::Unfound") {
29       f1->GetHeader()->ReplaceOrCreateByNumber( nbFrames, 0x0028, 0x0008);
30   }
31          
32   f1->GetHeader()->ReplaceOrCreateByNumber(
33     f2->GetHeader()->GetEntryByNumber(0x0028, 0x0010), 0x0028, 0x0010); // nbLig
34   f1->GetHeader()->ReplaceOrCreateByNumber( 
35     f2->GetHeader()->GetEntryByNumber(0x0028, 0x0011), 0x0028, 0x0011); // nbCol
36
37   // Some other tags should be updated:
38         
39         // TODO : add a default value
40   // TODO : a function which take as input a list of tuple (gr, el)
41   //        and that does the job
42
43   int dataSize    = f2->GetImageDataSize();
44   void *imageData = f2->GetImageData();
45
46   std::cout << "dataSize :" << dataSize << std::endl;
47                         
48   // TODO : Shouldn't we merge those two functions ?
49   f1->SetImageData( imageData, dataSize);
50   f1->GetHeader()->SetImageDataSize( dataSize );
51         
52   f1->GetHeader()->PrintEntry();
53         
54   std::string s0  = f2->GetHeader()->GetEntryByNumber(0x7fe0, 0x0000);
55   std::string s10 = f2->GetHeader()->GetEntryByNumber(0x7fe0, 0x0010);
56
57   std::cout << "lgr 7fe0, 0000 " << s0  << std::endl;
58   std::cout << "lgr 7fe0, 0010 " << s10 << std::endl;   
59
60   std::cout << "WriteDCM" << std::endl;
61
62   f1->WriteDcmExplVR("WriteDicom.dcm");
63   //f1->WriteDcmImplVR(resultat);
64   //f1->WriteAcr(resultat);
65
66   return 0;
67 }