[1460] | 1 | #ifndef _GvsPreprocessor_H__
|
---|
| 2 | #define _GvsPreprocessor_H__
|
---|
| 3 |
|
---|
| 4 | #include <fstream>
|
---|
[1473] | 5 | #include <stack>
|
---|
[1460] | 6 | using namespace std;
|
---|
| 7 |
|
---|
| 8 | #include "Preprocessor.h"
|
---|
| 9 |
|
---|
| 10 | namespace GtpVisibilityPreprocessor {
|
---|
| 11 |
|
---|
| 12 | class Exporter;
|
---|
[1473] | 13 | class VssRay;
|
---|
[1460] | 14 |
|
---|
[1473] | 15 |
|
---|
[1489] | 16 |
|
---|
[1473] | 17 | /** Sampling based visibility preprocessing. The implementation is
|
---|
| 18 | based on heuristical sampling of view space.
|
---|
| 19 | */
|
---|
[1460] | 20 | class GvsPreprocessor : public Preprocessor {
|
---|
| 21 |
|
---|
| 22 | public:
|
---|
[1473] | 23 |
|
---|
| 24 | GvsPreprocessor();
|
---|
| 25 | ~GvsPreprocessor() {}
|
---|
| 26 |
|
---|
| 27 | virtual bool ComputeVisibility();
|
---|
| 28 |
|
---|
| 29 |
|
---|
[1460] | 30 | protected:
|
---|
[1500] | 31 | #if 0
|
---|
[1492] | 32 | struct PendingRay
|
---|
| 33 | {
|
---|
| 34 | PendingRay(VssRay *ray, const bool d)
|
---|
| 35 | : mRay(ray), mFoundDiscontinuity(d)
|
---|
| 36 | {}
|
---|
| 37 |
|
---|
| 38 | VssRay *mRay;
|
---|
| 39 | bool mFoundDiscontinuity;
|
---|
| 40 | };
|
---|
| 41 |
|
---|
| 42 | typedef stack<PendingRay> PendingQueue;
|
---|
[1500] | 43 | #endif
|
---|
| 44 | typedef stack<VssRay *> RayQueue;
|
---|
[1492] | 45 |
|
---|
[1489] | 46 | /** Runs the adaptive sampling until the ray queue is empty.
|
---|
| 47 | The method starts with a number of random rays given
|
---|
| 48 | by the queue and continues as long it finds new visible geometry
|
---|
| 49 | (i.e., the queue is not empty).
|
---|
[1473] | 50 |
|
---|
| 51 | @returns the number of samples cast.
|
---|
| 52 | */
|
---|
[1489] | 53 | int ProcessQueue();
|
---|
[1473] | 54 |
|
---|
[1489] | 55 | /** One pass of the sampling preprocessor.
|
---|
| 56 | Continues as long as at least passSample rays have been cast.
|
---|
[1473] | 57 | @returns the number of samples cast.
|
---|
| 58 | */
|
---|
[1486] | 59 | int Pass();
|
---|
[1473] | 60 |
|
---|
| 61 | /** Generates the rays starting the adaptive visibility sampling process.
|
---|
| 62 | */
|
---|
[1489] | 63 | int CastInitialSamples(const int numSamples, const int sampleType);
|
---|
[1473] | 64 |
|
---|
| 65 | /** Uses the information gained from the ray for doing adaptive border sampling.
|
---|
| 66 | This function tries to find the border of the triangle found visible by the
|
---|
| 67 | current ray. New rays are generated which sample this border.
|
---|
| 68 |
|
---|
| 69 | We use the following strategies:
|
---|
| 70 |
|
---|
| 71 | a) if new triangle was found: adaptive border sampling
|
---|
| 72 | b) if triangle was found reverse sampling
|
---|
| 73 | */
|
---|
[1521] | 74 | bool HandleRay(VssRay *ray);
|
---|
[1473] | 75 |
|
---|
[1489] | 76 | /** The adaptive border sampling step. It aims to find neighbouring
|
---|
[1500] | 77 | triangles of the one hit by the current ray.
|
---|
[1473] | 78 | */
|
---|
[1500] | 79 | int AdaptiveBorderSampling(const VssRay ¤tRay);
|
---|
[1473] | 80 |
|
---|
[1489] | 81 | /** The reverse sampling step. It is started once the cast
|
---|
| 82 | ray finds a discontinuity, i.e., a closer triangle.
|
---|
| 83 | Then the process tries to find a ray from the old
|
---|
| 84 | triangle passing through a gap.
|
---|
| 85 | */
|
---|
[1500] | 86 | VssRay *ReverseSampling(const VssRay ¤tRay,
|
---|
| 87 | const Triangle3 &hitTriangle,
|
---|
| 88 | const VssRay &oldRay);
|
---|
[1473] | 89 |
|
---|
[1500] | 90 | /** Returns true if we sampled a closer triangle than with the previous ray.
|
---|
| 91 | Does reverse sampling if gap found.
|
---|
[1473] | 92 | */
|
---|
[1500] | 93 | bool CheckDiscontinuity(const VssRay ¤tRay,
|
---|
| 94 | const Triangle3 &hitTriangle,
|
---|
| 95 | const VssRay &oldRay);
|
---|
[1473] | 96 |
|
---|
[1489] | 97 | /** Adds new samples to the ray queue and classifies them
|
---|
| 98 | with respect to the previous ray.
|
---|
| 99 | */
|
---|
[1500] | 100 | void EnqueueRays(VssRayContainer &samples);
|
---|
| 101 |
|
---|
[1522] | 102 | /** Hepler function for adaptive border sampling. It finds
|
---|
[1500] | 103 | new sample points around a triangle in a eps environment
|
---|
| 104 | */
|
---|
| 105 | void EnlargeTriangle(VertexContainer &vertices,
|
---|
| 106 | const Triangle3 &hitTriangle,
|
---|
| 107 | const VssRay &ray);
|
---|
| 108 |
|
---|
| 109 | int SubdivideEdge(
|
---|
| 110 | const Triangle3 &hitTriangle,
|
---|
| 111 | const Vector3 &p1,
|
---|
| 112 | const Vector3 &p2,
|
---|
| 113 | const VssRay &x,
|
---|
| 114 | const VssRay &y,
|
---|
| 115 | const VssRay &oldRay);
|
---|
| 116 |
|
---|
[1522] | 117 | void Visualize();
|
---|
[1545] | 118 |
|
---|
[1473] | 119 | //////////////////////
|
---|
| 120 |
|
---|
| 121 | ofstream mStats;
|
---|
[1486] | 122 |
|
---|
[1473] | 123 | int mSamplesPerPass;
|
---|
[1545] | 124 | int mTotalSamples;
|
---|
| 125 | int mInitialSamples;
|
---|
| 126 |
|
---|
[1473] | 127 | RayQueue mRayQueue;
|
---|
| 128 | int mSamplingType;
|
---|
[1545] | 129 |
|
---|
[1563] | 130 | //AxisAlignedBox3 mViewSpaceBox;
|
---|
[1486] | 131 | float mEps;
|
---|
[1500] | 132 | float mThreshold;
|
---|
[1522] | 133 | VssRayContainer mVssRays;
|
---|
[1545] | 134 |
|
---|
| 135 | ///////////
|
---|
| 136 | // stats
|
---|
[1533] | 137 | int mSampleContriPerPass;
|
---|
| 138 | int mTotalSampleContri;
|
---|
| 139 | int mReverseSamples;
|
---|
| 140 | int mBorderSamples;
|
---|
[1545] | 141 | int mGvsPass;
|
---|
[1460] | 142 | };
|
---|
| 143 |
|
---|
| 144 | };
|
---|
| 145 |
|
---|
| 146 | #endif
|
---|