]> Creatis software - gdcm.git/blob - Example/exAnonymize.cxx
ENH: Apparently the new Free .Net compiler complains also about the dll heritance...
[gdcm.git] / Example / exAnonymize.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: exAnonymize.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/02/06 14:56:22 $
7   Version:   $Revision: 1.1 $
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 #include "gdcmCommon.h"
21
22 #include <iostream>
23
24 int main(int argc, char *argv[])
25 {  
26
27    gdcm::File *f1;
28      
29    if( argc < 3 )
30     {
31     std::cerr << "Usage " << argv[0] << " Source image.dcm  " 
32               << " Output image.dcm " << std::endl;
33     return 1;
34     }
35
36    std::string fileName       = argv[1];
37    std::string outputFileName = argv[2];
38
39 // --------------------- we read the input image
40
41    std::cout << argv[1] << std::endl;
42
43    f1 = new gdcm::File( fileName );
44    if (!f1->IsReadable()) {
45        std::cerr << "Sorry, " << fileName <<"  not a Readable DICOM / ACR File"
46                  <<std::endl;
47        return 0;
48    }
49
50 // ============================================================
51 //   Don't load the pixels in memory.
52 //   Overwrite the file
53 // ============================================================
54
55 // First, we set values to replace the ones we want to hide
56   
57    // Patient's name 
58    f1->AddAnonymizeElement(0x0010, 0x0010, "Tartempion");   
59    // Patient's ID
60    f1->AddAnonymizeElement( 0x0010, 0x0020,"007" );   
61    // Study Instance UID
62    f1->AddAnonymizeElement(0x0020, 0x000d, "6.66.666.6666" );
63
64 // --------------------- we overwrite the file
65
66 // No need to load the pixels.
67 // The gdcm::File remains untouched in memory
68
69    f1->AnonymizeNoLoad();
70
71 // No need to write the File : modif were done on disc !
72
73 // ============================================================
74 //   Load the pixels in memory.
75 //   Write a new file
76 // ============================================================
77
78    // We need a gdcm::FileHelper, since we want to load the pixels        
79    gdcm::FileHelper *fh1 = new gdcm::FileHelper(f1);
80
81 // --- Don't forget to load the Pixels ...
82 // (unit8_t DOESN'T mean it's mandatory for the image to be a 8 bits one) 
83
84    //uint8_t *imageData= fh1->GetImageData();
85    fh1->GetImageData();
86
87    // Institution name 
88    f1->AddAnonymizeElement(0x0008, 0x0080, "Xanadoo"); 
89    // Patient's name 
90    f1->AddAnonymizeElement(0x0010, 0x0010, "Fantomas");   
91    // Patient's ID
92    f1->AddAnonymizeElement( 0x0010, 0x0020,"1515" );   
93    // Study Instance UID
94    f1->AddAnonymizeElement(0x0020, 0x000d, "9.99.999.9999" );
95    // Telephone
96    f1->AddAnonymizeElement(0x0010, 0x2154, "3615" );
97
98    f1->AnonymizeFile();
99  
100    fh1->WriteDcmExplVR(outputFileName);
101
102   //If we reach here everything is fine, return 0 then:
103   
104    f1->ClearAnonymizeList();    
105    delete f1;
106    delete fh1; 
107   return 0;
108 }
109