-
Notifications
You must be signed in to change notification settings - Fork 0
/
Factory.h
117 lines (93 loc) · 2.89 KB
/
Factory.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
* Factory.h
*
* Created on: Aug 2, 2011
* Author: Jeroen Vlek
* Email: [email protected]
* Website: www.perceptivebits.com
* License: Free Beer (Feel free to use it in every
* way possible and if you like it, make
* sure to give me credit and buy me a drink
* if we ever meet ;) )
*/
#ifndef FACTORY_H_
#define FACTORY_H_
#include "Config.h"
#include "Gene.h"
#include "ImageImp.h"
#include <boost/shared_ptr.hpp>
#include <boost/random/linear_congruential.hpp>
#include <boost/random/uniform_int.hpp>
#include <boost/random/variate_generator.hpp>
/**
* Abstract factory for producing Genes and ImageImps. This is a singleton class.
*/
class Factory
{
public:
virtual ~Factory();
static Factory& Instance();
Gene makeRandomGene();
virtual ImageImp* makeImageImp() =0;
/**
* Updates the factory according to the settings in Config. Should be called
* after any config changes.
*/
void update();
/**
* @return Random gene size [0, Config::GetGenomeSize() ]
*/
unsigned int randGenomeIndex();
protected:
Factory();
/**
* @return Random primary color [0, 255]
*/
unsigned char randPrimary();
/**
* @return Random x-coordinate [0, Config::GetWidth() )
*/
unsigned int randX();
/**
* @return Random y-coordinate [0, Config::GetHeight() )
*/
unsigned int randY();
/**
* @return Random gene size [Config::GetMinGeneSize(), Config::GetMaxGeneSize() ]
*/
unsigned int randGeneSize();
private:
/**
* Fastest random number generator in the boost library.
*/
boost::rand48 m_gen;
/**
* Function object that generates primary colors.
* Distribution for color values: [0, 255]
*/
boost::variate_generator<boost::rand48&, boost::uniform_int<unsigned char> >* m_randPrimary;
/**
* Function object that generates x-coordinates. Distribution for
* x-coordinates: [0, Config::Width() ).
* On initialization Config::Width() is 0, meaning that the TargetImage should
* be loaded and subsequently the update function should be called first.
*/
boost::variate_generator<boost::rand48&, boost::uniform_int<unsigned int> >* m_randX;
/**
* Function object that generates y-coordinates. Distribution for
* x-coordinates: [0, Config::Height() ).
* On initialization Config::Height() is 0, meaning that the TargetImage should
* be loaded and subsequently the update function should be called first.
*/
boost::variate_generator<boost::rand48&, boost::uniform_int<unsigned int> >* m_randY;
/**
* Function object that generates gene sizes. Distribution for
* gene sizes: [Config::MinGeneSize, Config::MaxGeneSize].
*/
boost::variate_generator<boost::rand48&, boost::uniform_int<unsigned int> >* m_randGeneSize;
/**
* Function object that generates gene indices (used for mutation)
*/
boost::variate_generator<boost::rand48&, boost::uniform_int<unsigned int> >* m_randGenomeIndex;
};
#endif /* FACTORY_H_ */