Toast++  1.0.2 (r.539)
Forward and inverse modelling in optical tomography
param.h
1 // -*-C++-*-
2 // ==========================================================================
3 // TOAST package v14 - FEM library
4 // Martin Schweiger and Simon R. Arridge
5 // param.h
6 //
7 // Description:
8 // * Declaration of class Parameter: holds a single set of optical parameters
9 // (mua, kappa, n) and defines related methods
10 // * Declaration of class ParameterList: holds a list of parameter sets, e.g.
11 // for all nodes (or elements) of a mesh. Contains methods to read and write
12 // a list from/to a stream.
13 // ==========================================================================
14 
15 #ifndef __PARAM_H
16 #define __PARAM_H
17 
18 #ifdef UNDEF
19 // some typedefs
20 typedef enum {
21  PRM_MUA,
22  PRM_KAPPA,
23  PRM_N,
24  PRM_CMUA,
25  PRM_CKAPPA,
26  PRM_MUS,
27  PRM_CMUS,
28  PRM_C,
29  PRM_ETA, // canonical parameter: eta = cmua/ckappa
30  PRM_XI, // canonical parameter: xi = 1/ckappa
31  PRM_A, // boundary reflection term A
32  PRM_C2A, // c/2A
33  PRM_ZERO // dummy
34 } ParameterType;
35 #endif
36 // some typedefs
37 typedef enum {
38  PRM_CMUA, //
39  PRM_CKAPPA, // primary parameters
40  PRM_N, //
41 
42  PRM_MUA, //
43  PRM_KAPPA, //
44  PRM_MUS, // derived parameters
45  PRM_CMUS, //
46  PRM_C, //
47 
48  PRM_ETA, // canonical parameter: eta = cmua/ckappa
49  PRM_XI, // canonical parameter: xi = 1/ckappa
50  PRM_A, // boundary reflection term A
51  PRM_C2A, // c/2A
52  PRM_ZERO // dummy
53 } ParameterType;
54 
55 
56 typedef enum {
57  REFLECTION_KEIJZER,
58  REFLECTION_CONTINI,
59  REFLECTION_CONST
60 } ReflectionType;
61 
62 
63 typedef enum {
64  PLIST_BY_NODE,
65  PLIST_BY_ELEMENT
66 } PlistType;
67 
68 
69 // general conversion mus <-> kappa
70 inline double MuaMusToKappa (const double mua, const double mus)
71 { return 1.0 / (3.0*(mua+mus)); }
72 
73 inline double MuaKappaToMus (const double mua, const double kappa)
74 { return 1.0/(3.0*kappa) - mua; }
75 
76 // default parameter settings
77 const double c0 = 0.3; // speed of light in vacuum [mm/ps]
78 const double default_n = 1.4; // default refractive index of medium
79 const double default_mua = 0.025; // default absorption coefficient
80 const double default_mus = 2.0; // default (reduced) scatter coefficient
81 const double default_kappa = MuaMusToKappa (default_mua, default_mus);
82 const double default_a = -1.0; // "undefined"
83 
84 // some useful conversions
85 inline double lspeed (double n) { return c0/n; }
86 void SetReflectionFunction (ReflectionType rt, double A = 1.0);
87 // select reflection calculation method
88 // A is only used for reflection type REFLECTION_CONST
89 
90 // some algorithms for reflection term calculations
91 FELIB double A_Keijzer (double n);
92 FELIB double A_Contini (double n);
93 FELIB double A_Const (double /*n*/);
94 
95 // ==========================================================================
96 
97 class FELIB Parameter {
98 public:
99  Parameter ()
100  { mua = default_mua, kappa = default_kappa, n = default_n, a = default_a; }
101 
102  Parameter (const double _mua, const double _kappa, const double _n,
103  const double _a = default_a)
104  { mua = _mua, kappa = _kappa, n = _n, a = _a; }
105 
106  Parameter (const Parameter &prm)
107  { mua = prm.mua, kappa = prm.kappa, n = prm.n, a = prm.a; }
108 
109  // basic conversions mus <-> kappa
110  friend double MuaMusToKappa (const double mua, const double mus);
111  friend double MuaKappaToMus (const double mua, const double kappa);
112 
113  // some operators
114  Parameter &operator= (const Parameter &prm);
115  int operator== (const Parameter &prm) const;
116  int operator!= (const Parameter &prm) const;
117 
118  // read parameters
119  double Mua() const { return mua; }
120  double Kappa() const { return kappa; }
121  double N() const { return n; }
122  double C() const { return lspeed(n); }
123  double CMua() const { return C()*Mua(); }
124  double CKappa() const { return C()*Kappa(); }
125  double Mus() const { return MuaKappaToMus (mua, kappa); }
126  double CMus() const { return C()*Mus(); }
127  double A() const;
128  double bndA (double n2 = 1.0) const;
129  double C2A() const { return C()/(2.0*A()); }
130  double Param (ParameterType prmtp) const;
131 
132  static double C2A (ReflectionType rt, double n);
133 
134  // set parameters
135  void SetMua (const double _mua) { mua = _mua; }
136  void SetKappa (const double _kappa) { kappa = _kappa; }
137  void SetN (const double _n) { n = _n; }
138  void SetC (const double _c) { n = c0/_c; }
139  void SetMus (const double _mus) { kappa = MuaMusToKappa (mua, _mus); }
140  void SetCMua (const double _cmua) { mua = _cmua/C(); }
141  void SetCKappa (const double _ckappa) { kappa = _ckappa/C(); }
142  void SetA (const double _a) { a = _a; }
143  void SetMuaKappa (const double _mua, const double _kappa)
144  { mua = _mua, kappa = _kappa; }
145  void SetMuaMus (const double _mua, const double _mus)
146  { mua = _mua, kappa = MuaMusToKappa (_mua, _mus); }
147  void SetParam (ParameterType prmtp, const double val);
148 
149  // I/O
150  friend std::istream& operator>> (std::istream& is, Parameter& prm);
151  friend std::ostream& operator<< (std::ostream& os, Parameter& prm);
152  void get (std::istream &is, ParameterType p1 = PRM_MUA,
153  ParameterType p2 = PRM_KAPPA, ParameterType p3 = PRM_N);
154  void put (std::ostream &os, ParameterType p1 = PRM_MUA,
155  ParameterType p2 = PRM_KAPPA, ParameterType p3 = PRM_N);
156 
157  // miscellaneous
158  friend void Swap (Parameter& prm1, Parameter& prm2);
159 
160 private:
161  double mua; // mua
162  double kappa; // kappa
163  double n; // refractive index
164  double a; // reflection term
165 };
166 
167 // ==========================================================================
168 
169 class FELIB ParameterList {
170 public:
171  ParameterList ();
172  ParameterList (const int _size);
173  ~ParameterList() { if (size) delete []list; }
174 
175  void New (const int _size);
176  // create new list with '_size' entries and set to default values
177 
178  void Clear();
179  // clear the list
180 
181  int Len() const { return size; }
182 
183  void SetList (int no, Parameter *prms);
184  // replace parameter list with prms of length no
185 
186  void Swap (const int rec1, const int rec2);
187  // swap entries rec1 and rec2 in the list
188 
189  void Append (int number);
190  // Append 'number' empty to the list. The parameters of the new entries
191  // are set to default values.
192 
193  void Remove (const int rec);
194  // remove entry `rec' from the list
195 
196  // list type
197  PlistType pltype() const { return plist_type;}
198  void SetListType(PlistType p) { plist_type = p;}
199  // read parameter vectors
200  RVector Mua() const { return Param (PRM_MUA); }
201  RVector Kappa() const { return Param (PRM_KAPPA); }
202  RVector N() const { return Param (PRM_N); }
203  RVector C() const { return Param (PRM_C); }
204  RVector CMua() const { return Param (PRM_CMUA); }
205  RVector CKappa() const { return Param (PRM_CKAPPA); }
206  RVector Mus() const { return Param (PRM_MUS); }
207  RVector CMus() const { return Param (PRM_CMUS); }
208  RVector A() const { return Param (PRM_A); }
209  RVector C2A() const { return Param (PRM_C2A); }
210  RVector Param (ParameterType prmtp) const;
211 
212  // as above but use vector supplied in parameter list. This avoids
213  // creation of a temporary vector
214  void Mua (RVector &prmvec) const { Param (PRM_MUA, prmvec); }
215  void Kappa (RVector &prmvec) const { Param (PRM_KAPPA, prmvec); }
216  void N (RVector &prmvec) const { Param (PRM_N, prmvec); }
217  void C (RVector &prmvec) const { Param (PRM_C, prmvec); }
218  void CMua (RVector &prmvec) const { Param (PRM_CMUA, prmvec); }
219  void CKappa (RVector &prmvec) const { Param (PRM_CKAPPA, prmvec); }
220  void Mus (RVector &prmvec) const { Param (PRM_MUS, prmvec); }
221  void CMus (RVector &prmvec) const { Param (PRM_CMUS, prmvec); }
222  void A (RVector &prmvec) const { Param (PRM_A, prmvec); }
223  void C2A (RVector &prmvec) const { Param (PRM_C2A, prmvec); }
224  void Param (ParameterType prmtp, RVector &prmvec) const;
225 
226  // set parameter vectors. Vector must be of the same size as parameter list
227  void SetMua (const RVector& prmvec) { SetParam (PRM_MUA, prmvec); }
228  void SetKappa (const RVector& prmvec) { SetParam (PRM_KAPPA, prmvec); }
229  void SetN (const RVector& prmvec) { SetParam (PRM_N, prmvec); }
230  void SetC (const RVector& prmvec) { SetParam (PRM_C, prmvec); }
231  void SetCMua (const RVector& prmvec) { SetParam (PRM_CMUA, prmvec); }
232  void SetCKappa (const RVector& prmvec) { SetParam (PRM_CKAPPA, prmvec); }
233  void SetMus (const RVector& prmvec) { SetParam (PRM_MUS, prmvec); }
234  void SetA (const RVector& prmvec) { SetParam (PRM_A, prmvec); }
235  void SetParam (ParameterType prmtp, const RVector& prmvec);
236 
237  // set parameter vector to homogeneous value
238  void SetMua (double prm) { SetParam (PRM_MUA, prm); }
239  void SetKappa (double prm) { SetParam (PRM_KAPPA, prm); }
240  void SetN (double prm) { SetParam (PRM_N, prm); }
241  void SetC (double prm) { SetParam (PRM_C, prm); }
242  void SetCMua (double prm) { SetParam (PRM_CMUA, prm); }
243  void SetCKappa (double prm) { SetParam (PRM_CKAPPA, prm); }
244  void SetMus (double prm) { SetParam (PRM_MUS, prm); }
245  void SetA (double prm) { SetParam (PRM_A, prm); }
246  void SetParam (ParameterType prmtp, double prm);
247 
248 #ifdef FEM_DEBUG
249  Parameter& operator[] (const int rec) const;
250 #else
251  Parameter& operator[] (const int rec) const { return list[rec]; }
252 #endif
253 
254  // I/O
255  void SetOutputParameterTypes (const ParameterType p1,
256  const ParameterType p2, const ParameterType p3);
257 
258  friend std::istream& operator>> (std::istream& is, ParameterList& plist);
259  friend std::ostream& operator<< (std::ostream& os,
260  const ParameterList& plist);
261 
262 private:
263  int size; // list length
264  Parameter *list; // array of parameters
265  ParameterType output_prmtp_p1, output_prmtp_p2, output_prmtp_p3;
266  PlistType plist_type; // type of list (by node (default), or by element)
267 };
268 
269 #endif // !__PARAM_H
Definition: param.h:97
Definition: param.h:169