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