Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
sampler.h
Go to the documentation of this file.
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/***********************************************************************************************
20 *** 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 ***
21 ***********************************************************************************************
22 * *
23 * Project Name : Sampler *
24 * *
25 * $Archive:: /VSS_Sync/wwlib/sampler.h $*
26 * *
27 * Original Author:: Hector Yee *
28 * *
29 * $Author:: Vss_sync $*
30 * *
31 * $Modtime:: 8/29/01 10:25p $*
32 * *
33 * $Revision:: 1 $*
34 * *
35 *---------------------------------------------------------------------------------------------*
36 * Functions: *
37 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
38
39#if _MSC_VER >= 1000
40#pragma once
41#endif // _MSC_VER >= 1000
42
43// 'function selected for automatic inline expansion'. Cool, but since we're treating
44// warnings as errors, don't warn me about this!
45#pragma warning(disable : 4711)
46
47// 'not inlined' -- the evil twin of the above warning.
48#pragma warning(disable : 4710)
49
50#ifndef SAMPLER_H
51#define SAMPLER_H
52
53class Random4Class;
54
55// This module contains sampling techniques that sample over multidimensional space
56// Dimension is the length of the vector to sample
57// Divisions is used to determine the number of strata to sample over
58// In some samplers, e.g. regular grid, it will repeat after dimension*division calls
59// to sample. A call to sample increments the internal state of the sampler.
60// Hector Yee 6/11/01
61
62// Abstract base class
63// all these sampling algoriths modify a vector of length Dimensions
64// they all return a value between 0..1
65// Hector Yee 6/11/01
67{
68public:
69 SamplingClass(unsigned int dimensions, unsigned char divisions):
70 Dimensions(dimensions),
71 Divisions(divisions)
72 {};
73 virtual void Reset() {};
74 virtual void Sample(float *target)=0;
75 virtual ~SamplingClass() {};
76protected:
77 unsigned int Dimensions;
78 unsigned char Divisions;
79};
80
81// Samples randomly in the dimensions using Mesenne Twister
82// divisions ignored
83// Hector Yee 6/11/01
85{
86public:
87 RandomSamplingClass(unsigned int dimensions, unsigned char divisions=0);
88 virtual void Reset() {};
89 virtual void Sample(float *target);
90};
91
92// samples over a regular hypergrid
93// Hector Yee 6/11/01
95{
96public:
97 RegularSamplingClass(unsigned int dimensions, unsigned char divisions=3);
98 virtual void Reset();
99 virtual void Sample(float *target);
100 virtual ~RegularSamplingClass();
101protected:
102 unsigned char *index;
103};
104
105// samples over a regular hypergrid with random perturbations
106// Hector Yee 6/11/01
108{
109public:
110 StratifiedSamplingClass(unsigned int dimensions, unsigned char divisions=3);
111 virtual void Reset();
112 virtual void Sample(float *target);
113 virtual ~StratifiedSamplingClass();
114protected:
115 unsigned char *index;
116};
117
118// samples using QuasiMonteCarlo
119// divisions ignored
120// based on the Halton-Hammersly sequence which is in turn based on the inverse radical function
121// Hector Yee 6/11/01
123{
124public:
125 QMCSamplingClass(unsigned int dimensions, unsigned char divisions=0);
126 virtual void Reset() {index=0;};
127 virtual void Sample(float *target);
128 void Set_Offset(unsigned int offset) { index=offset; }
129protected:
130 unsigned int index;
131};
132
133
134#endif
virtual void Sample(float *target)
Definition sampler.cpp:255
unsigned int index
Definition sampler.h:130
virtual void Reset()
Definition sampler.h:126
void Set_Offset(unsigned int offset)
Definition sampler.h:128
QMCSamplingClass(unsigned int dimensions, unsigned char divisions=0)
Definition sampler.cpp:232
RandomSamplingClass(unsigned int dimensions, unsigned char divisions=0)
Definition sampler.cpp:57
virtual void Reset()
Definition sampler.h:88
virtual void Sample(float *target)
Definition sampler.cpp:77
unsigned char * index
Definition sampler.h:102
RegularSamplingClass(unsigned int dimensions, unsigned char divisions=3)
Definition sampler.cpp:86
virtual ~RegularSamplingClass()
Definition sampler.cpp:98
virtual void Reset()
Definition sampler.cpp:93
virtual void Sample(float *target)
Definition sampler.cpp:119
virtual void Reset()
Definition sampler.h:73
virtual ~SamplingClass()
Definition sampler.h:75
virtual void Sample(float *target)=0
unsigned int Dimensions
Definition sampler.h:77
SamplingClass(unsigned int dimensions, unsigned char divisions)
Definition sampler.h:69
unsigned char Divisions
Definition sampler.h:78
virtual void Reset()
Definition sampler.cpp:149
virtual void Sample(float *target)
Definition sampler.cpp:174
unsigned char * index
Definition sampler.h:115
StratifiedSamplingClass(unsigned int dimensions, unsigned char divisions=3)
Definition sampler.cpp:142
virtual ~StratifiedSamplingClass()
Definition sampler.cpp:154