fw4spl
DicomAnonymizer/src/main.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include <fwGdcmIO/helper/DicomAnonymizer.hpp>
8 
9 #include <boost/filesystem/operations.hpp>
10 #include <boost/filesystem/path.hpp>
11 #include <boost/program_options.hpp>
12 
13 #include <stdlib.h>
14 
15 #include <fstream>
16 #include <iostream>
17 #include <string>
18 
32 int main(int argc, char** argv)
33 {
34  // Declare the supported options.
35  ::boost::program_options::options_description desc("Allowed options");
36  desc.add_options()
37  ("help,h", "produce help message")
38  ("input,i", ::boost::program_options::value< std::string >(), "set input folder")
39  ("output,o", ::boost::program_options::value< std::string >(), "set output folder")
40  ;
41 
42  // Manage the options
43  ::boost::program_options::variables_map vm;
44  ::boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
45  ::boost::program_options::notify(vm);
46 
47  if (vm.count("help"))
48  {
49  std::cout << desc << std::endl;
50  return EXIT_SUCCESS;
51  }
52  else if(!vm.count("input"))
53  {
54  std::cout << "You must specify an input file." << std::endl << std::endl;
55  std::cout << desc << std::endl;
56  return EXIT_FAILURE;
57  }
58  else if(!vm.count("output"))
59  {
60  std::cout << "You must specify an output file." << std::endl << std::endl;
61  std::cout << desc << std::endl;
62  return EXIT_FAILURE;
63  }
64  else if(vm["input"].as< std::string >() == vm["output"].as< std::string >())
65  {
66  std::cout << "The output folder can not be the input folder." << std::endl;
67  return EXIT_FAILURE;
68  }
69 
70  // Get paths
71  ::boost::filesystem::path input(vm["input"].as< std::string >());
72  ::boost::filesystem::path output(vm["output"].as< std::string >());
73 
74  if(!::boost::filesystem::exists(input) || !::boost::filesystem::is_directory(input))
75  {
76  std::cout << "The specified input folder " << input << " is not a directory." << "\n";
77  return EXIT_FAILURE;
78  }
79  else if(::boost::filesystem::exists(output))
80  {
81  std::cout << "The specified output folder " << output << " already exists." << "\n";
82  return EXIT_FAILURE;
83  }
84 
85  // Copy and anonymize
88  anonymizer.anonymize(output);
89 
90  return EXIT_SUCCESS;
91 }
92 
This class contains helpers to anonymize dicom files on filesystem. Anonymization is performed accord...
static FWGDCMIO_API void copyDirectory(const ::boost::filesystem::path &input, const ::boost::filesystem::path &output)
Copy a directory recursively.
FWGDCMIO_API void anonymize(const ::boost::filesystem::path &dirPath)
Anonymize a folder containing Dicom files.