Toast++  1.0.2 (r.539)
Forward and inverse modelling in optical tomography
solution.h
1 // -*-C++-*-
2 // ==========================================================================
3 // Solution class
4 // ==========================================================================
5 
6 #ifndef __SOLUTION_H
7 #define __SOLUTION_H
8 
9 #include "mathlib.h"
10 
11 // definition of parameters for standard OT
12 #define OT_NPARAM 4
13 #define OT_CMUA 0
14 #define OT_CKAPPA 1
15 #define OT_C2A 2
16 #define OT_N 3
17 
18 // definition of parameters for fluorescence imaging
19 #define FLU_NPARAM 7
20 #define FLU_CMUA_EX 0
21 #define FLU_CKAPPA_EX 1
22 #define FLU_C2A_EX 2
23 #define FLU_CMUA_FL 3
24 #define FLU_CKAPPA_FL 4
25 #define FLU_C2A_FL 5
26 #define FLU_YIELD 6
27 
28 // =========================================================================
29 // Prototypes
30 
31 class STOASTLIB Solution;
32 
33 STOASTLIB double l2norm (const Solution &sol);
34 STOASTLIB Solution exp (const Solution &sol);
35 STOASTLIB Solution log (const Solution &sol);
36 
37 // =========================================================================
38 
39 class STOASTLIB Solution {
40  friend class Raster;
41 
42 public:
43  //enum PARAM { CMUA, CKAPPA, C2A };
44 
45  Solution (int nparam, int n);
46  Solution (const Solution &sol);
47  ~Solution();
48 
49  int nParam() const { return nprm; }
50  void SetParam (int which, const RVector &prm);
51  void SetParam (int which, double prm) { param[which] = prm; }
52  void Set (const RVector &prm);
53  const RVector GetParam (int which) const;
54 
55  const RVector GetActiveParams () const;
56  // returns concatenated vector of all active parameters
57 
58  void SetActiveParams (const RVector &prm);
59  // set active parameters from concatenated vector
60 
61  void SetActive (int which, bool act);
62  inline bool IsActive (int which) const { return active[which]; }
63  inline int nActive() const { return nactive; }
64 
65  int ActiveDim() const;
66  // returns the summed dimensions of all active components
67 
68  void Extents (int which, double &vmin, double &vmax) const;
69  bool Bounded (int which, double vmin, double vmax);
70  bool Valid ();
71 
72  //void SetParameterScale (PARAM which, double scale);
73  //void ScaleParams ();
74  //void UnscaleParams ();
75 
76  void Scale (int which, double factor);
77  void Add (const Solution &sol);
78  void vmul (const Solution &sol);
79  void vmul (const RVector &v) const;
80  Solution &operator= (const Solution &sol);
81 
82  Solution operator* (double s) const;
83  Solution &operator*= (double s);
84  // multiplication of _active_ parameters with s
85 
86  Solution operator+ (const Solution &sol) const;
87  Solution operator+ (const RVector &v) const;
88  Solution &operator*= (const RVector &v);
89  Solution &operator+= (const Solution &sol);
90  Solution &operator+= (const RVector &v);
91 
92  void WriteImgGeneric (int imgno, const char *filename,
93  int prmind, bool append = true);
94  // write param[prmind] to image file
95 
96  static void WriteImgGeneric (int imgno, const char *filename,
97  const RVector &img, bool append = true);
98  // write img to image file
99 
100  void WriteImg_mua (int imgno, const char *nimname, bool append = true);
101  void WriteImg_mus (int imgno, const char *nimname, bool append = true);
102 
103  friend STOASTLIB double l2norm (const Solution &sol);
104  friend STOASTLIB Solution exp (const Solution &sol);
105  friend STOASTLIB Solution log (const Solution &sol);
106 
107 protected:
108  int nprm; // number of components
109  RVector *param; // parameter components
110  bool *active; // activation flag
111  int nactive; // number of active components
112 };
113 
114 inline Solution log (const Solution &sol)
115 {
116  Solution res(sol);
117  for (int i = 0; i < sol.nprm; i++)
118  if (res.active[i]) res.param[i] = log(sol.param[i]);
119  return res;
120 }
121 
122 typedef Solution(*ParamTransform)(const Solution &sol);
123 
124 #endif // !__SOLUTION_H
Base class for mapping between mesh and an independent basis representation.
Definition: raster.h:20
Definition: solution.h:39