Blame view

main.cpp 7.33 KB
da3d4e0e   dmayerich   Initial commit.
1
2
3
4
5
6
7
8
9
  #include <fstream>
  using namespace std;
  #include "interactivemie.h"
  #include <QtGui/QApplication>
  #include "qtSpectrumDisplay.h"
  #include "globals.h"
  #include "rtsGUIConsole.h"
  #include "PerformanceData.h"
  #include <complex>
bfe3f56b   dmayerich   Fixed Linux compa...
10
  //#include <direct.h>
da3d4e0e   dmayerich   Initial commit.
11
12
13
14
15
  
  PerformanceData PD;
  
  qtSpectrumDisplay* gpSpectrumDisplay;
  
bfe3f56b   dmayerich   Fixed Linux compa...
16
  vector<vector<SpecPair> > RefSpectrum;
da3d4e0e   dmayerich   Initial commit.
17
18
19
20
21
  vector<SpecPair> SimSpectrum;
  vector<SpecPair> EtaK;
  vector<SpecPair> EtaN;
  int currentSpec = 0;
  
52a5fe9d   dmayerich   Added double supp...
22
23
24
  double nuMin = 800;
  double nuMax = 4000;
  double dNu = 2;
da3d4e0e   dmayerich   Initial commit.
25
  
52a5fe9d   dmayerich   Added double supp...
26
27
  double aMin = 0;
  double aMax = 1;
da3d4e0e   dmayerich   Initial commit.
28
  
52a5fe9d   dmayerich   Added double supp...
29
30
  double scaleI0 = 1.0;
  double refSlope = 0.0;
da3d4e0e   dmayerich   Initial commit.
31
32
33
34
35
36
37
  
  bool dispRefSpec = true;
  bool dispSimSpec = true;
  bool dispSimK = true;
  bool dispMatK = true;
  bool dispSimN = true;
  bool dispMatN = true;
52a5fe9d   dmayerich   Added double supp...
38
39
  double dispScaleK = 1.0;
  double dispScaleN = 1.0;
da3d4e0e   dmayerich   Initial commit.
40
41
  SpecType dispSimType = AbsorbanceSpecType;
  bool dispNormalize = false;
52a5fe9d   dmayerich   Added double supp...
42
  double dispNormFactor = 1.0;
da3d4e0e   dmayerich   Initial commit.
43
44
45
  
  
  //material parameters
52a5fe9d   dmayerich   Added double supp...
46
47
48
  double radius = 4.0f;
  double baseIR = 1.49f;
  double cA = 1.0;
da3d4e0e   dmayerich   Initial commit.
49
50
51
52
53
54
55
  //vector<SpecPair> KMaterial;
  //vector<SpecPair> NMaterial;
  bool applyMaterial = true;
  vector<Material> MaterialList;
  int currentMaterial = 0;
  
  //optical parameters
52a5fe9d   dmayerich   Added double supp...
56
57
58
59
  double cNAi = 0.0;
  double cNAo = 0.6;
  double oNAi = 0.0;
  double oNAo = 0.6;
da3d4e0e   dmayerich   Initial commit.
60
61
62
63
64
  OpticsType opticsMode = TransmissionOpticsType;
  bool pointDetector = false;
  int objectiveSamples = 200;
  
  //fitting parameters
52a5fe9d   dmayerich   Added double supp...
65
  double minMSE = 0.00001;
