Commit 0c9bf8ae3d756b11c482aa79a62fd9f3db7a51e0

Authored by dmayerich
1 parent bfe3f56b

Case-sensitive errors with the bessel functions.

CMakeLists.txt
1   -#Specify the version being used aswell as the language
2   -cmake_minimum_required(VERSION 2.8)
3   -#Name your project here
4   -project(IMie)
5   -
6   -#set the module directory
7   -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}")
8   -
9   -#find the Qt4
10   -find_package(Qt4 REQUIRED)
11   -find_package(Qt4 REQUIRED)
12   -include_directories(${QT_INCLUDE_DIRECTORY})
13   -include(${QT_USE_FILE})
14   -
15   -#set up CUDA
16   -find_package(CUDA)
17   -
18   -#find OpenGL
19   -find_package(OpenGL REQUIRED)
20   -
21   -#find GLUT
22   -set(GLUT_ROOT_PATH $ENV{GLUT_ROOT_PATH})
23   -find_package(GLUT REQUIRED)
24   -
25   -#find GLEW
26   -find_package(GLEW REQUIRED)
27   -
28   -#add Qt OpenGL stuff
29   -set(QT_USE_QTOPENGL TRUE)
30   -
31   -#ask the user for the RTS location
32   -set(RTS_ROOT_PATH $ENV{RTS_ROOT_PATH})
33   -find_package(RTS REQUIRED)
34   -
35   -#set the include directories
36   -include_directories(
37   - ${CMAKE_CURRENT_BINARY_DIR}
38   - ${QT_INCLUDES}
39   - ${QT_QTOPENGL_INCLUDE_DIR}
40   - ${OPENGL_INCLUDE_DIR}
41   - ${GLEW_INCLUDE_PATH}
42   - ${GLUT_INCLUDE_DIR}
43   - ${RTS_INCLUDE_DIR}
44   -)
45   -
46   -#Assign source files to the appropriate variables
47   -file(GLOB SRC_CPP "*.cpp")
48   -file(GLOB SRC_H "*.h")
49   -file(GLOB SRC_UI "*.ui")
50   -file(GLOB SRC_QRC "*.qrc")
51   -file(GLOB SRC_CU "*.cu")
52   -
53   -#set up copying data files
54   -configure_file(kPMMA.txt ${CMAKE_CURRENT_BINARY_DIR}/kPMMA.txt @ONLY)
55   -configure_file(eta_TolueneK.txt ${CMAKE_CURRENT_BINARY_DIR}/eta_TolueneK.txt @ONLY)
56   -configure_file(eta_TolueneN.txt ${CMAKE_CURRENT_BINARY_DIR}/eta_TolueneN.txt @ONLY)
57   -
58   -#determine which source files have to be moc'd
59   -Qt4_wrap_cpp(UI_MOC ${SRC_H})
60   -Qt4_wrap_ui(UI_H ${SRC_UI})
61   -Qt4_add_resources(ALL_RCC ${ALL_QRC})
62   -
63   -#moc the necessary files
64   -Qt4_automoc(${ALL_CPP})
65   -
66   -source_group(QtMoc FILES ${UI_MOC})
67   -source_group(QtUI FILES ${SRC_UI})
68   -
69   -#create an executable
70   -cuda_add_executable(IMie ${SRC_CPP} ${SRC_H} ${UI_H} ${UI_MOC} ${ALL_RCC} ${SRC_CU})
71   -
72   -#set the link libraries
73   -target_link_libraries(IMie ${QT_LIBRARIES} ${QT_QTOPENGL_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ${GLEW_LIBRARY})
74   -
75   -
76   -
  1 +#Specify the version being used aswell as the language
  2 +cmake_minimum_required(VERSION 2.8)
  3 +#Name your project here
  4 +project(IMie)
  5 +
  6 +#set the module directory
  7 +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}")
  8 +
  9 +#find the Qt4
  10 +find_package(Qt4 REQUIRED)
  11 +find_package(Qt4 REQUIRED)
  12 +include_directories(${QT_INCLUDE_DIRECTORY})
  13 +include(${QT_USE_FILE})
  14 +
  15 +#set up CUDA
  16 +find_package(CUDA)
  17 +
  18 +#find OpenGL
  19 +find_package(OpenGL REQUIRED)
  20 +
  21 +#find GLUT
  22 +set(GLUT_ROOT_PATH $ENV{GLUT_ROOT_PATH})
  23 +find_package(GLUT REQUIRED)
  24 +
  25 +#find GLEW
  26 +find_package(GLEW REQUIRED)
  27 +
  28 +#add Qt OpenGL stuff
  29 +set(QT_USE_QTOPENGL TRUE)
  30 +
  31 +#ask the user for the RTS location
  32 +set(RTS_ROOT_PATH $ENV{RTS_ROOT_PATH})
  33 +find_package(RTS REQUIRED)
  34 +
  35 +#set the include directories
  36 +include_directories(
  37 + ${CMAKE_CURRENT_BINARY_DIR}
  38 + ${QT_INCLUDES}
  39 + ${QT_QTOPENGL_INCLUDE_DIR}
  40 + ${OPENGL_INCLUDE_DIR}
  41 + ${GLEW_INCLUDE_PATH}
  42 + ${GLUT_INCLUDE_DIR}
  43 + ${RTS_INCLUDE_DIR}
  44 +)
  45 +
  46 +#Assign source files to the appropriate variables
  47 +file(GLOB SRC_CPP "*.cpp")
  48 +file(GLOB SRC_H "*.h")
  49 +file(GLOB SRC_UI "*.ui")
  50 +file(GLOB SRC_QRC "*.qrc")
  51 +file(GLOB SRC_CU "*.cu")
  52 +
  53 +#set up copying data files
  54 +configure_file(kPMMA.txt ${CMAKE_CURRENT_BINARY_DIR}/kPMMA.txt @ONLY)
  55 +configure_file(eta_TolueneK.txt ${CMAKE_CURRENT_BINARY_DIR}/eta_TolueneK.txt @ONLY)
  56 +configure_file(eta_TolueneN.txt ${CMAKE_CURRENT_BINARY_DIR}/eta_TolueneN.txt @ONLY)
  57 +
  58 +#determine which source files have to be moc'd
  59 +Qt4_wrap_cpp(UI_MOC ${SRC_H})
  60 +Qt4_wrap_ui(UI_H ${SRC_UI})
  61 +Qt4_add_resources(ALL_RCC ${ALL_QRC})
  62 +
  63 +#moc the necessary files
  64 +Qt4_automoc(${ALL_CPP})
  65 +
  66 +source_group(QtMoc FILES ${UI_MOC})
  67 +source_group(QtUI FILES ${SRC_UI})
  68 +
  69 +#create an executable
  70 +cuda_add_executable(IMie ${SRC_CPP} ${SRC_H} ${UI_H} ${UI_MOC} ${ALL_RCC} ${SRC_CU})
  71 +
  72 +#set the link libraries
  73 +target_link_libraries(IMie ${QT_LIBRARIES} ${QT_QTOPENGL_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ${GLEW_LIBRARY})
  74 +
  75 +
  76 +
... ...
EstimateMaterial.cpp
1   -#include "globals.h"
2   -#include <stdlib.h>
3   -#define PI 3.14159
4   -
5   -double CalculateError(double* E)
6   -{
7   - //Calculate the error between the Reference Spectrum and the Simulated Spectrum
8   - double sumE = 0.0;
9   - int nVals = RefSpectrum[currentSpec].size();
10   - double nu;
11   - for(int i=0; i<nVals; i++)
12   - {
13   - nu = RefSpectrum[currentSpec][i].nu;
14   - E[i] = RefSpectrum[currentSpec][i].A + nu * refSlope - SimSpectrum[i].A;
15   - sumE += E[i]*E[i];
16   - }
17   -
18   - return sumE/nVals;
19   -}
20   -
21   -void EstimateK(double* E)
22   -{
23   - int nVals = RefSpectrum[currentSpec].size();
24   - double nuStart = RefSpectrum[currentSpec].front().nu;
25   - double nuEnd = RefSpectrum[currentSpec].back().nu;
26   -
27   - double r = radius/10000.0;
28   - double nu;
29   - double dNu = (nuEnd - nuStart)/(nVals-1);
30   - double eScale;
31   - for(int i=0; i<nVals; i++)
32   - {
33   - nu = nuStart + i*2;
34   -
35   - eScale = 1/(8*PI*r*nu);
36   - EtaK[i].A = EtaK[i].A + eScale * E[i];
37   - if(EtaK[i].A < 0.0) EtaK[i].A = 0.0;
38   - }
39   -}
40   -
41   -void EstimateMaterial()
42   -{
43   - /*This function estimates the material properties of a sphere based on the
44   - input spectrum RefSpectrum and the optical properties of the system.
45   - 1) The material properties are stored in EtaK and EtaN
46   - 2) The best fit is stored in SimSpectrum*/
47   -
48   - //initialize the material index of refraction
49   - EtaN.clear();
50   - EtaK.clear();
51   -
52   - //insert the default material properties
53   - SpecPair temp;
54   - for(int s=0; s<(int)RefSpectrum[currentSpec].size(); s++)
55   - {
56   - //the real part of the IR is the user-specified baseline IR
57   - temp.nu = RefSpectrum[currentSpec][s].nu;
58   - temp.A = baseIR;
59   - EtaN.push_back(temp);
60   - //the imaginary part of the IR is zero absorbance
61   - temp.A = 0.0f;
62   - EtaK.push_back(temp);
63   - }
64   -
65   -
66   - //allocate space to store the list of error values
67   - double* E = (double*)malloc(sizeof(double) * RefSpectrum[currentSpec].size());
68   - //copy the absorbance values into a linear array
69   - double* k = (double*)malloc(sizeof(double) * EtaK.size());
70   - double* n = (double*)malloc(sizeof(double) * EtaN.size());
71   -
72   - //iterate to solve for both n and k
73   - double sumE = 99999.9;
74   - int j=0;
75   - //clear the console
76   - system("cls");
77   - while(sumE > minMSE && j < maxFitIter)
78   - {
79   - //simulate a spectrum based on the current IR
80   - SimulateSpectrum();
81   -
82   - //calculate the error term
83   - sumE = CalculateError(E);
84   -
85   - //estimate the new absorbance
86   - EstimateK(E);
87   -
88   - //use Kramers-Kronig to compute n
89   -
90   - for(unsigned int i=0; i<EtaK.size(); i++)
91   - k[i] = EtaK[i].A;
92   - cudaKramersKronig(n, k, EtaK.size(), EtaK.front().nu, EtaK.back().nu, baseIR);
93   -
94   - //copy the real part of the index of refraction into the vector
95   - EtaN.clear();
96   - for(int i=0; i<(int)EtaK.size(); i++)
97   - {
98   - temp.nu = EtaK[i].nu;
99   - temp.A = n[i];
100   - EtaN.push_back(temp);
101   - }
102   -
103   - cout<<" E = "<<sumE<<endl;
104   - j++;
105   - //SaveSpectrum(n, nVals, "simNj.txt");
106   - //SaveSpectrum(k, nVals, "simKj.txt");
107   - //SaveSpectrum(simSpec, nVals, "simSpec.txt");
108   - //exit(1);
109   -
110   - }
111   -
112   - free(E);
113   - free(k);
114   - free(n);
115   -
116   -
117   -
118   -
  1 +#include "globals.h"
  2 +#include <stdlib.h>
  3 +#define PI 3.14159
  4 +
  5 +double CalculateError(double* E)
  6 +{
  7 + //Calculate the error between the Reference Spectrum and the Simulated Spectrum
  8 + double sumE = 0.0;
  9 + int nVals = RefSpectrum[currentSpec].size();
  10 + double nu;
  11 + for(int i=0; i<nVals; i++)
  12 + {
  13 + nu = RefSpectrum[currentSpec][i].nu;
  14 + E[i] = RefSpectrum[currentSpec][i].A + nu * refSlope - SimSpectrum[i].A;
  15 + sumE += E[i]*E[i];
  16 + }
  17 +
  18 + return sumE/nVals;
  19 +}
  20 +
  21 +void EstimateK(double* E)
  22 +{
  23 + int nVals = RefSpectrum[currentSpec].size();
  24 + double nuStart = RefSpectrum[currentSpec].front().nu;
  25 + double nuEnd = RefSpectrum[currentSpec].back().nu;
  26 +
  27 + double r = radius/10000.0;
  28 + double nu;
  29 + double dNu = (nuEnd - nuStart)/(nVals-1);
  30 + double eScale;
  31 + for(int i=0; i<nVals; i++)
  32 + {
  33 + nu = nuStart + i*2;
  34 +
  35 + eScale = 1/(8*PI*r*nu);
  36 + EtaK[i].A = EtaK[i].A + eScale * E[i];
  37 + if(EtaK[i].A < 0.0) EtaK[i].A = 0.0;
  38 + }
  39 +}
  40 +
  41 +void EstimateMaterial()
  42 +{
  43 + /*This function estimates the material properties of a sphere based on the
  44 + input spectrum RefSpectrum and the optical properties of the system.
  45 + 1) The material properties are stored in EtaK and EtaN
  46 + 2) The best fit is stored in SimSpectrum*/
  47 +
  48 + //initialize the material index of refraction
  49 + EtaN.clear();
  50 + EtaK.clear();
  51 +
  52 + //insert the default material properties
  53 + SpecPair temp;
  54 + for(int s=0; s<(int)RefSpectrum[currentSpec].size(); s++)
  55 + {
  56 + //the real part of the IR is the user-specified baseline IR
  57 + temp.nu = RefSpectrum[currentSpec][s].nu;
  58 + temp.A = baseIR;
  59 + EtaN.push_back(temp);
  60 + //the imaginary part of the IR is zero absorbance
  61 + temp.A = 0.0f;
  62 + EtaK.push_back(temp);
  63 + }
  64 +
  65 +
  66 + //allocate space to store the list of error values
  67 + double* E = (double*)malloc(sizeof(double) * RefSpectrum[currentSpec].size());
  68 + //copy the absorbance values into a linear array
  69 + double* k = (double*)malloc(sizeof(double) * EtaK.size());
  70 + double* n = (double*)malloc(sizeof(double) * EtaN.size());
  71 +
  72 + //iterate to solve for both n and k
  73 + double sumE = 99999.9;
  74 + int j=0;
  75 + //clear the console
  76 + system("cls");
  77 + while(sumE > minMSE && j < maxFitIter)
  78 + {
  79 + //simulate a spectrum based on the current IR
  80 + SimulateSpectrum();
  81 +
  82 + //calculate the error term
  83 + sumE = CalculateError(E);
  84 +
  85 + //estimate the new absorbance
  86 + EstimateK(E);
  87 +
  88 + //use Kramers-Kronig to compute n
  89 +
  90 + for(unsigned int i=0; i<EtaK.size(); i++)
  91 + k[i] = EtaK[i].A;
  92 + cudaKramersKronig(n, k, EtaK.size(), EtaK.front().nu, EtaK.back().nu, baseIR);
  93 +
  94 + //copy the real part of the index of refraction into the vector
  95 + EtaN.clear();
  96 + for(int i=0; i<(int)EtaK.size(); i++)
  97 + {
  98 + temp.nu = EtaK[i].nu;
  99 + temp.A = n[i];
  100 + EtaN.push_back(temp);
  101 + }
  102 +
  103 + cout<<" E = "<<sumE<<endl;
  104 + j++;
  105 + //SaveSpectrum(n, nVals, "simNj.txt");
  106 + //SaveSpectrum(k, nVals, "simKj.txt");
  107 + //SaveSpectrum(simSpec, nVals, "simSpec.txt");
  108 + //exit(1);
  109 +
  110 + }
  111 +
  112 + free(E);
  113 + free(k);
  114 + free(n);
  115 +
  116 +
  117 +
  118 +
119 119 }
120 120 \ No newline at end of file
... ...
FileIO.cpp
1   -#include "globals.h"
2   -#include <sstream>
3   -#include <fstream>
4   -#include <iostream>
5   -using namespace std;
6   -
7   -vector<SpecPair> LoadSpectrum(string filename)
8   -{
9   - //load a spectrum from a file and resample to 2wn intervals
10   -
11   - //create the spectrum
12   - vector<SpecPair> S;
13   -
14   - //open the file
15   - ifstream inFile(filename.c_str());
16   -
17   -
18   - SpecPair temp;
19   - while(!inFile.eof()){
20   - inFile>>temp.nu;
21   - inFile>>temp.A;
22   - S.push_back(temp);
23   - }
24   -
25   - //compute the minimum and maximum input wavenumbers
26   - double inMin = S.front().nu;
27   - double inMax = S.back().nu;
28   -
29   - int nuMin = (int)ceil(inMin);
30   - int nuMax = (int)floor(inMax);
31   -
32   - //make sure both are either even or odd
33   - if(nuMin % 2 != nuMax % 2)
34   - nuMax--;
35   -
36   - //compute the number of values in the resampled spectrum
37   - int nVals = (nuMax - nuMin)/2 + 1;
38   -
39   - //allocate space for the spectrum
40   - vector<SpecPair> outSpec;
41   -
42   - double nu, highVal, lowVal, a;
43   - int j=1;
44   - for(int i=0; i<nVals; i++)
45   - {
46   - nu = nuMin + i * 2;
47   - temp.nu = nu;
48   -
49   - //handle the boundary cases
50   - if(nu < inMin || nu > inMax)
51   - temp.A = 0.0;
52   - else
53   - {
54   - //move to the correct position in the input array
55   - while(j < (int)S.size()-1 && S[j].nu <= nu)
56   - j++;
57   -
58   - lowVal = S[j-1].nu;
59   - highVal = S[j].nu;
60   - a = (nu - lowVal)/(highVal - lowVal);
61   - temp.A = S[j-1].A * (1.0 - a) + S[j].A * a;
62   - }
63   - outSpec.push_back(temp);
64   - }
65   -
66   -
67   -
68   - return outSpec;
69   -}
70   -
71   -vector<SpecPair> SetReferenceSpectrum(char* text)
72   -{
73   - stringstream inString(text);
74   -
75   - //create the spectrum
76   - vector<SpecPair> S;
77   -
78   - SpecPair temp;
79   - while(!inString.eof()){
80   - inString>>temp.nu;
81   - inString>>temp.A;
82   - S.push_back(temp);
83   - }
84   -
85   - return S;
86   -}
87   -
88   -void SaveK(string fileName)
89   -{
90   - ofstream outFile(fileName.c_str());
91   - for(unsigned int i=0; i<EtaK.size(); i++)
92   - {
93   - outFile<<EtaK[i].nu<<" ";
94   - outFile<<EtaK[i].A<<endl;
95   - }
96   - outFile.close();
97   -}
98   -
99   -void SaveN(string fileName)
100   -{
101   - ofstream outFile(fileName.c_str());
102   - for(unsigned int i=0; i<EtaN.size(); i++)
103   - {
104   - outFile<<EtaN[i].nu<<" ";
105   - outFile<<EtaN[i].A<<endl;
106   - }
107   - outFile.close();
108   -}
109   -
110   -void SaveSimulation(string fileName)
111   -{
112   - ofstream outFile(fileName.c_str());
113   - outFile.precision(10);
114   - for(unsigned int i=0; i<SimSpectrum.size(); i++)
115   - {
116   - outFile<<SimSpectrum[i].nu<<" ";
117   - outFile<<SimSpectrum[i].A<<endl;
118   - }
119   - outFile.close();
120   -}
121   -
122   -void SaveState()
123   -{
124   - ofstream outFile("main.prj");
125   - //Window Parameters
126   - outFile<<nuMin<<endl;
127   - outFile<<nuMax<<endl;
128   - outFile<<aMin<<endl;
129   - outFile<<aMax<<endl;
130   - outFile<<dNu<<endl;
131   -
132   - //material parameters
133   - outFile<<radius<<endl;
134   - outFile<<baseIR<<endl;
135   - outFile<<cA<<endl;
136   -
137   - //optical parameters
138   - outFile<<cNAi<<endl;
139   - outFile<<cNAo<<endl;
140   - outFile<<oNAi<<endl;
141   - outFile<<oNAo<<endl;
142   -
143   - outFile.close();
144   -
145   -}
146   -
147   -void LoadState()
148   -{
149   - ifstream inFile("main.prj");
150   - //Window Parameters
151   - inFile>>nuMin;
152   - inFile>>nuMax;
153   - inFile>>aMin;
154   - inFile>>aMax;
155   - inFile>>dNu;
156   -
157   - //material parameters
158   - inFile>>radius;
159   - inFile>>baseIR;
160   - inFile>>cA;
161   -
162   - //optical parameters
163   - inFile>>cNAi;
164   - inFile>>cNAo;
165   - inFile>>oNAi;
166   - inFile>>oNAo;
167   -
168   - inFile.close();
169   -
170   -}
171   -
172   -void SetDefaults()
173   -{
174   -
175   - nuMin = 800;
176   - nuMax = 4000;
177   - dNu = 2;
178   -
179   - aMin = 0;
180   - aMax = 1;
181   -
182   -
183   - //material parameters
184   - radius = 4.0f;
185   - baseIR = 1.49f;
186   - cA = 1.0;
187   - vector<SpecPair> KMaterial;
188   - vector<SpecPair> NMaterial;
189   -
190   - //optical parameters
191   - cNAi = 0.0;
192   - cNAo = 0.6;
193   - oNAi = 0.0;
194   - oNAo = 0.6;
  1 +#include "globals.h"
  2 +#include <sstream>
  3 +#include <fstream>
  4 +#include <iostream>
  5 +using namespace std;
  6 +
  7 +vector<SpecPair> LoadSpectrum(string filename)
  8 +{
  9 + //load a spectrum from a file and resample to 2wn intervals
  10 +
  11 + //create the spectrum
  12 + vector<SpecPair> S;
  13 +
  14 + //open the file
  15 + ifstream inFile(filename.c_str());
  16 +
  17 +
  18 + SpecPair temp;
  19 + while(!inFile.eof()){
  20 + inFile>>temp.nu;
  21 + inFile>>temp.A;
  22 + S.push_back(temp);
  23 + }
  24 +
  25 + //compute the minimum and maximum input wavenumbers
  26 + double inMin = S.front().nu;
  27 + double inMax = S.back().nu;
  28 +
  29 + int nuMin = (int)ceil(inMin);
  30 + int nuMax = (int)floor(inMax);
  31 +
  32 + //make sure both are either even or odd
  33 + if(nuMin % 2 != nuMax % 2)
  34 + nuMax--;
  35 +
  36 + //compute the number of values in the resampled spectrum
  37 + int nVals = (nuMax - nuMin)/2 + 1;
  38 +
  39 + //allocate space for the spectrum
  40 + vector<SpecPair> outSpec;
  41 +
  42 + double nu, highVal, lowVal, a;
  43 + int j=1;
  44 + for(int i=0; i<nVals; i++)
  45 + {
  46 + nu = nuMin + i * 2;
  47 + temp.nu = nu;
  48 +
  49 + //handle the boundary cases
  50 + if(nu < inMin || nu > inMax)
  51 + temp.A = 0.0;
  52 + else
  53 + {
  54 + //move to the correct position in the input array
  55 + while(j < (int)S.size()-1 && S[j].nu <= nu)
  56 + j++;
  57 +
  58 + lowVal = S[j-1].nu;
  59 + highVal = S[j].nu;
  60 + a = (nu - lowVal)/(highVal - lowVal);
  61 + temp.A = S[j-1].A * (1.0 - a) + S[j].A * a;
  62 + }
  63 + outSpec.push_back(temp);
  64 + }
  65 +
  66 +
  67 +
  68 + return outSpec;
  69 +}
  70 +
  71 +vector<SpecPair> SetReferenceSpectrum(char* text)
  72 +{
  73 + stringstream inString(text);
  74 +
  75 + //create the spectrum
  76 + vector<SpecPair> S;
  77 +
  78 + SpecPair temp;
  79 + while(!inString.eof()){
  80 + inString>>temp.nu;
  81 + inString>>temp.A;
  82 + S.push_back(temp);
  83 + }
  84 +
  85 + return S;
  86 +}
  87 +
  88 +void SaveK(string fileName)
  89 +{
  90 + ofstream outFile(fileName.c_str());
  91 + for(unsigned int i=0; i<EtaK.size(); i++)
  92 + {
  93 + outFile<<EtaK[i].nu<<" ";
  94 + outFile<<EtaK[i].A<<endl;
  95 + }
  96 + outFile.close();
  97 +}
  98 +
  99 +void SaveN(string fileName)
  100 +{
  101 + ofstream outFile(fileName.c_str());
  102 + for(unsigned int i=0; i<EtaN.size(); i++)
  103 + {
  104 + outFile<<EtaN[i].nu<<" ";
  105 + outFile<<EtaN[i].A<<endl;
  106 + }
  107 + outFile.close();
  108 +}
  109 +
  110 +void SaveSimulation(string fileName)
  111 +{
  112 + ofstream outFile(fileName.c_str());
  113 + outFile.precision(10);
  114 + for(unsigned int i=0; i<SimSpectrum.size(); i++)
  115 + {
  116 + outFile<<SimSpectrum[i].nu<<" ";
  117 + outFile<<SimSpectrum[i].A<<endl;
  118 + }
  119 + outFile.close();
  120 +}
  121 +
  122 +void SaveState()
  123 +{
  124 + ofstream outFile("main.prj");
  125 + //Window Parameters
  126 + outFile<<nuMin<<endl;
  127 + outFile<<nuMax<<endl;
  128 + outFile<<aMin<<endl;
  129 + outFile<<aMax<<endl;
  130 + outFile<<dNu<<endl;
  131 +
  132 + //material parameters
  133 + outFile<<radius<<endl;
  134 + outFile<<baseIR<<endl;
  135 + outFile<<cA<<endl;
  136 +
  137 + //optical parameters
  138 + outFile<<cNAi<<endl;
  139 + outFile<<cNAo<<endl;
  140 + outFile<<oNAi<<endl;
  141 + outFile<<oNAo<<endl;
  142 +
  143 + outFile.close();
  144 +
  145 +}
  146 +
  147 +void LoadState()
  148 +{
  149 + ifstream inFile("main.prj");
  150 + //Window Parameters
  151 + inFile>>nuMin;
  152 + inFile>>nuMax;
  153 + inFile>>aMin;
  154 + inFile>>aMax;
  155 + inFile>>dNu;
  156 +
  157 + //material parameters
  158 + inFile>>radius;
  159 + inFile>>baseIR;
  160 + inFile>>cA;
  161 +
  162 + //optical parameters
  163 + inFile>>cNAi;
  164 + inFile>>cNAo;
  165 + inFile>>oNAi;
  166 + inFile>>oNAo;
  167 +
  168 + inFile.close();
  169 +
  170 +}
  171 +
  172 +void SetDefaults()
  173 +{
  174 +
  175 + nuMin = 800;
  176 + nuMax = 4000;
  177 + dNu = 2;
  178 +
  179 + aMin = 0;
  180 + aMax = 1;
  181 +
  182 +
  183 + //material parameters
  184 + radius = 4.0f;
  185 + baseIR = 1.49f;
  186 + cA = 1.0;
  187 + vector<SpecPair> KMaterial;
  188 + vector<SpecPair> NMaterial;
  189 +
  190 + //optical parameters
  191 + cNAi = 0.0;
  192 + cNAo = 0.6;
  193 + oNAi = 0.0;
  194 + oNAo = 0.6;
195 195 }
196 196 \ No newline at end of file
... ...
FindCUDASDK.cmake
1   -#
2   -# The script defines the following variables:
3   -#
4   -##############################################################################
5   -# Note: Removed everything related to CUDA_SDK_ROOT_DIR and only left this as
6   -# a possible environment variable to set the SDK directory.
7   -# Include file will be: CUDA_CUT_INCLUDE_DIR
8   -# Cutil library: CUDA_CUT_LIBRARY
9   -##############################################################################
10   -#
11   -#
12   -# CUDA_SDK_ROOT_DIR -- Path to the CUDA SDK. Use this to find files in the
13   -# SDK. This script will not directly support finding
14   -# specific libraries or headers, as that isn't
15   -# supported by NVIDIA. If you want to change
16   -# libraries when the path changes see the
17   -# FindCUDA.cmake script for an example of how to clear
18   -# these variables. There are also examples of how to
19   -# use the CUDA_SDK_ROOT_DIR to locate headers or
20   -# libraries, if you so choose (at your own risk).
21   -#
22   -# This code is licensed under the MIT License. See the FindCUDASDK.cmake script
23   -# for the text of the license.
24   -
25   -# The MIT License
26   -#
27   -# License for the specific language governing rights and limitations under
28   -# Permission is hereby granted, free of charge, to any person obtaining a
29   -# copy of this software and associated documentation files (the "Software"),
30   -# to deal in the Software without restriction, including without limitation
31   -# the rights to use, copy, modify, merge, publish, distribute, sublicense,
32   -# and/or sell copies of the Software, and to permit persons to whom the
33   -# Software is furnished to do so, subject to the following conditions:
34   -#
35   -# The above copyright notice and this permission notice shall be included
36   -# in all copies or substantial portions of the Software.
37   -#
38   -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
39   -# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40   -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
41   -# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
42   -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
43   -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
44   -# DEALINGS IN THE SOFTWARE.
45   -#
46   -###############################################################################
47   -
48   -# FindCUDASDK.cmake
49   -
50   -# # Check to see if the CUDA_SDK_ROOT_DIR has changed,
51   -# # if it has then clear the cache variable, so that it will be detected again.
52   -# if(NOT "${CUDA_SDK_ROOT_DIR}" STREQUAL "${CUDA_SDK_ROOT_DIR_INTERNAL}")
53   -# # No specific variables to catch. Use this kind of code before calling
54   -# # find_package(CUDA) to clean up any variables that may depend on this path.
55   -#
56   -# # unset(MY_SPECIAL_CUDA_SDK_INCLUDE_DIR CACHE)
57   -# # unset(MY_SPECIAL_CUDA_SDK_LIBRARY CACHE)
58   -# endif()
59   -#
60   -# ########################
61   -# # Look for the SDK stuff
62   -# find_path(CUDA_SDK_ROOT_DIR cutil.h
63   -# PATH_SUFFIXES "common/inc" "C/common/inc"
64   -# "$ENV{NVSDKCUDA_ROOT}"
65   -# "[HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Installed Products\\NVIDIA SDK 10\\Compute;InstallDir]"
66   -# "/Developer/GPU\ Computing/C"
67   -# )
68   -#
69   -# # fallback method for determining CUDA_SDK_ROOT_DIR in case the previous one failed!
70   -# if (NOT CUDA_SDK_ROOT_DIR)
71   -# find_path(CUDA_SDK_ROOT_DIR C/common/inc/cutil.h
72   -# "$ENV{NVSDKCUDA_ROOT}"
73   -# "[HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Installed Products\\NVIDIA SDK 10\\Compute;InstallDir]"
74   -# "/Developer/GPU\ Computing/C"
75   -# )
76   -# endif()
77   -
78   -# Keep the CUDA_SDK_ROOT_DIR first in order to be able to override the
79   -# environment variables.
80   -set(CUDA_SDK_SEARCH_PATH
81   - "${CUDA_SDK_ROOT_DIR}"
82   - "${CUDA_TOOLKIT_ROOT_DIR}/local/NVSDK0.2"
83   - "${CUDA_TOOLKIT_ROOT_DIR}/NVSDK0.2"
84   - "${CUDA_TOOLKIT_ROOT_DIR}/NV_SDK"
85   - "${CUDA_TOOLKIT_ROOT_DIR}/NV_CUDA_SDK"
86   - "$ENV{HOME}/NVIDIA_CUDA_SDK"
87   - "$ENV{HOME}/NVIDIA_CUDA_SDK_MACOSX"
88   - "$ENV{HOME}/NVIDIA_GPU_Computing_SDK"
89   - "/Developer/CUDA"
90   - )
91   -
92   -# Find include file from the CUDA_SDK_SEARCH_PATH
93   -
94   -find_path(CUDA_CUT_INCLUDE_DIR
95   - cutil.h
96   - PATHS ${CUDA_SDK_SEARCH_PATH}
97   - PATH_SUFFIXES "common/inc" "C/common/inc"
98   - DOC "Location of cutil.h"
99   - NO_DEFAULT_PATH
100   - )
101   -# Now search system paths
102   -find_path(CUDA_CUT_INCLUDE_DIR cutil.h DOC "Location of cutil.h")
103   -
104   -# mark_as_advanced(CUDA_CUT_INCLUDE_DIR)
105   -
106   -
107   -# Example of how to find a library in the CUDA_SDK_ROOT_DIR
108   -
109   -# cutil library is called cutil64 for 64 bit builds on windows. We don't want
110   -# to get these confused, so we are setting the name based on the word size of
111   -# the build.
112   -
113   -# New library might be called cutil_x86_64 !
114   -
115   -if(CMAKE_SIZEOF_VOID_P EQUAL 8)
116   - set(cuda_cutil_name cutil64)
117   -else(CMAKE_SIZEOF_VOID_P EQUAL 8)
118   - set(cuda_cutil_name cutil32)
119   -endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
120   -
121   -find_library(CUDA_CUT_LIBRARY
122   - NAMES ${cuda_cutil_name} cutil cutil_x86_64 cutil_i386
123   - PATHS ${CUDA_SDK_SEARCH_PATH}
124   - # The new version of the sdk shows up in common/lib, but the old one is in lib
125   - # The very newest installation Path of the SDK is in subdirectory 'C'. Please add this Path to the possible suffixes.
126   - PATH_SUFFIXES "C/lib" "common/lib" "lib" "C/common/lib" "common/lib"
127   - DOC "Location of cutil library"
128   - NO_DEFAULT_PATH
129   - )
130   -# # Now search system paths
131   -# find_library(CUDA_CUT_LIBRARY NAMES cutil ${cuda_cutil_name} DOC "Location of cutil library")
132   -mark_as_advanced(CUDA_CUT_LIBRARY)
133   -set(CUDA_CUT_LIBRARIES ${CUDA_CUT_LIBRARY})
134   -
135   -#############################
136   -# Check for required components
137   -if(CUDA_CUT_INCLUDE_DIR)
138   - set(CUDASDK_FOUND TRUE)
139   -endif(CUDA_CUT_INCLUDE_DIR)
140   -
141   -# set(CUDA_SDK_ROOT_DIR_INTERNAL "${CUDA_SDK_ROOT_DIR}" CACHE INTERNAL
142   -# "This is the value of the last time CUDA_SDK_ROOT_DIR was set successfully." FORCE)
  1 +#
  2 +# The script defines the following variables:
  3 +#
  4 +##############################################################################
  5 +# Note: Removed everything related to CUDA_SDK_ROOT_DIR and only left this as
  6 +# a possible environment variable to set the SDK directory.
  7 +# Include file will be: CUDA_CUT_INCLUDE_DIR
  8 +# Cutil library: CUDA_CUT_LIBRARY
  9 +##############################################################################
  10 +#
  11 +#
  12 +# CUDA_SDK_ROOT_DIR -- Path to the CUDA SDK. Use this to find files in the
  13 +# SDK. This script will not directly support finding
  14 +# specific libraries or headers, as that isn't
  15 +# supported by NVIDIA. If you want to change
  16 +# libraries when the path changes see the
  17 +# FindCUDA.cmake script for an example of how to clear
  18 +# these variables. There are also examples of how to
  19 +# use the CUDA_SDK_ROOT_DIR to locate headers or
  20 +# libraries, if you so choose (at your own risk).
  21 +#
  22 +# This code is licensed under the MIT License. See the FindCUDASDK.cmake script
  23 +# for the text of the license.
  24 +
  25 +# The MIT License
  26 +#
  27 +# License for the specific language governing rights and limitations under
  28 +# Permission is hereby granted, free of charge, to any person obtaining a
  29 +# copy of this software and associated documentation files (the "Software"),
  30 +# to deal in the Software without restriction, including without limitation
  31 +# the rights to use, copy, modify, merge, publish, distribute, sublicense,
  32 +# and/or sell copies of the Software, and to permit persons to whom the
  33 +# Software is furnished to do so, subject to the following conditions:
  34 +#
  35 +# The above copyright notice and this permission notice shall be included
  36 +# in all copies or substantial portions of the Software.
  37 +#
  38 +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  39 +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  40 +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  41 +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  42 +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  43 +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  44 +# DEALINGS IN THE SOFTWARE.
  45 +#
  46 +###############################################################################
  47 +
  48 +# FindCUDASDK.cmake
  49 +
  50 +# # Check to see if the CUDA_SDK_ROOT_DIR has changed,
  51 +# # if it has then clear the cache variable, so that it will be detected again.
  52 +# if(NOT "${CUDA_SDK_ROOT_DIR}" STREQUAL "${CUDA_SDK_ROOT_DIR_INTERNAL}")
  53 +# # No specific variables to catch. Use this kind of code before calling
  54 +# # find_package(CUDA) to clean up any variables that may depend on this path.
  55 +#
  56 +# # unset(MY_SPECIAL_CUDA_SDK_INCLUDE_DIR CACHE)
  57 +# # unset(MY_SPECIAL_CUDA_SDK_LIBRARY CACHE)
  58 +# endif()
  59 +#
  60 +# ########################
  61 +# # Look for the SDK stuff
  62 +# find_path(CUDA_SDK_ROOT_DIR cutil.h
  63 +# PATH_SUFFIXES "common/inc" "C/common/inc"
  64 +# "$ENV{NVSDKCUDA_ROOT}"
  65 +# "[HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Installed Products\\NVIDIA SDK 10\\Compute;InstallDir]"
  66 +# "/Developer/GPU\ Computing/C"
  67 +# )
  68 +#
  69 +# # fallback method for determining CUDA_SDK_ROOT_DIR in case the previous one failed!
  70 +# if (NOT CUDA_SDK_ROOT_DIR)
  71 +# find_path(CUDA_SDK_ROOT_DIR C/common/inc/cutil.h
  72 +# "$ENV{NVSDKCUDA_ROOT}"
  73 +# "[HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Installed Products\\NVIDIA SDK 10\\Compute;InstallDir]"
  74 +# "/Developer/GPU\ Computing/C"
  75 +# )
  76 +# endif()
  77 +
  78 +# Keep the CUDA_SDK_ROOT_DIR first in order to be able to override the
  79 +# environment variables.
  80 +set(CUDA_SDK_SEARCH_PATH
  81 + "${CUDA_SDK_ROOT_DIR}"
  82 + "${CUDA_TOOLKIT_ROOT_DIR}/local/NVSDK0.2"
  83 + "${CUDA_TOOLKIT_ROOT_DIR}/NVSDK0.2"
  84 + "${CUDA_TOOLKIT_ROOT_DIR}/NV_SDK"
  85 + "${CUDA_TOOLKIT_ROOT_DIR}/NV_CUDA_SDK"
  86 + "$ENV{HOME}/NVIDIA_CUDA_SDK"
  87 + "$ENV{HOME}/NVIDIA_CUDA_SDK_MACOSX"
  88 + "$ENV{HOME}/NVIDIA_GPU_Computing_SDK"
  89 + "/Developer/CUDA"
  90 + )
  91 +
  92 +# Find include file from the CUDA_SDK_SEARCH_PATH
  93 +
  94 +find_path(CUDA_CUT_INCLUDE_DIR
  95 + cutil.h
  96 + PATHS ${CUDA_SDK_SEARCH_PATH}
  97 + PATH_SUFFIXES "common/inc" "C/common/inc"
  98 + DOC "Location of cutil.h"
  99 + NO_DEFAULT_PATH
  100 + )
  101 +# Now search system paths
  102 +find_path(CUDA_CUT_INCLUDE_DIR cutil.h DOC "Location of cutil.h")
  103 +
  104 +# mark_as_advanced(CUDA_CUT_INCLUDE_DIR)
  105 +
  106 +
  107 +# Example of how to find a library in the CUDA_SDK_ROOT_DIR
  108 +
  109 +# cutil library is called cutil64 for 64 bit builds on windows. We don't want
  110 +# to get these confused, so we are setting the name based on the word size of
  111 +# the build.
  112 +
  113 +# New library might be called cutil_x86_64 !
  114 +
  115 +if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  116 + set(cuda_cutil_name cutil64)
  117 +else(CMAKE_SIZEOF_VOID_P EQUAL 8)
  118 + set(cuda_cutil_name cutil32)
  119 +endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
  120 +
  121 +find_library(CUDA_CUT_LIBRARY
  122 + NAMES ${cuda_cutil_name} cutil cutil_x86_64 cutil_i386
  123 + PATHS ${CUDA_SDK_SEARCH_PATH}
  124 + # The new version of the sdk shows up in common/lib, but the old one is in lib
  125 + # The very newest installation Path of the SDK is in subdirectory 'C'. Please add this Path to the possible suffixes.
  126 + PATH_SUFFIXES "C/lib" "common/lib" "lib" "C/common/lib" "common/lib"
  127 + DOC "Location of cutil library"
  128 + NO_DEFAULT_PATH
  129 + )
  130 +# # Now search system paths
  131 +# find_library(CUDA_CUT_LIBRARY NAMES cutil ${cuda_cutil_name} DOC "Location of cutil library")
  132 +mark_as_advanced(CUDA_CUT_LIBRARY)
  133 +set(CUDA_CUT_LIBRARIES ${CUDA_CUT_LIBRARY})
  134 +
  135 +#############################
  136 +# Check for required components
  137 +if(CUDA_CUT_INCLUDE_DIR)
  138 + set(CUDASDK_FOUND TRUE)
  139 +endif(CUDA_CUT_INCLUDE_DIR)
  140 +
  141 +# set(CUDA_SDK_ROOT_DIR_INTERNAL "${CUDA_SDK_ROOT_DIR}" CACHE INTERNAL
  142 +# "This is the value of the last time CUDA_SDK_ROOT_DIR was set successfully." FORCE)
... ...
FindGLEW.cmake
1   -#
2   -# Try to find GLEW library and include path.
3   -# Once done this will define
4   -#
5   -# GLEW_FOUND
6   -# GLEW_INCLUDE_PATH
7   -# GLEW_LIBRARY
8   -#
9   -
10   -IF (WIN32)
11   - FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h
12   - $ENV{PROGRAMFILES}/GLEW/include
13   - ${PROJECT_SOURCE_DIR}/src/nvgl/glew/include
14   - DOC "The directory where GL/glew.h resides")
15   - FIND_LIBRARY( GLEW_LIBRARY
16   - NAMES glew GLEW glew32 glew32s
17   - PATHS
18   - $ENV{PROGRAMFILES}/GLEW/lib
19   - ${PROJECT_SOURCE_DIR}/src/nvgl/glew/bin
20   - ${PROJECT_SOURCE_DIR}/src/nvgl/glew/lib
21   - DOC "The GLEW library")
22   -ELSE (WIN32)
23   - FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h
24   - /usr/include
25   - /usr/local/include
26   - /sw/include
27   - /opt/local/include
28   - DOC "The directory where GL/glew.h resides")
29   - FIND_LIBRARY( GLEW_LIBRARY
30   - NAMES GLEW glew
31   - PATHS
32   - /usr/lib64
33   - /usr/lib
34   - /usr/local/lib64
35   - /usr/local/lib
36   - /sw/lib
37   - /opt/local/lib
38   - DOC "The GLEW library")
39   -ENDIF (WIN32)
40   -
41   -IF (GLEW_INCLUDE_PATH)
42   - SET( GLEW_FOUND 1 CACHE STRING "Set to 1 if GLEW is found, 0 otherwise")
43   -ELSE (GLEW_INCLUDE_PATH)
44   - SET( GLEW_FOUND 0 CACHE STRING "Set to 1 if GLEW is found, 0 otherwise")
45   -ENDIF (GLEW_INCLUDE_PATH)
46   -
47   -MARK_AS_ADVANCED(
48   - GLEW_FOUND
49   - GLEW_INCLUDE_PATH
50   - GLEW_LIBRARY
  1 +#
  2 +# Try to find GLEW library and include path.
  3 +# Once done this will define
  4 +#
  5 +# GLEW_FOUND
  6 +# GLEW_INCLUDE_PATH
  7 +# GLEW_LIBRARY
  8 +#
  9 +
  10 +IF (WIN32)
  11 + FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h
  12 + $ENV{PROGRAMFILES}/GLEW/include
  13 + ${PROJECT_SOURCE_DIR}/src/nvgl/glew/include
  14 + DOC "The directory where GL/glew.h resides")
  15 + FIND_LIBRARY( GLEW_LIBRARY
  16 + NAMES glew GLEW glew32 glew32s
  17 + PATHS
  18 + $ENV{PROGRAMFILES}/GLEW/lib
  19 + ${PROJECT_SOURCE_DIR}/src/nvgl/glew/bin
  20 + ${PROJECT_SOURCE_DIR}/src/nvgl/glew/lib
  21 + DOC "The GLEW library")
  22 +ELSE (WIN32)
  23 + FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h
  24 + /usr/include
  25 + /usr/local/include
  26 + /sw/include
  27 + /opt/local/include
  28 + DOC "The directory where GL/glew.h resides")
  29 + FIND_LIBRARY( GLEW_LIBRARY
  30 + NAMES GLEW glew
  31 + PATHS
  32 + /usr/lib64
  33 + /usr/lib
  34 + /usr/local/lib64
  35 + /usr/local/lib
  36 + /sw/lib
  37 + /opt/local/lib
  38 + DOC "The GLEW library")
  39 +ENDIF (WIN32)
  40 +
  41 +IF (GLEW_INCLUDE_PATH)
  42 + SET( GLEW_FOUND 1 CACHE STRING "Set to 1 if GLEW is found, 0 otherwise")
  43 +ELSE (GLEW_INCLUDE_PATH)
  44 + SET( GLEW_FOUND 0 CACHE STRING "Set to 1 if GLEW is found, 0 otherwise")
  45 +ENDIF (GLEW_INCLUDE_PATH)
  46 +
  47 +MARK_AS_ADVANCED(
  48 + GLEW_FOUND
  49 + GLEW_INCLUDE_PATH
  50 + GLEW_LIBRARY
51 51 )
52 52 \ No newline at end of file
... ...
FindRTS.cmake
1   -# Tries to find the RTS include directory
2   -
3   - FIND_PATH( RTS_INCLUDE_DIR NAMES rts_glShaderProgram.h
4   - PATHS
5   - ${CMAKE_CURRENT_SOURCE_DIR}/rts
6   - ${RTS_ROOT_PATH}
7   -)
8   -
9   -IF (RTS_FOUND)
10   - #The following deprecated settings are for backwards compatibility with CMake1.4
11   - SET (RTS_INCLUDE_PATH ${RTS_INCLUDE_DIR})
12   -ENDIF(RTS_FOUND)
13   -
14   -FIND_PACKAGE_HANDLE_STANDARD_ARGS(RTS REQUIRED_VARS TRUE RTS_INCLUDE_DIR)
  1 +# Tries to find the RTS include directory
  2 +
  3 + FIND_PATH( RTS_INCLUDE_DIR NAMES rts_glShaderProgram.h
  4 + PATHS
  5 + ${CMAKE_CURRENT_SOURCE_DIR}/rts
  6 + ${RTS_ROOT_PATH}
  7 +)
  8 +
  9 +IF (RTS_FOUND)
  10 + #The following deprecated settings are for backwards compatibility with CMake1.4
  11 + SET (RTS_INCLUDE_PATH ${RTS_INCLUDE_DIR})
  12 +ENDIF(RTS_FOUND)
  13 +
  14 +FIND_PACKAGE_HANDLE_STANDARD_ARGS(RTS REQUIRED_VARS TRUE RTS_INCLUDE_DIR)
