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

Revision 2593, 8.2 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;
33
34
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 
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*/
46class Preprocessor
47{
48        friend class RayCaster;
49        friend class IntelRayCaster;
50        friend class InternalRayCaster;
51        friend class HavranRayCaster;
52
53public:
54        /** Default constructor initialising e.g., KD tree and BSP tree.
55        */
56        Preprocessor();
57
58        virtual ~Preprocessor();
59
60        /** Load the input scene.
61                @param filename file to load
62                @return true on success
63        */
64        virtual bool LoadScene(const string &filename);
65
66        /** Export all preprocessed data in a XML format understandable by the
67                PreprocessingInterface of the GtpVisibilityPreprocessor Module.
68                The file can be compressed depending on the environement settings.
69                @return true on successful export
70        */
71        virtual bool ExportPreprocessedData(const string &filename);
72
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
79        /** Compute visibility method. This method has to be reimplemented by the actual
80                Preprocessor implementation (e.g. SamplingPreprocessor, ExactPreprocessor,
81                GlobalSamplingpreprocessor)
82        */
83        virtual bool ComputeVisibility() = 0;
84
85        /** Post Process the computed visibility. By default applys the visibility filter
86                (if specified in the environment and export the preprocessed data
87                */
88        virtual bool PostProcessVisibility();
89
90        /** View cells are either loaded or prepared for generation, according to the chosen environment
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).
93        */
94        bool PrepareViewCells();
95
96        /** Construct viewcells from the scratch
97        */
98        bool ConstructViewCells();
99
100        /** Returns the specified sample strategy, NULL if no valid strategy.
101        */
102        SamplingStrategy *GenerateSamplingStrategy(const int strategyId);
103
104        /** Export preprocessor data.
105        */
106        bool Export(const string &filename, const bool scene, const bool kdtree); 
107
108        virtual void KdTreeStatistics(ostream &s);
109        virtual void BspTreeStatistics(ostream &s);
110
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        */
116        bool LoadSamples(VssRayContainer &samples, ObjectContainer &objects) const;
117
118        /** Exports samples to file.
119                @returns true if samples were written successfully
120        */
121        bool ExportSamples(const VssRayContainer &samples) const;
122
123        bool LoadKdTree(const string &filename);
124        bool ExportKdTree(const string &filename);
125
126        virtual bool
127        ExportRays(const char *filename,
128                           const VssRayContainer &vssRays,
129                           const int number,
130                           const bool exportScene = false
131                           );
132
133        bool ExportRayAnimation(const char *filename,
134                                                        const vector<VssRayContainer> &vssRays);
135
136        virtual int     GenerateRays(const int number,
137                                                         SamplingStrategy &strategy,
138                                                         SimpleRayContainer &rays);
139
140        virtual int GenerateRays(const int number,
141                                                         const int raysType,
142                                                         SimpleRayContainer &rays);
143
144        bool GenerateRayBundle(SimpleRayContainer &rayBundle,
145                                                   const SimpleRay &mainRay,
146                                                   const int number,
147                                                   const int shuffleType) 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 new geometry to the existing one.
200        */
201        bool AddGeometry(const string &filename, ObjectContainer &pvsObjects, const ObjectContainer &prepObjects);
202
203        /////////////////////////
204
205        /// scene graph loaded from file
206        SceneGraph *mSceneGraph;
207
208        /// raw array of objects
209        ObjectContainer mObjects;
210
211        /// kD-tree organizing the scene graph (occluders + occludees) + viewcells
212        KdTree *mKdTree;
213  AxisAlignedBox3 sceneBox;
214        /// View space partition bsp tree
215        VspBspTree *mVspBspTree;
216        /// BSP tree representing the viewcells
217        BspTree *mBspTree;
218
219        /// list of all loaded occluders
220        ObjectContainer mOccluders;
221        /// list of all loaded occludees
222        ObjectContainer mOccludees;
223
224
225        ViewCellsManager *mViewCellsManager;
226
227        /// greedy optimized hierarchy for both objects and view cells
228        VspOspTree *mVspOspTree;
229
230        bool mUseGlRenderer;
231        bool mUseGlDebugger;
232
233        bool mUseHwGlobalLines;
234        bool mLoadViewCells;
235
236        bool mDetectEmptyViewSpace;
237
238        bool mQuitOnFinish;
239        bool mLoadMeshes;
240        bool mComputeVisibility;
241
242        bool mExportVisibility;
243        string mVisibilityFileName;
244
245        bool mApplyVisibilityFilter;
246        bool mApplyVisibilitySpatialFilter;
247
248        float mVisibilityFilterWidth;
249
250        int mPass;
251
252        bool mStopComputation;
253
254        bool mExportObj;
255
256        bool mExportRays;
257        bool mExportAnimation;
258        int mExportNumRays;
259
260        ofstream mStats;
261
262        GlRendererBuffer *renderer;
263
264        int mTotalSamples;
265        int mCurrentSamples;
266
267        int mTotalTime;
268        int mSamplesPerPass;
269        int mSamplesPerEvaluation;
270 
271        int mTotalRaysCast;
272
273        RayCaster *mRayCaster;
274
275
276protected:
277
278        bool LoadBinaryObj(const std::string &filename,
279                       SceneGraphNode *root,
280                                           std::vector<FaceParentInfo> *parents);
281
282        bool ExportBinaryObj(const std::string &filename, SceneGraphNode *root);
283
284        void SetupRay(Ray &ray, const Vector3 &point,
285                      const Vector3 &direction) const;
286
287        void EvalPvsStat();
288
289        virtual void EvalViewCellHistogram();
290
291
292        /////////////////////////
293
294        GlobalLinesRenderer *mGlobalLinesRenderer;
295
296        /// samples used for construction of the BSP view cells tree.
297        int mBspConstructionSamples;
298        /// samples used for construction of the VSP OSP tree.
299        int mVspOspConstructionSamples;
300        /// Simulates rendering of the scene.
301        RenderSimulator *mRenderSimulator;
302
303        vector<FaceParentInfo> mFaceParents;
304
305        /// if box around view space should be used
306        bool mUseViewSpaceBox;
307
308        PreprocessorThread *mThread;
309};
310
311extern Preprocessor *preprocessor;
312
313}
314
315#endif
Note: See TracBrowser for help on using the repository browser.