1 | #ifndef _Mutation_H__
|
---|
2 | #define _Mutation_H__
|
---|
3 |
|
---|
4 | #include <vector>
|
---|
5 | using namespace std;
|
---|
6 |
|
---|
7 | #include "common.h"
|
---|
8 | #include "Halton.h"
|
---|
9 |
|
---|
10 | namespace GtpVisibilityPreprocessor {
|
---|
11 |
|
---|
12 | class Vector2;
|
---|
13 | class Vector3;
|
---|
14 | class VssRay;
|
---|
15 | class Preprocessor;
|
---|
16 | struct SimpleRay;
|
---|
17 | class SimpleRayContainer;
|
---|
18 |
|
---|
19 | struct VssRayContainer;
|
---|
20 |
|
---|
21 | class MutationBasedDistribution: public SamplingStrategy
|
---|
22 | {
|
---|
23 | public:
|
---|
24 | MutationBasedDistribution(Preprocessor &preprocessor);
|
---|
25 | virtual void Update(VssRayContainer &vssRays);
|
---|
26 |
|
---|
27 | virtual bool RequiresRays() { return true; }
|
---|
28 |
|
---|
29 | private:
|
---|
30 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
31 |
|
---|
32 | bool
|
---|
33 | GenerateMutation(const int index, SimpleRay &ray);
|
---|
34 | bool
|
---|
35 | GenerateSilhouetteMutation(const int index, SimpleRay &ray);
|
---|
36 |
|
---|
37 | bool
|
---|
38 | GenerateMutationCandidate(const int index,
|
---|
39 | SimpleRay &ray,
|
---|
40 | Intersectable *object,
|
---|
41 | const AxisAlignedBox3 &box
|
---|
42 | );
|
---|
43 |
|
---|
44 |
|
---|
45 |
|
---|
46 | struct RayEntry {
|
---|
47 | // halton sequence for generatin gmutations of this ray
|
---|
48 | VssRay *mRay;
|
---|
49 | short mMutations;
|
---|
50 | short mUnsuccessfulMutations;
|
---|
51 | HaltonSequence mHalton;
|
---|
52 | float mImportance;
|
---|
53 | float mCdf;
|
---|
54 |
|
---|
55 | Vector3 mutatedOrigin;
|
---|
56 | Vector3 mutatedTermination;
|
---|
57 |
|
---|
58 | float GetSamplingFactor() const { return mMutations/mImportance; }
|
---|
59 | RayEntry() {}
|
---|
60 | RayEntry(VssRay *r):mRay(r),
|
---|
61 | mMutations(0),
|
---|
62 | mUnsuccessfulMutations(0),
|
---|
63 | mHalton(),
|
---|
64 | mImportance(1.0f)
|
---|
65 | {
|
---|
66 | ResetReverseMutation();
|
---|
67 | }
|
---|
68 |
|
---|
69 | void ResetReverseMutation() {
|
---|
70 | mutatedOrigin = mutatedTermination = Vector3(0,0,0);
|
---|
71 | }
|
---|
72 | bool HasReverseMutation() const {
|
---|
73 | return !(mutatedOrigin == mutatedTermination);
|
---|
74 | }
|
---|
75 |
|
---|
76 | void SetReverseMutation(const Vector3 &a, const Vector3 &b) {
|
---|
77 | mutatedOrigin = a;
|
---|
78 | mutatedTermination = b;
|
---|
79 | }
|
---|
80 |
|
---|
81 | };
|
---|
82 |
|
---|
83 |
|
---|
84 | Vector3
|
---|
85 | ComputeOriginMutation(const VssRay &ray,
|
---|
86 | const Vector3 &U,
|
---|
87 | const Vector3 &V,
|
---|
88 | const Vector2 vr2,
|
---|
89 | const float radius
|
---|
90 | );
|
---|
91 |
|
---|
92 | Vector3
|
---|
93 | ComputeTerminationMutation(const VssRay &ray,
|
---|
94 | const Vector3 &U,
|
---|
95 | const Vector3 &V,
|
---|
96 | const Vector2 vr2,
|
---|
97 | const float radius
|
---|
98 | );
|
---|
99 |
|
---|
100 |
|
---|
101 | Vector3
|
---|
102 | ComputeSilhouetteTerminationMutation(const VssRay &ray,
|
---|
103 | const Vector3 &origin,
|
---|
104 | const AxisAlignedBox3 &box,
|
---|
105 | const Vector3 &U,
|
---|
106 | const Vector3 &V,
|
---|
107 | const Vector2 vr2,
|
---|
108 | const float radius
|
---|
109 | );
|
---|
110 |
|
---|
111 |
|
---|
112 | bool
|
---|
113 | ComputeReverseMutation(
|
---|
114 | const VssRay &oldRay,
|
---|
115 | const VssRay &newRay,
|
---|
116 | Vector3 &origin,
|
---|
117 | Vector3 &termination
|
---|
118 | );
|
---|
119 |
|
---|
120 | RayEntry &GetEntry(const int index) {
|
---|
121 | return mRays[(mBufferStart+index)%mRays.size()];
|
---|
122 | }
|
---|
123 |
|
---|
124 | vector<RayEntry> mRays;
|
---|
125 | int mMaxRays;
|
---|
126 | float mOriginMutationSize;
|
---|
127 | int mBufferStart;
|
---|
128 | int mLastIndex;
|
---|
129 | };
|
---|
130 |
|
---|
131 |
|
---|
132 | }
|
---|
133 |
|
---|
134 | #endif
|
---|
135 |
|
---|