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

Revision 2600, 8.2 KB checked in by mattausch, 16 years ago (diff)

preparing for moving objects (contains compile errors!)

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