]> Creatis software - gdcm.git/blob - Example/AnonymizeNoLoad.cxx
Typo
[gdcm.git] / Example / AnonymizeNoLoad.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: AnonymizeNoLoad.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/06/14 09:09:50 $
7   Version:   $Revision: 1.2 $
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 "gdcmArgMgr.h"
24
25 #include <iostream>
26
27 int main(int argc, char *argv[])
28 {
29    START_USAGE(usage)
30    " \n AnonymizeNoLoad :\n",
31    " Anonymize a gdcm-readable Dicom image even if pixels aren't gdcm readable",
32    "          Warning : Warning : the image is overwritten",
33    "                    to preserve image integrity, use a copy.",
34    " usage: AnonymizeNoLoad filein=inputFileName fileout=[debug] ",
35    "        debug    : user wants to run the program in 'debug mode' ",
36    FINISH_USAGE
37
38    // ----- Initialize Arguments Manager ------   
39    gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv);
40   
41    if (am->ArgMgrDefined("usage")) 
42    {
43       am->ArgMgrUsage(usage); // Display 'usage'
44       delete am;
45       return 0;
46    }
47
48    if (am->ArgMgrDefined("debug"))
49       gdcm::Debug::DebugOn();
50
51    char *fileName = am->ArgMgrWantString("filein",usage);
52
53    int loadMode;
54    if ( am->ArgMgrDefined("noshadow") && am->ArgMgrDefined("noseq") )
55        loadMode = NO_SEQ | NO_SHADOW;  
56    else if ( am->ArgMgrDefined("noshadow") )
57       loadMode = NO_SHADOW;
58    else if ( am->ArgMgrDefined("noseq") )
59       loadMode = NO_SEQ;
60    else
61       loadMode = 0;
62
63    delete am;  // we don't need Argument Manager any longer
64
65    // ============================================================
66    //   Parse the input file.
67    // ============================================================
68
69    gdcm::File *f1;
70    f1 = new gdcm::File( );
71    f1->SetLoadMode(loadMode);
72    int res = f1->Load(fileName);
73
74    // gdcm::File::IsReadable() is no usable here, because we deal with
75    // any kind of gdcm::Readable *document*
76    // not only gdcm::File (as opposed to gdcm::DicomDir)
77    if ( !res ) 
78    {
79        std::cout <<std::endl
80            << "Sorry, " << fileName <<"  not a gdcm-readable "
81            << "DICOM / ACR Document"
82            << std::endl;
83         delete f1;
84         return 1;
85    }
86    std::cout << fileName << " is readable " << std::endl;
87
88    // ============================================================
89    //   No need to load the pixels in memory.
90    //   File will be overwritten
91    // ============================================================
92
93
94    // ============================================================
95    //  Choose the fields to anonymize.
96    // ============================================================
97    // Institution name 
98    f1->AddAnonymizeElement( 0x0008, 0x0080, "Xanadoo" ); 
99    // Patient's name 
100    f1->AddAnonymizeElement( 0x0010, 0x0010, "Fantomas" );   
101    // Patient's ID
102    f1->AddAnonymizeElement( 0x0010, 0x0020,"1515" );
103    // Patient's Birthdate
104    f1->AddAnonymizeElement( 0x0010, 0x0030,"11.11.1111" );
105    // Patient's Adress
106    f1->AddAnonymizeElement( 0x0010, 0x1040,"Sing-sing" );
107    // Patient's Mother's Birth Name
108    f1->AddAnonymizeElement( 0x0010, 0x1060,"Vampirella" );   
109    // Study Instance UID
110    f1->AddAnonymizeElement( 0x0020, 0x000d, "9.99.999.9999" );
111    // Telephone
112    f1->AddAnonymizeElement(0x0010, 0x2154, "3615" );
113
114   // Aware use will add new fields here
115
116    // ============================================================
117    //   Overwrite the file
118    // ============================================================
119
120    std::cout <<"Let's AnonymizeNoLoad " << std::endl;;
121
122    // The gdcm::File remains untouched in memory
123
124    f1->AnonymizeNoLoad();
125
126    // No need to write the File : modif were done on disc !
127    // File was overwritten ...
128
129    std::cout <<"End AnonymizeNoLoad" << std::endl;
130
131    // ============================================================
132    //   Remove the Anonymize list
133    // ============================================================  
134    f1->ClearAnonymizeList();
135     
136    delete f1;
137    return 0;
138 }
139