sampler.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. ** Command & Conquer Renegade(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:: 10/26/01 3:13p $*
  31. * *
  32. * $Revision:: 2 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #if _MSC_VER >= 1000
  38. #pragma once
  39. #endif // _MSC_VER >= 1000
  40. #ifndef SAMPLER_H
  41. #define SAMPLER_H
  42. class Random4Class;
  43. // This module contains sampling techniques that sample over multidimensional space
  44. // Dimension is the length of the vector to sample
  45. // Divisions is used to determine the number of strata to sample over
  46. // In some samplers, e.g. regular grid, it will repeat after dimension*division calls
  47. // to sample. A call to sample increments the internal state of the sampler.
  48. // Hector Yee 6/11/01
  49. // Abstract base class
  50. // all these sampling algoriths modify a vector of length Dimensions
  51. // they all return a value between 0..1
  52. // Hector Yee 6/11/01
  53. class SamplingClass
  54. {
  55. public:
  56. SamplingClass(unsigned int dimensions, unsigned char divisions):
  57. Dimensions(dimensions),
  58. Divisions(divisions)
  59. {};
  60. virtual void Reset() {};
  61. virtual void Sample(float *target)=0;
  62. virtual ~SamplingClass() {};
  63. protected:
  64. unsigned int Dimensions;
  65. unsigned char Divisions;
  66. };
  67. // Samples randomly in the dimensions using Mesenne Twister
  68. // divisions ignored
  69. // Hector Yee 6/11/01
  70. class RandomSamplingClass : public SamplingClass
  71. {
  72. public:
  73. RandomSamplingClass(unsigned int dimensions, unsigned char divisions=0);
  74. virtual void Reset() {};
  75. virtual void Sample(float *target);
  76. };
  77. // samples over a regular hypergrid
  78. // Hector Yee 6/11/01
  79. class RegularSamplingClass : public SamplingClass
  80. {
  81. public:
  82. RegularSamplingClass(unsigned int dimensions, unsigned char divisions=3);
  83. virtual void Reset();
  84. virtual void Sample(float *target);
  85. virtual ~RegularSamplingClass();
  86. protected:
  87. unsigned char *index;
  88. };
  89. // samples over a regular hypergrid with random perturbations
  90. // Hector Yee 6/11/01
  91. class StratifiedSamplingClass : public SamplingClass
  92. {
  93. public:
  94. StratifiedSamplingClass(unsigned int dimensions, unsigned char divisions=3);
  95. virtual void Reset();
  96. virtual void Sample(float *target);
  97. virtual ~StratifiedSamplingClass();
  98. protected:
  99. unsigned char *index;
  100. };
  101. // samples using QuasiMonteCarlo
  102. // divisions ignored
  103. // based on the Halton-Hammersly sequence which is in turn based on the inverse radical function
  104. // Hector Yee 6/11/01
  105. class QMCSamplingClass : public SamplingClass
  106. {
  107. public:
  108. QMCSamplingClass(unsigned int dimensions, unsigned char divisions=0);
  109. virtual void Reset() {index=0;};
  110. virtual void Sample(float *target);
  111. void Set_Offset(unsigned int offset) { index=offset; }
  112. protected:
  113. unsigned int index;
  114. };
  115. #endif