1 | #ifndef _Preprocessor_H__
|
---|
2 | #define _Preprocessor_H__
|
---|
3 |
|
---|
4 | #include <string>
|
---|
5 | using namespace std;
|
---|
6 | #include "Containers.h"
|
---|
7 | #include "Mesh.h"
|
---|
8 | #include "KdTree.h"
|
---|
9 |
|
---|
10 | // matt: remove qt dependencies
|
---|
11 | //#include <QObject>
|
---|
12 |
|
---|
13 | namespace GtpVisibilityPreprocessor {
|
---|
14 |
|
---|
15 | class RenderSimulator;
|
---|
16 | class SceneGraph;
|
---|
17 | class Exporter;
|
---|
18 | class ViewCellsManager;
|
---|
19 | class BspTree;
|
---|
20 | class VspOspTree;
|
---|
21 | class VspBspTree;
|
---|
22 | class RenderSimulator;
|
---|
23 | struct VssRayContainer;
|
---|
24 | class SamplingStrategy;
|
---|
25 | class GlRendererBuffer;
|
---|
26 | class VspTree;
|
---|
27 | class HierarchyManager;
|
---|
28 | class BvHierarchy;
|
---|
29 | class Intersectable;
|
---|
30 | class 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
|
---|
44 | class Preprocessor// : public QObject
|
---|
45 | {
|
---|
46 | //Q_OBJECT
|
---|
47 |
|
---|
48 | public:
|
---|
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 | /** Construct viewcells from the scratch
|
---|
91 | */
|
---|
92 | bool ConstructViewCells(const AxisAlignedBox3 &viewSpaceBox);
|
---|
93 |
|
---|
94 | /** Returns the specified sample strategy, NULL if no valid strategy.
|
---|
95 | */
|
---|
96 | SamplingStrategy *GenerateSamplingStrategy(const int strategyId) const;
|
---|
97 |
|
---|
98 | bool
|
---|
99 | Export( const string filename,
|
---|
100 | const bool scene,
|
---|
101 | const bool kdtree,
|
---|
102 | const bool bsptree
|
---|
103 | );
|
---|
104 |
|
---|
105 |
|
---|
106 | virtual void KdTreeStatistics(ostream &s);
|
---|
107 | virtual void BspTreeStatistics(ostream &s);
|
---|
108 |
|
---|
109 | /** Loads samples from file.
|
---|
110 | @param samples returns the stored sample rays
|
---|
111 | @param objects needed to associate the objects ids
|
---|
112 | @returns true if samples were loaded successfully
|
---|
113 | */
|
---|
114 | bool LoadSamples(VssRayContainer &samples,
|
---|
115 | ObjectContainer &objects) const;
|
---|
116 |
|
---|
117 | /** Exports samples to file.
|
---|
118 | @returns true if samples were written successfully
|
---|
119 | */
|
---|
120 | bool ExportSamples(const VssRayContainer &samples) const;
|
---|
121 |
|
---|
122 | bool LoadKdTree(const string filename);
|
---|
123 | bool ExportKdTree(const string filename);
|
---|
124 |
|
---|
125 | /** Get Sample rays of particular type, returns false if this
|
---|
126 | type of rays is not supported by the preprocessor
|
---|
127 | */
|
---|
128 | enum {
|
---|
129 | OBJECT_BASED_DISTRIBUTION,
|
---|
130 | DIRECTION_BASED_DISTRIBUTION,
|
---|
131 | DIRECTION_BOX_BASED_DISTRIBUTION,
|
---|
132 | SPATIAL_BOX_BASED_DISTRIBUTION,
|
---|
133 | RSS_BASED_DISTRIBUTION,
|
---|
134 | RSS_SILHOUETTE_BASED_DISTRIBUTION,
|
---|
135 | VSS_BASED_DISTRIBUTION,
|
---|
136 | OBJECT_DIRECTION_BASED_DISTRIBUTION,
|
---|
137 | OBJECTS_INTERIOR_DISTRIBUTION
|
---|
138 | };
|
---|
139 |
|
---|
140 | enum {
|
---|
141 | INTERNAL_RAYCASTER = 0,
|
---|
142 | INTEL_RAYCASTER
|
---|
143 | };
|
---|
144 |
|
---|
145 | virtual bool
|
---|
146 | GenerateRays(
|
---|
147 | const int number,
|
---|
148 | const int raysType,
|
---|
149 | SimpleRayContainer &rays
|
---|
150 | );
|
---|
151 |
|
---|
152 | bool GenerateRayBundle(
|
---|
153 | SimpleRayContainer &rayBundle,
|
---|
154 | const SimpleRay &mainRay,
|
---|
155 | const int number,
|
---|
156 | const int shuffleType) const;
|
---|
157 |
|
---|
158 | virtual void CastRays(SimpleRayContainer &rays,
|
---|
159 | VssRayContainer &vssRays);
|
---|
160 |
|
---|
161 | /** Returns a view cells manager of the given name.
|
---|
162 | */
|
---|
163 | ViewCellsManager *CreateViewCellsManager(const char *name);
|
---|
164 | /** Returns a hierarchy manager of the given name.
|
---|
165 | */
|
---|
166 | HierarchyManager *CreateHierarchyManager(const char *name);
|
---|
167 |
|
---|
168 | GlRendererBuffer *GetRenderer() { return renderer;}
|
---|
169 |
|
---|
170 | bool InitRayCast(const string externKdTree, const string internKdTree);
|
---|
171 |
|
---|
172 | int CastRay(
|
---|
173 | const Vector3 &viewPoint,
|
---|
174 | const Vector3 &direction,
|
---|
175 | const float probability,
|
---|
176 | VssRayContainer &vssRays,
|
---|
177 | const AxisAlignedBox3 &box
|
---|
178 | );
|
---|
179 |
|
---|
180 | Intersectable *
|
---|
181 | CastSimpleRay(
|
---|
182 | const Vector3 &viewPoint,
|
---|
183 | const Vector3 &direction,
|
---|
184 | const AxisAlignedBox3 &box,
|
---|
185 | Vector3 &point,
|
---|
186 | Vector3 &normal
|
---|
187 | );
|
---|
188 |
|
---|
189 | ////////////////////////////////////////////////
|
---|
190 |
|
---|
191 | /// scene graph loaded from file
|
---|
192 | SceneGraph *mSceneGraph;
|
---|
193 |
|
---|
194 | /// raw array of objects
|
---|
195 | ObjectContainer mObjects;
|
---|
196 |
|
---|
197 | /// kD-tree organizing the scene graph (occluders + occludees) + viewcells
|
---|
198 | KdTree *mKdTree;
|
---|
199 | /// View space partition bsp tree
|
---|
200 | VspBspTree *mVspBspTree;
|
---|
201 | /// Hierarchy manager handling view space and object space partition
|
---|
202 | HierarchyManager *mHierarchyManager;
|
---|
203 | /// BSP tree representing the viewcells
|
---|
204 | BspTree *mBspTree;
|
---|
205 |
|
---|
206 | /// list of all loaded occluders
|
---|
207 | ObjectContainer mOccluders;
|
---|
208 | /// list of all loaded occludees
|
---|
209 | ObjectContainer mOccludees;
|
---|
210 |
|
---|
211 |
|
---|
212 | ViewCellsManager *mViewCellsManager;
|
---|
213 |
|
---|
214 | /// greedy optimized hierarchy for both objects and view cells
|
---|
215 | VspOspTree *mVspOspTree;
|
---|
216 |
|
---|
217 | bool mUseGlRenderer;
|
---|
218 | bool mUseGlDebugger;
|
---|
219 |
|
---|
220 | bool mLoadViewCells;
|
---|
221 |
|
---|
222 | bool mDetectEmptyViewSpace;
|
---|
223 |
|
---|
224 | bool mQuitOnFinish;
|
---|
225 | bool mLoadMeshes;
|
---|
226 | bool mComputeVisibility;
|
---|
227 |
|
---|
228 | bool mExportVisibility;
|
---|
229 | string mVisibilityFileName;
|
---|
230 |
|
---|
231 | bool mApplyVisibilityFilter;
|
---|
232 | bool mApplyVisibilitySpatialFilter;
|
---|
233 |
|
---|
234 | float mVisibilityFilterWidth;
|
---|
235 |
|
---|
236 | int GetRayCastMethod() { return mRayCastMethod; }
|
---|
237 | void SetRayCastMethod(int rayCastMethod) { mRayCastMethod = rayCastMethod; }
|
---|
238 |
|
---|
239 | int mPass;
|
---|
240 |
|
---|
241 | protected:
|
---|
242 |
|
---|
243 | void SetupRay(Ray &ray, const Vector3 &point, const Vector3 &direction);
|
---|
244 |
|
---|
245 | int
|
---|
246 | ProcessRay(
|
---|
247 | const Vector3 &viewPoint,
|
---|
248 | const Vector3 &direction,
|
---|
249 | Intersectable *objectA,
|
---|
250 | Vector3 &pointA,
|
---|
251 | const Vector3 &normalA,
|
---|
252 | Intersectable *objectB,
|
---|
253 | Vector3 &pointB,
|
---|
254 | const Vector3 &normalB,
|
---|
255 | const float probability,
|
---|
256 | VssRayContainer &vssRays,
|
---|
257 | const AxisAlignedBox3 &box);
|
---|
258 |
|
---|
259 | int CastInternalRay(
|
---|
260 | const Vector3 &viewPoint,
|
---|
261 | const Vector3 &direction,
|
---|
262 | const float probability,
|
---|
263 | VssRayContainer &vssRays,
|
---|
264 | const AxisAlignedBox3 &box);
|
---|
265 |
|
---|
266 | int CastIntelDoubleRay(
|
---|
267 | const Vector3 &viewPoint,
|
---|
268 | const Vector3 &direction,
|
---|
269 | const float probability,
|
---|
270 | VssRayContainer &vssRays,
|
---|
271 | const AxisAlignedBox3 &box);
|
---|
272 |
|
---|
273 | Intersectable *CastIntelSingleRay(
|
---|
274 | const Vector3 &viewPoint,
|
---|
275 | const Vector3 &direction,
|
---|
276 | Vector3 &tPoint,
|
---|
277 | const AxisAlignedBox3 &box);
|
---|
278 |
|
---|
279 | /////////////////////////
|
---|
280 |
|
---|
281 | int mRayCastMethod;
|
---|
282 | /// samples used for construction of the BSP view cells tree.
|
---|
283 | int mBspConstructionSamples;
|
---|
284 | /// samples used for construction of the VSP OSP tree.
|
---|
285 | int mVspOspConstructionSamples;
|
---|
286 | /** Simulates rendering of the scene.
|
---|
287 | */
|
---|
288 | RenderSimulator *mRenderSimulator;
|
---|
289 |
|
---|
290 |
|
---|
291 | vector<FaceParentInfo> mFaceParents;
|
---|
292 |
|
---|
293 | GlRendererBuffer *renderer;
|
---|
294 | // matt: remove qt dependencies
|
---|
295 | //signals:
|
---|
296 | void EvalPvsStat();
|
---|
297 |
|
---|
298 | protected:
|
---|
299 |
|
---|
300 |
|
---|
301 | void CastRays16(const int i,
|
---|
302 | SimpleRayContainer &rays,
|
---|
303 | VssRayContainer &vssRays,
|
---|
304 | const AxisAlignedBox3 &sbox);
|
---|
305 |
|
---|
306 | };
|
---|
307 |
|
---|
308 | //extern Preprocessor *preprocessor;
|
---|
309 |
|
---|
310 | }
|
---|
311 |
|
---|
312 | #endif
|
---|