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

Revision 2736, 9.5 KB checked in by mattausch, 16 years ago (diff)
Line 
1#ifndef _Preprocessor_H__
2#define _Preprocessor_H__
3
4#include <string>
5//
6#include "Containers.h"
7#include "Mesh.h"
8#include "KdTree.h"
9#include "SimpleRay.h"
10
11
12namespace GtpVisibilityPreprocessor {
13
14class PreprocessorThread; 
15class RenderSimulator;
16class SceneGraph;
17class Exporter;
18class ViewCellsManager;
19class BspTree;
20class VspOspTree;
21class VspBspTree;
22class RenderSimulator;
23struct VssRayContainer;
24class SamplingStrategy;
25class GlRendererBuffer;
26class VspTree;
27class HierarchyManager;
28class BvHierarchy;
29class Intersectable;
30class VssRay;
31class RayCaster;
32class GlobalLinesRenderer;
33class SceneGraphLeaf;
34class GlRendererWidget;
35class IntersectableGroup;
36
37
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 
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*/
49class Preprocessor
50{
51        friend class RayCaster;
52        friend class IntelRayCaster;
53        friend class InternalRayCaster;
54        friend class HavranRayCaster;
55
56public:
57        /** Default constructor initialising e.g., KD tree and BSP tree.
58        */
59        Preprocessor();
60
61        virtual ~Preprocessor();
62        /** Load the input scene.
63                @param filename file to load
64                @return true on success
65        */
66        virtual bool LoadScene(const string &filename);
67        /** Export all preprocessed data in a XML format understandable by the
68                PreprocessingInterface of the GtpVisibilityPreprocessor Module.
69                The file can be compressed depending on the environement settings.
70                @return true on successful export
71        */
72        virtual bool ExportPreprocessedData(const string &filename);
73        /** Build the KdTree of currently loaded occluders/occludees/viewcells. The construction
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)
76        */
77        virtual bool BuildKdTree();
78        /** Compute visibility method. This method has to be reimplemented by the actual
79                Preprocessor implementation (e.g. SamplingPreprocessor, ExactPreprocessor,
80                GlobalSamplingpreprocessor)
81        */
82        virtual bool ComputeVisibility() = 0;
83        /** Post Process the computed visibility. By default applys the visibility filter
84                (if specified in the environment and export the preprocessed data
85        */
86        virtual bool PostProcessVisibility();
87        /** View cells are either loaded or prepared for generation, according to the chosen environment
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).
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        */
97        SamplingStrategy *GenerateSamplingStrategy(const int strategyId);
98        /** Export preprocessor data.
99        */
100        bool Export(const string &filename, const bool scene, const bool kdtree); 
101
102        virtual void KdTreeStatistics(ostream &s);
103        virtual void BspTreeStatistics(ostream &s);
104
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        */
110        bool LoadSamples(VssRayContainer &samples, ObjectContainer &objects) const;
111
112        /** Exports samples to file.
113                @returns true if samples were written successfully
114        */
115        bool ExportSamples(const VssRayContainer &samples) const;
116
117        bool LoadKdTree(const string &filename);
118        bool ExportKdTree(const string &filename);
119
120        virtual bool
121        ExportRays(const char *filename,
122                           const VssRayContainer &vssRays,
123                           const int number,
124                           const bool exportScene = false
125                           );
126
127        bool ExportRayAnimation(const char *filename,
128                                                        const vector<VssRayContainer> &vssRays);
129
130        virtual int     GenerateRays(const int number,
131                                                         SamplingStrategy &strategy,
132                                                         SimpleRayContainer &rays);
133
134        virtual int     GenerateRays(const int number,
135                                                         SamplingStrategy &strategy,
136                                                         SimpleRayContainer &rays,
137                                                         int &invalidSamples);
138
139        virtual int GenerateRays(const int number,
140                                                         const int raysType,
141                                                         SimpleRayContainer &rays);
142
143        bool GenerateJitteredRays(SimpleRayContainer &rayBundle,
144                                                         const SimpleRay &mainRay,
145                                                         int number,
146                                                         int shuffleType,
147                                                         float scale) const;
148
149        virtual void CastRays(SimpleRayContainer &rays,
150                                                  VssRayContainer &vssRays,
151                                                  const bool castDoubleRays,
152                                                  const bool pruneInvalidRays = true);
153
154        virtual void
155                CastRaysWithHwGlobalLines(
156                SimpleRayContainer &rays,
157                VssRayContainer &vssRays,
158                const bool castDoubleRays,
159                const bool pruneInvalidRays
160                );
161
162        /** Compute pixel error of the current PVS solution by sampling given number of viewpoints.
163        */
164        virtual void ComputeRenderError();
165
166        /** Returns a view cells manager of the given name.
167        */
168        ViewCellsManager *CreateViewCellsManager(const char *name);
169
170        GlRendererBuffer *GetRenderer();
171
172        bool InitRayCast(const string &externKdTree, const string &internKdTree);
173
174        bool LoadInternKdTree(const string &internKdTree);
175
176        bool ExportObj(const string &filename, const ObjectContainer &objects);
177
178        Intersectable *GetParentObject(const int index) const;
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
189        Intersectable *GetObjectById(const int id);
190
191        void PrepareHwGlobalLines();
192
193        virtual void DeterminePvsObjects(VssRayContainer &rays);
194
195        static bool LoadObjects(const string &filename,
196                                                        ObjectContainer &pvsObjects,
197                                                        const ObjectContainer &preprocessorObject);
198
199        /** Adds dynamic geometry
200        */
201        SceneGraphLeaf *LoadDynamicGeometry(const string &filename);
202
203        /** Register the dynamic object to be handled by the ray caster for visibility
204                computation.
205        */
206        void RegisterDynamicObject(SceneGraphLeaf *leaf);
207       
208        void PrepareObjectsForRayCaster(SceneGraphLeaf *l);
209       
210        void ScheduleUpdateDynamicObjects();
211        void UpdateDynamicObjects();
212        /** Notify the preprocessor that an object has been deleted
213        */
214        virtual void ObjectRemoved(SceneGraphLeaf *object);
215
216        SceneGraphLeaf *GenerateBoxGeometry(const AxisAlignedBox3 &box);
217
218        float _HackComputeRenderCost(ViewCell *vc);
219
220        /////////////////////////
221
222        bool mSynchronize;
223
224        /// scene graph loaded from file
225        SceneGraph *mSceneGraph;
226
227        /// raw array of objects
228        ObjectContainer mObjects;
229
230        /// kD-tree organizing the scene graph (occluders + occludees) + viewcells
231        KdTree *mKdTree;
232        AxisAlignedBox3 sceneBox;
233
234        /// View space partition bsp tree
235        VspBspTree *mVspBspTree;
236        /// BSP tree representing the viewcells
237        BspTree *mBspTree;
238
239        /// list of all loaded occluders
240        ObjectContainer mOccluders;
241        /// list of all loaded occludees
242        ObjectContainer mOccludees;
243        /// the view cells manager
244        ViewCellsManager *mViewCellsManager;
245
246        DynamicObjectsContainer mDynamicObjects;
247
248        /// greedy optimized hierarchy for both objects and view cells
249        VspOspTree *mVspOspTree;
250
251        bool mUseGlRenderer;
252        bool mUseGlDebugger;
253
254        bool mUseHwGlobalLines;
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;
272
273        bool mStopComputation;
274
275        bool mExportObj;
276
277        bool mExportRays;
278        bool mExportAnimation;
279        int mExportNumRays;
280
281        ofstream mStats;
282
283        GlRendererBuffer *renderer;
284        GlRendererWidget *mRendererWidget;
285
286        int mTotalSamples;
287        int mCurrentSamples;
288
289        int mTotalTime;
290        int mSamplesPerPass;
291        int mSamplesPerEvaluation;
292 
293        int mTotalRaysCast;
294
295        RayCaster *mRayCaster;
296
297        // triangle pvs for gvs
298        // hack: should be in gvspreprocessor but pulled
299        // out here for visualization purpose
300        ObjectContainer mTrianglePvs;
301
302        // generic stats vector that can be used for anything
303        int mGenericStats[2];
304
305        //std::vector<int> mDummyBuffer;
306
307
308protected:
309
310        bool LoadBinaryObj(const std::string &filename,
311                       SceneGraphLeaf *root,
312                                           std::vector<FaceParentInfo> *parents,
313                                           float scale = -1.0f);
314
315        bool ExportBinaryObj(const std::string &filename, SceneGraphLeaf *root);
316
317        void SetupRay(Ray &ray, const Vector3 &point,
318                      const Vector3 &direction) const;
319
320        void EvalPvsStat();
321
322        virtual void EvalViewCellHistogram();
323
324        /** Notify the preprocessor that an object has moved and must be reevaluated.
325        */
326        virtual void ObjectMoved(SceneGraphLeaf *object);
327       
328
329
330        /////////////////////////
331
332        GlobalLinesRenderer *mGlobalLinesRenderer;
333
334        /// samples used for construction of the BSP view cells tree.
335        int mBspConstructionSamples;
336        /// samples used for construction of the VSP OSP tree.
337        int mVspOspConstructionSamples;
338        /// Simulates rendering of the scene.
339        RenderSimulator *mRenderSimulator;
340
341        vector<FaceParentInfo> mFaceParents;
342
343        /// if box around view space should be used
344        bool mUseViewSpaceBox;
345
346        PreprocessorThread *mThread;
347
348        bool mUpdateDynamicObjects;
349
350       
351};
352
353extern Preprocessor *preprocessor;
354
355}
356
357#endif
Note: See TracBrowser for help on using the repository browser.