Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
FileFormatConverter.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 <mitkImageCast.h>
18 #include <mitkImage.h>
19 #include <mitkIOUtil.h>
20 #include <mitkFiberBundle.h>
21 #include "mitkCommandLineParser.h"
22 
23 using namespace mitk;
24 using namespace std;
25 
29 int main(int argc, char* argv[])
30 {
31  mitkCommandLineParser parser;
32 
33  parser.setTitle("Format Converter");
34  parser.setCategory("Fiber Tracking and Processing Methods");
35  parser.setDescription("Load image and save as specified file type.");
36  parser.setContributor("MBI");
37 
38  parser.setArgumentPrefix("--", "-");
39  parser.addArgument("in", "i", mitkCommandLineParser::InputFile, "Input:", "input file", us::Any(), false);
40  parser.addArgument("out", "o", mitkCommandLineParser::OutputFile, "Output:", "output file", us::Any(), false);
41 
42  map<string, us::Any> parsedArgs = parser.parseArguments(argc, argv);
43  if (parsedArgs.size()==0)
44  return EXIT_FAILURE;
45 
46  // mandatory arguments
47  string inName = us::any_cast<string>(parsedArgs["in"]);
48  string outName = us::any_cast<string>(parsedArgs["out"]);
49 
50  try
51  {
52  std::vector<mitk::BaseData::Pointer> baseData = mitk::IOUtil::Load(inName);
53 
54  if ( baseData.size()>0 && dynamic_cast<Image*>(baseData[0].GetPointer()) )
55  {
56  mitk::IOUtil::Save(dynamic_cast<Image*>(baseData[0].GetPointer()), outName.c_str());
57  }
58  else if ( baseData.size()>0 && dynamic_cast<FiberBundle*>(baseData[0].GetPointer()) )
59  {
60  mitk::IOUtil::Save(dynamic_cast<FiberBundle*>(baseData[0].GetPointer()) ,outName.c_str());
61  }
62  else
63  std::cout << "File type currently not supported!";
64  }
65  catch (itk::ExceptionObject e)
66  {
67  std::cout << e;
68  return EXIT_FAILURE;
69  }
70  catch (std::exception e)
71  {
72  std::cout << e.what();
73  return EXIT_FAILURE;
74  }
75  catch (...)
76  {
77  std::cout << "ERROR!?!";
78  return EXIT_FAILURE;
79  }
80  return EXIT_SUCCESS;
81 }
static void Save(const mitk::BaseData *data, const std::string &path)
Save a mitk::BaseData instance.
Definition: mitkIOUtil.cpp:824
void setContributor(std::string contributor)
STL namespace.
DataCollection - Class to facilitate loading/accessing structured data.
ValueType * any_cast(Any *operand)
Definition: usAny.h:377
std::map< std::string, us::Any > parseArguments(const StringContainerType &arguments, bool *ok=nullptr)
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)
Image class for storing images.
Definition: mitkImage.h:76
Definition: usAny.h:163
Base Class for Fiber Bundles;.
void setCategory(std::string category)
void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix)
int main(int argc, char *argv[])
Load image and save as specified file type.
static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage)
Load a file into the given DataStorage.
Definition: mitkIOUtil.cpp:483
void setTitle(std::string title)
void setDescription(std::string description)