]> Creatis software - gdcm.git/blob - Example/exAnonymizeNoLoad.cxx
AnonymizeNoLoad has now one more option :
[gdcm.git] / Example / exAnonymizeNoLoad.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: exAnonymizeNoLoad.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/07/07 17:31:54 $
7   Version:   $Revision: 1.9 $
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 *f;
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
51    f = new gdcm::File( );
52    f->SetLoadMode(NO_SEQ - NO_SHADOW);
53    f->SetFileName( fileName );
54    bool res = f->Load(); 
55
56    // gdcm::File::IsReadable() is no usable here, because we deal with
57    // any kind of gdcm::Readable *document*
58    // not only gdcm::File (as opposed to gdcm::DicomDir)
59    if ( !res ) {
60        std::cout <<std::endl
61            << "Sorry, " << fileName <<"  not a gdcm-readable "
62            << "DICOM / ACR Document"
63            <<std::endl;
64         return 1;
65    }
66    std::cout << argv[1] << " is readable " << std::endl;
67
68 // ============================================================
69 //   No need to load the pixels in memory.
70 //   File will be overwritten
71 // ============================================================
72
73
74 // ============================================================
75 //  Choose the fields to anonymize.
76 // ============================================================
77    // Institution name 
78    f->AddAnonymizeElement( 0x0008, 0x0080, "Xanadoo" ); 
79    // Patient's name 
80    f->AddAnonymizeElement( 0x0010, 0x0010, "Fantomas" );   
81    // Patient's ID
82    f->AddAnonymizeElement( 0x0010, 0x0020,"1515" );
83    // Patient's Birthdate
84    f->AddAnonymizeElement( 0x0010, 0x0030,"11.11.1111" );
85    // Patient's Adress
86    f->AddAnonymizeElement( 0x0010, 0x1040,"Sing-sing" );
87    // Patient's Mother's Birth Name
88    f->AddAnonymizeElement( 0x0010, 0x1060,"Vampirella" );   
89    // Study Instance UID
90    f->AddAnonymizeElement( 0x0020, 0x000d, "9.99.999.9999" );
91    // Telephone
92    f->AddAnonymizeElement(0x0010, 0x2154, "3615" );
93   // Aware use will add new fields here
94
95
96 // No need to load the pixels.
97
98
99 // ============================================================
100 //   Overwrite the file
101 // ============================================================
102
103    std::cout <<"Let's AnonymizeNoLoad " << std::endl;;
104
105 // The gdcm::File remains untouched in memory
106
107    f->AnonymizeNoLoad();
108
109 // No need to write the File : modif were done on disc !
110 // File was overwritten ...
111
112    std::cout <<"End AnonymizeNoLoad" << std::endl;
113
114 // ============================================================
115 //   Remove the Anonymize list
116 // ============================================================  
117    f->ClearAnonymizeList();
118     
119    delete f;
120    return 0;
121 }
122