Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkTwoCompartmentExchangeModel.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 #include "mitkConvolutionHelper.h"
15 #include <fstream>
16 
18  "Two Compartment Exchange Model";
19 
24 
25 const std::string mitk::TwoCompartmentExchangeModel::UNIT_PARAMETER_F = "ml/min/100ml";
26 const std::string mitk::TwoCompartmentExchangeModel::UNIT_PARAMETER_PS = "ml/min/100ml";
29 
34 
36 
37 
38 inline double square(double a)
39 {
40  return a * a;
41 }
42 
44 {
45  return MODEL_DISPLAY_NAME;
46 };
47 
49 {
50  return "Perfusion.MR";
51 };
52 
54 {
55 
56 }
57 
59 {
60 
61 }
62 
65 {
66  ParameterNamesType result;
67 
68  result.push_back(NAME_PARAMETER_F);
69  result.push_back(NAME_PARAMETER_PS);
70  result.push_back(NAME_PARAMETER_ve);
71  result.push_back(NAME_PARAMETER_vp);
72 
73  return result;
74 }
75 
78 {
79  return NUMBER_OF_PARAMETERS;
80 }
81 
84 {
85  ParamterUnitMapType result;
86 
87  result.insert(std::make_pair(NAME_PARAMETER_F, UNIT_PARAMETER_F));
88  result.insert(std::make_pair(NAME_PARAMETER_PS, UNIT_PARAMETER_PS));
89  result.insert(std::make_pair(NAME_PARAMETER_vp, UNIT_PARAMETER_vp));
90  result.insert(std::make_pair(NAME_PARAMETER_ve, UNIT_PARAMETER_ve));
91 
92  return result;
93 };
94 
95 
98 {
99  typedef mitk::ModelBase::ModelResultType ConvolutionResultType;
100 
101  if (this->m_TimeGrid.GetSize() == 0)
102  {
103  itkExceptionMacro("No Time Grid Set! Cannot Calculate Signal");
104  }
105 
106  AterialInputFunctionType aterialInputFunction;
107  aterialInputFunction = GetAterialInputFunction(this->m_TimeGrid);
108 
109  unsigned int timeSteps = this->m_TimeGrid.GetSize();
110  mitk::ModelBase::ModelResultType signal(timeSteps);
111  signal.fill(0.0);
112 
113  //Model Parameters
114  double F = parameters[POSITION_PARAMETER_F] / 6000.0;
115  double PS = parameters[POSITION_PARAMETER_PS] / 6000.0;
116  double ve = parameters[POSITION_PARAMETER_ve];
117  double vp = parameters[POSITION_PARAMETER_vp];
118 
119  if(PS != 0)
120  {
121  double Tp = vp/(PS + F);
122  double Te = ve/PS;
123  double Tb = vp/F;
124 
125  double Kp = 0.5 *( 1/Tp + 1/Te + sqrt(( 1/Tp + 1/Te )*( 1/Tp + 1/Te ) - 4 * 1/Te*1/Tb) );
126  double Km = 0.5 *( 1/Tp + 1/Te - sqrt(( 1/Tp + 1/Te )*( 1/Tp + 1/Te ) - 4 * 1/Te*1/Tb) );
127 
128  double E = ( Kp - 1/Tb )/( Kp - Km );
129 
130 
131 
132  ConvolutionResultType expp = mitk::convoluteAIFWithExponential(this->m_TimeGrid, aterialInputFunction,Kp);
133  ConvolutionResultType expm = mitk::convoluteAIFWithExponential(this->m_TimeGrid, aterialInputFunction,Km);
134 
135  //Signal that will be returned by ComputeModelFunction
136 
137  mitk::ModelBase::ModelResultType::const_iterator exppPos = expp.begin();
138  mitk::ModelBase::ModelResultType::const_iterator expmPos = expm.begin();
139 
140  for( mitk::ModelBase::ModelResultType::iterator signalPos = signal.begin(); signalPos!=signal.end(); ++exppPos,++expmPos, ++signalPos)
141  {
142  *signalPos = F * ( *exppPos + E*(*expmPos - *exppPos) );
143  }
144  }
145 
146 
147  else
148  {
149  double Kp = F/vp;
150  ConvolutionResultType exp = mitk::convoluteAIFWithExponential(this->m_TimeGrid, aterialInputFunction,Kp);
151  mitk::ModelBase::ModelResultType::const_iterator expPos = exp.begin();
152 
153  for( mitk::ModelBase::ModelResultType::iterator signalPos = signal.begin(); signalPos!=signal.end(); ++expPos, ++signalPos)
154  {
155  *signalPos = F * ( *expPos );
156  }
157 
158  }
159 
160  return signal;
161 }
162 
163 
164 itk::LightObject::Pointer mitk::TwoCompartmentExchangeModel::InternalClone() const
165 {
167 
168  newClone->SetTimeGrid(this->m_TimeGrid);
169 
170  return newClone.GetPointer();
171 }
172 
173 void mitk::TwoCompartmentExchangeModel::PrintSelf(std::ostream& os, ::itk::Indent indent) const
174 {
175  Superclass::PrintSelf(os, indent);
176 
177 
178 }
179 
180 
ParametersSizeType GetNumberOfParameters() const override
itk::LightObject::Pointer InternalClone() const override
ModelTraitsInterface::ParametersType ParametersType
Definition: mitkModelBase.h:59
TimeGridType m_TimeGrid
double square(double a)
void PrintSelf(std::ostream &os, ::itk::Indent indent) const override
const AterialInputFunctionType GetAterialInputFunction(TimeGridType currentTimeGrid) const
ParamterUnitMapType GetParameterUnits() const override
ModelTraitsInterface::ParametersSizeType ParametersSizeType
Definition: mitkModelBase.h:65
ModelTraitsInterface::ModelResultType ModelResultType
Definition: mitkModelBase.h:55
itk::Array< double > AterialInputFunctionType
ModelResultType ComputeModelfunction(const ParametersType &parameters) const override
void PrintSelf(std::ostream &os, ::itk::Indent indent) const override
ModelTraitsInterface::ParameterNamesType ParameterNamesType
Definition: mitkModelBase.h:64
itk::Array< double > convoluteAIFWithExponential(mitk::ModelBase::TimeGridType timeGrid, mitk::AIFBasedModelBase::AterialInputFunctionType aif, double lambda)
std::map< ParameterNameType, std::string > ParamterUnitMapType
ParameterNamesType GetParameterNames() const override