ANIMA  4.0
animaB1GMMRelaxometryCostFunction.h
Go to the documentation of this file.
1 #pragma once
2 #include <itkSingleValuedCostFunction.h>
3 #include "AnimaRelaxometryExport.h"
4 
7 #include <animaNNLSOptimizer.h>
8 
9 #include <map>
10 
11 namespace anima
12 {
13 
20 class ANIMARELAXOMETRY_EXPORT B1GMMRelaxometryCostFunction :
21  public itk::SingleValuedCostFunction
22 {
23 public:
26  typedef itk::SingleValuedCostFunction Superclass;
27  typedef itk::SmartPointer<Self> Pointer;
28  typedef itk::SmartPointer<const Self> ConstPointer;
29 
30  itkNewMacro(Self)
31 
32 
33  itkTypeMacro(B1GMMRelaxometryCostFunction, Superclass)
34 
35  typedef Superclass::MeasureType MeasureType;
36  typedef Superclass::DerivativeType DerivativeType;
37  typedef Superclass::ParametersType ParametersType;
38  typedef std::vector < std::complex <double> > ComplexVectorType;
39  typedef std::vector <ComplexVectorType> MatrixType;
40 
41  virtual MeasureType GetValue(const ParametersType &parameters) const ITK_OVERRIDE;
42  virtual void GetDerivative(const ParametersType &parameters, DerivativeType &derivative) const ITK_OVERRIDE;
43 
44  itkSetMacro(EchoSpacing, double)
45  itkSetMacro(ExcitationFlipAngle, double)
46 
47  void SetT2RelaxometrySignals(ParametersType &relaxoSignals) {m_T2RelaxometrySignals = relaxoSignals;}
48 
49  itkSetMacro(T1Value, double)
50  void SetGaussianMeans(std::vector <double> &val) {m_GaussianMeans = val;}
51  void SetGaussianVariances(std::vector <double> &val) {m_GaussianVariances = val;}
52  itkSetMacro(GaussianIntegralTolerance, double)
53 
54  unsigned int GetNumberOfParameters() const ITK_OVERRIDE
55  {
56  return 1;
57  }
58 
59  itkGetMacro(SigmaSquare, double)
60  ParametersType &GetOptimalT2Weights() {return m_OptimalT2Weights;}
61 
62 protected:
64  {
65  m_NNLSBordersOptimizer = anima::NNLSOptimizer::New();
66 
67  m_T1Value = 1;
68  m_EchoSpacing = 1;
69  m_GaussianIntegralTolerance = 1.0e-8;
70  }
71 
73 
74  void PrepareDataForLLS() const;
75 
77  void SolveLinearLeastSquares() const;
78 
79 private:
80  B1GMMRelaxometryCostFunction(const Self&); //purposely not implemented
81  void operator=(const Self&); //purposely not implemented
82 
83  double m_EchoSpacing;
84  ParametersType m_T2RelaxometrySignals;
85  mutable ParametersType m_TestedParameters;
86 
87  double m_ExcitationFlipAngle;
88 
89  mutable ParametersType m_OptimalT2Weights;
90  double m_T1Value;
91  std::vector <double> m_GaussianMeans, m_GaussianVariances;
92  double m_GaussianIntegralTolerance;
93 
94  // Internal working variables, not thread safe but so much faster !
95  mutable anima::EPGSignalSimulator m_T2SignalSimulator;
96 
97  mutable ParametersType m_FSignals;
98  mutable ParametersType m_Residuals;
99  mutable vnl_matrix <double> m_PredictedSignalAttenuations, m_CholeskyMatrix;
100  mutable double m_SigmaSquare;
101 
102  mutable anima::NNLSOptimizer::Pointer m_NNLSBordersOptimizer;
103  mutable anima::CholeskyDecomposition m_CholeskySolver;
104 };
105 
106 } // end namespace anima
itk::SmartPointer< Self > Pointer
Cost function for estimating B1 from T2 relaxometry acquisition, following a multi-T2 EPG decay model...
STL namespace.
void SetGaussianVariances(std::vector< double > &val)
std::vector< std::complex< double > > ComplexVectorType
static Pointer New()
Cholesky decomposition: decomposes a symmetric matrix A in the form L D L^T, where L is lower triangu...