Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
FiberJoin.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 "MiniAppManager.h"
18 #include <mitkBaseDataIOFactory.h>
19 #include <metaCommand.h>
20 #include "ctkCommandLineParser.h"
21 #include <usAny.h>
22 #include <mitkIOUtil.h>
23 #include <boost/lexical_cast.hpp>
24 #include <mitkCoreObjectFactory.h>
25 #include <mitkPlanarFigure.h>
27 #include <mitkFiberBundle.h>
28 
29 #define _USE_MATH_DEFINES
30 #include <math.h>
31 
35 int FiberJoin(int argc, char* argv[])
36  {
37  mitkCommandLineParser parser;
38 
39  parser.setTitle("Fiber Join");
40  parser.setCategory("Fiber Tracking and Processing Methods");
41  parser.setContributor("MBI");
42  parser.setDescription("Join multiple tractograms");
43 
44  parser.setArgumentPrefix("--", "-");
45  parser.addArgument("input", "i", mitkCommandLineParser::StringList, "Input:", "input tractograms (.fib, vtk file format)", us::Any(), false);
46  parser.addArgument("out", "o", mitkCommandLineParser::String, "Output:", "output tractogram", us::Any(), false);
47 
48  map<string, us::Any> parsedArgs = parser.parseArguments(argc, argv);
49  if (parsedArgs.size()==0)
50  return EXIT_FAILURE;
51 
53  string outFib = us::any_cast<string>(parsedArgs["out"]);
54 
55  if (inFibs.size()<=1)
56  {
57  std::cout << "More than one input tractogram required!";
58  return EXIT_FAILURE;
59  }
60 
61  try
62  {
63  mitk::FiberBundle::Pointer result = dynamic_cast<mitk::FiberBundle*>(mitk::IOUtil::LoadDataNode(inFibs.at(0))->GetData());
64  for (int i=1; i<inFibs.size(); i++)
65  {
66  try
67  {
68  mitk::FiberBundle::Pointer inputTractogram = dynamic_cast<mitk::FiberBundle*>(mitk::IOUtil::LoadDataNode(inFibs.at(i))->GetData());
69  result = result->AddBundle(inputTractogram);
70  }
71  catch(...){ std::cout << "could not load: " << inFibs.at(i); }
72  }
73  mitk::IOUtil::SaveBaseData(result, outFib);
74  }
75  catch (itk::ExceptionObject e)
76  {
77  std::cout << e;
78  return EXIT_FAILURE;
79  }
80  catch (std::exception e)
81  {
82  std::cout << e.what();
83  return EXIT_FAILURE;
84  }
85  catch (...)
86  {
87  std::cout << "ERROR!?!";
88  return EXIT_FAILURE;
89  }
90  return EXIT_SUCCESS;
91 }
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)
T::Pointer GetData(const std::string &name)
int FiberJoin(int argc, char *argv[])
Join multiple tractograms.
Definition: FiberJoin.cpp:35
static bool SaveBaseData(mitk::BaseData *data, const std::string &path)
SaveBaseData Convenience method to save arbitrary baseData.
Definition: mitkIOUtil.cpp:888
RegisterDiffusionMiniApp(FiberJoin)
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
Base Class for Fiber Bundles;.
void setCategory(std::string category)
static mitk::DataNode::Pointer LoadDataNode(const std::string &path)
LoadDataNode Method to load an arbitrary DataNode.
Definition: mitkIOUtil.cpp:586
void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix)
std::vector< std::string > StringContainerType
void setTitle(std::string title)
void setDescription(std::string description)