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

Revision 1287, 7.7 KB checked in by mattausch, 18 years ago (diff)

implemented bv hierarchy

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 with respect to the given name.
152  */
153  ViewCellsManager *CreateViewCellsManager(const char *name);
154   
155  GlRendererBuffer *GetRenderer() { return renderer;}
156
157  bool InitRayCast(const string externKdTree);
158
159  int CastRay(
160          const Vector3 &viewPoint,
161          const Vector3 &direction,
162          const float probability,
163          VssRayContainer &vssRays,
164          const AxisAlignedBox3 &box
165          );
166
167  ////////////////////////////////////////////////
168
169  /// scene graph loaded from file
170  SceneGraph *mSceneGraph;
171
172  /// raw array of objects
173  ObjectContainer mObjects;
174 
175  /// kD-tree organizing the scene graph (occluders + occludees) + viewcells
176  KdTree *mKdTree;
177  /// View space partition bsp tree
178  VspBspTree *mVspBspTree;
179  // view space partition tree
180  VspTree *mVspTree;
181  HierarchyManager *mHierarchyManager;
182  /// BSP tree representing the viewcells
183  BspTree *mBspTree;
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
225  ProcessRay(
226                         const Vector3 &viewPoint,
227                         const Vector3 &direction,
228                         Intersectable *objectA,
229                         Vector3 &pointA,
230                         const Vector3 &normalA,
231                         Intersectable *objectB,
232                         Vector3 &pointB,
233                         const Vector3 &normalB,
234                         const float probability,
235                         VssRayContainer &vssRays,
236                         const AxisAlignedBox3 &box);
237 
238  int CastInternalRay(
239                                          const Vector3 &viewPoint,
240                                          const Vector3 &direction,
241                                          const float probability,
242                                          VssRayContainer &vssRays,
243                                          const AxisAlignedBox3 &box);
244 
245  int CastIntelDoubleRay(
246                                                 const Vector3 &viewPoint,
247                                                 const Vector3 &direction,
248                                                 const float probability,
249                                                 VssRayContainer &vssRays,
250                                                 const AxisAlignedBox3 &box);
251 
252  Intersectable *CastIntelSingleRay(
253                                                                        const Vector3 &viewPoint,
254                                                                        const Vector3 &direction,
255                                                                        Vector3 &tPoint,
256                                                                        const AxisAlignedBox3 &box);
257 
258  /////////////////////////
259
260        int mRayCastMethod;
261  /// samples used for construction of the BSP view cells tree.
262  int mBspConstructionSamples;
263  /// samples used for construction of the VSP OSP tree.
264  int mVspOspConstructionSamples;
265  /** Simulates rendering of the scene.
266  */
267  RenderSimulator *mRenderSimulator;
268
269 
270  vector<FaceParentInfo> mFaceParents;
271 
272  GlRendererBuffer *renderer;
273// matt: remove qt dependencies
274//signals:
275  void EvalPvsStat();
276
277  protected:
278
279 
280  void CastRays16(const int i,
281                                  SimpleRayContainer &rays,
282                                  VssRayContainer &vssRays,
283                                  const AxisAlignedBox3 &sbox);
284 
285};
286
287//extern Preprocessor *preprocessor;
288
289}
290
291#endif
Note: See TracBrowser for help on using the repository browser.