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

Revision 1932, 7.0 KB checked in by mattausch, 18 years ago (diff)
Line 
1#ifndef _Preprocessor_H__
2#define _Preprocessor_H__
3
4#include <string>
5using namespace std;
6#include "Containers.h"
7#include "Mesh.h"
8#include "KdTree.h"
9
10
11namespace GtpVisibilityPreprocessor {
12  class PreprocessorThread;
13 
14class RenderSimulator;
15class SceneGraph;
16class Exporter;
17class ViewCellsManager;
18class BspTree;
19class VspOspTree;
20class VspBspTree;
21class RenderSimulator;
22struct VssRayContainer;
23class SamplingStrategy;
24class GlRendererBuffer;
25class VspTree;
26class HierarchyManager;
27class BvHierarchy;
28class Intersectable;
29class VssRay;
30class RayCaster;
31
32
33/** Namespace for the external visibility preprocessor
34
35    This namespace includes all classes which are created by the VUT (Vienna University
36    of Technology) for the External Visibility Preprocessor of the GTP (GameTools Project)
37    (www.gametools.org).
38*/
39 
40/** Main class of the visibility preprocessor. Responsible for loading and
41    saving of the input and output files. Initiates construction of the kD-tree,
42    viewcell loading/generation and the visibility computation itself.
43*/
44class Preprocessor
45{
46        friend class RayCaster;
47        friend class IntelRayCaster;
48        friend class InternalRayCaster;
49
50public:
51        /** Default constructor initialising e.g., KD tree and BSP tree.
52        */
53        Preprocessor();
54
55        virtual ~Preprocessor();
56
57        /** Load the input scene.
58        @param filename file to load
59        @return true on success
60        */
61        virtual bool LoadScene(const string filename);
62
63        /** Export all preprocessed data in a XML format understandable by the
64        PreprocessingInterface of the GtpVisibilityPreprocessor Module.
65        The file can be compressed depending on the environement settings.
66        @return true on successful export
67        */
68        virtual bool ExportPreprocessedData(const string filename);
69
70        /** Build the KdTree of currently loaded occluders/occludees/viewcells. The construction
71        is driven by the environment settings, which also sais which of the three types of
72        entities should be used to drive the heuristical construction (only occluders by default)
73        */
74        virtual bool BuildKdTree();
75
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
82        /** Post Process the computed visibility. By default applys the visibility filter
83        (if specified in the environment and export the preprocessed data */
84        virtual bool PostProcessVisibility();
85
86        /** View cells are either loaded or prepared for generation, according to the chosen environment
87        object. Important evironment options are, e.g, the view cell type.
88        Should be done after scene loading (i.e., some options are based on scene type).
89        */
90        bool PrepareViewCells();
91
92        /** Construct viewcells from the scratch
93        */
94        bool ConstructViewCells();
95
96        /** Returns the specified sample strategy, NULL if no valid strategy.
97        */
98        SamplingStrategy *GenerateSamplingStrategy(const int strategyId);
99
100        /** Export preprocessor data.
101        */
102        bool Export(const string filename, const bool scene, const bool kdtree); 
103
104        virtual void KdTreeStatistics(ostream &s);
105        virtual void BspTreeStatistics(ostream &s);
106
107        /** Loads samples from file.
108        @param samples returns the stored sample rays
109        @param objects needed to associate the objects ids
110        @returns true if samples were loaded successfully
111        */
112        bool LoadSamples(VssRayContainer &samples,
113                ObjectContainer &objects) const;
114
115        /** Exports samples to file.
116        @returns true if samples were written successfully
117        */
118        bool ExportSamples(const VssRayContainer &samples) const;
119
120        bool LoadKdTree(const string filename);
121        bool ExportKdTree(const string filename);
122
123        virtual bool
124                ExportRays(const char *filename,
125                const VssRayContainer &vssRays,
126                const int number
127                );
128
129        virtual int
130                GenerateRays(const int number,
131                SamplingStrategy &strategy,
132                SimpleRayContainer &rays);
133
134        virtual int GenerateRays(const int number,
135                const int raysType,
136                SimpleRayContainer &rays);
137
138        bool GenerateRayBundle(SimpleRayContainer &rayBundle,
139                const SimpleRay &mainRay,
140                const int number,
141                const int shuffleType) const;
142
143        virtual void CastRays(SimpleRayContainer &rays,
144                                                  VssRayContainer &vssRays,
145                                                  const bool castDoubleRays,
146                                                  const bool pruneInvalidRays = true);
147
148  /** Compute pixel error of the current PVS solution by sampling given number of viewpoints */
149  virtual void
150  ComputeRenderError();
151
152        /** Returns a view cells manager of the given name.
153        */
154        ViewCellsManager *CreateViewCellsManager(const char *name);
155
156        GlRendererBuffer *GetRenderer();
157
158        bool InitRayCast(const string externKdTree, const string internKdTree);
159
160        bool ExportObj(const string filename, const ObjectContainer &objects);
161
162        Intersectable *GetParentObject(const int index) const;
163        Vector3 GetParentNormal(const int index) const;
164
165        /** Sets a Preprocessor thread.
166        */
167        void SetThread(PreprocessorThread *t);
168
169        /** Returns a Preprocessor thread.
170        */
171        PreprocessorThread *GetThread() const;
172
173
174
175        ////////////////////////////////////////////////
176
177        /// scene graph loaded from file
178        SceneGraph *mSceneGraph;
179
180        /// raw array of objects
181        ObjectContainer mObjects;
182
183        /// kD-tree organizing the scene graph (occluders + occludees) + viewcells
184        KdTree *mKdTree;
185        /// View space partition bsp tree
186        VspBspTree *mVspBspTree;
187        /// BSP tree representing the viewcells
188        BspTree *mBspTree;
189
190        /// list of all loaded occluders
191        ObjectContainer mOccluders;
192        /// list of all loaded occludees
193        ObjectContainer mOccludees;
194
195
196        ViewCellsManager *mViewCellsManager;
197
198        /// greedy optimized hierarchy for both objects and view cells
199        VspOspTree *mVspOspTree;
200
201        bool mUseGlRenderer;
202        bool mUseGlDebugger;
203
204        bool mLoadViewCells;
205
206        bool mDetectEmptyViewSpace;
207
208        bool mQuitOnFinish;
209        bool mLoadMeshes;
210        bool mComputeVisibility;
211
212        bool mExportVisibility;
213        string mVisibilityFileName;
214
215        bool mApplyVisibilityFilter;
216        bool mApplyVisibilitySpatialFilter;
217
218        float mVisibilityFilterWidth;
219
220        int mPass;
221 
222        bool mStopComputation;
223 
224        bool mExportObj;
225
226        bool mExportRays;
227        int mExportNumRays;
228
229        ofstream mStats;
230
231        GlRendererBuffer *renderer;
232
233
234protected:
235
236        bool LoadBinaryObj(const string filename,
237                                           SceneGraphNode *root,
238                                           vector<FaceParentInfo> *parents);
239
240        bool ExportBinaryObj(const string filename, SceneGraphNode *root);
241
242        void SetupRay(Ray &ray, const Vector3 &point, const Vector3 &direction) const;
243
244        void EvalPvsStat();
245
246        virtual void EvalViewCellHistogram();
247
248        /////////////////////////
249
250        RayCaster *mRayCaster;
251        /// samples used for construction of the BSP view cells tree.
252        int mBspConstructionSamples;
253        /// samples used for construction of the VSP OSP tree.
254        int mVspOspConstructionSamples;
255        /// Simulates rendering of the scene.
256        RenderSimulator *mRenderSimulator;
257
258        vector<FaceParentInfo> mFaceParents;
259
260
261        /// if box around view space should be used
262        bool mUseViewSpaceBox;
263
264        PreprocessorThread *mThread;
265};
266
267  extern Preprocessor *preprocessor;
268
269}
270
271#endif
Note: See TracBrowser for help on using the repository browser.