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

Revision 2105, 7.8 KB checked in by bittner, 17 years ago (diff)

simple ray separated

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