Revision 355,
696 bytes
checked in by bittner, 19 years ago
(diff) |
halton added
|
Line | |
---|
1 | #ifndef __HALTON_H
|
---|
2 | #define __HALTON_H
|
---|
3 |
|
---|
4 | class Halton2 {
|
---|
5 |
|
---|
6 | float _invBases[2];
|
---|
7 | float _prev[2];
|
---|
8 |
|
---|
9 | float halton(float baseRec, float prev) const {
|
---|
10 | float r = 1 - prev - 1e-10;
|
---|
11 | if (baseRec < r) return prev + baseRec;
|
---|
12 | float h = baseRec;
|
---|
13 | float hh;
|
---|
14 | do {
|
---|
15 | hh = h;
|
---|
16 | h *= baseRec;
|
---|
17 | } while (h >= r);
|
---|
18 | return prev + hh + h - 1;
|
---|
19 | }
|
---|
20 |
|
---|
21 | public:
|
---|
22 |
|
---|
23 | void Reset() {
|
---|
24 | _prev[0] =_prev[1] = 0;
|
---|
25 | }
|
---|
26 |
|
---|
27 | Halton2() {
|
---|
28 | _invBases[0] = 1./2;
|
---|
29 | _invBases[1] = 1./3;
|
---|
30 | Reset();
|
---|
31 | }
|
---|
32 |
|
---|
33 | void
|
---|
34 | GetNext(float &a, float &b) {
|
---|
35 | a = halton(_invBases[0], _prev[0]);
|
---|
36 | b = halton(_invBases[1], _prev[1]);
|
---|
37 | _prev[0] = a;
|
---|
38 | _prev[1] = b;
|
---|
39 | }
|
---|
40 | };
|
---|
41 |
|
---|
42 | extern Halton2 halton2;
|
---|
43 |
|
---|
44 | #endif
|
---|
Note: See
TracBrowser
for help on using the repository browser.