HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Stratify.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_Stratify.h ( UT Library, C++)
7  *
8  * COMMENTS: Generate stratified samples over a grid. The samples may be
9  * biased in either the u or the v direction if desired.
10  * This class isn't rocket science.
11  */
12 
13 #ifndef __UT_Stratify__
14 #define __UT_Stratify__
15 
16 #include "UT_API.h"
17 #include <SYS/SYS_Types.h>
18 
20 public:
23 
24  // Factor total_samples into a usize and vsize. usize*vsize will
25  // be less than or equal to total_samples and will be weighted in
26  // the u direction by uweight. If exact is set to true, we will ensure
27  // that usize*vsize == total_samples.
28  static void weightedFactor(unsigned int total_samples, fpreal uweight,
29  int &usize, int &vsize, bool exact = false);
30 
31  // Initialize so that N samples will be generated. The samples generated
32  // will be between 0 and (1-inc) where inc is based on the number of
33  // samples. With a u-weight of 1, the samples will be uniformly
34  // distributed in the u and v directions. With a u weight of 2, there will
35  // be twice as many samples in the u direction. Since it's impossible to
36  // generate a perfect number of samples (i.e. not all numbers are nice
37  // composites), there will be a number of un-stratified samples generated
38  // as well.
39  void init(unsigned int total_samples, fpreal uweight=1);
40 
41  //
42  // Reset the stratification
43  void reset()
44  {
45  myU = myV = 0;
46  myDoneRegular = false;
47  }
48  //
49  // Move on to the next sample
50  void nextSample()
51  {
52  if (!myDoneRegular)
53  {
54  myU++;
55  if (myU == myUSize)
56  {
57  myV++;
58  if (myV == myVSize)
59  myDoneRegular = true;
60  else myU = 0;
61  }
62  }
63  }
64  //
65  // Set an arbitrary sample
66  void setSample(unsigned int sample_number)
67  {
68  // s = usize*row + col
69  // col = s % usize
70  // row = s / vszie
71  myV = sample_number / myUSize;
72  myU = sample_number - myV*myUSize;
73  myDoneRegular = myU >= myUSize || myV >= myVSize;
74  }
75 
76  //
77  // As input to the stratify method, the variables u and v should be
78  // initialized with (random) numbers between 0 and 1.
80  {
81  if (!myDoneRegular)
82  {
83  u = (u + (fpreal)myU) * myUInc;
84  v = (v + (fpreal)myV) * myVInc;
85  }
86  }
88  {
89  if (!myDoneRegular)
90  {
91  u = (u + (fpreal)myU) * myUInc;
92  v = (v + (fpreal)myV) * myVInc;
93  }
94  }
95  int getUSize() const { return myUSize; }
96  int getVSize() const { return myVSize; }
97  fpreal getUInc() const { return myUInc; }
98  fpreal getVInc() const { return myVInc; }
99  int getStratifiedSize() const { return myUSize*myVSize; }
100  int isStratifiedSample() const { return myDoneRegular; }
101 
102 private:
103  fpreal myUInc, myVInc;
104  int myU, myV;
105  int myUSize, myVSize;
106  bool myDoneRegular;
107 };
108 
109 #endif
110 
int getUSize() const
Definition: UT_Stratify.h:95
const GLdouble * v
Definition: glcorearb.h:836
#define UT_API
Definition: UT_API.h:13
int getStratifiedSize() const
Definition: UT_Stratify.h:99
void setSample(unsigned int sample_number)
Definition: UT_Stratify.h:66
fpreal getVInc() const
Definition: UT_Stratify.h:98
double fpreal64
Definition: SYS_Types.h:192
fpreal getUInc() const
Definition: UT_Stratify.h:97
void stratify(fpreal32 &u, fpreal32 &v)
Definition: UT_Stratify.h:79
int getVSize() const
Definition: UT_Stratify.h:96
double fpreal
Definition: SYS_Types.h:270
void reset()
Definition: UT_Stratify.h:43
int isStratifiedSample() const
Definition: UT_Stratify.h:100
void stratify(fpreal64 &u, fpreal64 &v)
Definition: UT_Stratify.h:87
float fpreal32
Definition: SYS_Types.h:191
void nextSample()
Definition: UT_Stratify.h:50