]> Creatis software - gdcm.git/blob - Example/TestChangeHeader.cxx
c0982e6d9095da93e149c005ef283f41a15b978a
[gdcm.git] / Example / TestChangeHeader.cxx
1 #include "gdcmHeader.h"
2 #include "gdcmFile.h"
3
4 // This examples read two images (could be the same). Try to modify
5 // Acquisition Matrix and then write the image again
6
7 int main(int argc, char* argv[])
8 {
9     if (argc < 3)
10     {
11        std::cerr << "usage :" << std::endl <<
12          argv[0] << " nomFichierPourEntete nomFichierPourDonnées" << 
13 std::endl;
14        return 1;
15     }
16
17     gdcmHeader *h1 = new gdcmHeader( argv[1] );
18     gdcmFile  *f1 = new gdcmFile( h1 );
19     gdcmFile  *f2 = new gdcmFile( argv[2] );
20
21     // 0018 1310 US ACQ Acquisition Matrix
22     gdcmDictEntry *dictEntry =
23          f2->GetHeader()->GetPubDict()->GetDictEntryByName( "Acquisition Matrix" );
24     std::cerr << std::hex << dictEntry->GetGroup() << "," << dictEntry->GetElement() << std::endl;
25
26    // std::string matrix = f2->GetHeader()->GetEntryByNumber(0x0018, 0x1310);
27    // Or, strictly equivalent (a little bit longer at run-time !):
28     std::string matrix = f2->GetHeader()->GetEntryByName("Acquisition Matrix");  
29     if(matrix != "gdcm::Unfound")
30     {
31        std::cerr << "Aquisition Matrix:" << matrix << std::endl;
32       f1->GetHeader()->ReplaceOrCreateByNumber( matrix, 0x0018, 0x1310);
33       
34        //f1->GetHeader()->ReplaceOrCreateByNumber( matrix, dictEntry->GetGroup(),
35        //  dictEntry->GetElement());
36     }
37
38     f1->GetImageData();
39     
40     h1->Print();
41     
42     f1->WriteDcmExplVR("output-matrix.dcm");
43
44     return 0;
45 }
46
47