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

Revision 2615, 8.3 KB checked in by mattausch, 16 years ago (diff)

did some stuff for the visualization

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#if DYNAMIC_OBJECTS_HACK
222        DynamicObjectsContainer mDynamicObjects;
223#endif
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                       SceneGraphLeaf *root,
277                                           std::vector<FaceParentInfo> *parents);
278
279        bool ExportBinaryObj(const std::string &filename, SceneGraphLeaf *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.