Commit 39a7d6e9b9e808e07fe73c37a4d5b8462ab7eaf4

Authored by dmayerich
1 parent 4385ea8c

Added dialog support and display of distortion maps.

@@ -9,3 +9,7 @@ RTS (my personal codebase) https://github.com/dmayerich/RTS @@ -9,3 +9,7 @@ RTS (my personal codebase) https://github.com/dmayerich/RTS
9 CUDA http://www.nvidia.com/object/cuda_home_new.html 9 CUDA http://www.nvidia.com/object/cuda_home_new.html
10 10
11 If CMake is unable to find these, make sure to specify their locations. 11 If CMake is unable to find these, make sure to specify their locations.
  12 +
  13 +Known Bugs in Source Version
  14 +---------------------------------
  15 +*) Simulation of the spectrum at the shortest wavelength is returning NaN in Linux.
SimulateSpectrum.cpp
@@ -2,7 +2,8 @@ @@ -2,7 +2,8 @@
2 #include <complex> 2 #include <complex>
3 #include <iostream> 3 #include <iostream>
4 #include <fstream> 4 #include <fstream>
5 -#include "globals.h" 5 +#include "globals.h"
  6 +#include <QProgressDialog>
6 #include <stdlib.h> 7 #include <stdlib.h>
7 //#include "cufft.h" 8 //#include "cufft.h"
8 using namespace std; 9 using namespace std;
@@ -137,7 +138,7 @@ void Legendre(double* P, double x, int Nl) @@ -137,7 +138,7 @@ void Legendre(double* P, double x, int Nl)
137 for(int l = 2; l < Nl; l++) 138 for(int l = 2; l < Nl; l++)
138 { 139 {
139 P[l] = ((2*l - 1)*x*P[l-1] - (l - 1)*P[l-2])/l; 140 P[l] = ((2*l - 1)*x*P[l-1] - (l - 1)*P[l-2])/l;
140 - } 141 + }
141 142
142 } 143 }
143 144
@@ -190,7 +191,7 @@ void computeCondenserAlpha(double* alpha, int Nl, double cAngleI, double cAngleO @@ -190,7 +191,7 @@ void computeCondenserAlpha(double* alpha, int Nl, double cAngleI, double cAngleO
190 191
191 } 192 }
192 193
193 -complex<double> integrateUs(double r, double lambda, complex<double> eta, 194 +complex<double> integrateUs(double r, double lambda, complex<double> eta,
194 double cAngleI, double cAngleO, double oAngleI, double oAngleO, double M = 2*pi) 195 double cAngleI, double cAngleO, double oAngleI, double oAngleO, double M = 2*pi)
195 { 196 {
196 /*This function integrates the incident field of magnitude M in the far zone 197 /*This function integrates the incident field of magnitude M in the far zone
@@ -223,7 +224,7 @@ complex&lt;double&gt; integrateUs(double r, double lambda, complex&lt;double&gt; eta, @@ -223,7 +224,7 @@ complex&lt;double&gt; integrateUs(double r, double lambda, complex&lt;double&gt; eta,
223 224
224 //store the index of refraction; 225 //store the index of refraction;
225 complex<double> IR(eta.real(), eta.imag()); 226 complex<double> IR(eta.real(), eta.imag());
226 - 227 +
227 //compute the scattering coefficients 228 //compute the scattering coefficients
228 computeB(B, r, IR, lambda, Nl); 229 computeB(B, r, IR, lambda, Nl);
229 230
@@ -248,8 +249,8 @@ complex&lt;double&gt; integrateUs(double r, double lambda, complex&lt;double&gt; eta, @@ -248,8 +249,8 @@ complex&lt;double&gt; integrateUs(double r, double lambda, complex&lt;double&gt; eta,
248 } 249 }
249 c = (2*pi)/(2.0 * l + 1.0); 250 c = (2*pi)/(2.0 * l + 1.0);
250 Us += c * alpha * beta * B[l] * M; 251 Us += c * alpha * beta * B[l] * M;
251 -  
252 - 252 +
  253 +
253 } 254 }
254 free(PcNAo); 255 free(PcNAo);
255 free(PcNAi); 256 free(PcNAi);
@@ -269,7 +270,7 @@ void pointSpectrum() @@ -269,7 +270,7 @@ void pointSpectrum()
269 270
270 double dNu = 2.0f; 271 double dNu = 2.0f;
271 double lambda; 272 double lambda;
272 - 273 +
273 //compute the angles based on NA 274 //compute the angles based on NA
274 double cAngleI = asin(cNAi); 275 double cAngleI = asin(cNAi);
275 double cAngleO = asin(cNAo); 276 double cAngleO = asin(cNAo);
@@ -278,7 +279,7 @@ void pointSpectrum() @@ -278,7 +279,7 @@ void pointSpectrum()
278 279
279 //implement a reflection-mode system if necessary 280 //implement a reflection-mode system if necessary
280 if(opticsMode == ReflectionOpticsType){ 281 if(opticsMode == ReflectionOpticsType){
281 - 282 +
282 //set the condenser to match the objective 283 //set the condenser to match the objective
283 cAngleI = oAngleI; 284 cAngleI = oAngleI;
284 cAngleO = oAngleO; 285 cAngleO = oAngleO;
@@ -293,7 +294,7 @@ void pointSpectrum() @@ -293,7 +294,7 @@ void pointSpectrum()
293 double I0 = Ui.real() * Ui.real() + Ui.imag() * Ui.imag(); 294 double I0 = Ui.real() * Ui.real() + Ui.imag() * Ui.imag();
294 I0 *= scaleI0; 295 I0 *= scaleI0;
295 296
296 - 297 +
297 298
298 //double I; 299 //double I;
299 SpecPair temp; 300 SpecPair temp;
@@ -316,7 +317,7 @@ void pointSpectrum() @@ -316,7 +317,7 @@ void pointSpectrum()
316 Us = integrateUs(radius, lambda, eta, cAngleI, cAngleO, oAngleI, oAngleO, 2*pi); 317 Us = integrateUs(radius, lambda, eta, cAngleI, cAngleO, oAngleI, oAngleO, 2*pi);
317 U = Us + Ui; 318 U = Us + Ui;
318 double I = U.real() * U.real() + U.imag() * U.imag(); 319 double I = U.real() * U.real() + U.imag() * U.imag();
319 - 320 +
320 temp.nu = nu; 321 temp.nu = nu;
321 322
322 //set the spectrum value based on the current display type 323 //set the spectrum value based on the current display type
@@ -327,8 +328,8 @@ void pointSpectrum() @@ -327,8 +328,8 @@ void pointSpectrum()
327 328
328 if(dispNormalize) 329 if(dispNormalize)
329 vecLen += temp.A * temp.A; 330 vecLen += temp.A * temp.A;
330 -  
331 - SimSpectrum.push_back(temp); 331 +
  332 + SimSpectrum.push_back(temp);
332 } 333 }
333 vecLen = sqrt(vecLen); 334 vecLen = sqrt(vecLen);
334 335
@@ -352,8 +353,10 @@ void updateSpectrum(double* I, double I0, int n) @@ -352,8 +353,10 @@ void updateSpectrum(double* I, double I0, int n)
352 //set the spectrum value based on the current display type 353 //set the spectrum value based on the current display type
353 if(dispSimType == AbsorbanceSpecType) 354 if(dispSimType == AbsorbanceSpecType)
354 temp.A = -log10(I[i]/I0); 355 temp.A = -log10(I[i]/I0);
355 - else  
356 - temp.A = I[i]; 356 + else
  357 + {
  358 + temp.A = I[i];
  359 + }
357 360
358 SimSpectrum.push_back(temp); 361 SimSpectrum.push_back(temp);
359 } 362 }
@@ -369,7 +372,7 @@ void computeCassegrainAngles(double&amp; cAngleI, double&amp; cAngleO, double&amp; oAngleI, @@ -369,7 +372,7 @@ void computeCassegrainAngles(double&amp; cAngleI, double&amp; cAngleO, double&amp; oAngleI,
369 372
370 //implement a reflection-mode system if necessary 373 //implement a reflection-mode system if necessary
371 if(opticsMode == ReflectionOpticsType){ 374 if(opticsMode == ReflectionOpticsType){
372 - 375 +
373 //set the condenser to match the objective 376 //set the condenser to match the objective
374 cAngleI = oAngleI; 377 cAngleI = oAngleI;
375 cAngleO = oAngleO; 378 cAngleO = oAngleO;
@@ -410,7 +413,7 @@ void computeBArray(complex&lt;double&gt;* B, int Nl, int nLambda) @@ -410,7 +413,7 @@ void computeBArray(complex&lt;double&gt;* B, int Nl, int nLambda)
410 eta = complex<double>(baseIR, 0.0); 413 eta = complex<double>(baseIR, 0.0);
411 414
412 //allocate memory for the scattering coefficients 415 //allocate memory for the scattering coefficients
413 - //complex<float>* B = (complex<float>*)malloc(sizeof(complex<float>)*Nl); 416 + //complex<float>* B = (complex<float>*)malloc(sizeof(complex<float>)*Nl);
414 417
415 complex<double> IR(eta.real(), eta.imag()); 418 complex<double> IR(eta.real(), eta.imag());
416 computeB(&B[i * Nl], radius, IR, Lambda[i], Nl); 419 computeB(&B[i * Nl], radius, IR, Lambda[i], Nl);
@@ -419,7 +422,7 @@ void computeBArray(complex&lt;double&gt;* B, int Nl, int nLambda) @@ -419,7 +422,7 @@ void computeBArray(complex&lt;double&gt;* B, int Nl, int nLambda)
419 422
420 void computeOpticalParameters(double& cAngleI, double& cAngleO, double& oAngleI, double& oAngleO, double& I0, double* alpha, int Nl) 423 void computeOpticalParameters(double& cAngleI, double& cAngleO, double& oAngleI, double& oAngleO, double& I0, double* alpha, int Nl)
421 { 424 {
422 - computeCassegrainAngles(cAngleI, cAngleO, oAngleI, oAngleO); 425 + computeCassegrainAngles(cAngleI, cAngleO, oAngleI, oAngleO);
423 426
424 //evaluate the incident field intensity 427 //evaluate the incident field intensity
425 I0 = 0.0; 428 I0 = 0.0;
@@ -437,7 +440,7 @@ void gpuDetectorSpectrum(int numSamples) @@ -437,7 +440,7 @@ void gpuDetectorSpectrum(int numSamples)
437 //integrate across the objective aperature and calculate the resulting intensity on a detector 440 //integrate across the objective aperature and calculate the resulting intensity on a detector
438 PD.StartTimer(SIMULATE_SPECTRUM); 441 PD.StartTimer(SIMULATE_SPECTRUM);
439 //clear the previous spectrum 442 //clear the previous spectrum
440 - SimSpectrum.clear(); 443 + SimSpectrum.clear();
441 444
442 //compute Nl (maximum order of the spectrum) 445 //compute Nl (maximum order of the spectrum)
443 int Nl = computeNl(); 446 int Nl = computeNl();
@@ -448,11 +451,11 @@ void gpuDetectorSpectrum(int numSamples) @@ -448,11 +451,11 @@ void gpuDetectorSpectrum(int numSamples)
448 451
449 //allocate space for a list of wavelengths 452 //allocate space for a list of wavelengths
450 int nLambda = EtaK.size(); 453 int nLambda = EtaK.size();
451 - 454 +
452 //allocate space for the 2D array (Nl x nu) of scattering coefficients 455 //allocate space for the 2D array (Nl x nu) of scattering coefficients
453 complex<double>* B = (complex<double>*)malloc(sizeof(complex<double>) * Nl * nLambda); 456 complex<double>* B = (complex<double>*)malloc(sizeof(complex<double>) * Nl * nLambda);
454 computeBArray(B, Nl, nLambda); 457 computeBArray(B, Nl, nLambda);
455 - 458 +
456 459
457 //allocate temporary space for the spectrum 460 //allocate temporary space for the spectrum
458 double* I = (double*)malloc(sizeof(double) * EtaK.size()); 461 double* I = (double*)malloc(sizeof(double) * EtaK.size());
@@ -500,33 +503,37 @@ double absorbanceDistortion(){ @@ -500,33 +503,37 @@ double absorbanceDistortion(){
500 503
501 double intensityDistortion(){ 504 double intensityDistortion(){
502 505
503 - //compute the magnitude of the spectrum 506 + //compute the mean intensity of the spectrum
504 double sumSim = 0.0; 507 double sumSim = 0.0;
505 for(unsigned int i=0; i<SimSpectrum.size(); i++) 508 for(unsigned int i=0; i<SimSpectrum.size(); i++)
506 { 509 {
507 - sumSim += SimSpectrum[i].A * SimSpectrum[i].A; 510 + sumSim += pow(SimSpectrum[i].A, 2);
508 } 511 }
509 double magSim = sqrt(sumSim); 512 double magSim = sqrt(sumSim);
510 513
511 //compute the distortion (MSE from the mean) 514 //compute the distortion (MSE from the mean)
512 - double sumSE = 0.0; 515 + double proj = 0.0;
513 for(unsigned int i=0; i<SimSpectrum.size(); i++) 516 for(unsigned int i=0; i<SimSpectrum.size(); i++)
514 { 517 {
515 - sumSE += (SimSpectrum[i].A/magSim) * (1.0/SimSpectrum.size()); 518 + proj += (SimSpectrum[i].A/magSim) * (1.0/SimSpectrum.size());
516 } 519 }
517 - double MSE = sumSE; 520 + double error = proj;
518 521
519 - return MSE; 522 + return error;
520 } 523 }
521 524
522 -void MinimizeDistortion(){ 525 +void DistortionMap(float* distortionMap, int nSteps){
523 ofstream outFile("distortion.txt"); 526 ofstream outFile("distortion.txt");
524 527
525 - //set the parameters for the distortion simulation  
526 - double step = 0.001; 528 + //set the parameters for the distortion simulation
  529 + double range = 0.4;
  530 + double step = (range)/(nSteps-1);
527 531
528 oNAi = 0.2; 532 oNAi = 0.2;
529 - oNAo = 0.5; 533 + oNAo = 0.5;
  534 +
  535 + double startNAi = 0.0;
  536 + double startNAo = 0.3;
530 537
531 //compute the optical parameters 538 //compute the optical parameters
532 //compute Nl (maximum order of the spectrum) 539 //compute Nl (maximum order of the spectrum)
@@ -534,7 +541,7 @@ void MinimizeDistortion(){ @@ -534,7 +541,7 @@ void MinimizeDistortion(){
534 541
535 double* alpha = (double*)malloc(sizeof(double)*(Nl + 1)); 542 double* alpha = (double*)malloc(sizeof(double)*(Nl + 1));
536 double cAngleI, cAngleO, oAngleI, oAngleO, I0; 543 double cAngleI, cAngleO, oAngleI, oAngleO, I0;
537 - 544 +
538 //allocate space for a list of wavelengths 545 //allocate space for a list of wavelengths
539 int nLambda = EtaK.size(); 546 int nLambda = EtaK.size();
540 547
@@ -546,20 +553,29 @@ void MinimizeDistortion(){ @@ -546,20 +553,29 @@ void MinimizeDistortion(){
546 complex<double>* B = (complex<double>*)malloc(sizeof(complex<double>) * Nl * nLambda); 553 complex<double>* B = (complex<double>*)malloc(sizeof(complex<double>) * Nl * nLambda);
547 computeBArray(B, Nl, nLambda); 554 computeBArray(B, Nl, nLambda);
548 555
549 - 556 + QProgressDialog progress("Computing distortion map...", "Stop", 0, nSteps * nSteps);
  557 + progress.setWindowModality(Qt::WindowModal);
550 558
551 double D; 559 double D;
552 - double e = 0.001;  
553 - for(double i=0.0; i<=oNAo-step; i+=step)  
554 - {  
555 -  
556 - for(double o=oNAi+step; o<=1.0; o+=step)  
557 - {  
558 -  
559 - 560 + double e = 0.001;
  561 + int i, o;
  562 + for(i=0; i<nSteps; i++)
  563 + {
  564 + for(o=0; o<nSteps; o++)
  565 + {
  566 + //update the progress bar and check for an exit
  567 + progress.setValue(i * nSteps + o);
  568 + if (progress.wasCanceled())
  569 + break;
  570 +
  571 + //set the current optical parameters
  572 + cNAi = startNAi + i * step;
  573 + cNAo = startNAo + o * step;
  574 + //cout<<cNAi<<" "<<cNAo<<endl;
  575 +
560 //set the current optical parameters 576 //set the current optical parameters
561 - cNAi = i;  
562 - cNAo = o; 577 + //cNAi = i;
  578 + //cNAo = o;
563 579
564 //compute the optical parameters 580 //compute the optical parameters
565 computeOpticalParameters(cAngleI, cAngleO, oAngleI, oAngleO, I0, alpha, Nl); 581 computeOpticalParameters(cAngleI, cAngleO, oAngleI, oAngleO, I0, alpha, Nl);
@@ -570,22 +586,26 @@ void MinimizeDistortion(){ @@ -570,22 +586,26 @@ void MinimizeDistortion(){
570 586
571 if(dispSimType == AbsorbanceSpecType) 587 if(dispSimType == AbsorbanceSpecType)
572 { 588 {
573 - if(i + e >= o || i + e >= oNAo || oNAi + e >= o || oNAi + e >= oNAo)  
574 - D = 0.0; 589 + if(cNAi >= cNAo || cNAi >= oNAo || oNAi >= cNAo || oNAi >= oNAo)
  590 + D = -1.0;
575 else 591 else
576 D = absorbanceDistortion(); 592 D = absorbanceDistortion();
577 } 593 }
578 else 594 else
579 { 595 {
580 - if(i >= o || oNAi >= oNAo)  
581 - D=0; 596 + if(cNAi >= cNAo || oNAi >= oNAo)
  597 + D = -1.0;
582 else 598 else
583 D = intensityDistortion(); 599 D = intensityDistortion();
584 - } 600 + }
  601 + distortionMap[o * nSteps + i] = D;
585 outFile<<D<<" "; 602 outFile<<D<<" ";
586 } 603 }
587 outFile<<endl; 604 outFile<<endl;
588 - cout<<i<<endl;  
589 - } 605 + //cout<<i<<endl;
  606 + }
  607 +
  608 + progress.setValue(nSteps * nSteps);
  609 +
590 outFile.close(); 610 outFile.close();
591 -}  
592 \ No newline at end of file 611 \ No newline at end of file
  612 +}
@@ -54,16 +54,18 @@ void cudaKramersKronig(double* cpuN, double* cpuK, int nVals, double nuStart, do @@ -54,16 +54,18 @@ void cudaKramersKronig(double* cpuN, double* cpuK, int nVals, double nuStart, do
54 HANDLE_ERROR(cudaFree(gpuN)); 54 HANDLE_ERROR(cudaFree(gpuN));
55 } 55 }
56 56
57 -__global__ void devComputeSpectrum(double* I, double2* B, double* alpha, int Nl,  
58 - int nSamples, double oThetaI, double oThetaO, double cThetaI, double cThetaO) 57 +__global__ void devComputeSpectrum(double* I, double2* B, double* alpha, int Nl,
  58 + int nSamples, int nLambda, double oThetaI, double oThetaO, double cThetaI, double cThetaO)
59 { 59 {
60 - int i = blockIdx.x * blockDim.x + threadIdx.x; 60 + int i = blockIdx.x * blockDim.x + threadIdx.x;
  61 + if(i >= nLambda-1)
  62 + return;
61 63
62 //compute the delta-theta value 64 //compute the delta-theta value
63 double dTheta = (oThetaO - oThetaI)/nSamples; 65 double dTheta = (oThetaO - oThetaI)/nSamples;
64 66
65 //allocate space for the Legendre polynomials 67 //allocate space for the Legendre polynomials
66 - double Ptheta[2]; 68 + double Ptheta[2];
67 69
68 double cosTheta, theta; 70 double cosTheta, theta;
69 cuDoubleComplex Us; 71 cuDoubleComplex Us;
@@ -122,7 +124,7 @@ __global__ void devComputeSpectrum(double* I, double2* B, double* alpha, int Nl, @@ -122,7 +124,7 @@ __global__ void devComputeSpectrum(double* I, double2* B, double* alpha, int Nl,
122 124
123 complexFac = cMult(B[Nl * i + l], exp_numer); 125 complexFac = cMult(B[Nl * i + l], exp_numer);
124 complexFac = cMult(complexFac, iL); 126 complexFac = cMult(complexFac, iL);
125 - 127 +
126 128
127 //combine the real and complex components 129 //combine the real and complex components
128 UsSample = cMult(complexFac, realFac); 130 UsSample = cMult(complexFac, realFac);
@@ -131,7 +133,7 @@ __global__ void devComputeSpectrum(double* I, double2* B, double* alpha, int Nl, @@ -131,7 +133,7 @@ __global__ void devComputeSpectrum(double* I, double2* B, double* alpha, int Nl,
131 //increment the imaginary exponent i^l 133 //increment the imaginary exponent i^l
132 iL = cMult(iL, imag); 134 iL = cMult(iL, imag);
133 135
134 - 136 +
135 } 137 }
136 138
137 //sum the scattered and incident fields 139 //sum the scattered and incident fields
@@ -158,8 +160,9 @@ void cudaComputeSpectrum(double* cpuI, double* cpuB, double* cpuAlpha, @@ -158,8 +160,9 @@ void cudaComputeSpectrum(double* cpuI, double* cpuB, double* cpuAlpha,
158 HANDLE_ERROR(cudaMemcpy(gpuAlpha, cpuAlpha, sizeof(double) * Nl, cudaMemcpyHostToDevice)); 160 HANDLE_ERROR(cudaMemcpy(gpuAlpha, cpuAlpha, sizeof(double) * Nl, cudaMemcpyHostToDevice));
159 161
160 double* gpuI; 162 double* gpuI;
161 - HANDLE_ERROR(cudaMalloc(&gpuI, sizeof(double) * nLambda));  
162 - 163 + HANDLE_ERROR(cudaMalloc(&gpuI, sizeof(double) * nLambda));
  164 + HANDLE_ERROR(cudaMemset(gpuI, 0, sizeof(double) * nLambda));
  165 +
163 166
164 //call the kernel to compute the spectrum 167 //call the kernel to compute the spectrum
165 dim3 block(BLOCK_SIZE*BLOCK_SIZE); 168 dim3 block(BLOCK_SIZE*BLOCK_SIZE);
@@ -167,15 +170,17 @@ void cudaComputeSpectrum(double* cpuI, double* cpuB, double* cpuAlpha, @@ -167,15 +170,17 @@ void cudaComputeSpectrum(double* cpuI, double* cpuB, double* cpuAlpha,
167 170
168 //devComputeSpectrum 171 //devComputeSpectrum
169 devComputeSpectrum<<<grid, block>>>(gpuI, (double2*)gpuB, gpuAlpha, Nl, 172 devComputeSpectrum<<<grid, block>>>(gpuI, (double2*)gpuB, gpuAlpha, Nl,
170 - nSamples, oThetaI, oThetaO, cThetaI, cThetaO); 173 + nSamples, nLambda, oThetaI, oThetaO, cThetaI, cThetaO);
171 174
172 HANDLE_ERROR(cudaMemcpy(cpuI, gpuI, sizeof(double) * nLambda, cudaMemcpyDeviceToHost)); 175 HANDLE_ERROR(cudaMemcpy(cpuI, gpuI, sizeof(double) * nLambda, cudaMemcpyDeviceToHost));
173 176
  177 + //printf("Final array value: %f\n", cpuI[nLambda-1]);
  178 +
174 HANDLE_ERROR(cudaFree(gpuB)); 179 HANDLE_ERROR(cudaFree(gpuB));
175 HANDLE_ERROR(cudaFree(gpuAlpha)); 180 HANDLE_ERROR(cudaFree(gpuAlpha));
176 HANDLE_ERROR(cudaFree(gpuI)); 181 HANDLE_ERROR(cudaFree(gpuI));
177 182
178 -  
179 183
180 184
181 -}  
182 \ No newline at end of file 185 \ No newline at end of file
  186 +
  187 +}
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
4 #include <vector> 4 #include <vector>
5 #include <string> 5 #include <string>
6 #include <iostream> 6 #include <iostream>
7 -#include "PerformanceData.h" 7 +#include "PerformanceData.h"
8 #include <complex> 8 #include <complex>
9 using namespace std; 9 using namespace std;
10 10
@@ -102,9 +102,13 @@ extern int maxFitIter; @@ -102,9 +102,13 @@ extern int maxFitIter;
102 void EstimateMaterial(); 102 void EstimateMaterial();
103 extern double scaleI0; 103 extern double scaleI0;
104 extern double refSlope; 104 extern double refSlope;
105 - 105 +
  106 +
  107 +//distortion maps
106 double ComputeDistortion(); 108 double ComputeDistortion();
107 -void MinimizeDistortion(); 109 +void DistortionMap(float* distortionMap, int nSteps);
  110 +
  111 +
108 112
109 113
110 -#endif  
111 \ No newline at end of file 114 \ No newline at end of file
  115 +#endif
interactivemie.cpp
1 #include "interactivemie.h" 1 #include "interactivemie.h"
  2 +#include <stdlib.h>
  3 +
  4 +qtDistortionDialog* distortionDialog;
2 5
3 InteractiveMie::InteractiveMie(QWidget *parent, Qt::WFlags flags) 6 InteractiveMie::InteractiveMie(QWidget *parent, Qt::WFlags flags)
4 : QMainWindow(parent, flags) 7 : QMainWindow(parent, flags)
@@ -9,4 +12,11 @@ InteractiveMie::InteractiveMie(QWidget *parent, Qt::WFlags flags) @@ -9,4 +12,11 @@ InteractiveMie::InteractiveMie(QWidget *parent, Qt::WFlags flags)
9 InteractiveMie::~InteractiveMie() 12 InteractiveMie::~InteractiveMie()
10 { 13 {
11 updating = false; 14 updating = false;
  15 +}
  16 +
  17 +void InteractiveMie::closeEvent(QCloseEvent *event)
  18 +{
  19 + cout<<"Exiting"<<endl;
  20 + exit(0);
  21 +
12 } 22 }
@@ -5,16 +5,20 @@ @@ -5,16 +5,20 @@
5 #include <QDragEnterEvent> 5 #include <QDragEnterEvent>
6 #include <qfiledialog.h> 6 #include <qfiledialog.h>
7 #include <qinputdialog.h> 7 #include <qinputdialog.h>
8 -#include "ui_interactivemie.h"  
9 -#include "globals.h"  
10 - 8 +#include "ui_interactivemie.h"
  9 +#include "qtDistortionDialog.h"
  10 +#include "globals.h"
  11 +
  12 +extern qtDistortionDialog* distortionDialog;
  13 +
11 class InteractiveMie : public QMainWindow 14 class InteractiveMie : public QMainWindow
12 { 15 {
13 Q_OBJECT 16 Q_OBJECT
14 17
15 public: 18 public:
16 InteractiveMie(QWidget *parent = 0, Qt::WFlags flags = 0); 19 InteractiveMie(QWidget *parent = 0, Qt::WFlags flags = 0);
17 - ~InteractiveMie(); 20 + ~InteractiveMie();
  21 + void closeEvent(QCloseEvent *event);
18 bool updating; 22 bool updating;
19 23
20 void refreshUI() 24 void refreshUI()
@@ -53,7 +57,6 @@ public: @@ -53,7 +57,6 @@ public:
53 ui.cmbMaterial->setCurrentIndex(currentMaterial); 57 ui.cmbMaterial->setCurrentIndex(currentMaterial);
54 58
55 updating = false; 59 updating = false;
56 -  
57 } 60 }
58 61
59 void dragEnterEvent(QDragEnterEvent *event) 62 void dragEnterEvent(QDragEnterEvent *event)
@@ -64,7 +67,7 @@ public: @@ -64,7 +67,7 @@ public:
64 event->mimeData()->hasFormat("text/plain")) 67 event->mimeData()->hasFormat("text/plain"))
65 { 68 {
66 event->acceptProposedAction(); 69 event->acceptProposedAction();
67 - 70 +
68 } 71 }
69 } 72 }
70 73
@@ -104,7 +107,7 @@ public slots: @@ -104,7 +107,7 @@ public slots:
104 void on_chkDisplayRefSpec_clicked(bool b){ 107 void on_chkDisplayRefSpec_clicked(bool b){
105 dispRefSpec = b; 108 dispRefSpec = b;
106 UpdateDisplay(); 109 UpdateDisplay();
107 - } 110 + }
108 void on_chkDisplaySimK_clicked(bool b){ 111 void on_chkDisplaySimK_clicked(bool b){
109 dispSimK = b; 112 dispSimK = b;
110 UpdateDisplay(); 113 UpdateDisplay();
@@ -287,7 +290,9 @@ public slots: @@ -287,7 +290,9 @@ public slots:
287 } 290 }
288 void on_btnDistortion_clicked(){ 291 void on_btnDistortion_clicked(){
289 //ComputeDistortion(); 292 //ComputeDistortion();
290 - MinimizeDistortion(); 293 + //DistortionMap();
  294 + cout<<"Distortion"<<endl;
  295 + distortionDialog->show();
291 } 296 }
292 void on_btnTimings_clicked(){ 297 void on_btnTimings_clicked(){
293 PD.PrintResults(cout); 298 PD.PrintResults(cout);
@@ -308,7 +313,7 @@ public slots: @@ -308,7 +313,7 @@ public slots:
308 313
309 //first load the imaginary part 314 //first load the imaginary part
310 QString kFileName = QFileDialog::getOpenFileName(this, tr("Open Imaginary (k) Spectrum")); 315 QString kFileName = QFileDialog::getOpenFileName(this, tr("Open Imaginary (k) Spectrum"));
311 - 316 +
312 //exit if no file was selected 317 //exit if no file was selected
313 if(kFileName == QString::null) 318 if(kFileName == QString::null)
314 return; 319 return;
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 <rect> 6 <rect>
7 <x>0</x> 7 <x>0</x>
8 <y>0</y> 8 <y>0</y>
9 - <width>464</width> 9 + <width>511</width>
10 <height>525</height> 10 <height>525</height>
11 </rect> 11 </rect>
12 </property> 12 </property>
@@ -32,7 +32,7 @@ @@ -32,7 +32,7 @@
32 <widget class="QDoubleSpinBox" name="spinScaleK"> 32 <widget class="QDoubleSpinBox" name="spinScaleK">
33 <property name="geometry"> 33 <property name="geometry">
34 <rect> 34 <rect>
35 - <x>70</x> 35 + <x>80</x>
36 <y>80</y> 36 <y>80</y>
37 <width>62</width> 37 <width>62</width>
38 <height>22</height> 38 <height>22</height>
@@ -48,7 +48,7 @@ @@ -48,7 +48,7 @@
48 <widget class="QDoubleSpinBox" name="spinBaseIR"> 48 <widget class="QDoubleSpinBox" name="spinBaseIR">
49 <property name="geometry"> 49 <property name="geometry">
50 <rect> 50 <rect>
51 - <x>70</x> 51 + <x>80</x>
52 <y>50</y> 52 <y>50</y>
53 <width>62</width> 53 <width>62</width>
54 <height>22</height> 54 <height>22</height>
@@ -80,7 +80,7 @@ @@ -80,7 +80,7 @@
80 <widget class="QDoubleSpinBox" name="spinRadius"> 80 <widget class="QDoubleSpinBox" name="spinRadius">
81 <property name="geometry"> 81 <property name="geometry">
82 <rect> 82 <rect>
83 - <x>70</x> 83 + <x>80</x>
84 <y>20</y> 84 <y>20</y>
85 <width>62</width> 85 <width>62</width>
86 <height>22</height> 86 <height>22</height>
@@ -127,7 +127,7 @@ @@ -127,7 +127,7 @@
127 <rect> 127 <rect>
128 <x>20</x> 128 <x>20</x>
129 <y>110</y> 129 <y>110</y>
130 - <width>101</width> 130 + <width>121</width>
131 <height>17</height> 131 <height>17</height>
132 </rect> 132 </rect>
133 </property> 133 </property>
@@ -166,7 +166,7 @@ @@ -166,7 +166,7 @@
166 <rect> 166 <rect>
167 <x>5</x> 167 <x>5</x>
168 <y>50</y> 168 <y>50</y>
169 - <width>71</width> 169 + <width>81</width>
170 <height>20</height> 170 <height>20</height>
171 </rect> 171 </rect>
172 </property> 172 </property>
@@ -177,7 +177,7 @@ @@ -177,7 +177,7 @@
177 <widget class="QDoubleSpinBox" name="spinCondNAi"> 177 <widget class="QDoubleSpinBox" name="spinCondNAi">
178 <property name="geometry"> 178 <property name="geometry">
179 <rect> 179 <rect>
180 - <x>80</x> 180 + <x>90</x>
181 <y>20</y> 181 <y>20</y>
182 <width>62</width> 182 <width>62</width>
183 <height>22</height> 183 <height>22</height>
@@ -195,7 +195,7 @@ @@ -195,7 +195,7 @@
195 <rect> 195 <rect>
196 <x>5</x> 196 <x>5</x>
197 <y>20</y> 197 <y>20</y>
198 - <width>71</width> 198 + <width>91</width>
199 <height>20</height> 199 <height>20</height>
200 </rect> 200 </rect>
201 </property> 201 </property>
@@ -244,7 +244,7 @@ @@ -244,7 +244,7 @@
244 <widget class="QDoubleSpinBox" name="spinObjNAi"> 244 <widget class="QDoubleSpinBox" name="spinObjNAi">
245 <property name="geometry"> 245 <property name="geometry">
246 <rect> 246 <rect>
247 - <x>80</x> 247 + <x>90</x>
248 <y>50</y> 248 <y>50</y>
249 <width>62</width> 249 <width>62</width>
250 <height>22</height> 250 <height>22</height>
@@ -262,7 +262,7 @@ @@ -262,7 +262,7 @@
262 <rect> 262 <rect>
263 <x>20</x> 263 <x>20</x>
264 <y>80</y> 264 <y>80</y>
265 - <width>82</width> 265 + <width>111</width>
266 <height>17</height> 266 <height>17</height>
267 </rect> 267 </rect>
268 </property> 268 </property>
@@ -278,7 +278,7 @@ @@ -278,7 +278,7 @@
278 <rect> 278 <rect>
279 <x>150</x> 279 <x>150</x>
280 <y>80</y> 280 <y>80</y>
281 - <width>82</width> 281 + <width>91</width>
282 <height>17</height> 282 <height>17</height>
283 </rect> 283 </rect>
284 </property> 284 </property>
@@ -296,15 +296,15 @@ @@ -296,15 +296,15 @@
296 </rect> 296 </rect>
297 </property> 297 </property>
298 <property name="text"> 298 <property name="text">
299 - <string>Point Detector</string> 299 + <string>Point Det.</string>
300 </property> 300 </property>
301 </widget> 301 </widget>
302 <widget class="QSpinBox" name="spinObjectiveSamples"> 302 <widget class="QSpinBox" name="spinObjectiveSamples">
303 <property name="geometry"> 303 <property name="geometry">
304 <rect> 304 <rect>
305 - <x>10</x> 305 + <x>1</x>
306 <y>100</y> 306 <y>100</y>
307 - <width>42</width> 307 + <width>51</width>
308 <height>22</height> 308 <height>22</height>
309 </rect> 309 </rect>
310 </property> 310 </property>
@@ -320,7 +320,7 @@ @@ -320,7 +320,7 @@
320 <rect> 320 <rect>
321 <x>60</x> 321 <x>60</x>
322 <y>100</y> 322 <y>100</y>
323 - <width>71</width> 323 + <width>81</width>
324 <height>16</height> 324 <height>16</height>
325 </rect> 325 </rect>
326 </property> 326 </property>
@@ -334,7 +334,7 @@ @@ -334,7 +334,7 @@
334 <rect> 334 <rect>
335 <x>280</x> 335 <x>280</x>
336 <y>20</y> 336 <y>20</y>
337 - <width>161</width> 337 + <width>181</width>
338 <height>411</height> 338 <height>411</height>
339 </rect> 339 </rect>
340 </property> 340 </property>
@@ -454,9 +454,9 @@ @@ -454,9 +454,9 @@
454 <widget class="QLabel" name="label"> 454 <widget class="QLabel" name="label">
455 <property name="geometry"> 455 <property name="geometry">
456 <rect> 456 <rect>
457 - <x>20</x> 457 + <x>10</x>
458 <y>20</y> 458 <y>20</y>
459 - <width>61</width> 459 + <width>71</width>
460 <height>16</height> 460 <height>16</height>
461 </rect> 461 </rect>
462 </property> 462 </property>
@@ -469,7 +469,7 @@ @@ -469,7 +469,7 @@
469 <rect> 469 <rect>
470 <x>10</x> 470 <x>10</x>
471 <y>230</y> 471 <y>230</y>
472 - <width>131</width> 472 + <width>151</width>
473 <height>17</height> 473 <height>17</height>
474 </rect> 474 </rect>
475 </property> 475 </property>
@@ -485,7 +485,7 @@ @@ -485,7 +485,7 @@
485 <rect> 485 <rect>
486 <x>10</x> 486 <x>10</x>
487 <y>170</y> 487 <y>170</y>
488 - <width>131</width> 488 + <width>151</width>
489 <height>17</height> 489 <height>17</height>
490 </rect> 490 </rect>
491 </property> 491 </property>
@@ -624,7 +624,7 @@ @@ -624,7 +624,7 @@
624 <widget class="QDoubleSpinBox" name="spinDispScaleK"> 624 <widget class="QDoubleSpinBox" name="spinDispScaleK">
625 <property name="geometry"> 625 <property name="geometry">
626 <rect> 626 <rect>
627 - <x>90</x> 627 + <x>120</x>
628 <y>290</y> 628 <y>290</y>
629 <width>51</width> 629 <width>51</width>
630 <height>22</height> 630 <height>22</height>
@@ -637,7 +637,7 @@ @@ -637,7 +637,7 @@
637 <widget class="QDoubleSpinBox" name="spinDispScaleN"> 637 <widget class="QDoubleSpinBox" name="spinDispScaleN">
638 <property name="geometry"> 638 <property name="geometry">
639 <rect> 639 <rect>
640 - <x>90</x> 640 + <x>120</x>
641 <y>340</y> 641 <y>340</y>
642 <width>51</width> 642 <width>51</width>
643 <height>22</height> 643 <height>22</height>
@@ -665,7 +665,7 @@ @@ -665,7 +665,7 @@
665 <rect> 665 <rect>
666 <x>50</x> 666 <x>50</x>
667 <y>190</y> 667 <y>190</y>
668 - <width>82</width> 668 + <width>101</width>
669 <height>17</height> 669 <height>17</height>
670 </rect> 670 </rect>
671 </property> 671 </property>
@@ -692,7 +692,7 @@ @@ -692,7 +692,7 @@
692 <widget class="QDoubleSpinBox" name="spinNormFactor"> 692 <widget class="QDoubleSpinBox" name="spinNormFactor">
693 <property name="geometry"> 693 <property name="geometry">
694 <rect> 694 <rect>
695 - <x>90</x> 695 + <x>120</x>
696 <y>380</y> 696 <y>380</y>
697 <width>62</width> 697 <width>62</width>
698 <height>22</height> 698 <height>22</height>
@@ -868,8 +868,8 @@ @@ -868,8 +868,8 @@
868 <rect> 868 <rect>
869 <x>120</x> 869 <x>120</x>
870 <y>50</y> 870 <y>50</y>
871 - <width>46</width>  
872 - <height>13</height> 871 + <width>51</width>
  872 + <height>16</height>
873 </rect> 873 </rect>
874 </property> 874 </property>
875 <property name="text"> 875 <property name="text">
@@ -883,8 +883,8 @@ @@ -883,8 +883,8 @@
883 <rect> 883 <rect>
884 <x>0</x> 884 <x>0</x>
885 <y>0</y> 885 <y>0</y>
886 - <width>464</width>  
887 - <height>21</height> 886 + <width>511</width>
  887 + <height>25</height>
888 </rect> 888 </rect>
889 </property> 889 </property>
890 <widget class="QMenu" name="menuFile"> 890 <widget class="QMenu" name="menuFile">
1 #include <fstream> 1 #include <fstream>
2 using namespace std; 2 using namespace std;
3 #include "interactivemie.h" 3 #include "interactivemie.h"
4 -#include <QtGui/QApplication> 4 +#include <QtGui/QApplication>
  5 +#include <QGraphicsScene>
  6 +#include <QGraphicsView>
  7 +#include <QGraphicsPixmapItem>
5 #include "qtSpectrumDisplay.h" 8 #include "qtSpectrumDisplay.h"
6 #include "globals.h" 9 #include "globals.h"
7 #include "rtsGUIConsole.h" 10 #include "rtsGUIConsole.h"
@@ -11,7 +14,11 @@ using namespace std; @@ -11,7 +14,11 @@ using namespace std;
11 14
12 PerformanceData PD; 15 PerformanceData PD;
13 16
14 -qtSpectrumDisplay* gpSpectrumDisplay; 17 +qtSpectrumDisplay* gpSpectrumDisplay;
  18 +
  19 +QGraphicsScene* distortionScene = NULL;
  20 +QGraphicsView* distortionWindow = NULL;
  21 +QGraphicsPixmapItem* pixmapItem = NULL;
15 22
16 vector<vector<SpecPair> > RefSpectrum; 23 vector<vector<SpecPair> > RefSpectrum;
17 vector<SpecPair> SimSpectrum; 24 vector<SpecPair> SimSpectrum;
@@ -209,7 +216,7 @@ void FitDisplay(){ @@ -209,7 +216,7 @@ void FitDisplay(){
209 void ChangeAbsorbance(){ 216 void ChangeAbsorbance(){
210 217
211 //compute the real part of the index of refraction 218 //compute the real part of the index of refraction
212 - 219 +
213 //copy the absorbance values into a linear array 220 //copy the absorbance values into a linear array
214 int nSamples = MaterialList[currentMaterial].eta.size(); 221 int nSamples = MaterialList[currentMaterial].eta.size();
215 double startNu = MaterialList[currentMaterial].nu.front(); 222 double startNu = MaterialList[currentMaterial].nu.front();
@@ -280,11 +287,11 @@ void SetMaterial() @@ -280,11 +287,11 @@ void SetMaterial()
280 287
281 int main(int argc, char *argv[]) 288 int main(int argc, char *argv[])
282 { 289 {
283 - 290 +
284 291
285 //load the default project file (any previous optical settings) 292 //load the default project file (any previous optical settings)
286 LoadState(); 293 LoadState();
287 - 294 +
288 //load the default materials 295 //load the default materials
289 LoadMaterial("eta_TolueneK.txt", "eta_TolueneN.txt", "Toluene"); 296 LoadMaterial("eta_TolueneK.txt", "eta_TolueneN.txt", "Toluene");
290 LoadMaterial("kPMMA.txt", "PMMA"); 297 LoadMaterial("kPMMA.txt", "PMMA");
@@ -294,25 +301,36 @@ int main(int argc, char *argv[]) @@ -294,25 +301,36 @@ int main(int argc, char *argv[])
294 //compute the analytical solution for the Mie scattered spectrum 301 //compute the analytical solution for the Mie scattered spectrum
295 SimulateSpectrum(); 302 SimulateSpectrum();
296 303
297 - QApplication a(argc, argv); 304 + QApplication a(argc, argv);
  305 +
  306 + //create and position the UI window
298 InteractiveMie w; 307 InteractiveMie w;
299 -  
300 -  
301 w.show(); 308 w.show();
302 -  
303 -  
304 w.move(0, 0); 309 w.move(0, 0);
305 - QRect frame = w.frameGeometry();  
306 - QRect inside = w.geometry(); 310 + QRect uiFrame = w.frameGeometry();
  311 + QRect uiNoFrame = w.geometry();
  312 + int frameHeight = uiFrame.height() - uiNoFrame.height();
307 313
308 //activate a console for output 314 //activate a console for output
309 - RedirectIOToConsole(0, frame.height(), frame.width());  
310 - 315 + RedirectIOToConsole(0, uiFrame.height(), uiFrame.width(), 400);
  316 + printf("Frame height: %d\n", frameHeight);
  317 +
  318 + //set the size and position of the spectrum window
  319 + int visWinSize = uiFrame.height()/2 - frameHeight;
  320 + //create the far field window
311 gpSpectrumDisplay = new qtSpectrumDisplay(); 321 gpSpectrumDisplay = new qtSpectrumDisplay();
312 - gpSpectrumDisplay->move(frame.width(), 0);  
313 - gpSpectrumDisplay->resize(2*inside.height(), inside.height());  
314 -  
315 - gpSpectrumDisplay->show(); 322 + gpSpectrumDisplay->resize(visWinSize*2, visWinSize);
  323 + gpSpectrumDisplay->move(uiFrame.width(), 0);
  324 + gpSpectrumDisplay->show();
  325 +
  326 + //distortion dialog box
  327 + distortionDialog = new qtDistortionDialog();
  328 + distortionDialog->move(0, 0);
  329 +
  330 + //display the distortion map
  331 + distortionScene = new QGraphicsScene();
  332 + distortionWindow = new QGraphicsView(distortionScene);
  333 + distortionWindow->move(uiFrame.width(), visWinSize);
316 334
317 //refresh the UI 335 //refresh the UI
318 w.refreshUI(); 336 w.refreshUI();
qtSpectrumDisplay.cpp
1 - #include <QtGui>  
2 - #include <QtOpenGL/QtOpenGL> 1 +#include <QtGui>
  2 +#include <QtOpenGL/QtOpenGL>
3 #include <GL/glu.h> 3 #include <GL/glu.h>
4 4
5 - #include <math.h>  
6 -  
7 - #include "qtSpectrumDisplay.h"  
8 -  
9 - qtSpectrumDisplay::qtSpectrumDisplay(QWidget *parent)  
10 - : QGLWidget(parent)  
11 - {  
12 - object = 0;  
13 - xRot = 0;  
14 - yRot = 0;  
15 - zRot = 0;  
16 -  
17 - qtGreen = QColor::fromCmykF(0.40, 0.0, 1.0, 0.0);  
18 - qtPurple = QColor::fromCmykF(0.39, 0.39, 0.0, 0.0);  
19 - }  
20 -  
21 - qtSpectrumDisplay::~qtSpectrumDisplay()  
22 - {  
23 - makeCurrent();  
24 - glDeleteLists(object, 1);  
25 - }  
26 -  
27 - QSize qtSpectrumDisplay::minimumSizeHint() const  
28 - {  
29 - return QSize(50, 50);  
30 - }  
31 -  
32 - QSize qtSpectrumDisplay::sizeHint() const  
33 - {  
34 - return QSize(400, 400);  
35 - }  
36 -  
37 - /*void qtSpectrumDisplay::setXRotation(int angle)  
38 - {  
39 - normalizeAngle(&angle);  
40 - if (angle != xRot) {  
41 - xRot = angle;  
42 - emit xRotationChanged(angle);  
43 - updateGL(); 5 +#include <math.h>
  6 +
  7 +#include "qtSpectrumDisplay.h"
  8 +
  9 +qtSpectrumDisplay::qtSpectrumDisplay(QWidget *parent)
  10 + : QGLWidget(parent)
  11 +{
  12 + object = 0;
  13 + xRot = 0;
  14 + yRot = 0;
  15 + zRot = 0;
  16 +
  17 + qtGreen = QColor::fromCmykF(0.40, 0.0, 1.0, 0.0);
  18 + qtPurple = QColor::fromCmykF(0.39, 0.39, 0.0, 0.0);
  19 +}
  20 +
  21 +qtSpectrumDisplay::~qtSpectrumDisplay()
  22 +{
  23 + makeCurrent();
  24 + glDeleteLists(object, 1);
  25 +}
  26 +
  27 +QSize qtSpectrumDisplay::minimumSizeHint() const
  28 +{
  29 + return QSize(50, 50);
  30 +}
  31 +
  32 +QSize qtSpectrumDisplay::sizeHint() const
  33 +{
  34 + return QSize(400, 400);
  35 +}
  36 +
  37 +void qtSpectrumDisplay::initializeGL()
  38 +{
  39 + qglClearColor(qtPurple.dark());
  40 + //object = makeObject();
  41 + glShadeModel(GL_FLAT);
  42 + glEnable(GL_DEPTH_TEST);
  43 + glEnable(GL_CULL_FACE);
  44 +}
  45 +
  46 +void qtSpectrumDisplay::printWavenumber(int xPos)
  47 +{
  48 + int viewParams[4];
  49 + glGetIntegerv(GL_VIEWPORT, viewParams);
  50 +
  51 + float a = (float)xPos/(float)viewParams[2];
  52 +
  53 + int wn = a * (nuMax - nuMin) + nuMin;
  54 + cout<<wn<<endl;
  55 +
  56 +
  57 +
  58 +}
  59 +
  60 +void qtSpectrumDisplay::paintGL()
  61 +{
  62 + //prepare the projection (orthographic, bounded by spectral values)
  63 + glMatrixMode(GL_PROJECTION);
  64 + glLoadIdentity();
  65 + gluOrtho2D(nuMin, nuMax, aMin, aMax);
  66 + glMatrixMode(GL_MODELVIEW);
  67 + glLoadIdentity();
  68 +
  69 + //clear the screen
  70 + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  71 +
  72 + //set the line width
  73 + glLineWidth(2);
  74 +
  75 + //draw the simulated spectrum (in white)
  76 + if(dispSimSpec)
  77 + {
  78 + glColor3f(1.0, 1.0, 1.0);
  79 + glBegin(GL_LINE_STRIP);
  80 + for(unsigned int i=0; i<SimSpectrum.size(); i++)
  81 + glVertex2f(SimSpectrum[i].nu, SimSpectrum[i].A);
  82 + glEnd();
  83 + }
  84 + //draw the reference spectrum in gray
  85 + if(dispRefSpec && RefSpectrum.size() > 0)
  86 + {
  87 + glColor3f(0.5, 0.5, 0.5);
  88 + glBegin(GL_LINE_STRIP);
  89 + float nu;
  90 + for(unsigned int i=0; i<RefSpectrum[currentSpec].size(); i++)
  91 + {
  92 + nu = RefSpectrum[currentSpec][i].nu;
  93 + glVertex2f(nu, RefSpectrum[currentSpec][i].A + nu * refSlope);
44 } 94 }
45 - }  
46 -  
47 - void qtSpectrumDisplay::setYRotation(int angle)  
48 - {  
49 - normalizeAngle(&angle);  
50 - if (angle != yRot) {  
51 - yRot = angle;  
52 - emit yRotationChanged(angle);  
53 - updateGL(); 95 + glEnd();
  96 + }
  97 +
  98 + //draw the material properties
  99 +
  100 + //change the viewport properties (materials are plotted on a different scale)
  101 +
  102 + //compute the maximum k and n
  103 + int nSamples = MaterialList[currentMaterial].eta.size();
  104 + float maxK = 0.0;
  105 + float maxN = 0.0;
  106 + float thisN, thisK;
  107 + for(int i=0; i<nSamples; i++)
  108 + {
  109 + thisN = fabs(MaterialList[currentMaterial].eta[i].real() - 1.49);
  110 + if(thisN > maxN)
  111 + maxN = thisN;
  112 + thisK = fabs(MaterialList[currentMaterial].eta[i].imag());
  113 + if(thisK > maxK)
  114 + thisK = maxK;
  115 + }
  116 + cout<<maxN<<"---------"<<maxK<<endl;
  117 +
  118 +
  119 + glMatrixMode(GL_PROJECTION);
  120 + glLoadIdentity();
  121 + gluOrtho2D(nuMin, nuMax, aMin, aMax);
  122 +
  123 +
  124 + float nu;
  125 + //display absorbance
  126 + if(dispMatK)
  127 + {
  128 +
  129 + glColor3f(1.0, 0.0, 0.0);
  130 + glBegin(GL_LINE_STRIP);
  131 + for(int i=0; i<nSamples; i++){
  132 + nu = MaterialList[currentMaterial].nu[i];
  133 + glVertex2f(nu, MaterialList[currentMaterial].eta[i].imag() * dispScaleK);
54 } 134 }
55 - }  
56 -  
57 - void qtSpectrumDisplay::setZRotation(int angle)  
58 - {  
59 - normalizeAngle(&angle);  
60 - if (angle != zRot) {  
61 - zRot = angle;  
62 - emit zRotationChanged(angle);  
63 - updateGL(); 135 + glEnd();
  136 + }
  137 + if(dispSimK)
  138 + {
  139 + glColor3f(1.0, 1.0, 0.0);
  140 + glBegin(GL_LINE_STRIP);
  141 + for(unsigned int i=0; i<EtaK.size(); i++){
  142 + glVertex2f(EtaK[i].nu, EtaK[i].A * dispScaleK);
64 } 143 }
65 - }*/  
66 -  
67 - void qtSpectrumDisplay::initializeGL()  
68 - {  
69 - qglClearColor(qtPurple.dark());  
70 - //object = makeObject();  
71 - glShadeModel(GL_FLAT);  
72 - glEnable(GL_DEPTH_TEST);  
73 - glEnable(GL_CULL_FACE);  
74 - }  
75 -  
76 - void qtSpectrumDisplay::printWavenumber(int xPos)  
77 - {  
78 - int viewParams[4];  
79 - glGetIntegerv(GL_VIEWPORT, viewParams);  
80 -  
81 - float a = (float)xPos/(float)viewParams[2];  
82 -  
83 - int wn = a * (nuMax - nuMin) + nuMin;  
84 - cout<<wn<<endl;  
85 -  
86 - }  
87 -  
88 - void qtSpectrumDisplay::paintGL()  
89 - {  
90 - glMatrixMode(GL_PROJECTION);  
91 - glLoadIdentity();  
92 - //glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);  
93 - gluOrtho2D(nuMin, nuMax, aMin, aMax);  
94 - glMatrixMode(GL_MODELVIEW);  
95 -  
96 - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  
97 - glLoadIdentity();  
98 - /*glTranslated(0.0, 0.0, -10.0);  
99 - glRotated(xRot / 16.0, 1.0, 0.0, 0.0);  
100 - glRotated(yRot / 16.0, 0.0, 1.0, 0.0);  
101 - glRotated(zRot / 16.0, 0.0, 0.0, 1.0);*/  
102 - glLineWidth(2);  
103 - if(dispSimSpec)  
104 - {  
105 - glColor3f(1.0, 1.0, 1.0);  
106 - glBegin(GL_LINE_STRIP);  
107 - for(unsigned int i=0; i<SimSpectrum.size(); i++)  
108 - glVertex2f(SimSpectrum[i].nu, SimSpectrum[i].A);  
109 - glEnd();  
110 - }  
111 - if(dispRefSpec && RefSpectrum.size() > 0)  
112 - {  
113 - glColor3f(0.5, 0.5, 0.5);  
114 - glBegin(GL_LINE_STRIP);  
115 - float nu;  
116 - for(unsigned int i=0; i<RefSpectrum[currentSpec].size(); i++)  
117 - {  
118 - nu = RefSpectrum[currentSpec][i].nu;  
119 - glVertex2f(nu, RefSpectrum[currentSpec][i].A + nu * refSlope);  
120 - }  
121 - glEnd();  
122 - }  
123 -  
124 - int nSamples = MaterialList[currentMaterial].eta.size();  
125 - float nu;  
126 - //display absorbance  
127 - if(dispMatK)  
128 - {  
129 -  
130 - glColor3f(1.0, 0.0, 0.0);  
131 - glBegin(GL_LINE_STRIP);  
132 - for(int i=0; i<nSamples; i++){  
133 - nu = MaterialList[currentMaterial].nu[i];  
134 - glVertex2f(nu, MaterialList[currentMaterial].eta[i].imag() * dispScaleK);  
135 - }  
136 - glEnd();  
137 - }  
138 - if(dispSimK)  
139 - {  
140 - glColor3f(1.0, 1.0, 0.0);  
141 - glBegin(GL_LINE_STRIP);  
142 - for(unsigned int i=0; i<EtaK.size(); i++){  
143 - glVertex2f(EtaK[i].nu, EtaK[i].A * dispScaleK);  
144 - }  
145 - glEnd();  
146 - }  
147 -  
148 - //display refractive index (real)  
149 - if(dispMatN)  
150 - {  
151 - glColor3f(0.0, 1.0, 0.0);  
152 - glBegin(GL_LINE_STRIP);  
153 - for(int i=0; i<nSamples; i++){  
154 - nu = MaterialList[currentMaterial].nu[i];  
155 - glVertex2f(nu, (MaterialList[currentMaterial].eta[i].real() - baseIR) * dispScaleN);  
156 - }  
157 - glEnd();  
158 - }  
159 - if(dispSimN)  
160 - {  
161 - glColor3f(0.0, 1.0, 1.0);  
162 - glBegin(GL_LINE_STRIP);  
163 - for(unsigned int i=0; i<EtaN.size(); i++)  
164 - glVertex2f(EtaN[i].nu, (EtaN[i].A - baseIR) * dispScaleN);  
165 - glEnd();  
166 - }  
167 -  
168 -  
169 - glCallList(object);  
170 - }  
171 -  
172 - void qtSpectrumDisplay::resizeGL(int width, int height)  
173 - {  
174 - int side = qMin(width, height);  
175 - //glViewport((width - side) / 2, (height - side) / 2, side, side);  
176 - glViewport(0, 0, width, height);  
177 -  
178 - /*glMatrixMode(GL_PROJECTION);  
179 - glLoadIdentity();  
180 - //glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);  
181 - gluOrtho2D(nuMin, nuMax, aMin, aMax);  
182 - glMatrixMode(GL_MODELVIEW);*/  
183 - }  
184 -  
185 - void qtSpectrumDisplay::mousePressEvent(QMouseEvent *event)  
186 - {  
187 - lastPos = event->pos();  
188 -  
189 - if(event->buttons() & Qt::LeftButton)  
190 - {  
191 - int wn = 0;  
192 - printWavenumber(event->x());  
193 - }  
194 - }  
195 -  
196 - void qtSpectrumDisplay::mouseMoveEvent(QMouseEvent *event)  
197 - {  
198 - int dx = event->x() - lastPos.x();  
199 - int dy = event->y() - lastPos.y();  
200 - /*  
201 - if (event->buttons() & Qt::LeftButton) {  
202 - setXRotation(xRot + 8 * dy);  
203 - setYRotation(yRot + 8 * dx);  
204 - } else if (event->buttons() & Qt::RightButton) {  
205 - setXRotation(xRot + 8 * dy);  
206 - setZRotation(zRot + 8 * dx);  
207 - }*/  
208 - lastPos = event->pos(); 144 + glEnd();
  145 +}
  146 +
  147 +//display refractive index (real)
  148 +if(dispMatN)
  149 +{
  150 + glColor3f(0.0, 1.0, 0.0);
  151 + glBegin(GL_LINE_STRIP);
  152 + for(int i=0; i<nSamples; i++){
  153 + nu = MaterialList[currentMaterial].nu[i];
  154 + glVertex2f(nu, (MaterialList[currentMaterial].eta[i].real() - baseIR) * dispScaleN);
209 } 155 }
  156 + glEnd();
  157 +}
  158 +if(dispSimN)
  159 +{
  160 + glColor3f(0.0, 1.0, 1.0);
  161 + glBegin(GL_LINE_STRIP);
  162 + for(unsigned int i=0; i<EtaN.size(); i++)
  163 + glVertex2f(EtaN[i].nu, (EtaN[i].A - baseIR) * dispScaleN);
  164 + glEnd();
  165 +}
210 166
211 - /*GLuint qtSpectrumDisplay::makeObject()  
212 - {  
213 - GLuint list = glGenLists(1);  
214 - glNewList(list, GL_COMPILE);  
215 -  
216 - glBegin(GL_QUADS);  
217 -  
218 - GLdouble x1 = +0.06;  
219 - GLdouble y1 = -0.14;  
220 - GLdouble x2 = +0.14;  
221 - GLdouble y2 = -0.06;  
222 - GLdouble x3 = +0.08;  
223 - GLdouble y3 = +0.00;  
224 - GLdouble x4 = +0.30;  
225 - GLdouble y4 = +0.22;  
226 -  
227 - quad(x1, y1, x2, y2, y2, x2, y1, x1);  
228 - quad(x3, y3, x4, y4, y4, x4, y3, x3);  
229 167
230 - extrude(x1, y1, x2, y2);  
231 - extrude(x2, y2, y2, x2);  
232 - extrude(y2, x2, y1, x1);  
233 - extrude(y1, x1, x1, y1);  
234 - extrude(x3, y3, x4, y4);  
235 - extrude(x4, y4, y4, x4);  
236 - extrude(y4, x4, y3, x3); 168 +glCallList(object);
  169 +
  170 +glFlush();
237 171
238 - const double Pi = 3.14159265358979323846;  
239 - const int NumSectors = 200; 172 +//display the values at the mouse location
  173 +renderText(50, 50, "test");
  174 +}
240 175
241 - for (int i = 0; i < NumSectors; ++i) {  
242 - double angle1 = (i * 2 * Pi) / NumSectors;  
243 - GLdouble x5 = 0.30 * sin(angle1);  
244 - GLdouble y5 = 0.30 * cos(angle1);  
245 - GLdouble x6 = 0.20 * sin(angle1);  
246 - GLdouble y6 = 0.20 * cos(angle1); 176 +void qtSpectrumDisplay::resizeGL(int width, int height)
  177 +{
  178 + int side = qMin(width, height);
  179 + glViewport(0, 0, width, height);
247 180
248 - double angle2 = ((i + 1) * 2 * Pi) / NumSectors;  
249 - GLdouble x7 = 0.20 * sin(angle2);  
250 - GLdouble y7 = 0.20 * cos(angle2);  
251 - GLdouble x8 = 0.30 * sin(angle2);  
252 - GLdouble y8 = 0.30 * cos(angle2); 181 +}
253 182
254 - quad(x5, y5, x6, y6, x7, y7, x8, y8);  
255 -  
256 - extrude(x6, y6, x7, y7);  
257 - extrude(x8, y8, x5, y5);  
258 - }  
259 -  
260 - glEnd(); 183 +void qtSpectrumDisplay::mousePressEvent(QMouseEvent *event)
  184 +{
  185 + lastPos = event->pos();
261 186
262 - glEndList();  
263 - return list;  
264 - }*/  
265 -  
266 - void qtSpectrumDisplay::quad(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2,  
267 - GLdouble x3, GLdouble y3, GLdouble x4, GLdouble y4) 187 + if(event->buttons() & Qt::LeftButton)
268 { 188 {
269 - qglColor(qtGreen);  
270 -  
271 - glVertex3d(x1, y1, -0.05);  
272 - glVertex3d(x2, y2, -0.05);  
273 - glVertex3d(x3, y3, -0.05);  
274 - glVertex3d(x4, y4, -0.05);  
275 -  
276 - glVertex3d(x4, y4, +0.05);  
277 - glVertex3d(x3, y3, +0.05);  
278 - glVertex3d(x2, y2, +0.05);  
279 - glVertex3d(x1, y1, +0.05); 189 + int wn = 0;
  190 + printWavenumber(event->x());
280 } 191 }
281 -  
282 - /*void qtSpectrumDisplay::extrude(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2)  
283 - {  
284 - qglColor(qtGreen.dark(250 + int(100 * x1)));  
285 -  
286 - glVertex3d(x1, y1, +0.05);  
287 - glVertex3d(x2, y2, +0.05);  
288 - glVertex3d(x2, y2, -0.05);  
289 - glVertex3d(x1, y1, -0.05);  
290 - }*/  
291 -  
292 - void qtSpectrumDisplay::normalizeAngle(int *angle)  
293 - {  
294 - while (*angle < 0)  
295 - *angle += 360 * 16;  
296 - while (*angle > 360 * 16)  
297 - *angle -= 360 * 16;  
298 - }  
299 \ No newline at end of file 192 \ No newline at end of file
  193 +}
  194 +
  195 +void qtSpectrumDisplay::mouseMoveEvent(QMouseEvent *event)
  196 +{
  197 + int dx = event->x() - lastPos.x();
  198 + int dy = event->y() - lastPos.y();
  199 +
  200 + lastPos = event->pos();
  201 +}
  202 +
  203 +void qtSpectrumDisplay::quad(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2,
  204 + GLdouble x3, GLdouble y3, GLdouble x4, GLdouble y4)
  205 +{
  206 + qglColor(qtGreen);
  207 +
  208 + glVertex3d(x1, y1, -0.05);
  209 + glVertex3d(x2, y2, -0.05);
  210 + glVertex3d(x3, y3, -0.05);
  211 + glVertex3d(x4, y4, -0.05);
  212 +
  213 + glVertex3d(x4, y4, +0.05);
  214 + glVertex3d(x3, y3, +0.05);
  215 + glVertex3d(x2, y2, +0.05);
  216 + glVertex3d(x1, y1, +0.05);
  217 +}
  218 +
  219 +void qtSpectrumDisplay::normalizeAngle(int *angle)
  220 +{
  221 + while (*angle < 0)
  222 + *angle += 360 * 16;
  223 + while (*angle > 360 * 16)
  224 + *angle -= 360 * 16;
  225 +}
