0ef519a4
David Mayerich
optimized materia...
|
1
2
|
#ifndef RTS_MATERIAL_H
#define RTS_MATERIAL_H
|
f1402849
dmayerich
renewed commit
|
3
4
5
6
7
8
9
10
|
#include <vector>
#include <ostream>
#include <iostream>
#include <fstream>
#include <complex>
#include <algorithm>
#include <sstream>
|
76396b52
David Mayerich
removed Qt from t...
|
11
12
13
|
#include "../math/complex.h"
#include "../math/constants.h"
#include "../math/function.h"
|
f1402849
dmayerich
renewed commit
|
14
|
|
f1402849
dmayerich
renewed commit
|
15
16
|
namespace rts{
|
0ef519a4
David Mayerich
optimized materia...
|
17
18
19
|
//Material class - default representation for the material property is the refractive index (RI)
template<typename T>
class material : public function< T, complex<T> >{
|
f1402849
dmayerich
renewed commit
|
20
|
|
0ef519a4
David Mayerich
optimized materia...
|
21
22
23
|
public:
enum wave_property{microns, inverse_cm};
enum material_property{ri, absorbance};
|
f1402849
dmayerich
renewed commit
|
24
|
|
0ef519a4
David Mayerich
optimized materia...
|
25
|
private:
|
f1402849
dmayerich
renewed commit
|
26
|
|
0ef519a4
David Mayerich
optimized materia...
|
27
28
29
30
|
using function< T, complex<T> >::X;
using function< T, complex<T> >::Y;
using function< T, complex<T> >::insert;
using function< T, complex<T> >::bounding;
|
f1402849
dmayerich
renewed commit
|
31
|
|
0ef519a4
David Mayerich
optimized materia...
|
32
|
std::string name; //name for the material (defaults to file name)
|
f1402849
dmayerich
renewed commit
|
33
|
|
0ef519a4
David Mayerich
optimized materia...
|
34
|
void process_header(std::string str, wave_property& wp, material_property& mp){
|
f1402849
dmayerich
renewed commit
|
35
|
|
0ef519a4
David Mayerich
optimized materia...
|
36
37
38
39
|
std::stringstream ss(str); //create a stream from the data string
std::string line;
std::getline(ss, line); //get the first line as a string
while(line[0] == '#'){ //continue looping while the line is a comment
|
7006df5f
David Mayerich
reformat of direc...
|
40
|
|
0ef519a4
David Mayerich
optimized materia...
|
41
42
|
std::stringstream lstream(line); //create a stream from the line
lstream.ignore(); //ignore the first character ('#')
|
f1402849
dmayerich
renewed commit
|
43
|
|
0ef519a4
David Mayerich
optimized materia...
|
44
45
|
std::string prop; //get the property name
lstream>>prop;
|
f1402849
dmayerich
renewed commit
|
46
|
|
0ef519a4
David Mayerich
optimized materia...
|
47
48
49
50
51
|
if(prop == "X"){
std::string wp_name;
lstream>>wp_name;
if(wp_name == "microns") wp = microns;
else if(wp_name == "inverse_cm") wp = inverse_cm;
|
f1402849
dmayerich
renewed commit
|
52
|
}
|
0ef519a4
David Mayerich
optimized materia...
|
53
54
55
56
57
|
else if(prop == "Y"){
std::string mp_name;
lstream>>mp_name;
if(mp_name == "ri") mp = ri;
else if(mp_name == "absorbance") mp = absorbance;
|
f1402849
dmayerich
renewed commit
|
58
59
|
}
|
0ef519a4
David Mayerich
optimized materia...
|
60
61
|
std::getline(ss, line); //get the next line
}
|
f1402849
dmayerich
renewed commit
|
62
|
|
0ef519a4
David Mayerich
optimized materia...
|
63
64
|
function< T, rts::complex<T> >::process_string(str);
}
|
f1402849
dmayerich
renewed commit
|
65
|
|
0ef519a4
David Mayerich
optimized materia...
|
66
67
68
69
|
void from_inverse_cm(){
//convert inverse centimeters to wavelength (in microns)
for(unsigned int i=0; i<X.size(); i++)
X[i] = 10000 / X[i];
|
f1402849
dmayerich
renewed commit
|
70
|
|
0ef519a4
David Mayerich
optimized materia...
|
71
72
73
|
//reverse the function array
std::reverse(X.begin(), X.end());
std::reverse(Y.begin(), Y.end());
|
f1402849
dmayerich
renewed commit
|
74
|
|
0ef519a4
David Mayerich
optimized materia...
|
75
|
}
|
f1402849
dmayerich
renewed commit
|
76
|
|
0ef519a4
David Mayerich
optimized materia...
|
77
78
79
|
void init(){
bounding[0] = bounding[1] = rts::complex<T>(1, 0);
}
|
f1402849
dmayerich
renewed commit
|
80
|
|
a47a23a9
dmayerich
added ENVI functions
|
81
|
|
0ef519a4
David Mayerich
optimized materia...
|
82
|
public:
|
f1402849
dmayerich
renewed commit
|
83
|
|
0ef519a4
David Mayerich
optimized materia...
|
84
85
86
87
|
material(std::string filename, wave_property wp, material_property mp){
name = filename;
load(filename, wp, mp);
}
|
f1402849
dmayerich
renewed commit
|
88
|
|
0ef519a4
David Mayerich
optimized materia...
|
89
90
91
92
|
material(std::string filename){
name = filename;
load(filename);
}
|
f1402849
dmayerich
renewed commit
|
93
|
|
0ef519a4
David Mayerich
optimized materia...
|
94
95
96
|
material(){
init();
}
|
6e257ab3
dmayerich
ENVI and colormap...
|
97
|
|
0ef519a4
David Mayerich
optimized materia...
|
98
99
100
|
complex<T> getN(T lambda){
return function< T, complex<T> >::linear(lambda);
}
|
6e257ab3
dmayerich
ENVI and colormap...
|
101
|
|
0ef519a4
David Mayerich
optimized materia...
|
102
|
void load(std::string filename, wave_property wp, material_property mp){
|
6e257ab3
dmayerich
ENVI and colormap...
|
103
|
|
0ef519a4
David Mayerich
optimized materia...
|
104
105
106
|
//load the file as a function
function< T, complex<T> >::load(filename);
}
|
f1402849
dmayerich
renewed commit
|
107
|
|
0ef519a4
David Mayerich
optimized materia...
|
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
void load(std::string filename){
wave_property wp = inverse_cm;
material_property mp = ri;
//turn the file into a string
std::ifstream t(filename.c_str()); //open the file as a stream
if(!t){
std::cout<<"ERROR: Couldn't open the material file '"<<filename<<"'"<<std::endl;
exit(1);
}
std::string str((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>());
//process the header information
process_header(str, wp, mp);
//convert units
if(wp == inverse_cm)
from_inverse_cm();
//set the bounding values
bounding[0] = Y[0];
bounding[1] = Y.back();
}
std::string str(){
std::stringstream ss;
ss<<name<<std::endl;
ss<<function< T, complex<T> >::str();
return ss.str();
}
std::string get_name(){
return name;
}
|
f1402849
dmayerich
renewed commit
|
141
|
|
0ef519a4
David Mayerich
optimized materia...
|
142
143
144
|
void set_name(std::string str){
name = str;
}
|
f1402849
dmayerich
renewed commit
|
145
|
|
0ef519a4
David Mayerich
optimized materia...
|
146
|
};
|
f1402849
dmayerich
renewed commit
|
147
|
|
f1402849
dmayerich
renewed commit
|
148
149
150
151
|
}
|
0ef519a4
David Mayerich
optimized materia...
|
152
|
|
f1402849
dmayerich
renewed commit
|
153
|
#endif
|