source: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h @ 2609

Revision 2609, 8.3 KB checked in by mattausch, 16 years ago (diff)
RevLine 
[372]1#ifndef _Preprocessor_H__
2#define _Preprocessor_H__
3
4#include <string>
[2176]5//
[372]6#include "Containers.h"
7#include "Mesh.h"
8#include "KdTree.h"
[2105]9#include "SimpleRay.h"
[372]10
[2342]11
[860]12namespace GtpVisibilityPreprocessor {
[2342]13
14class PreprocessorThread; 
[409]15class RenderSimulator;
[372]16class SceneGraph;
[429]17class Exporter;
[439]18class ViewCellsManager;
[445]19class BspTree;
[1006]20class VspOspTree;
[445]21class VspBspTree;
[468]22class RenderSimulator;
[490]23struct VssRayContainer;
[1020]24class SamplingStrategy;
[496]25class GlRendererBuffer;
[1022]26class VspTree;
[1279]27class HierarchyManager;
[1264]28class BvHierarchy;
[1221]29class Intersectable;
[1287]30class VssRay;
[1520]31class RayCaster;
[1968]32class GlobalLinesRenderer;
[2600]33class SceneGraphLeaf;
[490]34
[1520]35
[372]36/** Namespace for the external visibility preprocessor
37
38    This namespace includes all classes which are created by the VUT (Vienna University
39    of Technology) for the External Visibility Preprocessor of the GTP (GameTools Project)
40    (www.gametools.org).
41*/
42 
[1145]43/** Main class of the visibility preprocessor. Responsible for loading and
44    saving of the input and output files. Initiates construction of the kD-tree,
45    viewcell loading/generation and the visibility computation itself.
46*/
[1521]47class Preprocessor
[1145]48{
[1520]49        friend class RayCaster;
50        friend class IntelRayCaster;
51        friend class InternalRayCaster;
[2575]52        friend class HavranRayCaster;
[1564]53
[372]54public:
55        /** Default constructor initialising e.g., KD tree and BSP tree.
56        */
57        Preprocessor();
58
[1520]59        virtual ~Preprocessor();
[1564]60        /** Load the input scene.
[2187]61                @param filename file to load
62                @return true on success
[1564]63        */
[2342]64        virtual bool LoadScene(const string &filename);
[1564]65        /** Export all preprocessed data in a XML format understandable by the
[2187]66                PreprocessingInterface of the GtpVisibilityPreprocessor Module.
67                The file can be compressed depending on the environement settings.
68                @return true on successful export
[1564]69        */
[2342]70        virtual bool ExportPreprocessedData(const string &filename);
[1564]71        /** Build the KdTree of currently loaded occluders/occludees/viewcells. The construction
[2187]72                is driven by the environment settings, which also sais which of the three types of
73                entities should be used to drive the heuristical construction (only occluders by default)
[1564]74        */
75        virtual bool BuildKdTree();
76        /** Compute visibility method. This method has to be reimplemented by the actual
[2187]77                Preprocessor implementation (e.g. SamplingPreprocessor, ExactPreprocessor,
78                GlobalSamplingpreprocessor)
[1564]79        */
80        virtual bool ComputeVisibility() = 0;
81        /** Post Process the computed visibility. By default applys the visibility filter
[2187]82                (if specified in the environment and export the preprocessed data
[2609]83        */
[1564]84        virtual bool PostProcessVisibility();
85        /** View cells are either loaded or prepared for generation, according to the chosen environment
[2187]86                object. Important evironment options are, e.g, the view cell type.
87                Should be done after scene loading (i.e., some options are based on scene type).
[1564]88        */
89        bool PrepareViewCells();
90        /** Construct viewcells from the scratch
91        */
92        bool ConstructViewCells();
93        /** Returns the specified sample strategy, NULL if no valid strategy.
94        */
[1884]95        SamplingStrategy *GenerateSamplingStrategy(const int strategyId);
[1564]96        /** Export preprocessor data.
97        */
[2342]98        bool Export(const string &filename, const bool scene, const bool kdtree); 
[372]99
[1564]100        virtual void KdTreeStatistics(ostream &s);
101        virtual void BspTreeStatistics(ostream &s);
[490]102
[1564]103        /** Loads samples from file.
104        @param samples returns the stored sample rays
105        @param objects needed to associate the objects ids
106        @returns true if samples were loaded successfully
107        */
[2187]108        bool LoadSamples(VssRayContainer &samples, ObjectContainer &objects) const;
[508]109
[1564]110        /** Exports samples to file.
[2187]111                @returns true if samples were written successfully
[1564]112        */
113        bool ExportSamples(const VssRayContainer &samples) const;
[1197]114
[2342]115        bool LoadKdTree(const string &filename);
116        bool ExportKdTree(const string &filename);
[1381]117
[1926]118        virtual bool
[2001]119        ExportRays(const char *filename,
120                           const VssRayContainer &vssRays,
121                           const int number,
122                           const bool exportScene = false
123                           );
[1926]124
[2048]125        bool ExportRayAnimation(const char *filename,
126                                                        const vector<VssRayContainer> &vssRays);
[2002]127
[2048]128        virtual int     GenerateRays(const int number,
129                                                         SamplingStrategy &strategy,
130                                                         SimpleRayContainer &rays);
[1786]131
[1926]132        virtual int GenerateRays(const int number,
[2048]133                                                         const int raysType,
134                                                         SimpleRayContainer &rays);
[1786]135
136        bool GenerateRayBundle(SimpleRayContainer &rayBundle,
[2048]137                                                   const SimpleRay &mainRay,
138                                                   const int number,
139                                                   const int shuffleType) const;
[1786]140
141        virtual void CastRays(SimpleRayContainer &rays,
[1932]142                                                  VssRayContainer &vssRays,
143                                                  const bool castDoubleRays,
[1996]144                                                  const bool pruneInvalidRays = true);
[1786]145
[2342]146        virtual void
147                CastRaysWithHwGlobalLines(
148                SimpleRayContainer &rays,
149                VssRayContainer &vssRays,
150                const bool castDoubleRays,
151                const bool pruneInvalidRays
152                );
[2076]153
[2187]154        /** Compute pixel error of the current PVS solution by sampling given number of viewpoints.
[2048]155        */
[1958]156        virtual void ComputeRenderError();
[1931]157
[1564]158        /** Returns a view cells manager of the given name.
159        */
160        ViewCellsManager *CreateViewCellsManager(const char *name);
[1221]161
[1564]162        GlRendererBuffer *GetRenderer();
[492]163
[2342]164        bool InitRayCast(const string &externKdTree, const string &internKdTree);
[409]165
[2342]166        bool LoadInternKdTree(const string &internKdTree);
[2003]167
[2342]168        bool ExportObj(const string &filename, const ObjectContainer &objects);
[429]169
[1786]170        Intersectable *GetParentObject(const int index) const;
[1926]171        Vector3 GetParentNormal(const int index) const;
172
[2593]173        /** Sets a preprocessor thread.
[1926]174        */
175        void SetThread(PreprocessorThread *t);
176
[2593]177        /** Returns a preprocessor thread.
[1926]178        */
179        PreprocessorThread *GetThread() const;
180
[1958]181        Intersectable *GetObjectById(const int id);
[1926]182
[1968]183        void PrepareHwGlobalLines();
[2048]184
185        virtual void DeterminePvsObjects(VssRayContainer &rays);
186
[2115]187        static bool LoadObjects(const string &filename,
[2593]188                                                        ObjectContainer &pvsObjects,
189                                                        const ObjectContainer &preprocessorObject);
[2048]190
[2609]191        /** Adds dynamic geometry
[2593]192        */
[2609]193        bool LoadDynamicGeometry(const string &filename);
[538]194
[2609]195        Mesh *Preprocessor::LoadBinaryObjIntoMesh(const string &filename);
196
197
[2342]198        /////////////////////////
199
[1564]200        /// scene graph loaded from file
201        SceneGraph *mSceneGraph;
[599]202
[1564]203        /// raw array of objects
204        ObjectContainer mObjects;
[658]205
[1564]206        /// kD-tree organizing the scene graph (occluders + occludees) + viewcells
207        KdTree *mKdTree;
[2609]208        AxisAlignedBox3 sceneBox;
209
[1564]210        /// View space partition bsp tree
211        VspBspTree *mVspBspTree;
212        /// BSP tree representing the viewcells
213        BspTree *mBspTree;
[878]214
[1564]215        /// list of all loaded occluders
216        ObjectContainer mOccluders;
217        /// list of all loaded occludees
218        ObjectContainer mOccludees;
[2609]219        /// the view cells manager
[1564]220        ViewCellsManager *mViewCellsManager;
221
[2609]222        //SceneGraphNodeContainer mDynamicObjects;
223        DynamicObjectsContainer mDynamicObjects;
224
[1564]225        /// greedy optimized hierarchy for both objects and view cells
226        VspOspTree *mVspOspTree;
227
228        bool mUseGlRenderer;
229        bool mUseGlDebugger;
[2342]230
[2187]231        bool mUseHwGlobalLines;
[1564]232        bool mLoadViewCells;
233
234        bool mDetectEmptyViewSpace;
235
236        bool mQuitOnFinish;
237        bool mLoadMeshes;
238        bool mComputeVisibility;
239
240        bool mExportVisibility;
241        string mVisibilityFileName;
242
243        bool mApplyVisibilityFilter;
244        bool mApplyVisibilitySpatialFilter;
245
246        float mVisibilityFilterWidth;
247
248        int mPass;
[2342]249
[1723]250        bool mStopComputation;
[2342]251
[1695]252        bool mExportObj;
253
[1926]254        bool mExportRays;
[2008]255        bool mExportAnimation;
[1926]256        int mExportNumRays;
[1900]257
[1786]258        ofstream mStats;
[1771]259
[1926]260        GlRendererBuffer *renderer;
[2342]261
[1966]262        int mTotalSamples;
[2580]263        int mCurrentSamples;
264
[2046]265        int mTotalTime;
[1968]266        int mSamplesPerPass;
267        int mSamplesPerEvaluation;
[2580]268 
269        int mTotalRaysCast;
[1966]270
[2342]271        RayCaster *mRayCaster;
[2076]272
[2187]273
[492]274protected:
275
[2183]276        bool LoadBinaryObj(const std::string &filename,
[2600]277                       SceneGraphLeaf *root,
[2183]278                                           std::vector<FaceParentInfo> *parents);
[1658]279
[2600]280        bool ExportBinaryObj(const std::string &filename, SceneGraphLeaf *root);
[1658]281
[2575]282        void SetupRay(Ray &ray, const Vector3 &point,
283                      const Vector3 &direction) const;
[1251]284
[1520]285        void EvalPvsStat();
[492]286
[1786]287        virtual void EvalViewCellHistogram();
[1771]288
[2342]289
[1520]290        /////////////////////////
291
[2017]292        GlobalLinesRenderer *mGlobalLinesRenderer;
293
294        /// samples used for construction of the BSP view cells tree.
[1564]295        int mBspConstructionSamples;
296        /// samples used for construction of the VSP OSP tree.
297        int mVspOspConstructionSamples;
[1786]298        /// Simulates rendering of the scene.
[1564]299        RenderSimulator *mRenderSimulator;
[1520]300
[1564]301        vector<FaceParentInfo> mFaceParents;
[492]302
[1723]303        /// if box around view space should be used
304        bool mUseViewSpaceBox;
[1867]305
[1926]306        PreprocessorThread *mThread;
[372]307};
308
[2017]309extern Preprocessor *preprocessor;
[372]310
[860]311}
312
[372]313#endif
Note: See TracBrowser for help on using the repository browser.