]> Creatis software - gdcm.git/blob - Example/exAnonymizeNoLoad.cxx
I tried to make a Test for gdcm::Exception
[gdcm.git] / Example / exAnonymizeNoLoad.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: exAnonymizeNoLoad.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/02/08 18:02:03 $
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 #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    std::cout << "------------------------------------------------" << std::endl;
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  
37    if( argc < 3 )
38     {
39     std::cerr << "Usage " << argv[0] << " Source image.dcm  " 
40               << " Output image.dcm " << std::endl;
41     return 1;
42     }
43
44    std::string fileName       = argv[1];
45    std::string outputFileName = argv[2];
46
47 // ============================================================
48 //   Read the input image.
49 // ============================================================
50
51    std::cout << argv[1] << std::endl;
52
53    f1 = new gdcm::File( fileName );
54    if (!f1->IsReadable()) {
55        std::cerr << "Sorry, " << fileName <<"  not a gdcm-readable "
56            << "DICOM / ACR File"
57                  <<std::endl;
58    }
59    std::cout << " ... is readable " << std::endl;
60
61 // ============================================================
62 //   No need to load the pixels in memory.
63 //   File will be overwritten
64 // ============================================================
65
66
67 // ============================================================
68 //  Choose the fields to anonymize.
69 // ============================================================
70    // Institution name 
71    f1->AddAnonymizeElement(0x0008, 0x0080, "Xanadoo"); 
72    // Patient's name 
73    f1->AddAnonymizeElement(0x0010, 0x0010, "Fantomas");   
74    // Patient's ID
75    f1->AddAnonymizeElement( 0x0010, 0x0020,"1515" );   
76    // Study Instance UID
77    f1->AddAnonymizeElement(0x0020, 0x000d, "9.99.999.9999" );
78    // Telephone
79    f1->AddAnonymizeElement(0x0010, 0x2154, "3615" );
80   // Aware use will add new fields here
81
82
83 // No need to load the pixels.
84
85
86 // ============================================================
87 //   Overwrite the file
88 // ============================================================
89
90    std::cout <<"Let's AnonymizeNoLoad " << std::endl;;
91
92 // The gdcm::File remains untouched in memory
93
94    f1->AnonymizeNoLoad();
95
96 // No need to write the File : modif were done on disc !
97 // File was overwritten ...
98
99    std::cout <<"End AnonymizeNoLoad" << std::endl;
100
101 // ============================================================
102 //   Remove the Anonymize list
103 // ============================================================  
104    f1->ClearAnonymizeList();
105     
106    delete f1;
107    return 0;
108 }
109