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