#ifndef __HALTON_H #define __HALTON_H #include using namespace std; namespace GtpVisibilityPreprocessor { inline float halton(float baseRec, float prev) { float r = 1 - prev - 1e-10f; if (baseRec < r) return prev + baseRec; float h = baseRec; float hh; do { hh = h; h *= baseRec; } while (h >= r); return prev + hh + h - 1; } template class Halton { float _invBases[T]; float _prev[T]; public: void Reset() { for (int i=0; i < T; i++) _prev[i] = 0; } Halton() { for (int i=0; i < T; i++) { int base = FindPrime(i+1); if (base == 1) base++; _invBases[i] = 1.0f/base; } Reset(); } void GetNext(float *a) { for (int i=0; i < T; i++) { a[i] = halton(_invBases[i], _prev[i]); _prev[i] = a[i]; } } }; class Halton2 { static float _invBases[2]; float _prev[2]; public: void Reset() { _prev[0] =_prev[1] = 0; } Halton2() { _invBases[0] = 1.0f/2; _invBases[1] = 1.0f/3; Reset(); } void GetNext(float &a, float &b) { a = halton(_invBases[0], _prev[0]); b = halton(_invBases[1], _prev[1]); _prev[0] = a; _prev[1] = b; } }; /** * Assert whether the argument is a prime number. * @param number the number to be checked */ inline bool IsPrime(const int number) { bool isIt = true; for(int i = 2; i < number; i++) { if(number % i == 0) { isIt = false; break; } } if(number == 2) { isIt = false; } return isIt; } /** * Find the nth prime number. * @param index the ordinal position in the sequence */ inline int FindPrime(const int index) { // if (index < 1) { // cerr<<"FindPrime: The argument must be non-negative."<= 2) && (index >= 1)) { while(copyOfIndex > 0) { N1 = (copyOfIndex / base); remainder = copyOfIndex % base; output += fraction * remainder; copyOfIndex = (int)(copyOfIndex / base); fraction /= (double)base; } return output; } else { cerr<<"Error generating Halton sequence."<