]> Creatis software - gdcm.git/blob - Example/exAnonymizeNoLoad.cxx
a5d3de75cef24fa173bff234f13b83f3d9ea8a6b
[gdcm.git] / Example / exAnonymizeNoLoad.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: exAnonymizeNoLoad.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/05/03 10:40:28 $
7   Version:   $Revision: 1.6 $
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 #include "gdcmDebug.h"
22
23 #include <iostream>
24
25 int main(int argc, char *argv[])
26 {  
27    gdcm::File *f1;
28     
29    gdcm::Debug::DebugOn();
30
31    std::cout << "Anonymize a gdcm-readable Dicom image"            << std::endl;
32    std::cout << "even if pixels are not gdcm readable (JPEG2000)"  << std::endl;
33    std::cout << "Warning : the image is overwritten"               << std::endl;
34    std::cout << "        : to preserve image integrity,"
35              << " use exAnonymize "                                << std::endl;
36    std::cout << "------------------------------------------------" << std::endl;
37  
38    if( argc < 2 )
39     {
40     std::cerr << "Usage " << argv[0] << " Source Document  " 
41               << std::endl;
42     return 1;
43     }
44
45    std::string fileName       = argv[1];
46
47 // ============================================================
48 //   Read the input image.
49 // ============================================================
50    bool res;
51
52    f1 = new gdcm::File( );
53    f1->SetLoadMode(NO_SEQ - NO_SHADOW);
54    res = f1->Load(fileName);
55    // IsReadable() is no usable here, because we deal with
56    // any kind of gdcm::Readable *document* (no only gdcm::File)
57    if (res) {
58        std::cout <<std::endl
59            << "Sorry, " << fileName <<"  not a gdcm-readable "
60            << "DICOM / ACR Document"
61            <<std::endl;
62         return 1;
63    }
64    std::cout << argv[1] << " is readable " << std::endl;
65
66 // ============================================================
67 //   No need to load the pixels in memory.
68 //   File will be overwritten
69 // ============================================================
70
71
72 // ============================================================
73 //  Choose the fields to anonymize.
74 // ============================================================
75    // Institution name 
76    f1->AddAnonymizeElement( 0x0008, 0x0080, "Xanadoo" ); 
77    // Patient's name 
78    f1->AddAnonymizeElement( 0x0010, 0x0010, "Fantomas" );   
79    // Patient's ID
80    f1->AddAnonymizeElement( 0x0010, 0x0020,"1515" );
81    // Patient's Birthdate
82    f1->AddAnonymizeElement( 0x0010, 0x0030,"11.11.1111" );
83    // Patient's Adress
84    f1->AddAnonymizeElement( 0x0010, 0x1040,"Sing-sing" );
85    // Patient's Mother's Birth Name
86    f1->AddAnonymizeElement( 0x0010, 0x1060,"Vampirella" );   
87    // Study Instance UID
88    f1->AddAnonymizeElement( 0x0020, 0x000d, "9.99.999.9999" );
89    // Telephone
90    f1->AddAnonymizeElement(0x0010, 0x2154, "3615" );
91   // Aware use will add new fields here
92
93
94 // No need to load the pixels.
95
96
97 // ============================================================
98 //   Overwrite the file
99 // ============================================================
100
101    std::cout <<"Let's AnonymizeNoLoad " << std::endl;;
102
103 // The gdcm::File remains untouched in memory
104
105    f1->AnonymizeNoLoad();
106
107 // No need to write the File : modif were done on disc !
108 // File was overwritten ...
109
110    std::cout <<"End AnonymizeNoLoad" << std::endl;
111
112 // ============================================================
113 //   Remove the Anonymize list
114 // ============================================================  
115    f1->ClearAnonymizeList();
116     
117    delete f1;
118    return 0;
119 }
120