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 |
|
---|
34 |
|
---|
35 | /** Namespace for the external visibility preprocessor
|
---|
36 |
|
---|
37 | This namespace includes all classes which are created by the VUT (Vienna University
|
---|
38 | of Technology) for the External Visibility Preprocessor of the GTP (GameTools Project)
|
---|
39 | (www.gametools.org).
|
---|
40 | */
|
---|
41 |
|
---|
42 | /** Main class of the visibility preprocessor. Responsible for loading and
|
---|
43 | saving of the input and output files. Initiates construction of the kD-tree,
|
---|
44 | viewcell loading/generation and the visibility computation itself.
|
---|
45 | */
|
---|
46 | class Preprocessor
|
---|
47 | {
|
---|
48 | friend class RayCaster;
|
---|
49 | friend class IntelRayCaster;
|
---|
50 | friend class InternalRayCaster;
|
---|
51 |
|
---|
52 | public:
|
---|
53 | /** Default constructor initialising e.g., KD tree and BSP tree.
|
---|
54 | */
|
---|
55 | Preprocessor();
|
---|
56 |
|
---|
57 | virtual ~Preprocessor();
|
---|
58 |
|
---|
59 | /** Load the input scene.
|
---|
60 | @param filename file to load
|
---|
61 | @return true on success
|
---|
62 | */
|
---|
63 | virtual bool LoadScene(const string &filename);
|
---|
64 |
|
---|
65 | /** Export all preprocessed data in a XML format understandable by the
|
---|
66 | PreprocessingInterface of the GtpVisibilityPreprocessor Module.
|
---|
67 | The file can be compressed depending on the environement settings.
|
---|
68 | @return true on successful export
|
---|
69 | */
|
---|
70 | virtual bool ExportPreprocessedData(const string &filename);
|
---|
71 |
|
---|
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 |
|
---|
78 | /** Compute visibility method. This method has to be reimplemented by the actual
|
---|
79 | Preprocessor implementation (e.g. SamplingPreprocessor, ExactPreprocessor,
|
---|
80 | GlobalSamplingpreprocessor)
|
---|
81 | */
|
---|
82 | virtual bool ComputeVisibility() = 0;
|
---|
83 |
|
---|
84 | /** Post Process the computed visibility. By default applys the visibility filter
|
---|
85 | (if specified in the environment and export the preprocessed data
|
---|
86 | */
|
---|
87 | virtual bool PostProcessVisibility();
|
---|
88 |
|
---|
89 | /** View cells are either loaded or prepared for generation, according to the chosen environment
|
---|
90 | object. Important evironment options are, e.g, the view cell type.
|
---|
91 | Should be done after scene loading (i.e., some options are based on scene type).
|
---|
92 | */
|
---|
93 | bool PrepareViewCells();
|
---|
94 |
|
---|
95 | /** Construct viewcells from the scratch
|
---|
96 | */
|
---|
97 | bool ConstructViewCells();
|
---|
98 |
|
---|
99 | /** Returns the specified sample strategy, NULL if no valid strategy.
|
---|
100 | */
|
---|
101 | SamplingStrategy *GenerateSamplingStrategy(const int strategyId);
|
---|
102 |
|
---|
103 | /** Export preprocessor data.
|
---|
104 | */
|
---|
105 | bool Export(const string &filename, const bool scene, const bool kdtree);
|
---|
106 |
|
---|
107 | virtual void KdTreeStatistics(ostream &s);
|
---|
108 | virtual void BspTreeStatistics(ostream &s);
|
---|
109 |
|
---|
110 | /** Loads samples from file.
|
---|
111 | @param samples returns the stored sample rays
|
---|
112 | @param objects needed to associate the objects ids
|
---|
113 | @returns true if samples were loaded successfully
|
---|
114 | */
|
---|
115 | bool LoadSamples(VssRayContainer &samples, 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 | virtual bool
|
---|
126 | ExportRays(const char *filename,
|
---|
127 | const VssRayContainer &vssRays,
|
---|
128 | const int number,
|
---|
129 | const bool exportScene = false
|
---|
130 | );
|
---|
131 |
|
---|
132 | bool ExportRayAnimation(const char *filename,
|
---|
133 | const vector<VssRayContainer> &vssRays);
|
---|
134 |
|
---|
135 | virtual int GenerateRays(const int number,
|
---|
136 | SamplingStrategy &strategy,
|
---|
137 | SimpleRayContainer &rays);
|
---|
138 |
|
---|
139 | virtual int GenerateRays(const int number,
|
---|
140 | const int raysType,
|
---|
141 | SimpleRayContainer &rays);
|
---|
142 |
|
---|
143 | bool GenerateRayBundle(SimpleRayContainer &rayBundle,
|
---|
144 | const SimpleRay &mainRay,
|
---|
145 | const int number,
|
---|
146 | const int shuffleType) const;
|
---|
147 |
|
---|
148 | virtual void CastRays(SimpleRayContainer &rays,
|
---|
149 | VssRayContainer &vssRays,
|
---|
150 | const bool castDoubleRays,
|
---|
151 | const bool pruneInvalidRays = true);
|
---|
152 |
|
---|
153 | virtual void
|
---|
154 | CastRaysWithHwGlobalLines(
|
---|
155 | SimpleRayContainer &rays,
|
---|
156 | VssRayContainer &vssRays,
|
---|
157 | const bool castDoubleRays,
|
---|
158 | const bool pruneInvalidRays
|
---|
159 | );
|
---|
160 |
|
---|
161 | /** Compute pixel error of the current PVS solution by sampling given number of viewpoints.
|
---|
162 | */
|
---|
163 | virtual void ComputeRenderError();
|
---|
164 |
|
---|
165 | /** Returns a view cells manager of the given name.
|
---|
166 | */
|
---|
167 | ViewCellsManager *CreateViewCellsManager(const char *name);
|
---|
168 |
|
---|
169 | GlRendererBuffer *GetRenderer();
|
---|
170 |
|
---|
171 | bool InitRayCast(const string &externKdTree, const string &internKdTree);
|
---|
172 |
|
---|
173 | bool LoadInternKdTree(const string &internKdTree);
|
---|
174 |
|
---|
175 | bool ExportObj(const string &filename, const ObjectContainer &objects);
|
---|
176 |
|
---|
177 | Intersectable *GetParentObject(const int index) const;
|
---|
178 | Vector3 GetParentNormal(const int index) const;
|
---|
179 |
|
---|
180 | /** Sets a Preprocessor thread.
|
---|
181 | */
|
---|
182 | void SetThread(PreprocessorThread *t);
|
---|
183 |
|
---|
184 | /** Returns a Preprocessor thread.
|
---|
185 | */
|
---|
186 | PreprocessorThread *GetThread() const;
|
---|
187 |
|
---|
188 | Intersectable *GetObjectById(const int id);
|
---|
189 |
|
---|
190 | void PrepareHwGlobalLines();
|
---|
191 |
|
---|
192 | virtual void DeterminePvsObjects(VssRayContainer &rays);
|
---|
193 |
|
---|
194 | static bool LoadObjects(const string &filename,
|
---|
195 | ObjectContainer &pvsObjects,
|
---|
196 | const ObjectContainer &preprocessorObject);
|
---|
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 | /// View space partition bsp tree
|
---|
210 | VspBspTree *mVspBspTree;
|
---|
211 | /// BSP tree representing the viewcells
|
---|
212 | BspTree *mBspTree;
|
---|
213 |
|
---|
214 | /// list of all loaded occluders
|
---|
215 | ObjectContainer mOccluders;
|
---|
216 | /// list of all loaded occludees
|
---|
217 | ObjectContainer mOccludees;
|
---|
218 |
|
---|
219 |
|
---|
220 | ViewCellsManager *mViewCellsManager;
|
---|
221 |
|
---|
222 | /// greedy optimized hierarchy for both objects and view cells
|
---|
223 | VspOspTree *mVspOspTree;
|
---|
224 |
|
---|
225 | bool mUseGlRenderer;
|
---|
226 | bool mUseGlDebugger;
|
---|
227 |
|
---|
228 | bool mUseHwGlobalLines;
|
---|
229 | bool mLoadViewCells;
|
---|
230 |
|
---|
231 | bool mDetectEmptyViewSpace;
|
---|
232 |
|
---|
233 | bool mQuitOnFinish;
|
---|
234 | bool mLoadMeshes;
|
---|
235 | bool mComputeVisibility;
|
---|
236 |
|
---|
237 | bool mExportVisibility;
|
---|
238 | string mVisibilityFileName;
|
---|
239 |
|
---|
240 | bool mApplyVisibilityFilter;
|
---|
241 | bool mApplyVisibilitySpatialFilter;
|
---|
242 |
|
---|
243 | float mVisibilityFilterWidth;
|
---|
244 |
|
---|
245 | int mPass;
|
---|
246 |
|
---|
247 | bool mStopComputation;
|
---|
248 |
|
---|
249 | bool mExportObj;
|
---|
250 |
|
---|
251 | bool mExportRays;
|
---|
252 | bool mExportAnimation;
|
---|
253 | int mExportNumRays;
|
---|
254 |
|
---|
255 | ofstream mStats;
|
---|
256 |
|
---|
257 | GlRendererBuffer *renderer;
|
---|
258 |
|
---|
259 | int mTotalSamples;
|
---|
260 | int mTotalTime;
|
---|
261 | int mSamplesPerPass;
|
---|
262 | int mSamplesPerEvaluation;
|
---|
263 |
|
---|
264 | RayCaster *mRayCaster;
|
---|
265 |
|
---|
266 |
|
---|
267 | protected:
|
---|
268 |
|
---|
269 | bool LoadBinaryObj(const std::string &filename,
|
---|
270 | SceneGraphNode *root,
|
---|
271 | std::vector<FaceParentInfo> *parents);
|
---|
272 |
|
---|
273 | bool ExportBinaryObj(const std::string &filename, SceneGraphNode *root);
|
---|
274 |
|
---|
275 | void SetupRay(Ray &ray, const Vector3 &point, const Vector3 &direction) const;
|
---|
276 |
|
---|
277 | void EvalPvsStat();
|
---|
278 |
|
---|
279 | virtual void EvalViewCellHistogram();
|
---|
280 |
|
---|
281 |
|
---|
282 | /////////////////////////
|
---|
283 |
|
---|
284 | GlobalLinesRenderer *mGlobalLinesRenderer;
|
---|
285 |
|
---|
286 | /// samples used for construction of the BSP view cells tree.
|
---|
287 | int mBspConstructionSamples;
|
---|
288 | /// samples used for construction of the VSP OSP tree.
|
---|
289 | int mVspOspConstructionSamples;
|
---|
290 | /// Simulates rendering of the scene.
|
---|
291 | RenderSimulator *mRenderSimulator;
|
---|
292 |
|
---|
293 | vector<FaceParentInfo> mFaceParents;
|
---|
294 |
|
---|
295 | /// if box around view space should be used
|
---|
296 | bool mUseViewSpaceBox;
|
---|
297 |
|
---|
298 | PreprocessorThread *mThread;
|
---|
299 | };
|
---|
300 |
|
---|
301 | extern Preprocessor *preprocessor;
|
---|
302 |
|
---|
303 | }
|
---|
304 |
|
---|
305 | #endif
|
---|