]> Creatis software - gdcm.git/blob - Example/TestChangeHeader.cxx
ENH: Add license to examples since they belong to gdcm
[gdcm.git] / Example / TestChangeHeader.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestChangeHeader.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/11/16 04:26:18 $
7   Version:   $Revision: 1.4 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18 #include "gdcmHeader.h"
19 #include "gdcmFile.h"
20
21 // This examples read two images (could be the same). Try to modify
22 // Acquisition Matrix and then write the image again
23
24 int main(int argc, char* argv[])
25 {
26     if (argc < 3)
27     {
28        std::cerr << "usage :" << std::endl <<
29          argv[0] << " nomFichierPourEntete nomFichierPourDonnées" << 
30 std::endl;
31        return 1;
32     }
33
34     gdcm::Header *h1 = new gdcm::Header( argv[1] );
35     gdcm::File  *f1 = new gdcm::File( h1 );
36     gdcm::File  *f2 = new gdcm::File( argv[2] );
37
38     // 0018 1310 US ACQ Acquisition Matrix
39     gdcm::DictEntry *dictEntry =
40        f2->GetHeader()->GetPubDict()->GetDictEntryByName( "Acquisition Matrix" );
41     std::cerr << std::hex << dictEntry->GetGroup() << "," << dictEntry->GetElement() << std::endl;
42
43    // std::string matrix = f2->GetHeader()->GetEntryByNumber(0x0018, 0x1310);
44    // Or, strictly equivalent (a little bit longer at run-time !):
45     std::string matrix = f2->GetHeader()->GetEntryByName("Acquisition Matrix");  
46     if(matrix != "gdcm::Unfound")
47     {
48        std::cerr << "Aquisition Matrix:" << matrix << std::endl;
49       f1->GetHeader()->ReplaceOrCreateByNumber( matrix, 0x0018, 0x1310);
50       
51        //f1->GetHeader()->ReplaceOrCreateByNumber( matrix, dictEntry->GetGroup(),
52        //  dictEntry->GetElement());
53     }
54
55     f1->GetImageData();
56     
57     h1->Print();
58     
59     f1->WriteDcmExplVR("output-matrix.dcm");
60
61     return 0;
62 }
63
64