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

Revision 1251, 7.1 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// matt: remove qt dependencies
11//#include <QObject>
12
13namespace GtpVisibilityPreprocessor {
14
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 OspTree;
28class Intersectable;
29
30/** Namespace for the external visibility preprocessor
31
32    This namespace includes all classes which are created by the VUT (Vienna University
33    of Technology) for the External Visibility Preprocessor of the GTP (GameTools Project)
34    (www.gametools.org).
35*/
36 
37/** Main class of the visibility preprocessor. Responsible for loading and
38    saving of the input and output files. Initiates construction of the kD-tree,
39    viewcell loading/generation and the visibility computation itself.
40*/
41// matt: remove qt dependencies
42class Preprocessor// : public QObject
43{
44  //Q_OBJECT
45
46public:
47        /** Default constructor initialising e.g., KD tree and BSP tree.
48        */
49        Preprocessor();
50
51   virtual ~Preprocessor();
52
53  /** Load the input scene.
54      @param filename file to load
55          @return true on success
56  */
57  virtual bool LoadScene(const string filename);
58 
59  /** Export all preprocessed data in a XML format understandable by the
60      PreprocessingInterface of the GtpVisibilityPreprocessor Module. The file can be compressed depending
61      on the environement settings.
62      @return true on successful export
63  */
64  virtual bool ExportPreprocessedData(const string filename);
65 
66  /** Build the KdTree of currently loaded occluders/occludees/viewcells. The construction
67      is driven by the environment settings, which also sais which of the three types of
68      entities should be used to drive the heuristical construction (only occluders by default)
69  */
70  virtual bool BuildKdTree();
71
72  /** Compute visibility method. This method has to be reimplemented by the actual
73      Preprocessor implementation (e.g. SamplingPreprocessor, ExactPreprocessor,
74      GlobalSamplingpreprocessor)
75    */
76  virtual bool ComputeVisibility() = 0;
77
78  /** Post Process the computed visibility. By default applys the visibility filter
79          (if specified in the environment and export the preprocessed data */
80  virtual bool PostProcessVisibility();
81
82  /** View cells are either loaded or prepared for generation, according to the chosen environment
83      object. Important evironment options are, e.g, the view cell type.
84      Should be done after scene loading (i.e., some options are based on scene type).
85  */
86  bool PrepareViewCells();
87 
88  /** Returns the specified sample strategy, NULL if no valid strategy.
89  */
90  SamplingStrategy *GenerateSamplingStrategy(const int strategyId) const;
91
92  bool
93  Export( const string filename,
94          const bool scene,
95          const bool kdtree,
96          const bool bsptree
97          );
98 
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,
109                                   ObjectContainer &objects) const;
110
111  /** Exports samples to file.
112          @returns true if samples were written successfully
113  */
114  bool ExportSamples(const VssRayContainer &samples) const;
115
116  bool LoadKdTree();
117  bool ExportKdTree();
118
119  /** Get Sample rays of particular type, returns false if this
120          type of rays is not supported by the preprocessor
121  */
122  enum {
123        OBJECT_BASED_DISTRIBUTION,
124        DIRECTION_BASED_DISTRIBUTION,
125        DIRECTION_BOX_BASED_DISTRIBUTION,
126        SPATIAL_BOX_BASED_DISTRIBUTION,
127        RSS_BASED_DISTRIBUTION,
128        RSS_SILHOUETTE_BASED_DISTRIBUTION,
129        VSS_BASED_DISTRIBUTION,
130        OBJECT_DIRECTION_BASED_DISTRIBUTION,
131        OBJECTS_INTERIOR_DISTRIBUTION
132  };
133 
134  enum {
135          INTERNAL_RAYCASTER,
136          INTEL_RAYCASTER
137  };
138
139  virtual bool
140  GenerateRays(
141                           const int number,
142                           const int raysType,
143                           SimpleRayContainer &rays
144                           );
145 
146  virtual void CastRays(SimpleRayContainer &rays,
147          VssRayContainer &vssRays) {};
148
149  /** Returns a view cells manager with respect to the given name.
150  */
151  ViewCellsManager *CreateViewCellsManager(const char *name);
152   
153  GlRendererBuffer *GetRenderer() { return renderer;}
154
155  bool InitRayCast(const string externKdTree);
156
157  int CastRay(
158          const Vector3 &viewPoint,
159          const Vector3 &direction,
160          const float probability,
161          VssRayContainer &vssRays,
162          const AxisAlignedBox3 &box
163          );
164
165  ////////////////////////////////////////////////
166
167  /// scene graph loaded from file
168  SceneGraph *mSceneGraph;
169
170  /// raw array of objects
171  ObjectContainer mObjects;
172 
173  /// kD-tree organizing the scene graph (occluders + occludees) + viewcells
174  KdTree *mKdTree;
175  /// View space partition bsp tree
176  VspBspTree *mVspBspTree;
177  // view space partition tree
178  VspTree *mVspTree;
179  /// object space partition tree
180  OspTree *mOspTree;
181  /// BSP tree representing the viewcells
182  BspTree *mBspTree;
183
184
185  /// list of all loaded occluders
186  ObjectContainer mOccluders;
187  /// list of all loaded occludees
188  ObjectContainer mOccludees;
189   
190 
191  ViewCellsManager *mViewCellsManager;
192
193  /// greedy optimized hierarchy for both objects and view cells
194  VspOspTree *mVspOspTree;
195
196  bool mUseGlRenderer;
197  bool mUseGlDebugger;
198
199  bool mLoadViewCells;
200 
201  bool mDetectEmptyViewSpace;
202
203  bool mQuitOnFinish;
204  bool mLoadPolygonsAsMeshes;
205  bool mComputeVisibility;
206
207  bool mExportVisibility;
208  string mVisibilityFileName;
209 
210  bool mApplyVisibilityFilter;
211  bool mApplyVisibilitySpatialFilter;
212
213  float mVisibilityFilterWidth;
214 
215  int GetRayCastMethod() { return mRayCastMethod; }
216  void SetRayCastMethod(int rayCastMethod) { mRayCastMethod = rayCastMethod; }
217
218  int mPass;
219
220protected:
221
222        void SetupRay(Ray &ray, const Vector3 &point, const Vector3 &direction);
223
224        int CastInternalRay(
225                const Vector3 &viewPoint,
226                const Vector3 &direction,
227                const float probability,
228                VssRayContainer &vssRays,
229                const AxisAlignedBox3 &box);
230
231        int CastIntelDoubleRay(
232                const Vector3 &viewPoint,
233                const Vector3 &direction,
234                const float probability,
235                VssRayContainer &vssRays,
236                const AxisAlignedBox3 &box);
237
238        Intersectable *CastIntelSingleRay(
239                        const Vector3 &viewPoint,
240                        const Vector3 &direction,
241                        Vector3 &tPoint,
242                        const AxisAlignedBox3 &box);
243
244  /////////////////////////
245
246        int mRayCastMethod;
247  /// samples used for construction of the BSP view cells tree.
248  int mBspConstructionSamples;
249  /// samples used for construction of the VSP OSP tree.
250  int mVspOspConstructionSamples;
251  /** Simulates rendering of the scene.
252  */
253  RenderSimulator *mRenderSimulator;
254
255  vector<Intersectable *> mFaceParents;
256  GlRendererBuffer *renderer;
257// matt: remove qt dependencies
258//signals:
259  void EvalPvsStat();
260
261};
262
263//extern Preprocessor *preprocessor;
264
265}
266
267#endif
Note: See TracBrowser for help on using the repository browser.