ANIMA  4.0
animaB1GammaMixtureT2RelaxometryCostFunction.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "AnimaRelaxometryExport.h"
4 
5 #include <vector>
6 #include <itkSingleValuedCostFunction.h>
7 #include <vnl/vnl_matrix.h>
8 
11 #include <animaNNLSOptimizer.h>
12 #include <animaBaseTensorTools.h>
13 
14 namespace anima
15 {
16 
17 class ANIMARELAXOMETRY_EXPORT B1GammaMixtureT2RelaxometryCostFunction :
18  public itk::SingleValuedCostFunction
19 {
20 public:
23  typedef SingleValuedCostFunction Superclass;
24  typedef itk::SmartPointer<Self> Pointer;
25  typedef itk::SmartPointer<const Self> ConstPointer;
26 
27  itkNewMacro(Self)
28 
29 
30  itkTypeMacro(B1GammaMixtureT2RelaxometryCostFunction, SingleValuedCostFunction)
31 
32  typedef Superclass::MeasureType MeasureType;
33  typedef Superclass::DerivativeType DerivativeType;
34  typedef vnl_matrix <double> MatrixType;
35  typedef Superclass::ParametersType ParametersType;
36 
39 
45  virtual MeasureType GetValue(const ParametersType & parameters) const ITK_OVERRIDE;
46  virtual void GetDerivative(const ParametersType & parameters, DerivativeType & derivative) const ITK_OVERRIDE;
47 
48  itkSetMacro(EchoSpacing, double)
49  itkSetMacro(ExcitationFlipAngle, double)
50 
51  void SetT2RelaxometrySignals(ParametersType &relaxoSignals) {m_T2RelaxometrySignals = relaxoSignals;}
52 
53  itkSetMacro(T1Value, double)
54  void SetGammaMeans(std::vector <double> &val) {m_GammaMeans = val;}
55  void SetGammaVariances(std::vector <double> &val) {m_GammaVariances = val;}
56 
57  itkSetMacro(GammaIntegralTolerance, double)
58  itkSetMacro(ConstrainedParameters, bool)
59 
60  unsigned int GetNumberOfParameters() const ITK_OVERRIDE
61  {
62  if (m_ConstrainedParameters)
63  return 2;
64  else
65  return 4;
66  }
67 
68  itkGetMacro(SigmaSquare, double)
69  ParametersType &GetOptimalT2Weights() {return m_OptimalT2Weights;}
70 
71 protected:
73  {
74  m_NNLSBordersOptimizer = anima::NNLSOptimizer::New();
75  m_leCalculator = LECalculatorType::New();
76 
77  m_T1Value = 1;
78  m_EchoSpacing = 1;
79  }
80 
82 
83  void PrepareDataForLLS() const;
84  void PrepareDataForDerivative() const;
85 
87  void SolveLinearLeastSquares() const;
88 
89 private:
90  ITK_DISALLOW_COPY_AND_ASSIGN(B1GammaMixtureT2RelaxometryCostFunction);
91 
92  double m_EchoSpacing;
93 
94  ParametersType m_T2RelaxometrySignals;
95  mutable ParametersType m_TestedParameters;
96  bool m_ConstrainedParameters;
97 
98  double m_ExcitationFlipAngle;
99 
100  mutable ParametersType m_OptimalT2Weights;
101  double m_T1Value;
102 
103  mutable std::vector <double> m_GammaMeans, m_GammaVariances;
104  double m_GammaIntegralTolerance;
105 
106  // Internal working variables, not thread safe but so much faster !
107  mutable anima::EPGSignalSimulator m_T2SignalSimulator;
108 
109  mutable ParametersType m_FSignals;
110  mutable ParametersType m_Residuals;
111  mutable vnl_matrix <double> m_PredictedSignalAttenuations, m_CholeskyMatrix;
112  mutable double m_SigmaSquare;
113 
114  mutable std::vector <MatrixType> m_SignalAttenuationsJacobian;
115  mutable MatrixType m_GramMatrix, m_InverseGramMatrix, m_FMatrixInverseG;
116  mutable std::vector <bool> m_CompartmentSwitches;
117 
118  mutable anima::NNLSOptimizer::Pointer m_NNLSBordersOptimizer;
119  mutable anima::CholeskyDecomposition m_CholeskySolver;
120 
121  LECalculatorPointer m_leCalculator;
122 };
123 
124 } // end namespace anima
itk::SmartPointer< Self > Pointer
STL namespace.
static Pointer New()
Cholesky decomposition: decomposes a symmetric matrix A in the form L D L^T, where L is lower triangu...