00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __UT_Stratify__
00022 #define __UT_Stratify__
00023
00024 #include "UT_API.h"
00025 #include <SYS/SYS_Types.h>
00026
00027 class UT_API UT_Stratify {
00028 public:
00029 UT_Stratify() {}
00030 ~UT_Stratify() {}
00031
00032
00033
00034
00035
00036 static void weightedFactor(unsigned int total_samples, fpreal uweight,
00037 int &usize, int &vsize, bool exact = false);
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 void init(unsigned int total_samples, fpreal uweight=1);
00048
00049
00050
00051 void reset()
00052 {
00053 myU = myV = 0;
00054 myDoneRegular = false;
00055 }
00056
00057
00058 void nextSample()
00059 {
00060 if (!myDoneRegular)
00061 {
00062 myU++;
00063 if (myU == myUSize)
00064 {
00065 myV++;
00066 if (myV == myVSize)
00067 myDoneRegular = true;
00068 else myU = 0;
00069 }
00070 }
00071 }
00072
00073
00074 void setSample(unsigned int sample_number)
00075 {
00076
00077
00078
00079 myV = sample_number / myUSize;
00080 myU = sample_number - myV*myUSize;
00081 myDoneRegular = myU >= myUSize || myV >= myVSize;
00082 }
00083
00084
00085
00086
00087 void stratify(fpreal32 &u, fpreal32 &v)
00088 {
00089 if (!myDoneRegular)
00090 {
00091 u = (u + (fpreal)myU) * myUInc;
00092 v = (v + (fpreal)myV) * myVInc;
00093 }
00094 }
00095 void stratify(fpreal64 &u, fpreal64 &v)
00096 {
00097 if (!myDoneRegular)
00098 {
00099 u = (u + (fpreal)myU) * myUInc;
00100 v = (v + (fpreal)myV) * myVInc;
00101 }
00102 }
00103 int getUSize() const { return myUSize; }
00104 int getVSize() const { return myVSize; }
00105 fpreal getUInc() const { return myUInc; }
00106 fpreal getVInc() const { return myVInc; }
00107 int getStratifiedSize() const { return myUSize*myVSize; }
00108 int isStratifiedSample() const { return myDoneRegular; }
00109
00110 private:
00111 fpreal myUInc, myVInc;
00112 int myU, myV;
00113 int myUSize, myVSize;
00114 bool myDoneRegular;
00115 };
00116
00117 #endif
00118