Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkModelFitResultHelper.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 #include <mitkDataStorage.h>
16 #include <mitkUIDGenerator.h>
17 
19 #include "mitkModelFitConstants.h"
20 #include "mitkModelFitInfo.h"
21 
24 
25 namespace mitk
26 {
27  namespace modelFit
28  {
30  {
31  assert(data);
32 
33  if (!data)
34  {
35  mitkThrow() << "Cannot add model or fit properties to data instance. Passed data instance is null. parameter name:" << name;
36  }
37 
38  if (!fitInfo)
39  {
40  mitkThrow() << "Cannot add model or fit properties to data. Passed fit info instance is null. parameter name:" << name;
41  }
42 
43  data->GetPropertyList()->SetStringProperty(ModelFitConstants::PARAMETER_NAME_PROPERTY_NAME().c_str(),name.c_str());
44 
45  if (dataType == modelFit::Parameter::ParameterType)
46  {
48  }
49  else if (dataType == modelFit::Parameter::DerivedType)
50  {
52  }
53  else if (dataType == modelFit::Parameter::CriterionType)
54  {
56  }
57  else if (dataType == modelFit::Parameter::EvaluationType)
58  {
60  }
61 
62 
64  {
65  modelFit::Parameter::ConstPointer param = fitInfo->GetParameter(name,dataType);
66 
67  if (param.IsNull())
68  {
69  mitkThrow() << "Cannot generate model fit result data. Parameter name is not part of the model fit info. Parameter name: "<<name;
70  }
71 
72  if (!param->unit.empty())
73  {
74  data->GetPropertyList()->SetStringProperty(ModelFitConstants::PARAMETER_UNIT_PROPERTY_NAME().c_str(), param->unit.c_str());
75  }
76 
77  if (param->scale != 1.0)
78  {
79  data->GetPropertyList()->SetFloatProperty(ModelFitConstants::PARAMETER_SCALE_PROPERTY_NAME().c_str(), param->scale);
80  }
81  }
82 
83  };
84 
86  {
87  assert(data);
88 
89  if (!data)
90  {
91  mitkThrow() << "Cannot add model or fit properties to data. Passed data instance is null.";
92  }
93 
94  if (!fitInfo)
95  {
96  mitkThrow() << "Cannot add model or fit properties to data. Passed model traits instance is null.";
97  }
98 
99  //model section
100  data->GetPropertyList()->SetStringProperty(ModelFitConstants::MODEL_TYPE_PROPERTY_NAME().c_str(), fitInfo->modelType.c_str());
101  data->GetPropertyList()->SetStringProperty(ModelFitConstants::MODEL_NAME_PROPERTY_NAME().c_str(), fitInfo->modelName.c_str());
102 
103  data->GetPropertyList()->SetStringProperty(ModelFitConstants::MODEL_FUNCTION_CLASS_PROPERTY_NAME().c_str(), fitInfo->functionClassID.c_str());
104  if(!(fitInfo->function.empty()))
105  {
106  data->GetPropertyList()->SetStringProperty(ModelFitConstants::MODEL_FUNCTION_PROPERTY_NAME().c_str(), fitInfo->function.c_str());
107  data->GetPropertyList()->SetStringProperty(ModelFitConstants::MODEL_X_PROPERTY_NAME().c_str(), fitInfo->x.c_str());
108  }
109 
110  //axis section
111  if (!fitInfo->xAxisName.empty())
112  {
113  data->GetPropertyList()->SetStringProperty(ModelFitConstants::XAXIS_NAME_PROPERTY_NAME().c_str(), fitInfo->xAxisName.c_str());
114  }
115 
116  if (!fitInfo->xAxisUnit.empty())
117  {
118  data->GetPropertyList()->SetStringProperty(ModelFitConstants::XAXIS_UNIT_PROPERTY_NAME().c_str(), fitInfo->xAxisUnit.c_str());
119  }
120 
121  if (!fitInfo->yAxisName.empty())
122  {
123  data->GetPropertyList()->SetStringProperty(ModelFitConstants::YAXIS_NAME_PROPERTY_NAME().c_str(), fitInfo->yAxisName.c_str());
124  }
125 
126  if (!fitInfo->yAxisUnit.empty())
127  {
128  data->GetPropertyList()->SetStringProperty(ModelFitConstants::YAXIS_UNIT_PROPERTY_NAME().c_str(), fitInfo->yAxisUnit.c_str());
129  }
130 
131  //fit section
132  data->GetPropertyList()->SetStringProperty(ModelFitConstants::FIT_UID_PROPERTY_NAME().c_str(), fitInfo->uid.c_str());
133  data->GetPropertyList()->SetStringProperty(ModelFitConstants::FIT_NAME_PROPERTY_NAME().c_str(), fitInfo->fitName.c_str());
134  data->GetPropertyList()->SetStringProperty(ModelFitConstants::FIT_TYPE_PROPERTY_NAME().c_str(), fitInfo->fitType.c_str());
135  data->GetPropertyList()->SetStringProperty(ModelFitConstants::FIT_INPUT_IMAGEUID_PROPERTY_NAME().c_str(), fitInfo->inputUID.c_str());
136 
137  if (fitInfo->inputData.GetLookupTable().size() > 0)
138  {
139  mitk::ScalarListLookupTableProperty::Pointer inputDataProp = mitk::ScalarListLookupTableProperty::New();
140  inputDataProp->SetValue(fitInfo->inputData);
141 
142  data->SetProperty(ModelFitConstants::FIT_INPUT_DATA_PROPERTY_NAME().c_str(), inputDataProp);
143  }
144 
145  if (!fitInfo->roiUID.empty())
146  {
147  data->GetPropertyList()->SetStringProperty(ModelFitConstants::FIT_INPUT_ROIUID_PROPERTY_NAME().c_str(), fitInfo->roiUID.c_str());
148  }
149 
151  };
152 
154  {
155  if (!parameterImage)
156  {
157  mitkThrow() << "Cannot generate model fit result node. Passed parameterImage is null. parameter name: "<<name;
158  }
159 
160  if (!fitInfo)
161  {
162  mitkThrow() << "Cannot generate model fit result node. Passed model traits instance is null. parameter name: "<<name;
163  }
164 
165  DataNode::Pointer result = DataNode::New();
166 
167  result->SetData(parameterImage);
168 
169  std::string nodeName = name;
170 
171  if (!fitInfo->fitName.empty())
172  {
173  nodeName = fitInfo->fitName + "_" + nodeName;
174  }
175 
176  result->SetName(nodeName);
177 
178  result->SetVisibility(false);
179 
180  return result;
181  };
182  }
183 }
184 
185 mitk::ScalarListLookupTableProperty::Pointer mitk::modelFit::ConvertStaticParametersToProperty(const mitk::modelFit::StaticParameterMap& params)
186 {
187  mitk::ScalarListLookupTableProperty::Pointer result = mitk::ScalarListLookupTableProperty::New();
188 
189  ScalarListLookupTable table;
190 
191  for(mitk::modelFit::StaticParameterMap::const_iterator pos = params.begin(); pos != params.end(); ++pos)
192  {
193  table.SetTableValue(pos->first,pos->second);
194  }
195 
196  result->SetValue(table);
197 
198  return result;
199 };
200 
202 {
203  AdaptDataPropertyToModelFit(data, fitInfo);
204  AdaptDataPropertyToParameter(data, name, dataType, fitInfo);
205 };
206 
208 {
209  if (!parameterImage)
210  {
211  mitkThrow() << "Cannot generate model fit result node. Passed parameterImage is null. parameter name: "<<name;
212  }
213 
214  if (!modelFitInfo)
215  {
216  mitkThrow() << "Cannot generate model fit result node. Passed model fit info instance is null. parameter name: "<<name;
217  }
218 
219  DataNode::Pointer result = CreateNode(name, parameterImage, modelFitInfo);
220  SetModelFitDataProperties(parameterImage, name, nodeType, modelFitInfo);
221 
222  return result;
223 };
224 
226 {
227  if (!fitInfo)
228  {
229  mitkThrow() << "Cannot store model fit results in data storage. Passed model traits instance is null.";
230  }
231 
233 
234  for (ModelFitResultImageMapType::const_iterator pos = results.begin(); pos!=results.end(); ++pos)
235  {
236  DataNode::Pointer newNode = CreateResultNode(pos->first, modelFit::Parameter::ParameterType, pos->second, fitInfo);
237  nodes.push_back(newNode);
238  }
239 
240  for (ModelFitResultImageMapType::const_iterator pos = derivedResults.begin(); pos!=derivedResults.end(); ++pos)
241  {
242  DataNode::Pointer newNode = CreateResultNode(pos->first, modelFit::Parameter::DerivedType, pos->second, fitInfo);
243  nodes.push_back(newNode);
244  }
245 
246  for (ModelFitResultImageMapType::const_iterator pos = criterionResults.begin(); pos!=criterionResults.end(); ++pos)
247  {
248  DataNode::Pointer newNode = CreateResultNode(pos->first, modelFit::Parameter::CriterionType, pos->second, fitInfo);
249  nodes.push_back(newNode);
250  }
251 
252  for (ModelFitResultImageMapType::const_iterator pos = evaluationResults.begin(); pos!=evaluationResults.end(); ++pos)
253  {
254  DataNode::Pointer newNode = CreateResultNode(pos->first, modelFit::Parameter::EvaluationType, pos->second, fitInfo);
255  nodes.push_back(newNode);
256  }
257 
258  return nodes;
259 };
260 
262 {
263  if (!storage)
264  {
265  mitkThrow() << "Cannot store model fit results in data storage. Passed storage is null.";
266  }
267 
268  for (ModelFitResultNodeVectorType::const_iterator pos = resultNodes.begin(); pos!=resultNodes.end(); ++pos)
269  {
270  storage->Add(*pos,parentNode);
271  }
272 
273  // Set DICOM properties, paramap-secific (DICOMPM) and general properties from source data (DICOMQI)
274 
275  for (ModelFitResultNodeVectorType::const_iterator pos = resultNodes.begin(); pos != resultNodes.end(); pos++)
276  {
277  mitk::DICOMQIPropertyHelper::DeriveDICOMSourceProperties(parentNode->GetData(), pos->GetPointer()->GetData());
278  mitk::DICOMPMPropertyHelper::DeriveDICOMPMProperties(pos->GetPointer()->GetData());
279  }
280 
281 
282 };
283 
static void DeriveDICOMPMProperties(BaseData *derivedDICOMImage)
static const std::string PARAMETER_TYPE_VALUE_CRITERION()
static const std::string FIT_TYPE_PROPERTY_NAME()
Data management class that handles &#39;was created by&#39; relations.
void SetTableValue(const KeyType &key, const ValueType &value)
Sets the list at the given map key to the given value.
std::map< ModelBase::ParameterNameType, Image::Pointer > ModelFitResultImageMapType
MITKMODELFIT_EXPORT void StoreResultsInDataStorage(DataStorage *storage, const ModelFitResultNodeVectorType &resultNodes, DataNode *parentNode=nullptr)
Base of all data objects.
Definition: mitkBaseData.h:37
static const std::string MODEL_TYPE_PROPERTY_NAME()
MITKMODELFIT_EXPORT mitk::ScalarListLookupTableProperty::Pointer ConvertStaticParametersToProperty(const mitk::modelFit::StaticParameterMap &params)
static const std::string YAXIS_NAME_PROPERTY_NAME()
static const std::string PARAMETER_UNIT_PROPERTY_NAME()
DataCollection - Class to facilitate loading/accessing structured data.
Parameter::ConstPointer GetParameter(const std::string &name, const Parameter::Type &type) const
Searches for the parameter with the given name and type in the fit&#39;s parameter list and returns it...
static const std::string MODEL_NAME_PROPERTY_NAME()
Data class for modelfit properties that store a map of lists (e.g. static parameters).
virtual void Add(DataNode *node, const DataStorage::SetOfObjects *parents=nullptr)=0
Adds a DataNode containing a data object to its internal storage.
StaticParameterMap staticParamMap
#define MITKMODELFIT_EXPORT
void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName="", bool fallBackOnDefaultContext=false) override
Add new or change existent property.
static const std::string FIT_UID_PROPERTY_NAME()
void AdaptDataPropertyToParameter(mitk::BaseData *data, const ModelBase::ParameterNameType &name, modelFit::Parameter::Type dataType, const modelFit::ModelFitInfo *fitInfo)
MITKMODELFIT_EXPORT DataNode::Pointer CreateResultNode(const ModelBase::ParameterNameType &name, modelFit::Parameter::Type nodeType, Image *parameterImage, const ModelFitInfo *modelFitInfo)
static const std::string MODEL_FUNCTION_PROPERTY_NAME()
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
mitk::DataNode::Pointer CreateNode(const ModelBase::ParameterNameType &name, Image *parameterImage, const ModelFitInfo *fitInfo)
static Pointer New()
static const std::string PARAMETER_TYPE_VALUE_DERIVED_PARAMETER()
static const std::string FIT_INPUT_DATA_PROPERTY_NAME()
static void DeriveDICOMSourceProperties(const BaseData *sourceDICOMImage, BaseData *derivedDICOMImage)
static const std::string XAXIS_NAME_PROPERTY_NAME()
MITKMODELFIT_EXPORT void SetModelFitDataProperties(mitk::BaseData *data, const ModelBase::ParameterNameType &name, modelFit::Parameter::Type dataType, const modelFit::ModelFitInfo *fitInfo)
#define mitkThrow()
Image class for storing images.
Definition: mitkImage.h:72
static const std::string FIT_INPUT_IMAGEUID_PROPERTY_NAME()
std::vector< DataNode::Pointer > ModelFitResultNodeVectorType
MITKMODELFIT_EXPORT ModelFitResultNodeVectorType CreateResultNodeMap(const ModelFitResultImageMapType &results, const ModelFitResultImageMapType &derivedResults, const ModelFitResultImageMapType &criterionResults, const ModelFitResultImageMapType &evaluationResults, const ModelFitInfo *fitInfo)
static const std::string MODEL_X_PROPERTY_NAME()
Data class that stores all information about a modelfit that is relevant to the visualization and sto...
ModelTraitsInterface::ParameterNameType ParameterNameType
Definition: mitkModelBase.h:63
const LookupTableType & GetLookupTable() const
Returns the map of lists.
mitk::PropertyList::Pointer GetPropertyList() const
Get the data&#39;s property list.
void AdaptDataPropertyToModelFit(mitk::BaseData *data, const modelFit::ModelFitInfo *fitInfo)
static const std::string MODEL_FUNCTION_CLASS_PROPERTY_NAME()
static const std::string PARAMETER_TYPE_VALUE_PARAMETER()
static const std::string FIT_INPUT_ROIUID_PROPERTY_NAME()
static const std::string YAXIS_UNIT_PROPERTY_NAME()
ScalarListLookupTable inputData
static const std::string FIT_STATIC_PARAMETERS_PROPERTY_NAME()
static const std::string FIT_NAME_PROPERTY_NAME()
static const std::string XAXIS_UNIT_PROPERTY_NAME()
static const std::string PARAMETER_NAME_PROPERTY_NAME()
static const std::string PARAMETER_TYPE_PROPERTY_NAME()
static const std::string PARAMETER_SCALE_PROPERTY_NAME()
static const std::string PARAMETER_TYPE_VALUE_EVALUATION_PARAMETER()
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57
MapType::const_iterator const_iterator
Needed for &#39;foreach&#39; support.