... ...
GAMMA.cpp
1   -// gamma.cpp -- computation of gamma function.
2   -// Algorithms and coefficient values from "Computation of Special
3   -// Functions", Zhang and Jin, John Wiley and Sons, 1996.
4   -//
5   -// (C) 2003, C. Bond. All rights reserved.
6   -//
7   -// Returns gamma function of argument 'x'.
8   -//
9   -// NOTE: Returns 1e308 if argument is a negative integer or 0,
10   -// or if argument exceeds 171.
11   -//
12   -#define _USE_MATH_DEFINES
13   -#include <math.h>
14   -double gamma(double x)
15   -{
16   - int i,k,m;
17   - double ga,gr,r,z;
18   -
19   - static double g[] = {
20   - 1.0,
21   - 0.5772156649015329,
22   - -0.6558780715202538,
23   - -0.420026350340952e-1,
24   - 0.1665386113822915,
25   - -0.421977345555443e-1,
26   - -0.9621971527877e-2,
27   - 0.7218943246663e-2,
28   - -0.11651675918591e-2,
29   - -0.2152416741149e-3,
30   - 0.1280502823882e-3,
31   - -0.201348547807e-4,
32   - -0.12504934821e-5,
33   - 0.1133027232e-5,
34   - -0.2056338417e-6,
35   - 0.6116095e-8,
36   - 0.50020075e-8,
37   - -0.11812746e-8,
38   - 0.1043427e-9,
39   - 0.77823e-11,
40   - -0.36968e-11,
41   - 0.51e-12,
42   - -0.206e-13,
43   - -0.54e-14,
44   - 0.14e-14};
45   -
46   - if (x > 171.0) return 1e308; // This value is an overflow flag.
47   - if (x == (int)x) {
48   - if (x > 0.0) {
49   - ga = 1.0; // use factorial
50   - for (i=2;i<x;i++) {
51   - ga *= i;
52   - }
53   - }
54   - else
55   - ga = 1e308;
56   - }
57   - else {
58   - if (fabs(x) > 1.0) {
59   - z = fabs(x);
60   - m = (int)z;
61   - r = 1.0;
62   - for (k=1;k<=m;k++) {
63   - r *= (z-k);
64   - }
65   - z -= m;
66   - }
67   - else
68   - z = x;
69   - gr = g[24];
70   - for (k=23;k>=0;k--) {
71   - gr = gr*z+g[k];
72   - }
73   - ga = 1.0/(gr*z);
74   - if (fabs(x) > 1.0) {
75   - ga *= r;
76   - if (x < 0.0) {
77   - ga = -M_PI/(x*ga*sin(M_PI*x));
78   - }
79   - }
80   - }
81   - return ga;
82   -}
  1 +// gamma.cpp -- computation of gamma function.
  2 +// Algorithms and coefficient values from "Computation of Special
  3 +// Functions", Zhang and Jin, John Wiley and Sons, 1996.
  4 +//
  5 +// (C) 2003, C. Bond. All rights reserved.
  6 +//
  7 +// Returns gamma function of argument 'x'.
  8 +//
  9 +// NOTE: Returns 1e308 if argument is a negative integer or 0,
  10 +// or if argument exceeds 171.
  11 +//
  12 +#define _USE_MATH_DEFINES
  13 +#include <math.h>
  14 +double gamma(double x)
  15 +{
  16 + int i,k,m;
  17 + double ga,gr,r,z;
  18 +
  19 + static double g[] = {
  20 + 1.0,
  21 + 0.5772156649015329,
  22 + -0.6558780715202538,
  23 + -0.420026350340952e-1,
  24 + 0.1665386113822915,
  25 + -0.421977345555443e-1,
  26 + -0.9621971527877e-2,
  27 + 0.7218943246663e-2,
  28 + -0.11651675918591e-2,
  29 + -0.2152416741149e-3,
  30 + 0.1280502823882e-3,
  31 + -0.201348547807e-4,
  32 + -0.12504934821e-5,
  33 + 0.1133027232e-5,
  34 + -0.2056338417e-6,
  35 + 0.6116095e-8,
  36 + 0.50020075e-8,
  37 + -0.11812746e-8,
  38 + 0.1043427e-9,
  39 + 0.77823e-11,
  40 + -0.36968e-11,
  41 + 0.51e-12,
  42 + -0.206e-13,
  43 + -0.54e-14,
  44 + 0.14e-14};
  45 +
  46 + if (x > 171.0) return 1e308; // This value is an overflow flag.
  47 + if (x == (int)x) {
  48 + if (x > 0.0) {
  49 + ga = 1.0; // use factorial
  50 + for (i=2;i<x;i++) {
  51 + ga *= i;
  52 + }
  53 + }
  54 + else
  55 + ga = 1e308;
  56 + }
  57 + else {
  58 + if (fabs(x) > 1.0) {
  59 + z = fabs(x);
  60 + m = (int)z;
  61 + r = 1.0;
  62 + for (k=1;k<=m;k++) {
  63 + r *= (z-k);
  64 + }
  65 + z -= m;
  66 + }
  67 + else
  68 + z = x;
  69 + gr = g[24];
  70 + for (k=23;k>=0;k--) {
  71 + gr = gr*z+g[k];
  72 + }
  73 + ga = 1.0/(gr*z);
  74 + if (fabs(x) > 1.0) {
  75 + ga *= r;
  76 + if (x < 0.0) {
  77 + ga = -M_PI/(x*ga*sin(M_PI*x));
  78 + }
  79 + }
  80 + }
  81 + return ga;
  82 +}
