#ifndef _Preprocessor_H__ #define _Preprocessor_H__ #include using namespace std; #include "Containers.h" #include "Mesh.h" #include "KdTree.h" #include "SimpleRay.h" namespace GtpVisibilityPreprocessor { class PreprocessorThread; class RenderSimulator; class SceneGraph; class Exporter; class ViewCellsManager; class BspTree; class VspOspTree; class VspBspTree; class RenderSimulator; struct VssRayContainer; class SamplingStrategy; class GlRendererBuffer; class VspTree; class HierarchyManager; class BvHierarchy; class Intersectable; class VssRay; class RayCaster; class GlobalLinesRenderer; /** Namespace for the external visibility preprocessor This namespace includes all classes which are created by the VUT (Vienna University of Technology) for the External Visibility Preprocessor of the GTP (GameTools Project) (www.gametools.org). */ /** Main class of the visibility preprocessor. Responsible for loading and saving of the input and output files. Initiates construction of the kD-tree, viewcell loading/generation and the visibility computation itself. */ class Preprocessor { friend class RayCaster; friend class IntelRayCaster; friend class InternalRayCaster; public: /** Default constructor initialising e.g., KD tree and BSP tree. */ Preprocessor(); virtual ~Preprocessor(); /** Load the input scene. @param filename file to load @return true on success */ virtual bool LoadScene(const string filename); /** Export all preprocessed data in a XML format understandable by the PreprocessingInterface of the GtpVisibilityPreprocessor Module. The file can be compressed depending on the environement settings. @return true on successful export */ virtual bool ExportPreprocessedData(const string filename); /** Build the KdTree of currently loaded occluders/occludees/viewcells. The construction is driven by the environment settings, which also sais which of the three types of entities should be used to drive the heuristical construction (only occluders by default) */ virtual bool BuildKdTree(); /** Compute visibility method. This method has to be reimplemented by the actual Preprocessor implementation (e.g. SamplingPreprocessor, ExactPreprocessor, GlobalSamplingpreprocessor) */ virtual bool ComputeVisibility() = 0; /** Post Process the computed visibility. By default applys the visibility filter (if specified in the environment and export the preprocessed data */ virtual bool PostProcessVisibility(); /** View cells are either loaded or prepared for generation, according to the chosen environment object. Important evironment options are, e.g, the view cell type. Should be done after scene loading (i.e., some options are based on scene type). */ bool PrepareViewCells(); /** Construct viewcells from the scratch */ bool ConstructViewCells(); /** Returns the specified sample strategy, NULL if no valid strategy. */ SamplingStrategy *GenerateSamplingStrategy(const int strategyId); /** Export preprocessor data. */ bool Export(const string filename, const bool scene, const bool kdtree); virtual void KdTreeStatistics(ostream &s); virtual void BspTreeStatistics(ostream &s); /** Loads samples from file. @param samples returns the stored sample rays @param objects needed to associate the objects ids @returns true if samples were loaded successfully */ bool LoadSamples(VssRayContainer &samples, ObjectContainer &objects) const; /** Exports samples to file. @returns true if samples were written successfully */ bool ExportSamples(const VssRayContainer &samples) const; bool LoadKdTree(const string filename); bool ExportKdTree(const string filename); virtual bool ExportRays(const char *filename, const VssRayContainer &vssRays, const int number, const bool exportScene = false ); bool ExportRayAnimation(const char *filename, const vector &vssRays); virtual int GenerateRays(const int number, SamplingStrategy &strategy, SimpleRayContainer &rays); virtual int GenerateRays(const int number, const int raysType, SimpleRayContainer &rays); bool GenerateRayBundle(SimpleRayContainer &rayBundle, const SimpleRay &mainRay, const int number, const int shuffleType) const; virtual void CastRays(SimpleRayContainer &rays, VssRayContainer &vssRays, const bool castDoubleRays, const bool pruneInvalidRays = true); virtual void CastRaysWithHwGlobalLines( SimpleRayContainer &rays, VssRayContainer &vssRays, const bool castDoubleRays, const bool pruneInvalidRays ); /** Compute pixel error of the current PVS solution by sampling given number of viewpoints . */ virtual void ComputeRenderError(); /** Returns a view cells manager of the given name. */ ViewCellsManager *CreateViewCellsManager(const char *name); GlRendererBuffer *GetRenderer(); bool InitRayCast(const string externKdTree, const string internKdTree); bool LoadInternKdTree(const string internKdTree); bool ExportObj(const string filename, const ObjectContainer &objects); Intersectable *GetParentObject(const int index) const; Vector3 GetParentNormal(const int index) const; /** Sets a Preprocessor thread. */ void SetThread(PreprocessorThread *t); /** Returns a Preprocessor thread. */ PreprocessorThread *GetThread() const; Intersectable *GetObjectById(const int id); void PrepareHwGlobalLines(); virtual void DeterminePvsObjects(VssRayContainer &rays); static bool LoadObjects(const string &filename, ObjectContainer &pvsObjects, const ObjectContainer &preprocessorObject); //////////////////////////////////////////////// /// scene graph loaded from file SceneGraph *mSceneGraph; /// raw array of objects ObjectContainer mObjects; /// kD-tree organizing the scene graph (occluders + occludees) + viewcells KdTree *mKdTree; /// View space partition bsp tree VspBspTree *mVspBspTree; /// BSP tree representing the viewcells BspTree *mBspTree; /// list of all loaded occluders ObjectContainer mOccluders; /// list of all loaded occludees ObjectContainer mOccludees; ViewCellsManager *mViewCellsManager; /// greedy optimized hierarchy for both objects and view cells VspOspTree *mVspOspTree; bool mUseGlRenderer; bool mUseGlDebugger; bool mUseHwGlobalLines; bool mLoadViewCells; bool mDetectEmptyViewSpace; bool mQuitOnFinish; bool mLoadMeshes; bool mComputeVisibility; bool mExportVisibility; string mVisibilityFileName; bool mApplyVisibilityFilter; bool mApplyVisibilitySpatialFilter; float mVisibilityFilterWidth; int mPass; bool mStopComputation; bool mExportObj; bool mExportRays; bool mExportAnimation; int mExportNumRays; ofstream mStats; GlRendererBuffer *renderer; int mTotalSamples; int mTotalTime; int mSamplesPerPass; int mSamplesPerEvaluation; RayCaster *mRayCaster; protected: bool LoadBinaryObj(const string &filename, SceneGraphNode *root, vector *parents); bool ExportBinaryObj(const string filename, SceneGraphNode *root); void SetupRay(Ray &ray, const Vector3 &point, const Vector3 &direction) const; void EvalPvsStat(); virtual void EvalViewCellHistogram(); ///////////////////////// GlobalLinesRenderer *mGlobalLinesRenderer; /// samples used for construction of the BSP view cells tree. int mBspConstructionSamples; /// samples used for construction of the VSP OSP tree. int mVspOspConstructionSamples; /// Simulates rendering of the scene. RenderSimulator *mRenderSimulator; vector mFaceParents; /// if box around view space should be used bool mUseViewSpaceBox; PreprocessorThread *mThread; }; extern Preprocessor *preprocessor; } #endif