]> Creatis software - gdcm.git/blob - Example/TestChangeHeader.cxx
* Some classes inherit now from gdcm::RefCounter
[gdcm.git] / Example / TestChangeHeader.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestChangeHeader.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/10/25 14:52:27 $
7   Version:   $Revision: 1.18 $
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 "gdcmFile.h"
19 #include "gdcmFileHelper.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] << " fileNameForHeader fileNameForData" << 
30       std::endl;
31       return 1;
32    }
33
34    gdcm::File *h1 = gdcm::File::New( );
35    h1->SetFileName ( argv[1] );
36    h1->Load( );
37    gdcm::FileHelper  *f1 = gdcm::FileHelper::New( h1 );
38    
39    gdcm::File *h2 = gdcm::File::New( );
40    h2->SetFileName ( argv[2] );
41    h2->Load( );
42    gdcm::FileHelper  *f2 = gdcm::FileHelper::New( h2 );   
43    
44
45    // 0018 1310 US ACQ Acquisition Matrix
46    gdcm::DictEntry *dictEntry =
47                         f2->GetFile()->GetPubDict()->GetEntry( 0x0018, 1310 );
48    std::cerr << std::hex << dictEntry->GetGroup() << "," 
49             << dictEntry->GetElement() << std::endl;
50
51    std::string matrix = f2->GetFile()->GetEntryString(0x0018, 0x1310);
52    if(matrix != "gdcm::Unfound")
53    {
54       std::cerr << "Aquisition Matrix:" << matrix << std::endl;
55       f1->GetFile()->InsertEntryString( matrix, 0x0018, 0x1310);
56    }
57
58    f1->GetImageData();
59    
60    h1->Print();
61    
62    f1->WriteDcmExplVR("output-matrix.dcm");
63    
64    f1->Delete();
65    f2->Delete();
66    h1->Delete();
67    h2->Delete();
68
69    return 0;
70 }