#ifndef _GvsPreprocessor_H__ #define _GvsPreprocessor_H__ #include #include using namespace std; #include "Preprocessor.h" namespace GtpVisibilityPreprocessor { class Exporter; class VssRay; /** Sampling based visibility preprocessing. The implementation is based on heuristical sampling of view space. */ class GvsPreprocessor : public Preprocessor { public: GvsPreprocessor(); ~GvsPreprocessor() {} virtual bool ComputeVisibility(); protected: #if 0 struct PendingRay { PendingRay(VssRay *ray, const bool d) : mRay(ray), mFoundDiscontinuity(d) {} VssRay *mRay; bool mFoundDiscontinuity; }; typedef stack PendingQueue; #endif typedef stack RayQueue; /** Runs the adaptive sampling until the ray queue is empty. The method starts with a number of random rays given by the queue and continues as long it finds new visible geometry (i.e., the queue is not empty). @returns the number of samples cast. */ int ProcessQueue(); /** One pass of the sampling preprocessor. Continues as long as at least passSample rays have been cast. @returns the number of samples cast. */ int Pass(); /** Generates the rays starting the adaptive visibility sampling process. */ int CastInitialSamples(const int numSamples, const int sampleType); /** Uses the information gained from the ray for doing adaptive border sampling. This function tries to find the border of the triangle found visible by the current ray. New rays are generated which sample this border. We use the following strategies: a) if new triangle was found: adaptive border sampling b) if triangle was found reverse sampling */ bool HandleRay(VssRay *ray); /** The adaptive border sampling step. It aims to find neighbouring triangles of the one hit by the current ray. */ int AdaptiveBorderSampling(const VssRay ¤tRay); /** The reverse sampling step. It is started once the cast ray finds a discontinuity, i.e., a closer triangle. Then the process tries to find a ray from the old triangle passing through a gap. */ VssRay *ReverseSampling(const VssRay ¤tRay, const Triangle3 &hitTriangle, const VssRay &oldRay); /** Returns true if we sampled a closer triangle than with the previous ray. Does reverse sampling if gap found. */ bool CheckDiscontinuity(const VssRay ¤tRay, const Triangle3 &hitTriangle, const VssRay &oldRay); /** Adds new samples to the ray queue and classifies them with respect to the previous ray. */ void EnqueueRays(VssRayContainer &samples); /** Hepler function for adaptive border sampling. It finds new sample points around a triangle in a eps environment */ void EnlargeTriangle(VertexContainer &vertices, const Triangle3 &hitTriangle, const VssRay &ray); int SubdivideEdge( const Triangle3 &hitTriangle, const Vector3 &p1, const Vector3 &p2, const VssRay &x, const VssRay &y, const VssRay &oldRay); void Visualize(); ////////////////////// ofstream mStats; int mSamplesPerPass; int mTotalSamples; int mInitialSamples; RayQueue mRayQueue; int mSamplingType; AxisAlignedBox3 mViewSpaceBox; float mEps; float mThreshold; VssRayContainer mVssRays; /////////// // stats int mSampleContriPerPass; int mTotalSampleContri; int mReverseSamples; int mBorderSamples; int mGvsPass; }; }; #endif