]> Creatis software - gdcm.git/blob - Example/WriteDicom.cxx
81a790484beb16b1b950e4b9361b6c6132f6371f
[gdcm.git] / Example / WriteDicom.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: WriteDicom.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/08 15:03:57 $
7   Version:   $Revision: 1.10 $
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 // Writting of a DICOM file based on a correct dicom header
22 // and data pixel of another image
23
24 int main(int argc, char* argv[])
25 {
26  
27    if (argc < 3) 
28      {
29      std::cerr << "Usage :" << std::endl << argv[0] << 
30        " HeaderFileName DataFileName" << std::endl;
31      return 0;
32      }
33  
34    const char *first = argv[1];
35    gdcm::File *f1 = new gdcm::File( first );
36  
37    const char *second = argv[2];
38    gdcm::File *f2 = new gdcm::File( second );
39  
40    // We assume that DICOM fields of second file actually exists :
41  
42    std::string nbFrames = f2->GetHeader()->GetEntry(0x0028, 0x0008);
43    if(nbFrames != "gdcm::Unfound") {
44        f1->GetHeader()->ReplaceOrCreate( nbFrames, 0x0028, 0x0008);
45    }
46           
47    f1->GetHeader()->ReplaceOrCreate(
48      f2->GetHeader()->GetEntry(0x0028, 0x0010), 0x0028, 0x0010); // nbLig
49    f1->GetHeader()->ReplaceOrCreate( 
50      f2->GetHeader()->GetEntry(0x0028, 0x0011), 0x0028, 0x0011); // nbCol
51  
52    // Some other tags should be updated:
53  
54    // TODO : add a default value
55    // TODO : a function which take as input a list of tuple (gr, el)
56    //        and that does the job
57  
58    int dataSize    = f2->GetImageDataSize();
59    uint8_t* imageData = f2->GetImageData();
60  
61    std::cout << "dataSize :" << dataSize << std::endl;
62  
63    // TODO : Shouldn't we merge those two functions ?
64    f1->SetImageData( imageData, dataSize);
65  
66    f1->GetHeader()->Print();
67  
68    std::string s0  = f2->GetHeader()->GetEntry(0x7fe0, 0x0000);
69    std::string s10 = f2->GetHeader()->GetEntry(0x7fe0, 0x0010);
70  
71    std::cout << "lgr 7fe0, 0000 " << s0  << std::endl;
72    std::cout << "lgr 7fe0, 0010 " << s10 << std::endl;
73  
74    std::cout << "WriteDCM" << std::endl;
75  
76    f1->WriteDcmExplVR("WriteDicom.dcm");
77  
78    return 0;
79 }