1 /*
2 *	Copyright (C) 2012 Thorsten Liebig (Thorsten.Liebig@gmx.de)
3 *
4 *	This program is free software: you can redistribute it and/or modify
5 *	it under the terms of the GNU General Public License as published by
6 *	the Free Software Foundation, either version 3 of the License, or
7 *	(at your option) any later version.
8 *
9 *	This program is distributed in the hope that it will be useful,
10 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
11 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 *	GNU General Public License for more details.
13 *
14 *	You should have received a copy of the GNU General Public License
15 *	along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef SAR_CALCULATION_H
19 #define SAR_CALCULATION_H
20 
21 #include <complex>
22 
23 class SAR_Calculation
24 {
25 public:
26 	SAR_Calculation();
27 
28 	enum SARAveragingMethod { IEEE_C95_3, IEEE_62704, SIMPLE};
29 
30 	//! Reset and initialize all values (will keep all SAR settings)
31 	void Reset();
32 
33 	//! Set the debug level
SetDebugLevel(int level)34 	void SetDebugLevel(int level) {m_DebugLevel=level;}
35 
36 	//! Set the used averaging method
37 	void SetAveragingMethod(SARAveragingMethod method, bool silent=false);
38 
39 	//! Set the used averaging method
40 	void SetAveragingMethod(std::string method, bool silent=false);
41 
42 	//! Set number of lines in all direcitions. (mandatory information)
43 	void SetNumLines(unsigned int numLines[3]);
44 	//! Set cell width in all direcitions. (mandatory information for averaging)
45 	void SetCellWidth(float* cellWidth[3]);
46 
47 	//! Set the averaging mash. (mandatory information for averaging)
SetAveragingMass(float mass)48 	void SetAveragingMass(float mass) {m_avg_mass=mass;}
49 
50 	//! Set the cell volumes (optional for speedup)
SetCellVolumes(float *** cell_volume)51 	void SetCellVolumes(float*** cell_volume) {m_cell_volume=cell_volume;}
52 
53 	//! Set the cell densities (mandatory information)
SetCellDensities(float *** cell_density)54 	void SetCellDensities(float*** cell_density) {m_cell_density=cell_density;}
55 
56 	//! Set the cell conductivities (mandatory if no current density field is given)
SetCellCondictivity(float *** cell_conductivity)57 	void SetCellCondictivity(float*** cell_conductivity) {m_cell_conductivity=cell_conductivity;}
58 
59 	//! Set the electric field (mandatory information)
SetEField(std::complex<float> **** field)60 	void SetEField(std::complex<float>**** field) {m_E_field=field;}
61 	//! Set the current density field (mandatory if no conductivity distribution is given)
SetJField(std::complex<float> **** field)62 	void SetJField(std::complex<float>**** field) {m_J_field=field;}
63 
64 	//! Calculate the SAR, requires a preallocated 3D array
65 	float*** CalcSAR(float*** SAR);
66 
67 	//! Calculate the total power dumped
68 	double CalcSARPower();
69 
70 protected:
71 	unsigned int m_numLines[3];
72 	float* m_cellWidth[3];
73 
74 	float m_avg_mass;
75 	float*** m_cell_volume;
76 	float*** m_cell_density;
77 	float*** m_cell_conductivity;
78 	std::complex<float>**** m_E_field;
79 	std::complex<float>**** m_J_field;
80 
81 	bool*** m_Vx_Used;
82 	bool*** m_Vx_Valid;
83 
84 	unsigned int m_Valid;
85 	unsigned int m_Used;
86 	unsigned int m_Unused;
87 	unsigned int m_AirVoxel;
88 
89 	int m_DebugLevel;
90 
91 	/*********** SAR calculation parameter and settings ***********/
92 	float m_massTolerance;
93 	unsigned int m_maxMassIterations;
94 	float m_maxBGRatio;
95 	bool m_markPartialAsUsed;
96 	float m_UnusedRelativeVolLimit;
97 	bool m_IgnoreFaceValid;
98 
99 	/*********** SAR calculations methods ********/
100 	double CalcLocalPowerDensity(unsigned int pos[3]);
101 
102 	//! Calculate the local SAR
103 	float*** CalcLocalSAR(float*** SAR);
104 
105 	/****** start SAR averaging and all necessary methods ********/
106 	//! Calculate the averaged SAR
107 	float*** CalcAveragedSAR(float*** SAR);
108 
109 	int FindFittingCubicalMass(unsigned int pos[3], float box_size, unsigned int start[3], unsigned int stop[3],
110 						float partial_start[3], float partial_stop[3], double &mass, double &volume, double &bg_ratio, int disabledFace=-1, bool ignoreFaceValid=false);
111 	bool GetCubicalMass(unsigned int pos[3], double box_size, unsigned int start[3], unsigned int stop[3],
112 						float partial_start[3], float partial_stop[3], double &mass, double &volume, double &bg_ratio, int disabledFace=-1);
113 
114 	float CalcCubicalSAR(float*** SAR, unsigned int pos[3], unsigned int start[3], unsigned int stop[3], float partial_start[3], float partial_stop[3], bool assignUsed=false);
115 	/****** end SAR averaging and all necessary methods ********/
116 
117 	bool CheckValid();
118 	double CellVolume(unsigned int pos[3]);
119 	double CellMass(unsigned int pos[3]);
120 };
121 
122 #endif // SAR_CALCULATION_H
123