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

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