Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
HotspotMiniApp.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 "mitkImage.h"
19 #include "mitkIOUtil.h"
20 #include <iostream>
21 #include <usAny.h>
22 #include <fstream>
24 
25 
26 int main( int argc, char* argv[] )
27 {
28  mitkCommandLineParser parser;
29 
30  parser.setTitle("Test basic hotspot functionality");
31  parser.setCategory("Preprocessing Tools");
32  parser.setDescription("");
33  parser.setContributor("MBI");
34 
35  parser.setArgumentPrefix("--", "-");
36  parser.addArgument("help", "h", mitkCommandLineParser::String, "Help:", "Show this help text");
37  parser.addArgument("input", "i", mitkCommandLineParser::InputFile, "Input:", "input image", us::Any(),false);
38  parser.addArgument("mask", "m", mitkCommandLineParser::InputFile, "Mask:", "mask image / roi image denotin area on which statistics are calculated", us::Any(),true);
39  parser.addArgument("out", "o", mitkCommandLineParser::OutputFile, "Output", "output file (default: hotspotMiniApp_output.nrrd)", us::Any());
40 
41  std::cout << "test...." << std::endl;
42 
43  std::map<std::string, us::Any> parsedArgs = parser.parseArguments(argc, argv);
44  std::cout << "parsedArgs.size()= " << parsedArgs.size() << std::endl;
45  if (parsedArgs.size()==0 || parsedArgs.count("help") || parsedArgs.count("h"))
46  {
47 // std::cout << "\n\n MiniApp Description: \nCalculates and saves the hotspot of an image." << endl;
48 // std::cout << "Output is written to the designated output file" << endl;
49 // std::cout << parser.helpText();
50 // return EXIT_SUCCESS;
51  }
52 
53  // Parameters:
54  std::string inputImageFile;
55  if (!parsedArgs.count("i") && !parsedArgs.count("input"))
56  {
57  inputImageFile = "/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/Pic3D.nrrd";
58  }
59  else
60  {
61  inputImageFile = us::any_cast<std::string>(parsedArgs["input"]);
62  }
63 
64  mitk::Image::Pointer maskImage;
65  if (parsedArgs.count("mask") || parsedArgs.count("m"))
66  {
67  std::string maskImageFile = us::any_cast<std::string>(parsedArgs["mask"]);
68  maskImage = mitk::IOUtil::LoadImage(maskImageFile);
69  }
70 
71  std::string outFile;
72  if (parsedArgs.count("out") || parsedArgs.count("o") )
73  outFile = us::any_cast<std::string>(parsedArgs["out"]);
74  else
75  outFile = "hotspotMiniApp_output.nrrd";
76 
77  // Load image and mask
78  mitk::Image::Pointer inputImage = mitk::IOUtil::LoadImage(inputImageFile);
79 
80  // Calculate statistics
82  hotspotCalc->SetInputImage(inputImage);
83  hotspotCalc->SetHotspotRadiusInMM(10);
84  hotspotCalc->SetTimeStep(0);
85  mitk::Image::Pointer outImage;
86  try
87  {
88  outImage = hotspotCalc->GetMask();
89  }
90  catch( const itk::ExceptionObject& e)
91  {
92  MITK_ERROR << "Failed - ITK Exception:" << e.what();
93  return -1;
94  }
95 
96  if (outImage != nullptr)
97  {
98  mitk::IOUtil::SaveImage(outImage, outFile);
99  }
100 
101 
102  return EXIT_SUCCESS;
103 }
#define MITK_ERROR
Definition: mitkLogMacros.h:24
void setContributor(std::string contributor)
ValueType * any_cast(Any *operand)
Definition: usAny.h:377
int main(int argc, char *argv[])
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)
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