... ...
PerformanceData.h
1   -// add the following to a cpp file:
2   -// PerformanceData PD;
3   -
4   -
5   -#pragma once
6   -#include <ostream>
7   -using namespace std;
8   -
9   -enum PerformanceDataType
10   -{
11   - PD_DISPLAY=0,
12   - PD_SPS,
13   - PD_UNUSED0,
14   -
15   - //my stuff
16   - SIMULATE_SPECTRUM,
17   - SIMULATE_GPU,
18   - KRAMERS_KRONIG,
19   -
20   -
21   -
22   - //end my stuff
23   - PERFORMANCE_DATA_TYPE_COUNT
24   -};
25   -
26   -static char PDTypeNames[][255] = {
27   - "Display ",
28   - "Simulation Total ",
29   - " ----------------- ",
30   - //my stuff
31   - "Simulate Spectrum ",
32   - " GPU Portion ",
33   - "Kramers-Kronig ",
34   -
35   - //end my stuff
36   -
37   -};
38   -#ifdef WIN32
39   -#include <stdio.h>
40   -#include <windows.h>
41   -#include <float.h>
42   -
43   -#include <iostream>
44   -#include <iomanip>
45   -
46   -//-------------------------------------------------------------------------------
47   -
48   -class PerformanceData
49   -{
50   -public:
51   - PerformanceData() { ClearAll(); QueryPerformanceFrequency(&cps); }
52   - ~PerformanceData(){}
53   -
54   - void ClearAll()
55   - {
56   - for ( int i=0; i<PERFORMANCE_DATA_TYPE_COUNT; i++ ) {
57   - for ( int j=0; j<256; j++ ) times[i][j] = 0;
58   - pos[i] = 0;
59   - minTime[i] = 0xFFFFFFFF;
60   - maxTime[i] = 0;
61   - totalTime[i] = 0;
62   - dataReady[i] = false;
63   - }
64   - }
65   -
66   - void StartTimer( int type ) { QueryPerformanceCounter( &startTime[type] );}
67   - void EndTimer( int type ) {
68   - LARGE_INTEGER endTime;
69   - QueryPerformanceCounter( &endTime );
70   - double t = (double)(endTime.QuadPart - startTime[type].QuadPart);
71   - //unsigned int t = GetTickCount() - startTime[type];
72   - if ( t < minTime[type] ) minTime[type] = t;
73   - if ( t > maxTime[type] ) maxTime[type] = t;
74   - totalTime[type] -= times[type][ pos[type] ];
75   - times[type][ pos[type] ] = t;
76   - totalTime[type] += t;
77   - pos[type]++;
78   - if ( pos[type] == 0 ) dataReady[type] = true;
79   - }
80   -
81   - void PrintResult( ostream &os,int i=PERFORMANCE_DATA_TYPE_COUNT)
82   - {
83   - os.setf(ios::fixed);
84   - if ((i<PERFORMANCE_DATA_TYPE_COUNT)&&(i>=0)){
85   - double a = GetAvrgTime(i);
86   - if ( a )
87   - os<< PDTypeNames[i]<<" : avrg="<<setw(8)<<setprecision(3)<<a<<"\tmin="<<setw(8)<<setprecision(3)<< GetMinTime(i) <<"\tmax="<<setw(8)<<setprecision(3)<< GetMaxTime(i) <<endl ;
88   - else
89   - os<< PDTypeNames[i]<<" : avrg= -----\tmin= -----\tmax= -----"<<endl;
90   - }
91   - }
92   -
93   - void PrintResults( ostream &os)
94   - {
95   - for ( int i=0; i<PERFORMANCE_DATA_TYPE_COUNT; i++ )
96   - PrintResult(os,i);
97   - }
98   -
99   - double GetLastTime( int type ) { return times[type][pos[type]]; }
100   - double GetAvrgTime( int type ) { double a = 1000.0 * totalTime[type] / (float)cps.QuadPart / ( (dataReady[type]) ? 256.0 : (double)pos[type] ); return (_finite(a))? a:0; }
101   - double GetMinTime( int type ) { return 1000.0 * minTime[type] / (float)cps.LowPart; }
102   - double GetMaxTime( int type ) { return 1000.0 * maxTime[type] / (float)cps.LowPart; }
103   -
104   -private:
105   - double times[PERFORMANCE_DATA_TYPE_COUNT][256];
106   - unsigned char pos[PERFORMANCE_DATA_TYPE_COUNT];
107   - LARGE_INTEGER startTime[PERFORMANCE_DATA_TYPE_COUNT];
108   - double minTime[ PERFORMANCE_DATA_TYPE_COUNT ];
109   - double maxTime[ PERFORMANCE_DATA_TYPE_COUNT ];
110   - double totalTime[ PERFORMANCE_DATA_TYPE_COUNT ];
111   - bool dataReady[ PERFORMANCE_DATA_TYPE_COUNT ];
112   - LARGE_INTEGER cps;
113   -};
114   -
115   -//-------------------------------------------------------------------------------
116   -#else
117   -
118   -class PerformanceData{
119   -public:
120   - PerformanceData() {;};
121   - ~PerformanceData(){;};
122   - void ClearAll(){;};
123   - void StartTimer( int type ) {;};
124   - void EndTimer( int type ) {;};
125   - void PrintResults( ostream &os){;};
126   - void PrintResult( ostream &os, int i=PERFORMANCE_DATA_TYPE_COUNT){;};
127   - double GetLastTime( int type ) { return 0.0; };
128   - double GetAvrgTime( int type ) { return 0.0; };
129   - double GetMinTime( int type ) { return 0.0; };
130   - double GetMaxTime( int type ) { return 0.0; };
131   -};
132   -
133   -#endif
134   -//-------------------------------------------------------------------------------
135   -
136   -extern PerformanceData PD;
137   -
138   -//-------------------------------------------------------------------------------
  1 +// add the following to a cpp file:
  2 +// PerformanceData PD;
  3 +
  4 +
  5 +#pragma once
  6 +#include <ostream>
  7 +using namespace std;
  8 +
  9 +enum PerformanceDataType
  10 +{
  11 + PD_DISPLAY=0,
  12 + PD_SPS,
  13 + PD_UNUSED0,
  14 +
  15 + //my stuff
  16 + SIMULATE_SPECTRUM,
  17 + SIMULATE_GPU,
  18 + KRAMERS_KRONIG,
  19 +
  20 +
  21 +
  22 + //end my stuff
  23 + PERFORMANCE_DATA_TYPE_COUNT
  24 +};
  25 +
  26 +static char PDTypeNames[][255] = {
  27 + "Display ",
  28 + "Simulation Total ",
  29 + " ----------------- ",
  30 + //my stuff
  31 + "Simulate Spectrum ",
  32 + " GPU Portion ",
  33 + "Kramers-Kronig ",
  34 +
  35 + //end my stuff
  36 +
  37 +};
  38 +#ifdef WIN32
  39 +#include <stdio.h>
  40 +#include <windows.h>
  41 +#include <float.h>
  42 +
  43 +#include <iostream>
  44 +#include <iomanip>
  45 +
  46 +//-------------------------------------------------------------------------------
  47 +
  48 +class PerformanceData
  49 +{
  50 +public:
  51 + PerformanceData() { ClearAll(); QueryPerformanceFrequency(&cps); }
  52 + ~PerformanceData(){}
  53 +
  54 + void ClearAll()
  55 + {
  56 + for ( int i=0; i<PERFORMANCE_DATA_TYPE_COUNT; i++ ) {
  57 + for ( int j=0; j<256; j++ ) times[i][j] = 0;
  58 + pos[i] = 0;
  59 + minTime[i] = 0xFFFFFFFF;
  60 + maxTime[i] = 0;
  61 + totalTime[i] = 0;
  62 + dataReady[i] = false;
  63 + }
  64 + }
  65 +
  66 + void StartTimer( int type ) { QueryPerformanceCounter( &startTime[type] );}
  67 + void EndTimer( int type ) {
  68 + LARGE_INTEGER endTime;
  69 + QueryPerformanceCounter( &endTime );
  70 + double t = (double)(endTime.QuadPart - startTime[type].QuadPart);
  71 + //unsigned int t = GetTickCount() - startTime[type];
  72 + if ( t < minTime[type] ) minTime[type] = t;
  73 + if ( t > maxTime[type] ) maxTime[type] = t;
  74 + totalTime[type] -= times[type][ pos[type] ];
  75 + times[type][ pos[type] ] = t;
  76 + totalTime[type] += t;
  77 + pos[type]++;
  78 + if ( pos[type] == 0 ) dataReady[type] = true;
  79 + }
  80 +
  81 + void PrintResult( ostream &os,int i=PERFORMANCE_DATA_TYPE_COUNT)
  82 + {
  83 + os.setf(ios::fixed);
  84 + if ((i<PERFORMANCE_DATA_TYPE_COUNT)&&(i>=0)){
  85 + double a = GetAvrgTime(i);
  86 + if ( a )
  87 + os<< PDTypeNames[i]<<" : avrg="<<setw(8)<<setprecision(3)<<a<<"\tmin="<<setw(8)<<setprecision(3)<< GetMinTime(i) <<"\tmax="<<setw(8)<<setprecision(3)<< GetMaxTime(i) <<endl ;
  88 + else
  89 + os<< PDTypeNames[i]<<" : avrg= -----\tmin= -----\tmax= -----"<<endl;
  90 + }
  91 + }
  92 +
  93 + void PrintResults( ostream &os)
  94 + {
  95 + for ( int i=0; i<PERFORMANCE_DATA_TYPE_COUNT; i++ )
  96 + PrintResult(os,i);
  97 + }
  98 +
  99 + double GetLastTime( int type ) { return times[type][pos[type]]; }
  100 + double GetAvrgTime( int type ) { double a = 1000.0 * totalTime[type] / (float)cps.QuadPart / ( (dataReady[type]) ? 256.0 : (double)pos[type] ); return (_finite(a))? a:0; }
  101 + double GetMinTime( int type ) { return 1000.0 * minTime[type] / (float)cps.LowPart; }
  102 + double GetMaxTime( int type ) { return 1000.0 * maxTime[type] / (float)cps.LowPart; }
  103 +
  104 +private:
  105 + double times[PERFORMANCE_DATA_TYPE_COUNT][256];
  106 + unsigned char pos[PERFORMANCE_DATA_TYPE_COUNT];
  107 + LARGE_INTEGER startTime[PERFORMANCE_DATA_TYPE_COUNT];
  108 + double minTime[ PERFORMANCE_DATA_TYPE_COUNT ];
  109 + double maxTime[ PERFORMANCE_DATA_TYPE_COUNT ];
  110 + double totalTime[ PERFORMANCE_DATA_TYPE_COUNT ];
  111 + bool dataReady[ PERFORMANCE_DATA_TYPE_COUNT ];
  112 + LARGE_INTEGER cps;
  113 +};
  114 +
  115 +//-------------------------------------------------------------------------------
  116 +#else
  117 +
  118 +class PerformanceData{
  119 +public:
  120 + PerformanceData() {;};
  121 + ~PerformanceData(){;};
  122 + void ClearAll(){;};
  123 + void StartTimer( int type ) {;};
  124 + void EndTimer( int type ) {;};
  125 + void PrintResults( ostream &os){;};
  126 + void PrintResult( ostream &os, int i=PERFORMANCE_DATA_TYPE_COUNT){;};
  127 + double GetLastTime( int type ) { return 0.0; };
  128 + double GetAvrgTime( int type ) { return 0.0; };
  129 + double GetMinTime( int type ) { return 0.0; };
  130 + double GetMaxTime( int type ) { return 0.0; };
  131 +};
  132 +
  133 +#endif
  134 +//-------------------------------------------------------------------------------
  135 +
  136 +extern PerformanceData PD;
  137 +
  138 +//-------------------------------------------------------------------------------
