sampler.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Sampler *
  23. * *
  24. * $Archive:: /VSS_Sync/wwlib/sampler.h $*
  25. * *
  26. * Original Author:: Hector Yee *
  27. * *
  28. * $Author:: Vss_sync $*
  29. * *
  30. * $Modtime:: 8/29/01 10:25p $*
  31. * *
  32. * $Revision:: 1 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #if _MSC_VER >= 1000
  38. #pragma once
  39. #endif // _MSC_VER >= 1000
  40. // 'function selected for automatic inline expansion'. Cool, but since we're treating
  41. // warnings as errors, don't warn me about this!
  42. #pragma warning(disable : 4711)
  43. // 'not inlined' -- the evil twin of the above warning.
  44. #pragma warning(disable : 4710)
  45. #ifndef SAMPLER_H
  46. #define SAMPLER_H
  47. class Random4Class;
  48. // This module contains sampling techniques that sample over multidimensional space
  49. // Dimension is the length of the vector to sample
  50. // Divisions is used to determine the number of strata to sample over
  51. // In some samplers, e.g. regular grid, it will repeat after dimension*division calls
  52. // to sample. A call to sample increments the internal state of the sampler.
  53. // Hector Yee 6/11/01
  54. // Abstract base class
  55. // all these sampling algoriths modify a vector of length Dimensions
  56. // they all return a value between 0..1
  57. // Hector Yee 6/11/01
  58. class SamplingClass
  59. {
  60. public:
  61. SamplingClass(unsigned int dimensions, unsigned char divisions):
  62. Dimensions(dimensions),
  63. Divisions(divisions)
  64. {};
  65. virtual void Reset() {};
  66. virtual void Sample(float *target)=0;
  67. virtual ~SamplingClass() {};
  68. protected:
  69. unsigned int Dimensions;
  70. unsigned char Divisions;
  71. };
  72. // Samples randomly in the dimensions using Mesenne Twister
  73. // divisions ignored
  74. // Hector Yee 6/11/01
  75. class RandomSamplingClass : public SamplingClass
  76. {
  77. public:
  78. RandomSamplingClass(unsigned int dimensions, unsigned char divisions=0);
  79. virtual void Reset() {};
  80. virtual void Sample(float *target);
  81. };
  82. // samples over a regular hypergrid
  83. // Hector Yee 6/11/01
  84. class RegularSamplingClass : public SamplingClass
  85. {
  86. public:
  87. RegularSamplingClass(unsigned int dimensions, unsigned char divisions=3);
  88. virtual void Reset();
  89. virtual void Sample(float *target);
  90. virtual ~RegularSamplingClass();
  91. protected:
  92. unsigned char *index;
  93. };
  94. // samples over a regular hypergrid with random perturbations
  95. // Hector Yee 6/11/01
  96. class StratifiedSamplingClass : public SamplingClass
  97. {
  98. public:
  99. StratifiedSamplingClass(unsigned int dimensions, unsigned char divisions=3);
  100. virtual void Reset();
  101. virtual void Sample(float *target);
  102. virtual ~StratifiedSamplingClass();
  103. protected:
  104. unsigned char *index;
  105. };
  106. // samples using QuasiMonteCarlo
  107. // divisions ignored
  108. // based on the Halton-Hammersly sequence which is in turn based on the inverse radical function
  109. // Hector Yee 6/11/01
  110. class QMCSamplingClass : public SamplingClass
  111. {
  112. public:
  113. QMCSamplingClass(unsigned int dimensions, unsigned char divisions=0);
  114. virtual void Reset() {index=0;};
  115. virtual void Sample(float *target);
  116. void Set_Offset(unsigned int offset) { index=offset; }
  117. protected:
  118. unsigned int index;
  119. };
  120. #endif