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

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