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