#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: struct GvsRayInfo { GvsRayInfo(VssRay *ray, const bool d) : mRay(ray), mFoundDiscontinuity(d) {} VssRay *mRay; bool mFoundDiscontinuity; }; typedef stack RayQueue; struct PendingRay { PendingRay(VssRay *ray, const bool d) : mRay(ray), mFoundDiscontinuity(d) {} VssRay *mRay; bool mFoundDiscontinuity; }; typedef stack PendingQueue; /** 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 */ int HandleRay(const GvsRayInfo &ray); /** The adaptive border sampling step. It aims to find neighbouring triangles of the one hit by the previous ray. */ int AdaptiveBorderSampling(const VssRay &prevRay); /** 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. */ int ReverseSampling(const VssRay &prevRay); /** Returns true if we sampled a closer triangle than with the previous ray. */ const bool DiscontinuityFound(const VssRay &ray, const VssRay &prevRay) const; /** Adds new samples to the ray queue and classifies them with respect to the previous ray. */ void EnqueueRays(VssRayContainer &samples, VssRay *prevRay = NULL); ////////////////////// ofstream mStats; int mSamplesPerPass; RayQueue mRayQueue; int mSamplingType; int mTotalSamples; int mInitialSamples; AxisAlignedBox3 mViewSpaceBox; float mEps; }; }; #endif