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

Revision 2736, 9.5 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;
[2625]34class GlRendererWidget;
[2702]35class IntersectableGroup;
[490]36
[1520]37
[372]38/** Namespace for the external visibility preprocessor
39
40    This namespace includes all classes which are created by the VUT (Vienna University
41    of Technology) for the External Visibility Preprocessor of the GTP (GameTools Project)
42    (www.gametools.org).
43*/
44 
[1145]45/** Main class of the visibility preprocessor. Responsible for loading and
46    saving of the input and output files. Initiates construction of the kD-tree,
47    viewcell loading/generation and the visibility computation itself.
48*/
[1521]49class Preprocessor
[1145]50{
[1520]51        friend class RayCaster;
52        friend class IntelRayCaster;
53        friend class InternalRayCaster;
[2575]54        friend class HavranRayCaster;
[1564]55
[372]56public:
57        /** Default constructor initialising e.g., KD tree and BSP tree.
58        */
59        Preprocessor();
60
[1520]61        virtual ~Preprocessor();
[1564]62        /** Load the input scene.
[2187]63                @param filename file to load
64                @return true on success
[1564]65        */
[2342]66        virtual bool LoadScene(const string &filename);
[1564]67        /** Export all preprocessed data in a XML format understandable by the
[2187]68                PreprocessingInterface of the GtpVisibilityPreprocessor Module.
69                The file can be compressed depending on the environement settings.
70                @return true on successful export
[1564]71        */
[2342]72        virtual bool ExportPreprocessedData(const string &filename);
[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();
78        /** Compute visibility method. This method has to be reimplemented by the actual
[2187]79                Preprocessor implementation (e.g. SamplingPreprocessor, ExactPreprocessor,
80                GlobalSamplingpreprocessor)
[1564]81        */
82        virtual bool ComputeVisibility() = 0;
83        /** Post Process the computed visibility. By default applys the visibility filter
[2187]84                (if specified in the environment and export the preprocessed data
[2609]85        */
[1564]86        virtual bool PostProcessVisibility();
87        /** View cells are either loaded or prepared for generation, according to the chosen environment
[2187]88                object. Important evironment options are, e.g, the view cell type.
89                Should be done after scene loading (i.e., some options are based on scene type).
[1564]90        */
91        bool PrepareViewCells();
92        /** Construct viewcells from the scratch
93        */
94        bool ConstructViewCells();
95        /** Returns the specified sample strategy, NULL if no valid strategy.
96        */
[1884]97        SamplingStrategy *GenerateSamplingStrategy(const int strategyId);
[1564]98        /** Export preprocessor data.
99        */
[2342]100        bool Export(const string &filename, const bool scene, const bool kdtree); 
[372]101
[1564]102        virtual void KdTreeStatistics(ostream &s);
103        virtual void BspTreeStatistics(ostream &s);
[490]104
[1564]105        /** Loads samples from file.
106        @param samples returns the stored sample rays
107        @param objects needed to associate the objects ids
108        @returns true if samples were loaded successfully
109        */
[2187]110        bool LoadSamples(VssRayContainer &samples, ObjectContainer &objects) const;
[508]111
[1564]112        /** Exports samples to file.
[2187]113                @returns true if samples were written successfully
[1564]114        */
115        bool ExportSamples(const VssRayContainer &samples) const;
[1197]116
[2342]117        bool LoadKdTree(const string &filename);
118        bool ExportKdTree(const string &filename);
[1381]119
[1926]120        virtual bool
[2001]121        ExportRays(const char *filename,
122                           const VssRayContainer &vssRays,
123                           const int number,
124                           const bool exportScene = false
125                           );
[1926]126
[2048]127        bool ExportRayAnimation(const char *filename,
128                                                        const vector<VssRayContainer> &vssRays);
[2002]129
[2048]130        virtual int     GenerateRays(const int number,
131                                                         SamplingStrategy &strategy,
132                                                         SimpleRayContainer &rays);
[1786]133
[2726]134        virtual int     GenerateRays(const int number,
135                                                         SamplingStrategy &strategy,
136                                                         SimpleRayContainer &rays,
137                                                         int &invalidSamples);
138
[1926]139        virtual int GenerateRays(const int number,
[2048]140                                                         const int raysType,
141                                                         SimpleRayContainer &rays);
[1786]142
[2726]143        bool GenerateJitteredRays(SimpleRayContainer &rayBundle,
144                                                         const SimpleRay &mainRay,
145                                                         int number,
[2736]146                                                         int shuffleType,
147                                                         float scale) 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
[2593]181        /** Sets a preprocessor thread.
[1926]182        */
183        void SetThread(PreprocessorThread *t);
184
[2593]185        /** Returns a preprocessor thread.
[1926]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,
[2593]196                                                        ObjectContainer &pvsObjects,
197                                                        const ObjectContainer &preprocessorObject);
[2048]198
[2609]199        /** Adds dynamic geometry
[2593]200        */
[2694]201        SceneGraphLeaf *LoadDynamicGeometry(const string &filename);
[538]202
[2694]203        /** Register the dynamic object to be handled by the ray caster for visibility
204                computation.
205        */
[2702]206        void RegisterDynamicObject(SceneGraphLeaf *leaf);
[2694]207       
[2715]208        void PrepareObjectsForRayCaster(SceneGraphLeaf *l);
[2709]209       
210        void ScheduleUpdateDynamicObjects();
211        void UpdateDynamicObjects();
212        /** Notify the preprocessor that an object has been deleted
213        */
214        virtual void ObjectRemoved(SceneGraphLeaf *object);
[2609]215
[2720]216        SceneGraphLeaf *GenerateBoxGeometry(const AxisAlignedBox3 &box);
[2694]217
[2720]218        float _HackComputeRenderCost(ViewCell *vc);
[2709]219
[2342]220        /////////////////////////
221
[2709]222        bool mSynchronize;
223
[1564]224        /// scene graph loaded from file
225        SceneGraph *mSceneGraph;
[599]226
[1564]227        /// raw array of objects
228        ObjectContainer mObjects;
[658]229
[1564]230        /// kD-tree organizing the scene graph (occluders + occludees) + viewcells
231        KdTree *mKdTree;
[2609]232        AxisAlignedBox3 sceneBox;
233
[1564]234        /// View space partition bsp tree
235        VspBspTree *mVspBspTree;
236        /// BSP tree representing the viewcells
237        BspTree *mBspTree;
[878]238
[1564]239        /// list of all loaded occluders
240        ObjectContainer mOccluders;
241        /// list of all loaded occludees
242        ObjectContainer mOccludees;
[2609]243        /// the view cells manager
[1564]244        ViewCellsManager *mViewCellsManager;
[2678]245
[2609]246        DynamicObjectsContainer mDynamicObjects;
[2702]247
[1564]248        /// greedy optimized hierarchy for both objects and view cells
249        VspOspTree *mVspOspTree;
250
251        bool mUseGlRenderer;
252        bool mUseGlDebugger;
[2342]253
[2187]254        bool mUseHwGlobalLines;
[1564]255        bool mLoadViewCells;
256
257        bool mDetectEmptyViewSpace;
258
259        bool mQuitOnFinish;
260        bool mLoadMeshes;
261        bool mComputeVisibility;
262
263        bool mExportVisibility;
264        string mVisibilityFileName;
265
266        bool mApplyVisibilityFilter;
267        bool mApplyVisibilitySpatialFilter;
268
269        float mVisibilityFilterWidth;
270
271        int mPass;
[2342]272
[1723]273        bool mStopComputation;
[2342]274
[1695]275        bool mExportObj;
276
[1926]277        bool mExportRays;
[2008]278        bool mExportAnimation;
[1926]279        int mExportNumRays;
[1900]280
[1786]281        ofstream mStats;
[1771]282
[1926]283        GlRendererBuffer *renderer;
[2625]284        GlRendererWidget *mRendererWidget;
[2342]285
[1966]286        int mTotalSamples;
[2580]287        int mCurrentSamples;
288
[2046]289        int mTotalTime;
[1968]290        int mSamplesPerPass;
291        int mSamplesPerEvaluation;
[2580]292 
293        int mTotalRaysCast;
[1966]294
[2342]295        RayCaster *mRayCaster;
[2076]296
[2709]297        // triangle pvs for gvs
[2695]298        // hack: should be in gvspreprocessor but pulled
299        // out here for visualization purpose
300        ObjectContainer mTrianglePvs;
[2636]301
[2709]302        // generic stats vector that can be used for anything
303        int mGenericStats[2];
304
[2695]305        //std::vector<int> mDummyBuffer;
306
307
[492]308protected:
309
[2183]310        bool LoadBinaryObj(const std::string &filename,
[2600]311                       SceneGraphLeaf *root,
[2621]312                                           std::vector<FaceParentInfo> *parents,
313                                           float scale = -1.0f);
[1658]314
[2600]315        bool ExportBinaryObj(const std::string &filename, SceneGraphLeaf *root);
[1658]316
[2575]317        void SetupRay(Ray &ray, const Vector3 &point,
318                      const Vector3 &direction) const;
[1251]319
[1520]320        void EvalPvsStat();
[492]321
[1786]322        virtual void EvalViewCellHistogram();
[1771]323
[2678]324        /** Notify the preprocessor that an object has moved and must be reevaluated.
325        */
[2645]326        virtual void ObjectMoved(SceneGraphLeaf *object);
[2709]327       
[2645]328
329
[1520]330        /////////////////////////
331
[2017]332        GlobalLinesRenderer *mGlobalLinesRenderer;
333
334        /// samples used for construction of the BSP view cells tree.
[1564]335        int mBspConstructionSamples;
336        /// samples used for construction of the VSP OSP tree.
337        int mVspOspConstructionSamples;
[1786]338        /// Simulates rendering of the scene.
[1564]339        RenderSimulator *mRenderSimulator;
[1520]340
[1564]341        vector<FaceParentInfo> mFaceParents;
[492]342
[1723]343        /// if box around view space should be used
344        bool mUseViewSpaceBox;
[1867]345
[1926]346        PreprocessorThread *mThread;
[2636]347
[2695]348        bool mUpdateDynamicObjects;
349
350       
[372]351};
352
[2017]353extern Preprocessor *preprocessor;
[372]354
[860]355}
356
[372]357#endif
Note: See TracBrowser for help on using the repository browser.