Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
CLImageConverter.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkCommandLineParser.h"
18 #include "mitkIOUtil.h"
19 
20 int main(int argc, char* argv[])
21 {
22  mitkCommandLineParser parser;
23 
24  parser.setTitle("Dicom Loader");
25  parser.setCategory("Preprocessing Tools");
26  parser.setDescription("");
27  parser.setContributor("MBI");
28 
29  parser.setArgumentPrefix("--","-");
30  // Add command line argument names
31  parser.addArgument("help", "h",mitkCommandLineParser::Bool, "Help:", "Show this help text");
32  parser.addArgument("input", "i", mitkCommandLineParser::InputDirectory, "Input file:", "Input file",us::Any(),false);
33  parser.addArgument("output", "o", mitkCommandLineParser::OutputFile, "Output file:", "Output file",us::Any(),false);
34 
35  std::map<std::string, us::Any> parsedArgs = parser.parseArguments(argc, argv);
36 
37  if (parsedArgs.size()==0)
38  return EXIT_FAILURE;
39 
40  // Show a help message
41  if ( parsedArgs.count("help") || parsedArgs.count("h"))
42  {
43  std::cout << parser.helpText();
44  return EXIT_SUCCESS;
45  }
46 
47  std::string inputName = us::any_cast<std::string>(parsedArgs["input"]);
48  std::string outputName = us::any_cast<std::string>(parsedArgs["output"]);
49 
51  mitk::IOUtil::SaveImage(image, outputName);
52 
53  return EXIT_SUCCESS;
54 }
int main(int argc, char *argv[])
void setContributor(std::string contributor)
ValueType * any_cast(Any *operand)
Definition: usAny.h:377
std::map< std::string, us::Any > parseArguments(const StringContainerType &arguments, bool *ok=nullptr)
static bool SaveImage(mitk::Image::Pointer image, const std::string &path)
SaveImage Convenience method to save an arbitrary mitkImage.
Definition: mitkIOUtil.cpp:870
void addArgument(const std::string &longarg, const std::string &shortarg, Type type, const std::string &argLabel, const std::string &argHelp=std::string(), const us::Any &defaultValue=us::Any(), bool optional=true, bool ignoreRest=false, bool deprecated=false)
Definition: usAny.h:163
void setCategory(std::string category)
void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix)
std::string helpText() const
void setTitle(std::string title)
void setDescription(std::string description)
static mitk::Image::Pointer LoadImage(const std::string &path)
LoadImage Convenience method to load an arbitrary mitkImage.
Definition: mitkIOUtil.cpp:597