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

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