da3d4e0e   dmayerich   Initial commit.
66
67
68
69
70
71
72
73
  int maxFitIter = 20;
  
  void TempSimSpectrum()
  {
  	SpecPair temp;
  	for(int i=800; i<4000; i++)
  	{
  		temp.nu = i;
52a5fe9d   dmayerich   Added double supp...
74
  		temp.A = sin((double)i/200);
da3d4e0e   dmayerich   Initial commit.
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  		SimSpectrum.push_back(temp);
  	}
  }
  
  void UpdateDisplay(){
  	gpSpectrumDisplay->updateGL();
  }
  
  void LoadMaterial(string fileNameK, string fileNameN, string materialName)
  {
  	Material newMaterial;
  	newMaterial.name = materialName;
  
  	vector<SpecPair> KMaterial = LoadSpectrum(fileNameK.c_str());
  	vector<SpecPair> NMaterial = LoadSpectrum(fileNameN.c_str());
  
  	//make sure that the sizes are the same
  	if(KMaterial.size() != NMaterial.size()){
  		cout<<"Error, material properties don't match."<<endl;
  		exit(1);
  	}
  
52a5fe9d   dmayerich   Added double supp...
97
98
99
  	complex<double> eta;
  	//int j;
  	for(unsigned int i=0; i<KMaterial.size(); i++){
da3d4e0e   dmayerich   Initial commit.
100
  		newMaterial.nu.push_back(KMaterial[i].nu);
52a5fe9d   dmayerich   Added double supp...
101
  		eta = complex<double>(NMaterial[i].A, KMaterial[i].A);
da3d4e0e   dmayerich   Initial commit.
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
  		newMaterial.eta.push_back(eta);
  	}
  	MaterialList.push_back(newMaterial);
  
  }
  
  void LoadMaterial(string fileNameK, string materialName){
  
  	//load the material absorbance
  	vector<SpecPair> KMaterial = LoadSpectrum(fileNameK.c_str());
  	vector<SpecPair> NMaterial;
  	//KMaterial = LoadSpectrum("eta_TolueneK.txt");
  
  	//compute the real IR using Kramers Kronig
  	//copy the absorbance values into a linear array
52a5fe9d   dmayerich   Added double supp...
117
118
119
  	double* k = (double*)malloc(sizeof(double) * KMaterial.size());
  	double* n = (double*)malloc(sizeof(double) * KMaterial.size());
  	for(unsigned int i=0; i<KMaterial.size(); i++)
da3d4e0e   dmayerich   Initial commit.
120
121
122
123
124
  		k[i] = KMaterial[i].A;
  
  	//use Kramers Kronig to determine the real part of the index of refraction
  	cudaKramersKronig(n, k, KMaterial.size(), KMaterial[0].nu, KMaterial.back().nu, baseIR);
  	SpecPair temp;
52a5fe9d   dmayerich   Added double supp...
125
  	for(unsigned int i=0; i<KMaterial.size(); i++)
da3d4e0e   dmayerich   Initial commit.
126
127
128
129
130
131
132
133
134
  	{
  		temp.nu =  KMaterial[i].nu;
  		temp.A = n[i];
  		NMaterial.push_back(temp);
  	}
  
  	//create the material
  	Material newMaterial;
  	newMaterial.name = materialName;
52a5fe9d   dmayerich   Added double supp...
135
136
  	complex<double> eta;
  	for(unsigned int i=0; i<KMaterial.size(); i++){
da3d4e0e   dmayerich   Initial commit.
137
  		newMaterial.nu.push_back(KMaterial[i].nu);
52a5fe9d   dmayerich   Added double supp...
138
  		eta = complex<double>(NMaterial[i].A, KMaterial[i].A);
da3d4e0e   dmayerich   Initial commit.
139
140
141
142
143
144
145
  		newMaterial.eta.push_back(eta);
  	}
  
  	MaterialList.push_back(newMaterial);
  }
  
  void FitDisplay(){
52a5fe9d   dmayerich   Added double supp...
146
147
148
  	double minA = 99999.0;
  	double maxA = -99999.0;
  	double k, n;
da3d4e0e   dmayerich   Initial commit.
149
150
  
  	if(dispSimSpec)
52a5fe9d   dmayerich   Added double supp...
151
  		for(unsigned int i=0; i<SimSpectrum.size(); i++)
da3d4e0e   dmayerich   Initial commit.
152
153
154
155
156
157
158
159
  		{
  			if(SimSpectrum[i].A < minA)
  				minA = SimSpectrum[i].A;
  			if(SimSpectrum[i].A > maxA)
  				maxA = SimSpectrum[i].A;
  		}
  
  	if(dispRefSpec && RefSpectrum.size() > 0)
52a5fe9d   dmayerich   Added double supp...
160
  		for(unsigned int i=0; i<RefSpectrum[currentSpec].size(); i++)
da3d4e0e   dmayerich   Initial commit.
161
162
163
164
165
166
167
  		{
  			if(RefSpectrum[currentSpec][i].A < minA)
  				minA = RefSpectrum[currentSpec][i].A;
  			if(RefSpectrum[currentSpec][i].A > maxA)
  				maxA = RefSpectrum[currentSpec][i].A;
  		}
  	if(dispMatK)
52a5fe9d   dmayerich   Added double supp...
168
  		for(unsigned int i=0; i<EtaK.size(); i++)
da3d4e0e   dmayerich   Initial commit.
169
170
171
172
173
174
175
176
  		{
  			k = MaterialList[currentMaterial].eta[i].imag() * dispScaleK;
  			if(k < minA)
  				minA = k;
  			if(k > maxA)
  				maxA = k;
  		}
  	if(dispSimK)
52a5fe9d   dmayerich   Added double supp...
177
  		for(unsigned int i=0; i<EtaK.size(); i++)
da3d4e0e   dmayerich   Initial commit.
178
179
180
181
182
183
184
185
  		{
  			k = EtaK[i].A * dispScaleK;
  			if(k < minA)
  				minA = k;
  			if(EtaK[i].A > maxA)
  				maxA = k;
  		}
  	if(dispMatN)
52a5fe9d   dmayerich   Added double supp...
186
  		for(unsigned int i=0; i<EtaN.size(); i++)
da3d4e0e   dmayerich   Initial commit.
187
188
189
190
191
192
193
194
  		{
  			n = (MaterialList[currentMaterial].eta[i].real() - baseIR) * dispScaleN;
  			if(n < minA)
  				minA = n;
  			if(n > maxA)
  				maxA = n;
  		}
  	if(dispSimN)
52a5fe9d   dmayerich   Added double supp...
195
  		for(unsigned int i=0; i<EtaN.size(); i++)
da3d4e0e   dmayerich   Initial commit.
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
  		{
  			n = (EtaN[i].A - baseIR) * dispScaleN;
  			if(n < minA)
  				minA = n;
  			if(n > maxA)
  				maxA = n;
  		}
  
  	aMin = minA;
  	aMax = maxA;
  	UpdateDisplay();
  }
  
  void ChangeAbsorbance(){
  
  	//compute the real part of the index of refraction
  	
  	//copy the absorbance values into a linear array
  	int nSamples = MaterialList[currentMaterial].eta.size();
52a5fe9d   dmayerich   Added double supp...
215
216
217
218
  	double startNu = MaterialList[currentMaterial].nu.front();
  	double endNu = MaterialList[currentMaterial].nu.back();
  	double* k = (double*)malloc(sizeof(double) * nSamples);
  	double* n = (double*)malloc(sizeof(double) * nSamples);
da3d4e0e   dmayerich   Initial commit.
219
220
221
222
223
224
225
226
227
228
229
230
231
  	for(int i=0; i<nSamples; i++)
  		k[i] = MaterialList[currentMaterial].eta[i].imag() * cA;
  
  	//NMaterial.clear();
  	EtaK.clear();
  	EtaN.clear();
  	//use Kramers Kronig to determine the real part of the index of refraction
  	cudaKramersKronig(n, k, nSamples, startNu, endNu, baseIR);
  
  	//copy the real part of the index of refraction into the vector
  	SpecPair temp;
  
  	//load the imaginary IR from the absorbance data
52a5fe9d   dmayerich   Added double supp...
232
  	double nu;
da3d4e0e   dmayerich   Initial commit.
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
  	for(int i=0; i<nSamples; i++){
  		nu = MaterialList[currentMaterial].nu[i];
  		if(nu >= nuMin && nu <= nuMax){
  			temp.nu = nu;
  			temp.A = k[i];
  			EtaK.push_back(temp);
  			//temp.A = NMaterial[i].A;
  			temp.A = n[i];
  			EtaN.push_back(temp);
  		}
  	}
  
  	free(k);
  	free(n);
  }
  
  void SetMaterial()
  {
  	EtaK.clear();
  	EtaN.clear();
  
  	int nSamples = MaterialList[currentMaterial].eta.size();
52a5fe9d   dmayerich   Added double supp...
255
  	double nu;
da3d4e0e   dmayerich   Initial commit.
256
  	SpecPair temp;
bfe3f56b   dmayerich   Fixed Linux compa...
257
258
259
260
  
  	//initialize the current nuMin and nuMax values
  	nuMin = MaterialList[currentMaterial].nu[0];
  	nuMax = nuMin;
da3d4e0e   dmayerich   Initial commit.
261
262
  	for(int i=0; i<nSamples; i++){
  		nu = MaterialList[currentMaterial].nu[i];
bfe3f56b   dmayerich   Fixed Linux compa...
263
264
265
266
267
268
  		//if(nu >= nuMin && nu <= nuMax){
  
  		//update the min and max values for display
  		if(nu < nuMin) nuMin = nu;
  		if(nu > nuMax) nuMax = nu;
  
da3d4e0e   dmayerich   Initial commit.
269
270
271
272
273
  			temp.nu = nu;
  			temp.A = MaterialList[currentMaterial].eta[i].imag();
  			EtaK.push_back(temp);
  			temp.A = MaterialList[currentMaterial].eta[i].real();
  			EtaN.push_back(temp);
da3d4e0e   dmayerich   Initial commit.
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
  	}
  	cA = 1.0;
  
  }
  
  
  
  int main(int argc, char *argv[])
  {
  	
  
  	//load the default project file (any previous optical settings)
  	LoadState();
  	
  	//load the default materials
  	LoadMaterial("eta_TolueneK.txt", "eta_TolueneN.txt", "Toluene");
  	LoadMaterial("kPMMA.txt", "PMMA");
  	//LoadMaterial("../../../../data/materials/rtsSU8_k.txt", "../../../../data/materials/rtsSU8_n.txt", "SU8");
  	SetMaterial();
  
  	//compute the analytical solution for the Mie scattered spectrum
  	SimulateSpectrum();
  
  	QApplication a(argc, argv);
  	InteractiveMie w;
  	
  
  	w.show();
  	
  	
  	w.move(0, 0);
  	QRect frame = w.frameGeometry();
  	QRect inside = w.geometry();
  
  	//activate a console for output
  	RedirectIOToConsole(0, frame.height(), frame.width());
  
  	gpSpectrumDisplay = new qtSpectrumDisplay();
  	gpSpectrumDisplay->move(frame.width(), 0);
  	gpSpectrumDisplay->resize(2*inside.height(), inside.height());
  
  	gpSpectrumDisplay->show();
  
  	//refresh the UI
  	w.refreshUI();
  
  	return a.exec();
  }