Medical Imaging Interaction Toolkit  2018.4.99-1bab67a2
Medical Imaging Interaction Toolkit
mitkModelFitCmdAppsHelper.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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 
15 
16 std::string sanitizeString(const std::string& path)
17 {
18  auto result = path;
19  std::string illegalChars = "\\/:?\"<>|%* ";
20  for (auto &c : result)
21  {
22  bool found = illegalChars.find(c) != std::string::npos;
23  if (found){
24  c = '_';
25  }
26  }
27  return result;
28 }
29 
30 MITKMODELFIT_EXPORT std::string mitk::generateModelFitResultImagePath(const std::string& outputPathTemplate, const std::string& parameterName)
31 {
32  std::string ext = ::itksys::SystemTools::GetFilenameLastExtension(outputPathTemplate);
33 
34  std::string dir = itksys::SystemTools::GetFilenamePath(outputPathTemplate);
35  dir = itksys::SystemTools::ConvertToOutputPath(dir);
36 
37  std::string rootName = itksys::SystemTools::GetFilenameWithoutLastExtension(outputPathTemplate);
38 
39  std::string fileName = rootName + "_" + sanitizeString(parameterName) + ext;
40 
41  std::string fullOutPath = itksys::SystemTools::ConvertToOutputPath(dir + "/" + fileName);
42 
43  return fullOutPath;
44 }
45 
47 {
48  switch (type)
49  {
50  case mitk::modelFit::Parameter::ParameterType: return "parameter";
51  case mitk::modelFit::Parameter::DerivedType: return "derived";
52  case mitk::modelFit::Parameter::CriterionType: return "criterion";
53  case mitk::modelFit::Parameter::EvaluationType: return "evaluation";
54  default: return "unkown";
55  }
56 }
57 
58 MITKMODELFIT_EXPORT void mitk::storeModelFitResultImage(const std::string& outputPathTemplate, const std::string& parameterName, mitk::Image* image, mitk::modelFit::Parameter::Type nodeType, const mitk::modelFit::ModelFitInfo* modelFitInfo)
59 {
60  mitk::modelFit::SetModelFitDataProperties(image, parameterName, nodeType, modelFitInfo);
61 
62  storeParameterResultImage(outputPathTemplate, parameterName, image, nodeType);
63 }
64 
65 MITKMODELFIT_EXPORT void mitk::storeParameterResultImage(const std::string& outputPathTemplate, const std::string& parameterName, mitk::Image* image, mitk::modelFit::Parameter::Type parameterType)
66 {
67  std::string fullOutPath = generateModelFitResultImagePath(outputPathTemplate, parameterName);
68 
69  mitk::IOUtil::Save(image, fullOutPath);
70 
71  std::cout << "Store result " << convertParameterTypeToStr(parameterType) << ": " << parameterName << " -> " << fullOutPath << std::endl;
72 }
73 
75 {
76  if (generator)
77  {
78  for (auto imageIterator : generator->GetParameterImages())
79  {
80  storeModelFitResultImage(outputPathTemplate, imageIterator.first, imageIterator.second, mitk::modelFit::Parameter::ParameterType, fitSession);
81  }
82  for (auto imageIterator : generator->GetDerivedParameterImages())
83  {
84  storeModelFitResultImage(outputPathTemplate, imageIterator.first, imageIterator.second, mitk::modelFit::Parameter::DerivedType, fitSession);
85  }
86  for (auto imageIterator : generator->GetCriterionImages())
87  {
88  storeModelFitResultImage(outputPathTemplate, imageIterator.first, imageIterator.second, mitk::modelFit::Parameter::CriterionType, fitSession);
89  }
90  for (auto imageIterator : generator->GetEvaluationParameterImages())
91  {
92  storeModelFitResultImage(outputPathTemplate, imageIterator.first, imageIterator.second, mitk::modelFit::Parameter::EvaluationType, fitSession);
93  }
94  }
95 }
96 
97 
99 {
100  if (generator)
101  {
102  for (auto aName : generator->GetParameterNames())
103  {
104  std::cout << "Store result " << convertParameterTypeToStr(modelFit::Parameter::ParameterType) << ": " << aName << " -> " << generateModelFitResultImagePath(outputPathTemplate, aName) << std::endl;
105  }
106  for (auto aName : generator->GetDerivedParameterNames())
107  {
108  std::cout << "Store result " << convertParameterTypeToStr(modelFit::Parameter::DerivedType) << ": " << aName << " -> " << generateModelFitResultImagePath(outputPathTemplate, aName) << std::endl;
109  }
110  for (auto aName : generator->GetCriterionNames())
111  {
112  std::cout << "Store result " << convertParameterTypeToStr(modelFit::Parameter::CriterionType) << ": " << aName << " -> " << generateModelFitResultImagePath(outputPathTemplate, aName) << std::endl;
113  }
114  for (auto aName : generator->GetEvaluationParameterNames())
115  {
116  std::cout << "Store result " << convertParameterTypeToStr(modelFit::Parameter::EvaluationType) << ": " << aName << " -> " << generateModelFitResultImagePath(outputPathTemplate, aName) << std::endl;
117  }
118  std::cout << "Preview done." << std::endl;
119  }
120 }
virtual ParameterNamesType GetDerivedParameterNames() const =0
MITKMODELFIT_EXPORT std::string generateModelFitResultImagePath(const std::string &outputPathTemplate, const std::string &parameterName)
std::string sanitizeString(const std::string &path)
std::string convertParameterTypeToStr(mitk::modelFit::Parameter::Type type)
MITKMODELFIT_EXPORT void previewModelFitGeneratorResults(const std::string &outputPathTemplate, mitk::ParameterFitImageGeneratorBase *generator)
#define MITKMODELFIT_EXPORT
MITKMODELFIT_EXPORT void SetModelFitDataProperties(mitk::BaseData *data, const ModelBase::ParameterNameType &name, modelFit::Parameter::Type dataType, const modelFit::ModelFitInfo *fitInfo)
virtual ParameterNamesType GetEvaluationParameterNames() const =0
Image class for storing images.
Definition: mitkImage.h:72
mitk::Image::Pointer image
Data class that stores all information about a modelfit that is relevant to the visualization and sto...
MITKMODELFIT_EXPORT void storeModelFitResultImage(const std::string &outputPathTemplate, const std::string &parameterName, mitk::Image *image, mitk::modelFit::Parameter::Type nodeType, const mitk::modelFit::ModelFitInfo *modelFitInfo)
virtual ParameterNamesType GetParameterNames() const =0
MITKMODELFIT_EXPORT void storeParameterResultImage(const std::string &outputPathTemplate, const std::string &parameterName, mitk::Image *image, mitk::modelFit::Parameter::Type parameterType=mitk::modelFit::Parameter::ParameterType)
static void Save(const mitk::BaseData *data, const std::string &path, bool setPathProperty=false)
Save a mitk::BaseData instance.
Definition: mitkIOUtil.cpp:774
MITKMODELFIT_EXPORT void storeModelFitGeneratorResults(const std::string &outputPathTemplate, mitk::ParameterFitImageGeneratorBase *generator, const mitk::modelFit::ModelFitInfo *fitSession)
virtual ParameterNamesType GetCriterionNames() const =0