code/include/NewWave/Utils.hh
Go to the documentation of this file.
00001 #ifndef NEWWAVE_UTILS_HH 00002 #define NEWWAVE_UTILS_HH 00003 00004 #include "NewWave/PixelArray.hh" 00005 00006 #include <functional> 00007 #include <algorithm> 00008 #include <assert.h> 00009 #include <cmath> 00010 00011 namespace NewWave{ 00012 00013 using std::size_t; 00014 00016 const double TWOPI = 2.0 * M_PI; 00017 00019 00022 inline bool isEven(size_t n){ return (n%2 == 0);} 00023 00025 00028 inline bool isOdd(size_t n){return !isEven(n);} 00029 00031 00035 inline bool isRadix2(size_t n){return !((n-1) & n);} 00036 00038 inline size_t nearestRadix2(size_t n){ 00039 if(isOdd(n)) ++n; 00040 // @todo clever way of doing this? 00041 while(!isRadix2(n)){ 00042 n+=2; 00043 } 00044 return n; 00045 } 00046 00048 00058 inline vector<double> makeRowFromArray(const PixelArray &array){ 00059 vector<double> rowMajor; 00060 00061 for(PixelArray::const_iterator row = array.begin(); 00062 row != array.end(); ++row){ 00063 00064 for(vector<double>::const_iterator el = row->begin(); 00065 el != row->end(); ++el){ 00066 rowMajor.push_back(*el); 00067 } 00068 } 00069 00070 return rowMajor; 00071 } 00072 00073 inline PixelArray makeArray(const vector<double> &row){ 00074 size_t n = sqrt(row.size()); 00075 assert(n*n == row.size()); 00076 PixelArray output; 00077 00078 PixelRow line; 00079 for(double el: row){ 00080 line.push_back(el); 00081 if(line.size()==n){ 00082 output.push_back(line); 00083 line.clear(); 00084 } 00085 } 00086 00087 return output; 00088 } 00089 00091 00096 inline vector<double> operator / (vector<double> left, 00097 const vector<double> &right){ 00098 00099 std::transform(left.begin(), left.end(), right.begin(), left.begin(), std::divides<double>()); 00100 return left; 00101 } 00102 00104 00105 inline PixelArray operator / (PixelArray left, const PixelArray &right){ 00106 00107 std::transform(left.begin(), left.end(), right.begin(), left.begin(), 00108 [](PixelRow num, const PixelRow &denom){return num / denom;}); 00109 return left; 00110 } 00111 00112 00114 inline double mod2Pi(double angle){ 00115 if(angle < TWOPI && angle >= 0) return angle; 00116 00117 double dPhi = fmod(angle, TWOPI); 00118 return (angle >=0)? dPhi: TWOPI + dPhi; 00119 } 00120 00121 } 00122 #endif Generated on Wed Aug 23 2017 12:59:15 for New Wave - Noise Elimination With Wavelets At Vast Energies by 1.7.6.1 |