]> Creatis software - gdcm.git/blob - Example/TestChangeHeader.cxx
ENH: Minor cleanup, mostly remove comments
[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     gdcm::Header *h1 = new gdcm::Header( argv[1] );
18     gdcm::File  *f1 = new gdcm::File( h1 );
19     gdcm::File  *f2 = new gdcm::File( argv[2] );
20
21     // 0018 1310 US ACQ Acquisition Matrix
22     gdcm::DictEntry *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