1 /*=========================================================================
4 Module: $RCSfile: AnonymizeNoLoad.cxx,v $
6 Date: $Date: 2005/07/13 13:48:56 $
7 Version: $Revision: 1.5 $
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.
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.
17 =========================================================================*/
19 #include "gdcmFileHelper.h"
20 #include "gdcmCommon.h"
21 #include "gdcmDebug.h"
22 #include "gdcmDirList.h"
24 #include "gdcmArgMgr.h"
28 int main(int argc, char *argv[])
31 "\n AnonymizeNoLoad :\n",
32 "Anonymize a gdcm-readable Dicom image even if pixels aren't gdcm readable",
33 " Warning : Warning : the image is overwritten",
34 " to preserve image integrity, use a copy.",
35 "usage: AnonymizeNoLoad {filein=inputFileName|dirin=inputDirectoryName}",
36 " [ { [noshadowseq] | [noshadow][noseq] } ] [debug]",
37 " inputFileName : Name of the (single) file user wants to anonymize",
38 " inputDirectoryName : user wants to anonymize *all* the files",
39 " within the (single Patient!) directory",
40 " noshadowseq: user doesn't want to load Private Sequences",
41 " noshadow : user doesn't want to load Private groups (odd number)",
42 " noseq : user doesn't want to load Sequences ",
43 " debug : user wants to run the program in 'debug mode' ",
46 // ----- Initialize Arguments Manager ------
48 gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv);
50 if (am->ArgMgrDefined("usage"))
52 am->ArgMgrUsage(usage); // Display 'usage'
57 if (am->ArgMgrDefined("debug"))
58 gdcm::Debug::DebugOn();
60 char *fileName = am->ArgMgrGetString("filein",(char *)0);
61 char *dirName = am->ArgMgrGetString("dirin",(char *)0);
63 if ( (fileName == 0 && dirName == 0)
65 (fileName != 0 && dirName != 0) )
68 << "Either 'filein' or 'dirin' must be present;" << std::endl
69 << "Not both" << std::endl;
74 int loadMode = 0x00000000;
75 if ( am->ArgMgrDefined("noshadowseq") )
76 loadMode |= NO_SHADOWSEQ;
79 if ( am->ArgMgrDefined("noshadow") )
80 loadMode |= NO_SHADOW;
81 if ( am->ArgMgrDefined("noseq") )
85 delete am; // ------ we don't need Arguments Manager any longer ------
88 if ( fileName != 0 ) // ====== Deal with a single file ======
92 // Parse the input file.
95 f = new gdcm::File( );
96 f->SetLoadMode(loadMode);
97 f->SetFileName( fileName );
100 // gdcm::File::IsReadable() is no usable here, because we deal with
101 // any kind of gdcm::Readable *document*
102 // not only gdcm::File (as opposed to gdcm::DicomDir)
105 std::cout <<std::endl
106 << "Sorry, " << fileName <<" not a gdcm-readable "
107 << "DICOM / ACR Document"
112 std::cout << fileName << " is readable " << std::endl;
115 // No need to load the pixels in memory.
116 // File will be overwritten
121 // Choose the fields to anonymize.
125 f->AddAnonymizeElement( 0x0008, 0x0080, "Xanadoo" );
127 f->AddAnonymizeElement( 0x0010, 0x0010, "g^Fantomas" );
129 f->AddAnonymizeElement( 0x0010, 0x0020,"1515" );
130 // Patient's Birthdate
131 f->AddAnonymizeElement( 0x0010, 0x0030,"11.11.1111" );
133 f->AddAnonymizeElement( 0x0010, 0x1040,"Sing-sing" );
134 // Patient's Mother's Birth Name
135 f->AddAnonymizeElement( 0x0010, 0x1060,"g^Vampirella" );
136 // Study Instance UID
137 f->AddAnonymizeElement( 0x0020, 0x000d, "9.99.999.9999" );
139 f->AddAnonymizeElement(0x0010, 0x2154, "3615" );
141 // Aware use will add new fields here
144 // Overwrite the file
147 std::cout <<"Let's AnonymizeNoLoad " << std::endl;
149 // The gdcm::File remains untouched in memory
151 f->AnonymizeNoLoad();
153 // No need to write the File : modif were done on disc !
154 // File was overwritten ...
156 std::cout <<"End AnonymizeNoLoad" << std::endl;
159 // Remove the Anonymize list
161 f->ClearAnonymizeList();
167 else // ====== Deal with a (single Patient) Directory ======
169 std::cout << "dirName [" << dirName << "]" << std::endl;
170 gdcm::DirList dirList(dirName,1); // gets recursively the file list
171 gdcm::DirListType fileList = dirList.GetFilenames();
172 for( gdcm::DirListType::iterator it = fileList.begin();
173 it != fileList.end();
178 f = new gdcm::File( );
179 f->SetLoadMode(loadMode);
180 f->SetFileName( it->c_str() );
181 bool res = f->Load();
189 // Choose the fields to anonymize.
193 f->AddAnonymizeElement( 0x0008, 0x0080, "Xanadoo" );
195 f->AddAnonymizeElement( 0x0010, 0x0010, "g^Fantomas" );
197 f->AddAnonymizeElement( 0x0010, 0x0020,"1515" );
198 // Patient's Birthdate
199 f->AddAnonymizeElement( 0x0010, 0x0030,"11.11.1111" );
201 f->AddAnonymizeElement( 0x0010, 0x1040,"Sing-sing" );
202 // Patient's Mother's Birth Name
203 f->AddAnonymizeElement( 0x0010, 0x1060,"g^Vampirella" );
204 // Study Instance UID
205 // we may not brutaly overwrite it
206 //f->AddAnonymizeElement( 0x0020, 0x000d, "9.99.999.9999" );
208 f->AddAnonymizeElement(0x0010, 0x2154, "3615" );
210 std::cout <<"Let's AnonymizeNoLoad " << it->c_str() << std::endl;
212 // The gdcm::File remains untouched in memory
214 f->AnonymizeNoLoad();
217 // Remove the Anonymize list
220 f->ClearAnonymizeList();