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