]> Creatis software - gdcm.git/blob - Testing/TestChangeHeader.cxx
ADD : gdcmGlobal::CountSubstring method
[gdcm.git] / Testing / TestChangeHeader.cxx
1 #include "gdcmHeader.h"
2 #include "gdcmFile.h"
3 #include <string>
4
5 // Writting of a DICOM file, using a correct gdcmHeader.
6 // and pixels of an other image
7
8
9 int TestChangeHeader(int argc, char* argv[])
10 {
11    if (argc < 3)
12    {
13       std::cerr << "usage :" << std::endl << 
14       argv[0] << " FileForHeader FileForPixels" << std::endl;
15       return 1;
16    }
17
18    std::string premier = argv[1];
19    gdcmFile  *f1 = new gdcmFile(premier);
20
21    std::string deuxieme = argv[2];
22    gdcmFile  *f2 = new gdcmFile(deuxieme);
23
24    //f1->PrintPubElVal();
25
26    // We suppose the DICOM Entries of the second file *do* exist !
27
28    std::string nbFrames = f2->GetHeader()->GetEntryByNumber(0x0028, 0x0008);
29    if(nbFrames != "gdcm::Unfound")
30    {
31       f1->GetHeader()->ReplaceOrCreateByNumber( nbFrames, 0x0028, 0x0008);
32    }
33          
34    f1->GetHeader()->ReplaceOrCreateByNumber(
35       f2->GetHeader()->GetEntryByNumber(0x0028, 0x0010), 0x0028, 0x0010);// nbLig
36    f1->GetHeader()->ReplaceOrCreateByNumber( 
37       f2->GetHeader()->GetEntryByNumber(0x0028, 0x0011), 0x0028, 0x0011);// nbCol
38
39 // Probabely some more to update (?)
40
41 // TODO : add a default value
42 // TODO : add a method that receives a list of pairs  (gr,el), 
43 //                        and that does the work.
44
45    int dataSize = f2->GetImageDataSize();
46    printf ("dataSize %d\n",dataSize);
47    void* imageData= f2->GetImageData();
48
49 // TODO : Why don't we merge theese 2 functions ?
50
51    f1->SetImageData(imageData,dataSize);
52    f1->GetHeader()->SetImageDataSize(dataSize);
53
54    f1->GetHeader()->Print();
55
56    std::string s0 =f2->GetHeader()->GetEntryByNumber(0x7fe0, 0x0000);
57    std::string s10=f2->GetHeader()->GetEntryByNumber(0x7fe0, 0x0010);
58    printf("lgr 7fe0, 0000 %s\n",s0.c_str());
59    printf("lgr 7fe0, 0010 %s\n",s10.c_str());
60
61    char resultat[512];
62
63    sprintf(resultat, "%s.vol", deuxieme.c_str());
64    printf ("WriteDCM\n");
65   //f1->WriteDcmExplVR("itk-gdcm-ex.dcm");
66   //f1->WriteDcmImplVR(resultat);
67    f1->WriteAcr(resultat);
68
69    return 0;
70 }