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

Revision 2588, 8.1 KB checked in by bittner, 16 years ago (diff)

sceneBox bugfix

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
200        /////////////////////////
201
202        /// scene graph loaded from file
203        SceneGraph *mSceneGraph;
204
205        /// raw array of objects
206        ObjectContainer mObjects;
207
208        /// kD-tree organizing the scene graph (occluders + occludees) + viewcells
209        KdTree *mKdTree;
210  AxisAlignedBox3 sceneBox;
211        /// View space partition bsp tree
212        VspBspTree *mVspBspTree;
213        /// BSP tree representing the viewcells
214        BspTree *mBspTree;
215
216        /// list of all loaded occluders
217        ObjectContainer mOccluders;
218        /// list of all loaded occludees
219        ObjectContainer mOccludees;
220
221
222        ViewCellsManager *mViewCellsManager;
223
224        /// greedy optimized hierarchy for both objects and view cells
225        VspOspTree *mVspOspTree;
226
227        bool mUseGlRenderer;
228        bool mUseGlDebugger;
229
230        bool mUseHwGlobalLines;
231        bool mLoadViewCells;
232
233        bool mDetectEmptyViewSpace;
234
235        bool mQuitOnFinish;
236        bool mLoadMeshes;
237        bool mComputeVisibility;
238
239        bool mExportVisibility;
240        string mVisibilityFileName;
241
242        bool mApplyVisibilityFilter;
243        bool mApplyVisibilitySpatialFilter;
244
245        float mVisibilityFilterWidth;
246
247        int mPass;
248
249        bool mStopComputation;
250
251        bool mExportObj;
252
253        bool mExportRays;
254        bool mExportAnimation;
255        int mExportNumRays;
256
257        ofstream mStats;
258
259        GlRendererBuffer *renderer;
260
261        int mTotalSamples;
262        int mCurrentSamples;
263
264        int mTotalTime;
265        int mSamplesPerPass;
266        int mSamplesPerEvaluation;
267 
268        int mTotalRaysCast;
269
270        RayCaster *mRayCaster;
271
272
273protected:
274
275        bool LoadBinaryObj(const std::string &filename,
276                       SceneGraphNode *root,
277                                           std::vector<FaceParentInfo> *parents);
278
279        bool ExportBinaryObj(const std::string &filename, SceneGraphNode *root);
280
281        void SetupRay(Ray &ray, const Vector3 &point,
282                      const Vector3 &direction) const;
283
284        void EvalPvsStat();
285
286        virtual void EvalViewCellHistogram();
287
288
289        /////////////////////////
290
291        GlobalLinesRenderer *mGlobalLinesRenderer;
292
293        /// samples used for construction of the BSP view cells tree.
294        int mBspConstructionSamples;
295        /// samples used for construction of the VSP OSP tree.
296        int mVspOspConstructionSamples;
297        /// Simulates rendering of the scene.
298        RenderSimulator *mRenderSimulator;
299
300        vector<FaceParentInfo> mFaceParents;
301
302        /// if box around view space should be used
303        bool mUseViewSpaceBox;
304
305        PreprocessorThread *mThread;
306};
307
308extern Preprocessor *preprocessor;
309
310}
311
312#endif
Note: See TracBrowser for help on using the repository browser.