[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;
|
---|
[490] | 35 |
|
---|
[1520] | 36 |
|
---|
[372] | 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 |
|
---|
[1145] | 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 | */
|
---|
[1521] | 48 | class Preprocessor
|
---|
[1145] | 49 | {
|
---|
[1520] | 50 | friend class RayCaster;
|
---|
| 51 | friend class IntelRayCaster;
|
---|
| 52 | friend class InternalRayCaster;
|
---|
[2575] | 53 | friend class HavranRayCaster;
|
---|
[1564] | 54 |
|
---|
[372] | 55 | public:
|
---|
| 56 | /** Default constructor initialising e.g., KD tree and BSP tree.
|
---|
| 57 | */
|
---|
| 58 | Preprocessor();
|
---|
| 59 |
|
---|
[1520] | 60 | virtual ~Preprocessor();
|
---|
[1564] | 61 | /** Load the input scene.
|
---|
[2187] | 62 | @param filename file to load
|
---|
| 63 | @return true on success
|
---|
[1564] | 64 | */
|
---|
[2342] | 65 | virtual bool LoadScene(const string &filename);
|
---|
[1564] | 66 | /** Export all preprocessed data in a XML format understandable by the
|
---|
[2187] | 67 | PreprocessingInterface of the GtpVisibilityPreprocessor Module.
|
---|
| 68 | The file can be compressed depending on the environement settings.
|
---|
| 69 | @return true on successful export
|
---|
[1564] | 70 | */
|
---|
[2342] | 71 | virtual bool ExportPreprocessedData(const string &filename);
|
---|
[1564] | 72 | /** Build the KdTree of currently loaded occluders/occludees/viewcells. The construction
|
---|
[2187] | 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)
|
---|
[1564] | 75 | */
|
---|
| 76 | virtual bool BuildKdTree();
|
---|
| 77 | /** Compute visibility method. This method has to be reimplemented by the actual
|
---|
[2187] | 78 | Preprocessor implementation (e.g. SamplingPreprocessor, ExactPreprocessor,
|
---|
| 79 | GlobalSamplingpreprocessor)
|
---|
[1564] | 80 | */
|
---|
| 81 | virtual bool ComputeVisibility() = 0;
|
---|
| 82 | /** Post Process the computed visibility. By default applys the visibility filter
|
---|
[2187] | 83 | (if specified in the environment and export the preprocessed data
|
---|
[2609] | 84 | */
|
---|
[1564] | 85 | virtual bool PostProcessVisibility();
|
---|
| 86 | /** View cells are either loaded or prepared for generation, according to the chosen environment
|
---|
[2187] | 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).
|
---|
[1564] | 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 | */
|
---|
[1884] | 96 | SamplingStrategy *GenerateSamplingStrategy(const int strategyId);
|
---|
[1564] | 97 | /** Export preprocessor data.
|
---|
| 98 | */
|
---|
[2342] | 99 | bool Export(const string &filename, const bool scene, const bool kdtree);
|
---|
[372] | 100 |
|
---|
[1564] | 101 | virtual void KdTreeStatistics(ostream &s);
|
---|
| 102 | virtual void BspTreeStatistics(ostream &s);
|
---|
[490] | 103 |
|
---|
[1564] | 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 | */
|
---|
[2187] | 109 | bool LoadSamples(VssRayContainer &samples, ObjectContainer &objects) const;
|
---|
[508] | 110 |
|
---|
[1564] | 111 | /** Exports samples to file.
|
---|
[2187] | 112 | @returns true if samples were written successfully
|
---|
[1564] | 113 | */
|
---|
| 114 | bool ExportSamples(const VssRayContainer &samples) const;
|
---|
[1197] | 115 |
|
---|
[2342] | 116 | bool LoadKdTree(const string &filename);
|
---|
| 117 | bool ExportKdTree(const string &filename);
|
---|
[1381] | 118 |
|
---|
[1926] | 119 | virtual bool
|
---|
[2001] | 120 | ExportRays(const char *filename,
|
---|
| 121 | const VssRayContainer &vssRays,
|
---|
| 122 | const int number,
|
---|
| 123 | const bool exportScene = false
|
---|
| 124 | );
|
---|
[1926] | 125 |
|
---|
[2048] | 126 | bool ExportRayAnimation(const char *filename,
|
---|
| 127 | const vector<VssRayContainer> &vssRays);
|
---|
[2002] | 128 |
|
---|
[2048] | 129 | virtual int GenerateRays(const int number,
|
---|
| 130 | SamplingStrategy &strategy,
|
---|
| 131 | SimpleRayContainer &rays);
|
---|
[1786] | 132 |
|
---|
[1926] | 133 | virtual int GenerateRays(const int number,
|
---|
[2048] | 134 | const int raysType,
|
---|
| 135 | SimpleRayContainer &rays);
|
---|
[1786] | 136 |
|
---|
| 137 | bool GenerateRayBundle(SimpleRayContainer &rayBundle,
|
---|
[2048] | 138 | const SimpleRay &mainRay,
|
---|
| 139 | const int number,
|
---|
| 140 | const int shuffleType) const;
|
---|
[1786] | 141 |
|
---|
| 142 | virtual void CastRays(SimpleRayContainer &rays,
|
---|
[1932] | 143 | VssRayContainer &vssRays,
|
---|
| 144 | const bool castDoubleRays,
|
---|
[1996] | 145 | const bool pruneInvalidRays = true);
|
---|
[1786] | 146 |
|
---|
[2342] | 147 | virtual void
|
---|
| 148 | CastRaysWithHwGlobalLines(
|
---|
| 149 | SimpleRayContainer &rays,
|
---|
| 150 | VssRayContainer &vssRays,
|
---|
| 151 | const bool castDoubleRays,
|
---|
| 152 | const bool pruneInvalidRays
|
---|
| 153 | );
|
---|
[2076] | 154 |
|
---|
[2187] | 155 | /** Compute pixel error of the current PVS solution by sampling given number of viewpoints.
|
---|
[2048] | 156 | */
|
---|
[1958] | 157 | virtual void ComputeRenderError();
|
---|
[1931] | 158 |
|
---|
[1564] | 159 | /** Returns a view cells manager of the given name.
|
---|
| 160 | */
|
---|
| 161 | ViewCellsManager *CreateViewCellsManager(const char *name);
|
---|
[1221] | 162 |
|
---|
[1564] | 163 | GlRendererBuffer *GetRenderer();
|
---|
[492] | 164 |
|
---|
[2342] | 165 | bool InitRayCast(const string &externKdTree, const string &internKdTree);
|
---|
[409] | 166 |
|
---|
[2342] | 167 | bool LoadInternKdTree(const string &internKdTree);
|
---|
[2003] | 168 |
|
---|
[2342] | 169 | bool ExportObj(const string &filename, const ObjectContainer &objects);
|
---|
[429] | 170 |
|
---|
[1786] | 171 | Intersectable *GetParentObject(const int index) const;
|
---|
[1926] | 172 | Vector3 GetParentNormal(const int index) const;
|
---|
| 173 |
|
---|
[2593] | 174 | /** Sets a preprocessor thread.
|
---|
[1926] | 175 | */
|
---|
| 176 | void SetThread(PreprocessorThread *t);
|
---|
| 177 |
|
---|
[2593] | 178 | /** Returns a preprocessor thread.
|
---|
[1926] | 179 | */
|
---|
| 180 | PreprocessorThread *GetThread() const;
|
---|
| 181 |
|
---|
[1958] | 182 | Intersectable *GetObjectById(const int id);
|
---|
[1926] | 183 |
|
---|
[1968] | 184 | void PrepareHwGlobalLines();
|
---|
[2048] | 185 |
|
---|
| 186 | virtual void DeterminePvsObjects(VssRayContainer &rays);
|
---|
| 187 |
|
---|
[2115] | 188 | static bool LoadObjects(const string &filename,
|
---|
[2593] | 189 | ObjectContainer &pvsObjects,
|
---|
| 190 | const ObjectContainer &preprocessorObject);
|
---|
[2048] | 191 |
|
---|
[2609] | 192 | /** Adds dynamic geometry
|
---|
[2593] | 193 | */
|
---|
[2609] | 194 | bool LoadDynamicGeometry(const string &filename);
|
---|
[538] | 195 |
|
---|
[2609] | 196 | Mesh *Preprocessor::LoadBinaryObjIntoMesh(const string &filename);
|
---|
| 197 |
|
---|
| 198 |
|
---|
[2342] | 199 | /////////////////////////
|
---|
| 200 |
|
---|
[1564] | 201 | /// scene graph loaded from file
|
---|
| 202 | SceneGraph *mSceneGraph;
|
---|
[599] | 203 |
|
---|
[1564] | 204 | /// raw array of objects
|
---|
| 205 | ObjectContainer mObjects;
|
---|
[658] | 206 |
|
---|
[1564] | 207 | /// kD-tree organizing the scene graph (occluders + occludees) + viewcells
|
---|
| 208 | KdTree *mKdTree;
|
---|
[2609] | 209 | AxisAlignedBox3 sceneBox;
|
---|
| 210 |
|
---|
[1564] | 211 | /// View space partition bsp tree
|
---|
| 212 | VspBspTree *mVspBspTree;
|
---|
| 213 | /// BSP tree representing the viewcells
|
---|
| 214 | BspTree *mBspTree;
|
---|
[878] | 215 |
|
---|
[1564] | 216 | /// list of all loaded occluders
|
---|
| 217 | ObjectContainer mOccluders;
|
---|
| 218 | /// list of all loaded occludees
|
---|
| 219 | ObjectContainer mOccludees;
|
---|
[2609] | 220 | /// the view cells manager
|
---|
[1564] | 221 | ViewCellsManager *mViewCellsManager;
|
---|
[2615] | 222 | #if DYNAMIC_OBJECTS_HACK
|
---|
[2609] | 223 | DynamicObjectsContainer mDynamicObjects;
|
---|
[2615] | 224 | #endif
|
---|
[1564] | 225 | /// greedy optimized hierarchy for both objects and view cells
|
---|
| 226 | VspOspTree *mVspOspTree;
|
---|
| 227 |
|
---|
| 228 | bool mUseGlRenderer;
|
---|
| 229 | bool mUseGlDebugger;
|
---|
[2342] | 230 |
|
---|
[2187] | 231 | bool mUseHwGlobalLines;
|
---|
[1564] | 232 | bool mLoadViewCells;
|
---|
| 233 |
|
---|
| 234 | bool mDetectEmptyViewSpace;
|
---|
| 235 |
|
---|
| 236 | bool mQuitOnFinish;
|
---|
| 237 | bool mLoadMeshes;
|
---|
| 238 | bool mComputeVisibility;
|
---|
| 239 |
|
---|
| 240 | bool mExportVisibility;
|
---|
| 241 | string mVisibilityFileName;
|
---|
| 242 |
|
---|
| 243 | bool mApplyVisibilityFilter;
|
---|
| 244 | bool mApplyVisibilitySpatialFilter;
|
---|
| 245 |
|
---|
| 246 | float mVisibilityFilterWidth;
|
---|
| 247 |
|
---|
| 248 | int mPass;
|
---|
[2342] | 249 |
|
---|
[1723] | 250 | bool mStopComputation;
|
---|
[2342] | 251 |
|
---|
[1695] | 252 | bool mExportObj;
|
---|
| 253 |
|
---|
[1926] | 254 | bool mExportRays;
|
---|
[2008] | 255 | bool mExportAnimation;
|
---|
[1926] | 256 | int mExportNumRays;
|
---|
[1900] | 257 |
|
---|
[1786] | 258 | ofstream mStats;
|
---|
[1771] | 259 |
|
---|
[1926] | 260 | GlRendererBuffer *renderer;
|
---|
[2625] | 261 | GlRendererWidget *mRendererWidget;
|
---|
[2342] | 262 |
|
---|
[1966] | 263 | int mTotalSamples;
|
---|
[2580] | 264 | int mCurrentSamples;
|
---|
| 265 |
|
---|
[2046] | 266 | int mTotalTime;
|
---|
[1968] | 267 | int mSamplesPerPass;
|
---|
| 268 | int mSamplesPerEvaluation;
|
---|
[2580] | 269 |
|
---|
| 270 | int mTotalRaysCast;
|
---|
[1966] | 271 |
|
---|
[2342] | 272 | RayCaster *mRayCaster;
|
---|
[2076] | 273 |
|
---|
[2187] | 274 |
|
---|
[2636] | 275 | int mGenericStats;
|
---|
[2633] | 276 |
|
---|
[2636] | 277 | void ScheduleUpdateDynamicObjects() {
|
---|
| 278 | mUpdateDynamicObjects = true;
|
---|
| 279 | }
|
---|
| 280 |
|
---|
| 281 | void UpdateDynamicObjects();
|
---|
| 282 |
|
---|
[492] | 283 | protected:
|
---|
| 284 |
|
---|
[2183] | 285 | bool LoadBinaryObj(const std::string &filename,
|
---|
[2600] | 286 | SceneGraphLeaf *root,
|
---|
[2621] | 287 | std::vector<FaceParentInfo> *parents,
|
---|
| 288 | float scale = -1.0f);
|
---|
[1658] | 289 |
|
---|
[2600] | 290 | bool ExportBinaryObj(const std::string &filename, SceneGraphLeaf *root);
|
---|
[1658] | 291 |
|
---|
[2575] | 292 | void SetupRay(Ray &ray, const Vector3 &point,
|
---|
| 293 | const Vector3 &direction) const;
|
---|
[1251] | 294 |
|
---|
[1520] | 295 | void EvalPvsStat();
|
---|
[492] | 296 |
|
---|
[1786] | 297 | virtual void EvalViewCellHistogram();
|
---|
[1771] | 298 |
|
---|
[2636] | 299 | virtual void ObjectMoved(SceneGraphLeaf *object);
|
---|
[1520] | 300 | /////////////////////////
|
---|
| 301 |
|
---|
[2017] | 302 | GlobalLinesRenderer *mGlobalLinesRenderer;
|
---|
| 303 |
|
---|
| 304 | /// samples used for construction of the BSP view cells tree.
|
---|
[1564] | 305 | int mBspConstructionSamples;
|
---|
| 306 | /// samples used for construction of the VSP OSP tree.
|
---|
| 307 | int mVspOspConstructionSamples;
|
---|
[1786] | 308 | /// Simulates rendering of the scene.
|
---|
[1564] | 309 | RenderSimulator *mRenderSimulator;
|
---|
[1520] | 310 |
|
---|
[1564] | 311 | vector<FaceParentInfo> mFaceParents;
|
---|
[492] | 312 |
|
---|
[1723] | 313 | /// if box around view space should be used
|
---|
| 314 | bool mUseViewSpaceBox;
|
---|
[1867] | 315 |
|
---|
[1926] | 316 | PreprocessorThread *mThread;
|
---|
[2636] | 317 |
|
---|
| 318 | bool mUpdateDynamicObjects;
|
---|
[372] | 319 | };
|
---|
| 320 |
|
---|
[2017] | 321 | extern Preprocessor *preprocessor;
|
---|
[372] | 322 |
|
---|
[860] | 323 | }
|
---|
| 324 |
|
---|
[372] | 325 | #endif
|
---|