[372] | 1 | #ifndef _Preprocessor_H__
|
---|
| 2 | #define _Preprocessor_H__
|
---|
| 3 |
|
---|
| 4 | #include <string>
|
---|
[2176] | 5 | //
|
---|
[372] | 6 | #include "Containers.h"
|
---|
| 7 | #include "Mesh.h"
|
---|
| 8 | #include "KdTree.h"
|
---|
[2105] | 9 | #include "SimpleRay.h"
|
---|
[372] | 10 |
|
---|
[2743] | 11 | #define USE_RAY_POOL
|
---|
[2342] | 12 |
|
---|
[860] | 13 | namespace GtpVisibilityPreprocessor {
|
---|
[2342] | 14 |
|
---|
| 15 | class PreprocessorThread;
|
---|
[409] | 16 | class RenderSimulator;
|
---|
[372] | 17 | class SceneGraph;
|
---|
[429] | 18 | class Exporter;
|
---|
[439] | 19 | class ViewCellsManager;
|
---|
[445] | 20 | class BspTree;
|
---|
[1006] | 21 | class VspOspTree;
|
---|
[445] | 22 | class VspBspTree;
|
---|
[468] | 23 | class RenderSimulator;
|
---|
[490] | 24 | struct VssRayContainer;
|
---|
[1020] | 25 | class SamplingStrategy;
|
---|
[496] | 26 | class GlRendererBuffer;
|
---|
[1022] | 27 | class VspTree;
|
---|
[1279] | 28 | class HierarchyManager;
|
---|
[1264] | 29 | class BvHierarchy;
|
---|
[1221] | 30 | class Intersectable;
|
---|
[1287] | 31 | class VssRay;
|
---|
[1520] | 32 | class RayCaster;
|
---|
[1968] | 33 | class GlobalLinesRenderer;
|
---|
[2600] | 34 | class SceneGraphLeaf;
|
---|
[2625] | 35 | class GlRendererWidget;
|
---|
[2702] | 36 | class IntersectableGroup;
|
---|
[2743] | 37 | class TriangleIntersectable;
|
---|
[490] | 38 |
|
---|
[1520] | 39 |
|
---|
[2743] | 40 | /** Hack: Visualization structure for the GVS algorithm.
|
---|
| 41 | */
|
---|
| 42 | struct VizStruct
|
---|
| 43 | {
|
---|
| 44 | VertexContainer enlargedTriangle;
|
---|
| 45 | TriangleIntersectable *originalTriangle;
|
---|
| 46 | VssRay *ray;
|
---|
| 47 | };
|
---|
| 48 |
|
---|
| 49 |
|
---|
[372] | 50 | /** Namespace for the external visibility preprocessor
|
---|
| 51 |
|
---|
| 52 | This namespace includes all classes which are created by the VUT (Vienna University
|
---|
| 53 | of Technology) for the External Visibility Preprocessor of the GTP (GameTools Project)
|
---|
| 54 | (www.gametools.org).
|
---|
| 55 | */
|
---|
| 56 |
|
---|
[1145] | 57 | /** Main class of the visibility preprocessor. Responsible for loading and
|
---|
| 58 | saving of the input and output files. Initiates construction of the kD-tree,
|
---|
| 59 | viewcell loading/generation and the visibility computation itself.
|
---|
| 60 | */
|
---|
[1521] | 61 | class Preprocessor
|
---|
[1145] | 62 | {
|
---|
[1520] | 63 | friend class RayCaster;
|
---|
| 64 | friend class IntelRayCaster;
|
---|
| 65 | friend class InternalRayCaster;
|
---|
[2575] | 66 | friend class HavranRayCaster;
|
---|
[1564] | 67 |
|
---|
[372] | 68 | public:
|
---|
| 69 | /** Default constructor initialising e.g., KD tree and BSP tree.
|
---|
| 70 | */
|
---|
| 71 | Preprocessor();
|
---|
| 72 |
|
---|
[1520] | 73 | virtual ~Preprocessor();
|
---|
[1564] | 74 | /** Load the input scene.
|
---|
[2187] | 75 | @param filename file to load
|
---|
| 76 | @return true on success
|
---|
[1564] | 77 | */
|
---|
[2342] | 78 | virtual bool LoadScene(const string &filename);
|
---|
[1564] | 79 | /** Export all preprocessed data in a XML format understandable by the
|
---|
[2187] | 80 | PreprocessingInterface of the GtpVisibilityPreprocessor Module.
|
---|
| 81 | The file can be compressed depending on the environement settings.
|
---|
| 82 | @return true on successful export
|
---|
[1564] | 83 | */
|
---|
[2342] | 84 | virtual bool ExportPreprocessedData(const string &filename);
|
---|
[1564] | 85 | /** Build the KdTree of currently loaded occluders/occludees/viewcells. The construction
|
---|
[2187] | 86 | is driven by the environment settings, which also sais which of the three types of
|
---|
| 87 | entities should be used to drive the heuristical construction (only occluders by default)
|
---|
[1564] | 88 | */
|
---|
| 89 | virtual bool BuildKdTree();
|
---|
| 90 | /** Compute visibility method. This method has to be reimplemented by the actual
|
---|
[2187] | 91 | Preprocessor implementation (e.g. SamplingPreprocessor, ExactPreprocessor,
|
---|
| 92 | GlobalSamplingpreprocessor)
|
---|
[1564] | 93 | */
|
---|
| 94 | virtual bool ComputeVisibility() = 0;
|
---|
| 95 | /** Post Process the computed visibility. By default applys the visibility filter
|
---|
[2187] | 96 | (if specified in the environment and export the preprocessed data
|
---|
[2609] | 97 | */
|
---|
[1564] | 98 | virtual bool PostProcessVisibility();
|
---|
| 99 | /** View cells are either loaded or prepared for generation, according to the chosen environment
|
---|
[2187] | 100 | object. Important evironment options are, e.g, the view cell type.
|
---|
| 101 | Should be done after scene loading (i.e., some options are based on scene type).
|
---|
[1564] | 102 | */
|
---|
| 103 | bool PrepareViewCells();
|
---|
| 104 | /** Construct viewcells from the scratch
|
---|
| 105 | */
|
---|
| 106 | bool ConstructViewCells();
|
---|
| 107 | /** Returns the specified sample strategy, NULL if no valid strategy.
|
---|
| 108 | */
|
---|
[1884] | 109 | SamplingStrategy *GenerateSamplingStrategy(const int strategyId);
|
---|
[1564] | 110 | /** Export preprocessor data.
|
---|
| 111 | */
|
---|
[2342] | 112 | bool Export(const string &filename, const bool scene, const bool kdtree);
|
---|
[372] | 113 |
|
---|
[1564] | 114 | virtual void KdTreeStatistics(ostream &s);
|
---|
| 115 | virtual void BspTreeStatistics(ostream &s);
|
---|
[490] | 116 |
|
---|
[1564] | 117 | /** Loads samples from file.
|
---|
| 118 | @param samples returns the stored sample rays
|
---|
| 119 | @param objects needed to associate the objects ids
|
---|
| 120 | @returns true if samples were loaded successfully
|
---|
| 121 | */
|
---|
[2187] | 122 | bool LoadSamples(VssRayContainer &samples, ObjectContainer &objects) const;
|
---|
[508] | 123 |
|
---|
[1564] | 124 | /** Exports samples to file.
|
---|
[2187] | 125 | @returns true if samples were written successfully
|
---|
[1564] | 126 | */
|
---|
| 127 | bool ExportSamples(const VssRayContainer &samples) const;
|
---|
[1197] | 128 |
|
---|
[2342] | 129 | bool LoadKdTree(const string &filename);
|
---|
| 130 | bool ExportKdTree(const string &filename);
|
---|
[1381] | 131 |
|
---|
[1926] | 132 | virtual bool
|
---|
[2001] | 133 | ExportRays(const char *filename,
|
---|
| 134 | const VssRayContainer &vssRays,
|
---|
| 135 | const int number,
|
---|
| 136 | const bool exportScene = false
|
---|
| 137 | );
|
---|
[1926] | 138 |
|
---|
[2048] | 139 | bool ExportRayAnimation(const char *filename,
|
---|
| 140 | const vector<VssRayContainer> &vssRays);
|
---|
[2002] | 141 |
|
---|
[2048] | 142 | virtual int GenerateRays(const int number,
|
---|
| 143 | SamplingStrategy &strategy,
|
---|
| 144 | SimpleRayContainer &rays);
|
---|
[1786] | 145 |
|
---|
[2726] | 146 | virtual int GenerateRays(const int number,
|
---|
| 147 | SamplingStrategy &strategy,
|
---|
| 148 | SimpleRayContainer &rays,
|
---|
| 149 | int &invalidSamples);
|
---|
| 150 |
|
---|
[1926] | 151 | virtual int GenerateRays(const int number,
|
---|
[2048] | 152 | const int raysType,
|
---|
| 153 | SimpleRayContainer &rays);
|
---|
[1786] | 154 |
|
---|
[2726] | 155 | bool GenerateJitteredRays(SimpleRayContainer &rayBundle,
|
---|
| 156 | const SimpleRay &mainRay,
|
---|
| 157 | int number,
|
---|
[2736] | 158 | int shuffleType,
|
---|
| 159 | float scale) const;
|
---|
[1786] | 160 |
|
---|
| 161 | virtual void CastRays(SimpleRayContainer &rays,
|
---|
[1932] | 162 | VssRayContainer &vssRays,
|
---|
| 163 | const bool castDoubleRays,
|
---|
[1996] | 164 | const bool pruneInvalidRays = true);
|
---|
[1786] | 165 |
|
---|
[2342] | 166 | virtual void
|
---|
| 167 | CastRaysWithHwGlobalLines(
|
---|
| 168 | SimpleRayContainer &rays,
|
---|
| 169 | VssRayContainer &vssRays,
|
---|
| 170 | const bool castDoubleRays,
|
---|
| 171 | const bool pruneInvalidRays
|
---|
| 172 | );
|
---|
[2076] | 173 |
|
---|
[2187] | 174 | /** Compute pixel error of the current PVS solution by sampling given number of viewpoints.
|
---|
[2048] | 175 | */
|
---|
[1958] | 176 | virtual void ComputeRenderError();
|
---|
[1931] | 177 |
|
---|
[1564] | 178 | /** Returns a view cells manager of the given name.
|
---|
| 179 | */
|
---|
| 180 | ViewCellsManager *CreateViewCellsManager(const char *name);
|
---|
[1221] | 181 |
|
---|
[1564] | 182 | GlRendererBuffer *GetRenderer();
|
---|
[492] | 183 |
|
---|
[2342] | 184 | bool InitRayCast(const string &externKdTree, const string &internKdTree);
|
---|
[409] | 185 |
|
---|
[2342] | 186 | bool LoadInternKdTree(const string &internKdTree);
|
---|
[2003] | 187 |
|
---|
[2342] | 188 | bool ExportObj(const string &filename, const ObjectContainer &objects);
|
---|
[429] | 189 |
|
---|
[1786] | 190 | Intersectable *GetParentObject(const int index) const;
|
---|
[1926] | 191 | Vector3 GetParentNormal(const int index) const;
|
---|
| 192 |
|
---|
[2593] | 193 | /** Sets a preprocessor thread.
|
---|
[1926] | 194 | */
|
---|
| 195 | void SetThread(PreprocessorThread *t);
|
---|
| 196 |
|
---|
[2593] | 197 | /** Returns a preprocessor thread.
|
---|
[1926] | 198 | */
|
---|
| 199 | PreprocessorThread *GetThread() const;
|
---|
| 200 |
|
---|
[1958] | 201 | Intersectable *GetObjectById(const int id);
|
---|
[1926] | 202 |
|
---|
[1968] | 203 | void PrepareHwGlobalLines();
|
---|
[2048] | 204 |
|
---|
| 205 | virtual void DeterminePvsObjects(VssRayContainer &rays);
|
---|
| 206 |
|
---|
[2115] | 207 | static bool LoadObjects(const string &filename,
|
---|
[2593] | 208 | ObjectContainer &pvsObjects,
|
---|
| 209 | const ObjectContainer &preprocessorObject);
|
---|
[2048] | 210 |
|
---|
[2609] | 211 | /** Adds dynamic geometry
|
---|
[2593] | 212 | */
|
---|
[2694] | 213 | SceneGraphLeaf *LoadDynamicGeometry(const string &filename);
|
---|
[538] | 214 |
|
---|
[2694] | 215 | /** Register the dynamic object to be handled by the ray caster for visibility
|
---|
| 216 | computation.
|
---|
| 217 | */
|
---|
[2702] | 218 | void RegisterDynamicObject(SceneGraphLeaf *leaf);
|
---|
[2694] | 219 |
|
---|
[2715] | 220 | void PrepareObjectsForRayCaster(SceneGraphLeaf *l);
|
---|
[2709] | 221 |
|
---|
| 222 | void ScheduleUpdateDynamicObjects();
|
---|
| 223 | void UpdateDynamicObjects();
|
---|
| 224 | /** Notify the preprocessor that an object has been deleted
|
---|
| 225 | */
|
---|
| 226 | virtual void ObjectRemoved(SceneGraphLeaf *object);
|
---|
[2609] | 227 |
|
---|
[2720] | 228 | SceneGraphLeaf *GenerateBoxGeometry(const AxisAlignedBox3 &box);
|
---|
[2694] | 229 |
|
---|
[2720] | 230 | float _HackComputeRenderCost(ViewCell *vc);
|
---|
[2709] | 231 |
|
---|
[2342] | 232 | /////////////////////////
|
---|
| 233 |
|
---|
[2709] | 234 | bool mSynchronize;
|
---|
| 235 |
|
---|
[1564] | 236 | /// scene graph loaded from file
|
---|
| 237 | SceneGraph *mSceneGraph;
|
---|
[599] | 238 |
|
---|
[1564] | 239 | /// raw array of objects
|
---|
| 240 | ObjectContainer mObjects;
|
---|
[658] | 241 |
|
---|
[1564] | 242 | /// kD-tree organizing the scene graph (occluders + occludees) + viewcells
|
---|
| 243 | KdTree *mKdTree;
|
---|
[2609] | 244 | AxisAlignedBox3 sceneBox;
|
---|
| 245 |
|
---|
[1564] | 246 | /// View space partition bsp tree
|
---|
| 247 | VspBspTree *mVspBspTree;
|
---|
| 248 | /// BSP tree representing the viewcells
|
---|
| 249 | BspTree *mBspTree;
|
---|
[878] | 250 |
|
---|
[1564] | 251 | /// list of all loaded occluders
|
---|
| 252 | ObjectContainer mOccluders;
|
---|
| 253 | /// list of all loaded occludees
|
---|
| 254 | ObjectContainer mOccludees;
|
---|
[2609] | 255 | /// the view cells manager
|
---|
[1564] | 256 | ViewCellsManager *mViewCellsManager;
|
---|
[2678] | 257 |
|
---|
[2609] | 258 | DynamicObjectsContainer mDynamicObjects;
|
---|
[2702] | 259 |
|
---|
[1564] | 260 | /// greedy optimized hierarchy for both objects and view cells
|
---|
| 261 | VspOspTree *mVspOspTree;
|
---|
| 262 |
|
---|
| 263 | bool mUseGlRenderer;
|
---|
| 264 | bool mUseGlDebugger;
|
---|
[2342] | 265 |
|
---|
[2187] | 266 | bool mUseHwGlobalLines;
|
---|
[1564] | 267 | bool mLoadViewCells;
|
---|
| 268 |
|
---|
| 269 | bool mDetectEmptyViewSpace;
|
---|
| 270 |
|
---|
| 271 | bool mQuitOnFinish;
|
---|
| 272 | bool mLoadMeshes;
|
---|
| 273 | bool mComputeVisibility;
|
---|
| 274 |
|
---|
| 275 | bool mExportVisibility;
|
---|
| 276 | string mVisibilityFileName;
|
---|
| 277 |
|
---|
| 278 | bool mApplyVisibilityFilter;
|
---|
| 279 | bool mApplyVisibilitySpatialFilter;
|
---|
| 280 |
|
---|
| 281 | float mVisibilityFilterWidth;
|
---|
| 282 |
|
---|
| 283 | int mPass;
|
---|
[2342] | 284 |
|
---|
[1723] | 285 | bool mStopComputation;
|
---|
[2342] | 286 |
|
---|
[1695] | 287 | bool mExportObj;
|
---|
| 288 |
|
---|
[1926] | 289 | bool mExportRays;
|
---|
[2008] | 290 | bool mExportAnimation;
|
---|
[1926] | 291 | int mExportNumRays;
|
---|
[1900] | 292 |
|
---|
[1786] | 293 | ofstream mStats;
|
---|
[1771] | 294 |
|
---|
[1926] | 295 | GlRendererBuffer *renderer;
|
---|
[2625] | 296 | GlRendererWidget *mRendererWidget;
|
---|
[2342] | 297 |
|
---|
[1966] | 298 | int mTotalSamples;
|
---|
[2580] | 299 | int mCurrentSamples;
|
---|
| 300 |
|
---|
[2046] | 301 | int mTotalTime;
|
---|
[1968] | 302 | int mSamplesPerPass;
|
---|
| 303 | int mSamplesPerEvaluation;
|
---|
[2580] | 304 |
|
---|
| 305 | int mTotalRaysCast;
|
---|
[1966] | 306 |
|
---|
[2342] | 307 | RayCaster *mRayCaster;
|
---|
[2076] | 308 |
|
---|
[2709] | 309 | // triangle pvs for gvs
|
---|
[2695] | 310 | // hack: should be in gvspreprocessor but pulled
|
---|
| 311 | // out here for visualization purpose
|
---|
| 312 | ObjectContainer mTrianglePvs;
|
---|
[2743] | 313 | vector<VizStruct> visTriangles;
|
---|
[2636] | 314 |
|
---|
[2709] | 315 | // generic stats vector that can be used for anything
|
---|
| 316 | int mGenericStats[2];
|
---|
| 317 |
|
---|
[2695] | 318 | //std::vector<int> mDummyBuffer;
|
---|
| 319 |
|
---|
| 320 |
|
---|
[492] | 321 | protected:
|
---|
| 322 |
|
---|
[2183] | 323 | bool LoadBinaryObj(const std::string &filename,
|
---|
[2600] | 324 | SceneGraphLeaf *root,
|
---|
[2621] | 325 | std::vector<FaceParentInfo> *parents,
|
---|
| 326 | float scale = -1.0f);
|
---|
[1658] | 327 |
|
---|
[2600] | 328 | bool ExportBinaryObj(const std::string &filename, SceneGraphLeaf *root);
|
---|
[1658] | 329 |
|
---|
[2575] | 330 | void SetupRay(Ray &ray, const Vector3 &point,
|
---|
| 331 | const Vector3 &direction) const;
|
---|
[1251] | 332 |
|
---|
[1520] | 333 | void EvalPvsStat();
|
---|
[492] | 334 |
|
---|
[1786] | 335 | virtual void EvalViewCellHistogram();
|
---|
[1771] | 336 |
|
---|
[2678] | 337 | /** Notify the preprocessor that an object has moved and must be reevaluated.
|
---|
| 338 | */
|
---|
[2645] | 339 | virtual void ObjectMoved(SceneGraphLeaf *object);
|
---|
[2709] | 340 |
|
---|
[2645] | 341 |
|
---|
| 342 |
|
---|
[1520] | 343 | /////////////////////////
|
---|
| 344 |
|
---|
[2017] | 345 | GlobalLinesRenderer *mGlobalLinesRenderer;
|
---|
| 346 |
|
---|
| 347 | /// samples used for construction of the BSP view cells tree.
|
---|
[1564] | 348 | int mBspConstructionSamples;
|
---|
| 349 | /// samples used for construction of the VSP OSP tree.
|
---|
| 350 | int mVspOspConstructionSamples;
|
---|
[1786] | 351 | /// Simulates rendering of the scene.
|
---|
[1564] | 352 | RenderSimulator *mRenderSimulator;
|
---|
[1520] | 353 |
|
---|
[1564] | 354 | vector<FaceParentInfo> mFaceParents;
|
---|
[492] | 355 |
|
---|
[1723] | 356 | /// if box around view space should be used
|
---|
| 357 | bool mUseViewSpaceBox;
|
---|
[1867] | 358 |
|
---|
[1926] | 359 | PreprocessorThread *mThread;
|
---|
[2636] | 360 |
|
---|
[2695] | 361 | bool mUpdateDynamicObjects;
|
---|
| 362 |
|
---|
| 363 |
|
---|
[372] | 364 | };
|
---|
| 365 |
|
---|
[2017] | 366 | extern Preprocessor *preprocessor;
|
---|
[372] | 367 |
|
---|
[860] | 368 | }
|
---|
| 369 |
|
---|
[372] | 370 | #endif
|
---|