]> Creatis software - gdcm.git/blob - Testing/TestChangeHeader.cxx
* Remove some useless methods in gdcm::Document, gdcm::Header and gdcm::File
[gdcm.git] / Testing / TestChangeHeader.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestChangeHeader.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/11/26 10:55:03 $
7   Version:   $Revision: 1.27 $
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 #include <string>
21
22 // Writting of a DICOM file, using a correct gdcmHeader.
23 // and pixels of an other image
24
25
26 int TestChangeHeader(int argc, char* argv[])
27 {
28    if (argc < 3)
29    {
30       std::cerr << "usage :" << std::endl << 
31       argv[0] << " FileForHeader FileForPixels" << std::endl;
32       return 1;
33    }
34
35    std::string premier = argv[1];
36    gdcmFile  *f1 = new gdcmFile(premier);
37
38    std::string deuxieme = argv[2];
39    gdcmFile  *f2 = new gdcmFile(deuxieme);
40
41    //f1->PrintPubElVal();
42
43    // We suppose the DICOM Entries of the second file *do* exist !
44
45    std::string nbFrames = f2->GetHeader()->GetEntryByNumber(0x0028, 0x0008);
46    if(nbFrames != "gdcm::Unfound")
47    {
48       f1->GetHeader()->ReplaceOrCreateByNumber( nbFrames, 0x0028, 0x0008);
49    }
50
51
52 // WARNING : If user tries to 'merge' two mismatching images
53 // e.g. a LUT image and a RGB image
54 // or a compressed and an uncompressed one
55 // or a single frame and a multiframe,
56 // or a '12 Bits Allocated' image and anything else, etc
57 // Probabely TestChangeHeader will fail !
58 // It was not designed as a 'Test' program, but as a utility
59 // provided to 'transform' an image 'Siemens MRI New version' into an image 'Siemens MRI old version'
60          
61    f1->GetHeader()->ReplaceOrCreateByNumber(
62       f2->GetHeader()->GetEntryByNumber(0x0028, 0x0010), 0x0028, 0x0010);// nbLig
63    f1->GetHeader()->ReplaceOrCreateByNumber( 
64       f2->GetHeader()->GetEntryByNumber(0x0028, 0x0011), 0x0028, 0x0011);// nbCol
65    f1->GetHeader()->ReplaceOrCreateByNumber( 
66       f2->GetHeader()->GetEntryByNumber(0x0028, 0x0100), 0x0028, 0x0100);// BitsAllocated
67    f1->GetHeader()->ReplaceOrCreateByNumber( 
68       f2->GetHeader()->GetEntryByNumber(0x0028, 0x0101), 0x0028, 0x0101);// BitsStored
69    f1->GetHeader()->ReplaceOrCreateByNumber( 
70       f2->GetHeader()->GetEntryByNumber(0x0028, 0x0102), 0x0028, 0x0102);// HighBit
71    f1->GetHeader()->ReplaceOrCreateByNumber( 
72       f2->GetHeader()->GetEntryByNumber(0x0028, 0x0103), 0x0028, 0x0103);// Pixel Representation
73 // Probabely some more to update (?)
74
75 // TODO : add a default value
76 // TODO : add a method that receives a list of pairs  (gr,el), 
77 //                        and that does the work.
78
79    int dataSize = f2->GetImageDataSize();
80    printf ("dataSize %d\n",dataSize);
81    uint8_t* imageData= f2->GetImageData();
82
83 // TODO : Why don't we merge theese 2 functions ?
84
85    f1->SetImageData(imageData,dataSize);
86
87    f1->GetHeader()->Print();
88
89    std::string s0 =f2->GetHeader()->GetEntryByNumber(0x7fe0, 0x0000);
90    std::string s10=f2->GetHeader()->GetEntryByNumber(0x7fe0, 0x0010);
91    printf("lgr 7fe0, 0000 %s\n",s0.c_str());
92    printf("lgr 7fe0, 0010 %s\n",s10.c_str());
93
94    char resultat[512];
95
96    sprintf(resultat, "%s.vol", deuxieme.c_str());
97    printf ("WriteDCM\n");
98   //f1->WriteDcmExplVR("itk-gdcm-ex.dcm");
99   //f1->WriteDcmImplVR(resultat);
100    f1->WriteAcr(resultat);
101
102    return 0;
103 }