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

Revision 2726, 9.5 KB checked in by mattausch, 17 years ago (diff)

worked on gvs efficiency

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) const;
147
148        virtual void CastRays(SimpleRayContainer &rays,
149                                                  VssRayContainer &vssRays,
150                                                  const bool castDoubleRays,
151                                                  const bool pruneInvalidRays = true);
152
153        virtual void
154                CastRaysWithHwGlobalLines(
155                SimpleRayContainer &rays,
156                VssRayContainer &vssRays,
157                const bool castDoubleRays,
158                const bool pruneInvalidRays
159                );
160
161        /** Compute pixel error of the current PVS solution by sampling given number of viewpoints.
162        */
163        virtual void ComputeRenderError();
164
165        /** Returns a view cells manager of the given name.
166        */
167        ViewCellsManager *CreateViewCellsManager(const char *name);
168
169        GlRendererBuffer *GetRenderer();
170
171        bool InitRayCast(const string &externKdTree, const string &internKdTree);
172
173        bool LoadInternKdTree(const string &internKdTree);
174
175        bool ExportObj(const string &filename, const ObjectContainer &objects);
176
177        Intersectable *GetParentObject(const int index) const;
178        Vector3 GetParentNormal(const int index) const;
179
180        /** Sets a preprocessor thread.
181        */
182        void SetThread(PreprocessorThread *t);
183
184        /** Returns a preprocessor thread.
185        */
186        PreprocessorThread *GetThread() const;
187
188        Intersectable *GetObjectById(const int id);
189
190        void PrepareHwGlobalLines();
191
192        virtual void DeterminePvsObjects(VssRayContainer &rays);
193
194        static bool LoadObjects(const string &filename,
195                                                        ObjectContainer &pvsObjects,
196                                                        const ObjectContainer &preprocessorObject);
197
198        /** Adds dynamic geometry
199        */
200        SceneGraphLeaf *LoadDynamicGeometry(const string &filename);
201
202        /** Register the dynamic object to be handled by the ray caster for visibility
203                computation.
204        */
205        void RegisterDynamicObject(SceneGraphLeaf *leaf);
206       
207        void PrepareObjectsForRayCaster(SceneGraphLeaf *l);
208       
209        void ScheduleUpdateDynamicObjects();
210        void UpdateDynamicObjects();
211        /** Notify the preprocessor that an object has been deleted
212        */
213        virtual void ObjectRemoved(SceneGraphLeaf *object);
214
215        SceneGraphLeaf *GenerateBoxGeometry(const AxisAlignedBox3 &box);
216
217        float _HackComputeRenderCost(ViewCell *vc);
218
219        /////////////////////////
220
221        bool mSynchronize;
222
223        /// scene graph loaded from file
224        SceneGraph *mSceneGraph;
225
226        /// raw array of objects
227        ObjectContainer mObjects;
228
229        /// kD-tree organizing the scene graph (occluders + occludees) + viewcells
230        KdTree *mKdTree;
231        AxisAlignedBox3 sceneBox;
232
233        /// View space partition bsp tree
234        VspBspTree *mVspBspTree;
235        /// BSP tree representing the viewcells
236        BspTree *mBspTree;
237
238        /// list of all loaded occluders
239        ObjectContainer mOccluders;
240        /// list of all loaded occludees
241        ObjectContainer mOccludees;
242        /// the view cells manager
243        ViewCellsManager *mViewCellsManager;
244
245        DynamicObjectsContainer mDynamicObjects;
246
247        /// greedy optimized hierarchy for both objects and view cells
248        VspOspTree *mVspOspTree;
249
250        bool mUseGlRenderer;
251        bool mUseGlDebugger;
252
253        bool mUseHwGlobalLines;
254        bool mLoadViewCells;
255
256        bool mDetectEmptyViewSpace;
257
258        bool mQuitOnFinish;
259        bool mLoadMeshes;
260        bool mComputeVisibility;
261
262        bool mExportVisibility;
263        string mVisibilityFileName;
264
265        bool mApplyVisibilityFilter;
266        bool mApplyVisibilitySpatialFilter;
267
268        float mVisibilityFilterWidth;
269
270        int mPass;
271
272        bool mStopComputation;
273
274        bool mExportObj;
275
276        bool mExportRays;
277        bool mExportAnimation;
278        int mExportNumRays;
279
280        ofstream mStats;
281
282        GlRendererBuffer *renderer;
283        GlRendererWidget *mRendererWidget;
284
285        int mTotalSamples;
286        int mCurrentSamples;
287
288        int mTotalTime;
289        int mSamplesPerPass;
290        int mSamplesPerEvaluation;
291 
292        int mTotalRaysCast;
293
294        RayCaster *mRayCaster;
295
296        // triangle pvs for gvs
297        // hack: should be in gvspreprocessor but pulled
298        // out here for visualization purpose
299        ObjectContainer mTrianglePvs;
300
301        // generic stats vector that can be used for anything
302        int mGenericStats[2];
303
304        //std::vector<int> mDummyBuffer;
305
306
307protected:
308
309        bool LoadBinaryObj(const std::string &filename,
310                       SceneGraphLeaf *root,
311                                           std::vector<FaceParentInfo> *parents,
312                                           float scale = -1.0f);
313
314        bool ExportBinaryObj(const std::string &filename, SceneGraphLeaf *root);
315
316        void SetupRay(Ray &ray, const Vector3 &point,
317                      const Vector3 &direction) const;
318
319        void EvalPvsStat();
320
321        virtual void EvalViewCellHistogram();
322
323        /** Notify the preprocessor that an object has moved and must be reevaluated.
324        */
325        virtual void ObjectMoved(SceneGraphLeaf *object);
326       
327
328
329        /////////////////////////
330
331        GlobalLinesRenderer *mGlobalLinesRenderer;
332
333        /// samples used for construction of the BSP view cells tree.
334        int mBspConstructionSamples;
335        /// samples used for construction of the VSP OSP tree.
336        int mVspOspConstructionSamples;
337        /// Simulates rendering of the scene.
338        RenderSimulator *mRenderSimulator;
339
340        vector<FaceParentInfo> mFaceParents;
341
342        /// if box around view space should be used
343        bool mUseViewSpaceBox;
344
345        PreprocessorThread *mThread;
346
347        bool mUpdateDynamicObjects;
348
349       
350};
351
352extern Preprocessor *preprocessor;
353
354}
355
356#endif
Note: See TracBrowser for help on using the repository browser.