Authored by David Mayerich
1 parent 7c246292

optimized material class, still have to add KK

Showing 5 changed files with 199 additions and 584 deletions
math/complex.h

 @@ -294,6 +294,19 @@ struct complex @@ -294,6 +294,19 @@ struct complex 294 return false; 294 return false; 295 } 295 } 296 296 297 + CUDA_CALLABLE bool operator<(complex rhs){ 298 + return abs() < rhs.abs(); 299 + } 300 + CUDA_CALLABLE bool operator<=(complex rhs){ 301 + return abs() <= rhs.abs(); 302 + } 303 + CUDA_CALLABLE bool operator>(complex rhs){ 304 + return abs() > rhs.abs(); 305 + } 306 + CUDA_CALLABLE bool operator >=(complex rhs){ 307 + return abs() >= rhs.abs(); 308 + } 309 + 297 //CASTING operators 310 //CASTING operators 298 template < typename otherT > 311 template < typename otherT > 299 operator complex() 312 operator complex() @@ -469,6 +482,20 @@ std::ostream& operator<<(std::ostream& os, rts::complex<A> x) @@ -469,6 +482,20 @@ std::ostream& operator<<(std::ostream& os, rts::complex<A> x) 469 return os; 482 return os; 470 } 483 } 471 484 485 +template 486 +std::istream& operator>>(std::istream& is, rts::complex& x) 487 +{ 488 + A r, i; 489 + r = i = 0; //initialize the real and imaginary parts to zero 490 + is>>r; //parse 491 + is>>i; 492 + 493 + x.real(r); //assign the parsed values to x 494 + x.imag(i); 495 + 496 + return is; //return the stream 497 +} 498 + 472 //#if __GNUC__ > 3 && __GNUC_MINOR__ > 7 499 //#if __GNUC__ > 3 && __GNUC_MINOR__ > 7 473 //template using rtsComplex = rts::complex; 500 //template using rtsComplex = rts::complex; 474 //#endif 501 //#endif
math/function.h

 @@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@ 2 #define RTS_FUNCTION_H 2 #define RTS_FUNCTION_H 3 3 4 #include 4 #include 5 +#include 5 6 6 namespace rts{ 7 namespace rts{ 7 8 @@ -9,8 +10,12 @@ namespace rts{ @@ -9,8 +10,12 @@ namespace rts{ 9 template 10 template 10 class function 11 class function 11 { 12 { 13 +protected: 14 + 12 std::vector X; 15 std::vector X; 13 std::vector Y; 16 std::vector Y; 17 + Ty range[2]; 18 + Ty bounding[2]; 14 19 15 //comparison function for searching lambda 20 //comparison function for searching lambda 16 static bool findCeiling(Tx ax, Tx bx){ 21 static bool findCeiling(Tx ax, Tx bx){ @@ -21,11 +26,6 @@ class function @@ -21,11 +26,6 @@ class function 21 void process_string(std::string s){ 26 void process_string(std::string s){ 22 std::stringstream ss(s); 27 std::stringstream ss(s); 23 28 24 - //std::string test; 25 - //std::getline(ss, test); 26 - //std::cout<>x; //read the x value 40 lstream>>x; //read the x value 41 lstream>>y; //read the y value 41 lstream>>y; //read the y value 42 42 43 - //std::cout< range[1]) range[1] = y; 57 + } 58 + 51 59 52 public: 60 public: 61 + function(){ 62 + range[0] = range[1] = NAN; 63 + bounding[0] = bounding[1] = 0; 64 + } 53 65 54 //linear interpolation 66 //linear interpolation 55 Ty linear(Tx x) const 67 Ty linear(Tx x) const 56 { 68 { 57 - if(X.size() == 0) return (Ty)0; //return zero if the function is empty 69 + if(X.size() == 0) return bounding[0]; //return zero if the function is empty 70 + //return bounding values if x is outside the sample domain 71 + if(x < X[0]) return bounding[0]; 72 + if(x > X.back()) return bounding[1]; 58 73 59 unsigned int N = X.size(); //number of sample points 74 unsigned int N = X.size(); //number of sample points 60 75 @@ -92,6 +107,8 @@ public: @@ -92,6 +107,8 @@ public: 92 { 107 { 93 unsigned int N = X.size(); //number of sample points 108 unsigned int N = X.size(); //number of sample points 94 109 110 + update_range(y); //update the range of the function 111 + 95 if(N == 0 || X[N-1] < x){ 112 if(N == 0 || X[N-1] < x){ 96 X.push_back(x); 113 X.push_back(x); 97 Y.push_back(y); 114 Y.push_back(y); @@ -172,14 +189,30 @@ public: @@ -172,14 +189,30 @@ public: 172 } 189 } 173 190 174 191 175 - 192 + //output a string description of the function (used for console output and debugging) 176 std::string str(){ 193 std::string str(){ 177 - stringstream ss; 194 + unsigned int N = X.size(); 195 + 196 + std::stringstream ss; 197 + ss<<"# of samples: "<
optics/material.h