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

Revision 2609, 8.3 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;
33class SceneGraphLeaf;
34
35
36/** Namespace for the external visibility preprocessor
37
38    This namespace includes all classes which are created by the VUT (Vienna University
39    of Technology) for the External Visibility Preprocessor of the GTP (GameTools Project)
40    (www.gametools.org).
41*/
42 
43/** Main class of the visibility preprocessor. Responsible for loading and
44    saving of the input and output files. Initiates construction of the kD-tree,
45    viewcell loading/generation and the visibility computation itself.
46*/
47class Preprocessor
48{
49        friend class RayCaster;
50        friend class IntelRayCaster;
51        friend class InternalRayCaster;
52        friend class HavranRayCaster;
53
54public:
55        /** Default constructor initialising e.g., KD tree and BSP tree.
56        */
57        Preprocessor();
58
59        virtual ~Preprocessor();
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        /** Export all preprocessed data in a XML format understandable by the
66                PreprocessingInterface of the GtpVisibilityPreprocessor Module.
67                The file can be compressed depending on the environement settings.
68                @return true on successful export
69        */
70        virtual bool ExportPreprocessedData(const string &filename);
71        /** Build the KdTree of currently loaded occluders/occludees/viewcells. The construction
72                is driven by the environment settings, which also sais which of the three types of
73                entities should be used to drive the heuristical construction (only occluders by default)
74        */
75        virtual bool BuildKdTree();
76        /** Compute visibility method. This method has to be reimplemented by the actual
77                Preprocessor implementation (e.g. SamplingPreprocessor, ExactPreprocessor,
78                GlobalSamplingpreprocessor)
79        */
80        virtual bool ComputeVisibility() = 0;
81        /** Post Process the computed visibility. By default applys the visibility filter
82                (if specified in the environment and export the preprocessed data
83        */
84        virtual bool PostProcessVisibility();
85        /** View cells are either loaded or prepared for generation, according to the chosen environment
86                object. Important evironment options are, e.g, the view cell type.
87                Should be done after scene loading (i.e., some options are based on scene type).
88        */
89        bool PrepareViewCells();
90        /** Construct viewcells from the scratch
91        */
92        bool ConstructViewCells();
93        /** Returns the specified sample strategy, NULL if no valid strategy.
94        */
95        SamplingStrategy *GenerateSamplingStrategy(const int strategyId);
96        /** Export preprocessor data.
97        */
98        bool Export(const string &filename, const bool scene, const bool kdtree); 
99
100        virtual void KdTreeStatistics(ostream &s);
101        virtual void BspTreeStatistics(ostream &s);
102
103        /** Loads samples from file.
104        @param samples returns the stored sample rays
105        @param objects needed to associate the objects ids
106        @returns true if samples were loaded successfully
107        */
108        bool LoadSamples(VssRayContainer &samples, ObjectContainer &objects) const;
109
110        /** Exports samples to file.
111                @returns true if samples were written successfully
112        */
113        bool ExportSamples(const VssRayContainer &samples) const;
114
115        bool LoadKdTree(const string &filename);
116        bool ExportKdTree(const string &filename);
117
118        virtual bool
119        ExportRays(const char *filename,
120                           const VssRayContainer &vssRays,
121                           const int number,
122                           const bool exportScene = false
123                           );
124
125        bool ExportRayAnimation(const char *filename,
126                                                        const vector<VssRayContainer> &vssRays);
127
128        virtual int     GenerateRays(const int number,
129                                                         SamplingStrategy &strategy,
130                                                         SimpleRayContainer &rays);
131
132        virtual int GenerateRays(const int number,
133                                                         const int raysType,
134                                                         SimpleRayContainer &rays);
135
136        bool GenerateRayBundle(SimpleRayContainer &rayBundle,
137                                                   const SimpleRay &mainRay,
138                                                   const int number,
139                                                   const int shuffleType) const;
140
141        virtual void CastRays(SimpleRayContainer &rays,
142                                                  VssRayContainer &vssRays,
143                                                  const bool castDoubleRays,
144                                                  const bool pruneInvalidRays = true);
145
146        virtual void
147                CastRaysWithHwGlobalLines(
148                SimpleRayContainer &rays,
149                VssRayContainer &vssRays,
150                const bool castDoubleRays,
151                const bool pruneInvalidRays
152                );
153
154        /** Compute pixel error of the current PVS solution by sampling given number of viewpoints.
155        */
156        virtual void ComputeRenderError();
157
158        /** Returns a view cells manager of the given name.
159        */
160        ViewCellsManager *CreateViewCellsManager(const char *name);
161
162        GlRendererBuffer *GetRenderer();
163
164        bool InitRayCast(const string &externKdTree, const string &internKdTree);
165
166        bool LoadInternKdTree(const string &internKdTree);
167
168        bool ExportObj(const string &filename, const ObjectContainer &objects);
169
170        Intersectable *GetParentObject(const int index) const;
171        Vector3 GetParentNormal(const int index) const;
172
173        /** Sets a preprocessor thread.
174        */
175        void SetThread(PreprocessorThread *t);
176
177        /** Returns a preprocessor thread.
178        */
179        PreprocessorThread *GetThread() const;
180
181        Intersectable *GetObjectById(const int id);
182
183        void PrepareHwGlobalLines();
184
185        virtual void DeterminePvsObjects(VssRayContainer &rays);
186
187        static bool LoadObjects(const string &filename,
188                                                        ObjectContainer &pvsObjects,
189                                                        const ObjectContainer &preprocessorObject);
190
191        /** Adds dynamic geometry
192        */
193        bool LoadDynamicGeometry(const string &filename);
194
195        Mesh *Preprocessor::LoadBinaryObjIntoMesh(const string &filename);
196
197
198        /////////////////////////
199
200        /// scene graph loaded from file
201        SceneGraph *mSceneGraph;
202
203        /// raw array of objects
204        ObjectContainer mObjects;
205
206        /// kD-tree organizing the scene graph (occluders + occludees) + viewcells
207        KdTree *mKdTree;
208        AxisAlignedBox3 sceneBox;
209
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        /// the view cells manager
220        ViewCellsManager *mViewCellsManager;
221
222        //SceneGraphNodeContainer mDynamicObjects;
223        DynamicObjectsContainer mDynamicObjects;
224
225        /// greedy optimized hierarchy for both objects and view cells
226        VspOspTree *mVspOspTree;
227
228        bool mUseGlRenderer;
229        bool mUseGlDebugger;
230
231        bool mUseHwGlobalLines;
232        bool mLoadViewCells;
233
234        bool mDetectEmptyViewSpace;
235
236        bool mQuitOnFinish;
237        bool mLoadMeshes;
238        bool mComputeVisibility;
239
240        bool mExportVisibility;
241        string mVisibilityFileName;
242
243        bool mApplyVisibilityFilter;
244        bool mApplyVisibilitySpatialFilter;
245
246        float mVisibilityFilterWidth;
247
248        int mPass;
249
250        bool mStopComputation;
251
252        bool mExportObj;
253
254        bool mExportRays;
255        bool mExportAnimation;
256        int mExportNumRays;
257
258        ofstream mStats;
259
260        GlRendererBuffer *renderer;
261
262        int mTotalSamples;
263        int mCurrentSamples;
264
265        int mTotalTime;
266        int mSamplesPerPass;
267        int mSamplesPerEvaluation;
268 
269        int mTotalRaysCast;
270
271        RayCaster *mRayCaster;
272
273
274protected:
275
276        bool LoadBinaryObj(const std::string &filename,
277                       SceneGraphLeaf *root,
278                                           std::vector<FaceParentInfo> *parents);
279
280        bool ExportBinaryObj(const std::string &filename, SceneGraphLeaf *root);
281
282        void SetupRay(Ray &ray, const Vector3 &point,
283                      const Vector3 &direction) const;
284
285        void EvalPvsStat();
286
287        virtual void EvalViewCellHistogram();
288
289
290        /////////////////////////
291
292        GlobalLinesRenderer *mGlobalLinesRenderer;
293
294        /// samples used for construction of the BSP view cells tree.
295        int mBspConstructionSamples;
296        /// samples used for construction of the VSP OSP tree.
297        int mVspOspConstructionSamples;
298        /// Simulates rendering of the scene.
299        RenderSimulator *mRenderSimulator;
300
301        vector<FaceParentInfo> mFaceParents;
302
303        /// if box around view space should be used
304        bool mUseViewSpaceBox;
305
306        PreprocessorThread *mThread;
307};
308
309extern Preprocessor *preprocessor;
310
311}
312
313#endif
Note: See TracBrowser for help on using the repository browser.