[1991] | 1 | #ifndef _Mutation_H__
|
---|
| 2 | #define _Mutation_H__
|
---|
| 3 |
|
---|
| 4 | #include <vector>
|
---|
[2176] | 5 | //
|
---|
[1991] | 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 |
|
---|
| 35 | bool
|
---|
| 36 | GenerateMutationCandidate(const int index,
|
---|
| 37 | SimpleRay &ray,
|
---|
| 38 | Intersectable *object,
|
---|
| 39 | const AxisAlignedBox3 &box
|
---|
| 40 | );
|
---|
| 41 |
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 | struct RayEntry {
|
---|
| 45 | // halton sequence for generatin gmutations of this ray
|
---|
| 46 | VssRay *mRay;
|
---|
[2001] | 47 | short mMutations;
|
---|
| 48 | short mUnsuccessfulMutations;
|
---|
[2076] | 49 | // Halton<4> mHalton;
|
---|
[1991] | 50 | HaltonSequence mHalton;
|
---|
| 51 | float mImportance;
|
---|
| 52 | float mCdf;
|
---|
| 53 |
|
---|
[2001] | 54 | Vector3 mutatedOrigin;
|
---|
| 55 | Vector3 mutatedTermination;
|
---|
| 56 |
|
---|
[1991] | 57 | float GetSamplingFactor() const { return mMutations/mImportance; }
|
---|
[2011] | 58 |
|
---|
| 59 | friend bool operator<(const RayEntry &a, const RayEntry &b) {
|
---|
| 60 | return a.GetSamplingFactor() > b.GetSamplingFactor();
|
---|
| 61 | }
|
---|
| 62 |
|
---|
[1991] | 63 | RayEntry() {}
|
---|
| 64 | RayEntry(VssRay *r):mRay(r),
|
---|
| 65 | mMutations(0),
|
---|
| 66 | mUnsuccessfulMutations(0),
|
---|
| 67 | mHalton(),
|
---|
[2001] | 68 | mImportance(1.0f)
|
---|
| 69 | {
|
---|
| 70 | ResetReverseMutation();
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | void ResetReverseMutation() {
|
---|
| 74 | mutatedOrigin = mutatedTermination = Vector3(0,0,0);
|
---|
| 75 | }
|
---|
| 76 | bool HasReverseMutation() const {
|
---|
| 77 | return !(mutatedOrigin == mutatedTermination);
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | void SetReverseMutation(const Vector3 &a, const Vector3 &b) {
|
---|
| 81 | mutatedOrigin = a;
|
---|
| 82 | mutatedTermination = b;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
[1991] | 85 | };
|
---|
[2001] | 86 |
|
---|
[1991] | 87 |
|
---|
| 88 | Vector3
|
---|
| 89 | ComputeOriginMutation(const VssRay &ray,
|
---|
| 90 | const Vector3 &U,
|
---|
| 91 | const Vector3 &V,
|
---|
| 92 | const Vector2 vr2,
|
---|
| 93 | const float radius
|
---|
| 94 | );
|
---|
| 95 |
|
---|
| 96 | Vector3
|
---|
| 97 | ComputeTerminationMutation(const VssRay &ray,
|
---|
| 98 | const Vector3 &U,
|
---|
| 99 | const Vector3 &V,
|
---|
| 100 | const Vector2 vr2,
|
---|
| 101 | const float radius
|
---|
| 102 | );
|
---|
| 103 |
|
---|
[1997] | 104 |
|
---|
| 105 | Vector3
|
---|
| 106 | ComputeSilhouetteTerminationMutation(const VssRay &ray,
|
---|
| 107 | const Vector3 &origin,
|
---|
| 108 | const AxisAlignedBox3 &box,
|
---|
| 109 | const Vector3 &U,
|
---|
| 110 | const Vector3 &V,
|
---|
| 111 | const float radius
|
---|
| 112 | );
|
---|
| 113 |
|
---|
[2001] | 114 |
|
---|
| 115 | bool
|
---|
| 116 | ComputeReverseMutation(
|
---|
| 117 | const VssRay &oldRay,
|
---|
| 118 | const VssRay &newRay,
|
---|
| 119 | Vector3 &origin,
|
---|
| 120 | Vector3 &termination
|
---|
| 121 | );
|
---|
| 122 |
|
---|
[2011] | 123 | RayEntry &GetEntry(const int index);
|
---|
| 124 |
|
---|
[1991] | 125 |
|
---|
| 126 | vector<RayEntry> mRays;
|
---|
| 127 | int mBufferStart;
|
---|
| 128 | int mLastIndex;
|
---|
[2060] | 129 |
|
---|
| 130 |
|
---|
| 131 | int mMaxRays;
|
---|
| 132 | float mMutationRadiusOrigin;
|
---|
| 133 | float mMutationRadiusTermination;
|
---|
| 134 | bool mUseReverseSamples;
|
---|
| 135 | float mReverseSamplesDistance;
|
---|
| 136 | bool mUseSilhouetteSamples;
|
---|
| 137 | int mSilhouetteSearchSteps;
|
---|
| 138 | float mSilhouetteProb;
|
---|
| 139 | bool mUsePassImportance;
|
---|
| 140 | bool mUseUnsuccCountImportance;
|
---|
| 141 |
|
---|
[1991] | 142 | };
|
---|
| 143 |
|
---|
| 144 |
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | #endif
|
---|
| 148 |
|
---|