rtsGUIConsole.cpp deleted
1 -#ifdef WIN32  
2 -#include <windows.h>  
3 -#include <stdio.h>  
4 -#include <fcntl.h>  
5 -#include <io.h>  
6 -#include <iostream>  
7 -#include <fstream>  
8 -  
9 -#ifndef _USE_OLD_IOSTREAMS  
10 -  
11 -using namespace std;  
12 -#endif  
13 -  
14 -// maximum mumber of lines the output console should have  
15 -  
16 -static const WORD MAX_CONSOLE_LINES = 500;  
17 -//#ifdef _DEBUG  
18 -  
19 -void RedirectIOToConsole(int Xpos, int Ypos, int Width, int Height)  
20 -{  
21 - int hConHandle;  
22 - long lStdHandle;  
23 - CONSOLE_SCREEN_BUFFER_INFO coninfo;  
24 - FILE *fp;  
25 - // allocate a console for this app  
26 - AllocConsole();  
27 - // set the screen buffer to be big enough to let us scroll text  
28 - GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);  
29 - coninfo.dwSize.Y = MAX_CONSOLE_LINES;  
30 - SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE),  
31 - coninfo.dwSize);  
32 - // redirect unbuffered STDOUT to the console  
33 - lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);  
34 - hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);  
35 - fp = _fdopen( hConHandle, "w" );  
36 - *stdout = *fp;  
37 - setvbuf( stdout, NULL, _IONBF, 0 );  
38 - // redirect unbuffered STDIN to the console  
39 - lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE);  
40 - hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);  
41 - fp = _fdopen( hConHandle, "r" );  
42 - *stdin = *fp;  
43 - setvbuf( stdin, NULL, _IONBF, 0 );  
44 -  
45 - // redirect unbuffered STDERR to the console  
46 - lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE);  
47 - hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);  
48 - fp = _fdopen( hConHandle, "w" );  
49 - *stderr = *fp;  
50 - setvbuf( stderr, NULL, _IONBF, 0 );  
51 -  
52 - // make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog  
53 - // point to console as well  
54 - ios::sync_with_stdio();  
55 - //position  
56 - MoveWindow(GetConsoleWindow(), Xpos, Ypos, Width, Height, true);  
57 -}  
58 -  
59 -#else