... ...
1   -I've just added support for double-precision values. This allows simulation of extremely small (nano-scale) particles, however a GPU with a compute capability of at least 1.3 is required.
2   -
3   -TrueEyes requires the following libraries:
4   -
5   -GLUT (OpenGL Utility Toolkit) http://www.opengl.org/resources/libraries/glut/
6   -GLEW (OpenGL Extension Wrangler) http://glew.sourceforge.net/
7   -Qt http://qt-project.org/
8   -RTS (my personal codebase) https://github.com/dmayerich/RTS
9   -CUDA http://www.nvidia.com/object/cuda_home_new.html
10   -
  1 +I've just added support for double-precision values. This allows simulation of extremely small (nano-scale) particles, however a GPU with a compute capability of at least 1.3 is required.
  2 +
  3 +TrueEyes requires the following libraries:
  4 +
  5 +GLUT (OpenGL Utility Toolkit) http://www.opengl.org/resources/libraries/glut/
  6 +GLEW (OpenGL Extension Wrangler) http://glew.sourceforge.net/
  7 +Qt http://qt-project.org/
  8 +RTS (my personal codebase) https://github.com/dmayerich/RTS
  9 +CUDA http://www.nvidia.com/object/cuda_home_new.html
  10 +
11 11 If CMake is unable to find these, make sure to specify their locations.
12 12 \ No newline at end of file
... ...
SimulateSpectrum.cpp
1   -#include <math.h>
2   -#include <complex>
3   -#include <iostream>
4   -#include <fstream>
5   -#include "globals.h"
6   -#include <stdlib.h>
7   -//#include "cufft.h"
8   -using namespace std;
9   -
10   -#define pi 3.14159
11   -
12   -typedef complex<double> scComplex;
13   -
14   -extern int cbessjyva(double v,complex<double> z,double &vm,complex<double>*cjv,
15   - complex<double>*cyv,complex<double>*cjvp,complex<double>*cyvp);
16   -extern int bessjyv(double v,double x,double &vm,double *jv,double *yv,
17   - double *djv,double *dyv);
18   -
19   -complex<double> Jl_neg(complex<double> x)
20   -{
21   - //this function computes the bessel function of the first kind Jl(x) for l = -0.5
22   - return ( sqrt(2.0/pi) * cos(x) )/sqrt(x);
23   -}
24   -
25   -double Jl_neg(double x)
26   -{
27   - //this function computes the bessel function of the first kind Jl(x) for l = -0.5
28   - return ( sqrt(2.0/pi) * cos(x) )/sqrt(x);
29   -}
30   -
31   -double Yl_neg(double x)
32   -{
33   - //this function computes the bessel function of the second kind Yl(x) for l = -0.5;
34   - return ( sqrt(2.0/pi) * sin(x) )/sqrt(x);
35   -}
36   -
37   -void computeB(complex<double>* B, double radius, complex<double> refIndex, double lambda, int Nl)
38   -{
39   - double k = (2*pi)/lambda;
40   - int b = 2;
41   -
42   - //allocate space for the real bessel functions
43   - double* jv = (double*)malloc(sizeof(double)*(Nl+b));
44   - double* yv = (double*)malloc(sizeof(double)*(Nl+b));
45   - double* jvp = (double*)malloc(sizeof(double)*(Nl+b));
46   - double* yvp = (double*)malloc(sizeof(double)*(Nl+b));
47   -
48   - //allocate space for the complex bessel functions
49   - complex<double>* cjv = (complex<double>*)malloc(sizeof(complex<double>)*(Nl+b));
50   - complex<double>* cyv = (complex<double>*)malloc(sizeof(complex<double>)*(Nl+b));
51   - complex<double>* cjvp = (complex<double>*)malloc(sizeof(complex<double>)*(Nl+b));
52   - complex<double>* cyvp = (complex<double>*)malloc(sizeof(complex<double>)*(Nl+b));
53   -
54   - double kr = k*radius;
55   - complex<double> knr = k*refIndex*(double)radius;
56   - complex<double> n = refIndex;
57   -
58   - //compute the bessel functions for k*r
59   - double vm;// = Nl - 1;
60   - bessjyv((Nl)+0.5, kr, vm, jv, yv, jvp, yvp);
61   - //cout<<"Nl: "<<Nl<<" vm: "<<vm<<endl;
62   - //printf("Nl: %f, vm: %f\n", (float)Nl, (float)vm);
63   -
64   - //compute the bessel functions for k*n*r
65   - cbessjyva((Nl)+0.5, knr, vm, cjv, cyv, cjvp, cyvp);
66   -
67   - //scale factor for spherical bessel functions
68   - double scale_kr = sqrt(pi/(2.0*kr));
69   - complex<double> scale_knr = sqrt(pi/(2.0*knr));
70   -
71   - complex<double> numer, denom;
72   - double j_kr;
73   - double y_kr;
74   - complex<double> j_knr;
75   - complex<double> j_d_knr;
76   - double j_d_kr;
77   - complex<double> h_kr;
78   - complex<double> h_d_kr;
79   - complex<double> h_neg;
80   - complex<double> h_pos;
81   -
82   - //cout<<"B coefficients:"<<endl;
83   - for(int l=0; l<Nl; l++)
84   - {
85   - //compute the spherical bessel functions
86   - j_kr = jv[l] * scale_kr;
87   - y_kr = yv[l] * scale_kr;
88   - j_knr = cjv[l] * scale_knr;
89   -
90   - //compute the Hankel function
91   - h_kr = complex<double>(j_kr, y_kr);
92   -
93   - //compute the derivatives
94   - if(l == 0)
95   - {
96   - //spherical bessel functions for l=0
97   - j_d_kr = scale_kr * (Jl_neg(kr) - (jv[l] + kr*jv[l+1])/kr )/2.0;
98   - j_d_knr = scale_knr * ( Jl_neg(knr) - (cjv[l] + knr*cjv[l+1])/knr )/2.0;
99   - h_neg = complex<double>(scale_kr*Jl_neg(kr), scale_kr*Yl_neg(kr));
100   - h_pos = complex<double>(scale_kr*jv[l+1], scale_kr*yv[l+1]);
101   - h_d_kr = (h_neg - (h_kr + kr*h_pos)/kr)/2.0;
102