HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_SobolSequence.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_SobolSequence.h ( UT Library, C++)
7  *
8  * COMMENTS: A sobol low-discrepancy sequence.
9  */
10 
11 #ifndef __UT_SobolSequence__
12 #define __UT_SobolSequence__
13 
14 #include "UT_API.h"
15 #include <SYS/SYS_Types.h>
16 #include "UT_Assert.h"
17 #include "UT_Vector3.h"
18 
19 // Definitions are provided in UT for types:
20 // - uint
21 // - uint64
22 template <class itype>
24 {
25 public:
26  /// Initialize a new sequence with the given number of dimensions and
27  /// bits.
28  ///
29  /// dim = vector size for each sample (max 6)
30  /// bits = number of bits in each random value (max 32)
31  UT_SobolSequence(uint dim, uint bits=sizeof(itype)*8);
32  virtual ~UT_SobolSequence();
33 
34  uint dimension() const { return myDim; }
35  uint bits() const { return myBits; }
36 
37  /// Advance to the next sample, storing the result into x. When myN
38  /// exceeds the range of the sequence, it will automatically wrap.
39  void advance();
40 
41  /// Return the sequence value for dimension dim.
42  itype x(uint dim)
43  { UT_ASSERT_P(dim < myDim); return myX[dim]; }
45  {
46  SYS_FPRealUnionF fval;
47 
48  if (myBits < 23)
49  fval.uval = 0x3f800000 | (uint)(x(dim) << (23-myBits));
50  else
51  fval.uval = 0x3f800000 | (uint)(x(dim) >> (myBits-23));
52  return fval.fval - 1;
53  }
54 
55  /// Reset the sequence
56  void rewind(itype n = 0);
57 
58 private:
59  itype *myIV;
60  itype *myX;
61  uint myDim;
62  uint myBits;
63  itype myN;
64  itype myMask;
65 };
66 
68 {
69 public:
71  : mySobol(3)
72  {
73  myVec[0] = mySobol.xf(0);
74  myVec[1] = mySobol.xf(1);
75  myVec[2] = mySobol.xf(2);
76  }
77  virtual ~UT_VectorSequence() {}
78 
79  void advance() { mySobol.advance(); }
80  void rewind(uint64 n = 0) { mySobol.rewind(n); }
82  {
83  myVec[0] = mySobol.xf(0);
84  myVec[1] = mySobol.xf(1);
85  myVec[2] = mySobol.xf(2);
86  return myVec;
87  }
88 
89 private:
91  UT_Vector3 myVec;
92 };
93 
94 #endif
#define UT_API
Definition: UT_API.h:12
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:101
GLdouble n
Definition: glcorearb.h:2007
unsigned long long uint64
Definition: SYS_Types.h:101
const UT_Vector3 & getVector()
void rewind(uint64 n=0)
fpreal32 xf(uint dim)
unsigned int uint
Definition: SYS_Types.h:33
uint bits() const
itype x(uint dim)
Return the sequence value for dimension dim.
GLint GLenum GLint x
Definition: glcorearb.h:408
float fpreal32
Definition: SYS_Types.h:184
virtual ~UT_VectorSequence()
uint dimension() const