Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkModelBase.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 
13 #include "mitkModelBase.h"
14 #include "itkMacro.h"
15 
16 #include <algorithm>
17 
20 {
21  ParamterScaleMapType result;
23 
24  for (ParameterNamesType::iterator pos = names.begin(); pos != names.end(); ++pos)
25  {
26  result.insert(std::make_pair(*pos, 1.0));
27  }
28 
29  return result;
30 };
31 
34 {
35  ParamterUnitMapType result;
37 
38  for (ParameterNamesType::iterator pos = names.begin(); pos != names.end(); ++pos)
39  {
40  result.insert(std::make_pair(*pos, ""));
41  }
42 
43  return result;
44 };
45 
48 {
51 
52  for (DerivedParameterNamesType::iterator pos = names.begin(); pos != names.end(); ++pos)
53  {
54  result.insert(std::make_pair(*pos, 1.0));
55  }
56 
57  return result;
58 };
59 
62 {
65 
66  for (DerivedParameterNamesType::iterator pos = names.begin(); pos != names.end(); ++pos)
67  {
68  result.insert(std::make_pair(*pos, ""));
69  }
70 
71  return result;
72 };
73 
74 std::string
76 {
77  return this->GetClassID();
78 };
79 
80 std::string mitk::ModelBase::GetModelType() const
81 {
82  return "Unkown";
83 };
84 
86 {
87  return "";
88 };
89 
91 {
92  return this->GetNameOfClass();
93 };
94 
95 std::string mitk::ModelBase::GetXName() const
96 {
97  return "";
98 };
99 
100 std::string mitk::ModelBase::GetXAxisName() const
101 {
102  return "";
103 };
104 
105 std::string mitk::ModelBase::GetXAxisUnit() const
106 {
107  return "";
108 };
109 
110 std::string mitk::ModelBase::GetYAxisName() const
111 {
112  return "";
113 };
114 
115 std::string mitk::ModelBase::GetYAxisUnit() const
116 {
117  return "";
118 }
119 
121 {
122 }
123 
125 {
126 }
127 
129 {
130  if (parameters.size() != this->GetNumberOfParameters())
131  {
132  itkExceptionMacro("Passed parameter set has wrong size for model. Cannot evaluate model. Required size: "
133  << this->GetNumberOfParameters() << "; passed parameters: " << parameters);
134  }
135 
136  std::string error;
137 
138  if (!ValidateModel(error))
139  {
140  itkExceptionMacro("Cannot evaluate model and return signal. Model is in an invalid state. Validation error: "
141  << error);
142  }
143 
144  ModelResultType signal = ComputeModelfunction(parameters);
145 
146  return signal;
147 }
148 
149 bool mitk::ModelBase::ValidateModel(std::string& /*error*/) const
150 {
151  return true;
152 };
153 
154 
156 {
157  itkDebugMacro("setting TimeGrid to " << grid);
158 
159  if (grid.GetSize() == 0)
160  {
161  itkExceptionMacro("Time Grid Vector is empty! Set valid time grid");
162  }
163 
164  if (this->m_TimeGrid != grid)
165  {
166  this->m_TimeGrid = grid;
167  this->Modified();
168  }
169 }
170 
171 void mitk::ModelBase::PrintSelf(std::ostream& os, ::itk::Indent indent) const
172 {
173  Superclass::PrintSelf(os, indent);
174 
175  os << indent << "Time grid: " << m_TimeGrid;
176 };
177 
179  bool allParameters)
180 {
182 
183  if ((parameters.size() != names.size()) && allParameters)
184  {
185  itkExceptionMacro("Cannot set static parameter of model. Passed parameters does not define all parameters correctly. Required size:"
186  << names.size() << "; passed size: " << parameters.size());
187  }
188 
189  for (StaticParameterMapType::const_iterator pos = parameters.begin(); pos != parameters.end();
190  ++pos)
191  {
192  ParameterNamesType::iterator finding = std::find(names.begin(), names.end(), pos->first);
193 
194  if (finding == names.end())
195  {
196  itkExceptionMacro("Cannot set static parameter of model. Passed parameter name is not in the list of valid names. Passed name: "
197  << pos->first);
198  }
199  }
200 
201  //Setting is done in an other loop to ensure that the state of the model only changes if all values are valid.
202  for (StaticParameterMapType::const_iterator pos = parameters.begin(); pos != parameters.end();
203  ++pos)
204  {
205  this->SetStaticParameter(pos->first, pos->second);
206  }
207 
208 };
209 
211 {
212  StaticParameterMapType result;
214 
215  for (ParameterNamesType::const_iterator pos = names.begin(); pos != names.end(); ++pos)
216  {
218  result.insert(std::make_pair(*pos, values));
219  }
220 
221  return result;
222 };
223 
225 {
226  ParameterNamesType emptyResult;
227  return emptyResult;
228 };
229 
232 {
233  ParamterUnitMapType result;
235 
236  for (ParameterNamesType::iterator pos = names.begin(); pos != names.end(); ++pos)
237  {
238  result.insert(std::make_pair(*pos, ""));
239  }
240 
241  return result;
242 };
243 
245 {
246  return 0;
247 };
248 
250  const mitk::ModelBase::ParametersType& parameters) const
251 {
252  if (parameters.size() != this->GetNumberOfParameters())
253  {
254  itkExceptionMacro("Cannot compute derived parametes. Passed parameters does not define all parameters correctly. Required size:"
255  << this->GetNumberOfParameters() << "; passed size: " << parameters.size());
256  }
257 
258  return ComputeDerivedParameters(parameters);
259 };
260 
262  const mitk::ModelBase::ParametersType& /*parameters*/) const
263 {
264  DerivedParameterMapType emptyResult;
265  return emptyResult;
266 };
virtual bool ValidateModel(std::string &error) const
ParamterScaleMapType GetParameterScales() const override
virtual DerivedParameterMapType ComputeDerivedParameters(const ParametersType &parameters) const
ModelTraitsInterface::ParametersType ParametersType
Definition: mitkModelBase.h:59
TimeGridType m_TimeGrid
ModellClassIDType GetClassID() const override
std::map< ParameterNameType, double > DerivedParamterScaleMapType
std::map< ParameterNameType, StaticParameterValuesType > StaticParameterMapType
Definition: mitkModelBase.h:72
void SetStaticParameters(const StaticParameterMapType &parameters, bool allParameters=true)
std::map< ParameterNameType, double > ParamterScaleMapType
DerivedParameterMapType GetDerivedParameters(const ParametersType &parameters) const
DerivedParamterScaleMapType GetDerivedParameterScales() const override
virtual ParamterUnitMapType GetStaticParameterUnits() const
~ModelBase() override
StaticParameterMapType GetStaticParameters() const
itk::Array< double > TimeGridType
Definition: mitkModelBase.h:62
std::string GetXName() const override
std::string GetModelDisplayName() const override
std::string GetXAxisUnit() const override
std::string GetXAxisName() const override
virtual ParametersSizeType GetNumberOfParameters() const =0
DerivedParameterNamesType GetDerivedParameterNames() const override
void PrintSelf(std::ostream &os, ::itk::Indent indent) const override
FunctionStringType GetFunctionString() const override
virtual ParameterNamesType GetStaticParameterNames() const =0
virtual ParameterNamesType GetParameterNames() const =0
std::vector< StaticParameterValueType > StaticParameterValuesType
Definition: mitkModelBase.h:71
std::map< ParameterNameType, DerivedParameterValueType > DerivedParameterMapType
Definition: mitkModelBase.h:75
virtual ModelResultType ComputeModelfunction(const ParametersType &parameters) const =0
ModelTraitsInterface::ModelResultType ModelResultType
Definition: mitkModelBase.h:55
std::string GetModelType() const override
DerivedParametersSizeType GetNumberOfDerivedParameters() const override
ModelResultType GetSignal(const ParametersType &parameters) const
ModelTraitsInterface::DerivedParametersSizeType DerivedParametersSizeType
Definition: mitkModelBase.h:68
std::string GetYAxisName() const override
virtual StaticParameterValuesType GetStaticParameterValue(const ParameterNameType &name) const =0
ModelTraitsInterface::ParameterNamesType ParameterNamesType
Definition: mitkModelBase.h:64
virtual void SetTimeGrid(const TimeGridType &grid)
std::map< ParameterNameType, std::string > ParamterUnitMapType
ParamterUnitMapType GetParameterUnits() const override
std::string GetYAxisUnit() const override
ModelTraitsInterface::DerivedParameterNamesType DerivedParameterNamesType
Definition: mitkModelBase.h:67
virtual void SetStaticParameter(const ParameterNameType &name, const StaticParameterValuesType &values)=0
std::map< ParameterNameType, std::string > DerivedParamterUnitMapType
DerivedParamterUnitMapType GetDerivedParameterUnits() const override