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

Revision 2702, 9.0 KB checked in by mattausch, 16 years ago (diff)

implemented dynamic object placement / removal

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